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

Side by Side Diff: chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.cc

Issue 143333008: [Android] Remove the "Always show" button for blocked popups if the setting is controlled by policy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue340704a
Patch Set: x Created 6 years, 10 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
« no previous file with comments | « chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/android/content_settings/popup_blocked_infobar_deleg ate.h" 5 #include "chrome/browser/ui/android/content_settings/popup_blocked_infobar_deleg ate.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h" 8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/infobars/infobar.h" 9 #include "chrome/browser/infobars/infobar.h"
10 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 12 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
13 #include "chrome/common/content_settings.h"
13 #include "chrome/common/content_settings_types.h" 14 #include "chrome/common/content_settings_types.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
17 18
18 19
19 // static 20 // static
20 void PopupBlockedInfoBarDelegate::Create(InfoBarService* infobar_service, 21 void PopupBlockedInfoBarDelegate::Create(content::WebContents* web_contents,
21 int num_popups) { 22 int num_popups) {
23 const GURL& url = web_contents->GetURL();
24 Profile* profile =
25 Profile::FromBrowserContext(web_contents->GetBrowserContext());
22 scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( 26 scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar(
23 scoped_ptr<ConfirmInfoBarDelegate>( 27 scoped_ptr<ConfirmInfoBarDelegate>(
24 new PopupBlockedInfoBarDelegate(num_popups)))); 28 new PopupBlockedInfoBarDelegate(
29 num_popups, url, profile->GetHostContentSettingsMap()))));
25 30
31 InfoBarService* infobar_service =
32 InfoBarService::FromWebContents(web_contents);
26 // See if there is an existing popup infobar already. 33 // See if there is an existing popup infobar already.
27 // TODO(dfalcantara) When triggering more than one popup the infobar 34 // TODO(dfalcantara) When triggering more than one popup the infobar
28 // will be shown once, then hide then be shown again. 35 // will be shown once, then hide then be shown again.
29 // This will be fixed once we have an in place replace infobar mechanism. 36 // This will be fixed once we have an in place replace infobar mechanism.
30 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { 37 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
31 InfoBar* existing_infobar = infobar_service->infobar_at(i); 38 InfoBar* existing_infobar = infobar_service->infobar_at(i);
32 if (existing_infobar->delegate()->AsPopupBlockedInfoBarDelegate()) { 39 if (existing_infobar->delegate()->AsPopupBlockedInfoBarDelegate()) {
33 infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass()); 40 infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass());
34 return; 41 return;
35 } 42 }
36 } 43 }
37 44
38 infobar_service->AddInfoBar(infobar.Pass()); 45 infobar_service->AddInfoBar(infobar.Pass());
39 } 46 }
40 47
41 PopupBlockedInfoBarDelegate::~PopupBlockedInfoBarDelegate() { 48 PopupBlockedInfoBarDelegate::~PopupBlockedInfoBarDelegate() {
42 } 49 }
43 50
44 int PopupBlockedInfoBarDelegate::GetIconID() const { 51 int PopupBlockedInfoBarDelegate::GetIconID() const {
45 return IDR_BLOCKED_POPUPS; 52 return IDR_BLOCKED_POPUPS;
46 } 53 }
47 54
48 PopupBlockedInfoBarDelegate* 55 PopupBlockedInfoBarDelegate*
49 PopupBlockedInfoBarDelegate::AsPopupBlockedInfoBarDelegate() { 56 PopupBlockedInfoBarDelegate::AsPopupBlockedInfoBarDelegate() {
50 return this; 57 return this;
51 } 58 }
52 59
53 PopupBlockedInfoBarDelegate::PopupBlockedInfoBarDelegate(int num_popups) 60 PopupBlockedInfoBarDelegate::PopupBlockedInfoBarDelegate(
54 : ConfirmInfoBarDelegate(), 61 int num_popups,
55 num_popups_(num_popups) { 62 const GURL& url,
63 HostContentSettingsMap* map)
64 : ConfirmInfoBarDelegate(), num_popups_(num_popups), url_(url), map_(map) {
65 content_settings::SettingInfo setting_info;
66 scoped_ptr<base::Value> setting(
67 map->GetWebsiteSetting(
68 url,
69 url,
70 CONTENT_SETTINGS_TYPE_POPUPS,
71 std::string(),
72 &setting_info));
73 can_show_popups_ =
74 setting_info.source != content_settings::SETTING_SOURCE_POLICY;
56 } 75 }
57 76
58 base::string16 PopupBlockedInfoBarDelegate::GetMessageText() const { 77 base::string16 PopupBlockedInfoBarDelegate::GetMessageText() const {
59 return l10n_util::GetStringFUTF16Int(IDS_POPUPS_BLOCKED_INFOBAR_TEXT, 78 return l10n_util::GetStringFUTF16Int(IDS_POPUPS_BLOCKED_INFOBAR_TEXT,
60 num_popups_); 79 num_popups_);
61 } 80 }
62 81
63 int PopupBlockedInfoBarDelegate::GetButtons() const { 82 int PopupBlockedInfoBarDelegate::GetButtons() const {
83 if (!can_show_popups_)
84 return 0;
85
64 return BUTTON_OK; 86 return BUTTON_OK;
65 } 87 }
66 88
67 base::string16 PopupBlockedInfoBarDelegate::GetButtonLabel( 89 base::string16 PopupBlockedInfoBarDelegate::GetButtonLabel(
68 InfoBarButton button) const { 90 InfoBarButton button) const {
69 return l10n_util::GetStringUTF16(IDS_POPUPS_BLOCKED_INFOBAR_BUTTON_SHOW); 91 return l10n_util::GetStringUTF16(IDS_POPUPS_BLOCKED_INFOBAR_BUTTON_SHOW);
70 } 92 }
71 93
72 bool PopupBlockedInfoBarDelegate::Accept() { 94 bool PopupBlockedInfoBarDelegate::Accept() {
95 DCHECK(can_show_popups_);
96
73 // Create exceptions. 97 // Create exceptions.
74 const GURL& url = web_contents()->GetURL(); 98 map_->AddExceptionForURL(
75 Profile* profile = Profile::FromBrowserContext( 99 url_, url_, CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW);
76 web_contents()->GetBrowserContext());
77 profile->GetHostContentSettingsMap()->AddExceptionForURL(
78 url, url, CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW);
79 100
80 // Launch popups. 101 // Launch popups.
81 PopupBlockerTabHelper* popup_blocker_helper = 102 PopupBlockerTabHelper* popup_blocker_helper =
82 PopupBlockerTabHelper::FromWebContents(web_contents()); 103 PopupBlockerTabHelper::FromWebContents(web_contents());
83 DCHECK(popup_blocker_helper); 104 DCHECK(popup_blocker_helper);
84 PopupBlockerTabHelper::PopupIdMap blocked_popups = 105 PopupBlockerTabHelper::PopupIdMap blocked_popups =
85 popup_blocker_helper->GetBlockedPopupRequests(); 106 popup_blocker_helper->GetBlockedPopupRequests();
86 for (PopupBlockerTabHelper::PopupIdMap::iterator it = blocked_popups.begin(); 107 for (PopupBlockerTabHelper::PopupIdMap::iterator it = blocked_popups.begin();
87 it != blocked_popups.end(); ++it) 108 it != blocked_popups.end(); ++it)
88 popup_blocker_helper->ShowBlockedPopup(it->first); 109 popup_blocker_helper->ShowBlockedPopup(it->first);
89 110
90 return true; 111 return true;
91 } 112 }
92 113
OLDNEW
« no previous file with comments | « chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698