Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / content_settings / content_setting_bubble_model.h
blobb6b9f7b19520efe47a9d66d3b5452667ae5f6ccf
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 static ContentSettingBubbleModel* CreateContentSettingBubbleModel(
101 Delegate* delegate,
102 content::WebContents* web_contents,
103 Profile* profile,
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
126 // Done button.
127 virtual void OnDoneClicked() {}
129 protected:
130 ContentSettingBubbleModel(
131 content::WebContents* web_contents,
132 Profile* profile,
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;
176 private:
177 content::WebContents* web_contents_;
178 Profile* profile_;
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 {
191 public:
192 ContentSettingTitleAndLinkModel(Delegate* delegate,
193 content::WebContents* web_contents,
194 Profile* profile,
195 ContentSettingsType content_type);
196 ~ContentSettingTitleAndLinkModel() override {}
197 Delegate* delegate() const { return delegate_; }
199 private:
200 void SetTitle();
201 void SetManageLink();
202 void SetLearnMoreLink();
204 // content::ContentSettingBubbleModel:
205 void OnManageLinkClicked() override;
206 void OnLearnMoreLinkClicked() override;
207 Delegate* delegate_;
210 // RPH stands for Register Protocol Handler.
211 class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel {
212 public:
213 ContentSettingRPHBubbleModel(Delegate* delegate,
214 content::WebContents* web_contents,
215 Profile* profile,
216 ProtocolHandlerRegistry* registry);
218 void OnRadioClicked(int radio_index) override;
219 void OnDoneClicked() override;
221 private:
222 void RegisterProtocolHandler();
223 void UnregisterProtocolHandler();
224 void IgnoreProtocolHandler();
225 void ClearOrSetPreviousHandler();
227 int selected_item_;
228 ProtocolHandlerRegistry* registry_;
229 ProtocolHandler pending_handler_;
230 ProtocolHandler previous_handler_;
233 #endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_