Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / content_settings / content_setting_bubble_model.h
blobf6a1a17477a0a4c374b16653cee6a7848666540e
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_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
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"
21 #include "url/gurl.h"
23 class ContentSettingBubbleModelDelegate;
24 class Profile;
25 class ProtocolHandlerRegistry;
27 namespace content {
28 class WebContents;
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 {
34 public:
35 typedef ContentSettingBubbleModelDelegate Delegate;
37 struct ListItem {
38 ListItem(const gfx::Image& image,
39 const std::string& title,
40 bool has_link,
41 int32 item_id)
42 : image(image), title(title), has_link(has_link), item_id(item_id) {}
44 gfx::Image image;
45 std::string title;
46 bool has_link;
47 int32 item_id;
49 typedef std::vector<ListItem> ListItems;
51 typedef std::vector<std::string> RadioItems;
52 struct RadioGroup {
53 RadioGroup();
54 ~RadioGroup();
56 GURL url;
57 std::string title;
58 RadioItems radio_items;
59 int default_item;
62 struct DomainList {
63 DomainList();
64 ~DomainList();
66 std::string title;
67 std::set<std::string> hosts;
70 struct MediaMenu {
71 MediaMenu();
72 ~MediaMenu();
74 std::string label;
75 content::MediaStreamDevice default_device;
76 content::MediaStreamDevice selected_device;
77 bool disabled;
79 typedef std::map<content::MediaStreamType, MediaMenu> MediaMenuMap;
81 struct BubbleContent {
82 BubbleContent();
83 ~BubbleContent();
85 std::string title;
86 ListItems list_items;
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;
96 private:
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(
104 Delegate* delegate,
105 content::WebContents* web_contents,
106 Profile* profile,
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
129 // Done button.
130 virtual void OnDoneClicked() {}
132 protected:
133 ContentSettingBubbleModel(
134 content::WebContents* web_contents,
135 Profile* profile,
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;
179 private:
180 content::WebContents* web_contents_;
181 Profile* profile_;
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 {
194 public:
195 ContentSettingTitleAndLinkModel(Delegate* delegate,
196 content::WebContents* web_contents,
197 Profile* profile,
198 ContentSettingsType content_type);
199 ~ContentSettingTitleAndLinkModel() override {}
200 Delegate* delegate() const { return delegate_; }
202 private:
203 void SetTitle();
204 void SetManageLink();
205 void SetLearnMoreLink();
207 // content::ContentSettingBubbleModel:
208 void OnManageLinkClicked() override;
209 void OnLearnMoreLinkClicked() override;
210 Delegate* delegate_;
213 // RPH stands for Register Protocol Handler.
214 class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel {
215 public:
216 ContentSettingRPHBubbleModel(Delegate* delegate,
217 content::WebContents* web_contents,
218 Profile* profile,
219 ProtocolHandlerRegistry* registry);
221 void OnRadioClicked(int radio_index) override;
222 void OnDoneClicked() override;
224 private:
225 void RegisterProtocolHandler();
226 void UnregisterProtocolHandler();
227 void IgnoreProtocolHandler();
228 void ClearOrSetPreviousHandler();
230 int selected_item_;
231 ProtocolHandlerRegistry* registry_;
232 ProtocolHandler pending_handler_;
233 ProtocolHandler previous_handler_;
236 #endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_