- add sources.
[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 WebKit {
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   virtual ~PopupBlockerTabHelper();
31
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);
36
37   // Adds a popup request to the |blocked_popups_| container.
38   void AddBlockedPopup(const BlockedWindowParams& params);
39
40   // Creates the blocked popup with |popup_id|.
41   void ShowBlockedPopup(int32 popup_id);
42
43   // Returns the number of blocked popups.
44   size_t GetBlockedPopupsCount() const;
45
46   // Returns the mapping from popup IDs to blocked popup requests.
47   std::map<int32, GURL> GetBlockedPopupRequests();
48
49   // content::WebContentsObserver overrides:
50   virtual void DidNavigateMainFrame(
51       const content::LoadCommittedDetails& details,
52       const content::FrameNavigateParams& params) OVERRIDE;
53
54  private:
55   struct BlockedRequest;
56   friend class content::WebContentsUserData<PopupBlockerTabHelper>;
57
58   explicit PopupBlockerTabHelper(content::WebContents* web_contents);
59
60   // Called when the blocked popup notification is shown or hidden.
61   void PopupNotificationVisibilityChanged(bool visible);
62
63   IDMap<BlockedRequest, IDMapOwnPointer> blocked_popups_;
64
65   DISALLOW_COPY_AND_ASSIGN(PopupBlockerTabHelper);
66 };
67
68 #endif  // CHROME_BROWSER_UI_BLOCKED_CONTENT_POPUP_BLOCKER_TAB_HELPER_H_