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

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

Powered by Google App Engine
This is Rietveld 408576698