Bug 1295309 - Add isTopLevelLoad attribute in nsILoadInfo. r=billm, a=ritu
authorKershaw Chang <kechang@mozilla.com>
Sun, 21 Aug 2016 21:46:09 -0400
changeset 350254 249bd8812e3acca623030ad8633a9f6ec9087aaa
parent 350253 896ec9bfee489ed22542320b2a3b10fac74081a7
child 350255 dd43153e25c9973926703925830a1499c65a7c41
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm, ritu
bugs1295309
milestone50.0a2
Bug 1295309 - Add isTopLevelLoad attribute in nsILoadInfo. r=billm, a=ritu
devtools/shared/webconsole/network-helper.js
netwerk/base/LoadInfo.cpp
netwerk/base/nsILoadInfo.idl
--- a/devtools/shared/webconsole/network-helper.js
+++ b/devtools/shared/webconsole/network-helper.js
@@ -267,17 +267,17 @@ var NetworkHelper = {
    * Determines whether the request has been made for the top level document.
    *
    * @param nsIHttpChannel request
    * @returns Boolean True if the request represents the top level document.
    */
   isTopLevelLoad: function (request) {
     if (request instanceof Ci.nsIChannel) {
       let loadInfo = request.loadInfo;
-      if (loadInfo && loadInfo.parentOuterWindowID == loadInfo.outerWindowID) {
+      if (loadInfo && loadInfo.isTopLevelLoad) {
         return (request.loadFlags & Ci.nsIChannel.LOAD_DOCUMENT_URI);
       }
     }
 
     return false;
   },
 
   /**
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -794,10 +794,18 @@ LoadInfo::MaybeIncreaseTainting(uint32_t
   NS_ENSURE_ARG(aTainting <= TAINTING_OPAQUE);
   LoadTainting tainting = static_cast<LoadTainting>(aTainting);
   if (tainting > mTainting) {
     mTainting = tainting;
   }
   return NS_OK;
 }
 
+NS_IMETHODIMP
+LoadInfo::GetIsTopLevelLoad(bool *aResult)
+{
+  *aResult = mFrameOuterWindowID ? mFrameOuterWindowID == mOuterWindowID
+                                 : mParentOuterWindowID == mOuterWindowID;
+  return NS_OK;
+}
+
 } // namespace net
 } // namespace mozilla
--- a/netwerk/base/nsILoadInfo.idl
+++ b/netwerk/base/nsILoadInfo.idl
@@ -596,9 +596,15 @@ interface nsILoadInfo : nsISupports
   }
 
   void MaybeIncreaseTainting(mozilla::LoadTainting aTainting)
   {
     uint32_t tainting = static_cast<uint32_t>(aTainting);
     MOZ_ALWAYS_SUCCEEDS(MaybeIncreaseTainting(tainting));
   }
 %}
+
+  /**
+   * Returns true if this load is for top level document.
+   * Note that the load for a sub-frame's document will return false here.
+   */
+  [infallible] readonly attribute boolean isTopLevelLoad;
 };