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