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

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

Issue 10961066: Revert 158199 - extensions: Add ExtensionView interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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"
11 #include "chrome/common/view_type.h" 10 #include "chrome/common/view_type.h"
12 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/render_widget_host_view.h" 12 #include "content/public/browser/render_widget_host_view.h"
14 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_view.h" 14 #include "content/public/browser/web_contents_view.h"
16 15
17 // The minimum/maximum dimensions of the popup. 16 // The minimum/maximum dimensions of the popup.
18 const CGFloat ExtensionViewMac::kMinWidth = 25.0; 17 const CGFloat ExtensionViewMac::kMinWidth = 25.0;
19 const CGFloat ExtensionViewMac::kMinHeight = 25.0; 18 const CGFloat ExtensionViewMac::kMinHeight = 25.0;
20 const CGFloat ExtensionViewMac::kMaxWidth = 800.0; 19 const CGFloat ExtensionViewMac::kMaxWidth = 800.0;
21 const CGFloat ExtensionViewMac::kMaxHeight = 600.0; 20 const CGFloat ExtensionViewMac::kMaxHeight = 600.0;
22 21
23 ExtensionViewMac::ExtensionViewMac(extensions::ExtensionHost* extension_host, 22 ExtensionViewMac::ExtensionViewMac(extensions::ExtensionHost* extension_host,
24 Browser* browser) 23 Browser* browser)
25 : browser_(browser), 24 : browser_(browser),
26 extension_host_(extension_host), 25 extension_host_(extension_host),
27 container_(NULL) { 26 container_(NULL) {
28 DCHECK(extension_host_); 27 DCHECK(extension_host_);
29 [GetNativeView() setHidden:YES]; 28 [native_view() setHidden:YES];
30 } 29 }
31 30
32 ExtensionViewMac::~ExtensionViewMac() { 31 ExtensionViewMac::~ExtensionViewMac() {
33 } 32 }
34 33
35 void ExtensionViewMac::Init() { 34 void ExtensionViewMac::Init() {
36 CreateWidgetHostView(); 35 CreateWidgetHostView();
37 } 36 }
38 37
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
39 void ExtensionViewMac::SetBackground(const SkBitmap& background) { 50 void ExtensionViewMac::SetBackground(const SkBitmap& background) {
40 if (!pending_background_.empty() && GetRenderViewHost()->GetView()) { 51 if (!pending_background_.empty() && render_view_host()->GetView()) {
41 GetRenderViewHost()->GetView()->SetBackground(background); 52 render_view_host()->GetView()->SetBackground(background);
42 } else { 53 } else {
43 pending_background_ = background; 54 pending_background_ = background;
44 } 55 }
45 ShowIfCompletelyLoaded(); 56 ShowIfCompletelyLoaded();
46 } 57 }
47 58
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
68 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) { 59 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) {
69 if (container_) 60 if (container_)
70 container_->OnExtensionSizeChanged(this, new_size); 61 container_->OnExtensionSizeChanged(this, new_size);
71 } 62 }
72 63
73 void ExtensionViewMac::RenderViewCreated() { 64 void ExtensionViewMac::RenderViewCreated() {
74 if (!pending_background_.empty() && GetRenderViewHost()->GetView()) { 65 if (!pending_background_.empty() && render_view_host()->GetView()) {
75 GetRenderViewHost()->GetView()->SetBackground(pending_background_); 66 render_view_host()->GetView()->SetBackground(pending_background_);
76 pending_background_.reset(); 67 pending_background_.reset();
77 } 68 }
78 69
79 chrome::ViewType host_type = extension_host_->extension_host_type(); 70 chrome::ViewType host_type = extension_host_->extension_host_type();
80 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) { 71 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) {
81 gfx::Size min_size(ExtensionViewMac::kMinWidth, 72 gfx::Size min_size(ExtensionViewMac::kMinWidth,
82 ExtensionViewMac::kMinHeight); 73 ExtensionViewMac::kMinHeight);
83 gfx::Size max_size(ExtensionViewMac::kMaxWidth, 74 gfx::Size max_size(ExtensionViewMac::kMaxWidth,
84 ExtensionViewMac::kMaxHeight); 75 ExtensionViewMac::kMaxHeight);
85 GetRenderViewHost()->EnableAutoResize(min_size, max_size); 76 render_view_host()->EnableAutoResize(min_size, max_size);
86 } 77 }
87 } 78 }
88 79
89 void ExtensionViewMac::DidStopLoading() {
90 ShowIfCompletelyLoaded();
91 }
92
93 void ExtensionViewMac::WindowFrameChanged() { 80 void ExtensionViewMac::WindowFrameChanged() {
94 if (GetRenderViewHost()->GetView()) 81 if (render_view_host()->GetView())
95 GetRenderViewHost()->GetView()->WindowFrameChanged(); 82 render_view_host()->GetView()->WindowFrameChanged();
96 } 83 }
97 84
98 void ExtensionViewMac::CreateWidgetHostView() { 85 void ExtensionViewMac::CreateWidgetHostView() {
99 extension_host_->CreateRenderViewSoon(); 86 extension_host_->CreateRenderViewSoon();
100 } 87 }
101 88
102 void ExtensionViewMac::ShowIfCompletelyLoaded() { 89 void ExtensionViewMac::ShowIfCompletelyLoaded() {
103 // We wait to show the ExtensionView until it has loaded, and the view has 90 // We wait to show the ExtensionView until it has loaded, and the view has
104 // actually been created. These can happen in different orders. 91 // actually been created. These can happen in different orders.
105 if (extension_host_->did_stop_loading()) { 92 if (extension_host_->did_stop_loading()) {
106 [GetNativeView() setHidden:NO]; 93 [native_view() setHidden:NO];
107 if (container_) 94 if (container_)
108 container_->OnExtensionViewDidShow(this); 95 container_->OnExtensionViewDidShow(this);
109 } 96 }
110 } 97 }
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