Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / components / web_modal / popup_manager.h
1 // Copyright 2014 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 COMPONENTS_WEB_MODAL_POPUP_MANAGER_H_
6 #define COMPONENTS_WEB_MODAL_POPUP_MANAGER_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "components/web_modal/single_popup_manager.h"
11
12 namespace content {
13 class WebContents;
14 }
15
16 namespace gfx {
17 class Size;
18 }
19
20 namespace web_modal {
21
22 class WebContentsModalDialogHost;
23
24 // Per-Browser class to manage popups (bubbles, web-modal dialogs).
25 class PopupManager : public SinglePopupManagerDelegate {
26  public:
27   // |host| may be null.
28   PopupManager(WebContentsModalDialogHost* host);
29
30   virtual ~PopupManager();
31
32   // Returns the native view which will be the parent of managed popups.
33   virtual gfx::NativeView GetHostView() const;
34
35   // Schedules a popup governed by the |manager| to be shown. The popup
36   // may be shown inline with this call, at a later time, or not at all.
37   virtual void ShowPopup(scoped_ptr<SinglePopupManager> manager);
38
39   // Temporary method: Provides compatibility with existing
40   // WebContentsModalDialogManager code.
41   virtual void ShowModalDialog(NativePopup popup,
42                                content::WebContents* web_contents);
43
44   // Returns true if a web modal dialog is active and not closed in the
45   // given |web_contents|. Note: this is intended for legacy use only; it will
46   // be deleted at some point -- new code shouldn't use it.
47   virtual bool IsWebModalDialogActive(
48       const content::WebContents* web_contents) const;
49
50   // Called when a NativePopup we own is about to be closed.
51   virtual void WillClose(NativePopup popup) OVERRIDE;
52
53   // Called by views code to re-activate popups anchored to a particular tab
54   // when that tab gets focus. Note that depending on the situation, more than
55   // one popup may actually be shown (depending on overlappability). The
56   // semantics are that the popups that would have been displayed had the tab
57   // never lost focus are re-focused when tab focus is regained.
58   virtual void WasFocused(const content::WebContents* web_contents);
59
60   // WebContentsUserData-alike API for retrieving the associated window
61   // PopupManager from a |web_contents|. Any window which doesn't have a popup
62   // manager associated will return null -- popups should not be issued against
63   // that window.
64   static PopupManager* FromWebContents(content::WebContents* web_contents);
65
66   // Should not be called except by WebContents-owning class; not by clients.
67   void RegisterWith(content::WebContents* web_contents);
68   void UnregisterWith(content::WebContents* web_contents);
69
70   // DEPRECATED.
71   virtual void CloseAllDialogsForTesting(content::WebContents* web_contents);
72
73  private:
74   WebContentsModalDialogHost* host_;
75
76   base::WeakPtrFactory<PopupManager> weak_factory_;
77
78   DISALLOW_COPY_AND_ASSIGN(PopupManager);
79 };
80
81 }  // namespace web_modal
82
83 #endif  // COMPONENTS_WEB_MODAL_POPUP_MANAGER_H_