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/browser/content_settings/tab_specific_content_settings.h"
15 #include "chrome/common/content_settings.h"
16 #include "chrome/common/custom_handlers/protocol_handler.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 PopupItem(const gfx::Image
& image
, const std::string
& title
, int32 popup_id
)
39 : image(image
), title(title
), popup_id(popup_id
) {}
45 typedef std::vector
<PopupItem
> PopupItems
;
47 typedef std::vector
<std::string
> RadioItems
;
54 RadioItems radio_items
;
63 std::set
<std::string
> hosts
;
71 content::MediaStreamDevice default_device
;
72 content::MediaStreamDevice selected_device
;
75 typedef std::map
<content::MediaStreamType
, MediaMenu
> MediaMenuMap
;
77 struct BubbleContent
{
82 PopupItems popup_items
;
83 RadioGroup radio_group
;
84 bool radio_group_enabled
;
85 std::vector
<DomainList
> domain_lists
;
86 std::string custom_link
;
87 bool custom_link_enabled
;
88 std::string manage_link
;
89 MediaMenuMap media_menus
;
92 DISALLOW_COPY_AND_ASSIGN(BubbleContent
);
95 static ContentSettingBubbleModel
* CreateContentSettingBubbleModel(
97 content::WebContents
* web_contents
,
99 ContentSettingsType content_type
);
101 virtual ~ContentSettingBubbleModel();
103 ContentSettingsType
content_type() const { return content_type_
; }
105 const BubbleContent
& bubble_content() const { return bubble_content_
; }
107 // content::NotificationObserver:
108 virtual void Observe(int type
,
109 const content::NotificationSource
& source
,
110 const content::NotificationDetails
& details
) OVERRIDE
;
112 virtual void OnRadioClicked(int radio_index
) {}
113 virtual void OnPopupClicked(int index
) {}
114 virtual void OnCustomLinkClicked() {}
115 virtual void OnManageLinkClicked() {}
116 virtual void OnMediaMenuClicked(content::MediaStreamType type
,
117 const std::string
& selected_device_id
) {}
119 // Called by the view code when the bubble is closed by the user using the
121 virtual void OnDoneClicked() {}
124 ContentSettingBubbleModel(
125 content::WebContents
* web_contents
,
127 ContentSettingsType content_type
);
129 content::WebContents
* web_contents() const { return web_contents_
; }
130 Profile
* profile() const { return profile_
; }
132 void set_title(const std::string
& title
) { bubble_content_
.title
= title
; }
133 void add_popup(const PopupItem
& popup
) {
134 bubble_content_
.popup_items
.push_back(popup
);
136 void set_radio_group(const RadioGroup
& radio_group
) {
137 bubble_content_
.radio_group
= radio_group
;
139 void set_radio_group_enabled(bool enabled
) {
140 bubble_content_
.radio_group_enabled
= enabled
;
142 void add_domain_list(const DomainList
& domain_list
) {
143 bubble_content_
.domain_lists
.push_back(domain_list
);
145 void set_custom_link(const std::string
& link
) {
146 bubble_content_
.custom_link
= link
;
148 void set_custom_link_enabled(bool enabled
) {
149 bubble_content_
.custom_link_enabled
= enabled
;
151 void set_manage_link(const std::string
& link
) {
152 bubble_content_
.manage_link
= link
;
154 void add_media_menu(content::MediaStreamType type
, const MediaMenu
& menu
) {
155 bubble_content_
.media_menus
[type
] = menu
;
157 void set_selected_device(const content::MediaStreamDevice
& device
) {
158 bubble_content_
.media_menus
[device
.type
].selected_device
= device
;
160 bool setting_is_managed() {
161 return setting_is_managed_
;
163 void set_setting_is_managed(bool managed
) {
164 setting_is_managed_
= managed
;
168 content::WebContents
* web_contents_
;
170 ContentSettingsType content_type_
;
171 BubbleContent bubble_content_
;
172 // A registrar for listening for WEB_CONTENTS_DESTROYED notifications.
173 content::NotificationRegistrar registrar_
;
174 // A flag that indicates if the content setting managed i.e. can't be
175 // controlled by the user.
176 bool setting_is_managed_
;
178 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleModel
);
181 class ContentSettingTitleAndLinkModel
: public ContentSettingBubbleModel
{
183 ContentSettingTitleAndLinkModel(Delegate
* delegate
,
184 content::WebContents
* web_contents
,
186 ContentSettingsType content_type
);
187 virtual ~ContentSettingTitleAndLinkModel() {}
188 Delegate
* delegate() const { return delegate_
; }
192 void SetManageLink();
193 virtual void OnManageLinkClicked() OVERRIDE
;
198 class ContentSettingRPHBubbleModel
: public ContentSettingTitleAndLinkModel
{
200 ContentSettingRPHBubbleModel(Delegate
* delegate
,
201 content::WebContents
* web_contents
,
203 ProtocolHandlerRegistry
* registry
,
204 ContentSettingsType content_type
);
206 virtual void OnRadioClicked(int radio_index
) OVERRIDE
;
207 virtual void OnDoneClicked() OVERRIDE
;
210 // These states must match the order of appearance of the radio buttons
211 // in the XIB file for the Mac port.
218 void RegisterProtocolHandler();
219 void UnregisterProtocolHandler();
220 void IgnoreProtocolHandler();
221 void ClearOrSetPreviousHandler();
224 ProtocolHandlerRegistry
* registry_
;
225 ProtocolHandler pending_handler_
;
226 ProtocolHandler previous_handler_
;
229 #endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_