Bug 1287007 - Set the principal in ChildAPIManager draft
authorRob Wu <rob@robwu.nl>
Wed, 07 Sep 2016 20:35:39 -0700
changeset 428436 2eac95f806a789f9e6bf42132a8e5a623de0573d
parent 428435 2cb89c1b0f273070d2279d94aa074507faeb576a
child 428437 a87e1dc8643455fb72fe04ca53f41ea82963cc48
push id33305
push userbmo:rob@robwu.nl
push dateSun, 23 Oct 2016 20:56:25 +0000
bugs1287007
milestone52.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
@@ -1859,16 +1859,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, allowedContexts) {
     // Do not generate content script APIs, unless explicitly allowed.
     return this.context.envType !== "content_child" || allowedContexts.includes("content");
   }
 
   getImplementation(namespace, name) {
     let pathObj = this.localApis;
     if (pathObj) {