• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_H_
7 #pragma once
8 
9 #include "build/build_config.h"
10 
11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "views/controls/native/native_view_host.h"
13 
14 class Browser;
15 class Extension;
16 class ExtensionHost;
17 class ExtensionView;
18 class RenderViewHost;
19 
20 // This handles the display portion of an ExtensionHost.
21 class ExtensionView : public views::NativeViewHost {
22  public:
23   ExtensionView(ExtensionHost* host, Browser* browser);
24   ~ExtensionView();
25 
26   // A class that represents the container that this view is in.
27   // (bottom shelf, side bar, etc.)
28   class Container {
29    public:
~Container()30     virtual ~Container() {}
31     // Mouse event notifications from the view. (useful for hover UI).
32     virtual void OnExtensionMouseMove(ExtensionView* view) = 0;
33     virtual void OnExtensionMouseLeave(ExtensionView* view) = 0;
OnExtensionPreferredSizeChanged(ExtensionView * view)34     virtual void OnExtensionPreferredSizeChanged(ExtensionView* view) {}
35   };
36 
host()37   ExtensionHost* host() const { return host_; }
browser()38   Browser* browser() const { return browser_; }
39   const Extension* extension() const;
40   RenderViewHost* render_view_host() const;
41   void DidStopLoading();
42   void SetIsClipped(bool is_clipped);
43 
44   // Notification from ExtensionHost.
45   void UpdatePreferredSize(const gfx::Size& new_size);
46   void HandleMouseMove();
47   void HandleMouseLeave();
48 
49   // Method for the ExtensionHost to notify us when the RenderViewHost has a
50   // connection.
51   void RenderViewCreated();
52 
53   // Set a custom background for the view. The background will be tiled.
54   void SetBackground(const SkBitmap& background);
55 
56   // Sets the container for this view.
SetContainer(Container * container)57   void SetContainer(Container* container) { container_ = container; }
58 
59   // Overridden from views::NativeViewHost:
60   virtual void SetVisible(bool is_visible) OVERRIDE;
61   virtual void ViewHierarchyChanged(
62       bool is_add, views::View *parent, views::View *child) OVERRIDE;
63 
64  protected:
65   // Overridden from views::View.
66   virtual void PreferredSizeChanged() OVERRIDE;
67   virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) OVERRIDE;
68   virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
69 
70  private:
71   friend class ExtensionHost;
72 
73   // Initializes the RenderWidgetHostView for this object.
74   void CreateWidgetHostView();
75 
76   // We wait to show the ExtensionView until several things have loaded.
77   void ShowIfCompletelyLoaded();
78 
79   // Restore object to initial state. Called on shutdown or after a renderer
80   // crash.
81   void CleanUp();
82 
83   // The running extension instance that we're displaying.
84   // Note that host_ owns view
85   ExtensionHost* host_;
86 
87   // The browser window that this view is in.
88   Browser* browser_;
89 
90   // True if we've been initialized.
91   bool initialized_;
92 
93   // The background the view should have once it is initialized. This is set
94   // when the view has a custom background, but hasn't been initialized yet.
95   SkBitmap pending_background_;
96 
97   // What we should set the preferred width to once the ExtensionView has
98   // loaded.
99   gfx::Size pending_preferred_size_;
100 
101   // The container this view is in (not necessarily its direct superview).
102   // Note: the view does not own its container.
103   Container* container_;
104 
105   // Whether this extension view is clipped.
106   bool is_clipped_;
107 
108   DISALLOW_COPY_AND_ASSIGN(ExtensionView);
109 };
110 
111 #endif  // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_VIEW_H_
112