Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/browser/ui/cocoa/extensions/extension_view_mac.mm

Issue 10913243: extensions: Add ExtensionView interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: weak Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" 7 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h"
8 8
9 #include "chrome/browser/extensions/extension_host.h" 9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_view_container.h"
10 #include "chrome/common/view_type.h" 11 #include "chrome/common/view_type.h"
11 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/render_widget_host_view.h" 13 #include "content/public/browser/render_widget_host_view.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_view.h" 15 #include "content/public/browser/web_contents_view.h"
15 16
16 // The minimum/maximum dimensions of the popup. 17 // The minimum/maximum dimensions of the popup.
17 const CGFloat ExtensionViewMac::kMinWidth = 25.0; 18 const CGFloat ExtensionViewMac::kMinWidth = 25.0;
18 const CGFloat ExtensionViewMac::kMinHeight = 25.0; 19 const CGFloat ExtensionViewMac::kMinHeight = 25.0;
19 const CGFloat ExtensionViewMac::kMaxWidth = 800.0; 20 const CGFloat ExtensionViewMac::kMaxWidth = 800.0;
20 const CGFloat ExtensionViewMac::kMaxHeight = 600.0; 21 const CGFloat ExtensionViewMac::kMaxHeight = 600.0;
21 22
22 ExtensionViewMac::ExtensionViewMac(extensions::ExtensionHost* extension_host, 23 ExtensionViewMac::ExtensionViewMac(extensions::ExtensionHost* extension_host,
23 Browser* browser) 24 Browser* browser)
24 : browser_(browser), 25 : browser_(browser),
25 extension_host_(extension_host), 26 extension_host_(extension_host),
26 container_(NULL) { 27 container_(NULL) {
27 DCHECK(extension_host_); 28 DCHECK(extension_host_);
28 [native_view() setHidden:YES]; 29 [GetNativeView() setHidden:YES];
29 } 30 }
30 31
31 ExtensionViewMac::~ExtensionViewMac() { 32 ExtensionViewMac::~ExtensionViewMac() {
32 } 33 }
33 34
34 void ExtensionViewMac::Init() { 35 void ExtensionViewMac::Init() {
35 CreateWidgetHostView(); 36 CreateWidgetHostView();
36 } 37 }
37 38
38 gfx::NativeView ExtensionViewMac::native_view() {
39 return extension_host_->host_contents()->GetView()->GetNativeView();
40 }
41
42 content::RenderViewHost* ExtensionViewMac::render_view_host() const {
43 return extension_host_->render_view_host();
44 }
45
46 void ExtensionViewMac::DidStopLoading() {
47 ShowIfCompletelyLoaded();
48 }
49
50 void ExtensionViewMac::SetBackground(const SkBitmap& background) { 39 void ExtensionViewMac::SetBackground(const SkBitmap& background) {
51 if (!pending_background_.empty() && render_view_host()->GetView()) { 40 if (!pending_background_.empty() && GetRenderViewHost()->GetView()) {
52 render_view_host()->GetView()->SetBackground(background); 41 GetRenderViewHost()->GetView()->SetBackground(background);
53 } else { 42 } else {
54 pending_background_ = background; 43 pending_background_ = background;
55 } 44 }
56 ShowIfCompletelyLoaded(); 45 ShowIfCompletelyLoaded();
57 } 46 }
58 47
48 Browser* ExtensionViewMac::GetBrowser() {
49 return browser_;
50 }
51
52 const Browser* ExtensionViewMac::GetBrowser() const {
53 return browser_;
54 }
55
56 gfx::NativeView ExtensionViewMac::GetNativeView() {
57 return extension_host_->host_contents()->GetView()->GetNativeView();
58 }
59
60 content::RenderViewHost* ExtensionViewMac::GetRenderViewHost() const {
61 return extension_host_->render_view_host();
62 }
63
64 void ExtensionViewMac::SetContainer(ExtensionViewContainer* container) {
65 container_ = container;
66 }
67
59 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) { 68 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) {
60 if (container_) 69 if (container_)
61 container_->OnExtensionSizeChanged(this, new_size); 70 container_->OnExtensionSizeChanged(this, new_size);
62 } 71 }
63 72
64 void ExtensionViewMac::RenderViewCreated() { 73 void ExtensionViewMac::RenderViewCreated() {
65 if (!pending_background_.empty() && render_view_host()->GetView()) { 74 if (!pending_background_.empty() && GetRenderViewHost()->GetView()) {
66 render_view_host()->GetView()->SetBackground(pending_background_); 75 GetRenderViewHost()->GetView()->SetBackground(pending_background_);
67 pending_background_.reset(); 76 pending_background_.reset();
68 } 77 }
69 78
70 chrome::ViewType host_type = extension_host_->extension_host_type(); 79 chrome::ViewType host_type = extension_host_->extension_host_type();
71 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) { 80 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) {
72 gfx::Size min_size(ExtensionViewMac::kMinWidth, 81 gfx::Size min_size(ExtensionViewMac::kMinWidth,
73 ExtensionViewMac::kMinHeight); 82 ExtensionViewMac::kMinHeight);
74 gfx::Size max_size(ExtensionViewMac::kMaxWidth, 83 gfx::Size max_size(ExtensionViewMac::kMaxWidth,
75 ExtensionViewMac::kMaxHeight); 84 ExtensionViewMac::kMaxHeight);
76 render_view_host()->EnableAutoResize(min_size, max_size); 85 GetRenderViewHost()->EnableAutoResize(min_size, max_size);
77 } 86 }
78 } 87 }
79 88
89 void ExtensionViewMac::DidStopLoading() {
90 ShowIfCompletelyLoaded();
91 }
92
80 void ExtensionViewMac::WindowFrameChanged() { 93 void ExtensionViewMac::WindowFrameChanged() {
81 if (render_view_host()->GetView()) 94 if (GetRenderViewHost()->GetView())
82 render_view_host()->GetView()->WindowFrameChanged(); 95 GetRenderViewHost()->GetView()->WindowFrameChanged();
83 } 96 }
84 97
85 void ExtensionViewMac::CreateWidgetHostView() { 98 void ExtensionViewMac::CreateWidgetHostView() {
86 extension_host_->CreateRenderViewSoon(); 99 extension_host_->CreateRenderViewSoon();
87 } 100 }
88 101
89 void ExtensionViewMac::ShowIfCompletelyLoaded() { 102 void ExtensionViewMac::ShowIfCompletelyLoaded() {
90 // We wait to show the ExtensionView until it has loaded, and the view has 103 // We wait to show the ExtensionView until it has loaded, and the view has
91 // actually been created. These can happen in different orders. 104 // actually been created. These can happen in different orders.
92 if (extension_host_->did_stop_loading()) { 105 if (extension_host_->did_stop_loading()) {
93 [native_view() setHidden:NO]; 106 [GetNativeView() setHidden:NO];
94 if (container_) 107 if (container_)
95 container_->OnExtensionViewDidShow(this); 108 container_->OnExtensionViewDidShow(this);
96 } 109 }
97 } 110 }
111
112 // static
113 ExtensionView* ExtensionView::Create(extensions::ExtensionHost* host,
114 Browser* browser) {
115 ExtensionViewMac* extension_view = new ExtensionViewMac(host, browser);
116 extension_view->Init();
117 return extension_view;
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698