Bug 1099092 - Navigation Timing has incorrect values when page is load via link with target=_blank attribute r=bz
authorValentin Gosu <valentin.gosu@gmail.com>
Fri, 09 Jan 2015 16:36:00 +0200
changeset 248840 f0341b791d11fcb58ddd621755cba3f9748a6080
parent 248839 f2d5cd863b148f524bc1a5b117d1617110735417
child 248841 7a4d06a8f2ca98a540089364e2ffe3289d25ed55
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1099092
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1099092 - Navigation Timing has incorrect values when page is load via link with target=_blank attribute r=bz
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
dom/base/nsPerformance.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -190,16 +190,17 @@
 #include "nsISupportsArray.h"
 #include "nsIURIFixup.h"
 #include "nsIURILoader.h"
 #include "nsIWebBrowserFind.h"
 #include "nsIWidget.h"
 #include "mozilla/dom/EncodingUtils.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/URLSearchParams.h"
+#include "nsPerformance.h"
 
 #ifdef MOZ_TOOLKIT_SEARCH
 #include "nsIBrowserSearchService.h"
 #endif
 
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 #if defined(DEBUG_bryner) || defined(DEBUG_chb)
@@ -854,16 +855,17 @@ nsDocShell::nsDocShell():
     mSavingOldViewer(false),
 #ifdef DEBUG
     mInEnsureScriptEnv(false),
 #endif
     mAffectPrivateSessionLifetime(true),
     mInvisible(false),
     mHasLoadedNonBlankURI(false),
     mDefaultLoadFlags(nsIRequest::LOAD_NORMAL),
+    mBlankTiming(false),
     mFrameType(eFrameTypeRegular),
     mOwnOrContainingAppId(nsIScriptSecurityManager::UNKNOWN_APP_ID),
     mParentCharsetSource(0),
     mJSRunToCompletionDepth(0)
 {
     mHistoryID = ++gDocshellIDCounter;
     if (gDocShellCount++ == 0) {
         NS_ASSERTION(sURIFixup == nullptr,
@@ -1765,21 +1767,32 @@ nsDocShell::FirePageHideNotification(boo
     }
 
     return NS_OK;
 }
 
 void
 nsDocShell::MaybeInitTiming()
 {
-    if (mTiming) {
+    if (mTiming && !mBlankTiming) {
         return;
     }
 
-    mTiming = new nsDOMNavigationTiming();
+    if (mScriptGlobal && mBlankTiming) {
+        nsPIDOMWindow* innerWin = mScriptGlobal->GetCurrentInnerWindow();
+        if (innerWin && innerWin->GetPerformance()) {
+            mTiming = innerWin->GetPerformance()->GetDOMTiming();
+            mBlankTiming = false;
+        }
+    }
+
+    if (!mTiming) {
+      mTiming = new nsDOMNavigationTiming();
+    }
+
     mTiming->NotifyNavigationStart();
 }
 
 
 //
 // Bug 13871: Prevent frameset spoofing
 //
 // This routine answers: 'Is origin's document from same domain as
@@ -7864,16 +7877,17 @@ nsDocShell::CreateAboutBlankContentViewe
 
   // The transient about:blank viewer doesn't have a session history entry.
   SetHistoryEntry(&mOSHE, nullptr);
 
   // Clear out our mTiming like we would in EndPageLoad, if we didn't
   // have one before entering this function.
   if (!hadTiming) {
     mTiming = nullptr;
+    mBlankTiming = true;
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal *aPrincipal)
 {
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -924,16 +924,21 @@ protected:
     bool                       mHasLoadedNonBlankURI;
     uint64_t                   mHistoryID;
     uint32_t                   mDefaultLoadFlags;
 
     static nsIURIFixup *sURIFixup;
 
     nsRefPtr<nsDOMNavigationTiming> mTiming;
 
+    // This flag means that mTiming has been initialized but nulled out.
+    // We will check the innerWin's timing before creating a new one
+    // in MaybeInitTiming()
+    bool                            mBlankTiming;
+
     // Are we a regular frame, a browser frame, or an app frame?
     FrameType mFrameType;
 
     // We only expect mOwnOrContainingAppId to be something other than
     // UNKNOWN_APP_ID if mFrameType != eFrameTypeRegular.  For vanilla iframes
     // inside an app, we'll retrieve the containing app-id by walking up the
     // docshell hierarchy.
     //
--- a/dom/base/nsPerformance.cpp
+++ b/dom/base/nsPerformance.cpp
@@ -180,21 +180,21 @@ nsPerformanceTiming::RedirectStartHighRe
   }
   return TimeStampToDOMHighResOrFetchStart(mRedirectStart);
 }
 
 DOMTimeMilliSec
 nsPerformanceTiming::RedirectStart()
 {
   if (!IsInitialized()) {
-    return mZeroTime;
+    return 0;
   }
   // We have to check if all the redirect URIs had the same origin (since there
   // is no check in RedirectStartHighRes())
-  if (mAllRedirectsSameOrigin) {
+  if (mAllRedirectsSameOrigin && mRedirectCount) {
     return static_cast<int64_t>(RedirectStartHighRes());
   }
   return 0;
 }
 
 /**
  * RedirectEndHighRes() is used by both the navigation timing and the resource
  * timing. Since, navigation timing and resource timing check and interpret
@@ -213,21 +213,21 @@ nsPerformanceTiming::RedirectEndHighRes(
   }
   return TimeStampToDOMHighResOrFetchStart(mRedirectEnd);
 }
 
 DOMTimeMilliSec
 nsPerformanceTiming::RedirectEnd()
 {
   if (!IsInitialized()) {
-    return mZeroTime;
+    return 0;
   }
   // We have to check if all the redirect URIs had the same origin (since there
   // is no check in RedirectEndHighRes())
-  if (mAllRedirectsSameOrigin) {
+  if (mAllRedirectsSameOrigin && mRedirectCount) {
     return static_cast<int64_t>(RedirectEndHighRes());
   }
   return 0;
 }
 
 DOMHighResTimeStamp
 nsPerformanceTiming::DomainLookupStartHighRes()
 {