Bug 1150277 - Match hostname when removing GMP data. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Mon, 06 Apr 2015 07:41:53 +0800
changeset 267610 2ceecfb46d8cda567cf0941fe6d3f5674ac82764
parent 267609 48efa200aae98f4b5fced4f1afa4f1b8c8cde9e1
child 267611 574170b78a17d8e6ebd0c53d1d4521b2fa962a33
push id4830
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:18:48 +0000
treeherdermozilla-beta@4c2175bb0420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1150277
milestone40.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 1150277 - Match hostname when removing GMP data. r=cpearce
dom/media/gmp/GMPServiceParent.cpp
dom/media/gmp/GMPServiceParent.h
dom/media/gmp/mozIGeckoMediaPluginChromeService.idl
--- a/dom/media/gmp/GMPServiceParent.cpp
+++ b/dom/media/gmp/GMPServiceParent.cpp
@@ -1018,30 +1018,52 @@ GeckoMediaPluginServiceParent::GetNodeId
                                          UniquePtr<GetNodeIdCallback>&& aCallback)
 {
   nsCString nodeId;
   nsresult rv = GetNodeId(aOrigin, aTopLevelOrigin, aInPrivateBrowsing, nodeId);
   aCallback->Done(rv, nodeId);
   return rv;
 }
 
+static bool
+ExtractHostName(const nsACString& aOrigin, nsACString& aOutData)
+{
+  nsCString str;
+  str.Assign(aOrigin);
+  int begin = str.Find("://");
+  // The scheme is missing!
+  if (begin == -1) {
+    return false;
+  }
+
+  int end = str.RFind(":");
+  // Remove the port number
+  if (end != begin) {
+    str.SetLength(end);
+  }
+
+  nsDependentCSubstring host(str, begin + 3);
+  aOutData.Assign(host);
+  return true;
+}
+
 bool
-MatchOrigin(nsIFile* aPath, const nsACString& aOrigin)
+MatchOrigin(nsIFile* aPath, const nsACString& aSite)
 {
   // http://en.wikipedia.org/wiki/Domain_Name_System#Domain_name_syntax
   static const uint32_t MaxDomainLength = 253;
 
   nsresult rv;
   nsCString str;
   rv = ReadFromFile(aPath, NS_LITERAL_CSTRING("origin"), str, MaxDomainLength);
-  if (NS_SUCCEEDED(rv) && aOrigin.Equals(str)) {
+  if (NS_SUCCEEDED(rv) && ExtractHostName(str, str) && str.Equals(aSite)) {
     return true;
   }
   rv = ReadFromFile(aPath, NS_LITERAL_CSTRING("topLevelOrigin"), str, MaxDomainLength);
-  if (NS_SUCCEEDED(rv) && aOrigin.Equals(str)) {
+  if (NS_SUCCEEDED(rv) && ExtractHostName(str, str) && str.Equals(aSite)) {
     return true;
   }
   return false;
 }
 
 template<typename T> static void
 KillPlugins(const nsTArray<nsRefPtr<GMPParent>>& aPlugins,
             Mutex& aMutex, T&& aFilter)
@@ -1186,29 +1208,29 @@ GeckoMediaPluginServiceParent::ClearNode
 
     if (NS_FAILED(DeleteDir(dirEntry))) {
       NS_WARNING("Failed to delete GMP storage directory for the node");
     }
   }
 }
 
 void
