Bug 1237868 - Don't set URI_IS_LOCAL_RESOURCE on media streams. r=baku, a=gchang
authorKate McKinley <kmckinley@mozilla.com>
Sat, 01 Apr 2017 15:11:53 -0400
changeset 395671 f68178e63a35f47aab44a384f697696b037f46bd
parent 395670 bb23eb792eba53ae4464ebff9dc79f3572208836
child 395672 29eab893bad014e0e9e6af3df255230e2abebad5
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, gchang
bugs1237868
milestone54.0a2
Bug 1237868 - Don't set URI_IS_LOCAL_RESOURCE on media streams. r=baku, a=gchang This patch only sets URI_IS_LOCAL_RESOURCE if the resource is a blob or font table entry, to avoid having media streams treated as local objects. MozReview-Commit-ID: GOVr8FPByQy
dom/file/moz.build
dom/file/nsHostObjectProtocolHandler.cpp
dom/file/nsHostObjectProtocolHandler.h
dom/file/tests/test_bloburi.js
dom/file/tests/xpcshell.ini
--- a/dom/file/moz.build
+++ b/dom/file/moz.build
@@ -60,11 +60,13 @@ UNIFIED_SOURCES += [
 ]
 
 LOCAL_INCLUDES += [
     '/dom/workers',
 ]
 
 MOCHITEST_MANIFESTS += ['tests/mochitest.ini']
 
+XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell.ini']
+
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
--- a/dom/file/nsHostObjectProtocolHandler.cpp
+++ b/dom/file/nsHostObjectProtocolHandler.cpp
@@ -29,16 +29,17 @@
 #define RELEASING_TIMER 1000
 
 using mozilla::DOMMediaStream;
 using mozilla::dom::BlobImpl;
 using mozilla::dom::MediaSource;
 using mozilla::ErrorResult;
 using mozilla::net::LoadInfo;
 using mozilla::Move;
