[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / extension_view_mac.mm
blobf0a61c27a6290c4a41ec058c4e130a61020036ce
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 "content/public/browser/render_view_host.h"
10 #include "content/public/browser/render_widget_host_view.h"
11 #include "content/public/browser/web_contents.h"
12 #include "extensions/browser/extension_host.h"
13 #include "extensions/common/view_type.h"
15 // The minimum/maximum dimensions of the popup.
16 const CGFloat ExtensionViewMac::kMinWidth = 25.0;
17 const CGFloat ExtensionViewMac::kMinHeight = 25.0;
18 const CGFloat ExtensionViewMac::kMaxWidth = 800.0;
19 const CGFloat ExtensionViewMac::kMaxHeight = 600.0;
21 ExtensionViewMac::ExtensionViewMac(extensions::ExtensionHost* extension_host,
22                                    Browser* browser)
23     : browser_(browser),
24       extension_host_(extension_host),
25       container_(NULL) {
26   DCHECK(extension_host_);
27   [native_view() setHidden:YES];
30 ExtensionViewMac::~ExtensionViewMac() {
33 void ExtensionViewMac::Init() {
34   CreateWidgetHostView();
37 gfx::NativeView ExtensionViewMac::native_view() {
38   return extension_host_->host_contents()->GetNativeView();
41 content::RenderViewHost* ExtensionViewMac::render_view_host() const {
42   return extension_host_->render_view_host();
45 void ExtensionViewMac::DidStopLoading() {
46   ShowIfCompletelyLoaded();
49 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) {
50   if (container_)
51     container_->OnExtensionSizeChanged(this, new_size);
54 void ExtensionViewMac::RenderViewCreated() {
55   extensions::ViewType host_type = extension_host_->extension_host_type();
56   if (host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) {
57     gfx::Size min_size(ExtensionViewMac::kMinWidth,
58                        ExtensionViewMac::kMinHeight);
59     gfx::Size max_size(ExtensionViewMac::kMaxWidth,
60                        ExtensionViewMac::kMaxHeight);
61     render_view_host()->EnableAutoResize(min_size, max_size);
62   }
65 void ExtensionViewMac::WindowFrameChanged() {
66   if (render_view_host()->GetView())
67     render_view_host()->GetView()->WindowFrameChanged();
70 void ExtensionViewMac::CreateWidgetHostView() {
71   extension_host_->CreateRenderViewSoon();
74 void ExtensionViewMac::ShowIfCompletelyLoaded() {
75   // We wait to show the ExtensionView until it has loaded, and the view has
76   // actually been created. These can happen in different orders.
77   if (extension_host_->did_stop_loading()) {
78     [native_view() setHidden:NO];
79     if (container_)
80       container_->OnExtensionViewDidShow(this);
81   }