-GeckoMediaPluginServiceParent::ForgetThisSiteOnGMPThread(const nsACString& aOrigin)
+GeckoMediaPluginServiceParent::ForgetThisSiteOnGMPThread(const nsACString& aSite)
 {
   MOZ_ASSERT(NS_GetCurrentThread() == mGMPThread);
-  LOGD(("%s::%s: origin=%s", __CLASS__, __FUNCTION__, aOrigin.Data()));
+  LOGD(("%s::%s: origin=%s", __CLASS__, __FUNCTION__, aSite.Data()));
 
   struct OriginFilter : public DirectoryFilter {
-    explicit OriginFilter(const nsACString& aOrigin) : mOrigin(aOrigin) {}
+    explicit OriginFilter(const nsACString& aSite) : mSite(aSite) {}
     virtual bool operator()(nsIFile* aPath) {
-      return MatchOrigin(aPath, mOrigin);
+      return MatchOrigin(aPath, mSite);
     }
   private:
-    const nsACString& mOrigin;
-  } filter(aOrigin);
+    const nsACString& mSite;
+  } filter(aSite);
 
   ClearNodeIdAndPlugin(filter);
 }
 
 void
 GeckoMediaPluginServiceParent::ClearRecentHistoryOnGMPThread(PRTime aSince)
 {
   MOZ_ASSERT(NS_GetCurrentThread() == mGMPThread);
@@ -1291,22 +1313,22 @@ GeckoMediaPluginServiceParent::ClearRece
   } filter(aSince, storagePath.forget());
 
   ClearNodeIdAndPlugin(filter);
 
   NS_DispatchToMainThread(new NotifyObserversTask("gmp-clear-storage-complete"), NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
-GeckoMediaPluginServiceParent::ForgetThisSite(const nsAString& aOrigin)
+GeckoMediaPluginServiceParent::ForgetThisSite(const nsAString& aSite)
 {
   MOZ_ASSERT(NS_IsMainThread());
   return GMPDispatch(NS_NewRunnableMethodWithArg<nsCString>(
       this, &GeckoMediaPluginServiceParent::ForgetThisSiteOnGMPThread,
-      NS_ConvertUTF16toUTF8(aOrigin)));
+      NS_ConvertUTF16toUTF8(aSite)));
 }
 
 static bool IsNodeIdValid(GMPParent* aParent) {
   return !aParent->GetNodeId().IsEmpty();
 }
 
 void
 GeckoMediaPluginServiceParent::ClearStorage()
--- a/dom/media/gmp/GMPServiceParent.h
+++ b/dom/media/gmp/GMPServiceParent.h
@@ -165,17 +165,17 @@ private:
   nsClassHashtable<nsUint32HashKey, nsCString> mTempNodeIds;
 
   // Hashes node id to whether that node id is allowed to store data
   // persistently on disk.
   nsDataHashtable<nsCStringHashKey, bool> mPersistentStorageAllowed;
 };
 
 nsresult ReadSalt(nsIFile* aPath, nsACString& aOutData);
-bool MatchOrigin(nsIFile* aPath, const nsACString& aOrigin);
+bool MatchOrigin(nsIFile* aPath, const nsACString& aSite);
 
 class GMPServiceParent final : public PGMPServiceParent
 {
 public:
   explicit GMPServiceParent(GeckoMediaPluginServiceParent* aService)
     : mService(aService)
   {
   }
--- a/dom/media/gmp/mozIGeckoMediaPluginChromeService.idl
+++ b/dom/media/gmp/mozIGeckoMediaPluginChromeService.idl
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 #include "nsIFile.idl"
 
-[scriptable, uuid(5878366c-73f6-486e-ad2f-9aca602864e4)]
+[scriptable, uuid(4d50f2df-736d-41b8-9292-9067f6bcd892)]
 interface mozIGeckoMediaPluginChromeService : nsISupports
 {
   /**
    * Add a directory to scan for gecko media plugins.
    * @note Main-thread API.
    */
   void addPluginDirectory(in AString directory);
 
@@ -23,19 +23,19 @@ interface mozIGeckoMediaPluginChromeServ
 
   /**
    * Remove a directory for gecko media plugins and delete it from disk.
    * @note Main-thread API.
    */
   void removeAndDeletePluginDirectory(in AString directory);
 
   /**
-   * Clears storage data associated with the origin.
+   * Clears storage data associated with the site.
    */
-  void forgetThisSite(in AString origin);
+  void forgetThisSite(in AString site);
 
   /**
    * Returns true if the given node id is allowed to store things
    * persistently on disk. Private Browsing and local content are not
    * allowed to store persistent data.
    */
   bool isPersistentStorageAllowed(in ACString nodeId);