| 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
|
| index 40c6b71212cced9327d62f0164fdc50de0c0997d..f4eab97dbed20725f340eb056d39df501c567b54 100644
|
| --- a/ios/chrome/browser/web/blocked_popup_handler.mm
|
| +++ b/ios/chrome/browser/web/blocked_popup_handler.mm
|
| @@ -17,12 +17,15 @@
|
| #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/browser/infobars/infobar_manager_impl.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"
|
|
|
| +DEFINE_WEB_STATE_USER_DATA_KEY(BlockedPopupHandler);
|
| +
|
| namespace {
|
| // The infobar to display when a popup is blocked.
|
| class BlockPopupInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| @@ -85,27 +88,28 @@ class BlockPopupInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| };
|
| } // namespace
|
|
|
| -BlockedPopupHandler::BlockedPopupHandler(ios::ChromeBrowserState* browser_state)
|
| - : browser_state_(browser_state),
|
| - delegate_(nullptr),
|
| - infobar_(nullptr),
|
| - scoped_observer_(this) {}
|
| +// static
|
| +void BlockedPopupHandler::CreateForWebState(web::WebState* web_state) {
|
| + DCHECK(web_state);
|
| + if (!FromWebState(web_state)) {
|
| + web_state->SetUserData(UserDataKey(), new BlockedPopupHandler(web_state));
|
| + }
|
| +}
|
| +
|
| +BlockedPopupHandler::BlockedPopupHandler(web::WebState* web_state)
|
| + : web_state_(web_state), 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::Initialize() {
|
| + infobars::InfoBarManager* manager =
|
| + InfoBarManagerImpl::FromWebState(web_state_);
|
| + DCHECK(manager);
|
| + scoped_observer_.Add(manager);
|
| }
|
|
|
| void BlockedPopupHandler::HandlePopup(
|
| const web::BlockedPopupInfo& blocked_popup_info) {
|
| - if (!delegate_)
|
| - return;
|
| -
|
| popups_.push_back(blocked_popup_info);
|
| ShowInfoBar();
|
| }
|
| @@ -124,13 +128,17 @@ void BlockedPopupHandler::OnManagerShuttingDown(
|
| }
|
|
|
| void BlockedPopupHandler::ShowInfoBar() {
|
| - if (!popups_.size() || !delegate_)
|
| + infobars::InfoBarManager* infobar_manager =
|
| + InfoBarManagerImpl::FromWebState(web_state_);
|
| + if (!popups_.size() || !infobar_manager)
|
| return;
|
| - infobars::InfoBarManager* infobar_manager = [delegate_ infoBarManager];
|
| +
|
| + ios::ChromeBrowserState* browser_state =
|
| + ios::ChromeBrowserState::FromBrowserState(web_state_->GetBrowserState());
|
| std::unique_ptr<infobars::InfoBar> infobar =
|
| infobar_manager->CreateConfirmInfoBar(
|
| std::unique_ptr<ConfirmInfoBarDelegate>(
|
| - new BlockPopupInfoBarDelegate(browser_state_, popups_)));
|
| + new BlockPopupInfoBarDelegate(browser_state, popups_)));
|
| if (infobar_) {
|
| infobar_ = infobar_manager->ReplaceInfoBar(infobar_, std::move(infobar));
|
| } else {
|
|
|