Bug 1658244: Allow view-background-image to open a data: URI by setting a flag on the loadinfo r=Gijs
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Tue, 11 Aug 2020 13:41:54 +0000
changeset 544285 869d82e5b984a126d4674efac49d5ea8798f6b82
parent 544284 356f890107b02ab000426d14ec917f56cd26e8f0
child 544286 06456f429c2215fe320d6317ebece38a0577e8d8
push id123934
push usermozilla@christophkerschbaumer.com
push dateTue, 11 Aug 2020 13:45:19 +0000
treeherderautoland@869d82e5b984 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1658244
milestone81.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1658244: Allow view-background-image to open a data: URI by setting a flag on the loadinfo r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D86592
browser/base/content/nsContextMenu.js
dom/security/test/general/browser.ini
dom/security/test/general/browser_test_view_image_data_navigation.js
dom/security/test/general/file_view_bg_image_data_navigation.html
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -1334,16 +1334,17 @@ class nsContextMenu {
     urlSecurityCheck(
       this.bgImageURL,
       this.principal,
       Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT
     );
 
     openUILink(this.bgImageURL, e, {
       referrerInfo: this.contentData.referrerInfo,
+      forceAllowDataURI: true,
       triggeringPrincipal: this.principal,
       csp: this.csp,
     });
   }
 
   setDesktopBackground() {
     if (!Services.policies.isAllowed("setDesktopBackground")) {
       return;
--- a/dom/security/test/general/browser.ini
+++ b/dom/security/test/general/browser.ini
@@ -8,16 +8,17 @@ support-files =
 support-files =
   file_data_download.html
 [browser_test_data_text_csv.js]
 support-files =
   file_data_text_csv.html
 [browser_test_view_image_data_navigation.js]
 support-files =
   file_view_image_data_navigation.html
+  file_view_bg_image_data_navigation.html
 [browser_test_FTP_console_warning.js]
 support-files =
   file_FTP_console_warning.html
 [browser_test_assert_systemprincipal_documents.js]
 skip-if = !nightly_build
 support-files =
   file_assert_systemprincipal_documents.html
   file_assert_systemprincipal_documents_iframe.html
--- a/dom/security/test/general/browser_test_view_image_data_navigation.js
+++ b/dom/security/test/general/browser_test_view_image_data_navigation.js
@@ -1,18 +1,18 @@
 "use strict";
 
-const TEST_PAGE =
-  getRootDirectory(gTestPath) + "file_view_image_data_navigation.html";
-
 add_task(async function test_principal_right_click_open_link_in_new_tab() {
   await SpecialPowers.pushPrefEnv({
     set: [["security.data_uri.block_toplevel_data_uri_navigations", true]],
   });
 
+  const TEST_PAGE =
+    getRootDirectory(gTestPath) + "file_view_image_data_navigation.html";
+
   await BrowserTestUtils.withNewTab(TEST_PAGE, async function(browser) {
     let loadPromise = BrowserTestUtils.browserLoaded(
       gBrowser.selectedBrowser,
       true
     );
 
     // simulate right-click->view-image
     BrowserTestUtils.waitForEvent(document, "popupshown", false, event => {
@@ -23,16 +23,51 @@ add_task(async function test_principal_r
     });
     BrowserTestUtils.synthesizeMouseAtCenter(
       "#testimage",
       { type: "contextmenu", button: 2 },
       gBrowser.selectedBrowser
     );
     await loadPromise;
 
-    await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function() {
-      ok(
-        content.document.location.toString().startsWith("data:image/svg+xml;"),
-        "data:image/svg navigation allowed through right-click view-image"
-      );
-    });
+    let spec = gBrowser.selectedBrowser.currentURI.spec;
+    ok(
+      spec.startsWith("data:image/svg+xml;"),
+      "data:image/svg navigation allowed through right-click view-image"
+    );
   });
 });
+
+add_task(async function test_right_click_open_bg_image() {
+  await SpecialPowers.pushPrefEnv({
+    set: [["security.data_uri.block_toplevel_data_uri_navigations", true]],
+  });
+
+  const TEST_PAGE =
+    getRootDirectory(gTestPath) + "file_view_bg_image_data_navigation.html";
+
+  await BrowserTestUtils.withNewTab(TEST_PAGE, async function(browser) {
+    let loadPromise = BrowserTestUtils.browserLoaded(
+      gBrowser.selectedBrowser,
+      true
+    );
+
+    // simulate right-click->view-bg-image
+    BrowserTestUtils.waitForEvent(document, "popupshown", false, event => {
+      // These are operations that must be executed synchronously with the event.
+      document.getElementById("context-viewbgimage").doCommand();
+      event.target.hidePopup();
+      return true;
+    });
+    BrowserTestUtils.synthesizeMouseAtCenter(
+      "#testbody",
+      { type: "contextmenu", button: 2 },
+      gBrowser.selectedBrowser
+    );
+    await loadPromise;
+
+    let spec = gBrowser.selectedBrowser.currentURI.spec;
+    ok(
+      spec.startsWith("data:image/svg+xml;"),
+      "data:image/svg navigation allowed through right-click view-bg-image"
+    );
+  });
+});
new file mode 100644
--- /dev/null
+++ b/dom/security/test/general/file_view_bg_image_data_navigation.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Bug 1658244: Test navigation for right-click view-bg-image on data:image/svg</title>
+<style>
+body {
+    background: fixed #222 url("data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjUwMCIgd2lkdGg9IjUwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+PGZpbHRlciBpZD0iYSI+PGZlVHVyYnVsZW5jZSBiYXNlRnJlcXVlbmN5PSIuOSIgbnVtT2N0YXZlcz0iMTAiIHN0aXRjaFRpbGVzPSJzdGl0Y2giIHR5cGU9ImZyYWN0YWxOb2lzZSIvPjwvZmlsdGVyPjxwYXRoIGQ9Im0wIDBoNTAwdjUwMGgtNTAweiIgZmlsbD0iIzExMSIvPjxwYXRoIGQ9Im0wIDBoNTAwdjUwMGgtNTAweiIgZmlsdGVyPSJ1cmwoI2EpIiBvcGFjaXR5PSIuMiIvPjwvc3ZnPgo=");
+    color: #ccc;
+}
+</style>
+</head>
+<body id="testbody">
+  This page has an inline SVG image as a background.
+</body>
+</html>