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

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: x 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, Profile* profile,
Peter Kasting 2010/12/09 17:56:34 Nit: While you're here, can you fix the parameter
165 ContentSettingsType content_type) 156 ContentSettingsType content_type)
166 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type), 157 : ContentSettingTitleLinkAndCustomModel(tab_contents, profile,
158 content_type),
167 block_setting_(CONTENT_SETTING_BLOCK) { 159 block_setting_(CONTENT_SETTING_BLOCK) {
168 SetRadioGroup(); 160 SetRadioGroup();
169 } 161 }
170 162
171 private: 163 private:
172 ContentSetting block_setting_; 164 ContentSetting block_setting_;
173 165
174 // Initialize the radio group by setting the appropriate labels for the 166 // Initialize the radio group by setting the appropriate labels for the
175 // content type and setting the default value based on the content setting. 167 // content type and setting the default value based on the content setting.
176 void SetRadioGroup() { 168 void SetRadioGroup() {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 AddException(setting, std::string()); 271 AddException(setting, std::string());
280 } else { 272 } else {
281 for (std::set<std::string>::const_iterator it = resources.begin(); 273 for (std::set<std::string>::const_iterator it = resources.begin();
282 it != resources.end(); ++it) { 274 it != resources.end(); ++it) {
283 AddException(setting, *it); 275 AddException(setting, *it);
284 } 276 }
285 } 277 }
286 } 278 }
287 }; 279 };
288 280
281 class ContentSettingCookiesBubbleModel
282 : public ContentSettingTitleLinkAndCustomModel {
283 public:
284 ContentSettingCookiesBubbleModel(TabContents* tab_contents, Profile* profile,
Peter Kasting 2010/12/09 17:56:34 Nit: |profile| goes on its own line.
285 ContentSettingsType content_type)
286 : ContentSettingTitleLinkAndCustomModel(tab_contents, profile,
287 content_type) {
288 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_COOKIES);
Peter Kasting 2010/12/09 17:56:34 Nit: DCHECK_EQ(EXPECTED, ACTUAL);
289 }
290
291 private:
292 virtual void OnCustomLinkClicked() OVERRIDE {
293 if (tab_contents()) {
294 NotificationService::current()->Notify(
295 NotificationType::COLLECTED_COOKIES_SHOWN,
296 Source<TabSpecificContentSettings>(
297 tab_contents()->GetTabSpecificContentSettings()),
298 NotificationService::NoDetails());
299 tab_contents()->delegate()->ShowCollectedCookiesDialog(tab_contents());
300 }
301 }
302 };
303
289 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { 304 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup {
290 public: 305 public:
291 ContentSettingPluginBubbleModel(TabContents* tab_contents, Profile* profile, 306 ContentSettingPluginBubbleModel(TabContents* tab_contents, Profile* profile,
292 ContentSettingsType content_type) 307 ContentSettingsType content_type)
293 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) { 308 : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) {
294 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); 309 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS);
295 SetLoadPluginsLinkTitle();
296 } 310 }
297 311
298 private: 312 private:
299 void SetLoadPluginsLinkTitle() { 313 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")); 314 UserMetrics::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble"));
306 if (tab_contents()) { 315 if (tab_contents()) {
Peter Kasting 2010/12/09 17:56:34 Nit: While here, remove extra {}
307 tab_contents()->render_view_host()->LoadBlockedPlugins(); 316 tab_contents()->render_view_host()->LoadBlockedPlugins();
308 } 317 }
309 set_load_plugins_link_enabled(false); 318 set_custom_link_enabled(false);
310 TabSpecificContentSettings* settings = 319 TabSpecificContentSettings* settings =
311 tab_contents()->GetTabSpecificContentSettings(); 320 tab_contents()->GetTabSpecificContentSettings();
312 settings->set_load_plugins_link_enabled(false); 321 settings->set_load_plugins_link_enabled(false);
313 } 322 }
314 }; 323 };
315 324
316 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { 325 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup {
317 public: 326 public:
318 ContentSettingPopupBubbleModel(TabContents* tab_contents, Profile* profile, 327 ContentSettingPopupBubbleModel(TabContents* tab_contents, Profile* profile,
319 ContentSettingsType content_type) 328 ContentSettingsType content_type)
(...skipping 23 matching lines...) Expand all
343 add_popup(popup_item); 352 add_popup(popup_item);
344 } 353 }
345 } 354 }
346 355
347 virtual void OnPopupClicked(int index) { 356 virtual void OnPopupClicked(int index) {
348 if (tab_contents() && tab_contents()->blocked_content_container()) { 357 if (tab_contents() && tab_contents()->blocked_content_container()) {
349 tab_contents()->blocked_content_container()->LaunchForContents( 358 tab_contents()->blocked_content_container()->LaunchForContents(
350 bubble_content().popup_items[index].tab_contents); 359 bubble_content().popup_items[index].tab_contents);
351 } 360 }
352 } 361 }
362 virtual void OnCustomLinkClicked() OVERRIDE {}
Peter Kasting 2010/12/09 17:56:34 Nit: No need for this since the base class provide
353 }; 363 };
354 364
355 class ContentSettingDomainListBubbleModel 365 class ContentSettingDomainListBubbleModel
356 : public ContentSettingTitleAndLinkModel { 366 : public ContentSettingTitleAndLinkModel {
357 public: 367 public:
358 ContentSettingDomainListBubbleModel(TabContents* tab_contents, 368 ContentSettingDomainListBubbleModel(TabContents* tab_contents,
359 Profile* profile, 369 Profile* profile,
360 ContentSettingsType content_type) 370 ContentSettingsType content_type)
361 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) { 371 : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) {
362 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << 372 DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) <<
363 "SetDomains currently only supports geolocation content type"; 373 "SetDomains currently only supports geolocation content type";
364 SetDomainsAndClearLink(); 374 SetDomainsAndCustomLink();
365 } 375 }
366 376
367 private: 377 private:
368 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) { 378 void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) {
369 if (!hosts.empty()) { 379 if (!hosts.empty()) {
370 DomainList domain_list; 380 DomainList domain_list;
371 domain_list.title = l10n_util::GetStringUTF8(title_id); 381 domain_list.title = l10n_util::GetStringUTF8(title_id);
372 domain_list.hosts = hosts; 382 domain_list.hosts = hosts;
373 add_domain_list(domain_list); 383 add_domain_list(domain_list);
374 } 384 }
375 } 385 }
376 void SetDomainsAndClearLink() { 386 void SetDomainsAndCustomLink() {
377 TabSpecificContentSettings* content_settings = 387 TabSpecificContentSettings* content_settings =
378 tab_contents()->GetTabSpecificContentSettings(); 388 tab_contents()->GetTabSpecificContentSettings();
379 const GeolocationSettingsState& settings = 389 const GeolocationSettingsState& settings =
380 content_settings->geolocation_settings_state(); 390 content_settings->geolocation_settings_state();
381 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state; 391 GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state;
382 unsigned int tab_state_flags = 0; 392 unsigned int tab_state_flags = 0;
383 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags); 393 settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
384 // Divide the tab's current geolocation users into sets according to their 394 // Divide the tab's current geolocation users into sets according to their
385 // permission state. 395 // permission state.
386 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW], 396 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
387 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED); 397 IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED);
388 398
389 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK], 399 MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK],
390 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED); 400 IDS_GEOLOCATION_BUBBLE_SECTION_DENIED);
391 401
392 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) { 402 if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) {
393 set_clear_link( 403 set_custom_link(l10n_util::GetStringUTF8(
394 l10n_util::GetStringUTF8(IDS_GEOLOCATION_BUBBLE_CLEAR_LINK)); 404 IDS_GEOLOCATION_BUBBLE_CLEAR_LINK));
405 set_custom_link_enabled(true);
395 } else if (tab_state_flags & 406 } else if (tab_state_flags &
396 GeolocationSettingsState::TABSTATE_HAS_CHANGED) { 407 GeolocationSettingsState::TABSTATE_HAS_CHANGED) {
397 // It is a slight abuse of the domain list field to use it for the reload 408 set_custom_link(l10n_util::GetStringUTF8(
398 // hint, but works fine for now. TODO(joth): If we need to style it 409 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR));
399 // differently, consider adding an explicit field, or generalize the 410 set_custom_link_enabled(false);
Peter Kasting 2010/12/09 17:56:34 Nit: You can remove this line and the conditional
400 // domain list to be a flat list of style formatted lines. 411 } else {
401 DomainList reload_section; 412 set_custom_link(std::string());
402 reload_section.title = l10n_util::GetStringUTF8( 413 set_custom_link_enabled(false);
403 IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR);
404 add_domain_list(reload_section);
405 } 414 }
406 } 415 }
407 virtual void OnClearLinkClicked() { 416 virtual void OnCustomLinkClicked() OVERRIDE {
408 if (!tab_contents()) 417 if (!tab_contents())
409 return; 418 return;
410 // Reset this embedder's entry to default for each of the requesting 419 // Reset this embedder's entry to default for each of the requesting
411 // origins currently on the page. 420 // origins currently on the page.
412 const GURL& embedder_url = tab_contents()->GetURL(); 421 const GURL& embedder_url = tab_contents()->GetURL();
413 TabSpecificContentSettings* content_settings = 422 TabSpecificContentSettings* content_settings =
414 tab_contents()->GetTabSpecificContentSettings(); 423 tab_contents()->GetTabSpecificContentSettings();
415 const GeolocationSettingsState::StateMap& state_map = 424 const GeolocationSettingsState::StateMap& state_map =
416 content_settings->geolocation_settings_state().state_map(); 425 content_settings->geolocation_settings_state().state_map();
417 GeolocationContentSettingsMap* settings_map = 426 GeolocationContentSettingsMap* settings_map =
418 profile()->GetGeolocationContentSettingsMap(); 427 profile()->GetGeolocationContentSettingsMap();
419 for (GeolocationSettingsState::StateMap::const_iterator it = 428 for (GeolocationSettingsState::StateMap::const_iterator it =
420 state_map.begin(); it != state_map.end(); ++it) { 429 state_map.begin(); it != state_map.end(); ++it) {
421 settings_map->SetContentSetting(it->first, embedder_url, 430 settings_map->SetContentSetting(it->first, embedder_url,
422 CONTENT_SETTING_DEFAULT); 431 CONTENT_SETTING_DEFAULT);
423 } 432 }
424 } 433 }
425 }; 434 };
426 435
427 // static 436 // static
428 ContentSettingBubbleModel* 437 ContentSettingBubbleModel*
429 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 438 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
430 TabContents* tab_contents, 439 TabContents* tab_contents,
431 Profile* profile, 440 Profile* profile,
432 ContentSettingsType content_type) { 441 ContentSettingsType content_type) {
433 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { 442 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
434 return new ContentSettingTitleLinkAndInfoModel(tab_contents, profile, 443 return new ContentSettingCookiesBubbleModel(tab_contents, profile,
435 content_type); 444 content_type);
436 } 445 }
437 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { 446 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) {
438 return new ContentSettingPopupBubbleModel(tab_contents, profile, 447 return new ContentSettingPopupBubbleModel(tab_contents, profile,
439 content_type); 448 content_type);
440 } 449 }
441 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 450 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
442 return new ContentSettingDomainListBubbleModel(tab_contents, profile, 451 return new ContentSettingDomainListBubbleModel(tab_contents, profile,
443 content_type); 452 content_type);
444 } 453 }
445 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { 454 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
446 return new ContentSettingPluginBubbleModel(tab_contents, profile, 455 return new ContentSettingPluginBubbleModel(tab_contents, profile,
447 content_type); 456 content_type);
448 } 457 }
449 return new ContentSettingSingleRadioGroup(tab_contents, profile, 458 return new ContentSettingSingleRadioGroup(tab_contents, profile,
450 content_type); 459 content_type);
451 } 460 }
452 461
453 ContentSettingBubbleModel::ContentSettingBubbleModel( 462 ContentSettingBubbleModel::ContentSettingBubbleModel(
454 TabContents* tab_contents, Profile* profile, 463 TabContents* tab_contents, Profile* profile,
455 ContentSettingsType content_type) 464 ContentSettingsType content_type)
456 : tab_contents_(tab_contents), profile_(profile), 465 : tab_contents_(tab_contents), profile_(profile),
457 content_type_(content_type) { 466 content_type_(content_type) {
458 if (tab_contents) { 467 if (tab_contents) {
Peter Kasting 2010/12/09 17:56:34 Nit: This whole conditional could be reduced to ju
459 TabSpecificContentSettings* settings = 468 TabSpecificContentSettings* settings =
460 tab_contents->GetTabSpecificContentSettings(); 469 tab_contents->GetTabSpecificContentSettings();
461 set_load_plugins_link_enabled(settings->load_plugins_link_enabled()); 470 set_custom_link_enabled(settings->load_plugins_link_enabled());
462 } else { 471 } else {
463 set_load_plugins_link_enabled(true); 472 set_custom_link_enabled(true);
464 } 473 }
465 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, 474 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
466 Source<TabContents>(tab_contents)); 475 Source<TabContents>(tab_contents));
467 } 476 }
468 477
469 ContentSettingBubbleModel::~ContentSettingBubbleModel() { 478 ContentSettingBubbleModel::~ContentSettingBubbleModel() {
470 } 479 }
471 480
472 ContentSettingBubbleModel::RadioGroup::RadioGroup() : default_item(0) {} 481 ContentSettingBubbleModel::RadioGroup::RadioGroup() : default_item(0) {}
473 482
474 ContentSettingBubbleModel::RadioGroup::~RadioGroup() {} 483 ContentSettingBubbleModel::RadioGroup::~RadioGroup() {}
475 484
476 ContentSettingBubbleModel::DomainList::DomainList() {} 485 ContentSettingBubbleModel::DomainList::DomainList() {}
477 486
478 ContentSettingBubbleModel::DomainList::~DomainList() {} 487 ContentSettingBubbleModel::DomainList::~DomainList() {}
479 488
480 ContentSettingBubbleModel::BubbleContent::BubbleContent() 489 ContentSettingBubbleModel::BubbleContent::BubbleContent()
481 : load_plugins_link_enabled(false) { 490 : custom_link_enabled(false) {
482 } 491 }
483 492
484 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {} 493 ContentSettingBubbleModel::BubbleContent::~BubbleContent() {}
485 494
486 495
487 void ContentSettingBubbleModel::AddBlockedResource( 496 void ContentSettingBubbleModel::AddBlockedResource(
488 const std::string& resource_identifier) { 497 const std::string& resource_identifier) {
489 bubble_content_.resource_identifiers.insert(resource_identifier); 498 bubble_content_.resource_identifiers.insert(resource_identifier);
490 } 499 }
491 500
492 void ContentSettingBubbleModel::Observe(NotificationType type, 501 void ContentSettingBubbleModel::Observe(NotificationType type,
493 const NotificationSource& source, 502 const NotificationSource& source,
494 const NotificationDetails& details) { 503 const NotificationDetails& details) {
495 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); 504 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
496 DCHECK(source == Source<TabContents>(tab_contents_)); 505 DCHECK(source == Source<TabContents>(tab_contents_));
497 tab_contents_ = NULL; 506 tab_contents_ = NULL;
498 } 507 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698