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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_BLOCKED_CONTENT_POPUP_BLOCKER_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_BLOCKED_CONTENT_POPUP_BLOCKER_TAB_HELPER_H_
10 #include "base/id_map.h"
11 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h"
16 struct NavigateParams;
20 struct WebWindowFeatures;
25 // Per-tab class to manage blocked popups.
26 class PopupBlockerTabHelper
27 : public content::WebContentsObserver,
28 public content::WebContentsUserData<PopupBlockerTabHelper> {
30 virtual ~PopupBlockerTabHelper();
32 // Returns true if the popup request defined by |params| should be blocked.
33 // In that case, it is also added to the |blocked_popups_| container.
34 bool MaybeBlockPopup(const chrome::NavigateParams& params,
35 const WebKit::WebWindowFeatures& window_features);
37 // Adds a popup request to the |blocked_popups_| container.
38 void AddBlockedPopup(const BlockedWindowParams& params);
40 // Creates the blocked popup with |popup_id|.
41 void ShowBlockedPopup(int32 popup_id);
43 // Returns the number of blocked popups.
44 size_t GetBlockedPopupsCount() const;
46 // Returns the mapping from popup IDs to blocked popup requests.
47 std::map<int32, GURL> GetBlockedPopupRequests();
49 // content::WebContentsObserver overrides:
50 virtual void DidNavigateMainFrame(
51 const content::LoadCommittedDetails& details,
52 const content::FrameNavigateParams& params) OVERRIDE;
55 struct BlockedRequest;
56 friend class content::WebContentsUserData<PopupBlockerTabHelper>;
58 explicit PopupBlockerTabHelper(content::WebContents* web_contents);
60 // Called when the blocked popup notification is shown or hidden.
61 void PopupNotificationVisibilityChanged(bool visible);
63 IDMap<BlockedRequest, IDMapOwnPointer> blocked_popups_;
65 DISALLOW_COPY_AND_ASSIGN(PopupBlockerTabHelper);
68 #endif // CHROME_BROWSER_UI_BLOCKED_CONTENT_POPUP_BLOCKER_TAB_HELPER_H_