From 048e54ab0d4da1ca77a26fb3a7c04e36c863b742 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Mon, 6 Apr 2015 07:41:53 +0800 Subject: [PATCH] Bug 1150277 - Match hostname when removing GMP data. r=cpearce --- dom/media/gmp/GMPServiceParent.cpp | 44 ++++++++++++++----- dom/media/gmp/GMPServiceParent.h | 2 +- .../gmp/mozIGeckoMediaPluginChromeService.idl | 6 +-- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/dom/media/gmp/GMPServiceParent.cpp b/dom/media/gmp/GMPServiceParent.cpp index bd9cb25145e..be9dddeb45e 100644 --- a/dom/media/gmp/GMPServiceParent.cpp +++ b/dom/media/gmp/GMPServiceParent.cpp @@ -1023,8 +1023,30 @@ GeckoMediaPluginServiceParent::GetNodeId(const nsAString& aOrigin, 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; @@ -1032,11 +1054,11 @@ MatchOrigin(nsIFile* aPath, const nsACString& aOrigin) 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; @@ -1191,19 +1213,19 @@ GeckoMediaPluginServiceParent::ClearNodeIdAndPlugin(DirectoryFilter& aFilter) } 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); } @@ -1296,12 +1318,12 @@ GeckoMediaPluginServiceParent::ClearRecentHistoryOnGMPThread(PRTime aSince) } NS_IMETHODIMP -GeckoMediaPluginServiceParent::ForgetThisSite(const nsAString& aOrigin) +GeckoMediaPluginServiceParent::ForgetThisSite(const nsAString& aSite) { MOZ_ASSERT(NS_IsMainThread()); return GMPDispatch(NS_NewRunnableMethodWithArg( this, &GeckoMediaPluginServiceParent::ForgetThisSiteOnGMPThread, - NS_ConvertUTF16toUTF8(aOrigin))); + NS_ConvertUTF16toUTF8(aSite))); } static bool IsNodeIdValid(GMPParent* aParent) { diff --git a/dom/media/gmp/GMPServiceParent.h b/dom/media/gmp/GMPServiceParent.h index a3fcc09d09a..3288d7eee90 100644 --- a/dom/media/gmp/GMPServiceParent.h +++ b/dom/media/gmp/GMPServiceParent.h @@ -170,7 +170,7 @@ private: }; 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 { diff --git a/dom/media/gmp/mozIGeckoMediaPluginChromeService.idl b/dom/media/gmp/mozIGeckoMediaPluginChromeService.idl index 915c61b48c1..ed114119bbc 100644 --- a/dom/media/gmp/mozIGeckoMediaPluginChromeService.idl +++ b/dom/media/gmp/mozIGeckoMediaPluginChromeService.idl @@ -6,7 +6,7 @@ #include "nsISupports.idl" #include "nsIFile.idl" -[scriptable, uuid(5878366c-73f6-486e-ad2f-9aca602864e4)] +[scriptable, uuid(4d50f2df-736d-41b8-9292-9067f6bcd892)] interface mozIGeckoMediaPluginChromeService : nsISupports { /** @@ -28,9 +28,9 @@ interface mozIGeckoMediaPluginChromeService : nsISupports 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