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"
24 class DevToolsAgentHost
;
27 namespace extensions
{
28 class ExtensionViewHost
;
31 class ExtensionPopup
: public views::BubbleDelegateView
,
32 public ExtensionViewViews::Container
,
33 public content::NotificationObserver
,
34 public TabStripModelObserver
{
41 ~ExtensionPopup() override
;
43 // Create and show a popup with the given |host| positioned adjacent to
45 // The positioning of the pop-up is determined by |arrow| according to the
46 // following logic: The popup is anchored so that the corner indicated by the
47 // value of |arrow| remains fixed during popup resizes. If |arrow| is
48 // BOTTOM_*, then the popup 'pops up', otherwise the popup 'drops down'.
49 // The actual display of the popup is delayed until the page contents
50 // finish loading in order to minimize UI flashing and resizing.
51 static ExtensionPopup
* ShowPopup(
52 scoped_ptr
<extensions::ExtensionViewHost
> host
,
53 views::View
* anchor_view
,
54 views::BubbleBorder::Arrow arrow
,
55 ShowAction show_action
);
58 extensions::ExtensionViewHost
* host() const { return host_
.get(); }
60 // content::NotificationObserver overrides.
61 void Observe(int type
,
62 const content::NotificationSource
& source
,
63 const content::NotificationDetails
& details
) override
;
65 // ExtensionViewViews::Container overrides.
66 void OnExtensionSizeChanged(ExtensionViewViews
* view
) override
;
68 // views::View overrides.
69 gfx::Size
GetPreferredSize() const override
;
70 void ViewHierarchyChanged(
71 const ViewHierarchyChangedDetails
& details
) override
;
73 // views::WidgetObserver overrides.
74 void OnWidgetActivationChanged(views::Widget
* widget
, bool active
) override
;
76 // TabStripModelObserver overrides.
77 void ActiveTabChanged(content::WebContents
* old_contents
,
78 content::WebContents
* new_contents
,
82 // The min/max height of popups.
83 static const int kMinWidth
;
84 static const int kMinHeight
;
85 static const int kMaxWidth
;
86 static const int kMaxHeight
;
89 ExtensionPopup(extensions::ExtensionViewHost
* host
,
90 views::View
* anchor_view
,
91 views::BubbleBorder::Arrow arrow
,
92 ShowAction show_action
);
94 // Called on anchor window activation (ie. user clicked the browser window).
95 void OnAnchorWindowActivation();
98 static ExtensionPopup
* Create(extensions::ExtensionViewHost
* host
,
99 views::View
* anchor_view
,
100 views::BubbleBorder::Arrow arrow
,
101 ShowAction show_action
);
103 // Show the bubble, focus on its content, and register listeners.
106 void OnDevToolsStateChanged(content::DevToolsAgentHost
*, bool attached
);
108 // The contained host for the view.
109 scoped_ptr
<extensions::ExtensionViewHost
> host_
;
111 // Flag used to indicate if the pop-up should open a devtools window once
112 // it is shown inspecting it.
113 bool inspect_with_devtools_
;
115 content::NotificationRegistrar registrar_
;
117 base::Callback
<void(content::DevToolsAgentHost
*, bool)> devtools_callback_
;
119 bool widget_initialized_
;
121 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup
);
124 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_