Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsDOMNavigationTiming.h" |
michael@0 | 7 | #include "nsPerformance.h" |
michael@0 | 8 | #include "nsCOMPtr.h" |
michael@0 | 9 | #include "nsContentUtils.h" |
michael@0 | 10 | #include "nsIScriptSecurityManager.h" |
michael@0 | 11 | #include "prtime.h" |
michael@0 | 12 | #include "nsIURI.h" |
michael@0 | 13 | #include "mozilla/TimeStamp.h" |
michael@0 | 14 | |
michael@0 | 15 | nsDOMNavigationTiming::nsDOMNavigationTiming() |
michael@0 | 16 | { |
michael@0 | 17 | Clear(); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | nsDOMNavigationTiming::~nsDOMNavigationTiming() |
michael@0 | 21 | { |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | void |
michael@0 | 25 | nsDOMNavigationTiming::Clear() |
michael@0 | 26 | { |
michael@0 | 27 | mNavigationType = mozilla::dom::PerformanceNavigation::TYPE_RESERVED; |
michael@0 | 28 | mNavigationStartHighRes = 0; |
michael@0 | 29 | mBeforeUnloadStart = 0; |
michael@0 | 30 | mUnloadStart = 0; |
michael@0 | 31 | mUnloadEnd = 0; |
michael@0 | 32 | mLoadEventStart = 0; |
michael@0 | 33 | mLoadEventEnd = 0; |
michael@0 | 34 | mDOMLoading = 0; |
michael@0 | 35 | mDOMInteractive = 0; |
michael@0 | 36 | mDOMContentLoadedEventStart = 0; |
michael@0 | 37 | mDOMContentLoadedEventEnd = 0; |
michael@0 | 38 | mDOMComplete = 0; |
michael@0 | 39 | |
michael@0 | 40 | mLoadEventStartSet = false; |
michael@0 | 41 | mLoadEventEndSet = false; |
michael@0 | 42 | mDOMLoadingSet = false; |
michael@0 | 43 | mDOMInteractiveSet = false; |
michael@0 | 44 | mDOMContentLoadedEventStartSet = false; |
michael@0 | 45 | mDOMContentLoadedEventEndSet = false; |
michael@0 | 46 | mDOMCompleteSet = false; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | DOMTimeMilliSec |
michael@0 | 50 | nsDOMNavigationTiming::TimeStampToDOM(mozilla::TimeStamp aStamp) const |
michael@0 | 51 | { |
michael@0 | 52 | if (aStamp.IsNull()) { |
michael@0 | 53 | return 0; |
michael@0 | 54 | } |
michael@0 | 55 | mozilla::TimeDuration duration = aStamp - mNavigationStartTimeStamp; |
michael@0 | 56 | return GetNavigationStart() + static_cast<int64_t>(duration.ToMilliseconds()); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | DOMTimeMilliSec nsDOMNavigationTiming::DurationFromStart(){ |
michael@0 | 60 | return TimeStampToDOM(mozilla::TimeStamp::Now()); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | void |
michael@0 | 64 | nsDOMNavigationTiming::NotifyNavigationStart() |
michael@0 | 65 | { |
michael@0 | 66 | mNavigationStartHighRes = (double)PR_Now() / PR_USEC_PER_MSEC; |
michael@0 | 67 | mNavigationStartTimeStamp = mozilla::TimeStamp::Now(); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | void |
michael@0 | 71 | nsDOMNavigationTiming::NotifyFetchStart(nsIURI* aURI, nsDOMPerformanceNavigationType aNavigationType) |
michael@0 | 72 | { |
michael@0 | 73 | mNavigationType = aNavigationType; |
michael@0 | 74 | // At the unload event time we don't really know the loading uri. |
michael@0 | 75 | // Need it for later check for unload timing access. |
michael@0 | 76 | mLoadedURI = aURI; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | void |
michael@0 | 80 | nsDOMNavigationTiming::NotifyBeforeUnload() |
michael@0 | 81 | { |
michael@0 | 82 | mBeforeUnloadStart = DurationFromStart(); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | void |
michael@0 | 86 | nsDOMNavigationTiming::NotifyUnloadAccepted(nsIURI* aOldURI) |
michael@0 | 87 | { |
michael@0 | 88 | mUnloadStart = mBeforeUnloadStart; |
michael@0 | 89 | mUnloadedURI = aOldURI; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | void |
michael@0 | 93 | nsDOMNavigationTiming::NotifyUnloadEventStart() |
michael@0 | 94 | { |
michael@0 | 95 | mUnloadStart = DurationFromStart(); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | void |
michael@0 | 99 | nsDOMNavigationTiming::NotifyUnloadEventEnd() |
michael@0 | 100 | { |
michael@0 | 101 | mUnloadEnd = DurationFromStart(); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | void |
michael@0 | 105 | nsDOMNavigationTiming::NotifyLoadEventStart() |
michael@0 | 106 | { |
michael@0 | 107 | if (!mLoadEventStartSet) { |
michael@0 | 108 | mLoadEventStart = DurationFromStart(); |
michael@0 | 109 | mLoadEventStartSet = true; |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | void |
michael@0 | 114 | nsDOMNavigationTiming::NotifyLoadEventEnd() |
michael@0 | 115 | { |
michael@0 | 116 | if (!mLoadEventEndSet) { |
michael@0 | 117 | mLoadEventEnd = DurationFromStart(); |
michael@0 | 118 | mLoadEventEndSet = true; |
michael@0 | 119 | } |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | void |
michael@0 | 123 | nsDOMNavigationTiming::SetDOMLoadingTimeStamp(nsIURI* aURI, mozilla::TimeStamp aValue) |
michael@0 | 124 | { |
michael@0 | 125 | if (!mDOMLoadingSet) { |
michael@0 | 126 | mLoadedURI = aURI; |
michael@0 | 127 | mDOMLoading = TimeStampToDOM(aValue); |
michael@0 | 128 | mDOMLoadingSet = true; |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | void |
michael@0 | 133 | nsDOMNavigationTiming::NotifyDOMLoading(nsIURI* aURI) |
michael@0 | 134 | { |
michael@0 | 135 | if (!mDOMLoadingSet) { |
michael@0 | 136 | mLoadedURI = aURI; |
michael@0 | 137 | mDOMLoading = DurationFromStart(); |
michael@0 | 138 | mDOMLoadingSet = true; |
michael@0 | 139 | } |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | void |
michael@0 | 143 | nsDOMNavigationTiming::NotifyDOMInteractive(nsIURI* aURI) |
michael@0 | 144 | { |
michael@0 | 145 | if (!mDOMInteractiveSet) { |
michael@0 | 146 | mLoadedURI = aURI; |
michael@0 | 147 | mDOMInteractive = DurationFromStart(); |
michael@0 | 148 | mDOMInteractiveSet = true; |
michael@0 | 149 | } |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | void |
michael@0 | 153 | nsDOMNavigationTiming::NotifyDOMComplete(nsIURI* aURI) |
michael@0 | 154 | { |
michael@0 | 155 | if (!mDOMCompleteSet) { |
michael@0 | 156 | mLoadedURI = aURI; |
michael@0 | 157 | mDOMComplete = DurationFromStart(); |
michael@0 | 158 | mDOMCompleteSet = true; |
michael@0 | 159 | } |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | void |
michael@0 | 163 | nsDOMNavigationTiming::NotifyDOMContentLoadedStart(nsIURI* aURI) |
michael@0 | 164 | { |
michael@0 | 165 | if (!mDOMContentLoadedEventStartSet) { |
michael@0 | 166 | mLoadedURI = aURI; |
michael@0 | 167 | mDOMContentLoadedEventStart = DurationFromStart(); |
michael@0 | 168 | mDOMContentLoadedEventStartSet = true; |
michael@0 | 169 | } |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | void |
michael@0 | 173 | nsDOMNavigationTiming::NotifyDOMContentLoadedEnd(nsIURI* aURI) |
michael@0 | 174 | { |
michael@0 | 175 | if (!mDOMContentLoadedEventEndSet) { |
michael@0 | 176 | mLoadedURI = aURI; |
michael@0 | 177 | mDOMContentLoadedEventEnd = DurationFromStart(); |
michael@0 | 178 | mDOMContentLoadedEventEndSet = true; |
michael@0 | 179 | } |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | DOMTimeMilliSec |
michael@0 | 183 | nsDOMNavigationTiming::GetUnloadEventStart() |
michael@0 | 184 | { |
michael@0 | 185 | nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); |
michael@0 | 186 | nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false); |
michael@0 | 187 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 188 | return mUnloadStart; |
michael@0 | 189 | } |
michael@0 | 190 | return 0; |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | DOMTimeMilliSec |
michael@0 | 194 | nsDOMNavigationTiming::GetUnloadEventEnd() |
michael@0 | 195 | { |
michael@0 | 196 | nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); |
michael@0 | 197 | nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false); |
michael@0 | 198 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 199 | return mUnloadEnd; |
michael@0 | 200 | } |
michael@0 | 201 | return 0; |
michael@0 | 202 | } |
michael@0 | 203 |