Bug 1261289 - Allow webextensions to open view-source links. r=mixedpuppy, r=smaug
authorThomas Wisniewski <wisniewskit@gmail.com>
Tue, 20 Jun 2017 15:23:49 -0400
changeset 373920 9a2e09bc461f1df68700ea0eee570516c1f8f234
parent 373919 d79d7873a618e32ed77dd119523f83bbe9daedcd
child 373921 164240dd108df3cd7b3a3cb683511781c3577fbb
push id32311
push userkwierso@gmail.com
push dateFri, 11 Aug 2017 01:14:57 +0000
treeherdermozilla-central@253a8560dc34 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, smaug
bugs1261289
milestone57.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 1261289 - Allow webextensions to open view-source links. r=mixedpuppy, r=smaug MozReview-Commit-ID: A8TGE448vBs
browser/components/extensions/test/browser/browser_ext_tabs_create.js
caps/nsScriptSecurityManager.cpp
netwerk/base/nsIProtocolHandler.idl
netwerk/protocol/viewsource/nsViewSourceHandler.cpp
--- a/browser/components/extensions/test/browser/browser_ext_tabs_create.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_create.js
@@ -47,16 +47,20 @@ add_task(async function test_create_opti
           };
 
           let tests = [
             {
               create: {url: "http://example.com/"},
               result: {url: "http://example.com/"},
             },
             {
+              create: {url: "view-source:http://example.com/"},
+              result: {url: "view-source:http://example.com/"},
+            },
+            {
               create: {url: "blank.html"},
               result: {url: browser.runtime.getURL("bg/blank.html")},
             },
             {
               create: {},
               result: {url: "about:newtab"},
             },
             {
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -757,16 +757,31 @@ nsScriptSecurityManager::CheckLoadURIWit
              sourceScheme.EqualsIgnoreCase(targetScheme.get()) &&
              NS_SUCCEEDED(aTargetURI->SchemeIs("view-source", &targetIsViewSource)) &&
              targetIsViewSource)
     {
         // exception for foo: linking to view-source:foo for reftests...
         return NS_OK;
     }
 
+    // Check for webextension
+    rv = NS_URIChainHasFlags(aTargetURI,
+                             nsIProtocolHandler::URI_LOADABLE_BY_EXTENSIONS,
+                             &hasFlags);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (hasFlags) {
+      nsString addonId;
+      aPrincipal->GetAddonId(addonId);
+
+      if (!addonId.IsEmpty()) {
+        return NS_OK;
+      }
+    }
+
     // If we get here, check all the schemes can link to each other, from the top down:
     nsCaseInsensitiveCStringComparator stringComparator;
     nsCOMPtr<nsIURI> currentURI = sourceURI;
     nsCOMPtr<nsIURI> currentOtherURI = aTargetURI;
 
     bool denySameSchemeLinks = false;
     rv = NS_URIChainHasFlags(aTargetURI, nsIProtocolHandler::URI_SCHEME_NOT_SELF_LINKABLE,
                              &denySameSchemeLinks);
--- a/netwerk/base/nsIProtocolHandler.idl
+++ b/netwerk/base/nsIProtocolHandler.idl
@@ -323,9 +323,14 @@ interface nsIProtocolHandler : nsISuppor
      */
     const unsigned long ORIGIN_IS_FULL_SPEC = (1 << 20);
 
     /**
      * If this flag is set, the URI does not always allow content using the same
      * protocol to link to it.
      */
     const unsigned long URI_SCHEME_NOT_SELF_LINKABLE = (1 << 21);
+
+    /**
+     * The URIs for this protocol can be loaded only by extensions.
+     */
+    const unsigned long URI_LOADABLE_BY_EXTENSIONS = (1 << 22);
 };
--- a/netwerk/protocol/viewsource/nsViewSourceHandler.cpp
+++ b/netwerk/protocol/viewsource/nsViewSourceHandler.cpp
@@ -34,17 +34,17 @@ nsViewSourceHandler::GetDefaultPort(int3
     *result = -1;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsViewSourceHandler::GetProtocolFlags(uint32_t *result)
 {
     *result = URI_NORELATIVE | URI_NOAUTH | URI_DANGEROUS_TO_LOAD |
-        URI_NON_PERSISTABLE;
+        URI_LOADABLE_BY_EXTENSIONS | URI_NON_PERSISTABLE;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsViewSourceHandler::NewURI(const nsACString &aSpec,
                             const char *aCharset,
                             nsIURI *aBaseURI,
                             nsIURI **aResult)