Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model.cc

Issue 10546083: Convert ProtocolHandlerRegistry to be a ProfileKeyedService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update content_setting_bubble_model tests to use injected ProtocolHandlerRegistry (integrating Greg… Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/content_settings/content_settings_utils.h" 8 #include "chrome/browser/content_settings/content_settings_utils.h"
9 #include "chrome/browser/content_settings/cookie_settings.h" 9 #include "chrome/browser/content_settings/cookie_settings.h"
10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 ContentSettingsType type) { 49 ContentSettingsType type) {
50 for (size_t i = 0; i < num_entries; ++i) { 50 for (size_t i = 0; i < num_entries; ++i) {
51 if (entries[i].type == type) 51 if (entries[i].type == type)
52 return entries[i].id; 52 return entries[i].id;
53 } 53 }
54 return 0; 54 return 0;
55 } 55 }
56 56
57 } // namespace 57 } // namespace
58 58
59 class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { 59 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel(
60 public: 60 Delegate* delegate,
61 ContentSettingTitleAndLinkModel(Delegate* delegate, 61 TabContents* tab_contents,
62 TabContents* tab_contents, 62 Profile* profile,
63 Profile* profile, 63 ContentSettingsType content_type)
64 ContentSettingsType content_type) 64 : ContentSettingBubbleModel(tab_contents, profile, content_type),
65 : ContentSettingBubbleModel(tab_contents, profile, content_type),
66 delegate_(delegate) { 65 delegate_(delegate) {
67 // Notifications do not have a bubble. 66 // Notifications do not have a bubble.
68 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 67 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
69 SetBlockedResources(); 68 SetBlockedResources();
70 SetTitle(); 69 SetTitle();
71 SetManageLink(); 70 SetManageLink();
71 }
72
73 void ContentSettingTitleAndLinkModel::SetBlockedResources() {
74 TabSpecificContentSettings* settings = tab_contents()->content_settings();
75 const std::set<std::string>& resources = settings->BlockedResourcesForType(
76 content_type());
77 for (std::set<std::string>::const_iterator it = resources.begin();
78 it != resources.end(); ++it) {
79 AddBlockedResource(*it);
72 } 80 }
81 }
73 82
74 virtual ~ContentSettingTitleAndLinkModel() {} 83 void ContentSettingTitleAndLinkModel::SetTitle() {
75 Delegate* delegate() const { return delegate_; } 84 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = {
85 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE},
86 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE},
87 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE},
88 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE},
89 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE},
90 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
91 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT},
92 };
93 // Fields as for kBlockedTitleIDs, above.
94 static const ContentSettingsTypeIdEntry
95 kResourceSpecificBlockedTitleIDs[] = {
96 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE},
97 };
98 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = {
99 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE},
100 };
101 const ContentSettingsTypeIdEntry *title_ids = kBlockedTitleIDs;
102 size_t num_title_ids = arraysize(kBlockedTitleIDs);
103 if (tab_contents() && tab_contents()->content_settings()->
104 IsContentAccessed(content_type()) &&
105 !tab_contents()->content_settings()->IsContentBlocked(content_type())) {
106 title_ids = kAccessedTitleIDs;
107 num_title_ids = arraysize(kAccessedTitleIDs);
108 } else if (!bubble_content().resource_identifiers.empty()) {
109 title_ids = kResourceSpecificBlockedTitleIDs;
110 num_title_ids = arraysize(kResourceSpecificBlockedTitleIDs);
111 }
112 int title_id =
113 GetIdForContentType(title_ids, num_title_ids, content_type());
114 if (title_id)
115 set_title(l10n_util::GetStringUTF8(title_id));
116 }
76 117
77 private: 118 void ContentSettingTitleAndLinkModel::SetManageLink() {
78 void SetBlockedResources() { 119 static const ContentSettingsTypeIdEntry kLinkIDs[] = {
79 TabSpecificContentSettings* settings = tab_contents()->content_settings(); 120 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK},
80 const std::set<std::string>& resources = settings->BlockedResourcesForType( 121 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK},
81 content_type()); 122 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK},
82 for (std::set<std::string>::const_iterator it = resources.begin(); 123 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK},
83 it != resources.end(); ++it) { 124 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK},
84 AddBlockedResource(*it); 125 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK},
85 } 126 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE},
86 } 127 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}
128 };
129 set_manage_link(l10n_util::GetStringUTF8(
130 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type())));
131 }
87 132
88 void SetTitle() { 133 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() {
89 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { 134 if (delegate_)
90 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, 135 delegate_->ShowContentSettingsPage(content_type());
91 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, 136 }
92 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE},
93 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE},
94 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE},
95 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
96 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT},
97 };
98 // Fields as for kBlockedTitleIDs, above.
99 static const ContentSettingsTypeIdEntry
100 kResourceSpecificBlockedTitleIDs[] = {
101 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE},
102 };
103 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = {
104 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE},
105 };
106 const ContentSettingsTypeIdEntry *title_ids = kBlockedTitleIDs;
107 size_t num_title_ids = arraysize(kBlockedTitleIDs);
108 if (tab_contents() && tab_contents()->content_settings()->
109 IsContentAccessed(content_type()) &&
110 !tab_contents()->content_settings()->IsContentBlocked(content_type())) {
111 title_ids = kAccessedTitleIDs;
112 num_title_ids = arraysize(kAccessedTitleIDs);
113 } else if (!bubble_content().resource_identifiers.empty()) {
114 title_ids = kResourceSpecificBlockedTitleIDs;
115 num_title_ids = arraysize(kResourceSpecificBlockedTitleIDs);
116 }
117 int title_id =
118 GetIdForContentType(title_ids, num_title_ids, content_type());
119 if (title_id)
120 set_title(l10n_util::GetStringUTF8(title_id));
121 }
122
123 void SetManageLink() {
124 static const ContentSettingsTypeIdEntry kLinkIDs[] = {
125 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK},
126 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK},
127 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK},
128 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK},
129 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK},
130 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK},
131 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE},
132 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}
133 };
134 set_manage_link(l10n_util::GetStringUTF8(
135 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type())));
136 }
137
138 virtual void OnManageLinkClicked() {
139 if (delegate_)
140 delegate_->ShowContentSettingsPage(content_type());
141 }
142
143 Delegate* delegate_;
144 };
145 137
146 class ContentSettingTitleLinkAndCustomModel 138 class ContentSettingTitleLinkAndCustomModel
147 : public ContentSettingTitleAndLinkModel { 139 : public ContentSettingTitleAndLinkModel {
148 public: 140 public:
149 ContentSettingTitleLinkAndCustomModel(Delegate* delegate, 141 ContentSettingTitleLinkAndCustomModel(Delegate* delegate,
150 TabContents* tab_contents, 142 TabContents* tab_contents,
151 Profile* profile, 143 Profile* profile,
152 ContentSettingsType content_type) 144 ContentSettingsType content_type);
153 : ContentSettingTitleAndLinkModel(
154 delegate, tab_contents, profile, content_type) {
155 SetCustomLink();
156 }
157
158 virtual ~ContentSettingTitleLinkAndCustomModel() {} 145 virtual ~ContentSettingTitleLinkAndCustomModel() {}
159 146
160 private: 147 private:
161 void SetCustomLink() { 148 void SetCustomLink();
162 static const ContentSettingsTypeIdEntry kCustomIDs[] = {
163 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_INFO},
164 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LOAD_ALL},
165 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_ALLOW_INSECURE_CONTENT_BUTTON},
166 };
167 int custom_link_id =
168 GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type());
169 if (custom_link_id)
170 set_custom_link(l10n_util::GetStringUTF8(custom_link_id));
171 }
172
173 virtual void OnCustomLinkClicked() {} 149 virtual void OnCustomLinkClicked() {}
174 }; 150 };
175 151
152 ContentSettingTitleLinkAndCustomModel::ContentSettingTitleLinkAndCustomModel(
153 Delegate* delegate,
154 TabContents* tab_contents,
155 Profile* profile,
156 ContentSettingsType content_type)
157 : ContentSettingTitleAndLinkModel(
158 delegate, tab_contents, profile, content_type) {
159 SetCustomLink();
160 }
161
162 void ContentSettingTitleLinkAndCustomModel::SetCustomLink() {
163 static const ContentSettingsTypeIdEntry kCustomIDs[] = {
164 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_INFO},
165 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LOAD_ALL},
166 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_ALLOW_INSECURE_CONTENT_BUTTON},
167 };
168 int custom_link_id =
169 GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type());
170 if (custom_link_id)
171 set_custom_link(l10n_util::GetStringUTF8(custom_link_id));
172 }
176 173
177 class ContentSettingSingleRadioGroup 174 class ContentSettingSingleRadioGroup
178 : public ContentSettingTitleLinkAndCustomModel { 175 : public ContentSettingTitleLinkAndCustomModel {
179 public: 176 public:
180 ContentSettingSingleRadioGroup(Delegate* delegate, 177 ContentSettingSingleRadioGroup(Delegate* delegate,
181 TabContents* tab_contents, 178 TabContents* tab_contents,
182 Profile* profile, 179 Profile* profile,
183 ContentSettingsType content_type) 180 ContentSettingsType content_type);
184 : ContentSettingTitleLinkAndCustomModel(delegate, tab_contents, profile, 181 virtual ~ContentSettingSingleRadioGroup();
185 content_type), 182
186 block_setting_(CONTENT_SETTING_BLOCK), 183 protected:
187 selected_item_(0) { 184 bool settings_changed() const;
188 SetRadioGroup(); 185
189 } 186 private:
190 187 void SetRadioGroup();
191 virtual ~ContentSettingSingleRadioGroup() { 188 void AddException(ContentSetting setting,
192 if (settings_changed()) { 189 const std::string& resource_identifier);
193 ContentSetting setting = 190 virtual void OnRadioClicked(int radio_index);
194 selected_item_ == 0 ? CONTENT_SETTING_ALLOW : block_setting_; 191
195 const std::set<std::string>& resources = 192 ContentSetting block_setting_;
196 bubble_content().resource_identifiers; 193 int selected_item_;
197 if (resources.empty()) { 194 };
198 AddException(setting, std::string()); 195
199 } else { 196 ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup(
200 for (std::set<std::string>::const_iterator it = resources.begin(); 197 Delegate* delegate,
201 it != resources.end(); ++it) { 198 TabContents* tab_contents,
202 AddException(setting, *it); 199 Profile* profile,
203 } 200 ContentSettingsType content_type)
201 : ContentSettingTitleLinkAndCustomModel(delegate, tab_contents, profile,
202 content_type),
203 block_setting_(CONTENT_SETTING_BLOCK),
204 selected_item_(0) {
205 SetRadioGroup();
206 }
207
208 ContentSettingSingleRadioGroup::~ContentSettingSingleRadioGroup() {
209 if (settings_changed()) {
210 ContentSetting setting =
211 selected_item_ == 0 ? CONTENT_SETTING_ALLOW : block_setting_;
212 const std::set<std::string>& resources =
213 bubble_content().resource_identifiers;
214 if (resources.empty()) {
215 AddException(setting, std::string());
216 } else {
217 for (std::set<std::string>::const_iterator it = resources.begin();
218 it != resources.end(); ++it) {
219 AddException(setting, *it);
204 } 220 }
205 } 221 }
206 } 222 }
207 223 }
208 protected: 224
209 bool settings_changed() const { 225 bool ContentSettingSingleRadioGroup::settings_changed() const {
210 return selected_item_ != bubble_content().radio_group.default_item; 226 return selected_item_ != bubble_content().radio_group.default_item;
211 } 227 }
212 228
213 private: 229 // Initialize the radio group by setting the appropriate labels for the
214 ContentSetting block_setting_; 230 // content type and setting the default value based on the content setting.
215 int selected_item_; 231 void ContentSettingSingleRadioGroup::SetRadioGroup() {
216 232 GURL url = tab_contents()->web_contents()->GetURL();
217 // Initialize the radio group by setting the appropriate labels for the 233 string16 display_host_utf16;
218 // content type and setting the default value based on the content setting. 234 net::AppendFormattedHost(
219 void SetRadioGroup() { 235 url,
220 GURL url = tab_contents()->web_contents()->GetURL(); 236 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
221 string16 display_host_utf16; 237 &display_host_utf16);
222 net::AppendFormattedHost(url, 238 std::string display_host(UTF16ToUTF8(display_host_utf16));
223 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), 239
224 &display_host_utf16); 240 if (display_host.empty())
225 std::string display_host(UTF16ToUTF8(display_host_utf16)); 241 display_host = url.spec();
226 242
227 if (display_host.empty()) 243 const std::set<std::string>& resources =
228 display_host = url.spec(); 244 bubble_content().resource_identifiers;
229 245
230 const std::set<std::string>& resources = 246 RadioGroup radio_group;
231 bubble_content().resource_identifiers; 247 radio_group.url = url;
232 248
233 RadioGroup radio_group; 249 static const ContentSettingsTypeIdEntry kAllowIDs[] = {
234 radio_group.url = url; 250 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK},
235 251 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK},
236 static const ContentSettingsTypeIdEntry kAllowIDs[] = { 252 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK},
237 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, 253 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL},
238 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, 254 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK},
239 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, 255 };
240 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, 256 // Fields as for kAllowIDs, above.
241 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, 257 static const ContentSettingsTypeIdEntry kResourceSpecificAllowIDs[] = {
242 }; 258 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK},
243 // Fields as for kAllowIDs, above. 259 };
244 static const ContentSettingsTypeIdEntry kResourceSpecificAllowIDs[] = { 260 std::string radio_allow_label;
245 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK}, 261 const ContentSettingsTypeIdEntry* allow_ids = resources.empty() ?
246 }; 262 kAllowIDs : kResourceSpecificAllowIDs;
247 std::string radio_allow_label; 263 size_t num_allow_ids = resources.empty() ?
248 const ContentSettingsTypeIdEntry* allow_ids = resources.empty() ? 264 arraysize(kAllowIDs) : arraysize(kResourceSpecificAllowIDs);
249 kAllowIDs : kResourceSpecificAllowIDs; 265 radio_allow_label = l10n_util::GetStringFUTF8(
250 size_t num_allow_ids = resources.empty() ? 266 GetIdForContentType(allow_ids, num_allow_ids, content_type()),
251 arraysize(kAllowIDs) : arraysize(kResourceSpecificAllowIDs); 267 UTF8ToUTF16(display_host));
252 radio_allow_label = l10n_util::GetStringFUTF8( 268
253 GetIdForContentType(allow_ids, num_allow_ids, content_type()), 269 static const ContentSettingsTypeIdEntry kBlockIDs[] = {
254 UTF8ToUTF16(display_host)); 270 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION},
255 271 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION},
256 static const ContentSettingsTypeIdEntry kBlockIDs[] = { 272 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION},
257 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, 273 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION},
258 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, 274 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION},
259 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION}, 275 };
260 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION}, 276 std::string radio_block_label;
261 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION}, 277 radio_block_label = l10n_util::GetStringUTF8(
262 }; 278 GetIdForContentType(kBlockIDs, arraysize(kBlockIDs), content_type()));
263 std::string radio_block_label; 279
264 radio_block_label = l10n_util::GetStringUTF8( 280 radio_group.radio_items.push_back(radio_allow_label);
265 GetIdForContentType(kBlockIDs, arraysize(kBlockIDs), content_type())); 281 radio_group.radio_items.push_back(radio_block_label);
266 282 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
267 radio_group.radio_items.push_back(radio_allow_label); 283 CookieSettings* cookie_settings =
268 radio_group.radio_items.push_back(radio_block_label); 284 CookieSettings::Factory::GetForProfile(profile());
269 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); 285 ContentSetting most_restrictive_setting;
270 CookieSettings* cookie_settings = 286 SettingSource most_restrictive_setting_source = SETTING_SOURCE_NONE;
271 CookieSettings::Factory::GetForProfile(profile()); 287
272 ContentSetting most_restrictive_setting; 288 if (resources.empty()) {
273 SettingSource most_restrictive_setting_source = SETTING_SOURCE_NONE; 289 if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) {
274 290 most_restrictive_setting = cookie_settings->GetCookieSetting(
275 if (resources.empty()) { 291 url, url, true, &most_restrictive_setting_source);
276 if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) { 292 } else {
277 most_restrictive_setting = cookie_settings->GetCookieSetting( 293 SettingInfo info;
278 url, url, true, &most_restrictive_setting_source); 294 scoped_ptr<Value> value(map->GetWebsiteSetting(
279 } else { 295 url, url, content_type(), std::string(), &info));
280 SettingInfo info; 296 most_restrictive_setting =
281 scoped_ptr<Value> value(map->GetWebsiteSetting( 297 content_settings::ValueToContentSetting(value.get());
282 url, url, content_type(), std::string(), &info)); 298 most_restrictive_setting_source = info.source;
283 most_restrictive_setting = 299 }
284 content_settings::ValueToContentSetting(value.get()); 300 } else {
301 most_restrictive_setting = CONTENT_SETTING_ALLOW;
302 for (std::set<std::string>::const_iterator it = resources.begin();
303 it != resources.end(); ++it) {
304 SettingInfo info;
305 scoped_ptr<Value> value(map->GetWebsiteSetting(
306 url, url, content_type(), *it, &info));
307 ContentSetting setting =
308 content_settings::ValueToContentSetting(value.get());
309 if (setting == CONTENT_SETTING_BLOCK) {
310 most_restrictive_setting = CONTENT_SETTING_BLOCK;
311 most_restrictive_setting_source = info.source;
312 break;
313 }
314 if (setting == CONTENT_SETTING_ASK) {
315 most_restrictive_setting = CONTENT_SETTING_ASK;
285 most_restrictive_setting_source = info.source; 316 most_restrictive_setting_source = info.source;
286 } 317 }
287 } else {
288 most_restrictive_setting = CONTENT_SETTING_ALLOW;
289 for (std::set<std::string>::const_iterator it = resources.begin();
290 it != resources.end(); ++it) {
291 SettingInfo info;
292 scoped_ptr<Value> value(map->GetWebsiteSetting(
293 url, url, content_type(), *it, &info));
294 ContentSetting setting =
295 content_settings::ValueToContentSetting(value.get());
296 if (setting == CONTENT_SETTING_BLOCK) {
297 most_restrictive_setting = CONTENT_SETTING_BLOCK;
298 most_restrictive_setting_source = info.source;
299 break;
300 }
301 if (setting == CONTENT_SETTING_ASK) {
302 most_restrictive_setting = CONTENT_SETTING_ASK;
303 most_restrictive_setting_source = info.source;
304 }
305 }
306 } 318 }
307 if (most_restrictive_setting == CONTENT_SETTING_ALLOW) { 319 }
308 radio_group.default_item = 0; 320 if (most_restrictive_setting == CONTENT_SETTING_ALLOW) {
309 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. 321 radio_group.default_item = 0;
310 } else { 322 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|.
311 radio_group.default_item = 1; 323 } else {
312 block_setting_ = most_restrictive_setting; 324 radio_group.default_item = 1;
313 } 325 block_setting_ = most_restrictive_setting;
314 if (most_restrictive_setting_source != SETTING_SOURCE_USER) { 326 }
315 set_radio_group_enabled(false); 327 if (most_restrictive_setting_source != SETTING_SOURCE_USER) {
316 } else { 328 set_radio_group_enabled(false);
317 set_radio_group_enabled(true); 329 } else {
318 } 330 set_radio_group_enabled(true);
319 selected_item_ = radio_group.default_item; 331 }
320 set_radio_group(radio_group); 332 selected_item_ = radio_group.default_item;
321 } 333 set_radio_group(radio_group);
322 334 }
323 void AddException(ContentSetting setting, 335
324 const std::string& resource_identifier) { 336 void ContentSettingSingleRadioGroup::AddException(
325 if (profile()) { 337 ContentSetting setting,
326 profile()->GetHostContentSettingsMap()->AddExceptionForURL( 338 const std::string& resource_identifier) {
327 bubble_content().radio_group.url, 339 if (profile()) {
328 bubble_content().radio_group.url, 340 profile()->GetHostContentSettingsMap()->AddExceptionForURL(
329 content_type(), 341 bubble_content().radio_group.url,
330 resource_identifier, 342 bubble_content().radio_group.url,
331 setting); 343 content_type(),
332 } 344 resource_identifier,
333 } 345 setting);
334 346 }
335 virtual void OnRadioClicked(int radio_index) { 347 }
336 selected_item_ = radio_index; 348
337 } 349 void ContentSettingSingleRadioGroup::OnRadioClicked(int radio_index) {
338 }; 350 selected_item_ = radio_index;
351 }
339 352
340 class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { 353 class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup {
341 public: 354 public:
342 ContentSettingCookiesBubbleModel(Delegate* delegate, 355 ContentSettingCookiesBubbleModel(Delegate* delegate,
343 TabContents* tab_contents, 356 TabContents* tab_contents,
344 Profile* profile, 357 Profile* profile,
345 ContentSettingsType content_type) 358 ContentSettingsType content_type);
346 : ContentSettingSingleRadioGroup( 359
347 delegate, tab_contents, profile, content_type) { 360 virtual ~ContentSettingCookiesBubbleModel();
348 DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type);
349 set_custom_link_enabled(true);
350 }
351
352 virtual ~ContentSettingCookiesBubbleModel() {
353 if (settings_changed()) {
354 InfoBarTabHelper* infobar_helper = tab_contents()->infobar_tab_helper();
355 infobar_helper->AddInfoBar(
356 new CollectedCookiesInfoBarDelegate(infobar_helper));
357 }
358 }
359 361
360 private: 362 private:
361 virtual void OnCustomLinkClicked() OVERRIDE { 363 virtual void OnCustomLinkClicked() OVERRIDE;
362 if (!tab_contents())
363 return;
364 content::NotificationService::current()->Notify(
365 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN,
366 content::Source<TabSpecificContentSettings>(
367 tab_contents()->content_settings()),
368 content::NotificationService::NoDetails());
369 delegate()->ShowCollectedCookiesDialog(tab_contents());
370 }
371 }; 364 };
372 365
366 ContentSettingCookiesBubbleModel::ContentSettingCookiesBubbleModel(
367 Delegate* delegate,
368 TabContents* tab_contents,
369 Profile* profile,
370 ContentSettingsType content_type)
371 : ContentSettingSingleRadioGroup(
372 delegate, tab_contents, profile, content_type) {
373 DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type);
374 set_custom_link_enabled(true);
375 }
376
377 ContentSettingCookiesBubbleModel::~ContentSettingCookiesBubbleModel() {
378 if (settings_changed()) {
379 InfoBarTabHelper* infobar_helper = tab_contents()->infobar_tab_helper();
380 infobar_helper->AddInfoBar(
381 new CollectedCookiesInfoBarDelegate(infobar_helper));
382 }
383 }
384
385 void ContentSettingCookiesBubbleModel::OnCustomLinkClicked() {
386 if (!tab_contents())
387 return;
388 content::NotificationService::current()->Notify(
389 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN,
390 content::Source<TabSpecificContentSettings>(
391 tab_contents()->content_settings()),
392 content::NotificationService::NoDetails());
393 delegate()->ShowCollectedCookiesDialog(tab_contents());
394 }
395
373 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { 396 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup {
374 public: 397 public:
375 ContentSettingPluginBubbleModel(Delegate* delegate, 398 ContentSettingPluginBubbleModel(Delegate* delegate,
376 TabContents* tab_contents, 399 TabContents* tab_contents,
377 Profile* profile, 400 Profile* profile,
378 ContentSettingsType content_type) 401 ContentSettingsType content_type);
379 : ContentSettingSingleRadioGroup(
380 delegate, tab_contents, profile, content_type) {
381 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS);
382 set_custom_link_enabled(tab_contents && tab_contents->content_settings()->
383 load_plugins_link_enabled());
384 }
385 402
386 virtual ~ContentSettingPluginBubbleModel() {} 403 virtual ~ContentSettingPluginBubbleModel() {}
387 404
388 private: 405 private:
389 virtual void OnCustomLinkClicked() OVERRIDE { 406 virtual void OnCustomLinkClicked() OVERRIDE;
390 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble"));
391 DCHECK(tab_contents());
392 content::RenderViewHost* host =
393 tab_contents()->web_contents()->GetRenderViewHost();
394 // TODO(bauerb): We should send the identifiers of blocked plug-ins here.
395 host->Send(new ChromeViewMsg_LoadBlockedPlugins(host->GetRoutingID(),
396 std::string()));
397 set_custom_link_enabled(false);
398 tab_contents()->content_settings()->set_load_plugins_link_enabled(false);
399 }
400 }; 407 };
401 408
409 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel(
410 Delegate* delegate,
411 TabContents* tab_contents,
412 Profile* profile,
413 ContentSettingsType content_type)
414 : ContentSettingSingleRadioGroup(
415 delegate, tab_contents, profile, content_type) {
416 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS);
417 set_custom_link_enabled(tab_contents && tab_contents->content_settings()->
418 load_plugins_link_enabled());
419 }
420
421 void ContentSettingPluginBubbleModel::OnCustomLinkClicked() {
422 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble"));
423 DCHECK(tab_contents());
424 content::RenderViewHost* host =
425 tab_contents()->web_contents()->GetRenderViewHost();
426 // TODO(bauerb): We should send the identifiers of blocked plug-ins here.
427 host->Send(new ChromeViewMsg_LoadBlockedPlugins(host->GetRoutingID(),
428 std::string()));
429 set_custom_link_enabled(false);
430 tab_contents()->content_settings()->set_load_plugins_link_enabled(false);
431 }
432
402 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { 433 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup {
403 public: 434 public:
404 ContentSettingPopupBubbleModel(Delegate* delegate, 435 ContentSettingPopupBubbleModel(Delegate* delegate,
405 TabContents* tab_contents, 436 TabContents* tab_contents,
406 Profile* profile, 437 Profile* profile,
407 ContentSettingsType content_type) 438 ContentSettingsType content_type);
408 : ContentSettingSingleRadioGroup(
409 delegate, tab_contents, profile, content_type) {
410 SetPopups();
411 }
412
413 virtual ~ContentSettingPopupBubbleModel() {} 439 virtual ~ContentSettingPopupBubbleModel() {}
414 440
415 private: 441 private:
416 void SetPopups() { 442 void SetPopups();
417 std::vector<TabContents*> blocked_contents; 443 virtual void OnPopupClicked(int index);
444 };
445
446 ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel(
447 Delegate* delegate,
448 TabContents* tab_contents,
449 Profile* profile,
450 ContentSettingsType content_type)
451 : ContentSettingSingleRadioGroup(
452 delegate, tab_contents, profile, content_type) {
453 SetPopups();
454 }
455
456
457 void ContentSettingPopupBubbleModel::SetPopups() {
458 std::vector<TabContents*> blocked_contents;
459 tab_contents()->blocked_content_tab_helper()->
460 GetBlockedContents(&blocked_contents);
461 for (std::vector<TabContents*>::const_iterator
462 i = blocked_contents.begin(); i != blocked_contents.end(); ++i) {
463 std::string title(UTF16ToUTF8((*i)->web_contents()->GetTitle()));
464 // The popup may not have committed a load yet, in which case it won't
465 // have a URL or title.
466 if (title.empty())
467 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE);
468 PopupItem popup_item;
469 popup_item.title = title;
470 popup_item.bitmap = (*i)->favicon_tab_helper()->GetFavicon();
471 popup_item.tab_contents = (*i);
472 add_popup(popup_item);
473 }
474 }
475
476 void ContentSettingPopupBubbleModel::OnPopupClicked(int index) {
477 if (tab_contents()) {
418 tab_contents()->blocked_content_tab_helper()-> 478 tab_contents()->blocked_content_tab_helper()->
419 GetBlockedContents(&blocked_contents); 479 LaunchForContents(bubble_content().popup_items[index].tab_contents);
420 for (std::vector<TabContents*>::const_iterator 480 }
421 i = blocked_contents.begin(); i != blocked_contents.end(); ++i) { 481 }
422 std::string title(UTF16ToUTF8((*i)->web_contents()->GetTitle()));
423 // The popup may not have committed a load yet, in which case it won't
424 // have a URL or title.
425 if (title.empty())
426 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE);
427 PopupItem popup_item;
428 popup_item.title = title;
429 popup_item.bitmap = (*i)->favicon_tab_helper()->GetFavicon();
430 popup_item.tab_contents = (*i);
431 add_popup(popup_item);
432 }
433 }
434
435 virtual void OnPopupClicked(int index) {
436 if (tab_contents()) {
437 tab_contents()->blocked_content_tab_helper()->
438 LaunchForContents(bubble_content().popup_items[index].tab_contents);
439 }
440 }
441 };
442 482
443 class ContentSettingDomainListBubbleModel 483 class ContentSettingDomainListBubbleModel
444 : public ContentSettingTitleAndLinkModel { 484 : public ContentSettingTitleAndLinkModel {
445 public: 485 public:
446 ContentSettingDomainListBubbleModel(Delegate* delegate, 486 ContentSettingDomainListBubbleModel(Delegate* delegate,
447 TabContents* tab_contents, 487 TabContents* tab_contents,
448 Profile* profile, 488 Profile* profile,
449 ContentSettingsType content_type) 489 ContentSettingsType content_type);
450 : ContentSettingTitleAndLinkModel(
451 delegate, tab_contents, profile, content_type) {
452 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) <<
453 "SetDomains currently only supports geolocation content type";
454 SetDomainsAndCustomLink();
455 }
456
457 virtual ~ContentSettingDomainListBubbleModel() {} 490 virtual ~ContentSettingDomainListBubbleModel() {}
458 491
459 private: 492 private:
460 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) { 493 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id);
461 if (!hosts.empty()) { 494 void SetDomainsAndCustomLink();
462 DomainList domain_list; 495 virtual void OnCustomLinkClicked() OVERRIDE;
463 domain_list.title = l10n_util::GetStringUTF8(title_id); 496 };
464 domain_list.hosts = hosts; 497
465 add_domain_list(domain_list); 498 ContentSettingDomainListBubbleModel::ContentSettingDomainListBubbleModel(
466 } 499 Delegate* delegate,
500 TabContents* tab_contents,
501 Profile* profile,
502 ContentSettingsType content_type)
503 : ContentSettingTitleAndLinkModel(
504 delegate, tab_contents, profile, content_type) {
505 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) <<
506 "SetDomains currently only supports geolocation content type";
507 SetDomainsAndCustomLink();
508 }
509
510 void ContentSettingDomainListBubbleModel::MaybeAddDomainList(
511 const std::set<std::string>& hosts, int title_id) {
512 if (!hosts.empty()) {
513 DomainList domain_list;
514 domain_list.title = l10n_util::GetStringUTF8(title_id);
515 domain_list.hosts = hosts;
516 add_domain_list(domain_list);
467 } 517 }
468 void SetDomainsAndCustomLink() { 518 }
469 TabSpecificContentSettings* content_settings =
470 tab_contents()->content_settings();
471 const GeolocationSettingsState& settings =
472 content_settings->geolocation_settings_state();
473 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state;
474 unsigned int tab_state_flags = 0;
475 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
476 // Divide the tab's current geolocation users into sets according to their
477 // permission state.
478 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
479 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED);
480 519
481 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], 520 void ContentSettingDomainListBubbleModel::SetDomainsAndCustomLink() {
482 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED); 521 TabSpecificContentSettings* content_settings =
522 tab_contents()->content_settings();
523 const GeolocationSettingsState& settings =
524 content_settings->geolocation_settings_state();
525 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state;
526 unsigned int tab_state_flags = 0;
527 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
528 // Divide the tab's current geolocation users into sets according to their
529 // permission state.
530 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
531 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED);
483 532
484 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) { 533 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK],
485 set_custom_link(l10n_util::GetStringUTF8( 534 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED);
486 IDS_GEOLOCATION_BUBBLE_CLEAR_LINK)); 535
487 set_custom_link_enabled(true); 536 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) {
488 } else if (tab_state_flags & 537 set_custom_link(l10n_util::GetStringUTF8(
489 GeolocationSettingsState::TABSTATE_HAS_CHANGED) { 538 IDS_GEOLOCATION_BUBBLE_CLEAR_LINK));
490 set_custom_link(l10n_util::GetStringUTF8( 539 set_custom_link_enabled(true);
491 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR)); 540 } else if (tab_state_flags &
492 } 541 GeolocationSettingsState::TABSTATE_HAS_CHANGED) {
542 set_custom_link(l10n_util::GetStringUTF8(
543 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR));
493 } 544 }
494 virtual void OnCustomLinkClicked() OVERRIDE { 545 }
495 if (!tab_contents())
496 return;
497 // Reset this embedder's entry to default for each of the requesting
498 // origins currently on the page.
499 const GURL& embedder_url = tab_contents()->web_contents()->GetURL();
500 TabSpecificContentSettings* content_settings =
501 tab_contents()->content_settings();
502 const GeolocationSettingsState::StateMap& state_map =
503 content_settings->geolocation_settings_state().state_map();
504 HostContentSettingsMap* settings_map =
505 profile()->GetHostContentSettingsMap();
506 546
507 for (GeolocationSettingsState::StateMap::const_iterator it = 547 void ContentSettingDomainListBubbleModel::OnCustomLinkClicked() {
508 state_map.begin(); it != state_map.end(); ++it) { 548 if (!tab_contents())
509 settings_map->SetContentSetting( 549 return;
510 ContentSettingsPattern::FromURLNoWildcard(it->first), 550 // Reset this embedder's entry to default for each of the requesting
511 ContentSettingsPattern::FromURLNoWildcard(embedder_url), 551 // origins currently on the page.
512 CONTENT_SETTINGS_TYPE_GEOLOCATION, 552 const GURL& embedder_url = tab_contents()->web_contents()->GetURL();
513 std::string(), 553 TabSpecificContentSettings* content_settings =
514 CONTENT_SETTING_DEFAULT); 554 tab_contents()->content_settings();
515 } 555 const GeolocationSettingsState::StateMap& state_map =
556 content_settings->geolocation_settings_state().state_map();
557 HostContentSettingsMap* settings_map =
558 profile()->GetHostContentSettingsMap();
559
560 for (GeolocationSettingsState::StateMap::const_iterator it =
561 state_map.begin(); it != state_map.end(); ++it) {
562 settings_map->SetContentSetting(
563 ContentSettingsPattern::FromURLNoWildcard(it->first),
564 ContentSettingsPattern::FromURLNoWildcard(embedder_url),
565 CONTENT_SETTINGS_TYPE_GEOLOCATION,
566 std::string(),
567 CONTENT_SETTING_DEFAULT);
516 } 568 }
517 }; 569 }
518 570
519 class ContentSettingMixedScriptBubbleModel 571 class ContentSettingMixedScriptBubbleModel
520 : public ContentSettingTitleLinkAndCustomModel { 572 : public ContentSettingTitleLinkAndCustomModel {
521 public: 573 public:
522 ContentSettingMixedScriptBubbleModel(Delegate* delegate, 574 ContentSettingMixedScriptBubbleModel(Delegate* delegate,
523 TabContents* tab_contents, 575 TabContents* tab_contents,
524 Profile* profile, 576 Profile* profile,
525 ContentSettingsType content_type); 577 ContentSettingsType content_type);
526 578
527 virtual ~ContentSettingMixedScriptBubbleModel() {} 579 virtual ~ContentSettingMixedScriptBubbleModel() {}
(...skipping 15 matching lines...) Expand all
543 595
544 void ContentSettingMixedScriptBubbleModel::OnCustomLinkClicked() { 596 void ContentSettingMixedScriptBubbleModel::OnCustomLinkClicked() {
545 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble")); 597 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble"));
546 DCHECK(tab_contents()); 598 DCHECK(tab_contents());
547 content::RenderViewHost* host = 599 content::RenderViewHost* host =
548 tab_contents()->web_contents()->GetRenderViewHost(); 600 tab_contents()->web_contents()->GetRenderViewHost();
549 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent( 601 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent(
550 host->GetRoutingID(), true)); 602 host->GetRoutingID(), true));
551 } 603 }
552 604
553 class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel { 605 ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
554 public: 606 Delegate* delegate,
555 ContentSettingRPHBubbleModel(Delegate* delegate, 607 TabContents* tab_contents,
556 TabContents* tab_contents, 608 Profile* profile,
557 Profile* profile, 609 ProtocolHandlerRegistry* registry,
558 ContentSettingsType content_type); 610 ContentSettingsType content_type)
559 611 : ContentSettingTitleAndLinkModel(
560 virtual void OnRadioClicked(int radio_index) OVERRIDE; 612 delegate, tab_contents, profile, content_type),
561 613 selected_item_(0),
562 private: 614 registry_(registry),
563 // These states must match the order of appearance of the radio buttons 615 pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
564 // in the XIB file for the Mac port. 616 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
565 enum RPHState { 617 Init();
566 RPH_ALLOW = 0, 618 }
567 RPH_BLOCK,
568 RPH_IGNORE,
569 };
570
571 void RegisterProtocolHandler();
572 void UnregisterProtocolHandler();
573 void IgnoreProtocolHandler();
574 void ClearOrSetPreviousHandler();
575
576 int selected_item_;
577 ProtocolHandler pending_handler_;
578 ProtocolHandler previous_handler_;
579 };
580 619
581 ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel( 620 ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
582 Delegate* delegate, 621 Delegate* delegate,
583 TabContents* tab_contents, 622 TabContents* tab_contents,
584 Profile* profile, 623 Profile* profile,
585 ContentSettingsType content_type) 624 ContentSettingsType content_type)
586 : ContentSettingTitleAndLinkModel( 625 : ContentSettingTitleAndLinkModel(
587 delegate, tab_contents, profile, content_type), 626 delegate, tab_contents, profile, content_type),
588 selected_item_(0), 627 selected_item_(0),
628 registry_(profile->GetProtocolHandlerRegistry()),
Greg Billock 2012/07/19 14:49:57 This needs to use the PKS factory, right?
Steve McKay 2012/07/19 16:59:55 Ah. Yeah. I was thinking since this is deprecated
589 pending_handler_(ProtocolHandler::EmptyProtocolHandler()), 629 pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
590 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) { 630 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
591 DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type); 631 Init();
632 }
633
634 void ContentSettingRPHBubbleModel::Init() {
635 DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type());
592 636
593 TabSpecificContentSettings* content_settings = 637 TabSpecificContentSettings* content_settings =
594 tab_contents->content_settings(); 638 tab_contents()->content_settings();
595 pending_handler_ = content_settings->pending_protocol_handler(); 639 pending_handler_ = content_settings->pending_protocol_handler();
596 previous_handler_ = content_settings->previous_protocol_handler(); 640 previous_handler_ = content_settings->previous_protocol_handler();
597 641
598 string16 protocol; 642 string16 protocol;
599 if (pending_handler_.protocol() == "mailto") { 643 if (pending_handler_.protocol() == "mailto") {
600 protocol = l10n_util::GetStringUTF16( 644 protocol = l10n_util::GetStringUTF16(
601 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); 645 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
602 } else if (pending_handler_.protocol() == "webcal") { 646 } else if (pending_handler_.protocol() == "webcal") {
603 protocol = l10n_util::GetStringUTF16( 647 protocol = l10n_util::GetStringUTF16(
604 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); 648 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
(...skipping 14 matching lines...) Expand all
619 } 663 }
620 664
621 std::string radio_allow_label = 665 std::string radio_allow_label =
622 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT, 666 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT,
623 pending_handler_.title()); 667 pending_handler_.title());
624 std::string radio_deny_label = 668 std::string radio_deny_label =
625 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY); 669 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
626 std::string radio_ignore_label = 670 std::string radio_ignore_label =
627 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE); 671 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE);
628 672
629 GURL url = tab_contents->web_contents()->GetURL(); 673 GURL url = tab_contents()->web_contents()->GetURL();
630 RadioGroup radio_group; 674 RadioGroup radio_group;
631 radio_group.url = url; 675 radio_group.url = url;
632 676
633 radio_group.radio_items.push_back(radio_allow_label); 677 radio_group.radio_items.push_back(radio_allow_label);
634 radio_group.radio_items.push_back(radio_deny_label); 678 radio_group.radio_items.push_back(radio_deny_label);
635 radio_group.radio_items.push_back(radio_ignore_label); 679 radio_group.radio_items.push_back(radio_ignore_label);
636 ContentSetting setting = 680 ContentSetting setting =
637 content_settings->pending_protocol_handler_setting(); 681 content_settings->pending_protocol_handler_setting();
638 if (setting == CONTENT_SETTING_ALLOW) 682 if (setting == CONTENT_SETTING_ALLOW)
639 radio_group.default_item = RPH_ALLOW; 683 radio_group.default_item = RPH_ALLOW;
(...skipping 19 matching lines...) Expand all
659 UnregisterProtocolHandler(); 703 UnregisterProtocolHandler();
660 else if (radio_index == RPH_IGNORE) 704 else if (radio_index == RPH_IGNORE)
661 IgnoreProtocolHandler(); 705 IgnoreProtocolHandler();
662 else 706 else
663 NOTREACHED(); 707 NOTREACHED();
664 } 708 }
665 709
666 void ContentSettingRPHBubbleModel::RegisterProtocolHandler() { 710 void ContentSettingRPHBubbleModel::RegisterProtocolHandler() {
667 // A no-op if the handler hasn't been ignored, but needed in case the user 711 // A no-op if the handler hasn't been ignored, but needed in case the user
668 // selects sequences like register/ignore/register. 712 // selects sequences like register/ignore/register.
669 profile()->GetProtocolHandlerRegistry()->RemoveIgnoredHandler( 713 registry_->RemoveIgnoredHandler(pending_handler_);
670 pending_handler_);
671 714
672 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( 715 registry_->OnAcceptRegisterProtocolHandler(pending_handler_);
673 pending_handler_);
674 tab_contents()->content_settings()->set_pending_protocol_handler_setting( 716 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
675 CONTENT_SETTING_ALLOW); 717 CONTENT_SETTING_ALLOW);
676 } 718 }
677 719
678 void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() { 720 void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() {
679 profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler( 721 registry_->OnDenyRegisterProtocolHandler(pending_handler_);
680 pending_handler_);
681 tab_contents()->content_settings()->set_pending_protocol_handler_setting( 722 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
682 CONTENT_SETTING_BLOCK); 723 CONTENT_SETTING_BLOCK);
683 ClearOrSetPreviousHandler(); 724 ClearOrSetPreviousHandler();
684 } 725 }
685 726
686 void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() { 727 void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() {
687 profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler( 728 registry_->OnIgnoreRegisterProtocolHandler(pending_handler_);
688 pending_handler_);
689 tab_contents()->content_settings()->set_pending_protocol_handler_setting( 729 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
690 CONTENT_SETTING_DEFAULT); 730 CONTENT_SETTING_DEFAULT);
691 ClearOrSetPreviousHandler(); 731 ClearOrSetPreviousHandler();
692 } 732 }
693 733
694 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { 734 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() {
695 if (previous_handler_.IsEmpty()) { 735 if (previous_handler_.IsEmpty()) {
696 profile()->GetProtocolHandlerRegistry()->ClearDefault( 736 registry_->ClearDefault(pending_handler_.protocol());
697 pending_handler_.protocol());
698 } else { 737 } else {
699 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( 738 registry_->OnAcceptRegisterProtocolHandler(previous_handler_);
700 previous_handler_);
701 } 739 }
702 } 740 }
703 741
704 // static 742 // static
705 ContentSettingBubbleModel* 743 ContentSettingBubbleModel*
706 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 744 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
707 Delegate* delegate, 745 Delegate* delegate,
708 TabContents* tab_contents, 746 TabContents* tab_contents,
709 Profile* profile, 747 Profile* profile,
710 ContentSettingsType content_type) { 748 ContentSettingsType content_type) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 const content::NotificationDetails& details) { 817 const content::NotificationDetails& details) {
780 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { 818 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) {
781 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); 819 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr());
782 tab_contents_ = NULL; 820 tab_contents_ = NULL;
783 } else { 821 } else {
784 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 822 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
785 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 823 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
786 profile_ = NULL; 824 profile_ = NULL;
787 } 825 }
788 } 826 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698