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/views/focus/widget_focus_manager.h"
19 #include "ui/aura/client/activation_change_observer.h"
28 class DevToolsAgentHost
;
31 namespace extensions
{
32 class ExtensionViewHost
;
35 class ExtensionPopup
: public views::BubbleDelegateView
,
37 public aura::client::ActivationChangeObserver
,
39 public ExtensionViewViews::Container
,
40 public content::NotificationObserver
,
41 public TabStripModelObserver
{
48 virtual ~ExtensionPopup();
50 // Create and show a popup with |url| positioned adjacent to |anchor_view|.
51 // |browser| is the browser to which the pop-up will be attached. NULL is a
52 // valid parameter for pop-ups not associated with a browser.
53 // The positioning of the pop-up is determined by |arrow| according to the
54 // following logic: The popup is anchored so that the corner indicated by the
55 // value of |arrow| remains fixed during popup resizes. If |arrow| is
56 // BOTTOM_*, then the popup 'pops up', otherwise the popup 'drops down'.
57 // The actual display of the popup is delayed until the page contents
58 // finish loading in order to minimize UI flashing and resizing.
59 static ExtensionPopup
* ShowPopup(const GURL
& url
,
61 views::View
* anchor_view
,
62 views::BubbleBorder::Arrow arrow
,
63 ShowAction show_action
);
65 extensions::ExtensionViewHost
* host() const { return host_
.get(); }
67 // content::NotificationObserver overrides.
68 virtual void Observe(int type
,
69 const content::NotificationSource
& source
,
70 const content::NotificationDetails
& details
) OVERRIDE
;
72 // ExtensionViewViews::Container overrides.
73 virtual void OnExtensionSizeChanged(ExtensionViewViews
* view
) OVERRIDE
;
75 // views::View overrides.
76 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
78 // views::BubbleDelegateView overrides.
79 virtual void OnWidgetDestroying(views::Widget
* widget
) OVERRIDE
;
80 virtual void OnWidgetActivationChanged(views::Widget
* widget
,
81 bool active
) OVERRIDE
;
84 // aura::client::ActivationChangeObserver overrides.
85 virtual void OnWindowActivated(aura::Window
* gained_active
,
86 aura::Window
* lost_active
) OVERRIDE
;
89 // TabStripModelObserver overrides.
90 virtual void ActiveTabChanged(content::WebContents
* old_contents
,
91 content::WebContents
* new_contents
,
95 // The min/max height of popups.
96 static const int kMinWidth
;
97 static const int kMinHeight
;
98 static const int kMaxWidth
;
99 static const int kMaxHeight
;
102 ExtensionPopup(extensions::ExtensionViewHost
* host
,
103 views::View
* anchor_view
,
104 views::BubbleBorder::Arrow arrow
,
105 ShowAction show_action
);
107 // Show the bubble, focus on its content, and register listeners.
110 void OnDevToolsStateChanged(content::DevToolsAgentHost
*, bool attached
);
112 // The contained host for the view.
113 scoped_ptr
<extensions::ExtensionViewHost
> host_
;
115 // Flag used to indicate if the pop-up should open a devtools window once
116 // it is shown inspecting it.
117 bool inspect_with_devtools_
;
119 content::NotificationRegistrar registrar_
;
121 base::Callback
<void(content::DevToolsAgentHost
*, bool)> devtools_callback_
;
123 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup
);
126 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_