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

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

Issue 5564007: Update Content Settings Bubbles (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address CR feedback, fix tests Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/content_setting_bubble_model.h" 5 #include "chrome/browser/content_setting_bubble_model.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/blocked_content_container.h" 10 #include "chrome/browser/blocked_content_container.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 Need_a_setting_for_every_content_settings_type); 111 Need_a_setting_for_every_content_settings_type);
112 set_manage_link(l10n_util::GetStringUTF8(kLinkIDs[content_type()])); 112 set_manage_link(l10n_util::GetStringUTF8(kLinkIDs[content_type()]));
113 } 113 }
114 114
115 virtual void OnManageLinkClicked() { 115 virtual void OnManageLinkClicked() {
116 if (tab_contents()) 116 if (tab_contents())
117 tab_contents()->delegate()->ShowContentSettingsWindow(content_type()); 117 tab_contents()->delegate()->ShowContentSettingsWindow(content_type());
118 } 118 }
119 }; 119 };
120 120
121 class ContentSettingTitleLinkAndInfoModel 121 class ContentSettingTitleLinkAndCustomModel
122 : public ContentSettingTitleAndLinkModel { 122 : public ContentSettingTitleAndLinkModel {
123 public: 123 public:
124 ContentSettingTitleLinkAndInfoModel(TabContents* tab_contents, 124 ContentSettingTitleLinkAndCustomModel(TabContents* tab_contents,
125 Profile* profile, 125 Profile* profile,
126 ContentSettingsType content_type) 126 ContentSettingsType content_type)
127 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { 127 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) {
128 SetInfoLink(); 128 SetCustomLink();
129 } 129 }
130 130
131 private: 131 private:
132 void SetInfoLink() { 132 void SetCustomLink() {
133 static const int kInfoIDs[] = { 133 static const int kCustomIDs[] = {
134 IDS_BLOCKED_COOKIES_INFO, 134 IDS_BLOCKED_COOKIES_INFO,
135 0, // Images do not have an info link. 135 0, // Images do not have a custom link.
136 0, // Javascript doesn't have an info link. 136 0, // Javascript doesn't have a custom link.
137 0, // Plugins do not have an info link. 137 IDS_BLOCKED_PLUGINS_LOAD_ALL,
138 0, // Popups do not have an info link. 138 0, // Popups do not have a custom link.
139 0, // Geolocation does not have an info link. 139 0, // Geolocation custom links are set within that class.
140 0, // Notifications do not have a bubble. 140 0, // Notifications do not have a bubble.
141 }; 141 };
142 COMPILE_ASSERT(arraysize(kInfoIDs) == CONTENT_SETTINGS_NUM_TYPES, 142 COMPILE_ASSERT(arraysize(kCustomIDs) == CONTENT_SETTINGS_NUM_TYPES,
143 Need_a_setting_for_every_content_settings_type); 143 Need_a_setting_for_every_content_settings_type);
144 if (kInfoIDs[content_type()]) 144 if (kCustomIDs[content_type()])
145 set_info_link(l10n_util::GetStringUTF8(kInfoIDs[content_type()])); 145 set_custom_link(l10n_util::GetStringUTF8(kCustomIDs[content_type()]));
146 } 146 }
147 147
148 virtual void OnInfoLinkClicked() { 148 virtual void OnCustomLinkClicked() {}
149 DCHECK(content_type() == CONTENT_SETTINGS_TYPE_COOKIES);
150 if (tab_contents()) {
151 NotificationService::current()->Notify(
152 NotificationType::COLLECTED_COOKIES_SHOWN,
153 Source<TabSpecificContentSettings>(
154 tab_contents()->GetTabSpecificContentSettings()),
155 NotificationService::NoDetails());
156 tab_contents()->delegate()->ShowCollectedCookiesDialog(tab_contents());
157 }
158 }
159 }; 149 };
160 150
161 151
162 class ContentSettingSingleRadioGroup : public ContentSettingTitleAndLinkModel { 152 class ContentSettingSingleRadioGroup
153 : public ContentSettingTitleLinkAndCustomModel {
163 public: 154 public:
164 ContentSettingSingleRadioGroup(TabContents* tab_contents, Profile* profile, 155 ContentSettingSingleRadioGroup(TabContents* tab_contents,
165 ContentSettingsType content_type) 156 Profile* profile,
166 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type), 157 ContentSettingsType content_type)
158 : ContentSettingTitleLinkAndCustomModel(tab_contents, profile,
159 content_type),
167 block_setting_(CONTENT_SETTING_BLOCK) { 160 block_setting_(CONTENT_SETTING_BLOCK) {
168 SetRadioGroup(); 161 SetRadioGroup();
169 } 162 }
170 163
171 private: 164 private:
172 ContentSetting block_setting_; 165 ContentSetting block_setting_;
173 166
174 // Initialize the radio group by setting the appropriate labels for the 167 // Initialize the radio group by setting the appropriate labels for the
175 // content type and setting the default value based on the content setting. 168 // content type and setting the default value based on the content setting.
176 void SetRadioGroup() { 169 void SetRadioGroup() {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 AddException(setting, std::string()); 272 AddException(setting, std::string());
280 } else { 273 } else {
281 for (std::set<std::string>::const_iterator it = resources.begin(); 274 for (std::set<std::string>::const_iterator it = resources.begin();
282 it != resources.end(); ++it) { 275 it != resources.end(); ++it) {
283 AddException(setting, *it); 276 AddException(setting, *it);
284 } 277 }
285 } 278 }
286 } 279 }
287 }; 280 };
288 281
282 class ContentSettingCookiesBubbleModel
283 : public ContentSettingTitleLinkAndCustomModel {
284 public:
285 ContentSettingCookiesBubbleModel(TabContents* tab_contents,
286 Profile* profile,
287 ContentSettingsType content_type)
288 : ContentSettingTitleLinkAndCustomModel(tab_contents, profile,
289 content_type) {
290 DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type);
291 set_custom_link_enabled(true);
292 }
293
294 private:
295 virtual void OnCustomLinkClicked() OVERRIDE {
296 if (tab_contents()) {
297 NotificationService::current()->Notify(
298 NotificationType::COLLECTED_COOKIES_SHOWN,
299 Source<TabSpecificContentSettings>(
300 tab_contents()->GetTabSpecificContentSettings()),
301 NotificationService::NoDetails());
302 tab_contents()->delegate()->ShowCollectedCookiesDialog(tab_contents());
303 }
304 }
305 };
306
289 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { 307 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup {
290 public: 308 public:
291 ContentSettingPluginBubbleModel(TabContents* tab_contents, Profile* profile, 309 ContentSettingPluginBubbleModel(TabContents* tab_contents, Profile* profile,
Peter Kasting 2010/12/10 00:57:24 Nit: Can you fix the arg wrapping here too?
msw 2010/12/10 03:32:05 Done, also caught ContentSettingTitleAndLinkModel
292 ContentSettingsType content_type) 310 ContentSettingsType content_type)
293 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { 311 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) {
294 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); 312 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS);
295 SetLoadPluginsLinkTitle(); 313 TabSpecificContentSettings* settings = !tab_contents ? NULL :
314 tab_contents->GetTabSpecificContentSettings();
315 set_custom_link_enabled(!settings || settings->load_plugins_link_enabled());
Peter Kasting 2010/12/10 00:57:24 How about we just do: set_custom_link_enabled(t
msw 2010/12/10 03:32:05 Done, also refactored OnCustomLinkClicked() slight
296 } 316 }
297 317
298 private: 318 private:
299 void SetLoadPluginsLinkTitle() { 319 virtual void OnCustomLinkClicked() OVERRIDE {
300 set_load_plugins_link_title(
301 l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_LOAD_ALL));
302 }
303
304 virtual void OnLoadPluginsLinkClicked() {
305 UserMetrics::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); 320 UserMetrics::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble"));
306 if (tab_contents()) { 321 if (tab_contents()) {
307 tab_contents()->render_view_host()->LoadBlockedPlugins(); 322 tab_contents()->render_view_host()->LoadBlockedPlugins();
323 set_custom_link_enabled(false);
324 TabSpecificContentSettings* settings =
325 tab_contents()->GetTabSpecificContentSettings();
326 settings->set_load_plugins_link_enabled(false);
308 } 327 }
309 set_load_plugins_link_enabled(false);
310 TabSpecificContentSettings* settings =
311 tab_contents()->GetTabSpecificContentSettings();
312 settings->set_load_plugins_link_enabled(false);
313 } 328 }
314 }; 329 };
315 330
316 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { 331 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup {
317 public: 332 public:
318 ContentSettingPopupBubbleModel(TabContents* tab_contents, Profile* profile, 333 ContentSettingPopupBubbleModel(TabContents* tab_contents, Profile* profile,
Peter Kasting 2010/12/10 00:57:24 Nit: And fix arg wrapping here
msw 2010/12/10 03:32:05 Done.
319 ContentSettingsType content_type) 334 ContentSettingsType content_type)
320 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { 335 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) {
321 SetPopups(); 336 SetPopups();
322 } 337 }
323 338
324 private: 339 private:
325 void SetPopups() { 340 void SetPopups() {
326 // check for crbug.com/53176 341 // check for crbug.com/53176
327 if (!tab_contents()->blocked_content_container()) 342 if (!tab_contents()->blocked_content_container())
328 return; 343 return;
(...skipping 25 matching lines...) Expand all
354 369
355 class ContentSettingDomainListBubbleModel 370 class ContentSettingDomainListBubbleModel
356 : public ContentSettingTitleAndLinkModel { 371 : public ContentSettingTitleAndLinkModel {
357 public: 372 public:
358 ContentSettingDomainListBubbleModel(TabContents* tab_contents, 373 ContentSettingDomainListBubbleModel(TabContents* tab_contents,
359 Profile* profile, 374 Profile* profile,
360 ContentSettingsType content_type) 375 ContentSettingsType content_type)
361 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { 376 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) {
362 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << 377 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) <<
363 "SetDomains currently only supports geolocation content type"; 378 "SetDomains currently only supports geolocation content type";
364 SetDomainsAndClearLink(); 379 SetDomainsAndCustomLink();
365 } 380 }
366 381
367 private: 382 private:
368 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) { 383 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) {
369 if (!hosts.empty()) { 384 if (!hosts.empty()) {
370 DomainList domain_list; 385 DomainList domain_list;
371 domain_list.title = l10n_util::GetStringUTF8(title_id); 386 domain_list.title = l10n_util::GetStringUTF8(title_id);
372 domain_list.hosts = hosts; 387 domain_list.hosts = hosts;
373 add_domain_list(domain_list); 388 add_domain_list(domain_list);
374 } 389 }
375 } 390 }
376 void SetDomainsAndClearLink() { 391 void SetDomainsAndCustomLink() {
377 TabSpecificContentSettings* content_settings = 392 TabSpecificContentSettings* content_settings =
378 tab_contents()->GetTabSpecificContentSettings(); 393 tab_contents()->GetTabSpecificContentSettings();
379 const GeolocationSettingsState& settings = 394 const GeolocationSettingsState& settings =
380 content_settings->geolocation_settings_state(); 395 content_settings->geolocation_settings_state();
381 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state; 396 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state;
382 unsigned int tab_state_flags = 0; 397 unsigned int tab_state_flags = 0;
383 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags); 398 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
384 // Divide the tab's current geolocation users into sets according to their 399 // Divide the tab's current geolocation users into sets according to their
385 // permission state. 400 // permission state.
386 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW], 401 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
387 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED); 402 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED);
388 403
389 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], 404 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK],
390 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED); 405 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED);
391 406
392 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) { 407 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) {
393 set_clear_link( 408 set_custom_link(l10n_util::GetStringUTF8(
394 l10n_util::GetStringUTF8(IDS_GEOLOCATION_BUBBLE_CLEAR_LINK)); 409 IDS_GEOLOCATION_BUBBLE_CLEAR_LINK));
410 set_custom_link_enabled(true);
395 } else if (tab_state_flags & 411 } else if (tab_state_flags &
396 GeolocationSettingsState::TABSTATE_HAS_CHANGED) { 412 GeolocationSettingsState::TABSTATE_HAS_CHANGED) {
397 // It is a slight abuse of the domain list field to use it for the reload 413 set_custom_link(l10n_util::GetStringUTF8(
398 // hint, but works fine for now. TODO(joth): If we need to style it 414 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR));
399 // differently, consider adding an explicit field, or generalize the
400 // domain list to be a flat list of style formatted lines.
401 DomainList reload_section;
402 reload_section.title = l10n_util::GetStringUTF8(
403 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR);
404 add_domain_list(reload_section);
405 } 415 }
406 } 416 }
407 virtual void OnClearLinkClicked() { 417 virtual void OnCustomLinkClicked() OVERRIDE {
408 if (!tab_contents()) 418 if (!tab_contents())
409 return; 419 return;
410 // Reset this embedder's entry to default for each of the requesting 420 // Reset this embedder's entry to default for each of the requesting
411 // origins currently on the page. 421 // origins currently on the page.
412 const GURL& embedder_url = tab_contents()->GetURL(); 422 const GURL& embedder_url = tab_contents()->GetURL();
413 TabSpecificContentSettings* content_settings = 423 TabSpecificContentSettings* content_settings =
414 tab_contents()->GetTabSpecificContentSettings(); 424 tab_contents()->GetTabSpecificContentSettings();
415 const GeolocationSettingsState::StateMap& state_map = 425 const GeolocationSettingsState::StateMap& state_map =
416 content_settings->geolocation_settings_state().state_map(); 426 content_settings->geolocation_settings_state().state_map();
417 GeolocationContentSettingsMap* settings_map = 427 GeolocationContentSettingsMap* settings_map =
418 profile()->GetGeolocationContentSettingsMap(); 428 profile()->GetGeolocationContentSettingsMap();
419 for (GeolocationSettingsState::StateMap::const_iterator it = 429 for (GeolocationSettingsState::StateMap::const_iterator it =
420 state_map.begin(); it != state_map.end(); ++it) { 430 state_map.begin(); it != state_map.end(); ++it) {
421 settings_map->SetContentSetting(it->first, embedder_url, 431 settings_map->SetContentSetting(it->first, embedder_url,
422 CONTENT_SETTING_DEFAULT); 432 CONTENT_SETTING_DEFAULT);
423 } 433 }
424 } 434 }
425 }; 435 };
426 436
427 // static 437 // static
428 ContentSettingBubbleModel* 438 ContentSettingBubbleModel*
429 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 439 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
430 TabContents* tab_contents, 440 TabContents* tab_contents,
431 Profile* profile, 441 Profile* profile,
432 ContentSettingsType content_type) { 442 ContentSettingsType content_type) {
433 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { 443 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
434 return new ContentSettingTitleLinkAndInfoModel(tab_contents, profile, 444 return new ContentSettingCookiesBubbleModel(tab_contents, profile,
435 content_type); 445 content_type);
436 } 446 }
437 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { 447 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) {
438 return new ContentSettingPopupBubbleModel(tab_contents, profile, 448 return new ContentSettingPopupBubbleModel(tab_contents, profile,
439 content_type); 449 content_type);
440 } 450 }
441 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 451 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
442 return new ContentSettingDomainListBubbleModel(tab_contents, profile, 452 return new ContentSettingDomainListBubbleModel(tab_contents, profile,
443 content_type); 453 content_type);
444 } 454 }
445 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { 455 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
446 return new ContentSettingPluginBubbleModel(tab_contents, profile, 456 return new ContentSettingPluginBubbleModel(tab_contents, profile,
447 content_type); 457 content_type);
448 } 458 }
449 return new ContentSettingSingleRadioGroup(tab_contents, profile, 459 return new ContentSettingSingleRadioGroup(tab_contents, profile,
450 content_type); 460 content_type);
451 } 461 }
452 462
453 ContentSettingBubbleModel::ContentSettingBubbleModel( 463 ContentSettingBubbleModel::ContentSettingBubbleModel(
454 TabContents* tab_contents, Profile* profile, 464 TabContents* tab_contents, Profile* profile,
455 ContentSettingsType content_type) 465 ContentSettingsType content_type)
456 : tab_contents_(tab_contents), profile_(profile), 466 : tab_contents_(tab_contents), profile_(profile),
457 content_type_(content_type) { 467 content_type_(content_type) {
458 if (tab_contents) {
459 TabSpecificContentSettings* settings =
460 tab_contents->GetTabSpecificContentSettings();
461 set_load_plugins_link_enabled(settings->load_plugins_link_enabled());
462 } else {
463 set_load_plugins_link_enabled(true);
464 }
465 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, 468 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
466 Source<TabContents>(tab_contents)); 469 Source<TabContents>(tab_contents));
467 } 470 }
468 471
469 ContentSettingBubbleModel::~ContentSettingBubbleModel() { 472 ContentSettingBubbleModel::~ContentSettingBubbleModel() {
470 } 473 }
471 474
472 ContentSettingBubbleModel::RadioGroup::RadioGroup() : default_item(0) {} 475 ContentSettingBubbleModel::RadioGroup::RadioGroup() : default_item(0) {}
473 476
474 ContentSettingBubbleModel::RadioGroup::~RadioGroup() {} 477 ContentSettingBubbleModel::RadioGroup::~RadioGroup() {}
475 478
476 ContentSettingBubbleModel::DomainList::DomainList() {} 479 ContentSettingBubbleModel::DomainList::DomainList() {}
477 480
478 ContentSettingBubbleModel::DomainList::~DomainList() {} 481 ContentSettingBubbleModel::DomainList::~DomainList() {}
479 482
480 ContentSettingBubbleModel::BubbleContent::BubbleContent() 483 ContentSettingBubbleModel::BubbleContent::BubbleContent()
481 : load_plugins_link_enabled(false) { 484 : custom_link_enabled(false) {
482 } 485 }
483 486
484 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {} 487 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {}
485 488
486 489
487 void ContentSettingBubbleModel::AddBlockedResource( 490 void ContentSettingBubbleModel::AddBlockedResource(
488 const std::string& resource_identifier) { 491 const std::string& resource_identifier) {
489 bubble_content_.resource_identifiers.insert(resource_identifier); 492 bubble_content_.resource_identifiers.insert(resource_identifier);
490 } 493 }
491 494
492 void ContentSettingBubbleModel::Observe(NotificationType type, 495 void ContentSettingBubbleModel::Observe(NotificationType type,
493 const NotificationSource& source, 496 const NotificationSource& source,
494 const NotificationDetails& details) { 497 const NotificationDetails& details) {
495 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); 498 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
496 DCHECK(source == Source<TabContents>(tab_contents_)); 499 DCHECK(source == Source<TabContents>(tab_contents_));
497 tab_contents_ = NULL; 500 tab_contents_ = NULL;
498 } 501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698