+using mozilla::Unused;
 
 // -----------------------------------------------------------------------
 // Hash table
 struct DataInfo
 {
   enum ObjectType {
     eBlobImpl,
     eMediaStream,
@@ -741,17 +742,36 @@ nsHostObjectProtocolHandler::GetDefaultP
   *result = -1;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHostObjectProtocolHandler::GetProtocolFlags(uint32_t *result)
 {
   *result = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_SUBSUMERS |
-            URI_IS_LOCAL_RESOURCE | URI_NON_PERSISTABLE;
+            URI_NON_PERSISTABLE;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsHostObjectProtocolHandler::GetFlagsForURI(nsIURI *aURI, uint32_t *aResult)
+{
+  Unused << nsHostObjectProtocolHandler::GetProtocolFlags(aResult);
+  if (IsFontTableURI(aURI) || IsBlobURI(aURI)) {
+    *aResult |= URI_IS_LOCAL_RESOURCE;
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsBlobProtocolHandler::GetProtocolFlags(uint32_t *result)
+{
+  Unused << nsHostObjectProtocolHandler::GetProtocolFlags(result);
+  *result |= URI_IS_LOCAL_RESOURCE;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHostObjectProtocolHandler::NewURI(const nsACString& aSpec,
                                     const char *aCharset,
                                     nsIURI *aBaseURI,
                                     nsIURI **aResult)
@@ -872,16 +892,24 @@ nsHostObjectProtocolHandler::AllowPort(i
 NS_IMETHODIMP
 nsBlobProtocolHandler::GetScheme(nsACString &result)
 {
   result.AssignLiteral(BLOBURI_SCHEME);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsFontTableProtocolHandler::GetProtocolFlags(uint32_t *result)
+{
+  Unused << nsHostObjectProtocolHandler::GetProtocolFlags(result);
+  *result |= URI_IS_LOCAL_RESOURCE;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsFontTableProtocolHandler::GetScheme(nsACString &result)
 {
   result.AssignLiteral(FONTTABLEURI_SCHEME);
   return NS_OK;
 }
 
 nsresult
 NS_GetBlobForBlobURI(nsIURI* aURI, BlobImpl** aBlob)
--- a/dom/file/nsHostObjectProtocolHandler.h
+++ b/dom/file/nsHostObjectProtocolHandler.h
@@ -27,30 +27,34 @@ namespace dom {
 class BlobImpl;
 class BlobURLRegistrationData;
 class ContentParent;
 class MediaSource;
 } // namespace dom
 } // namespace mozilla
 
 class nsHostObjectProtocolHandler : public nsIProtocolHandler
+                                  , public nsIProtocolHandlerWithDynamicFlags
 {
 public:
   nsHostObjectProtocolHandler();
   NS_DECL_ISUPPORTS
 
   // nsIProtocolHandler methods, except for GetScheme which is only defined
   // in subclasses.
   NS_IMETHOD GetDefaultPort(int32_t *aDefaultPort) override;
   NS_IMETHOD GetProtocolFlags(uint32_t *aProtocolFlags) override;
   NS_IMETHOD NewURI(const nsACString & aSpec, const char * aOriginCharset, nsIURI *aBaseURI, nsIURI * *_retval) override;
   NS_IMETHOD NewChannel2(nsIURI *aURI, nsILoadInfo *aLoadinfo, nsIChannel * *_retval) override;
   NS_IMETHOD NewChannel(nsIURI *aURI, nsIChannel * *_retval) override;
   NS_IMETHOD AllowPort(int32_t port, const char * scheme, bool *_retval) override;
 
+  // nsIProtocolHandlerWithDynamicFlags methods
+  NS_IMETHOD GetFlagsForURI(nsIURI *aURI, uint32_t *aResult) override;
+
   // If principal is not null, its origin will be used to generate the URI.
   static nsresult GenerateURIString(const nsACString &aScheme,
                                     nsIPrincipal* aPrincipal,
                                     nsACString &aUri);
   static nsresult GenerateURIStringForBlobURL(nsIPrincipal* aPrincipal,
                                               nsACString &aUri);
 
   // Methods for managing uri->object mapping
@@ -89,24 +93,29 @@ protected:
 
 private:
   static void Init();
 };
 
 class nsBlobProtocolHandler : public nsHostObjectProtocolHandler
 {
 public:
+  NS_IMETHOD GetProtocolFlags(uint32_t *aProtocolFlags) override;
   NS_IMETHOD GetScheme(nsACString &result) override;
 };
 
 class nsFontTableProtocolHandler : public nsHostObjectProtocolHandler
 {
 public:
-  NS_IMETHOD GetScheme(nsACString &result);
-  NS_IMETHOD NewURI(const nsACString & aSpec, const char * aOriginCharset, nsIURI *aBaseURI, nsIURI * *_retval);
+  NS_IMETHOD GetProtocolFlags(uint32_t *aProtocolFlags) override;
+  NS_IMETHOD GetScheme(nsACString &result) override;
+  NS_IMETHOD NewURI(const nsACString & aSpec,
+                    const char *aOriginCharset,
+                    nsIURI *aBaseURI,
+                    nsIURI **_retval) override;
 };
 
 bool IsBlobURI(nsIURI* aUri);
 bool IsMediaStreamURI(nsIURI* aUri);
 bool IsMediaSourceURI(nsIURI* aUri);
 
 inline bool IsRtspURI(nsIURI* aUri)
 {
new file mode 100644
--- /dev/null
+++ b/dom/file/tests/test_bloburi.js
@@ -0,0 +1,33 @@
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cr = Components.results;
+
+var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+
+var uris = [
+  {
+    uri: "blob:https://example.com/230d5d50-35f9-9745-a64a-15e47b731a81",
+    local: true,
+  },
+  {
+    uri: "rstp://1.2.3.4/some_path?param=a",
+    local: false,
+  },
+  {
+    uri: "moz-fonttable://something",
+    local: true,
+  }
+];
+
+function run_test()
+{
+  for (let i = 0; i < uris.length; i++) {
+    let uri = ios.newURI(uris[i].uri);
+    let handler = ios.getProtocolHandler(uri.scheme).QueryInterface(Ci.nsIProtocolHandler);
+    let flags = handler.protocolFlags;
+    
+    do_check_eq(Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE & flags,
+                (uris[i].local) ? Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE : 0);
+  }
+}
+
new file mode 100644
--- /dev/null
+++ b/dom/file/tests/xpcshell.ini
@@ -0,0 +1,3 @@
+[DEFAULT]
+
+[test_bloburi.js]