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/extensions/extension_host.h"
11 #include "chrome/browser/ui/views/extensions/extension_view_views.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "ui/views/bubble/bubble_delegate.h"
14 #include "ui/views/focus/widget_focus_manager.h"
23 class DevToolsAgentHost;
26 class ExtensionPopup : public views::BubbleDelegateView,
27 public ExtensionViewViews::Container,
28 public content::NotificationObserver {
35 virtual ~ExtensionPopup();
37 // Create and show a popup with |url| positioned adjacent to |anchor_view|.
38 // |browser| is the browser to which the pop-up will be attached. NULL is a
39 // valid parameter for pop-ups not associated with a browser.
40 // The positioning of the pop-up is determined by |arrow| according to the
41 // following logic: The popup is anchored so that the corner indicated by the
42 // value of |arrow| remains fixed during popup resizes. If |arrow| is
43 // BOTTOM_*, then the popup 'pops up', otherwise the popup 'drops down'.
44 // The actual display of the popup is delayed until the page contents
45 // finish loading in order to minimize UI flashing and resizing.
46 static ExtensionPopup* ShowPopup(const GURL& url,
48 views::View* anchor_view,
49 views::BubbleBorder::Arrow arrow,
50 ShowAction show_action);
52 extensions::ExtensionHost* host() const { return extension_host_.get(); }
54 // content::NotificationObserver overrides.
55 virtual void Observe(int type,
56 const content::NotificationSource& source,
57 const content::NotificationDetails& details) OVERRIDE;
59 // ExtensionViewViews::Container overrides.
60 virtual void OnExtensionSizeChanged(ExtensionViewViews* view) OVERRIDE;
62 // views::View overrides.
63 virtual gfx::Size GetPreferredSize() OVERRIDE;
65 // views::BubbleDelegateView overrides.
66 virtual void OnWidgetActivationChanged(views::Widget* widget, bool active)
69 // The min/max height of popups.
70 static const int kMinWidth;
71 static const int kMinHeight;
72 static const int kMaxWidth;
73 static const int kMaxHeight;
76 ExtensionPopup(extensions::ExtensionHost* host,
77 views::View* anchor_view,
78 views::BubbleBorder::Arrow arrow,
79 ShowAction show_action);
81 // Show the bubble, focus on its content, and register listeners.
84 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
86 // The contained host for the view.
87 scoped_ptr<extensions::ExtensionHost> extension_host_;
89 // Flag used to indicate if the pop-up should open a devtools window once
90 // it is shown inspecting it.
91 bool inspect_with_devtools_;
93 content::NotificationRegistrar registrar_;
95 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_;
97 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup);
100 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_