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_COCOA_EXTENSIONS_EXTENSION_VIEW_MAC_H_
6#define CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_VIEW_MAC_H_
7
8#include "base/basictypes.h"
9#include "third_party/skia/include/core/SkBitmap.h"
10#include "ui/gfx/native_widget_types.h"
11#include "ui/gfx/size.h"
12
13class Browser;
14class SkBitmap;
15
16namespace content {
17class RenderViewHost;
18}
19
20namespace extensions {
21class ExtensionHost;
22}
23
24// This class represents extension views. An extension view internally contains
25// a bridge to an extension process, which draws to the extension view's
26// native view object through IPC.
27class ExtensionViewMac {
28 public:
29  class Container {
30   public:
31    virtual ~Container() {}
32    virtual void OnExtensionSizeChanged(ExtensionViewMac* view,
33                                        const gfx::Size& new_size) {}
34    virtual void OnExtensionViewDidShow(ExtensionViewMac* view) {};
35  };
36
37  ExtensionViewMac(extensions::ExtensionHost* extension_host, Browser* browser);
38  ~ExtensionViewMac();
39
40  // Starts the extension process and creates the native view. You must call
41  // this method before calling any of this class's other methods.
42  void Init();
43
44  // Returns the extension's native view.
45  gfx::NativeView native_view();
46
47  // Returns the browser the extension belongs to.
48  Browser* browser() const { return browser_; }
49
50  // Method for the ExtensionHost to notify us that the extension page is
51  // loaded.
52  void DidStopLoading();
53
54  // Sets the container for this view.
55  void set_container(Container* container) { container_ = container; }
56
57  // Method for the ExtensionHost to notify us about the correct size for
58  // extension contents.
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  // Informs the view that its containing window's frame changed.
66  void WindowFrameChanged();
67
68  // The minimum/maximum dimensions of the popup.
69  // The minimum is just a little larger than the size of the button itself.
70  // The maximum is an arbitrary number that should be smaller than most
71  // screens.
72  static const CGFloat kMinWidth;
73  static const CGFloat kMinHeight;
74  static const CGFloat kMaxWidth;
75  static const CGFloat kMaxHeight;
76
77 private:
78  content::RenderViewHost* render_view_host() const;
79
80  void CreateWidgetHostView();
81
82  // We wait to show the ExtensionView until several things have loaded.
83  void ShowIfCompletelyLoaded();
84
85  Browser* browser_;  // weak
86
87  extensions::ExtensionHost* extension_host_;  // weak
88
89  // What we should set the preferred width to once the ExtensionView has
90  // loaded.
91  gfx::Size pending_preferred_size_;
92
93  Container* container_;
94
95  DISALLOW_COPY_AND_ASSIGN(ExtensionViewMac);
96};
97
98#endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_EXTENSION_VIEW_MAC_H_
99