зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1278037 - Part 4: Modify the mozIGeckoMediaPluginChromeService.forgetThisSite() to take the originAttributes pattern as an argument. r=cpearce
--HG-- extra : rebase_source : c480a89fabd99a6ead348c172e68f524dbb2b458 extra : histedit_source : 145d639edff67799e33dd2c4592b4f5902b872e5
This commit is contained in:
Родитель
5277f5e7aa
Коммит
52370e14ba
|
@ -1553,19 +1553,38 @@ ExtractHostName(const nsACString& aOrigin, nsACString& aOutData)
|
|||
}
|
||||
|
||||
bool
|
||||
MatchOrigin(nsIFile* aPath, const nsACString& aSite)
|
||||
MatchOrigin(nsIFile* aPath,
|
||||
const nsACString& aSite,
|
||||
const mozilla::OriginAttributesPattern& aPattern)
|
||||
{
|
||||
// http://en.wikipedia.org/wiki/Domain_Name_System#Domain_name_syntax
|
||||
static const uint32_t MaxDomainLength = 253;
|
||||
|
||||
nsresult rv;
|
||||
nsCString str;
|
||||
nsCString originNoSuffix;
|
||||
mozilla::PrincipalOriginAttributes originAttributes;
|
||||
|
||||
rv = ReadFromFile(aPath, NS_LITERAL_CSTRING("origin"), str, MaxDomainLength);
|
||||
if (NS_SUCCEEDED(rv) && ExtractHostName(str, str) && str.Equals(aSite)) {
|
||||
if (!originAttributes.PopulateFromOrigin(str, originNoSuffix)) {
|
||||
// Fails on parsing the originAttributes, treat this as a non-match.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && ExtractHostName(originNoSuffix, str) && str.Equals(aSite) &&
|
||||
aPattern.Matches(originAttributes)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
mozilla::PrincipalOriginAttributes topLevelOriginAttributes;
|
||||
rv = ReadFromFile(aPath, NS_LITERAL_CSTRING("topLevelOrigin"), str, MaxDomainLength);
|
||||
if (NS_SUCCEEDED(rv) && ExtractHostName(str, str) && str.Equals(aSite)) {
|
||||
if (!topLevelOriginAttributes.PopulateFromOrigin(str, originNoSuffix)) {
|
||||
// Fails on paring the originAttributes, treat this as a non-match.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && ExtractHostName(originNoSuffix, str) && str.Equals(aSite) &&
|
||||
aPattern.Matches(topLevelOriginAttributes)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1701,19 +1720,25 @@ GeckoMediaPluginServiceParent::ClearNodeIdAndPlugin(nsIFile* aPluginStorageDir,
|
|||
}
|
||||
|
||||
void
|
||||
GeckoMediaPluginServiceParent::ForgetThisSiteOnGMPThread(const nsACString& aSite)
|
||||
GeckoMediaPluginServiceParent::ForgetThisSiteOnGMPThread(const nsACString& aSite,
|
||||
const mozilla::OriginAttributesPattern& aPattern)
|
||||
{
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == mGMPThread);
|
||||
LOGD(("%s::%s: origin=%s", __CLASS__, __FUNCTION__, aSite.Data()));
|
||||
|
||||
struct OriginFilter : public DirectoryFilter {
|
||||
explicit OriginFilter(const nsACString& aSite) : mSite(aSite) {}
|
||||
explicit OriginFilter(const nsACString& aSite,
|
||||
const mozilla::OriginAttributesPattern& aPattern)
|
||||
: mSite(aSite)
|
||||
, mPattern(aPattern)
|
||||
{ }
|
||||
bool operator()(nsIFile* aPath) override {
|
||||
return MatchOrigin(aPath, mSite);
|
||||
return MatchOrigin(aPath, mSite, mPattern);
|
||||
}
|
||||
private:
|
||||
const nsACString& mSite;
|
||||
} filter(aSite);
|
||||
const mozilla::OriginAttributesPattern& mPattern;
|
||||
} filter(aSite, aPattern);
|
||||
|
||||
ClearNodeIdAndPlugin(filter);
|
||||
}
|
||||
|
@ -1783,12 +1808,29 @@ GeckoMediaPluginServiceParent::ClearRecentHistoryOnGMPThread(PRTime aSince)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoMediaPluginServiceParent::ForgetThisSite(const nsAString& aSite)
|
||||
GeckoMediaPluginServiceParent::ForgetThisSite(const nsAString& aSite,
|
||||
const nsAString& aPattern)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return GMPDispatch(NewRunnableMethod<nsCString>(
|
||||
|
||||
mozilla::OriginAttributesPattern pattern;
|
||||
|
||||
if (!pattern.Init(aPattern)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return ForgetThisSiteNative(aSite, pattern);
|
||||
}
|
||||
|
||||
nsresult
|
||||
GeckoMediaPluginServiceParent::ForgetThisSiteNative(const nsAString& aSite,
|
||||
const mozilla::OriginAttributesPattern& aPattern)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
return GMPDispatch(NewRunnableMethod<nsCString, mozilla::OriginAttributesPattern>(
|
||||
this, &GeckoMediaPluginServiceParent::ForgetThisSiteOnGMPThread,
|
||||
NS_ConvertUTF16toUTF8(aSite)));
|
||||
NS_ConvertUTF16toUTF8(aSite), aPattern));
|
||||
}
|
||||
|
||||
static bool IsNodeIdValid(GMPParent* aParent) {
|
||||
|
|
|
@ -62,6 +62,8 @@ public:
|
|||
bool IsShuttingDown();
|
||||
|
||||
already_AddRefed<GMPStorage> GetMemoryStorageFor(const nsACString& aNodeId);
|
||||
nsresult ForgetThisSiteNative(const nsAString& aSite,
|
||||
const mozilla::OriginAttributesPattern& aPattern);
|
||||
|
||||
private:
|
||||
friend class GMPServiceParent;
|
||||
|
@ -103,7 +105,8 @@ private:
|
|||
void ClearNodeIdAndPlugin(DirectoryFilter& aFilter);
|
||||
void ClearNodeIdAndPlugin(nsIFile* aPluginStorageDir,
|
||||
DirectoryFilter& aFilter);
|
||||
void ForgetThisSiteOnGMPThread(const nsACString& aOrigin);
|
||||
void ForgetThisSiteOnGMPThread(const nsACString& aOrigin,
|
||||
const mozilla::OriginAttributesPattern& aPattern);
|
||||
void ClearRecentHistoryOnGMPThread(PRTime aSince);
|
||||
|
||||
already_AddRefed<GMPParent> GetById(uint32_t aPluginId);
|
||||
|
@ -217,7 +220,9 @@ private:
|
|||
};
|
||||
|
||||
nsresult ReadSalt(nsIFile* aPath, nsACString& aOutData);
|
||||
bool MatchOrigin(nsIFile* aPath, const nsACString& aSite);
|
||||
bool MatchOrigin(nsIFile* aPath,
|
||||
const nsACString& aSite,
|
||||
const mozilla::OriginAttributesPattern& aPattern);
|
||||
|
||||
class GMPServiceParent final : public PGMPServiceParent
|
||||
{
|
||||
|
|
|
@ -30,9 +30,11 @@ interface mozIGeckoMediaPluginChromeService : nsISupports
|
|||
[optional] in bool defer);
|
||||
|
||||
/**
|
||||
* Clears storage data associated with the site.
|
||||
* Clears storage data associated with the site and the originAttributes
|
||||
* pattern in JSON format.
|
||||
*/
|
||||
void forgetThisSite(in AString site);
|
||||
void forgetThisSite(in AString site,
|
||||
in DOMString aPattern);
|
||||
|
||||
/**
|
||||
* Returns true if the given node id is allowed to store things
|
||||
|
|
|
@ -740,8 +740,13 @@ class GMPStorageTest : public GMPDecryptorProxyCallback
|
|||
}
|
||||
|
||||
struct NodeInfo {
|
||||
explicit NodeInfo(const nsACString& aSite) : siteToForget(aSite) {}
|
||||
explicit NodeInfo(const nsACString& aSite,
|
||||
const mozilla::OriginAttributesPattern& aPattern)
|
||||
: siteToForget(aSite)
|
||||
, mPattern(aPattern)
|
||||
{ }
|
||||
nsCString siteToForget;
|
||||
mozilla::OriginAttributesPattern mPattern;
|
||||
nsTArray<nsCString> expectedRemainingNodeIds;
|
||||
};
|
||||
|
||||
|
@ -752,7 +757,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback
|
|||
nsCString salt;
|
||||
nsresult rv = ReadSalt(aFile, salt);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
if (!MatchOrigin(aFile, mNodeInfo->siteToForget)) {
|
||||
if (!MatchOrigin(aFile, mNodeInfo->siteToForget, mNodeInfo->mPattern)) {
|
||||
mNodeInfo->expectedRemainingNodeIds.AppendElement(salt);
|
||||
}
|
||||
}
|
||||
|
@ -761,8 +766,11 @@ class GMPStorageTest : public GMPDecryptorProxyCallback
|
|||
};
|
||||
|
||||
void TestForgetThisSite_CollectSiteInfo() {
|
||||
mozilla::OriginAttributesPattern pattern;
|
||||
|
||||
nsAutoPtr<NodeInfo> siteInfo(
|
||||
new NodeInfo(NS_LITERAL_CSTRING("http://example1.com")));
|
||||
new NodeInfo(NS_LITERAL_CSTRING("http://example1.com"),
|
||||
pattern));
|
||||
// Collect nodeIds that are expected to remain for later comparison.
|
||||
EnumerateGMPStorageDir(NS_LITERAL_CSTRING("id"), NodeIdCollector(siteInfo));
|
||||
// Invoke "Forget this site" on the main thread.
|
||||
|
@ -773,7 +781,8 @@ class GMPStorageTest : public GMPDecryptorProxyCallback
|
|||
void TestForgetThisSite_Forget(nsAutoPtr<NodeInfo> aSiteInfo) {
|
||||
RefPtr<GeckoMediaPluginServiceParent> service =
|
||||
GeckoMediaPluginServiceParent::GetSingleton();
|
||||
service->ForgetThisSite(NS_ConvertUTF8toUTF16(aSiteInfo->siteToForget));
|
||||
service->ForgetThisSiteNative(NS_ConvertUTF8toUTF16(aSiteInfo->siteToForget),
|
||||
aSiteInfo->mPattern);
|
||||
|
||||
nsCOMPtr<nsIThread> thread;
|
||||
service->GetThread(getter_AddRefs(thread));
|
||||
|
@ -797,7 +806,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback
|
|||
nsresult rv = ReadSalt(aFile, salt);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
// Shouldn't match the origin if we clear correctly.
|
||||
EXPECT_FALSE(MatchOrigin(aFile, mNodeInfo->siteToForget));
|
||||
EXPECT_FALSE(MatchOrigin(aFile, mNodeInfo->siteToForget, mNodeInfo->mPattern));
|
||||
// Check if remaining nodeIDs are as expected.
|
||||
EXPECT_TRUE(mExpectedRemainingNodeIds.RemoveElement(salt));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче