Bug 1134391 - Make "View Image/Video" command use messages to avoid unsafe CPOW warnings. r=mconley
authorIan Moody <moz-ian@perix.co.uk>
Wed, 04 Mar 2015 21:27:35 +0000
changeset 234226 839427d11a62b13084f7ef6efe913021c78d759b
parent 234225 2f64916c94aa4b783e1c4abb2e5e5baf5b27637c
child 234227 7490149fd064fe9a312528d0233eccbb92805a9d
push id11828
push userryanvm@gmail.com
push dateWed, 18 Mar 2015 15:24:53 +0000
treeherderfx-team@4b5850a205d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1134391
milestone39.0a1
Bug 1134391 - Make "View Image/Video" command use messages to avoid unsafe CPOW warnings. r=mconley
browser/base/content/content.js
browser/base/content/nsContextMenu.js
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -1104,8 +1104,13 @@ addMessageListener("ContextMenu:MediaCom
       media.dispatchEvent(event);
       break;
     case "fullscreen":
       if (content.document.mozFullScreenEnabled)
         media.mozRequestFullScreen();
       break;
   }
 });
+
+addMessageListener("ContextMenu:Canvas:ToDataURL", (message) => {
+  let dataURL = message.objects.target.toDataURL();
+  sendAsyncMessage("ContextMenu:Canvas:ToDataURL:Result", { dataURL });
+});
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -1020,32 +1020,45 @@ nsContextMenu.prototype = {
     urlSecurityCheck(this.mediaURL,
                      this.browser.contentPrincipal,
                      Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
 
     if (this.target instanceof Ci.nsIImageLoadingContent)
       this.target.forceReload();
   },
 
+  _canvasToDataURL: function(target) {
+    let mm = this.browser.messageManager;
+    return new Promise(function(resolve) {
+      mm.sendAsyncMessage("ContextMenu:Canvas:ToDataURL", {}, { target });
+
+      let onMessage = (message) => {
+        mm.removeMessageListener("ContextMenu:Canvas:ToDataURL:Result", onMessage);
+        resolve(message.data.dataURL);
+      };
+      mm.addMessageListener("ContextMenu:Canvas:ToDataURL:Result", onMessage);
+    });
+  },
+
   // Change current window to the URL of the image, video, or audio.
   viewMedia: function(e) {
-    var viewURL;
-
-    if (this.onCanvas)
-      viewURL = this.target.toDataURL();
+    let referrerURI = gContextMenuContentData.documentURIObject;
+    if (this.onCanvas) {
+      this._canvasToDataURL(this.target).then(function(dataURL) {
+        openUILink(dataURL, e, { disallowInheritPrincipal: true,
+                                 referrerURI: referrerURI });
+      }, Cu.reportError);
+    }
     else {
-      viewURL = this.mediaURL;
-      urlSecurityCheck(viewURL,
+      urlSecurityCheck(this.mediaURL,
                        this.browser.contentPrincipal,
                        Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
+      openUILink(this.mediaURL, e, { disallowInheritPrincipal: true,
+                                     referrerURI: referrerURI });
     }
-
-    var doc = this.target.ownerDocument;
-    openUILink(viewURL, e, { disallowInheritPrincipal: true,
-                             referrerURI: doc.documentURIObject });
   },
 
   saveVideoFrameAsImage: function () {
     let mm = this.browser.messageManager;
     let name = "";
     if (this.mediaURL) {
       try {
         let uri = makeURI(this.mediaURL);