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

Side by Side Diff: ios/chrome/browser/web/blocked_popup_tab_helper.h

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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #ifndef IOS_CHROME_BROWSER_WEB_BLOCKED_POPUP_HANDLER_H_ 5 #ifndef IOS_CHROME_BROWSER_WEB_BLOCKED_POPUP_TAB_HELPER_H_
6 #define IOS_CHROME_BROWSER_WEB_BLOCKED_POPUP_HANDLER_H_ 6 #define IOS_CHROME_BROWSER_WEB_BLOCKED_POPUP_TAB_HELPER_H_
7 7
8 #import <UIKit/UIKit.h> 8 #import <UIKit/UIKit.h>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/scoped_observer.h" 12 #include "base/scoped_observer.h"
13 #include "components/infobars/core/infobar_manager.h" 13 #include "components/infobars/core/infobar_manager.h"
14 #import "ios/web/public/web_state/web_state_user_data.h"
14 #include "ios/web/web_state/blocked_popup_info.h" 15 #include "ios/web/web_state/blocked_popup_info.h"
15 #include "url/gurl.h"
16
17 namespace ios {
18 class ChromeBrowserState;
19 }
20
21 @protocol BlockedPopupHandlerDelegate;
22 16
23 // Handles blocked popups. Will display an infobar informing the user and 17 // Handles blocked popups. Will display an infobar informing the user and
24 // allowing the user to add an exception and navigate to the site. 18 // allowing the user to add an exception and navigate to the site.
25 class BlockedPopupHandler : public infobars::InfoBarManager::Observer { 19 class BlockedPopupTabHelper
20 : public infobars::InfoBarManager::Observer,
21 public web::WebStateUserData<BlockedPopupTabHelper> {
26 public: 22 public:
27 explicit BlockedPopupHandler(ios::ChromeBrowserState* browser_state); 23 explicit BlockedPopupTabHelper(web::WebState* web_state);
28 ~BlockedPopupHandler() override; 24 ~BlockedPopupTabHelper() override;
29 25
30 void SetDelegate(id<BlockedPopupHandlerDelegate> delegate); 26 // Shows the popup blocker infobar for the given popup.
31
32 // Show the popup blocker infobar for the given popup.
33 void HandlePopup(const web::BlockedPopupInfo& blocked_popup_info); 27 void HandlePopup(const web::BlockedPopupInfo& blocked_popup_info);
34 28
35 // infobars::InfoBarManager::Observer implementation. 29 // infobars::InfoBarManager::Observer implementation.
36 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override; 30 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override;
37 void OnManagerShuttingDown( 31 void OnManagerShuttingDown(
38 infobars::InfoBarManager* infobar_manager) override; 32 infobars::InfoBarManager* infobar_manager) override;
39 33
40 private: 34 private:
41 // Show the infobar for the current popups. Will also handle replacing an 35 friend class BlockedPopupTabHelperTest;
36
37 // Shows the infobar for the current popups. Will also handle replacing an
42 // existing infobar with the updated count. 38 // existing infobar with the updated count.
43 void ShowInfoBar(); 39 void ShowInfoBar();
44 40
45 // The user browser state. 41 // Registers this object as an observer for the InfoBarManager associated with
46 ios::ChromeBrowserState* browser_state_; 42 // |web_state_|. Does nothing if already registered.
47 // The delegate that will display the infobar. 43 void RegisterAsInfoBarManagerObserverIfNeeded(
48 id<BlockedPopupHandlerDelegate> delegate_; 44 infobars::InfoBarManager* infobar_manager);
45
46 // The WebState that this object is attached to.
47 web::WebState* web_state_;
49 // The currently displayed infobar. 48 // The currently displayed infobar.
50 infobars::InfoBar* infobar_; 49 infobars::InfoBar* infobar_;
51 // The popups to open. 50 // The popups to open.
52 std::vector<web::BlockedPopupInfo> popups_; 51 std::vector<web::BlockedPopupInfo> popups_;
53 // For management of infobars::InfoBarManager::Observer registration. 52 // For management of infobars::InfoBarManager::Observer registration. This
53 // object will not start observing the InfoBarManager until ShowInfoBars() is
54 // called.
54 ScopedObserver<infobars::InfoBarManager, infobars::InfoBarManager::Observer> 55 ScopedObserver<infobars::InfoBarManager, infobars::InfoBarManager::Observer>
55 scoped_observer_; 56 scoped_observer_;
56 57
57 DISALLOW_COPY_AND_ASSIGN(BlockedPopupHandler); 58 DISALLOW_COPY_AND_ASSIGN(BlockedPopupTabHelper);
58 }; 59 };
59 60
60 // Methods implemented by the delegate of the BlockedPopupHandler. 61 #endif // IOS_CHROME_BROWSER_WEB_BLOCKED_POPUP_TAB_HELPER_H_
61 @protocol BlockedPopupHandlerDelegate
62
63 // Returns the infobars::InfoBarManager.
64 - (infobars::InfoBarManager*)infoBarManager;
65
66 @end
67
68 #endif // IOS_CHROME_BROWSER_WEB_BLOCKED_POPUP_HANDLER_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/blocked_popup_handler.mm ('k') | ios/chrome/browser/web/blocked_popup_tab_helper.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698