Bug 1459750 - Remove unused principal variable r=rpl
authorRob Wu <rob@robwu.nl>
Tue, 08 May 2018 11:31:57 +0200
changeset 819849 11a2e09c259b41c8183b655bebd8b1979c7b7a31
parent 819848 9aeb585f5f7d932875bc020500779e1f04f01c4d
child 819850 47ec1288baef1469e118ab1842b083bd5d0be85a
push id116678
push userbmo:nchevobbe@mozilla.com
push dateWed, 18 Jul 2018 18:05:12 +0000
reviewersrpl
bugs1459750, 1214658, 1317697
milestone63.0a1
Bug 1459750 - Remove unused principal variable r=rpl Variable `principal` is only used when `this.isExtensionPage` is false. So move this inside the branch where this condition is satisfied, and remove the `else if (this.isExtensionPage) { ... }` block. (This is a follow-up to bug 1214658, where the check was introduced that obsoleted the principal variable when `this.isExtensionPage` due to the use of `contentWindow` instead of `principal`). (`principal = contentPrincipal` was already unused at its introduction in bug 1317697) MozReview-Commit-ID: F7VX9vAH8MM
toolkit/components/extensions/ExtensionContent.jsm
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -532,41 +532,38 @@ class ContentScriptContextChild extends 
 
     // Copy origin attributes from the content window origin attributes to
     // preserve the user context id.
     let attrs = contentPrincipal.originAttributes;
     let extensionPrincipal = ssm.createCodebasePrincipal(this.extension.baseURI, attrs);
 
     this.isExtensionPage = contentPrincipal.equals(extensionPrincipal);
 
-    let principal;
-    if (ssm.isSystemPrincipal(contentPrincipal)) {
-      // Make sure we don't hand out the system principal by accident.
-      // also make sure that the null principal has the right origin attributes
-      principal = ssm.createNullPrincipal(attrs);
-    } else if (this.isExtensionPage) {
-      principal = contentPrincipal;
-    } else {
-      principal = [contentPrincipal, extensionPrincipal];
-    }
-
     if (this.isExtensionPage) {
       // This is an iframe with content script API enabled and its principal
       // should be the contentWindow itself. We create a sandbox with the
       // contentWindow as principal and with X-rays disabled because it
       // enables us to create the APIs object in this sandbox object and then
       // copying it into the iframe's window.  See bug 1214658.
       this.sandbox = Cu.Sandbox(contentWindow, {
         sandboxName: `Web-Accessible Extension Page ${extension.policy.debugName}`,
         sandboxPrototype: contentWindow,
         sameZoneAs: contentWindow,
         wantXrays: false,
         isWebExtensionContentScript: true,
       });
     } else {
+      let principal;
+      if (ssm.isSystemPrincipal(contentPrincipal)) {
+        // Make sure we don't hand out the system principal by accident.
+        // Also make sure that the null principal has the right origin attributes.
+        principal = ssm.createNullPrincipal(attrs);
+      } else {
+        principal = [contentPrincipal, extensionPrincipal];
+      }
       // This metadata is required by the Developer Tools, in order for
       // the content script to be associated with both the extension and
       // the tab holding the content page.
       let metadata = {
         "inner-window-id": this.innerWindowID,
         addonId: extensionPrincipal.addonId,
       };