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.
5 #import <Cocoa/Cocoa.h>
7 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h"
9 #include "chrome/browser/extensions/extension_host.h"
10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/render_widget_host_view.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_view.h"
14 #include "extensions/common/view_type.h"
16 // The minimum/maximum dimensions of the popup.
17 const CGFloat ExtensionViewMac::kMinWidth = 25.0;
18 const CGFloat ExtensionViewMac::kMinHeight = 25.0;
19 const CGFloat ExtensionViewMac::kMaxWidth = 800.0;
20 const CGFloat ExtensionViewMac::kMaxHeight = 600.0;
22 ExtensionViewMac::ExtensionViewMac(extensions::ExtensionHost* extension_host,
25 extension_host_(extension_host),
27 DCHECK(extension_host_);
28 [native_view() setHidden:YES];
31 ExtensionViewMac::~ExtensionViewMac() {
34 void ExtensionViewMac::Init() {
35 CreateWidgetHostView();
38 gfx::NativeView ExtensionViewMac::native_view() {
39 return extension_host_->host_contents()->GetView()->GetNativeView();
42 content::RenderViewHost* ExtensionViewMac::render_view_host() const {
43 return extension_host_->render_view_host();
46 void ExtensionViewMac::DidStopLoading() {
47 ShowIfCompletelyLoaded();
50 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) {
52 container_->OnExtensionSizeChanged(this, new_size);
55 void ExtensionViewMac::RenderViewCreated() {
56 extensions::ViewType host_type = extension_host_->extension_host_type();
57 if (host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) {
58 gfx::Size min_size(ExtensionViewMac::kMinWidth,
59 ExtensionViewMac::kMinHeight);
60 gfx::Size max_size(ExtensionViewMac::kMaxWidth,
61 ExtensionViewMac::kMaxHeight);
62 render_view_host()->EnableAutoResize(min_size, max_size);
66 void ExtensionViewMac::WindowFrameChanged() {
67 if (render_view_host()->GetView())
68 render_view_host()->GetView()->WindowFrameChanged();
71 void ExtensionViewMac::CreateWidgetHostView() {
72 extension_host_->CreateRenderViewSoon();
75 void ExtensionViewMac::ShowIfCompletelyLoaded() {
76 // We wait to show the ExtensionView until it has loaded, and the view has
77 // actually been created. These can happen in different orders.
78 if (extension_host_->did_stop_loading()) {
79 [native_view() setHidden:NO];
81 container_->OnExtensionViewDidShow(this);