Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / blocked_content / popup_blocker_tab_helper.h
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.
4
5 #ifndef CHROME_BROWSER_UI_BLOCKED_CONTENT_POPUP_BLOCKER_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_BLOCKED_CONTENT_POPUP_BLOCKER_TAB_HELPER_H_
7
8 #include <map>
9
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"
14
15 namespace chrome {
16 struct NavigateParams;
17 }
18
19 namespace blink {
20 struct WebWindowFeatures;
21 }
22
23 class GURL;
24
25 // Per-tab class to manage blocked popups.
26 class PopupBlockerTabHelper
27     : public content::WebContentsObserver,
28       public content::WebContentsUserData<PopupBlockerTabHelper> {
29  public:
30   // Mapping from popup IDs to blocked popup requests.
31   typedef std::map<int32, GURL> PopupIdMap;
32
33   ~PopupBlockerTabHelper() override;
34
35   // Returns true if the popup request defined by |params| should be blocked.
36   // In that case, it is also added to the |blocked_popups_| container.
37   bool MaybeBlockPopup(const chrome::NavigateParams& params,
38                        const blink::WebWindowFeatures& window_features);
39
40   // Adds a popup request to the |blocked_popups_| container.
41   void AddBlockedPopup(const BlockedWindowParams& params);
42
43   // Creates the blocked popup with |popup_id|.
44   void ShowBlockedPopup(int32 popup_id);
45
46   // Returns the number of blocked popups.
47   size_t GetBlockedPopupsCount() const;
48
49   PopupIdMap GetBlockedPopupRequests();
50
51   // content::WebContentsObserver overrides:
52   void DidNavigateMainFrame(
53       const content::LoadCommittedDetails& details,
54       const content::FrameNavigateParams& params) override;
55
56  private:
57   struct BlockedRequest;
58   friend class content::WebContentsUserData<PopupBlockerTabHelper>;
59
60   explicit PopupBlockerTabHelper(content::WebContents* web_contents);
61
62   // Called when the blocked popup notification is shown or hidden.
63   void PopupNotificationVisibilityChanged(bool visible);
64
65   IDMap<BlockedRequest, IDMapOwnPointer> blocked_popups_;
66
67   DISALLOW_COPY_AND_ASSIGN(PopupBlockerTabHelper);
68 };
69
70 #endif  // CHROME_BROWSER_UI_BLOCKED_CONTENT_POPUP_BLOCKER_TAB_HELPER_H_