Commit 439b4f7d authored by Carlos Caballero's avatar Carlos Caballero Committed by Commit Bot

Handle null TabSpecificContentSettings in PageInfo

TabSpecificContentSettings is bound to the page (aka main frame) and
might be null at times this TabSpecificContentSettings clients should
be able to tolerate null instances.

Bug: 1096101
Change-Id: I6aa51f710a92cd883727525a2adf65b2588b5e98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2260617
Commit-Queue: Carlos Caballero <carlscab@google.com>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781813}
parent 71b54c14
......@@ -1138,38 +1138,52 @@ PageInfo::GetTabSpecificContentSettings() const {
}
bool PageInfo::HasContentSettingChangedViaPageInfo(ContentSettingsType type) {
return GetTabSpecificContentSettings()->HasContentSettingChangedViaPageInfo(
type);
}
auto* settings = GetTabSpecificContentSettings();
if (!settings)
return false;
void PageInfo::ContentSettingChangedViaPageInfo(ContentSettingsType type) {
GetTabSpecificContentSettings()->ContentSettingChangedViaPageInfo(type);
return settings->HasContentSettingChangedViaPageInfo(type);
}
const browsing_data::LocalSharedObjectsContainer& PageInfo::GetAllowedObjects(
const GURL& site_url) {
return GetTabSpecificContentSettings()->allowed_local_shared_objects();
}
void PageInfo::ContentSettingChangedViaPageInfo(ContentSettingsType type) {
auto* settings = GetTabSpecificContentSettings();
if (!settings)
return;
const browsing_data::LocalSharedObjectsContainer& PageInfo::GetBlockedObjects(
const GURL& site_url) {
return GetTabSpecificContentSettings()->blocked_local_shared_objects();
return settings->ContentSettingChangedViaPageInfo(type);
}
int PageInfo::GetFirstPartyAllowedCookiesCount(const GURL& site_url) {
return GetAllowedObjects(site_url).GetObjectCountForDomain(site_url);
auto* settings = GetTabSpecificContentSettings();
if (!settings)
return 0;
return settings->allowed_local_shared_objects().GetObjectCountForDomain(
site_url);
}
int PageInfo::GetFirstPartyBlockedCookiesCount(const GURL& site_url) {
return GetBlockedObjects(site_url).GetObjectCountForDomain(site_url);
auto* settings = GetTabSpecificContentSettings();
if (!settings)
return 0;
return settings->blocked_local_shared_objects().GetObjectCountForDomain(
site_url);
}
int PageInfo::GetThirdPartyAllowedCookiesCount(const GURL& site_url) {
return GetAllowedObjects(site_url).GetObjectCount() -
auto* settings = GetTabSpecificContentSettings();
if (!settings)
return 0;
return settings->allowed_local_shared_objects().GetObjectCount() -
GetFirstPartyAllowedCookiesCount(site_url);
}
int PageInfo::GetThirdPartyBlockedCookiesCount(const GURL& site_url) {
return GetBlockedObjects(site_url).GetObjectCount() -
auto* settings = GetTabSpecificContentSettings();
if (!settings)
return 0;
return settings->blocked_local_shared_objects().GetObjectCount() -
GetFirstPartyBlockedCookiesCount(site_url);
}
......@@ -260,8 +260,8 @@ class PageInfo : public content::WebContentsObserver {
// Exposed for testing.
static std::vector<ContentSettingsType> GetAllPermissionsForTesting();
// Creates if necessary, and returns TabSpecificContentSettings
// for the observed WebContents.
// Returns TabSpecificContentSettings for the observed WebContents if present,
// nullptr otherwise.
content_settings::TabSpecificContentSettings* GetTabSpecificContentSettings()
const;
......@@ -272,13 +272,6 @@ class PageInfo : public content::WebContentsObserver {
// via Page Info UI.
void ContentSettingChangedViaPageInfo(ContentSettingsType type);
// Get allowed and blocked shared objects like cookies, local storage, etc for
// |site_url|.
const browsing_data::LocalSharedObjectsContainer& GetAllowedObjects(
const GURL& site_url);
const browsing_data::LocalSharedObjectsContainer& GetBlockedObjects(
const GURL& site_url);
// Get counts of allowed and blocked cookies.
int GetFirstPartyAllowedCookiesCount(const GURL& site_url);
int GetFirstPartyBlockedCookiesCount(const GURL& site_url);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment