Commit 4cf113ad authored by Charlie Harrison's avatar Charlie Harrison Committed by Commit Bot

Remove "BlockageIndicated" from TabSpecificContentSettings

Image models are not 1:1 with content settings. This CL replaces
per-tab storage from TSCS to a new per-WebContents container,
ContentSettingImageModelState, which contains information that
is 1:1 with image models.

This allows us to remove custom logic for image models that aren't
backed by a single content setting.

The new behavior works like this:
 1. Per-tab state is stored in ContentSettingImageModelState
 2. ShouldRunAnimation / SetAnimationHasRun updates the state
 3. State is additionally updated when an image is hidden

(3) entails a bunch of changes to UpdateFromWebContents, namely,
making it return a boolean for whether the update triggered visibility.

The benefit of this CL is that all of the logic to control animation of
image models come from ContentSettingImageModel.

This CL has no intended user-facing behavior change.

Bug: 900645
Change-Id: I99c36a8184a0e04e6356e58fbc93a5aed3f03127
Reviewed-on: https://chromium-review.googlesource.com/c/1310674Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Commit-Queue: Charlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607331}
parent 792bd337
...@@ -282,19 +282,6 @@ bool TabSpecificContentSettings::IsContentBlocked( ...@@ -282,19 +282,6 @@ bool TabSpecificContentSettings::IsContentBlocked(
return false; return false;
} }
bool TabSpecificContentSettings::IsBlockageIndicated(
ContentSettingsType content_type) const {
const auto& it = content_settings_status_.find(content_type);
if (it != content_settings_status_.end())
return it->second.blockage_indicated_to_user;
return false;
}
void TabSpecificContentSettings::SetBlockageHasBeenIndicated(
ContentSettingsType content_type) {
content_settings_status_[content_type].blockage_indicated_to_user = true;
}
bool TabSpecificContentSettings::IsContentAllowed( bool TabSpecificContentSettings::IsContentAllowed(
ContentSettingsType content_type) const { ContentSettingsType content_type) const {
DCHECK_NE(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, content_type) DCHECK_NE(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, content_type)
...@@ -666,7 +653,6 @@ ClearContentSettingsExceptForNavigationRelatedSettings() { ...@@ -666,7 +653,6 @@ ClearContentSettingsExceptForNavigationRelatedSettings() {
status.first == CONTENT_SETTINGS_TYPE_JAVASCRIPT) status.first == CONTENT_SETTINGS_TYPE_JAVASCRIPT)
continue; continue;
status.second.blocked = false; status.second.blocked = false;
status.second.blockage_indicated_to_user = false;
status.second.allowed = false; status.second.allowed = false;
} }
microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED; microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED;
...@@ -685,7 +671,6 @@ void TabSpecificContentSettings::ClearNavigationRelatedContentSettings() { ...@@ -685,7 +671,6 @@ void TabSpecificContentSettings::ClearNavigationRelatedContentSettings() {
ContentSettingsStatus& status = ContentSettingsStatus& status =
content_settings_status_[type]; content_settings_status_[type];
status.blocked = false; status.blocked = false;
status.blockage_indicated_to_user = false;
status.allowed = false; status.allowed = false;
} }
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
...@@ -699,11 +684,10 @@ void TabSpecificContentSettings::FlashDownloadBlocked() { ...@@ -699,11 +684,10 @@ void TabSpecificContentSettings::FlashDownloadBlocked() {
base::UTF8ToUTF16(content::kFlashPluginName)); base::UTF8ToUTF16(content::kFlashPluginName));
} }
void TabSpecificContentSettings::SetPopupsBlocked(bool blocked) { void TabSpecificContentSettings::ClearPopupsBlocked() {
ContentSettingsStatus& status = ContentSettingsStatus& status =
content_settings_status_[CONTENT_SETTINGS_TYPE_POPUPS]; content_settings_status_[CONTENT_SETTINGS_TYPE_POPUPS];
status.blocked = blocked; status.blocked = false;
status.blockage_indicated_to_user = false;
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
content::Source<WebContents>(web_contents()), content::Source<WebContents>(web_contents()),
......
...@@ -192,7 +192,7 @@ class TabSpecificContentSettings ...@@ -192,7 +192,7 @@ class TabSpecificContentSettings
void FlashDownloadBlocked(); void FlashDownloadBlocked();
// Changes the |content_blocked_| entry for popups. // Changes the |content_blocked_| entry for popups.
void SetPopupsBlocked(bool blocked); void ClearPopupsBlocked();
// Called when audio has been blocked on the page. // Called when audio has been blocked on the page.
void OnAudioBlocked(); void OnAudioBlocked();
...@@ -201,11 +201,6 @@ class TabSpecificContentSettings ...@@ -201,11 +201,6 @@ class TabSpecificContentSettings
// page. // page.
bool IsContentBlocked(ContentSettingsType content_type) const; bool IsContentBlocked(ContentSettingsType content_type) const;
// Returns true if content blockage was indicated to the user.
bool IsBlockageIndicated(ContentSettingsType content_type) const;
void SetBlockageHasBeenIndicated(ContentSettingsType content_type);
// Returns whether a particular kind of content has been allowed. Currently // Returns whether a particular kind of content has been allowed. Currently
// only tracks cookies. // only tracks cookies.
bool IsContentAllowed(ContentSettingsType content_type) const; bool IsContentAllowed(ContentSettingsType content_type) const;
...@@ -429,7 +424,6 @@ class TabSpecificContentSettings ...@@ -429,7 +424,6 @@ class TabSpecificContentSettings
struct ContentSettingsStatus { struct ContentSettingsStatus {
bool blocked; bool blocked;
bool blockage_indicated_to_user;
bool allowed; bool allowed;
}; };
// Stores which content setting types actually have blocked content. // Stores which content setting types actually have blocked content.
......
...@@ -80,7 +80,7 @@ TEST_F(TabSpecificContentSettingsTest, BlockedContent) { ...@@ -80,7 +80,7 @@ TEST_F(TabSpecificContentSettingsTest, BlockedContent) {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES);
#endif #endif
content_settings->SetPopupsBlocked(true); content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS);
TabSpecificContentSettings::MicrophoneCameraState TabSpecificContentSettings::MicrophoneCameraState
blocked_microphone_camera_state = blocked_microphone_camera_state =
TabSpecificContentSettings::MICROPHONE_ACCESSED | TabSpecificContentSettings::MICROPHONE_ACCESSED |
......
...@@ -824,6 +824,8 @@ jumbo_split_static_library("ui") { ...@@ -824,6 +824,8 @@ jumbo_split_static_library("ui") {
"content_settings/content_setting_bubble_model_delegate.h", "content_settings/content_setting_bubble_model_delegate.h",
"content_settings/content_setting_image_model.cc", "content_settings/content_setting_image_model.cc",
"content_settings/content_setting_image_model.h", "content_settings/content_setting_image_model.h",
"content_settings/content_setting_image_model_states.cc",
"content_settings/content_setting_image_model_states.h",
"exclusive_access/exclusive_access_bubble.cc", "exclusive_access/exclusive_access_bubble.cc",
"exclusive_access/exclusive_access_bubble.h", "exclusive_access/exclusive_access_bubble.h",
"exclusive_access/exclusive_access_bubble_hide_callback.h", "exclusive_access/exclusive_access_bubble_hide_callback.h",
......
...@@ -70,7 +70,6 @@ void FramebustBlockTabHelper::DidFinishNavigation( ...@@ -70,7 +70,6 @@ void FramebustBlockTabHelper::DidFinishNavigation(
} }
blocked_urls_.clear(); blocked_urls_.clear();
callbacks_.clear(); callbacks_.clear();
animation_has_run_ = false;
UpdateLocationBarUI(web_contents()); UpdateLocationBarUI(web_contents());
} }
...@@ -58,10 +58,6 @@ class FramebustBlockTabHelper ...@@ -58,10 +58,6 @@ class FramebustBlockTabHelper
// Returns all of the currently blocked URLs. // Returns all of the currently blocked URLs.
const std::vector<GURL>& blocked_urls() const { return blocked_urls_; } const std::vector<GURL>& blocked_urls() const { return blocked_urls_; }
// Remembers if the animation has run.
void set_animation_has_run() { animation_has_run_ = true; }
bool animation_has_run() const { return animation_has_run_; }
private: private:
friend class content::WebContentsUserData<FramebustBlockTabHelper>; friend class content::WebContentsUserData<FramebustBlockTabHelper>;
...@@ -79,9 +75,6 @@ class FramebustBlockTabHelper ...@@ -79,9 +75,6 @@ class FramebustBlockTabHelper
// distribution of the URLs in blocked_urls(). // distribution of the URLs in blocked_urls().
std::vector<ClickCallback> callbacks_; std::vector<ClickCallback> callbacks_;
// Remembers if the animation has run.
bool animation_has_run_ = false;
base::ObserverList<Observer>::Unchecked observers_; base::ObserverList<Observer>::Unchecked observers_;
DISALLOW_COPY_AND_ASSIGN(FramebustBlockTabHelper); DISALLOW_COPY_AND_ASSIGN(FramebustBlockTabHelper);
......
...@@ -76,15 +76,14 @@ void PopupBlockerTabHelper::DidFinishNavigation( ...@@ -76,15 +76,14 @@ void PopupBlockerTabHelper::DidFinishNavigation(
// Close blocked popups. // Close blocked popups.
if (!blocked_popups_.empty()) { if (!blocked_popups_.empty()) {
blocked_popups_.clear(); blocked_popups_.clear();
PopupNotificationVisibilityChanged(false); HidePopupNotification();
} }
} }
void PopupBlockerTabHelper::PopupNotificationVisibilityChanged( void PopupBlockerTabHelper::HidePopupNotification() {
bool visible) {
if (!web_contents()->IsBeingDestroyed()) { if (!web_contents()->IsBeingDestroyed()) {
TabSpecificContentSettings::FromWebContents(web_contents())-> TabSpecificContentSettings::FromWebContents(web_contents())
SetPopupsBlocked(visible); ->ClearPopupsBlocked();
} }
} }
...@@ -165,7 +164,7 @@ void PopupBlockerTabHelper::ShowBlockedPopup( ...@@ -165,7 +164,7 @@ void PopupBlockerTabHelper::ShowBlockedPopup(
blocked_popups_.erase(id); blocked_popups_.erase(id);
if (blocked_popups_.empty()) if (blocked_popups_.empty())
PopupNotificationVisibilityChanged(false); HidePopupNotification();
} }
size_t PopupBlockerTabHelper::GetBlockedPopupsCount() const { size_t PopupBlockerTabHelper::GetBlockedPopupsCount() const {
......
...@@ -93,8 +93,8 @@ class PopupBlockerTabHelper ...@@ -93,8 +93,8 @@ class PopupBlockerTabHelper
explicit PopupBlockerTabHelper(content::WebContents* web_contents); explicit PopupBlockerTabHelper(content::WebContents* web_contents);
// Called when the blocked popup notification is shown or hidden. // Called when the blocked popup notification is hidden.
void PopupNotificationVisibilityChanged(bool visible); void HidePopupNotification();
// Note, this container should be sorted based on the position in the popup // Note, this container should be sorted based on the position in the popup
// list, so it is keyed by an id which is continually increased. // list, so it is keyed by an id which is continually increased.
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h" #include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model_states.h"
#include "chrome/browser/ui/layout_constants.h" #include "chrome/browser/ui/layout_constants.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
...@@ -56,7 +57,7 @@ class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel { ...@@ -56,7 +57,7 @@ class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel {
ContentSettingBlockedImageModel(ImageType image_type, ContentSettingBlockedImageModel(ImageType image_type,
ContentSettingsType content_type); ContentSettingsType content_type);
void UpdateFromWebContents(WebContents* web_contents) override; bool UpdateAndGetVisibility(WebContents* web_contents) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingBlockedImageModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingBlockedImageModel);
...@@ -67,7 +68,7 @@ class ContentSettingGeolocationImageModel ...@@ -67,7 +68,7 @@ class ContentSettingGeolocationImageModel
public: public:
ContentSettingGeolocationImageModel(); ContentSettingGeolocationImageModel();
void UpdateFromWebContents(WebContents* web_contents) override; bool UpdateAndGetVisibility(WebContents* web_contents) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingGeolocationImageModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingGeolocationImageModel);
...@@ -77,7 +78,7 @@ class ContentSettingRPHImageModel : public ContentSettingSimpleImageModel { ...@@ -77,7 +78,7 @@ class ContentSettingRPHImageModel : public ContentSettingSimpleImageModel {
public: public:
ContentSettingRPHImageModel(); ContentSettingRPHImageModel();
void UpdateFromWebContents(WebContents* web_contents) override; bool UpdateAndGetVisibility(WebContents* web_contents) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingRPHImageModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingRPHImageModel);
...@@ -88,7 +89,7 @@ class ContentSettingMIDISysExImageModel ...@@ -88,7 +89,7 @@ class ContentSettingMIDISysExImageModel
public: public:
ContentSettingMIDISysExImageModel(); ContentSettingMIDISysExImageModel();
void UpdateFromWebContents(WebContents* web_contents) override; bool UpdateAndGetVisibility(WebContents* web_contents) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel);
...@@ -99,7 +100,7 @@ class ContentSettingDownloadsImageModel ...@@ -99,7 +100,7 @@ class ContentSettingDownloadsImageModel
public: public:
ContentSettingDownloadsImageModel(); ContentSettingDownloadsImageModel();
void UpdateFromWebContents(WebContents* web_contents) override; bool UpdateAndGetVisibility(WebContents* web_contents) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingDownloadsImageModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingDownloadsImageModel);
...@@ -110,7 +111,7 @@ class ContentSettingClipboardReadImageModel ...@@ -110,7 +111,7 @@ class ContentSettingClipboardReadImageModel
public: public:
ContentSettingClipboardReadImageModel(); ContentSettingClipboardReadImageModel();
void UpdateFromWebContents(WebContents* web_contents) override; bool UpdateAndGetVisibility(WebContents* web_contents) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingClipboardReadImageModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingClipboardReadImageModel);
...@@ -121,16 +122,13 @@ class ContentSettingMediaImageModel : public ContentSettingImageModel { ...@@ -121,16 +122,13 @@ class ContentSettingMediaImageModel : public ContentSettingImageModel {
public: public:
ContentSettingMediaImageModel(); ContentSettingMediaImageModel();
void UpdateFromWebContents(WebContents* web_contents) override; bool UpdateAndGetVisibility(WebContents* web_contents) override;
ContentSettingBubbleModel* CreateBubbleModelImpl( ContentSettingBubbleModel* CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
Profile* profile) override; Profile* profile) override;
bool ShouldRunAnimation(WebContents* web_contents) override;
void SetAnimationHasRun(WebContents* web_contents) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingMediaImageModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingMediaImageModel);
}; };
...@@ -139,7 +137,7 @@ class ContentSettingSensorsImageModel : public ContentSettingSimpleImageModel { ...@@ -139,7 +137,7 @@ class ContentSettingSensorsImageModel : public ContentSettingSimpleImageModel {
public: public:
ContentSettingSensorsImageModel(); ContentSettingSensorsImageModel();
void UpdateFromWebContents(WebContents* web_contents) override; bool UpdateAndGetVisibility(WebContents* web_contents) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingSensorsImageModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingSensorsImageModel);
...@@ -204,29 +202,6 @@ ContentSettingSimpleImageModel::CreateBubbleModelImpl( ...@@ -204,29 +202,6 @@ ContentSettingSimpleImageModel::CreateBubbleModelImpl(
content_type()); content_type());
} }
bool ContentSettingSimpleImageModel::ShouldRunAnimation(
WebContents* web_contents) {
if (!web_contents)
return false;
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings)
return false;
return !content_settings->IsBlockageIndicated(content_type());
}
void ContentSettingSimpleImageModel::SetAnimationHasRun(
WebContents* web_contents) {
if (!web_contents)
return;
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
if (content_settings)
content_settings->SetBlockageHasBeenIndicated(content_type());
}
// static // static
std::unique_ptr<ContentSettingImageModel> std::unique_ptr<ContentSettingImageModel>
ContentSettingImageModel::CreateForContentType(ImageType image_type) { ContentSettingImageModel::CreateForContentType(ImageType image_type) {
...@@ -281,6 +256,29 @@ ContentSettingImageModel::CreateForContentType(ImageType image_type) { ...@@ -281,6 +256,29 @@ ContentSettingImageModel::CreateForContentType(ImageType image_type) {
return nullptr; return nullptr;
} }
void ContentSettingImageModel::Update(content::WebContents* contents) {
bool new_visibility = contents ? UpdateAndGetVisibility(contents) : false;
is_visible_ = new_visibility;
if (contents && !is_visible_) {
ContentSettingImageModelStates::Get(contents)->SetAnimationHasRun(
image_type(), false);
}
}
bool ContentSettingImageModel::ShouldRunAnimation(
content::WebContents* contents) {
DCHECK(contents);
return !ContentSettingImageModelStates::Get(contents)->AnimationHasRun(
image_type());
}
void ContentSettingImageModel::SetAnimationHasRun(
content::WebContents* contents) {
DCHECK(contents);
ContentSettingImageModelStates::Get(contents)->SetAnimationHasRun(
image_type(), true);
}
// Generic blocked content settings -------------------------------------------- // Generic blocked content settings --------------------------------------------
ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( ContentSettingBlockedImageModel::ContentSettingBlockedImageModel(
...@@ -288,12 +286,8 @@ ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( ...@@ -288,12 +286,8 @@ ContentSettingBlockedImageModel::ContentSettingBlockedImageModel(
ContentSettingsType content_type) ContentSettingsType content_type)
: ContentSettingSimpleImageModel(image_type, content_type) {} : ContentSettingSimpleImageModel(image_type, content_type) {}
void ContentSettingBlockedImageModel::UpdateFromWebContents( bool ContentSettingBlockedImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
const ContentSettingsType type = content_type(); const ContentSettingsType type = content_type();
const ContentSettingsImageDetails* image_details = GetImageDetails(type); const ContentSettingsImageDetails* image_details = GetImageDetails(type);
DCHECK(image_details) << "No entry for " << type << " in kImageDetails[]."; DCHECK(image_details) << "No entry for " << type << " in kImageDetails[].";
...@@ -325,21 +319,20 @@ void ContentSettingBlockedImageModel::UpdateFromWebContents( ...@@ -325,21 +319,20 @@ void ContentSettingBlockedImageModel::UpdateFromWebContents(
TabSpecificContentSettings* content_settings = TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents); TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings) if (!content_settings)
return; return false;
if (!content_settings->IsContentBlocked(type)) { if (!content_settings->IsContentBlocked(type)) {
if (!content_settings->IsContentAllowed(type)) if (!content_settings->IsContentAllowed(type))
return; return false;
// For cookies, only show the cookie blocked page action if cookies are // For cookies, only show the cookie blocked page action if cookies are
// blocked by default. // blocked by default.
if (type == CONTENT_SETTINGS_TYPE_COOKIES && if (type == CONTENT_SETTINGS_TYPE_COOKIES &&
(map->GetDefaultContentSetting(type, nullptr) != CONTENT_SETTING_BLOCK)) (map->GetDefaultContentSetting(type, nullptr) != CONTENT_SETTING_BLOCK))
return; return false;
tooltip_id = image_details->accessed_tooltip_id; tooltip_id = image_details->accessed_tooltip_id;
explanation_id = 0; explanation_id = 0;
} }
set_visible(true);
const gfx::VectorIcon* badge_id = &gfx::kNoneIcon; const gfx::VectorIcon* badge_id = &gfx::kNoneIcon;
if (type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER) if (type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER)
badge_id = &kWarningBadgeIcon; badge_id = &kWarningBadgeIcon;
...@@ -356,6 +349,7 @@ void ContentSettingBlockedImageModel::UpdateFromWebContents( ...@@ -356,6 +349,7 @@ void ContentSettingBlockedImageModel::UpdateFromWebContents(
set_explanatory_string_id(explanation_id); set_explanatory_string_id(explanation_id);
DCHECK(tooltip_id); DCHECK(tooltip_id);
set_tooltip(l10n_util::GetStringUTF16(tooltip_id)); set_tooltip(l10n_util::GetStringUTF16(tooltip_id));
return true;
} }
// Geolocation ----------------------------------------------------------------- // Geolocation -----------------------------------------------------------------
...@@ -364,20 +358,16 @@ ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() ...@@ -364,20 +358,16 @@ ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel()
: ContentSettingSimpleImageModel(ImageType::GEOLOCATION, : ContentSettingSimpleImageModel(ImageType::GEOLOCATION,
CONTENT_SETTINGS_TYPE_GEOLOCATION) {} CONTENT_SETTINGS_TYPE_GEOLOCATION) {}
void ContentSettingGeolocationImageModel::UpdateFromWebContents( bool ContentSettingGeolocationImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
TabSpecificContentSettings* content_settings = TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents); TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings) if (!content_settings)
return; return false;
const ContentSettingsUsagesState& usages_state = content_settings-> const ContentSettingsUsagesState& usages_state = content_settings->
geolocation_usages_state(); geolocation_usages_state();
if (usages_state.state_map().empty()) if (usages_state.state_map().empty())
return; return false;
set_visible(true);
// If any embedded site has access the allowed icon takes priority over the // If any embedded site has access the allowed icon takes priority over the
// blocked icon. // blocked icon.
...@@ -389,6 +379,7 @@ void ContentSettingGeolocationImageModel::UpdateFromWebContents( ...@@ -389,6 +379,7 @@ void ContentSettingGeolocationImageModel::UpdateFromWebContents(
set_tooltip(l10n_util::GetStringUTF16(allowed set_tooltip(l10n_util::GetStringUTF16(allowed
? IDS_GEOLOCATION_ALLOWED_TOOLTIP ? IDS_GEOLOCATION_ALLOWED_TOOLTIP
: IDS_GEOLOCATION_BLOCKED_TOOLTIP)); : IDS_GEOLOCATION_BLOCKED_TOOLTIP));
return true;
} }
// Protocol handlers ----------------------------------------------------------- // Protocol handlers -----------------------------------------------------------
...@@ -400,20 +391,16 @@ ContentSettingRPHImageModel::ContentSettingRPHImageModel() ...@@ -400,20 +391,16 @@ ContentSettingRPHImageModel::ContentSettingRPHImageModel()
set_tooltip(l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP)); set_tooltip(l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP));
} }
void ContentSettingRPHImageModel::UpdateFromWebContents( bool ContentSettingRPHImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
TabSpecificContentSettings* content_settings = TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents); TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings) if (!content_settings)
return; return false;
if (content_settings->pending_protocol_handler().IsEmpty()) if (content_settings->pending_protocol_handler().IsEmpty())
return; return false;
set_visible(true); return true;
} }
// MIDI SysEx ------------------------------------------------------------------ // MIDI SysEx ------------------------------------------------------------------
...@@ -422,20 +409,16 @@ ContentSettingMIDISysExImageModel::ContentSettingMIDISysExImageModel() ...@@ -422,20 +409,16 @@ ContentSettingMIDISysExImageModel::ContentSettingMIDISysExImageModel()
: ContentSettingSimpleImageModel(ImageType::MIDI_SYSEX, : ContentSettingSimpleImageModel(ImageType::MIDI_SYSEX,
CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {} CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {}
void ContentSettingMIDISysExImageModel::UpdateFromWebContents( bool ContentSettingMIDISysExImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
TabSpecificContentSettings* content_settings = TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents); TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings) if (!content_settings)
return; return false;
const ContentSettingsUsagesState& usages_state = const ContentSettingsUsagesState& usages_state =
content_settings->midi_usages_state(); content_settings->midi_usages_state();
if (usages_state.state_map().empty()) if (usages_state.state_map().empty())
return; return false;
set_visible(true);
// If any embedded site has access the allowed icon takes priority over the // If any embedded site has access the allowed icon takes priority over the
// blocked icon. // blocked icon.
...@@ -448,6 +431,7 @@ void ContentSettingMIDISysExImageModel::UpdateFromWebContents( ...@@ -448,6 +431,7 @@ void ContentSettingMIDISysExImageModel::UpdateFromWebContents(
set_tooltip(l10n_util::GetStringUTF16(allowed set_tooltip(l10n_util::GetStringUTF16(allowed
? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP
: IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP));
return true;
} }
// Automatic downloads --------------------------------------------------------- // Automatic downloads ---------------------------------------------------------
...@@ -457,35 +441,29 @@ ContentSettingDownloadsImageModel::ContentSettingDownloadsImageModel() ...@@ -457,35 +441,29 @@ ContentSettingDownloadsImageModel::ContentSettingDownloadsImageModel()
ImageType::AUTOMATIC_DOWNLOADS, ImageType::AUTOMATIC_DOWNLOADS,
CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {} CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {}
void ContentSettingDownloadsImageModel::UpdateFromWebContents( bool ContentSettingDownloadsImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
DownloadRequestLimiter* download_request_limiter = DownloadRequestLimiter* download_request_limiter =
g_browser_process->download_request_limiter(); g_browser_process->download_request_limiter();
// DownloadRequestLimiter can be absent in unit_tests. // DownloadRequestLimiter can be absent in unit_tests.
if (!download_request_limiter) if (!download_request_limiter)
return; return false;
switch (download_request_limiter->GetDownloadUiStatus(web_contents)) { switch (download_request_limiter->GetDownloadUiStatus(web_contents)) {
case DownloadRequestLimiter::DOWNLOAD_UI_ALLOWED: case DownloadRequestLimiter::DOWNLOAD_UI_ALLOWED:
set_visible(true);
set_icon(kFileDownloadIcon, gfx::kNoneIcon); set_icon(kFileDownloadIcon, gfx::kNoneIcon);
set_explanatory_string_id(0); set_explanatory_string_id(0);
set_tooltip(l10n_util::GetStringUTF16(IDS_ALLOWED_DOWNLOAD_TITLE)); set_tooltip(l10n_util::GetStringUTF16(IDS_ALLOWED_DOWNLOAD_TITLE));
return; return true;
case DownloadRequestLimiter::DOWNLOAD_UI_BLOCKED: case DownloadRequestLimiter::DOWNLOAD_UI_BLOCKED:
set_visible(true);
set_icon(kFileDownloadIcon, kBlockedBadgeIcon); set_icon(kFileDownloadIcon, kBlockedBadgeIcon);
set_explanatory_string_id(IDS_BLOCKED_DOWNLOADS_EXPLANATION); set_explanatory_string_id(IDS_BLOCKED_DOWNLOADS_EXPLANATION);
set_tooltip(l10n_util::GetStringUTF16(IDS_BLOCKED_DOWNLOAD_TITLE)); set_tooltip(l10n_util::GetStringUTF16(IDS_BLOCKED_DOWNLOAD_TITLE));
return; return true;
case DownloadRequestLimiter::DOWNLOAD_UI_DEFAULT: case DownloadRequestLimiter::DOWNLOAD_UI_DEFAULT:
// No need to show icon otherwise. // No need to show icon otherwise.
return; return false;
} }
} }
...@@ -495,25 +473,22 @@ ContentSettingClipboardReadImageModel::ContentSettingClipboardReadImageModel() ...@@ -495,25 +473,22 @@ ContentSettingClipboardReadImageModel::ContentSettingClipboardReadImageModel()
: ContentSettingSimpleImageModel(ImageType::CLIPBOARD_READ, : ContentSettingSimpleImageModel(ImageType::CLIPBOARD_READ,
CONTENT_SETTINGS_TYPE_CLIPBOARD_READ) {} CONTENT_SETTINGS_TYPE_CLIPBOARD_READ) {}
void ContentSettingClipboardReadImageModel::UpdateFromWebContents( bool ContentSettingClipboardReadImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
TabSpecificContentSettings* content_settings = TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents); TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings) if (!content_settings)
return; return false;
ContentSettingsType content_type = CONTENT_SETTINGS_TYPE_CLIPBOARD_READ; ContentSettingsType content_type = CONTENT_SETTINGS_TYPE_CLIPBOARD_READ;
bool blocked = content_settings->IsContentBlocked(content_type); bool blocked = content_settings->IsContentBlocked(content_type);
bool allowed = content_settings->IsContentAllowed(content_type); bool allowed = content_settings->IsContentAllowed(content_type);
if (!blocked && !allowed) if (!blocked && !allowed)
return; return false;
set_visible(true);
set_icon(kContentPasteIcon, allowed ? gfx::kNoneIcon : kBlockedBadgeIcon); set_icon(kContentPasteIcon, allowed ? gfx::kNoneIcon : kBlockedBadgeIcon);
set_tooltip(l10n_util::GetStringUTF16( set_tooltip(l10n_util::GetStringUTF16(
allowed ? IDS_ALLOWED_CLIPBOARD_MESSAGE : IDS_BLOCKED_CLIPBOARD_MESSAGE)); allowed ? IDS_ALLOWED_CLIPBOARD_MESSAGE : IDS_BLOCKED_CLIPBOARD_MESSAGE));
return true;
} }
// Media ----------------------------------------------------------------------- // Media -----------------------------------------------------------------------
...@@ -521,24 +496,19 @@ void ContentSettingClipboardReadImageModel::UpdateFromWebContents( ...@@ -521,24 +496,19 @@ void ContentSettingClipboardReadImageModel::UpdateFromWebContents(
ContentSettingMediaImageModel::ContentSettingMediaImageModel() ContentSettingMediaImageModel::ContentSettingMediaImageModel()
: ContentSettingImageModel(ImageType::MEDIASTREAM) {} : ContentSettingImageModel(ImageType::MEDIASTREAM) {}
void ContentSettingMediaImageModel::UpdateFromWebContents( bool ContentSettingMediaImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
TabSpecificContentSettings* content_settings = TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents); TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings) if (!content_settings)
return; return false;
TabSpecificContentSettings::MicrophoneCameraState state = TabSpecificContentSettings::MicrophoneCameraState state =
content_settings->GetMicrophoneCameraState(); content_settings->GetMicrophoneCameraState();
// If neither the microphone nor the camera stream was accessed then no icon // If neither the microphone nor the camera stream was accessed then no icon
// is displayed in the omnibox. // is displayed in the omnibox.
if (state == TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) if (state == TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED)
return; return false;
bool is_mic = (state & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; bool is_mic = (state & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0;
bool is_cam = (state & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; bool is_cam = (state & TabSpecificContentSettings::CAMERA_ACCESSED) != 0;
...@@ -557,7 +527,7 @@ void ContentSettingMediaImageModel::UpdateFromWebContents( ...@@ -557,7 +527,7 @@ void ContentSettingMediaImageModel::UpdateFromWebContents(
id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED;
} }
set_tooltip(l10n_util::GetStringUTF16(id)); set_tooltip(l10n_util::GetStringUTF16(id));
set_visible(true); return true;
} }
ContentSettingBubbleModel* ContentSettingMediaImageModel::CreateBubbleModelImpl( ContentSettingBubbleModel* ContentSettingMediaImageModel::CreateBubbleModelImpl(
...@@ -569,54 +539,20 @@ ContentSettingBubbleModel* ContentSettingMediaImageModel::CreateBubbleModelImpl( ...@@ -569,54 +539,20 @@ ContentSettingBubbleModel* ContentSettingMediaImageModel::CreateBubbleModelImpl(
profile); profile);
} }
bool ContentSettingMediaImageModel::ShouldRunAnimation(
WebContents* web_contents) {
if (!web_contents)
return false;
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings)
return false;
return (!content_settings->IsBlockageIndicated(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) &&
!content_settings->IsBlockageIndicated(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
}
void ContentSettingMediaImageModel::SetAnimationHasRun(
WebContents* web_contents) {
if (!web_contents)
return;
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
if (content_settings) {
content_settings->SetBlockageHasBeenIndicated(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
content_settings->SetBlockageHasBeenIndicated(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
}
}
// Blocked Framebust ----------------------------------------------------------- // Blocked Framebust -----------------------------------------------------------
ContentSettingFramebustBlockImageModel::ContentSettingFramebustBlockImageModel() ContentSettingFramebustBlockImageModel::ContentSettingFramebustBlockImageModel()
: ContentSettingImageModel(ImageType::FRAMEBUST) {} : ContentSettingImageModel(ImageType::FRAMEBUST) {}
void ContentSettingFramebustBlockImageModel::UpdateFromWebContents( bool ContentSettingFramebustBlockImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
// Early exit if no blocked Framebust. // Early exit if no blocked Framebust.
if (!FramebustBlockTabHelper::FromWebContents(web_contents)->HasBlockedUrls()) if (!FramebustBlockTabHelper::FromWebContents(web_contents)->HasBlockedUrls())
return; return false;
set_icon(kBlockedRedirectIcon, kBlockedBadgeIcon); set_icon(kBlockedRedirectIcon, kBlockedBadgeIcon);
set_explanatory_string_id(IDS_REDIRECT_BLOCKED_TITLE); set_explanatory_string_id(IDS_REDIRECT_BLOCKED_TITLE);
set_tooltip(l10n_util::GetStringUTF16(IDS_REDIRECT_BLOCKED_TOOLTIP)); set_tooltip(l10n_util::GetStringUTF16(IDS_REDIRECT_BLOCKED_TOOLTIP));
set_visible(true); return true;
} }
ContentSettingBubbleModel* ContentSettingBubbleModel*
...@@ -628,45 +564,28 @@ ContentSettingFramebustBlockImageModel::CreateBubbleModelImpl( ...@@ -628,45 +564,28 @@ ContentSettingFramebustBlockImageModel::CreateBubbleModelImpl(
profile); profile);
} }
bool ContentSettingFramebustBlockImageModel::ShouldRunAnimation(
WebContents* web_contents) {
return web_contents && !FramebustBlockTabHelper::FromWebContents(web_contents)
->animation_has_run();
}
void ContentSettingFramebustBlockImageModel::SetAnimationHasRun(
WebContents* web_contents) {
if (!web_contents)
return;
FramebustBlockTabHelper::FromWebContents(web_contents)
->set_animation_has_run();
}
// Sensors --------------------------------------------------------------------- // Sensors ---------------------------------------------------------------------
ContentSettingSensorsImageModel::ContentSettingSensorsImageModel() ContentSettingSensorsImageModel::ContentSettingSensorsImageModel()
: ContentSettingSimpleImageModel(ImageType::SENSORS, : ContentSettingSimpleImageModel(ImageType::SENSORS,
CONTENT_SETTINGS_TYPE_SENSORS) {} CONTENT_SETTINGS_TYPE_SENSORS) {}
void ContentSettingSensorsImageModel::UpdateFromWebContents( bool ContentSettingSensorsImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { WebContents* web_contents) {
set_visible(false);
if (!web_contents)
return;
auto* content_settings = auto* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents); TabSpecificContentSettings::FromWebContents(web_contents);
if (!content_settings) if (!content_settings)
return; return false;
bool blocked = content_settings->IsContentBlocked(content_type()); bool blocked = content_settings->IsContentBlocked(content_type());
bool allowed = content_settings->IsContentAllowed(content_type()); bool allowed = content_settings->IsContentAllowed(content_type());
if (!blocked && !allowed) if (!blocked && !allowed)
return; return false;
set_visible(true);
set_icon(kSensorsIcon, allowed ? gfx::kNoneIcon : kBlockedBadgeIcon); set_icon(kSensorsIcon, allowed ? gfx::kNoneIcon : kBlockedBadgeIcon);
set_tooltip(l10n_util::GetStringUTF16(allowed ? IDS_SENSORS_ALLOWED_TOOLTIP set_tooltip(l10n_util::GetStringUTF16(allowed ? IDS_SENSORS_ALLOWED_TOOLTIP
: IDS_SENSORS_BLOCKED_TOOLTIP)); : IDS_SENSORS_BLOCKED_TOOLTIP));
return true;
} }
// Base class ------------------------------------------------------------------ // Base class ------------------------------------------------------------------
...@@ -738,13 +657,3 @@ size_t ContentSettingImageModel::GetContentSettingImageModelIndexForTesting( ...@@ -738,13 +657,3 @@ size_t ContentSettingImageModel::GetContentSettingImageModelIndexForTesting(
NOTREACHED(); NOTREACHED();
return models.size(); return models.size();
} }
#if defined(OS_MACOSX)
bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged(
content::WebContents* web_contents) {
const gfx::VectorIcon* old_icon = icon_;
const gfx::VectorIcon* old_badge_icon = icon_badge_;
UpdateFromWebContents(web_contents);
return old_icon != icon_ && old_badge_icon != icon_badge_;
}
#endif
...@@ -67,9 +67,7 @@ class ContentSettingImageModel { ...@@ -67,9 +67,7 @@ class ContentSettingImageModel {
static std::unique_ptr<ContentSettingImageModel> CreateForContentType( static std::unique_ptr<ContentSettingImageModel> CreateForContentType(
ImageType image_type); ImageType image_type);
// Notifies this model that its setting might have changed and it may need to void Update(content::WebContents* contents);
// update its visibility, icon and tooltip.
virtual void UpdateFromWebContents(content::WebContents* web_contents) = 0;
// Creates the model for the bubble that will be attached to this image. // Creates the model for the bubble that will be attached to this image.
// The bubble model is owned by the caller. // The bubble model is owned by the caller.
...@@ -79,20 +77,14 @@ class ContentSettingImageModel { ...@@ -79,20 +77,14 @@ class ContentSettingImageModel {
Profile* profile); Profile* profile);
// Whether the animation should be run for the given |web_contents|. // Whether the animation should be run for the given |web_contents|.
virtual bool ShouldRunAnimation(content::WebContents* web_contents) = 0; bool ShouldRunAnimation(content::WebContents* web_contents);
// Remembers that the animation has already run for the given |web_contents|, // Remembers that the animation has already run for the given |web_contents|,
// so that we do not restart it when the parent view is updated. // so that we do not restart it when the parent view is updated.
virtual void SetAnimationHasRun(content::WebContents* web_contents) = 0; void SetAnimationHasRun(content::WebContents* web_contents);
bool is_visible() const { return is_visible_; } bool is_visible() const { return is_visible_; }
#if defined(OS_MACOSX)
// Calls UpdateFromWebContents() and returns true if the icon has changed.
bool UpdateFromWebContentsAndCheckIfIconChanged(
content::WebContents* web_contents);
#endif
// Retrieve the icon that represents this content setting. Blocked content // Retrieve the icon that represents this content setting. Blocked content
// settings icons will have a blocked badge. // settings icons will have a blocked badge.
gfx::Image GetIcon(SkColor icon_color) const; gfx::Image GetIcon(SkColor icon_color) const;
...@@ -107,6 +99,11 @@ class ContentSettingImageModel { ...@@ -107,6 +99,11 @@ class ContentSettingImageModel {
protected: protected:
explicit ContentSettingImageModel(ImageType type); explicit ContentSettingImageModel(ImageType type);
// Notifies this model that its setting might have changed and it may need to
// update its visibility, icon and tooltip. This method returns whether the
// model should be visible.
virtual bool UpdateAndGetVisibility(content::WebContents* web_contents) = 0;
// Internal implementation by subclasses of bubble model creation. // Internal implementation by subclasses of bubble model creation.
virtual ContentSettingBubbleModel* CreateBubbleModelImpl( virtual ContentSettingBubbleModel* CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
...@@ -118,7 +115,6 @@ class ContentSettingImageModel { ...@@ -118,7 +115,6 @@ class ContentSettingImageModel {
icon_badge_ = &badge; icon_badge_ = &badge;
} }
void set_visible(bool visible) { is_visible_ = visible; }
void set_explanatory_string_id(int text_id) { void set_explanatory_string_id(int text_id) {
explanatory_string_id_ = text_id; explanatory_string_id_ = text_id;
} }
...@@ -147,8 +143,6 @@ class ContentSettingSimpleImageModel : public ContentSettingImageModel { ...@@ -147,8 +143,6 @@ class ContentSettingSimpleImageModel : public ContentSettingImageModel {
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents, content::WebContents* web_contents,
Profile* profile) override; Profile* profile) override;
bool ShouldRunAnimation(content::WebContents* web_contents) override;
void SetAnimationHasRun(content::WebContents* web_contents) override;
ContentSettingsType content_type() { return content_type_; } ContentSettingsType content_type() { return content_type_; }
...@@ -162,16 +156,13 @@ class ContentSettingFramebustBlockImageModel : public ContentSettingImageModel { ...@@ -162,16 +156,13 @@ class ContentSettingFramebustBlockImageModel : public ContentSettingImageModel {
public: public:
ContentSettingFramebustBlockImageModel(); ContentSettingFramebustBlockImageModel();
void UpdateFromWebContents(content::WebContents* web_contents) override; bool UpdateAndGetVisibility(content::WebContents* web_contents) override;
ContentSettingBubbleModel* CreateBubbleModelImpl( ContentSettingBubbleModel* CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents, content::WebContents* web_contents,
Profile* profile) override; Profile* profile) override;
bool ShouldRunAnimation(content::WebContents* web_contents) override;
void SetAnimationHasRun(content::WebContents* web_contents) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingFramebustBlockImageModel); DISALLOW_COPY_AND_ASSIGN(ContentSettingFramebustBlockImageModel);
}; };
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/content_settings/content_setting_image_model_states.h"
#include "base/logging.h"
ContentSettingImageModelStates::~ContentSettingImageModelStates() = default;
// static
ContentSettingImageModelStates* ContentSettingImageModelStates::Get(
content::WebContents* contents) {
DCHECK(contents);
if (auto* state = FromWebContents(contents))
return state;
CreateForWebContents(contents);
return FromWebContents(contents);
}
void ContentSettingImageModelStates::SetAnimationHasRun(
ImageType type,
bool animation_has_run) {
VerifyType(type);
animations_[static_cast<int>(type)] = animation_has_run;
}
bool ContentSettingImageModelStates::AnimationHasRun(ImageType type) const {
VerifyType(type);
return animations_[static_cast<int>(type)];
}
ContentSettingImageModelStates::ContentSettingImageModelStates(
content::WebContents* contents) {}
void ContentSettingImageModelStates::VerifyType(ImageType type) const {
CHECK_GE(type, static_cast<ImageType>(0));
CHECK_LT(type, ImageType::NUM_IMAGE_TYPES);
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_STATES_H_
#define CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_STATES_H_
#include "base/macros.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model.h"
#include "content/public/browser/web_contents_user_data.h"
using ImageType = ContentSettingImageModel::ImageType;
// Class that keeps track of the tab-specific state associated with each
// ContentSettingImageModel. Each tab will have one instance of this class,
// which keeps track of states for each ImageType.
class ContentSettingImageModelStates
: public content::WebContentsUserData<ContentSettingImageModelStates> {
public:
~ContentSettingImageModelStates() override;
static ContentSettingImageModelStates* Get(content::WebContents* contents);
void SetAnimationHasRun(ImageType type, bool animation_has_run);
bool AnimationHasRun(ImageType type) const;
private:
friend class content::WebContentsUserData<ContentSettingImageModelStates>;
explicit ContentSettingImageModelStates(content::WebContents* contents);
// ImageTypes are used for direct access into a raw array, use this method to
// CHECK that everything is in-bounds.
void VerifyType(ImageType type) const;
// Array of bool for whether an animation has run for a given image model.
// This bit is reset to false when the image is hidden.
bool animations_[static_cast<int>(ImageType::NUM_IMAGE_TYPES)] = {};
DISALLOW_COPY_AND_ASSIGN(ContentSettingImageModelStates);
};
#endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_STATES_H_
...@@ -47,8 +47,7 @@ class NotificationForwarder : public content::NotificationObserver { ...@@ -47,8 +47,7 @@ class NotificationForwarder : public content::NotificationObserver {
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) override { const content::NotificationDetails& details) override {
if (type == chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED) { if (type == chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED) {
model_->UpdateFromWebContents( model_->Update(content::Source<content::WebContents>(source).ptr());
content::Source<content::WebContents>(source).ptr());
} }
} }
...@@ -62,7 +61,7 @@ class NotificationForwarder : public content::NotificationObserver { ...@@ -62,7 +61,7 @@ class NotificationForwarder : public content::NotificationObserver {
class ContentSettingImageModelTest : public ChromeRenderViewHostTestHarness { class ContentSettingImageModelTest : public ChromeRenderViewHostTestHarness {
}; };
TEST_F(ContentSettingImageModelTest, UpdateFromWebContents) { TEST_F(ContentSettingImageModelTest, Update) {
TabSpecificContentSettings::CreateForWebContents(web_contents()); TabSpecificContentSettings::CreateForWebContents(web_contents());
TabSpecificContentSettings* content_settings = TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents()); TabSpecificContentSettings::FromWebContents(web_contents());
...@@ -73,19 +72,19 @@ TEST_F(ContentSettingImageModelTest, UpdateFromWebContents) { ...@@ -73,19 +72,19 @@ TEST_F(ContentSettingImageModelTest, UpdateFromWebContents) {
EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); EXPECT_TRUE(content_setting_image_model->get_tooltip().empty());
content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES);
content_setting_image_model->UpdateFromWebContents(web_contents()); content_setting_image_model->Update(web_contents());
EXPECT_TRUE(content_setting_image_model->is_visible()); EXPECT_TRUE(content_setting_image_model->is_visible());
EXPECT_TRUE(HasIcon(*content_setting_image_model)); EXPECT_TRUE(HasIcon(*content_setting_image_model));
EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); EXPECT_FALSE(content_setting_image_model->get_tooltip().empty());
} }
TEST_F(ContentSettingImageModelTest, RPHUpdateFromWebContents) { TEST_F(ContentSettingImageModelTest, RPHUpdate) {
TabSpecificContentSettings::CreateForWebContents(web_contents()); TabSpecificContentSettings::CreateForWebContents(web_contents());
auto content_setting_image_model = auto content_setting_image_model =
ContentSettingImageModel::CreateForContentType( ContentSettingImageModel::CreateForContentType(
ContentSettingImageModel::ImageType::PROTOCOL_HANDLERS); ContentSettingImageModel::ImageType::PROTOCOL_HANDLERS);
content_setting_image_model->UpdateFromWebContents(web_contents()); content_setting_image_model->Update(web_contents());
EXPECT_FALSE(content_setting_image_model->is_visible()); EXPECT_FALSE(content_setting_image_model->is_visible());
TabSpecificContentSettings* content_settings = TabSpecificContentSettings* content_settings =
...@@ -93,7 +92,7 @@ TEST_F(ContentSettingImageModelTest, RPHUpdateFromWebContents) { ...@@ -93,7 +92,7 @@ TEST_F(ContentSettingImageModelTest, RPHUpdateFromWebContents) {
content_settings->set_pending_protocol_handler( content_settings->set_pending_protocol_handler(
ProtocolHandler::CreateProtocolHandler( ProtocolHandler::CreateProtocolHandler(
"mailto", GURL("http://www.google.com/"))); "mailto", GURL("http://www.google.com/")));
content_setting_image_model->UpdateFromWebContents(web_contents()); content_setting_image_model->Update(web_contents());
EXPECT_TRUE(content_setting_image_model->is_visible()); EXPECT_TRUE(content_setting_image_model->is_visible());
} }
...@@ -116,7 +115,7 @@ TEST_F(ContentSettingImageModelTest, CookieAccessed) { ...@@ -116,7 +115,7 @@ TEST_F(ContentSettingImageModelTest, CookieAccessed) {
net::CanonicalCookie::Create(origin, "A=B", base::Time::Now(), options)); net::CanonicalCookie::Create(origin, "A=B", base::Time::Now(), options));
ASSERT_TRUE(cookie); ASSERT_TRUE(cookie);
content_settings->OnCookieChange(origin, origin, *cookie, false); content_settings->OnCookieChange(origin, origin, *cookie, false);
content_setting_image_model->UpdateFromWebContents(web_contents()); content_setting_image_model->Update(web_contents());
EXPECT_TRUE(content_setting_image_model->is_visible()); EXPECT_TRUE(content_setting_image_model->is_visible());
EXPECT_TRUE(HasIcon(*content_setting_image_model)); EXPECT_TRUE(HasIcon(*content_setting_image_model));
EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); EXPECT_FALSE(content_setting_image_model->get_tooltip().empty());
...@@ -144,7 +143,7 @@ TEST_F(ContentSettingImageModelTest, SubresourceFilter) { ...@@ -144,7 +143,7 @@ TEST_F(ContentSettingImageModelTest, SubresourceFilter) {
EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); EXPECT_TRUE(content_setting_image_model->get_tooltip().empty());
content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_ADS); content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_ADS);
content_setting_image_model->UpdateFromWebContents(web_contents()); content_setting_image_model->Update(web_contents());
EXPECT_TRUE(content_setting_image_model->is_visible()); EXPECT_TRUE(content_setting_image_model->is_visible());
EXPECT_TRUE(HasIcon(*content_setting_image_model)); EXPECT_TRUE(HasIcon(*content_setting_image_model));
......
...@@ -46,13 +46,13 @@ void ContentSettingImageView::Update() { ...@@ -46,13 +46,13 @@ void ContentSettingImageView::Update() {
delegate_->GetContentSettingWebContents(); delegate_->GetContentSettingWebContents();
// Note: We explicitly want to call this even if |web_contents| is NULL, so we // Note: We explicitly want to call this even if |web_contents| is NULL, so we
// get hidden properly while the user is editing the omnibox. // get hidden properly while the user is editing the omnibox.
content_setting_image_model_->UpdateFromWebContents(web_contents); content_setting_image_model_->Update(web_contents);
if (!content_setting_image_model_->is_visible()) { if (!content_setting_image_model_->is_visible()) {
SetVisible(false); SetVisible(false);
return; return;
} }
DCHECK(web_contents);
UpdateImage(); UpdateImage();
SetVisible(true); SetVisible(true);
......
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