1 // Copyright (c) 2011 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 #pragma once 8 9 #include "base/memory/ref_counted.h" 10 #include "chrome/browser/extensions/extension_host.h" 11 #include "chrome/browser/ui/views/browser_bubble.h" 12 #include "chrome/browser/ui/views/bubble/bubble_border.h" 13 #include "chrome/browser/ui/views/extensions/extension_view.h" 14 #include "content/common/notification_observer.h" 15 #include "googleurl/src/gurl.h" 16 17 18 class Browser; 19 class ExtensionHost; 20 class Profile; 21 22 namespace views { 23 class Widget; 24 } 25 26 class ExtensionPopup : public BrowserBubble, 27 public BrowserBubble::Delegate, 28 public ExtensionView::Container, 29 public NotificationObserver, 30 public base::RefCounted<ExtensionPopup> { 31 public: 32 // Observer to ExtensionPopup events. 33 class Observer { 34 public: 35 // Called when the ExtensionPopup is closing. Note that it 36 // is ref-counted, and thus will be released shortly after 37 // making this delegate call. 38 virtual void ExtensionPopupIsClosing(ExtensionPopup* popup) {} 39 }; 40 41 virtual ~ExtensionPopup(); 42 43 // Create and show a popup with |url| positioned adjacent to |relative_to| in 44 // screen coordinates. 45 // |browser| is the browser to which the pop-up will be attached. NULL is a 46 // valid parameter for pop-ups not associated with a browser. 47 // The positioning of the pop-up is determined by |arrow_location| according 48 // to the following logic: The popup is anchored so that the corner indicated 49 // by value of |arrow_location| remains fixed during popup resizes. 50 // If |arrow_location| is BOTTOM_*, then the popup 'pops up', otherwise 51 // the popup 'drops down'. 52 // Pass |inspect_with_devtools| as true to pin the popup open and show the 53 // devtools window for it. 54 // The actual display of the popup is delayed until the page contents 55 // finish loading in order to minimize UI flashing and resizing. 56 static ExtensionPopup* Show(const GURL& url, Browser* browser, 57 const gfx::Rect& relative_to, 58 BubbleBorder::ArrowLocation arrow_location, 59 bool inspect_with_devtools, 60 Observer* observer); 61 62 // Closes the ExtensionPopup. 63 void Close(); 64 65 // Some clients wish to do their own custom focus change management. If this 66 // is set to false, then the ExtensionPopup will not do anything in response 67 // to the BubbleLostFocus() calls it gets from the BrowserBubble. 68 void set_close_on_lost_focus(bool close_on_lost_focus) { 69 close_on_lost_focus_ = close_on_lost_focus; 70 } 71 72 ExtensionHost* host() const { return extension_host_.get(); } 73 74 // BrowserBubble overrides. 75 virtual void Show(bool activate); 76 77 // BrowserBubble::Delegate methods. 78 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); 79 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); 80 virtual void BubbleGotFocus(BrowserBubble* bubble); 81 virtual void BubbleLostFocus(BrowserBubble* bubble, 82 bool lost_focus_to_child); 83 84 // NotificationObserver overrides. 85 virtual void Observe(NotificationType type, 86 const NotificationSource& source, 87 const NotificationDetails& details); 88 89 // ExtensionView::Container overrides. 90 virtual void OnExtensionMouseMove(ExtensionView* view) { } 91 virtual void OnExtensionMouseLeave(ExtensionView* view) { } 92 virtual void OnExtensionPreferredSizeChanged(ExtensionView* view); 93 94 // The min/max height of popups. 95 static const int kMinWidth; 96 static const int kMinHeight; 97 static const int kMaxWidth; 98 static const int kMaxHeight; 99 100 private: 101 ExtensionPopup(ExtensionHost* host, 102 views::Widget* frame, 103 const gfx::Rect& relative_to, 104 BubbleBorder::ArrowLocation arrow_location, 105 bool inspect_with_devtools, 106 Observer* observer); 107 108 // The area on the screen that the popup should be positioned relative to. 109 gfx::Rect relative_to_; 110 111 // The contained host for the view. 112 scoped_ptr<ExtensionHost> extension_host_; 113 114 // Flag used to indicate if the pop-up should open a devtools window once 115 // it is shown inspecting it. 116 bool inspect_with_devtools_; 117 118 // If false, ignore BrowserBubble::Delegate::BubbleLostFocus() calls. 119 bool close_on_lost_focus_; 120 121 // Whether the ExtensionPopup is current going about closing itself. 122 bool closing_; 123 124 NotificationRegistrar registrar_; 125 126 // The observer of this popup. 127 Observer* observer_; 128 129 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup); 130 }; 131 132 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ 133