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.
5 #ifndef COMPONENTS_WEB_MODAL_POPUP_MANAGER_H_
6 #define COMPONENTS_WEB_MODAL_POPUP_MANAGER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "ui/gfx/native_widget_types.h"
22 class WebContentsModalDialogHost
;
24 // Per-Browser class to manage popups (bubbles, web-modal dialogs).
27 // |host| may be null.
28 explicit PopupManager(WebContentsModalDialogHost
* host
);
32 // Returns the native view which will be the parent of managed popups.
33 gfx::NativeView
GetHostView() const;
35 // Temporary method: Provides compatibility with existing
36 // WebContentsModalDialogManager code.
37 void ShowModalDialog(gfx::NativeWindow popup
,
38 content::WebContents
* web_contents
);
40 // Returns true if a web modal dialog is active and not closed in the
41 // given |web_contents|. Note: this is intended for legacy use only; it will
42 // be deleted at some point -- new code shouldn't use it.
43 bool IsWebModalDialogActive(const content::WebContents
* web_contents
) const;
45 // Called when a native popup we own is about to be closed.
46 void WillClose(gfx::NativeWindow popup
);
48 // Called by views code to re-activate popups anchored to a particular tab
49 // when that tab gets focus. Note that depending on the situation, more than
50 // one popup may actually be shown (depending on overlappability). The
51 // semantics are that the popups that would have been displayed had the tab
52 // never lost focus are re-focused when tab focus is regained.
53 void WasFocused(const content::WebContents
* web_contents
);
55 // WebContentsUserData-alike API for retrieving the associated window
56 // PopupManager from a |web_contents|. Any window which doesn't have a popup
57 // manager associated will return null -- popups should not be issued against
59 static PopupManager
* FromWebContents(content::WebContents
* web_contents
);
61 // Should not be called except by WebContents-owning class; not by clients.
62 void RegisterWith(content::WebContents
* web_contents
);
63 void UnregisterWith(content::WebContents
* web_contents
);
66 void CloseAllDialogsForTesting(content::WebContents
* web_contents
);
69 WebContentsModalDialogHost
* host_
;
71 base::WeakPtrFactory
<PopupManager
> weak_factory_
;
73 DISALLOW_COPY_AND_ASSIGN(PopupManager
);
76 } // namespace web_modal
78 #endif // COMPONENTS_WEB_MODAL_POPUP_MANAGER_H_