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

Unified Diff: ios/chrome/browser/web/blocked_popup_handler.mm

Issue 2640463002: [ios] Convert BlockedPopupHandler into a tab helper class. (Closed)
Patch Set: Rebased. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/web/blocked_popup_handler.h ('k') | ios/chrome/browser/web/blocked_popup_tab_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/web/blocked_popup_handler.mm
diff --git a/ios/chrome/browser/web/blocked_popup_handler.mm b/ios/chrome/browser/web/blocked_popup_handler.mm
deleted file mode 100644
index 40c6b71212cced9327d62f0164fdc50de0c0997d..0000000000000000000000000000000000000000
--- a/ios/chrome/browser/web/blocked_popup_handler.mm
+++ /dev/null
@@ -1,139 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import "ios/chrome/browser/web/blocked_popup_handler.h"
-
-#include <memory>
-#include <utility>
-
-#include "base/format_macros.h"
-#include "base/mac/bundle_locations.h"
-#include "base/mac/foundation_util.h"
-#include "base/strings/stringprintf.h"
-#include "base/strings/utf_string_conversions.h"
-#include "components/content_settings/core/browser/host_content_settings_map.h"
-#include "components/infobars/core/confirm_infobar_delegate.h"
-#include "components/infobars/core/infobar.h"
-#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
-#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
-#include "ios/chrome/grit/ios_strings.h"
-#include "ios/web/public/referrer.h"
-#include "net/base/mac/url_conversions.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/gfx/image/image.h"
-
-namespace {
-// The infobar to display when a popup is blocked.
-class BlockPopupInfoBarDelegate : public ConfirmInfoBarDelegate {
- public:
- BlockPopupInfoBarDelegate(ios::ChromeBrowserState* browser_state,
- const std::vector<web::BlockedPopupInfo>& popups)
- : browser_state_(browser_state), popups_(popups) {}
-
- ~BlockPopupInfoBarDelegate() override {}
-
- InfoBarIdentifier GetIdentifier() const override {
- return POPUP_BLOCKED_INFOBAR_DELEGATE;
- }
-
- gfx::Image GetIcon() const override {
- if (icon_.IsEmpty()) {
- icon_ = gfx::Image([UIImage imageNamed:@"infobar_popup_blocker"]);
- }
- return icon_;
- }
-
- infobars::InfoBarDelegate::Type GetInfoBarType() const override {
- return WARNING_TYPE;
- }
-
- base::string16 GetMessageText() const override {
- return l10n_util::GetStringFUTF16(
- IDS_IOS_POPUPS_BLOCKED_MOBILE,
- base::UTF8ToUTF16(base::StringPrintf("%" PRIuS, popups_.size())));
- }
-
- base::string16 GetButtonLabel(InfoBarButton button) const override {
- DCHECK(button == BUTTON_OK);
- return l10n_util::GetStringUTF16(IDS_IOS_POPUPS_ALWAYS_SHOW_MOBILE);
- }
-
- bool Accept() override {
- std::vector<web::BlockedPopupInfo>::iterator it;
- scoped_refptr<HostContentSettingsMap> host_content_map_settings(
- ios::HostContentSettingsMapFactory::GetForBrowserState(browser_state_));
- for (it = popups_.begin(); it != popups_.end(); ++it) {
- it->ShowPopup();
- host_content_map_settings->SetContentSettingCustomScope(
- ContentSettingsPattern::FromURL(it->referrer().url),
- ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS,
- std::string(), CONTENT_SETTING_ALLOW);
- }
- return true;
- }
-
- int GetButtons() const override { return BUTTON_OK; }
-
- private:
- // The browser state to access user preferences.
- ios::ChromeBrowserState* browser_state_;
- // The popups to open.
- std::vector<web::BlockedPopupInfo> popups_;
- // The icon to display.
- mutable gfx::Image icon_;
-};
-} // namespace
-
-BlockedPopupHandler::BlockedPopupHandler(ios::ChromeBrowserState* browser_state)
- : browser_state_(browser_state),
- delegate_(nullptr),
- infobar_(nullptr),
- scoped_observer_(this) {}
-
-BlockedPopupHandler::~BlockedPopupHandler() {}
-
-void BlockedPopupHandler::SetDelegate(
- id<BlockedPopupHandlerDelegate> delegate) {
- scoped_observer_.RemoveAll();
- delegate_ = delegate;
- if (delegate_)
- scoped_observer_.Add([delegate_ infoBarManager]);
-}
-
-void BlockedPopupHandler::HandlePopup(
- const web::BlockedPopupInfo& blocked_popup_info) {
- if (!delegate_)
- return;
-
- popups_.push_back(blocked_popup_info);
- ShowInfoBar();
-}
-
-void BlockedPopupHandler::OnInfoBarRemoved(infobars::InfoBar* infobar,
- bool animate) {
- if (infobar == infobar_) {
- infobar_ = nullptr;
- popups_.clear();
- }
-}
-
-void BlockedPopupHandler::OnManagerShuttingDown(
- infobars::InfoBarManager* infobar_manager) {
- scoped_observer_.Remove(infobar_manager);
-}
-
-void BlockedPopupHandler::ShowInfoBar() {
- if (!popups_.size() || !delegate_)
- return;
- infobars::InfoBarManager* infobar_manager = [delegate_ infoBarManager];
- std::unique_ptr<infobars::InfoBar> infobar =
- infobar_manager->CreateConfirmInfoBar(
- std::unique_ptr<ConfirmInfoBarDelegate>(
- new BlockPopupInfoBarDelegate(browser_state_, popups_)));
- if (infobar_) {
- infobar_ = infobar_manager->ReplaceInfoBar(infobar_, std::move(infobar));
- } else {
- infobar_ = infobar_manager->AddInfoBar(std::move(infobar));
- }
-}
« no previous file with comments | « ios/chrome/browser/web/blocked_popup_handler.h ('k') | ios/chrome/browser/web/blocked_popup_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698