• 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_COCOA_EXTENSIONS_EXTENSION_VIEW_MAC_H_
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_VIEW_MAC_H_
7 #pragma once
8 
9 #include "base/basictypes.h"
10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "ui/gfx/native_widget_types.h"
12 #include "ui/gfx/size.h"
13 
14 class Browser;
15 class ExtensionHost;
16 class RenderViewHost;
17 class RenderWidgetHostViewMac;
18 class SkBitmap;
19 
20 // This class represents extension views. An extension view internally contains
21 // a bridge to an extension process, which draws to the extension view's
22 // native view object through IPC.
23 class ExtensionViewMac {
24  public:
25   ExtensionViewMac(ExtensionHost* extension_host, Browser* browser);
26   ~ExtensionViewMac();
27 
28   // Starts the extension process and creates the native view. You must call
29   // this method before calling any of this class's other methods.
30   void Init();
31 
32   // Returns the extension's native view.
33   gfx::NativeView native_view();
34 
35   // Returns the browser the extension belongs to.
browser()36   Browser* browser() const { return browser_; }
37 
38   // Does this extension live as a toolstrip in an extension shelf?
is_toolstrip()39   bool is_toolstrip() const { return is_toolstrip_; }
set_is_toolstrip(bool is_toolstrip)40   void set_is_toolstrip(bool is_toolstrip) { is_toolstrip_ = is_toolstrip; }
41 
42   // Sets the extensions's background image.
43   void SetBackground(const SkBitmap& background);
44 
45   // Method for the ExtensionHost to notify us about the correct size for
46   // extension contents.
47   void UpdatePreferredSize(const gfx::Size& new_size);
48 
49   // Method for the ExtensionHost to notify us when the RenderViewHost has a
50   // connection.
51   void RenderViewCreated();
52 
53   // Informs the view that its containing window's frame changed.
54   void WindowFrameChanged();
55 
56   // The minimum/maximum dimensions of the popup.
57   // The minimum is just a little larger than the size of the button itself.
58   // The maximum is an arbitrary number that should be smaller than most
59   // screens.
60   static const CGFloat kMinWidth;
61   static const CGFloat kMinHeight;
62   static const CGFloat kMaxWidth;
63   static const CGFloat kMaxHeight;
64 
65  private:
66   RenderViewHost* render_view_host() const;
67 
68   void CreateWidgetHostView();
69 
70   // True if the contents are being displayed inside the extension shelf.
71   bool is_toolstrip_;
72 
73   Browser* browser_;  // weak
74 
75   ExtensionHost* extension_host_;  // weak
76 
77   // Created by us, but owned by its |native_view()|. We |release| the
78   // rwhv's native view in our destructor, effectively freeing this.
79   RenderWidgetHostViewMac* render_widget_host_view_;
80 
81   // The background the view should have once it is initialized. This is set
82   // when the view has a custom background, but hasn't been initialized yet.
83   SkBitmap pending_background_;
84 
85   DISALLOW_COPY_AND_ASSIGN(ExtensionViewMac);
86 };
87 
88 #endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_VIEW_MAC_H_
89