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

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

Issue 11418261: Browser Plugin: Update DOM Node attributes when properties are updated (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_number_conversions.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "content/common/browser_plugin_messages.h" 12 #include "content/common/browser_plugin_messages.h"
12 #include "content/common/view_messages.h" 13 #include "content/common/view_messages.h"
13 #include "content/public/common/content_client.h" 14 #include "content/public/common/content_client.h"
14 #include "content/public/renderer/content_renderer_client.h" 15 #include "content/public/renderer/content_renderer_client.h"
15 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" 16 #include "content/renderer/browser_plugin/browser_plugin_bindings.h"
16 #include "content/renderer/browser_plugin/browser_plugin_manager.h" 17 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
17 #include "content/renderer/render_process_impl.h" 18 #include "content/renderer/render_process_impl.h"
18 #include "content/renderer/render_thread_impl.h" 19 #include "content/renderer/render_thread_impl.h"
(...skipping 30 matching lines...) Expand all
49 // Events. 50 // Events.
50 const char kEventExit[] = "exit"; 51 const char kEventExit[] = "exit";
51 const char kEventLoadAbort[] = "loadabort"; 52 const char kEventLoadAbort[] = "loadabort";
52 const char kEventLoadCommit[] = "loadcommit"; 53 const char kEventLoadCommit[] = "loadcommit";
53 const char kEventLoadRedirect[] = "loadredirect"; 54 const char kEventLoadRedirect[] = "loadredirect";
54 const char kEventLoadStart[] = "loadstart"; 55 const char kEventLoadStart[] = "loadstart";
55 const char kEventLoadStop[] = "loadstop"; 56 const char kEventLoadStop[] = "loadstop";
56 const char kEventSizeChanged[] = "sizechanged"; 57 const char kEventSizeChanged[] = "sizechanged";
57 58
58 // Parameters/properties on events. 59 // Parameters/properties on events.
60 const char kAutoSize[] = "autosize";
lazyboy 2012/11/30 19:15:06 I'd group them separately if we have to add them,
Fady Samuel 2012/11/30 21:56:50 Added UpdateDOMAttribute as an abstract method of
59 const char kIsTopLevel[] = "isTopLevel"; 61 const char kIsTopLevel[] = "isTopLevel";
62 const char kMaxHeight[] = "maxHeight";
63 const char kMaxWidth[] = "maxWidth";
64 const char kMinHeight[] = "minHeight";
65 const char kMinWidth[] = "minWidth";
60 const char kNewURL[] = "newUrl"; 66 const char kNewURL[] = "newUrl";
61 const char kNewHeight[] = "newHeight"; 67 const char kNewHeight[] = "newHeight";
62 const char kNewWidth[] = "newWidth"; 68 const char kNewWidth[] = "newWidth";
63 const char kOldURL[] = "oldUrl"; 69 const char kOldURL[] = "oldUrl";
64 const char kOldHeight[] = "oldHeight"; 70 const char kOldHeight[] = "oldHeight";
65 const char kOldWidth[] = "oldWidth"; 71 const char kOldWidth[] = "oldWidth";
66 const char kPartition[] = "partition"; 72 const char kPartition[] = "partition";
67 const char kPersistPrefix[] = "persist:"; 73 const char kPersistPrefix[] = "persist:";
68 const char kProcessId[] = "processId"; 74 const char kProcessId[] = "processId";
75 const char kReason[] = "reason";
69 const char kSrc[] = "src"; 76 const char kSrc[] = "src";
70 const char kReason[] = "reason";
71 const char kURL[] = "url"; 77 const char kURL[] = "url";
72 78
73 // Error messages. 79 // Error messages.
74 const char kErrorAlreadyNavigated[] = 80 const char kErrorAlreadyNavigated[] =
75 "The object has already navigated, so its partition cannot be changed."; 81 "The object has already navigated, so its partition cannot be changed.";
76 const char kErrorInvalidPartition[] = 82 const char kErrorInvalidPartition[] =
77 "Invalid partition attribute."; 83 "Invalid partition attribute.";
78 84
79 static std::string TerminationStatusToString(base::TerminationStatus status) { 85 static std::string TerminationStatusToString(base::TerminationStatus status) {
80 switch (status) { 86 switch (status) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 browser_plugin_manager()->Send( 187 browser_plugin_manager()->Send(
182 new BrowserPluginHostMsg_NavigateGuest( 188 new BrowserPluginHostMsg_NavigateGuest(
183 render_view_routing_id_, 189 render_view_routing_id_,
184 instance_id_, 190 instance_id_,
185 src)); 191 src));
186 // Record that we sent a NavigateGuest message to embedder. 192 // Record that we sent a NavigateGuest message to embedder.
187 // Once this instance has navigated, the storage partition cannot be changed, 193 // Once this instance has navigated, the storage partition cannot be changed,
188 // so this value is used for enforcing this. 194 // so this value is used for enforcing this.
189 navigate_src_sent_ = true; 195 navigate_src_sent_ = true;
190 src_ = src; 196 src_ = src;
197 UpdateAttribute(kSrc, src_);
lazyboy 2012/11/30 19:15:06 UpdateDOMAttribute maybe? b/c we already call the
Fady Samuel 2012/11/30 21:56:50 Done.
191 return true; 198 return true;
192 } 199 }
193 200
194 void BrowserPlugin::SetAutoSizeAttribute(bool auto_size) { 201 void BrowserPlugin::SetAutoSizeAttribute(bool auto_size) {
195 if (auto_size_ == auto_size) 202 if (auto_size_ == auto_size)
196 return; 203 return;
197 auto_size_ = auto_size; 204 auto_size_ = auto_size;
205 UpdateAttribute(kAutoSize, auto_size_ ? "true" : "false");
198 last_view_size_ = plugin_rect_.size(); 206 last_view_size_ = plugin_rect_.size();
199 UpdateGuestAutoSizeState(); 207 UpdateGuestAutoSizeState();
200 } 208 }
201 209
202 void BrowserPlugin::PopulateAutoSizeParameters( 210 void BrowserPlugin::PopulateAutoSizeParameters(
203 BrowserPluginHostMsg_AutoSize_Params* params) { 211 BrowserPluginHostMsg_AutoSize_Params* params) {
204 // If maxWidth or maxHeight have not been set, set them to the container size. 212 // If maxWidth or maxHeight have not been set, set them to the container size.
205 max_height_ = max_height_ ? max_height_ : height(); 213 max_height_ = max_height_ ? max_height_ : height();
206 max_width_ = max_width_ ? max_width_ : width(); 214 max_width_ = max_width_ ? max_width_ : width();
207 // minWidth should not be bigger than maxWidth, and minHeight should not be 215 // minWidth should not be bigger than maxWidth, and minHeight should not be
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 #else 260 #else
253 bool BrowserPlugin::DamageBufferMatches( 261 bool BrowserPlugin::DamageBufferMatches(
254 const TransportDIB* damage_buffer, 262 const TransportDIB* damage_buffer,
255 const TransportDIB::Handle& other_damage_buffer_handle) { 263 const TransportDIB::Handle& other_damage_buffer_handle) {
256 if (!damage_buffer) 264 if (!damage_buffer)
257 return false; 265 return false;
258 return damage_buffer->handle() == other_damage_buffer_handle; 266 return damage_buffer->handle() == other_damage_buffer_handle;
259 } 267 }
260 #endif 268 #endif
261 269
270 void BrowserPlugin::UpdateAttribute(
271 const std::string& attribute_name,
272 const std::string& attribute_value) {
273 if (container()) {
274 container()->element().setAttribute(
275 WebKit::WebString::fromUTF8(attribute_name),
276 WebKit::WebString::fromUTF8(attribute_value));
277 }
278 }
279
262 void BrowserPlugin::SetMaxHeightAttribute(int max_height) { 280 void BrowserPlugin::SetMaxHeightAttribute(int max_height) {
263 if (max_height_ == max_height) 281 if (max_height_ == max_height)
264 return; 282 return;
265 max_height_ = max_height; 283 max_height_ = max_height;
266 if (!auto_size_) 284 if (!auto_size_)
267 return; 285 return;
286 UpdateAttribute(kMaxHeight, base::IntToString(max_height));
268 UpdateGuestAutoSizeState(); 287 UpdateGuestAutoSizeState();
269 } 288 }
270 289
271 void BrowserPlugin::SetMaxWidthAttribute(int max_width) { 290 void BrowserPlugin::SetMaxWidthAttribute(int max_width) {
272 if (max_width_ == max_width) 291 if (max_width_ == max_width)
273 return; 292 return;
274 max_width_ = max_width; 293 max_width_ = max_width;
275 if (!auto_size_) 294 if (!auto_size_)
276 return; 295 return;
296 UpdateAttribute(kMaxWidth, base::IntToString(max_width_));
277 UpdateGuestAutoSizeState(); 297 UpdateGuestAutoSizeState();
278 } 298 }
279 299
280 void BrowserPlugin::SetMinHeightAttribute(int min_height) { 300 void BrowserPlugin::SetMinHeightAttribute(int min_height) {
281 if (min_height_ == min_height) 301 if (min_height_ == min_height)
282 return; 302 return;
283 min_height_ = min_height; 303 min_height_ = min_height;
284 if (!auto_size_) 304 if (!auto_size_)
285 return; 305 return;
306 UpdateAttribute(kMinHeight, base::IntToString(min_height_));
286 UpdateGuestAutoSizeState(); 307 UpdateGuestAutoSizeState();
287 } 308 }
288 309
289 void BrowserPlugin::SetMinWidthAttribute(int min_width) { 310 void BrowserPlugin::SetMinWidthAttribute(int min_width) {
290 if (min_width_ == min_width) 311 if (min_width_ == min_width)
291 return; 312 return;
292 min_width_ = min_width; 313 min_width_ = min_width;
293 if (!auto_size_) 314 if (!auto_size_)
294 return; 315 return;
316 UpdateAttribute(kMinWidth, base::IntToString(min_width_));
295 UpdateGuestAutoSizeState(); 317 UpdateGuestAutoSizeState();
296 } 318 }
297 319
298 bool BrowserPlugin::InAutoSizeBounds(const gfx::Size& size) const { 320 bool BrowserPlugin::InAutoSizeBounds(const gfx::Size& size) const {
299 return size.width() <= max_width_ && size.height() <= max_height_; 321 return size.width() <= max_width_ && size.height() <= max_height_;
300 } 322 }
301 323
302 NPObject* BrowserPlugin::GetContentWindow() const { 324 NPObject* BrowserPlugin::GetContentWindow() const {
303 if (content_window_routing_id_ == MSG_ROUTING_NONE) 325 if (content_window_routing_id_ == MSG_ROUTING_NONE)
304 return NULL; 326 return NULL;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 *error_message = kErrorInvalidPartition; 373 *error_message = kErrorInvalidPartition;
352 return false; 374 return false;
353 } 375 }
354 persist_storage_ = true; 376 persist_storage_ = true;
355 } else { 377 } else {
356 persist_storage_ = false; 378 persist_storage_ = false;
357 } 379 }
358 380
359 valid_partition_id_ = true; 381 valid_partition_id_ = true;
360 storage_partition_id_ = input; 382 storage_partition_id_ = input;
383 UpdateAttribute(kPartition, storage_partition_id_);
361 return true; 384 return true;
362 } 385 }
363 386
364 void BrowserPlugin::ParseAttributes(const WebKit::WebPluginParams& params) { 387 void BrowserPlugin::ParseAttributes(const WebKit::WebPluginParams& params) {
365 std::string src; 388 std::string src;
366 389
367 // Get the src attribute from the attributes vector 390 // Get the src attribute from the attributes vector
368 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { 391 for (unsigned i = 0; i < params.attributeNames.size(); ++i) {
369 std::string attributeName = params.attributeNames[i].utf8(); 392 std::string attributeName = params.attributeNames[i].utf8();
370 if (LowerCaseEqualsASCII(attributeName, kSrc)) { 393 if (LowerCaseEqualsASCII(attributeName, kSrc)) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); 629 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
607 630
608 TriggerEvent(kEventLoadStart, &props); 631 TriggerEvent(kEventLoadStart, &props);
609 } 632 }
610 633
611 void BrowserPlugin::LoadCommit( 634 void BrowserPlugin::LoadCommit(
612 const BrowserPluginMsg_LoadCommit_Params& params) { 635 const BrowserPluginMsg_LoadCommit_Params& params) {
613 // If the guest has just committed a new navigation then it is no longer 636 // If the guest has just committed a new navigation then it is no longer
614 // crashed. 637 // crashed.
615 guest_crashed_ = false; 638 guest_crashed_ = false;
616 src_ = params.url.spec(); 639 if (params.is_top_level) {
lazyboy 2012/11/30 19:15:06 Yes, please make this fix in a separate CL.
Fady Samuel 2012/11/30 21:56:50 Done.
640 src_ = params.url.spec();
641 UpdateAttribute(kSrc, src_.c_str());
642 }
617 process_id_ = params.process_id; 643 process_id_ = params.process_id;
618 current_nav_entry_index_ = params.current_entry_index; 644 current_nav_entry_index_ = params.current_entry_index;
619 nav_entry_count_ = params.entry_count; 645 nav_entry_count_ = params.entry_count;
620 646
621 std::map<std::string, base::Value*> props; 647 std::map<std::string, base::Value*> props;
622 props[kURL] = base::Value::CreateStringValue(src_); 648 props[kURL] = base::Value::CreateStringValue(src_);
623 props[kIsTopLevel] = base::Value::CreateBooleanValue(params.is_top_level); 649 props[kIsTopLevel] = base::Value::CreateBooleanValue(params.is_top_level);
624 TriggerEvent(kEventLoadCommit, &props); 650 TriggerEvent(kEventLoadCommit, &props);
625 } 651 }
626 652
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 void* notify_data) { 1003 void* notify_data) {
978 } 1004 }
979 1005
980 void BrowserPlugin::didFailLoadingFrameRequest( 1006 void BrowserPlugin::didFailLoadingFrameRequest(
981 const WebKit::WebURL& url, 1007 const WebKit::WebURL& url,
982 void* notify_data, 1008 void* notify_data,
983 const WebKit::WebURLError& error) { 1009 const WebKit::WebURLError& error) {
984 } 1010 }
985 1011
986 } // namespace content 1012 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698