1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_
6 #define CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_
13 #include "base/compiler_specific.h"
14 #include "chrome/common/custom_handlers/protocol_handler.h"
15 #include "components/content_settings/core/common/content_settings.h"
16 #include "components/content_settings/core/common/content_settings_types.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/common/media_stream_request.h"
20 #include "ui/gfx/image/image.h"
23 class ContentSettingBubbleModelDelegate
;
25 class ProtocolHandlerRegistry
;
31 // This model provides data for ContentSettingBubble, and also controls
32 // the action triggered when the allow / block radio buttons are triggered.
33 class ContentSettingBubbleModel
: public content::NotificationObserver
{
35 typedef ContentSettingBubbleModelDelegate Delegate
;
38 ListItem(const gfx::Image
& image
,
39 const std::string
& title
,
42 : image(image
), title(title
), has_link(has_link
), item_id(item_id
) {}
49 typedef std::vector
<ListItem
> ListItems
;
51 typedef std::vector
<std::string
> RadioItems
;
58 RadioItems radio_items
;
67 std::set
<std::string
> hosts
;
75 content::MediaStreamDevice default_device
;
76 content::MediaStreamDevice selected_device
;
79 typedef std::map
<content::MediaStreamType
, MediaMenu
> MediaMenuMap
;
81 struct BubbleContent
{
87 RadioGroup radio_group
;
88 bool radio_group_enabled
;
89 std::vector
<DomainList
> domain_lists
;
90 std::string custom_link
;
91 bool custom_link_enabled
;
92 std::string manage_link
;
93 MediaMenuMap media_menus
;
94 std::string learn_more_link
;
97 DISALLOW_COPY_AND_ASSIGN(BubbleContent
);
100 static ContentSettingBubbleModel
* CreateContentSettingBubbleModel(
102 content::WebContents
* web_contents
,
104 ContentSettingsType content_type
);
106 ~ContentSettingBubbleModel() override
;
108 ContentSettingsType
content_type() const { return content_type_
; }
110 const BubbleContent
& bubble_content() const { return bubble_content_
; }
112 // content::NotificationObserver:
113 void Observe(int type
,
114 const content::NotificationSource
& source
,
115 const content::NotificationDetails
& details
) override
;
117 virtual void OnRadioClicked(int radio_index
) {}
118 virtual void OnListItemClicked(int index
) {}
119 virtual void OnCustomLinkClicked() {}
120 virtual void OnManageLinkClicked() {}
121 virtual void OnLearnMoreLinkClicked() {}
122 virtual void OnMediaMenuClicked(content::MediaStreamType type
,
123 const std::string
& selected_device_id
) {}
125 // Called by the view code when the bubble is closed by the user using the
127 virtual void OnDoneClicked() {}
130 ContentSettingBubbleModel(
131 content::WebContents
* web_contents
,
133 ContentSettingsType content_type
);
135 content::WebContents
* web_contents() const { return web_contents_
; }
136 Profile
* profile() const { return profile_
; }
138 void set_title(const std::string
& title
) { bubble_content_
.title
= title
; }
139 void add_list_item(const ListItem
& item
) {
140 bubble_content_
.list_items
.push_back(item
);
142 void set_radio_group(const RadioGroup
& radio_group
) {
143 bubble_content_
.radio_group
= radio_group
;
145 void set_radio_group_enabled(bool enabled
) {
146 bubble_content_
.radio_group_enabled
= enabled
;
148 void add_domain_list(const DomainList
& domain_list
) {
149 bubble_content_
.domain_lists
.push_back(domain_list
);
151 void set_custom_link(const std::string
& link
) {
152 bubble_content_
.custom_link
= link
;
154 void set_custom_link_enabled(bool enabled
) {
155 bubble_content_
.custom_link_enabled
= enabled
;
157 void set_manage_link(const std::string
& link
) {
158 bubble_content_
.manage_link
= link
;
160 void set_learn_more_link(const std::string
& link
) {
161 bubble_content_
.learn_more_link
= link
;
163 void add_media_menu(content::MediaStreamType type
, const MediaMenu
& menu
) {
164 bubble_content_
.media_menus
[type
] = menu
;
166 void set_selected_device(const content::MediaStreamDevice
& device
) {
167 bubble_content_
.media_menus
[device
.type
].selected_device
= device
;
169 bool setting_is_managed() {
170 return setting_is_managed_
;
172 void set_setting_is_managed(bool managed
) {
173 setting_is_managed_
= managed
;
177 content::WebContents
* web_contents_
;
179 ContentSettingsType content_type_
;
180 BubbleContent bubble_content_
;
181 // A registrar for listening for WEB_CONTENTS_DESTROYED notifications.
182 content::NotificationRegistrar registrar_
;
183 // A flag that indicates if the content setting managed i.e. can't be
184 // controlled by the user.
185 bool setting_is_managed_
;
187 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleModel
);
190 class ContentSettingTitleAndLinkModel
: public ContentSettingBubbleModel
{
192 ContentSettingTitleAndLinkModel(Delegate
* delegate
,
193 content::WebContents
* web_contents
,
195 ContentSettingsType content_type
);
196 ~ContentSettingTitleAndLinkModel() override
{}
197 Delegate
* delegate() const { return delegate_
; }
201 void SetManageLink();
202 void SetLearnMoreLink();
204 // content::ContentSettingBubbleModel:
205 void OnManageLinkClicked() override
;
206 void OnLearnMoreLinkClicked() override
;
210 // RPH stands for Register Protocol Handler.
211 class ContentSettingRPHBubbleModel
: public ContentSettingTitleAndLinkModel
{
213 ContentSettingRPHBubbleModel(Delegate
* delegate
,
214 content::WebContents
* web_contents
,
216 ProtocolHandlerRegistry
* registry
);
218 void OnRadioClicked(int radio_index
) override
;
219 void OnDoneClicked() override
;
222 void RegisterProtocolHandler();
223 void UnregisterProtocolHandler();
224 void IgnoreProtocolHandler();
225 void ClearOrSetPreviousHandler();
228 ProtocolHandlerRegistry
* registry_
;
229 ProtocolHandler pending_handler_
;
230 ProtocolHandler previous_handler_
;
233 #endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_