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_VIEW_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_
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"
23 // This handles the display portion of an ExtensionHost.
24 class ExtensionViewViews : public views::NativeViewHost,
25 public extensions::ExtensionView {
27 // A class that represents the container that this view is in.
28 // (bottom shelf, side bar, etc.)
31 virtual ~Container() {}
33 virtual void OnExtensionSizeChanged(ExtensionViewViews* view) {}
36 ExtensionViewViews(extensions::ExtensionHost* host, Browser* browser);
37 ~ExtensionViewViews() override;
39 // views::NativeViewHost:
40 gfx::Size GetMinimumSize() const override;
41 void SetVisible(bool is_visible) override;
42 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override;
43 void ViewHierarchyChanged(
44 const ViewHierarchyChangedDetails& details) override;
46 extensions::ExtensionHost* host() const { return host_; }
47 const extensions::Extension* extension() const { return host_->extension(); }
48 content::RenderViewHost* render_view_host() const {
49 return host_->render_view_host();
51 void set_minimum_size(const gfx::Size& minimum_size) {
52 minimum_size_ = minimum_size;
54 void set_container(Container* container) { container_ = container; }
56 void SetIsClipped(bool is_clipped);
58 // extensions::ExtensionView:
60 Browser* GetBrowser() override;
61 gfx::NativeView GetNativeView() override;
62 void ResizeDueToAutoResize(const gfx::Size& new_size) override;
63 void RenderViewCreated() override;
64 void HandleKeyboardEvent(
65 content::WebContents* source,
66 const content::NativeWebKeyboardEvent& event) override;
67 void DidStopLoading() override;
70 friend class extensions::ExtensionHost;
72 // views::NativeViewHost:
73 bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) override;
74 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
75 void PreferredSizeChanged() override;
76 void OnFocus() override;
78 // Initializes the RenderWidgetHostView for this object.
79 void CreateWidgetHostView();
81 // We wait to show the ExtensionViewViews until several things have loaded.
82 void ShowIfCompletelyLoaded();
84 // Restore object to initial state. Called on shutdown or after a renderer
88 // The running extension instance that we're displaying.
89 // Note that host_ owns view
90 extensions::ExtensionHost* host_;
92 // The browser window that this view is in.
95 // True if we've been initialized.
98 // What we should set the preferred width to once the ExtensionViewViews has
100 gfx::Size pending_preferred_size_;
101 gfx::Size minimum_size_;
103 // The container this view is in (not necessarily its direct superview).
104 // Note: the view does not own its container.
105 Container* container_;
107 // Whether this extension view is clipped.
110 // A handler to handle unhandled keyboard messages coming back from the
112 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
114 DISALLOW_COPY_AND_ASSIGN(ExtensionViewViews);
117 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_VIEWS_H_