OLD | NEW |
---|---|
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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "components/content_settings/core/browser/content_settings_utils.h" | 29 #include "components/content_settings/core/browser/content_settings_utils.h" |
30 #include "components/content_settings/core/common/content_settings.h" | 30 #include "components/content_settings/core/common/content_settings.h" |
31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/render_frame_host.h" | 32 #include "content/public/browser/render_frame_host.h" |
33 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
34 #include "content/public/browser/render_view_host.h" | 34 #include "content/public/browser/render_view_host.h" |
35 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
37 #include "content/public/browser/web_contents_delegate.h" | 37 #include "content/public/browser/web_contents_delegate.h" |
38 #include "grit/components_strings.h" | 38 #include "grit/components_strings.h" |
39 #include "grit/theme_resources.h" | |
39 #include "net/base/net_util.h" | 40 #include "net/base/net_util.h" |
40 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
41 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
42 #include "ui/resources/grit/ui_resources.h" | 43 #include "ui/resources/grit/ui_resources.h" |
43 | 44 |
44 using base::UserMetricsAction; | 45 using base::UserMetricsAction; |
45 using content::WebContents; | 46 using content::WebContents; |
46 using content_settings::SettingInfo; | 47 using content_settings::SettingInfo; |
47 using content_settings::SettingSource; | 48 using content_settings::SettingSource; |
48 using content_settings::SETTING_SOURCE_USER; | 49 using content_settings::SETTING_SOURCE_USER; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 SetLearnMoreLink(); | 108 SetLearnMoreLink(); |
108 } | 109 } |
109 | 110 |
110 void ContentSettingTitleAndLinkModel::SetTitle() { | 111 void ContentSettingTitleAndLinkModel::SetTitle() { |
111 TabSpecificContentSettings* content_settings = NULL; | 112 TabSpecificContentSettings* content_settings = NULL; |
112 if (web_contents()) { | 113 if (web_contents()) { |
113 content_settings = | 114 content_settings = |
114 TabSpecificContentSettings::FromWebContents(web_contents()); | 115 TabSpecificContentSettings::FromWebContents(web_contents()); |
115 } | 116 } |
116 | 117 |
117 if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS && content_settings && | |
118 content_settings->IsContentBlocked(content_type())) { | |
119 set_plugin_names(content_settings->GetBlockedPluginNames()); | |
120 } | |
121 | |
122 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { | 118 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { |
123 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, | 119 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, |
124 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, | 120 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, |
125 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, | 121 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, |
126 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE}, | 122 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE}, |
127 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, | 123 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, |
128 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, | 124 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, |
129 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, | 125 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, |
130 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | 126 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
131 IDS_BLOCKED_PPAPI_BROKER_TITLE}, | 127 IDS_BLOCKED_PPAPI_BROKER_TITLE}, |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 if (!web_contents()) | 454 if (!web_contents()) |
459 return; | 455 return; |
460 content::NotificationService::current()->Notify( | 456 content::NotificationService::current()->Notify( |
461 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, | 457 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, |
462 content::Source<TabSpecificContentSettings>( | 458 content::Source<TabSpecificContentSettings>( |
463 TabSpecificContentSettings::FromWebContents(web_contents())), | 459 TabSpecificContentSettings::FromWebContents(web_contents())), |
464 content::NotificationService::NoDetails()); | 460 content::NotificationService::NoDetails()); |
465 delegate()->ShowCollectedCookiesDialog(web_contents()); | 461 delegate()->ShowCollectedCookiesDialog(web_contents()); |
466 } | 462 } |
467 | 463 |
468 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { | 464 // A bubble model that can display a list of items. |
465 class ContentSettingItemListModel : public ContentSettingSingleRadioGroup { | |
466 public: | |
467 ContentSettingItemListModel(Delegate* delegate, | |
468 WebContents* web_contents, | |
469 Profile* profile, | |
470 ContentSettingsType content_type) | |
471 : ContentSettingSingleRadioGroup(delegate, | |
472 web_contents, | |
473 profile, | |
474 content_type) {} | |
475 ~ContentSettingItemListModel() override {} | |
476 | |
477 protected: | |
478 int32 item_id_from_item_index(int index) const { | |
479 return bubble_content().list_items[index].item_id; | |
480 } | |
481 | |
482 private: | |
483 virtual void SetListItems() = 0; | |
msw
2015/03/20 22:06:33
Shouldn't this be protected for subclasses to over
meacer
2015/03/20 23:39:42
Done.
| |
484 }; | |
485 | |
486 class ContentSettingPluginBubbleModel : public ContentSettingItemListModel { | |
msw
2015/03/20 22:06:33
nit: rename PluginBubbleModel?
meacer
2015/03/20 23:39:42
Done.
msw
2015/03/21 00:25:19
Jeez, I should have looked closer, maybe we should
msw
2015/03/23 19:21:06
Ping, you should revert the renaming of these two
meacer
2015/03/23 20:23:29
Sorry missed this comment. I named them back to Co
| |
469 public: | 487 public: |
470 ContentSettingPluginBubbleModel(Delegate* delegate, | 488 ContentSettingPluginBubbleModel(Delegate* delegate, |
471 WebContents* web_contents, | 489 WebContents* web_contents, |
472 Profile* profile, | 490 Profile* profile, |
473 ContentSettingsType content_type); | 491 ContentSettingsType content_type); |
474 | 492 |
475 ~ContentSettingPluginBubbleModel() override; | 493 ~ContentSettingPluginBubbleModel() override; |
476 | 494 |
477 private: | 495 private: |
496 void SetListItems() override; | |
478 void OnCustomLinkClicked() override; | 497 void OnCustomLinkClicked() override; |
479 }; | 498 }; |
480 | 499 |
481 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( | 500 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( |
482 Delegate* delegate, | 501 Delegate* delegate, |
483 WebContents* web_contents, | 502 WebContents* web_contents, |
484 Profile* profile, | 503 Profile* profile, |
485 ContentSettingsType content_type) | 504 ContentSettingsType content_type) |
msw
2015/03/20 22:06:33
nit: nix the content_type arg; inline CONTENT_SETT
meacer
2015/03/20 23:39:42
Done.
| |
486 : ContentSettingSingleRadioGroup( | 505 : ContentSettingItemListModel(delegate, |
487 delegate, web_contents, profile, content_type) { | 506 web_contents, |
507 profile, | |
508 content_type) { | |
488 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); | 509 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); |
489 // Disable the "Run all plugins this time" link if the setting is managed and | 510 // Disable the "Run all plugins this time" link if the setting is managed and |
490 // can't be controlled by the user or if the user already clicked on the link | 511 // can't be controlled by the user or if the user already clicked on the link |
491 // and ran all plugins. | 512 // and ran all plugins. |
492 set_custom_link_enabled(!setting_is_managed() && | 513 set_custom_link_enabled(!setting_is_managed() && |
493 web_contents && | 514 web_contents && |
494 TabSpecificContentSettings::FromWebContents( | 515 TabSpecificContentSettings::FromWebContents( |
495 web_contents)->load_plugins_link_enabled()); | 516 web_contents)->load_plugins_link_enabled()); |
517 SetListItems(); | |
496 } | 518 } |
497 | 519 |
498 ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() { | 520 ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() { |
499 if (settings_changed()) { | 521 if (settings_changed()) { |
500 // If the user elected to allow all plugins then run plugins at this time. | 522 // If the user elected to allow all plugins then run plugins at this time. |
501 if (selected_item() == kAllowButtonIndex) | 523 if (selected_item() == kAllowButtonIndex) |
502 OnCustomLinkClicked(); | 524 OnCustomLinkClicked(); |
503 } | 525 } |
504 } | 526 } |
505 | 527 |
528 void ContentSettingPluginBubbleModel::SetListItems() { | |
529 if (!web_contents()) | |
530 return; | |
531 TabSpecificContentSettings* content_settings = | |
532 TabSpecificContentSettings::FromWebContents(web_contents()); | |
533 | |
534 const std::vector<base::string16>& blocked_plugins = | |
535 content_settings->GetBlockedPluginNames(); | |
536 for (std::vector<base::string16>::const_iterator iter = | |
msw
2015/03/20 22:06:33
nit: use range-based-for or auto
meacer
2015/03/20 23:39:42
Done.
| |
537 blocked_plugins.begin(); | |
538 iter != blocked_plugins.end(); ++iter) { | |
539 // TODO(meacer): Link to chrome://plugins#plugin_id from here. | |
msw
2015/03/23 19:21:06
nit: should you keep this TODO?
meacer
2015/03/23 20:23:29
Removed in a previous patchset.
| |
540 ListItem plugin_item(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
541 IDR_BLOCKED_PLUGINS), | |
542 base::UTF16ToUTF8(*iter), false, 0); | |
543 add_list_item(plugin_item); | |
544 } | |
545 } | |
546 | |
506 void ContentSettingPluginBubbleModel::OnCustomLinkClicked() { | 547 void ContentSettingPluginBubbleModel::OnCustomLinkClicked() { |
507 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); | 548 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); |
508 // Web contents can be NULL if the tab was closed while the plugins | 549 // Web contents can be NULL if the tab was closed while the plugins |
509 // settings bubble is visible. | 550 // settings bubble is visible. |
510 if (!web_contents()) | 551 if (!web_contents()) |
511 return; | 552 return; |
512 #if defined(ENABLE_PLUGINS) | 553 #if defined(ENABLE_PLUGINS) |
513 // TODO(bauerb): We should send the identifiers of blocked plugins here. | 554 // TODO(bauerb): We should send the identifiers of blocked plugins here. |
514 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 555 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
515 web_contents(), true, std::string()); | 556 web_contents(), true, std::string()); |
516 #endif | 557 #endif |
517 set_custom_link_enabled(false); | 558 set_custom_link_enabled(false); |
518 TabSpecificContentSettings::FromWebContents(web_contents())-> | 559 TabSpecificContentSettings::FromWebContents(web_contents())-> |
519 set_load_plugins_link_enabled(false); | 560 set_load_plugins_link_enabled(false); |
520 } | 561 } |
521 | 562 |
522 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { | 563 class ContentSettingPopupBubbleModel : public ContentSettingItemListModel { |
msw
2015/03/20 22:06:33
nit: rename PopupBubbleModel?
meacer
2015/03/20 23:39:42
Done.
| |
523 public: | 564 public: |
524 ContentSettingPopupBubbleModel(Delegate* delegate, | 565 ContentSettingPopupBubbleModel(Delegate* delegate, |
525 WebContents* web_contents, | 566 WebContents* web_contents, |
526 Profile* profile, | 567 Profile* profile, |
527 ContentSettingsType content_type); | 568 ContentSettingsType content_type); |
528 ~ContentSettingPopupBubbleModel() override {} | 569 ~ContentSettingPopupBubbleModel() override {} |
529 | 570 |
530 private: | 571 private: |
531 void SetPopups(); | 572 void SetListItems() override; |
532 void OnPopupClicked(int index) override; | 573 void OnListItemClicked(int index) override; |
533 }; | 574 }; |
534 | 575 |
535 ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel( | 576 ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel( |
536 Delegate* delegate, | 577 Delegate* delegate, |
537 WebContents* web_contents, | 578 WebContents* web_contents, |
538 Profile* profile, | 579 Profile* profile, |
539 ContentSettingsType content_type) | 580 ContentSettingsType content_type) |
msw
2015/03/20 22:06:33
nit: nix the content_type arg; inline CONTENT_SETT
meacer
2015/03/20 23:39:42
Done, removed from some more classes where applica
| |
540 : ContentSettingSingleRadioGroup( | 581 : ContentSettingItemListModel(delegate, |
541 delegate, web_contents, profile, content_type) { | 582 web_contents, |
542 SetPopups(); | 583 profile, |
584 content_type) { | |
585 SetListItems(); | |
543 } | 586 } |
544 | 587 |
545 | 588 void ContentSettingPopupBubbleModel::SetListItems() { |
546 void ContentSettingPopupBubbleModel::SetPopups() { | |
547 std::map<int32, GURL> blocked_popups = | 589 std::map<int32, GURL> blocked_popups = |
548 PopupBlockerTabHelper::FromWebContents(web_contents()) | 590 PopupBlockerTabHelper::FromWebContents(web_contents()) |
549 ->GetBlockedPopupRequests(); | 591 ->GetBlockedPopupRequests(); |
550 for (std::map<int32, GURL>::const_iterator iter = blocked_popups.begin(); | 592 for (std::map<int32, GURL>::const_iterator iter = blocked_popups.begin(); |
msw
2015/03/20 22:06:33
ditto nit: use range-based-for or auto
meacer
2015/03/20 23:39:42
Done.
| |
551 iter != blocked_popups.end(); | 593 iter != blocked_popups.end(); |
552 ++iter) { | 594 ++iter) { |
553 std::string title(iter->second.spec()); | 595 std::string title(iter->second.spec()); |
554 // The popup may not have a valid URL. | 596 // The popup may not have a valid URL. |
555 if (title.empty()) | 597 if (title.empty()) |
556 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); | 598 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); |
557 PopupItem popup_item( | 599 ListItem popup_item(ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
558 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 600 IDR_DEFAULT_FAVICON), |
559 IDR_DEFAULT_FAVICON), | 601 title, true, iter->first); |
560 title, | 602 add_list_item(popup_item); |
561 iter->first); | |
562 add_popup(popup_item); | |
563 } | 603 } |
564 } | 604 } |
565 | 605 |
566 void ContentSettingPopupBubbleModel::OnPopupClicked(int index) { | 606 void ContentSettingPopupBubbleModel::OnListItemClicked(int index) { |
567 if (web_contents()) { | 607 if (web_contents()) { |
568 PopupBlockerTabHelper::FromWebContents(web_contents())-> | 608 PopupBlockerTabHelper::FromWebContents(web_contents()) |
569 ShowBlockedPopup(bubble_content().popup_items[index].popup_id); | 609 ->ShowBlockedPopup(item_id_from_item_index(index)); |
msw
2015/03/20 22:06:33
This function, item_id_from_item_index(), is only
meacer
2015/03/20 23:39:42
Removed ContentSettingItemListModel.
| |
570 } | 610 } |
571 } | 611 } |
572 | 612 |
573 // The model of the content settings bubble for media settings. | 613 // The model of the content settings bubble for media settings. |
574 class ContentSettingMediaStreamBubbleModel | 614 class ContentSettingMediaStreamBubbleModel |
575 : public ContentSettingTitleAndLinkModel { | 615 : public ContentSettingTitleAndLinkModel { |
576 public: | 616 public: |
577 ContentSettingMediaStreamBubbleModel(Delegate* delegate, | 617 ContentSettingMediaStreamBubbleModel(Delegate* delegate, |
578 WebContents* web_contents, | 618 WebContents* web_contents, |
579 Profile* profile); | 619 Profile* profile); |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1306 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 1346 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
1307 DCHECK_EQ(web_contents_, | 1347 DCHECK_EQ(web_contents_, |
1308 content::Source<WebContents>(source).ptr()); | 1348 content::Source<WebContents>(source).ptr()); |
1309 web_contents_ = NULL; | 1349 web_contents_ = NULL; |
1310 } else { | 1350 } else { |
1311 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1351 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
1312 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1352 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
1313 profile_ = NULL; | 1353 profile_ = NULL; |
1314 } | 1354 } |
1315 } | 1355 } |
OLD | NEW |