| OLD | NEW |
| 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_factory.h" |
| 8 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 11 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
| 11 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/content_settings/core/browser/host_content_settings_map.h" | 13 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 13 #include "components/content_settings/core/common/content_settings.h" | 14 #include "components/content_settings/core/common/content_settings.h" |
| 14 #include "components/content_settings/core/common/content_settings_types.h" | 15 #include "components/content_settings/core/common/content_settings_types.h" |
| 15 #include "components/infobars/core/infobar.h" | 16 #include "components/infobars/core/infobar.h" |
| 16 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 18 | 19 |
| 19 | 20 |
| 20 // static | 21 // static |
| 21 void PopupBlockedInfoBarDelegate::Create(content::WebContents* web_contents, | 22 void PopupBlockedInfoBarDelegate::Create(content::WebContents* web_contents, |
| 22 int num_popups) { | 23 int num_popups) { |
| 23 const GURL& url = web_contents->GetURL(); | 24 const GURL& url = web_contents->GetURL(); |
| 24 Profile* profile = | 25 Profile* profile = |
| 25 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 26 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 26 InfoBarService* infobar_service = | 27 InfoBarService* infobar_service = |
| 27 InfoBarService::FromWebContents(web_contents); | 28 InfoBarService::FromWebContents(web_contents); |
| 28 scoped_ptr<infobars::InfoBar> infobar(infobar_service->CreateConfirmInfoBar( | 29 scoped_ptr<infobars::InfoBar> infobar(infobar_service->CreateConfirmInfoBar( |
| 29 scoped_ptr<ConfirmInfoBarDelegate>(new PopupBlockedInfoBarDelegate( | 30 scoped_ptr<ConfirmInfoBarDelegate>(new PopupBlockedInfoBarDelegate( |
| 30 num_popups, url, profile->GetHostContentSettingsMap())))); | 31 num_popups, |
| 32 url, |
| 33 HostContentSettingsMapFactory::GetForProfile(profile))))); |
| 31 | 34 |
| 32 // See if there is an existing popup infobar already. | 35 // See if there is an existing popup infobar already. |
| 33 // TODO(dfalcantara) When triggering more than one popup the infobar | 36 // TODO(dfalcantara) When triggering more than one popup the infobar |
| 34 // will be shown once, then hide then be shown again. | 37 // will be shown once, then hide then be shown again. |
| 35 // This will be fixed once we have an in place replace infobar mechanism. | 38 // This will be fixed once we have an in place replace infobar mechanism. |
| 36 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 39 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| 37 infobars::InfoBar* existing_infobar = infobar_service->infobar_at(i); | 40 infobars::InfoBar* existing_infobar = infobar_service->infobar_at(i); |
| 38 if (existing_infobar->delegate()->AsPopupBlockedInfoBarDelegate()) { | 41 if (existing_infobar->delegate()->AsPopupBlockedInfoBarDelegate()) { |
| 39 infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass()); | 42 infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass()); |
| 40 return; | 43 return; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 PopupBlockerTabHelper::FromWebContents(web_contents); | 102 PopupBlockerTabHelper::FromWebContents(web_contents); |
| 100 DCHECK(popup_blocker_helper); | 103 DCHECK(popup_blocker_helper); |
| 101 PopupBlockerTabHelper::PopupIdMap blocked_popups = | 104 PopupBlockerTabHelper::PopupIdMap blocked_popups = |
| 102 popup_blocker_helper->GetBlockedPopupRequests(); | 105 popup_blocker_helper->GetBlockedPopupRequests(); |
| 103 for (PopupBlockerTabHelper::PopupIdMap::iterator it = blocked_popups.begin(); | 106 for (PopupBlockerTabHelper::PopupIdMap::iterator it = blocked_popups.begin(); |
| 104 it != blocked_popups.end(); ++it) | 107 it != blocked_popups.end(); ++it) |
| 105 popup_blocker_helper->ShowBlockedPopup(it->first); | 108 popup_blocker_helper->ShowBlockedPopup(it->first); |
| 106 | 109 |
| 107 return true; | 110 return true; |
| 108 } | 111 } |
| OLD | NEW |