Bug 836567 - Part 1: Set ResultPrincipalURI to active document's URI before evaluating script. r?bz draft
authorSamael Wang <freesamael@gmail.com>
Thu, 23 Nov 2017 17:21:17 +0800
changeset 704049 ec6b203b3b439d39338d96ea62d7d563e404f7c5
parent 689820 ee21e5f7f1c1726e0ed2697eb45df54cdceedd36
child 704050 284f75f1cb0b2fd41403f78af57ed1649034aee1
push id91050
push userbmo:sawang@mozilla.com
push dateTue, 28 Nov 2017 06:08:27 +0000
reviewersbz
bugs836567
milestone58.0a1
Bug 836567 - Part 1: Set ResultPrincipalURI to active document's URI before evaluating script. r?bz MozReview-Commit-ID: CQ5l4Diagy0
dom/jsurl/nsJSProtocolHandler.cpp
--- a/dom/jsurl/nsJSProtocolHandler.cpp
+++ b/dom/jsurl/nsJSProtocolHandler.cpp
@@ -687,16 +687,26 @@ nsJSChannel::EvaluateScript()
     // indicate the the request is busy while the script is executing...
 
     // Note that we want to be in the loadgroup and pending while we evaluate
     // the script, so that we find out if the loadgroup gets canceled by the
     // script execution (in which case we shouldn't pump out data even if the
     // script returns it).
 
     if (NS_SUCCEEDED(mStatus)) {
+        nsCOMPtr<nsILoadInfo> loadInfo;
+        mStreamChannel->GetLoadInfo(getter_AddRefs(loadInfo));
+        if (loadInfo) {
+            // Set the channel's resultPrincipalURI to the active document's URI.
+            nsCOMPtr<nsIURI> docURI = mOriginalInnerWindow->GetDocumentURI();
+            if (docURI) {
+                loadInfo->SetResultPrincipalURI(docURI);
+            }
+        }
+
         nsresult rv = mIOThunk->EvaluateScript(mStreamChannel, mPopupState,
                                                mExecutionPolicy,
                                                mOriginalInnerWindow);
 
         // Note that evaluation may have canceled us, so recheck mStatus again
         if (NS_FAILED(rv) && NS_SUCCEEDED(mStatus)) {
             mStatus = rv;
         }