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 ~ExtensionPopup() override;
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 void Observe(int type,
64 const content::NotificationSource& source,
65 const content::NotificationDetails& details) override;
67 // ExtensionViewViews::Container overrides.
68 void OnExtensionSizeChanged(ExtensionViewViews* view) override;
70 // views::View overrides.
71 gfx::Size GetPreferredSize() const override;
72 void ViewHierarchyChanged(
73 const ViewHierarchyChangedDetails& details) override;
75 // views::WidgetObserver overrides.
76 void OnWidgetDestroying(views::Widget* widget) override;
77 void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
79 // aura::client::ActivationChangeObserver overrides.
80 void OnWindowActivated(aura::Window* gained_active,
81 aura::Window* lost_active) override;
83 // TabStripModelObserver overrides.
84 void ActiveTabChanged(content::WebContents* old_contents,
85 content::WebContents* new_contents,
89 // The min/max height of popups.
90 static const int kMinWidth;
91 static const int kMinHeight;
92 static const int kMaxWidth;
93 static const int kMaxHeight;
96 ExtensionPopup(extensions::ExtensionViewHost* host,
97 views::View* anchor_view,
98 views::BubbleBorder::Arrow arrow,
99 ShowAction show_action);
101 // Show the bubble, focus on its content, and register listeners.
104 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
106 // The contained host for the view.
107 scoped_ptr<extensions::ExtensionViewHost> host_;
109 // Flag used to indicate if the pop-up should open a devtools window once
110 // it is shown inspecting it.
111 bool inspect_with_devtools_;
113 content::NotificationRegistrar registrar_;
115 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_;
117 bool widget_initialized_;
119 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup);
122 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_