1 // Copyright (c) 2012 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_GTK_EXTENSIONS_EXTENSION_POPUP_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_EXTENSIONS_EXTENSION_POPUP_GTK_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h"
13 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "ui/gfx/rect.h"
21 namespace extensions
{
22 class ExtensionViewHost
;
26 class DevToolsAgentHost
;
29 class ExtensionPopupGtk
: public content::NotificationObserver
,
30 public BubbleDelegateGtk
,
31 public ExtensionViewGtk::Container
{
38 static void Show(const GURL
& url
,
41 ShowAction show_action
);
43 // content::NotificationObserver implementation.
44 virtual void Observe(int type
,
45 const content::NotificationSource
& source
,
46 const content::NotificationDetails
& details
) OVERRIDE
;
48 // BubbleDelegateGtk implementation.
49 virtual void BubbleClosing(BubbleGtk
* bubble
,
50 bool closed_by_escape
) OVERRIDE
;
52 // ExtensionViewGtk::Container implementation.
53 virtual void OnExtensionSizeChanged(
54 ExtensionViewGtk
* view
,
55 const gfx::Size
& new_size
) OVERRIDE
;
57 // Destroys the popup widget. This will in turn destroy us since we delete
58 // ourselves when the bubble closes. Returns true if we successfully
62 // Get the currently showing extension popup, or NULL.
63 static ExtensionPopupGtk
* get_current_extension_popup() {
64 return current_extension_popup_
;
67 bool being_inspected() const {
68 return being_inspected_
;
71 // Declared here for testing.
72 static const int kMinWidth
;
73 static const int kMinHeight
;
74 static const int kMaxWidth
;
75 static const int kMaxHeight
;
78 ExtensionPopupGtk(Browser
* browser
,
79 extensions::ExtensionViewHost
* host
,
81 ShowAction show_action
);
82 virtual ~ExtensionPopupGtk();
84 // Shows the popup widget. Called after loading completes.
87 // See DestroyPopup. Does not return success or failure. Necessitated by
88 // base::Bind and friends, which cannot handle a WeakPtr for a function that
89 // has a return value.
90 void DestroyPopupWithoutResult();
92 void OnDevToolsStateChanged(content::DevToolsAgentHost
*, bool attached
);
98 // We take ownership of the popup ExtensionViewHost.
99 scoped_ptr
<extensions::ExtensionViewHost
> host_
;
101 // The widget for anchoring the position of the bubble.
104 content::NotificationRegistrar registrar_
;
106 static ExtensionPopupGtk
* current_extension_popup_
;
108 // Whether a devtools window is attached to this bubble.
109 bool being_inspected_
;
111 base::Callback
<void(content::DevToolsAgentHost
*, bool)> devtools_callback_
;
113 base::WeakPtrFactory
<ExtensionPopupGtk
> weak_factory_
;
115 // Used for testing. ---------------------------------------------------------
116 gfx::Rect
GetViewBounds();
118 friend class BrowserActionTestUtil
;
120 DISALLOW_COPY_AND_ASSIGN(ExtensionPopupGtk
);
123 #endif // CHROME_BROWSER_UI_GTK_EXTENSIONS_EXTENSION_POPUP_GTK_H_