Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / extensions / extension_view_views.h
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:
31     virtual ~Container() {}
32
33     virtual void OnExtensionSizeChanged(ExtensionViewViews* view) {}
34   };
35
36   ExtensionViewViews(extensions::ExtensionHost* host, Browser* browser);
37   ~ExtensionViewViews() override;
38
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;
45
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();
50   }
51   void set_minimum_size(const gfx::Size& minimum_size) {
52     minimum_size_ = minimum_size;
53   }
54   void set_container(Container* container) { container_ = container; }
55
56   void SetIsClipped(bool is_clipped);
57
58   // extensions::ExtensionView:
59   void Init() override;
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;
68
69  private:
70   friend class extensions::ExtensionHost;
71
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;
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_