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. 4 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ 7 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" 16 #include "url/gurl.h" 17 18 #if defined(USE_AURA) 19 #include "ui/aura/client/activation_change_observer.h" 20 #endif 21 22 class Browser; 23 namespace views { 24 class Widget; 25 } 26 27 namespace content { 28 class DevToolsAgentHost; 29 } 30 31 namespace extensions { 32 class ExtensionViewHost; 33 } 34 35 class ExtensionPopup : public views::BubbleDelegateView, 36 #if defined(USE_AURA) 37 public aura::client::ActivationChangeObserver, 38 #endif 39 public ExtensionViewViews::Container, 40 public content::NotificationObserver, 41 public TabStripModelObserver { 42 public: 43 enum ShowAction { 44 SHOW, 45 SHOW_AND_INSPECT 46 }; 47 48 virtual ~ExtensionPopup(); 49 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, 60 Browser* browser, 61 views::View* anchor_view, 62 views::BubbleBorder::Arrow arrow, 63 ShowAction show_action); 64 host()65 extensions::ExtensionViewHost* host() const { return host_.get(); } 66 67 // content::NotificationObserver overrides. 68 virtual void Observe(int type, 69 const content::NotificationSource& source, 70 const content::NotificationDetails& details) OVERRIDE; 71 72 // ExtensionViewViews::Container overrides. 73 virtual void OnExtensionSizeChanged(ExtensionViewViews* view) OVERRIDE; 74 75 // views::View overrides. 76 virtual gfx::Size GetPreferredSize() OVERRIDE; 77 78 // views::BubbleDelegateView overrides. 79 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 80 virtual void OnWidgetActivationChanged(views::Widget* widget, 81 bool active) OVERRIDE; 82 83 #if defined(USE_AURA) 84 // aura::client::ActivationChangeObserver overrides. 85 virtual void OnWindowActivated(aura::Window* gained_active, 86 aura::Window* lost_active) OVERRIDE; 87 #endif 88 89 // TabStripModelObserver overrides. 90 virtual void ActiveTabChanged(content::WebContents* old_contents, 91 content::WebContents* new_contents, 92 int index, 93 int reason) OVERRIDE; 94 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; 100 101 private: 102 ExtensionPopup(extensions::ExtensionViewHost* host, 103 views::View* anchor_view, 104 views::BubbleBorder::Arrow arrow, 105 ShowAction show_action); 106 107 // Show the bubble, focus on its content, and register listeners. 108 void ShowBubble(); 109 110 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); 111 112 // The contained host for the view. 113 scoped_ptr<extensions::ExtensionViewHost> host_; 114 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_; 118 119 content::NotificationRegistrar registrar_; 120 121 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; 122 123 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup); 124 }; 125 126 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ 127