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 // Returns a set of the supported bubble types.
101 static const std::set
<ContentSettingsType
>& GetSupportedBubbleTypes();
103 static ContentSettingBubbleModel
* CreateContentSettingBubbleModel(
105 content::WebContents
* web_contents
,
107 ContentSettingsType content_type
);
109 ~ContentSettingBubbleModel() override
;
111 ContentSettingsType
content_type() const { return content_type_
; }
113 const BubbleContent
& bubble_content() const { return bubble_content_
; }
115 // content::NotificationObserver:
116 void Observe(int type
,
117 const content::NotificationSource
& source
,
118 const content::NotificationDetails
& details
) override
;
120 virtual void OnRadioClicked(int radio_index
) {}
121 virtual void OnListItemClicked(int index
) {}
122 virtual void OnCustomLinkClicked() {}
123 virtual void OnManageLinkClicked() {}
124 virtual void OnLearnMoreLinkClicked() {}
125 virtual void OnMediaMenuClicked(content::MediaStreamType type
,
126 const std::string
& selected_device_id
) {}
128 // Called by the view code when the bubble is closed by the user using the
130 virtual void OnDoneClicked() {}
133 ContentSettingBubbleModel(
134 content::WebContents
* web_contents
,
136 ContentSettingsType content_type
);
138 content::WebContents
* web_contents() const { return web_contents_
; }
139 Profile
* profile() const { return profile_
; }
141 void set_title(const std::string
& title
) { bubble_content_
.title
= title
; }
142 void add_list_item(const ListItem
& item
) {
143 bubble_content_
.list_items
.push_back(item
);
145 void set_radio_group(const RadioGroup
& radio_group
) {
146 bubble_content_
.radio_group
= radio_group
;
148 void set_radio_group_enabled(bool enabled
) {
149 bubble_content_
.radio_group_enabled
= enabled
;
151 void add_domain_list(const DomainList
& domain_list
) {
152 bubble_content_
.domain_lists
.push_back(domain_list
);
154 void set_custom_link(const std::string
& link
) {
155 bubble_content_
.custom_link
= link
;
157 void set_custom_link_enabled(bool enabled
) {
158 bubble_content_
.custom_link_enabled
= enabled
;
160 void set_manage_link(const std::string
& link
) {
161 bubble_content_
.manage_link
= link
;
163 void set_learn_more_link(const std::string
& link
) {
164 bubble_content_
.learn_more_link
= link
;
166 void add_media_menu(content::MediaStreamType type
, const MediaMenu
& menu
) {
167 bubble_content_
.media_menus
[type
] = menu
;
169 void set_selected_device(const content::MediaStreamDevice
& device
) {
170 bubble_content_
.media_menus
[device
.type
].selected_device
= device
;
172 bool setting_is_managed() {
173 return setting_is_managed_
;
175 void set_setting_is_managed(bool managed
) {
176 setting_is_managed_
= managed
;
180 content::WebContents
* web_contents_
;
182 ContentSettingsType content_type_
;
183 BubbleContent bubble_content_
;
184 // A registrar for listening for WEB_CONTENTS_DESTROYED notifications.
185 content::NotificationRegistrar registrar_
;
186 // A flag that indicates if the content setting managed i.e. can't be
187 // controlled by the user.
188 bool setting_is_managed_
;
190 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleModel
);
193 class ContentSettingTitleAndLinkModel
: public ContentSettingBubbleModel
{
195 ContentSettingTitleAndLinkModel(Delegate
* delegate
,
196 content::WebContents
* web_contents
,
198 ContentSettingsType content_type
);
199 ~ContentSettingTitleAndLinkModel() override
{}
200 Delegate
* delegate() const { return delegate_
; }
204 void SetManageLink();
205 void SetLearnMoreLink();
207 // content::ContentSettingBubbleModel:
208 void OnManageLinkClicked() override
;
209 void OnLearnMoreLinkClicked() override
;
213 // RPH stands for Register Protocol Handler.
214 class ContentSettingRPHBubbleModel
: public ContentSettingTitleAndLinkModel
{
216 ContentSettingRPHBubbleModel(Delegate
* delegate
,
217 content::WebContents
* web_contents
,
219 ProtocolHandlerRegistry
* registry
);
221 void OnRadioClicked(int radio_index
) override
;
222 void OnDoneClicked() override
;
225 void RegisterProtocolHandler();
226 void UnregisterProtocolHandler();
227 void IgnoreProtocolHandler();
228 void ClearOrSetPreviousHandler();
231 ProtocolHandlerRegistry
* registry_
;
232 ProtocolHandler pending_handler_
;
233 ProtocolHandler previous_handler_
;
236 #endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_