Bug 1287007 - Set the principal in ChildAPIManager draft
authorRob Wu <rob@robwu.nl>
Wed, 07 Sep 2016 20:35:39 -0700
changeset 411563 37e8ed7cb027293a4f72c989113024bdb5bf07ec
parent 411562 1e14b8075658f11a523c6a8550800ab989aa5f2d
child 530755 a878502208e70cca82d79a758d1eb4f6a766bd26
push id28922
push userbmo:rob@robwu.nl
push dateThu, 08 Sep 2016 08:44:00 +0000
bugs1287007
milestone51.0a1
Bug 1287007 - Set the principal in ChildAPIManager The `browser.downloads.download` API takes a "url" parameter. The schema file at downloads.json defines the type to be "url". This means that the parameter is checked with `context.checkLoadURL(url)` in Schemas.jsm. This method uses the principal of the object that was passed to `Schemas.inject`. Currently, this works just fine because the `schemaWrapper` in Extension.jsm returns the context's principal. But when we move to using the ChildAPIManager, the principal is not defined and Schemas.jsm will fall back to a Null principal. As a result, the test_ext_downloads_download.js fails because the blob:-URL with the extension origin cannot be loaded by a null principal. To fix this, the context's principal must be set. MozReview-Commit-ID: FmpqYfPemyY
toolkit/components/extensions/ExtensionUtils.jsm
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -1794,16 +1794,20 @@ class ChildAPIManager {
   close() {
     this.messageManager.sendAsyncMessage("API:CloseProxyContext", {childId: this.id});
   }
 
   get cloneScope() {
     return this.context.cloneScope;
   }
 
+  get principal() {
+    return this.context.principal;
+  }
+
   shouldInject(namespace, name, restrictions) {
     // Do not generate content script APIs, unless explicitly allowed.
     if (this.context.envType === "content_child" &&
         (!restrictions || !restrictions.includes("content"))) {
       return false;
     }
     return true;
   }