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_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
11 #include "chrome/browser/ui/views/extensions/extension_view_views.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "ui/views/bubble/bubble_delegate.h"
15 #include "ui/wm/public/activation_change_observer.h"
25 class DevToolsAgentHost
;
28 namespace extensions
{
29 class ExtensionViewHost
;
32 class ExtensionPopup
: public views::BubbleDelegateView
,
33 public aura::client::ActivationChangeObserver
,
34 public ExtensionViewViews::Container
,
35 public content::NotificationObserver
,
36 public TabStripModelObserver
{
43 virtual ~ExtensionPopup();
45 // Create and show a popup with |url| positioned adjacent to |anchor_view|.
46 // |browser| is the browser to which the pop-up will be attached. NULL is a
47 // valid parameter for pop-ups not associated with a browser.
48 // The positioning of the pop-up is determined by |arrow| according to the
49 // following logic: The popup is anchored so that the corner indicated by the
50 // value of |arrow| remains fixed during popup resizes. If |arrow| is
51 // BOTTOM_*, then the popup 'pops up', otherwise the popup 'drops down'.
52 // The actual display of the popup is delayed until the page contents
53 // finish loading in order to minimize UI flashing and resizing.
54 static ExtensionPopup
* ShowPopup(const GURL
& url
,
56 views::View
* anchor_view
,
57 views::BubbleBorder::Arrow arrow
,
58 ShowAction show_action
);
60 extensions::ExtensionViewHost
* host() const { return host_
.get(); }
62 // content::NotificationObserver overrides.
63 virtual void Observe(int type
,
64 const content::NotificationSource
& source
,
65 const content::NotificationDetails
& details
) OVERRIDE
;
67 // ExtensionViewViews::Container overrides.
68 virtual void OnExtensionSizeChanged(ExtensionViewViews
* view
) OVERRIDE
;
70 // views::View overrides.
71 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
72 virtual void ViewHierarchyChanged(
73 const ViewHierarchyChangedDetails
& details
) OVERRIDE
;
75 // views::WidgetObserver overrides.
76 virtual void OnWidgetDestroying(views::Widget
* widget
) OVERRIDE
;
77 virtual void OnWidgetActivationChanged(views::Widget
* widget
,
78 bool active
) OVERRIDE
;
80 // aura::client::ActivationChangeObserver overrides.
81 virtual void OnWindowActivated(aura::Window
* gained_active
,
82 aura::Window
* lost_active
) OVERRIDE
;
84 // TabStripModelObserver overrides.
85 virtual void ActiveTabChanged(content::WebContents
* old_contents
,
86 content::WebContents
* new_contents
,
90 // The min/max height of popups.
91 static const int kMinWidth
;
92 static const int kMinHeight
;
93 static const int kMaxWidth
;
94 static const int kMaxHeight
;
97 ExtensionPopup(extensions::ExtensionViewHost
* host
,
98 views::View
* anchor_view
,
99 views::BubbleBorder::Arrow arrow
,
100 ShowAction show_action
);
102 // Show the bubble, focus on its content, and register listeners.
105 void OnDevToolsStateChanged(content::DevToolsAgentHost
*, bool attached
);
107 // The contained host for the view.
108 scoped_ptr
<extensions::ExtensionViewHost
> host_
;
110 // Flag used to indicate if the pop-up should open a devtools window once
111 // it is shown inspecting it.
112 bool inspect_with_devtools_
;
114 content::NotificationRegistrar registrar_
;
116 base::Callback
<void(content::DevToolsAgentHost
*, bool)> devtools_callback_
;
118 bool widget_initialized_
;
120 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup
);
123 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_