Bug 1525208 - Part 1: Devirtualize the calls to ThirdPartyUtil in nsContentUtils::IsThirdPartyWindowOrChannel(); r=baku

Differential Revision: https://phabricator.services.mozilla.com/D18643

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2019-02-05 18:11:44 +00:00
parent d30333735e
commit 70c4bbbed8
3 changed files with 34 additions and 3 deletions

View File

@ -16,7 +16,9 @@
#include "nsIScriptObjectPrincipal.h"
#include "nsIURI.h"
#include "nsThreadUtils.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Logging.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/Unused.h"
#include "nsPIDOMWindow.h"
@ -29,15 +31,42 @@ static mozilla::LazyLogModule gThirdPartyLog("thirdPartyUtil");
#undef LOG
#define LOG(args) MOZ_LOG(gThirdPartyLog, mozilla::LogLevel::Debug, args)
static mozilla::StaticRefPtr<ThirdPartyUtil> gService;
nsresult ThirdPartyUtil::Init() {
NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_AVAILABLE);
MOZ_ASSERT(!gService);
gService = this;
mozilla::ClearOnShutdown(&gService);
nsresult rv;
mTLDService = do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID, &rv);
return rv;
}
ThirdPartyUtil::~ThirdPartyUtil() {
MOZ_ASSERT(gService == this);
gService = nullptr;
}
// static
ThirdPartyUtil* ThirdPartyUtil::GetInstance() {
if (gService) {
return gService;
}
nsCOMPtr<mozIThirdPartyUtil> tpuService =
mozilla::services::GetThirdPartyUtil();
if (!tpuService) {
return nullptr;
}
MOZ_ASSERT(
gService,
"gService must have been initialized in nsEffectiveTLDService::Init");
return gService;
}
// Determine if aFirstDomain is a different base domain to aSecondURI; or, if
// the concept of base domain does not apply, determine if the two hosts are not
// string-identical.

View File

@ -22,8 +22,10 @@ class ThirdPartyUtil final : public mozIThirdPartyUtil {
nsresult Init();
static ThirdPartyUtil* GetInstance();
private:
~ThirdPartyUtil() {}
~ThirdPartyUtil();
nsresult IsThirdPartyInternal(const nsCString& aFirstDomain,
nsIURI* aSecondURI, bool* aResult);

View File

@ -224,7 +224,7 @@
#include "nsContentTypeParser.h"
#include "nsICookiePermission.h"
#include "nsICookieService.h"
#include "mozIThirdPartyUtil.h"
#include "ThirdPartyUtil.h"
#include "mozilla/EnumSet.h"
#include "mozilla/BloomFilter.h"
#include "TabChild.h"
@ -8204,7 +8204,7 @@ bool nsContentUtils::IsThirdPartyWindowOrChannel(nsPIDOMWindowInner* aWindow,
MOZ_ASSERT(!aWindow || !aChannel,
"A window and channel should not both be provided.");
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil = services::GetThirdPartyUtil();
ThirdPartyUtil* thirdPartyUtil = ThirdPartyUtil::GetInstance();
if (!thirdPartyUtil) {
return false;
}