Bug 920877 - Remove fragment identifier in nsHostObjectProtocolHandler before matching the URI. r=khuey
authorPhoebe Chang <phchang@mozilla.com>
Thu, 17 Oct 2013 14:37:57 -0400
changeset 165917 ae8714cdf381c196880974e7cd98e241ec9f280e
parent 165916 ae664f27e66337dd3d878289e32d32e14a1c92eb
child 165918 112e8748b75ced35fc9963f235b41ced4fa1cff0
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs920877
milestone27.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 920877 - Remove fragment identifier in nsHostObjectProtocolHandler before matching the URI. r=khuey
content/base/src/nsHostObjectProtocolHandler.cpp
--- a/content/base/src/nsHostObjectProtocolHandler.cpp
+++ b/content/base/src/nsHostObjectProtocolHandler.cpp
@@ -44,17 +44,25 @@ nsHostObjectProtocolHandler::AddDataEntr
   gDataTable->Put(aUri, info);
   return NS_OK;
 }
 
 void
 nsHostObjectProtocolHandler::RemoveDataEntry(const nsACString& aUri)
 {
   if (gDataTable) {
-    gDataTable->Remove(aUri);
+    nsCString uriIgnoringRef;
+    int32_t hashPos = aUri.FindChar('#');
+    if (hashPos < 0) {
+      uriIgnoringRef = aUri;
+    }
+    else {
+      uriIgnoringRef = StringHead(aUri, hashPos);
+    }
+    gDataTable->Remove(uriIgnoringRef);
     if (gDataTable->Count() == 0) {
       delete gDataTable;
       gDataTable = nullptr;
     }
   }
 }
 
 nsresult
@@ -75,25 +83,46 @@ nsHostObjectProtocolHandler::GenerateURI
 
   aUri += aScheme;
   aUri += NS_LITERAL_CSTRING(":");
   aUri += Substring(chars + 1, chars + NSID_LENGTH - 2);
 
   return NS_OK;
 }
 
+static DataInfo*
+GetDataInfo(const nsACString& aUri)
+{
+  if (!gDataTable) {
+    return nullptr;
+  }
+
+  DataInfo* res;
+  nsCString uriIgnoringRef;
+  int32_t hashPos = aUri.FindChar('#');
+  if (hashPos < 0) {
+    uriIgnoringRef = aUri;
+  }
+  else {
+    uriIgnoringRef = StringHead(aUri, hashPos);
+  }
+  gDataTable->Get(uriIgnoringRef, &res);
+  
+  return res;
+}
+
 nsIPrincipal*
 nsHostObjectProtocolHandler::GetDataEntryPrincipal(const nsACString& aUri)
 {
   if (!gDataTable) {
     return nullptr;
   }
 
-  DataInfo* res;
-  gDataTable->Get(aUri, &res);
+  DataInfo* res = GetDataInfo(aUri);
+
   if (!res) {
     return nullptr;
   }
 
   return res->mPrincipal;
 }
 
 void
@@ -109,28 +138,16 @@ nsHostObjectProtocolHandler::Traverse(co
   if (!res) {
     return;
   }
 
   NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCallback, "HostObjectProtocolHandler DataInfo.mObject");
   aCallback.NoteXPCOMChild(res->mObject);
 }
 
-static DataInfo*
-GetDataInfo(const nsACString& aUri)
-{
-  if (!gDataTable) {
-    return nullptr;
-  }
-
-  DataInfo* res;
-  gDataTable->Get(aUri, &res);
-  return res;
-}
-
 static nsISupports*
 GetDataObject(nsIURI* aURI)
 {
   nsCString spec;
   aURI->GetSpec(spec);
 
   DataInfo* info = GetDataInfo(spec);
   return info ? info->mObject : nullptr;