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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 11361052: Browser Plugin: Implement autosize (Embedder-side code) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 "content/renderer/browser_plugin/browser_plugin.h" 5 #include "content/renderer/browser_plugin/browser_plugin.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #if defined (OS_WIN) 9 #if defined (OS_WIN)
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const WebPluginParams& params) 83 const WebPluginParams& params)
84 : instance_id_(instance_id), 84 : instance_id_(instance_id),
85 render_view_(render_view->AsWeakPtr()), 85 render_view_(render_view->AsWeakPtr()),
86 render_view_routing_id_(render_view->GetRoutingID()), 86 render_view_routing_id_(render_view->GetRoutingID()),
87 container_(NULL), 87 container_(NULL),
88 damage_buffer_(NULL), 88 damage_buffer_(NULL),
89 sad_guest_(NULL), 89 sad_guest_(NULL),
90 guest_crashed_(false), 90 guest_crashed_(false),
91 resize_pending_(false), 91 resize_pending_(false),
92 navigate_src_sent_(false), 92 navigate_src_sent_(false),
93 autosize_(false),
94 maxheight_(0),
95 maxwidth_(0),
96 minheight_(0),
97 minwidth_(0),
93 process_id_(-1), 98 process_id_(-1),
94 persist_storage_(false), 99 persist_storage_(false),
95 content_window_routing_id_(MSG_ROUTING_NONE), 100 content_window_routing_id_(MSG_ROUTING_NONE),
96 focused_(false), 101 focused_(false),
97 visible_(true), 102 visible_(true),
98 current_nav_entry_index_(0), 103 current_nav_entry_index_(0),
99 nav_entry_count_(0) { 104 nav_entry_count_(0) {
100 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); 105 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this);
101 bindings_.reset(new BrowserPluginBindings(this)); 106 bindings_.reset(new BrowserPluginBindings(this));
102 107
(...skipping 23 matching lines...) Expand all
126 } 131 }
127 132
128 void BrowserPlugin::SetSrcAttribute(const std::string& src) { 133 void BrowserPlugin::SetSrcAttribute(const std::string& src) {
129 if (src.empty() || (src == src_ && !guest_crashed_)) 134 if (src.empty() || (src == src_ && !guest_crashed_))
130 return; 135 return;
131 136
132 // If we haven't created the guest yet, do so now. We will navigate it right 137 // If we haven't created the guest yet, do so now. We will navigate it right
133 // after creation. If |src| is empty, we can delay the creation until we 138 // after creation. If |src| is empty, we can delay the creation until we
134 // acutally need it. 139 // acutally need it.
135 if (!navigate_src_sent_) { 140 if (!navigate_src_sent_) {
141 BrowserPluginHostMsg_CreateGuest_Params params;
142 params.storage_partition_id = storage_partition_id_;
143 params.persist_storage = persist_storage_;
144 params.focused = focused_;
145 params.visible = visible_;
146 PopulateAutoSizeParameters(&params.autosize);
136 BrowserPluginManager::Get()->Send( 147 BrowserPluginManager::Get()->Send(
137 new BrowserPluginHostMsg_CreateGuest( 148 new BrowserPluginHostMsg_CreateGuest(
138 render_view_routing_id_, 149 render_view_routing_id_,
139 instance_id_, 150 instance_id_,
140 storage_partition_id_, 151 params));
141 persist_storage_,
142 focused_,
143 visible_));
144 } 152 }
145 153
146 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> params( 154 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> params(
147 GetPendingResizeParams()); 155 GetPendingResizeParams());
148 DCHECK(!params->resize_pending); 156 DCHECK(!params->resize_pending);
149 157
150 BrowserPluginManager::Get()->Send( 158 BrowserPluginManager::Get()->Send(
151 new BrowserPluginHostMsg_NavigateGuest( 159 new BrowserPluginHostMsg_NavigateGuest(
152 render_view_routing_id_, 160 render_view_routing_id_,
153 instance_id_, 161 instance_id_,
154 src, 162 src,
155 *params)); 163 *params));
156 // Record that we sent a NavigateGuest message to embedder. 164 // Record that we sent a NavigateGuest message to embedder.
157 // Once this instance has navigated, the storage partition cannot be changed, 165 // Once this instance has navigated, the storage partition cannot be changed,
158 // so this value is used for enforcing this. 166 // so this value is used for enforcing this.
159 navigate_src_sent_ = true; 167 navigate_src_sent_ = true;
160 src_ = src; 168 src_ = src;
161 } 169 }
162 170
171 bool BrowserPlugin::GetAutoSizeAttribute() const {
172 return autosize_;
173 }
174
175 void BrowserPlugin::SetAutoSizeAttribute(bool autosize) {
176 if (autosize_ == autosize)
177 return;
178 autosize_ = autosize;
179 UpdateGuestAutoSizeState();
180 }
181
182 void BrowserPlugin::PopulateAutoSizeParameters(
183 BrowserPluginHostMsg_AutoSize_Params* params) const {
184 params->enable = autosize_;
185 params->maxheight = maxheight_;
186 params->maxwidth = maxwidth_;
187 params->minheight = minheight_;
188 params->minwidth = minwidth_;
189 }
190
191 void BrowserPlugin::UpdateGuestAutoSizeState() const {
192 if (!navigate_src_sent_)
193 return;
194 BrowserPluginHostMsg_AutoSize_Params params;
195 PopulateAutoSizeParameters(&params);
196 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetAutoSize(
197 render_view_routing_id_,
198 instance_id_,
199 params));
200 }
201
202 int BrowserPlugin::GetMaxHeightAttribute() const {
jam 2012/11/02 19:11:10 nit: all these getters should jus be unix_hacker s
Fady Samuel 2012/11/02 20:32:23 Done.
203 return maxheight_;
204 }
205
206 void BrowserPlugin::SetMaxHeightAttribute(int maxheight) {
207 if (maxheight_ == maxheight)
208 return;
209 maxheight_ = maxheight;
210 if (!autosize_)
211 return;
212 UpdateGuestAutoSizeState();
213 }
214
215 int BrowserPlugin::GetMaxWidthAttribute() const {
216 return maxwidth_;
217 }
218
219 void BrowserPlugin::SetMaxWidthAttribute(int maxwidth) {
220 if (maxwidth_ == maxwidth)
221 return;
222 maxwidth_ = maxwidth;
223 if (!autosize_)
224 return;
225 UpdateGuestAutoSizeState();
226 }
227
228 int BrowserPlugin::GetMinHeightAttribute() const {
229 return minheight_;
230 }
231
232 void BrowserPlugin::SetMinHeightAttribute(int minheight) {
233 if (minheight_ == minheight)
234 return;
235 minheight_ = minheight;
236 if (!autosize_)
237 return;
238 UpdateGuestAutoSizeState();
239 }
240
241 int BrowserPlugin::GetMinWidthAttribute() const {
242 return minwidth_;
243 }
244
245 void BrowserPlugin::SetMinWidthAttribute(int minwidth) {
246 if (minwidth_ == minwidth)
247 return;
248 minwidth_ = minwidth;
249 if (!autosize_)
250 return;
251 UpdateGuestAutoSizeState();
252 }
253
163 NPObject* BrowserPlugin::GetContentWindow() const { 254 NPObject* BrowserPlugin::GetContentWindow() const {
164 if (content_window_routing_id_ == MSG_ROUTING_NONE) 255 if (content_window_routing_id_ == MSG_ROUTING_NONE)
165 return NULL; 256 return NULL;
166 RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( 257 RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>(
167 ChildThread::current()->ResolveRoute(content_window_routing_id_)); 258 ChildThread::current()->ResolveRoute(content_window_routing_id_));
168 if (!guest_render_view) 259 if (!guest_render_view)
169 return NULL; 260 return NULL;
170 WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); 261 WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame();
171 return guest_frame->windowObject(); 262 return guest_frame->windowObject();
172 } 263 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 362 }
272 363
273 bool BrowserPlugin::IsValidEvent(const std::string& event_name) { 364 bool BrowserPlugin::IsValidEvent(const std::string& event_name) {
274 return event_listener_map_.find(event_name) != event_listener_map_.end(); 365 return event_listener_map_.find(event_name) != event_listener_map_.end();
275 } 366 }
276 367
277 void BrowserPlugin::TriggerEvent(const std::string& event_name, 368 void BrowserPlugin::TriggerEvent(const std::string& event_name,
278 v8::Local<v8::Object>* event) { 369 v8::Local<v8::Object>* event) {
279 WebKit::WebElement plugin = container()->element(); 370 WebKit::WebElement plugin = container()->element();
280 371
281 // TODO(fsamuel): Copying the event listeners is insufficent because
282 // new persistent handles are not created when the copy constructor is
283 // called. See http://crbug.com/155044.
284 const EventListeners& listeners = event_listener_map_[event_name.c_str()]; 372 const EventListeners& listeners = event_listener_map_[event_name.c_str()];
285 // A v8::Local copy of the listeners is created from the v8::Persistent 373 // A v8::Local copy of the listeners is created from the v8::Persistent
286 // listeners before firing them. This is to ensure that if one of these 374 // listeners before firing them. This is to ensure that if one of these
287 // listeners mutate the list of listeners (by calling 375 // listeners mutate the list of listeners (by calling
288 // addEventListener/removeEventListener), this local copy is not affected. 376 // addEventListener/removeEventListener), this local copy is not affected.
289 // This means if you mutate the list of listeners for an event X while event X 377 // This means if you mutate the list of listeners for an event X while event X
290 // is firing, the mutation is deferred until all current listeners for X have 378 // is firing, the mutation is deferred until all current listeners for X have
291 // fired. 379 // fired.
292 EventListenersLocal listeners_local; 380 EventListenersLocal listeners_local;
293 listeners_local.reserve(listeners.size()); 381 listeners_local.reserve(listeners.size());
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 } 769 }
682 770
683 void BrowserPlugin::updateGeometry( 771 void BrowserPlugin::updateGeometry(
684 const WebRect& window_rect, 772 const WebRect& window_rect,
685 const WebRect& clip_rect, 773 const WebRect& clip_rect,
686 const WebVector<WebRect>& cut_outs_rects, 774 const WebVector<WebRect>& cut_outs_rects,
687 bool is_visible) { 775 bool is_visible) {
688 int old_width = width(); 776 int old_width = width();
689 int old_height = height(); 777 int old_height = height();
690 plugin_rect_ = window_rect; 778 plugin_rect_ = window_rect;
691 if (old_width == window_rect.width && 779 if (autosize_ || (old_width == window_rect.width &&
692 old_height == window_rect.height) { 780 old_height == window_rect.height)) {
693 return; 781 return;
694 } 782 }
695 783
696 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width); 784 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width);
697 // Make sure the size of the damage buffer is at least four bytes so that we 785 // Make sure the size of the damage buffer is at least four bytes so that we
698 // can fit in a magic word to verify that the memory is shared correctly. 786 // can fit in a magic word to verify that the memory is shared correctly.
699 size_t size = 787 size_t size =
700 std::max(sizeof(unsigned int), 788 std::max(sizeof(unsigned int),
701 static_cast<size_t>(window_rect.height * 789 static_cast<size_t>(window_rect.height *
702 stride * 790 stride *
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 void* notify_data) { 978 void* notify_data) {
891 } 979 }
892 980
893 void BrowserPlugin::didFailLoadingFrameRequest( 981 void BrowserPlugin::didFailLoadingFrameRequest(
894 const WebKit::WebURL& url, 982 const WebKit::WebURL& url,
895 void* notify_data, 983 void* notify_data,
896 const WebKit::WebURLError& error) { 984 const WebKit::WebURLError& error) {
897 } 985 }
898 986
899 } // namespace content 987 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698