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_VIEW_VIEWS_H_ 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_ 7 8 #include "base/basictypes.h" 9 #include "base/compiler_specific.h" 10 #include "chrome/browser/extensions/extension_view.h" 11 #include "content/public/browser/native_web_keyboard_event.h" 12 #include "extensions/browser/extension_host.h" 13 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "ui/views/controls/native/native_view_host.h" 15 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" 16 17 class Browser; 18 19 namespace content { 20 class RenderViewHost; 21 } 22 23 // This handles the display portion of an ExtensionHost. 24 class ExtensionViewViews : public views::NativeViewHost, 25 public extensions::ExtensionView { 26 public: 27 // A class that represents the container that this view is in. 28 // (bottom shelf, side bar, etc.) 29 class Container { 30 public: ~Container()31 virtual ~Container() {} 32 OnExtensionSizeChanged(ExtensionViewViews * view)33 virtual void OnExtensionSizeChanged(ExtensionViewViews* view) {} 34 }; 35 36 ExtensionViewViews(extensions::ExtensionHost* host, Browser* browser); 37 virtual ~ExtensionViewViews(); 38 39 // views::NativeViewHost: 40 virtual gfx::Size GetMinimumSize() const OVERRIDE; 41 virtual void SetVisible(bool is_visible) OVERRIDE; 42 virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE; 43 virtual void ViewHierarchyChanged( 44 const ViewHierarchyChangedDetails& details) OVERRIDE; 45 host()46 extensions::ExtensionHost* host() const { return host_; } extension()47 const extensions::Extension* extension() const { return host_->extension(); } render_view_host()48 content::RenderViewHost* render_view_host() const { 49 return host_->render_view_host(); 50 } set_minimum_size(const gfx::Size & minimum_size)51 void set_minimum_size(const gfx::Size& minimum_size) { 52 minimum_size_ = minimum_size; 53 } set_container(Container * container)54 void set_container(Container* container) { container_ = container; } 55 56 void SetIsClipped(bool is_clipped); 57 58 // extensions::ExtensionView: 59 virtual void Init() OVERRIDE; 60 virtual Browser* GetBrowser() OVERRIDE; 61 virtual gfx::NativeView GetNativeView() OVERRIDE; 62 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE; 63 virtual void RenderViewCreated() OVERRIDE; 64 virtual void HandleKeyboardEvent( 65 content::WebContents* source, 66 const content::NativeWebKeyboardEvent& event) OVERRIDE; 67 virtual void DidStopLoading() OVERRIDE; 68 69 private: 70 friend class extensions::ExtensionHost; 71 72 // views::NativeViewHost: 73 virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE; 74 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; 75 virtual void PreferredSizeChanged() OVERRIDE; 76 virtual void OnFocus() OVERRIDE; 77 78 // Initializes the RenderWidgetHostView for this object. 79 void CreateWidgetHostView(); 80 81 // We wait to show the ExtensionViewViews until several things have loaded. 82 void ShowIfCompletelyLoaded(); 83 84 // Restore object to initial state. Called on shutdown or after a renderer 85 // crash. 86 void CleanUp(); 87 88 // The running extension instance that we're displaying. 89 // Note that host_ owns view 90 extensions::ExtensionHost* host_; 91 92 // The browser window that this view is in. 93 Browser* browser_; 94 95 // True if we've been initialized. 96 bool initialized_; 97 98 // What we should set the preferred width to once the ExtensionViewViews has 99 // loaded. 100 gfx::Size pending_preferred_size_; 101 gfx::Size minimum_size_; 102 103 // The container this view is in (not necessarily its direct superview). 104 // Note: the view does not own its container. 105 Container* container_; 106 107 // Whether this extension view is clipped. 108 bool is_clipped_; 109 110 // A handler to handle unhandled keyboard messages coming back from the 111 // renderer process. 112 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; 113 114 DISALLOW_COPY_AND_ASSIGN(ExtensionViewViews); 115 }; 116 117 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_ 118