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

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

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 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 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_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 12 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
12 #include "chrome/common/content_settings_types.h" 13 #include "chrome/common/content_settings_types.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 17
17 18
18 // static 19 // static
19 void PopupBlockedInfoBarDelegate::Create(InfoBarService* infobar_service, 20 void PopupBlockedInfoBarDelegate::Create(InfoBarService* infobar_service,
20 int num_popups) { 21 int num_popups) {
21 scoped_ptr<InfoBarDelegate> infobar( 22 scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar(
22 new PopupBlockedInfoBarDelegate(infobar_service, num_popups)); 23 scoped_ptr<ConfirmInfoBarDelegate>(
24 new PopupBlockedInfoBarDelegate(num_popups))));
23 25
24 // See if there is an existing popup infobar already. 26 // See if there is an existing popup infobar already.
25 // TODO(dfalcantara) When triggering more than one popup the infobar 27 // TODO(dfalcantara) When triggering more than one popup the infobar
26 // will be shown once, then hide then be shown again. 28 // will be shown once, then hide then be shown again.
27 // This will be fixed once we have an in place replace infobar mechanism. 29 // This will be fixed once we have an in place replace infobar mechanism.
28 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { 30 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
29 InfoBarDelegate* existing_infobar = infobar_service->infobar_at(i); 31 InfoBar* existing_infobar = infobar_service->infobar_at(i);
30 if (existing_infobar->AsPopupBlockedInfoBarDelegate()) { 32 if (existing_infobar->delegate()->AsPopupBlockedInfoBarDelegate()) {
31 infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass()); 33 infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass());
32 return; 34 return;
33 } 35 }
34 } 36 }
35 37
36 infobar_service->AddInfoBar(infobar.Pass()); 38 infobar_service->AddInfoBar(infobar.Pass());
37 } 39 }
38 40
39 PopupBlockedInfoBarDelegate::~PopupBlockedInfoBarDelegate() { 41 PopupBlockedInfoBarDelegate::~PopupBlockedInfoBarDelegate() {
40 } 42 }
41 43
42 int PopupBlockedInfoBarDelegate::GetIconID() const { 44 int PopupBlockedInfoBarDelegate::GetIconID() const {
43 return IDR_BLOCKED_POPUPS; 45 return IDR_BLOCKED_POPUPS;
44 } 46 }
45 47
46 PopupBlockedInfoBarDelegate* 48 PopupBlockedInfoBarDelegate*
47 PopupBlockedInfoBarDelegate::AsPopupBlockedInfoBarDelegate() { 49 PopupBlockedInfoBarDelegate::AsPopupBlockedInfoBarDelegate() {
48 return this; 50 return this;
49 } 51 }
50 52
51 PopupBlockedInfoBarDelegate::PopupBlockedInfoBarDelegate( 53 PopupBlockedInfoBarDelegate::PopupBlockedInfoBarDelegate(int num_popups)
52 InfoBarService* infobar_service, 54 : ConfirmInfoBarDelegate(),
53 int num_popups)
54 : ConfirmInfoBarDelegate(infobar_service),
55 num_popups_(num_popups) { 55 num_popups_(num_popups) {
56 } 56 }
57 57
58 string16 PopupBlockedInfoBarDelegate::GetMessageText() const { 58 string16 PopupBlockedInfoBarDelegate::GetMessageText() const {
59 return l10n_util::GetStringFUTF16Int(IDS_POPUPS_BLOCKED_INFOBAR_TEXT, 59 return l10n_util::GetStringFUTF16Int(IDS_POPUPS_BLOCKED_INFOBAR_TEXT,
60 num_popups_); 60 num_popups_);
61 } 61 }
62 62
63 int PopupBlockedInfoBarDelegate::GetButtons() const { 63 int PopupBlockedInfoBarDelegate::GetButtons() const {
64 return BUTTON_OK; 64 return BUTTON_OK;
65 } 65 }
66 66
67 string16 PopupBlockedInfoBarDelegate::GetButtonLabel( 67 string16 PopupBlockedInfoBarDelegate::GetButtonLabel(
68 InfoBarButton button) const { 68 InfoBarButton button) const {
69 return l10n_util::GetStringUTF16(IDS_POPUPS_BLOCKED_INFOBAR_BUTTON_SHOW); 69 return l10n_util::GetStringUTF16(IDS_POPUPS_BLOCKED_INFOBAR_BUTTON_SHOW);
70 } 70 }
71 71
72 bool PopupBlockedInfoBarDelegate::Accept() { 72 bool PopupBlockedInfoBarDelegate::Accept() {
73 // Create exceptions. 73 // Create exceptions.
74 content::WebContents* web_contents = owner()->web_contents(); 74 const GURL& url = web_contents()->GetURL();
75 const GURL& url = web_contents->GetURL();
76 Profile* profile = Profile::FromBrowserContext( 75 Profile* profile = Profile::FromBrowserContext(
77 web_contents->GetBrowserContext()); 76 web_contents()->GetBrowserContext());
78 profile->GetHostContentSettingsMap()->AddExceptionForURL( 77 profile->GetHostContentSettingsMap()->AddExceptionForURL(
79 url, url, CONTENT_SETTINGS_TYPE_POPUPS, std::string(), 78 url, url, CONTENT_SETTINGS_TYPE_POPUPS, std::string(),
80 CONTENT_SETTING_ALLOW); 79 CONTENT_SETTING_ALLOW);
81 80
82 // Launch popups. 81 // Launch popups.
83 PopupBlockerTabHelper* popup_blocker_helper = 82 PopupBlockerTabHelper* popup_blocker_helper =
84 PopupBlockerTabHelper::FromWebContents(web_contents); 83 PopupBlockerTabHelper::FromWebContents(web_contents());
85 DCHECK(popup_blocker_helper); 84 DCHECK(popup_blocker_helper);
86 PopupBlockerTabHelper::PopupIdMap blocked_popups = 85 PopupBlockerTabHelper::PopupIdMap blocked_popups =
87 popup_blocker_helper->GetBlockedPopupRequests(); 86 popup_blocker_helper->GetBlockedPopupRequests();
88 for (PopupBlockerTabHelper::PopupIdMap::iterator it = blocked_popups.begin(); 87 for (PopupBlockerTabHelper::PopupIdMap::iterator it = blocked_popups.begin();
89 it != blocked_popups.end(); ++it) 88 it != blocked_popups.end(); ++it)
90 popup_blocker_helper->ShowBlockedPopup(it->first); 89 popup_blocker_helper->ShowBlockedPopup(it->first);
91 90
92 return true; 91 return true;
93 } 92 }
94 93
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698