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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_view_views.cc

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 #include "chrome/browser/ui/views/extensions/extension_view_views.h" 5 #include "chrome/browser/ui/views/extensions/extension_view_views.h"
6 6
7 #include "chrome/browser/extensions/extension_host.h" 7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/ui/views/extensions/extension_popup.h" 8 #include "chrome/browser/ui/views/extensions/extension_popup.h"
9 #include "chrome/common/view_type.h" 9 #include "chrome/common/view_type.h"
10 #include "content/public/browser/content_browser_client.h" 10 #include "content/public/browser/content_browser_client.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 #include "ui/base/events/event.h" 15 #include "ui/base/events/event.h"
16 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
17 17
18 ExtensionViewViews::ExtensionViewViews(extensions::ExtensionHost* host, 18 ExtensionViewViews::ExtensionViewViews(extensions::ExtensionHost* host,
19 Browser* browser) 19 Browser* browser)
20 : host_(host), 20 : host_(host),
21 browser_(browser), 21 browser_(browser),
22 initialized_(false), 22 initialized_(false),
23 container_(NULL), 23 container_(NULL) {
24 is_clipped_(false) { 24 host_->SetExtensionView(this);
25 host_->set_view(this);
26 25
27 // This view needs to be focusable so it can act as the focused view for the 26 // This view needs to be focusable so it can act as the focused view for the
28 // focus manager. This is required to have SkipDefaultKeyEventProcessing 27 // focus manager. This is required to have SkipDefaultKeyEventProcessing
29 // called so the tab key events are forwarded to the renderer. 28 // called so the tab key events are forwarded to the renderer.
30 set_focusable(true); 29 set_focusable(true);
31 } 30 }
32 31
33 ExtensionViewViews::~ExtensionViewViews() { 32 ExtensionViewViews::~ExtensionViewViews() {
34 if (parent()) 33 if (parent())
35 parent()->RemoveChildView(this); 34 parent()->RemoveChildView(this);
36 CleanUp(); 35 CleanUp();
37 } 36 }
38 37
39 const extensions::Extension* ExtensionViewViews::extension() const { 38 const extensions::Extension* ExtensionViewViews::extension() const {
40 return host_->extension(); 39 return host_->extension();
41 } 40 }
42 41
43 content::RenderViewHost* ExtensionViewViews::render_view_host() const {
44 return host_->render_view_host();
45 }
46
47 void ExtensionViewViews::DidStopLoading() {
48 ShowIfCompletelyLoaded();
49 }
50
51 void ExtensionViewViews::SetIsClipped(bool is_clipped) {
52 if (is_clipped_ != is_clipped) {
53 is_clipped_ = is_clipped;
54 if (visible())
55 ShowIfCompletelyLoaded();
56 }
57 }
58
59 gfx::NativeCursor ExtensionViewViews::GetCursor(const ui::MouseEvent& event) { 42 gfx::NativeCursor ExtensionViewViews::GetCursor(const ui::MouseEvent& event) {
60 return gfx::kNullCursor; 43 return gfx::kNullCursor;
61 } 44 }
62 45
63 void ExtensionViewViews::SetVisible(bool is_visible) { 46 void ExtensionViewViews::SetVisible(bool is_visible) {
64 if (is_visible != visible()) { 47 if (is_visible != visible()) {
65 NativeViewHost::SetVisible(is_visible); 48 NativeViewHost::SetVisible(is_visible);
66 49
67 // Also tell RenderWidgetHostView the new visibility. Despite its name, it 50 // Also tell RenderWidgetHostView the new visibility. Despite its name, it
68 // is not part of the View hierarchy and does not know about the change 51 // is not part of the View hierarchy and does not know about the change
69 // unless we tell it. 52 // unless we tell it.
70 if (render_view_host()->GetView()) { 53 if (render_view_host()->GetView()) {
71 if (is_visible) 54 if (is_visible)
72 render_view_host()->GetView()->Show(); 55 render_view_host()->GetView()->Show();
73 else 56 else
74 render_view_host()->GetView()->Hide(); 57 render_view_host()->GetView()->Hide();
75 } 58 }
76 } 59 }
77 } 60 }
78 61
62 Browser* ExtensionViewViews::GetBrowser() {
63 return browser_;
64 }
65
66 const Browser* ExtensionViewViews::GetBrowser() const {
67 return browser_;
68 }
69
70 gfx::NativeView ExtensionViewViews::GetNativeView() {
71 return extension_host_->host_contents()->GetView()->GetNativeView();
72 }
73
74 void ExtensionViewViews::SetContainer(ExtensionViewContainer* container) {
75 container_ = container;
76 }
77
78 void ExtensionViewViews::ResizeDueToAutoResize(const gfx::Size& new_size) {
79 // Don't actually do anything with this information until we have been shown.
80 // Size changes will not be honored by lower layers while we are hidden.
81 if (!visible()) {
82 pending_preferred_size_ = new_size;
83 return;
84 }
85
86 gfx::Size preferred_size = GetPreferredSize();
87 if (new_size != preferred_size)
88 SetPreferredSize(new_size);
89 }
90
91 void ExtensionViewViews::RenderViewCreated() {
92 if (!pending_background_.empty() && render_view_host()->GetView()) {
93 render_view_host()->GetView()->SetBackground(pending_background_);
94 pending_background_.reset();
95 }
96
97 chrome::ViewType host_type = host_->extension_host_type();
98 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) {
99 gfx::Size min_size(ExtensionPopup::kMinWidth,
100 ExtensionPopup::kMinHeight);
101 gfx::Size max_size(ExtensionPopup::kMaxWidth,
102 ExtensionPopup::kMaxHeight);
103 render_view_host()->EnableAutoResize(min_size, max_size);
104 }
105
106 if (container_)
107 container_->OnViewWasResized();
108 }
109
110 void ExtensionViewViews::DidStopLoading() {
111 ShowIfCompletelyLoaded();
112 }
113
79 void ExtensionViewViews::CreateWidgetHostView() { 114 void ExtensionViewViews::CreateWidgetHostView() {
80 DCHECK(!initialized_); 115 DCHECK(!initialized_);
81 initialized_ = true; 116 initialized_ = true;
82 Attach(host_->host_contents()->GetView()->GetNativeView()); 117 Attach(host_->host_contents()->GetView()->GetNativeView());
83 host_->CreateRenderViewSoon(); 118 host_->CreateRenderViewSoon();
84 SetVisible(false); 119 SetVisible(false);
85 } 120 }
86 121
87 void ExtensionViewViews::ShowIfCompletelyLoaded() { 122 void ExtensionViewViews::ShowIfCompletelyLoaded() {
88 if (visible() || is_clipped_) 123 if (visible())
89 return; 124 return;
90 125
91 // We wait to show the ExtensionViewViews until it has loaded, and the view 126 // We wait to show the ExtensionViewViews until it has loaded, and the view
92 // has actually been created. These can happen in different orders. 127 // has actually been created. These can happen in different orders.
93 if (host_->did_stop_loading()) { 128 if (host_->did_stop_loading()) {
94 SetVisible(true); 129 SetVisible(true);
95 ResizeDueToAutoResize(pending_preferred_size_); 130 ResizeDueToAutoResize(pending_preferred_size_);
96 } 131 }
97 } 132 }
98 133
99 void ExtensionViewViews::CleanUp() { 134 void ExtensionViewViews::CleanUp() {
100 if (!initialized_) 135 if (!initialized_)
101 return; 136 return;
102 if (native_view()) 137 if (native_view())
103 Detach(); 138 Detach();
104 initialized_ = false; 139 initialized_ = false;
105 } 140 }
106 141
142 content::RenderViewHost* ExtensionViewViews::render_view_host() const {
143 return host_->render_view_host();
144 }
145
107 void ExtensionViewViews::SetBackground(const SkBitmap& background) { 146 void ExtensionViewViews::SetBackground(const SkBitmap& background) {
108 if (render_view_host()->IsRenderViewLive() && render_view_host()->GetView()) { 147 if (render_view_host()->IsRenderViewLive() && render_view_host()->GetView()) {
109 render_view_host()->GetView()->SetBackground(background); 148 render_view_host()->GetView()->SetBackground(background);
110 } else { 149 } else {
111 pending_background_ = background; 150 pending_background_ = background;
112 } 151 }
113 ShowIfCompletelyLoaded(); 152 ShowIfCompletelyLoaded();
114 } 153 }
115 154
116 void ExtensionViewViews::ResizeDueToAutoResize(const gfx::Size& new_size) {
117 // Don't actually do anything with this information until we have been shown.
118 // Size changes will not be honored by lower layers while we are hidden.
119 if (!visible()) {
120 pending_preferred_size_ = new_size;
121 return;
122 }
123
124 gfx::Size preferred_size = GetPreferredSize();
125 if (new_size != preferred_size)
126 SetPreferredSize(new_size);
127 }
128
129 void ExtensionViewViews::ViewHierarchyChanged(bool is_add, 155 void ExtensionViewViews::ViewHierarchyChanged(bool is_add,
130 views::View* parent, 156 views::View* parent,
131 views::View* child) { 157 views::View* child) {
132 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); 158 NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
133 if (is_add && GetWidget() && !initialized_) 159 if (is_add && GetWidget() && !initialized_)
134 CreateWidgetHostView(); 160 CreateWidgetHostView();
135 } 161 }
136 162
137 void ExtensionViewViews::PreferredSizeChanged() { 163 void ExtensionViewViews::PreferredSizeChanged() {
138 View::PreferredSizeChanged(); 164 View::PreferredSizeChanged();
(...skipping 14 matching lines...) Expand all
153 // Propagate the new size to RenderWidgetHostView. 179 // Propagate the new size to RenderWidgetHostView.
154 // We can't send size zero because RenderWidget DCHECKs that. 180 // We can't send size zero because RenderWidget DCHECKs that.
155 if (render_view_host()->GetView() && !bounds().IsEmpty()) { 181 if (render_view_host()->GetView() && !bounds().IsEmpty()) {
156 render_view_host()->GetView()->SetSize(size()); 182 render_view_host()->GetView()->SetSize(size());
157 183
158 if (container_) 184 if (container_)
159 container_->OnViewWasResized(); 185 container_->OnViewWasResized();
160 } 186 }
161 } 187 }
162 188
163 void ExtensionViewViews::RenderViewCreated() { 189 // static
164 if (!pending_background_.empty() && render_view_host()->GetView()) { 190 ExtensionView* ExtensionView::Create(extensions::ExtensionHost* host,
165 render_view_host()->GetView()->SetBackground(pending_background_); 191 Browser* browser) {
166 pending_background_.reset(); 192 return new ExtensionViewViews(host, browser);
167 }
168
169 chrome::ViewType host_type = host_->extension_host_type();
170 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) {
171 gfx::Size min_size(ExtensionPopup::kMinWidth,
172 ExtensionPopup::kMinHeight);
173 gfx::Size max_size(ExtensionPopup::kMaxWidth,
174 ExtensionPopup::kMaxHeight);
175 render_view_host()->EnableAutoResize(min_size, max_size);
176 }
177
178 if (container_)
179 container_->OnViewWasResized();
180 } 193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698