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