Bug 1246125 - [webext] webNavigation events should not resolve local special schemes into file/jar URLs. r=krizsa
authorLuca Greco <lgreco@mozilla.com>
Thu, 07 Apr 2016 00:04:23 +0200
changeset 331621 170eb8db5f8c99212b07756ce67ef86c45d7c229
parent 331620 3e8852edb5a0cd8c2bbbc4e6cf1142d0acef5514
child 331622 6f7203377bf7871fe80ac0f3b23e0a23a57cdbfb
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskrizsa
bugs1246125
milestone48.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 1246125 - [webext] webNavigation events should not resolve local special schemes into file/jar URLs. r=krizsa - chrome, resource, about and moz-extension URLs should not be reported with their resolved file or jar URLs MozReview-Commit-ID: H03rjxGpgOZ
toolkit/components/extensions/test/mochitest/chrome.ini
toolkit/components/extensions/test/mochitest/test_chrome_ext_webnavigation_resolved_urls.html
toolkit/modules/addons/WebNavigationContent.js
--- a/toolkit/components/extensions/test/mochitest/chrome.ini
+++ b/toolkit/components/extensions/test/mochitest/chrome.ini
@@ -8,8 +8,10 @@ support-files =
 [test_chrome_ext_background_debug_global.html]
 skip-if = (os == 'android') # android doesn't have devtools
 [test_chrome_ext_downloads_download.html]
 [test_chrome_ext_downloads_misc.html]
 [test_chrome_ext_downloads_search.html]
 [test_chrome_ext_eventpage_warning.html]
 [test_chrome_ext_contentscript_unrecognizedprop_warning.html]
 skip-if = (os == 'android') # browser.tabs is undefined. Bug 1258975 on android.
+[test_chrome_ext_webnavigation_resolved_urls.html]
+skip-if = (os == 'android') # browser.tabs is undefined. Bug 1258975 on android.
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_webnavigation_resolved_urls.html
@@ -0,0 +1,83 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for simple WebExtension</title>
+  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+  <script src="chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js"></script>
+  <script type="text/javascript" src="head.js"></script>
+  <link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="text/javascript">
+"use strict";
+
+add_task(function* webnav_unresolved_uri_on_expected_URI_scheme() {
+  function backgroundScript() {
+    let checkURLs;
+
+    browser.webNavigation.onCompleted.addListener((msg) => {
+      if (checkURLs.length > 0) {
+        let expectedURL = checkURLs.shift();
+        browser.test.assertEq(expectedURL, msg.url, "Got the expected URL");
+        browser.tabs.remove(msg.tabId).then(() => {
+          browser.test.sendMessage("next");
+        });
+      }
+    });
+
+    browser.test.onMessage.addListener((name, urls) => {
+      if (name == "checkURLs") {
+        checkURLs = urls;
+      }
+    });
+
+    browser.test.sendMessage("ready", browser.runtime.getURL("/tab.html"));
+  }
+
+  let extensionData = {
+    manifest: {
+      permissions: [
+        "webNavigation",
+      ],
+    },
+    background: "new " + backgroundScript,
+    files: {
+      "tab.html": `<!DOCTYPE html>
+        <html>
+          <head>
+           <meta charset="utf-8">
+          </head>
+        </html>
+      `,
+    },
+  };
+
+  let extension = ExtensionTestUtils.loadExtension(extensionData);
+
+  yield extension.startup();
+
+  let checkURLs = [
+    "resource://gre/modules/Services.jsm",
+    "chrome://mochikit/content/tests/SimpleTest/SimpleTest.js",
+    "about:mozilla",
+  ];
+
+  let tabURL = yield extension.awaitMessage("ready");
+  checkURLs.push(tabURL);
+
+  extension.sendMessage("checkURLs", checkURLs);
+
+  for (let url of checkURLs) {
+    window.open(url);
+    yield extension.awaitMessage("next");
+  }
+
+  yield extension.unload();
+});
+
+</script>
+
+</body>
+</html>
--- a/toolkit/modules/addons/WebNavigationContent.js
+++ b/toolkit/modules/addons/WebNavigationContent.js
@@ -49,17 +49,28 @@ var WebProgressListener = {
       return;
     }
     let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                               .getInterface(Ci.nsIWebProgress);
     webProgress.removeProgressListener(this);
   },
 
   onStateChange: function onStateChange(webProgress, request, stateFlags, status) {
-    let locationURI = request.QueryInterface(Ci.nsIChannel).URI;
+    let {originalURI, URI: locationURI} = request.QueryInterface(Ci.nsIChannel);
+
+    // Prevents "about", "chrome", "resource" and "moz-extension" URI schemes to be
+    // reported with the resolved "file" or "jar" URIs. (see Bug 1246125 for rationale)
+    if (locationURI.schemeIs("file") || locationURI.schemeIs("jar")) {
+      let shouldUseOriginalURI = originalURI.schemeIs("about") ||
+                                 originalURI.schemeIs("chrome") ||
+                                 originalURI.schemeIs("resource") ||
+                                 originalURI.schemeIs("moz-extension");
+
+      locationURI = shouldUseOriginalURI ? originalURI : locationURI;
+    }
 
     this.sendStateChange({webProgress, locationURI, stateFlags, status});
 
     // Based on the docs of the webNavigation.onCommitted event, it should be raised when:
     // "The document  might still be downloading, but at least part of
     // the document has been received"
     // and for some reason we don't fire onLocationChange for the
     // initial navigation of a sub-frame.