OLD | NEW |
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_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 instance_id_)); | 145 instance_id_)); |
146 } | 146 } |
147 | 147 |
148 void BrowserPlugin::Cleanup() { | 148 void BrowserPlugin::Cleanup() { |
149 if (current_damage_buffer_) | 149 if (current_damage_buffer_) |
150 FreeDamageBuffer(¤t_damage_buffer_); | 150 FreeDamageBuffer(¤t_damage_buffer_); |
151 if (pending_damage_buffer_) | 151 if (pending_damage_buffer_) |
152 FreeDamageBuffer(&pending_damage_buffer_); | 152 FreeDamageBuffer(&pending_damage_buffer_); |
153 } | 153 } |
154 | 154 |
| 155 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
| 156 bool handled = true; |
| 157 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
| 158 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
| 159 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
| 160 OnGuestContentWindowReady) |
| 161 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
| 162 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) |
| 163 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) |
| 164 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) |
| 165 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) |
| 166 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) |
| 167 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) |
| 168 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) |
| 169 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, |
| 170 OnShouldAcceptTouchEvents) |
| 171 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) |
| 172 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) |
| 173 IPC_MESSAGE_UNHANDLED(handled = false) |
| 174 IPC_END_MESSAGE_MAP() |
| 175 return handled; |
| 176 } |
| 177 |
| 178 void BrowserPlugin::UpdateDOMAttribute( |
| 179 const std::string& attribute_name, |
| 180 const std::string& attribute_value) { |
| 181 if (!container()) |
| 182 return; |
| 183 |
| 184 WebKit::WebElement element = container()->element(); |
| 185 WebKit::WebString web_attribute_name = |
| 186 WebKit::WebString::fromUTF8(attribute_name); |
| 187 std::string current_value(element.getAttribute(web_attribute_name).utf8()); |
| 188 if (current_value == attribute_value) |
| 189 return; |
| 190 |
| 191 if (attribute_value.empty()) { |
| 192 element.removeAttribute(web_attribute_name); |
| 193 } else { |
| 194 element.setAttribute(web_attribute_name, |
| 195 WebKit::WebString::fromUTF8(attribute_value)); |
| 196 } |
| 197 } |
| 198 |
| 199 |
155 bool BrowserPlugin::SetSrcAttribute(const std::string& src, | 200 bool BrowserPlugin::SetSrcAttribute(const std::string& src, |
156 std::string* error_message) { | 201 std::string* error_message) { |
157 if (!valid_partition_id_) { | 202 if (!valid_partition_id_) { |
158 *error_message = kErrorInvalidPartition; | 203 *error_message = kErrorInvalidPartition; |
159 return false; | 204 return false; |
160 } | 205 } |
161 | 206 |
162 if (src.empty() || (src == src_ && !guest_crashed_)) | 207 if (src.empty() || (src == src_ && !guest_crashed_)) |
163 return true; | 208 return true; |
164 | 209 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 #else | 300 #else |
256 bool BrowserPlugin::DamageBufferMatches( | 301 bool BrowserPlugin::DamageBufferMatches( |
257 const TransportDIB* damage_buffer, | 302 const TransportDIB* damage_buffer, |
258 const TransportDIB::Handle& other_damage_buffer_handle) { | 303 const TransportDIB::Handle& other_damage_buffer_handle) { |
259 if (!damage_buffer) | 304 if (!damage_buffer) |
260 return false; | 305 return false; |
261 return damage_buffer->handle() == other_damage_buffer_handle; | 306 return damage_buffer->handle() == other_damage_buffer_handle; |
262 } | 307 } |
263 #endif | 308 #endif |
264 | 309 |
265 void BrowserPlugin::UpdateDOMAttribute( | 310 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { |
266 const std::string& attribute_name, | 311 DCHECK(render_view_); |
267 const std::string& attribute_value) { | 312 render_view_->GetWebView()->advanceFocus(reverse); |
268 if (!container()) | 313 } |
| 314 |
| 315 void BrowserPlugin::OnGuestContentWindowReady(int instance_id, |
| 316 int content_window_routing_id) { |
| 317 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); |
| 318 content_window_routing_id_ = content_window_routing_id; |
| 319 } |
| 320 |
| 321 void BrowserPlugin::OnGuestGone(int instance_id, int process_id, int status) { |
| 322 // We fire the event listeners before painting the sad graphic to give the |
| 323 // developer an opportunity to display an alternative overlay image on crash. |
| 324 std::string termination_status = TerminationStatusToString( |
| 325 static_cast<base::TerminationStatus>(status)); |
| 326 std::map<std::string, base::Value*> props; |
| 327 props[kProcessId] = base::Value::CreateIntegerValue(process_id); |
| 328 props[kReason] = base::Value::CreateStringValue(termination_status); |
| 329 |
| 330 // Event listeners may remove the BrowserPlugin from the document. If that |
| 331 // happens, the BrowserPlugin will be scheduled for later deletion (see |
| 332 // BrowserPlugin::destroy()). That will clear the container_ reference, |
| 333 // but leave other member variables valid below. |
| 334 TriggerEvent(kEventExit, &props); |
| 335 |
| 336 guest_crashed_ = true; |
| 337 // We won't paint the contents of the current backing store again so we might |
| 338 // as well toss it out and save memory. |
| 339 backing_store_.reset(); |
| 340 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
| 341 // NULL so we shouldn't attempt to access it. |
| 342 if (container_) |
| 343 container_->invalidate(); |
| 344 } |
| 345 |
| 346 void BrowserPlugin::OnGuestResponsive(int instance_id, int process_id) { |
| 347 std::map<std::string, base::Value*> props; |
| 348 props[kProcessId] = base::Value::CreateIntegerValue(process_id); |
| 349 TriggerEvent(kEventResponsive, &props); |
| 350 } |
| 351 |
| 352 void BrowserPlugin::OnGuestUnresponsive(int instance_id, int process_id) { |
| 353 std::map<std::string, base::Value*> props; |
| 354 props[kProcessId] = base::Value::CreateIntegerValue(process_id); |
| 355 TriggerEvent(kEventUnresponsive, &props); |
| 356 } |
| 357 |
| 358 void BrowserPlugin::OnLoadAbort(int instance_id, |
| 359 const GURL& url, |
| 360 bool is_top_level, |
| 361 const std::string& type) { |
| 362 std::map<std::string, base::Value*> props; |
| 363 props[kURL] = base::Value::CreateStringValue(url.spec()); |
| 364 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
| 365 props[kReason] = base::Value::CreateStringValue(type); |
| 366 TriggerEvent(kEventLoadAbort, &props); |
| 367 } |
| 368 |
| 369 void BrowserPlugin::OnLoadCommit( |
| 370 int instance_id, |
| 371 const BrowserPluginMsg_LoadCommit_Params& params) { |
| 372 // If the guest has just committed a new navigation then it is no longer |
| 373 // crashed. |
| 374 guest_crashed_ = false; |
| 375 if (params.is_top_level) { |
| 376 src_ = params.url.spec(); |
| 377 UpdateDOMAttribute(kSrc, src_.c_str()); |
| 378 } |
| 379 process_id_ = params.process_id; |
| 380 current_nav_entry_index_ = params.current_entry_index; |
| 381 nav_entry_count_ = params.entry_count; |
| 382 |
| 383 std::map<std::string, base::Value*> props; |
| 384 props[kURL] = base::Value::CreateStringValue(params.url.spec()); |
| 385 props[kIsTopLevel] = base::Value::CreateBooleanValue(params.is_top_level); |
| 386 TriggerEvent(kEventLoadCommit, &props); |
| 387 } |
| 388 |
| 389 void BrowserPlugin::OnLoadRedirect(int instance_id, |
| 390 const GURL& old_url, |
| 391 const GURL& new_url, |
| 392 bool is_top_level) { |
| 393 std::map<std::string, base::Value*> props; |
| 394 props[kOldURL] = base::Value::CreateStringValue(old_url.spec()); |
| 395 props[kNewURL] = base::Value::CreateStringValue(new_url.spec()); |
| 396 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
| 397 TriggerEvent(kEventLoadRedirect, &props); |
| 398 } |
| 399 |
| 400 void BrowserPlugin::OnLoadStart(int instance_id, |
| 401 const GURL& url, |
| 402 bool is_top_level) { |
| 403 std::map<std::string, base::Value*> props; |
| 404 props[kURL] = base::Value::CreateStringValue(url.spec()); |
| 405 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
| 406 |
| 407 TriggerEvent(kEventLoadStart, &props); |
| 408 } |
| 409 |
| 410 void BrowserPlugin::OnLoadStop(int instance_id) { |
| 411 TriggerEvent(kEventLoadStop, NULL); |
| 412 } |
| 413 |
| 414 void BrowserPlugin::OnSetCursor(int instance_id, const WebCursor& cursor) { |
| 415 cursor_ = cursor; |
| 416 } |
| 417 |
| 418 void BrowserPlugin::OnShouldAcceptTouchEvents(int instance_id, bool accept) { |
| 419 if (container()) { |
| 420 container()->requestTouchEventType(accept ? |
| 421 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : |
| 422 WebKit::WebPluginContainer::TouchEventRequestTypeNone); |
| 423 } |
| 424 } |
| 425 |
| 426 void BrowserPlugin::OnUpdateRect( |
| 427 int instance_id, |
| 428 int message_id, |
| 429 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 430 bool use_new_damage_buffer = !backing_store_; |
| 431 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
| 432 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
| 433 // If we have a pending damage buffer, and the guest has begun to use the |
| 434 // damage buffer then we know the guest will no longer use the current |
| 435 // damage buffer. At this point, we drop the current damage buffer, and |
| 436 // mark the pending damage buffer as the current damage buffer. |
| 437 if (DamageBufferMatches(pending_damage_buffer_, |
| 438 params.damage_buffer_identifier)) { |
| 439 SwapDamageBuffers(); |
| 440 use_new_damage_buffer = true; |
| 441 } |
| 442 if ((!auto_size_ && |
| 443 (width() != params.view_size.width() || |
| 444 height() != params.view_size.height())) || |
| 445 (auto_size_ && (!InAutoSizeBounds(params.view_size)))) { |
| 446 if (pending_damage_buffer_) { |
| 447 // The guest has not yet responded to the last resize request, and |
| 448 // so we don't want to do anything at this point other than ACK the guest. |
| 449 PopulateAutoSizeParameters(&auto_size_params); |
| 450 } else { |
| 451 // If we have no pending damage buffer, then the guest has not caught up |
| 452 // with the BrowserPlugin container. We now tell the guest about the new |
| 453 // container size. |
| 454 pending_damage_buffer_ = |
| 455 GetDamageBufferWithSizeParams(&auto_size_params, |
| 456 &resize_guest_params); |
| 457 } |
| 458 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 459 render_view_routing_id_, |
| 460 instance_id_, |
| 461 message_id, |
| 462 auto_size_params, |
| 463 resize_guest_params)); |
269 return; | 464 return; |
270 | 465 } |
271 WebKit::WebElement element = container()->element(); | 466 |
272 WebKit::WebString web_attribute_name = | 467 if (auto_size_ && (params.view_size != last_view_size_)) { |
273 WebKit::WebString::fromUTF8(attribute_name); | 468 if (backing_store_) |
274 std::string current_value(element.getAttribute(web_attribute_name).utf8()); | 469 backing_store_->Clear(SK_ColorWHITE); |
275 if (current_value == attribute_value) | 470 gfx::Size old_view_size = last_view_size_; |
276 return; | 471 last_view_size_ = params.view_size; |
277 | 472 // Schedule a SizeChanged instead of calling it directly to ensure that |
278 if (attribute_value.empty()) { | 473 // the backing store has been updated before the developer attempts to |
279 element.removeAttribute(web_attribute_name); | 474 // resize to avoid flicker. |size_changed_in_flight_| acts as a form of |
280 } else { | 475 // flow control for SizeChanged events. If the guest's view size is changing |
281 element.setAttribute(web_attribute_name, | 476 // rapidly before a SizeChanged event fires, then we avoid scheduling |
282 WebKit::WebString::fromUTF8(attribute_value)); | 477 // another SizeChanged event. SizeChanged reads the new size from |
283 } | 478 // |last_view_size_| so we can be sure that it always fires an event |
| 479 // with the last seen view size. |
| 480 if (container_ && !size_changed_in_flight_) { |
| 481 size_changed_in_flight_ = true; |
| 482 MessageLoop::current()->PostTask( |
| 483 FROM_HERE, |
| 484 base::Bind(&BrowserPlugin::SizeChangedDueToAutoSize, |
| 485 base::Unretained(this), |
| 486 old_view_size)); |
| 487 } |
| 488 } |
| 489 |
| 490 // If we are now using a new damage buffer, then that means that the guest |
| 491 // has updated its size state in response to a resize request. We change |
| 492 // the backing store's size to accomodate the new damage buffer size. |
| 493 if (use_new_damage_buffer) { |
| 494 int backing_store_width = auto_size_ ? max_width_ : width(); |
| 495 int backing_store_height = auto_size_ ? max_height_: height(); |
| 496 backing_store_.reset( |
| 497 new BrowserPluginBackingStore( |
| 498 gfx::Size(backing_store_width, backing_store_height), |
| 499 params.scale_factor)); |
| 500 } |
| 501 |
| 502 // Update the backing store. |
| 503 if (!params.scroll_rect.IsEmpty()) { |
| 504 backing_store_->ScrollBackingStore(params.scroll_delta, |
| 505 params.scroll_rect, |
| 506 params.view_size); |
| 507 } |
| 508 for (unsigned i = 0; i < params.copy_rects.size(); i++) { |
| 509 backing_store_->PaintToBackingStore(params.bitmap_rect, |
| 510 params.copy_rects, |
| 511 current_damage_buffer_); |
| 512 } |
| 513 // Invalidate the container. |
| 514 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
| 515 // NULL so we shouldn't attempt to access it. |
| 516 if (container_) |
| 517 container_->invalidate(); |
| 518 PopulateAutoSizeParameters(&auto_size_params); |
| 519 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 520 render_view_routing_id_, |
| 521 instance_id_, |
| 522 message_id, |
| 523 auto_size_params, |
| 524 resize_guest_params)); |
284 } | 525 } |
285 | 526 |
286 void BrowserPlugin::SetMaxHeightAttribute(int max_height) { | 527 void BrowserPlugin::SetMaxHeightAttribute(int max_height) { |
287 if (max_height_ == max_height) | 528 if (max_height_ == max_height) |
288 return; | 529 return; |
289 max_height_ = max_height; | 530 max_height_ = max_height; |
290 if (!auto_size_) | 531 if (!auto_size_) |
291 return; | 532 return; |
292 UpdateGuestAutoSizeState(); | 533 UpdateGuestAutoSizeState(); |
293 } | 534 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 } | 730 } |
490 | 731 |
491 void BrowserPlugin::Reload() { | 732 void BrowserPlugin::Reload() { |
492 if (!navigate_src_sent_) | 733 if (!navigate_src_sent_) |
493 return; | 734 return; |
494 browser_plugin_manager()->Send( | 735 browser_plugin_manager()->Send( |
495 new BrowserPluginHostMsg_Reload(render_view_routing_id_, | 736 new BrowserPluginHostMsg_Reload(render_view_routing_id_, |
496 instance_id_)); | 737 instance_id_)); |
497 } | 738 } |
498 | 739 |
499 void BrowserPlugin::SetCursor(const WebCursor& cursor) { | |
500 cursor_ = cursor; | |
501 } | |
502 | |
503 void BrowserPlugin::UpdateRect( | |
504 int message_id, | |
505 const BrowserPluginMsg_UpdateRect_Params& params) { | |
506 bool use_new_damage_buffer = !backing_store_; | |
507 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | |
508 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | |
509 // If we have a pending damage buffer, and the guest has begun to use the | |
510 // damage buffer then we know the guest will no longer use the current | |
511 // damage buffer. At this point, we drop the current damage buffer, and | |
512 // mark the pending damage buffer as the current damage buffer. | |
513 if (DamageBufferMatches(pending_damage_buffer_, | |
514 params.damage_buffer_identifier)) { | |
515 SwapDamageBuffers(); | |
516 use_new_damage_buffer = true; | |
517 } | |
518 if ((!auto_size_ && | |
519 (width() != params.view_size.width() || | |
520 height() != params.view_size.height())) || | |
521 (auto_size_ && (!InAutoSizeBounds(params.view_size)))) { | |
522 if (pending_damage_buffer_) { | |
523 // The guest has not yet responded to the last resize request, and | |
524 // so we don't want to do anything at this point other than ACK the guest. | |
525 PopulateAutoSizeParameters(&auto_size_params); | |
526 } else { | |
527 // If we have no pending damage buffer, then the guest has not caught up | |
528 // with the BrowserPlugin container. We now tell the guest about the new | |
529 // container size. | |
530 pending_damage_buffer_ = | |
531 GetDamageBufferWithSizeParams(&auto_size_params, | |
532 &resize_guest_params); | |
533 } | |
534 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | |
535 render_view_routing_id_, | |
536 instance_id_, | |
537 message_id, | |
538 auto_size_params, | |
539 resize_guest_params)); | |
540 return; | |
541 } | |
542 | |
543 if (auto_size_ && (params.view_size != last_view_size_)) { | |
544 if (backing_store_) | |
545 backing_store_->Clear(SK_ColorWHITE); | |
546 gfx::Size old_view_size = last_view_size_; | |
547 last_view_size_ = params.view_size; | |
548 // Schedule a SizeChanged instead of calling it directly to ensure that | |
549 // the backing store has been updated before the developer attempts to | |
550 // resize to avoid flicker. |size_changed_in_flight_| acts as a form of | |
551 // flow control for SizeChanged events. If the guest's view size is changing | |
552 // rapidly before a SizeChanged event fires, then we avoid scheduling | |
553 // another SizeChanged event. SizeChanged reads the new size from | |
554 // |last_view_size_| so we can be sure that it always fires an event | |
555 // with the last seen view size. | |
556 if (container_ && !size_changed_in_flight_) { | |
557 size_changed_in_flight_ = true; | |
558 MessageLoop::current()->PostTask( | |
559 FROM_HERE, | |
560 base::Bind(&BrowserPlugin::SizeChangedDueToAutoSize, | |
561 base::Unretained(this), | |
562 old_view_size)); | |
563 } | |
564 } | |
565 | |
566 // If we are now using a new damage buffer, then that means that the guest | |
567 // has updated its size state in response to a resize request. We change | |
568 // the backing store's size to accomodate the new damage buffer size. | |
569 if (use_new_damage_buffer) { | |
570 int backing_store_width = auto_size_ ? max_width_ : width(); | |
571 int backing_store_height = auto_size_ ? max_height_: height(); | |
572 backing_store_.reset( | |
573 new BrowserPluginBackingStore( | |
574 gfx::Size(backing_store_width, backing_store_height), | |
575 params.scale_factor)); | |
576 } | |
577 | |
578 // Update the backing store. | |
579 if (!params.scroll_rect.IsEmpty()) { | |
580 backing_store_->ScrollBackingStore(params.scroll_delta, | |
581 params.scroll_rect, | |
582 params.view_size); | |
583 } | |
584 for (unsigned i = 0; i < params.copy_rects.size(); i++) { | |
585 backing_store_->PaintToBackingStore(params.bitmap_rect, | |
586 params.copy_rects, | |
587 current_damage_buffer_); | |
588 } | |
589 // Invalidate the container. | |
590 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | |
591 // NULL so we shouldn't attempt to access it. | |
592 if (container_) | |
593 container_->invalidate(); | |
594 PopulateAutoSizeParameters(&auto_size_params); | |
595 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | |
596 render_view_routing_id_, | |
597 instance_id_, | |
598 message_id, | |
599 auto_size_params, | |
600 resize_guest_params)); | |
601 } | |
602 | |
603 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) { | |
604 // We fire the event listeners before painting the sad graphic to give the | |
605 // developer an opportunity to display an alternative overlay image on crash. | |
606 std::string termination_status = TerminationStatusToString(status); | |
607 std::map<std::string, base::Value*> props; | |
608 props[kProcessId] = base::Value::CreateIntegerValue(process_id); | |
609 props[kReason] = base::Value::CreateStringValue(termination_status); | |
610 | |
611 // Event listeners may remove the BrowserPlugin from the document. If that | |
612 // happens, the BrowserPlugin will be scheduled for later deletion (see | |
613 // BrowserPlugin::destroy()). That will clear the container_ reference, | |
614 // but leave other member variables valid below. | |
615 TriggerEvent(kEventExit, &props); | |
616 | |
617 guest_crashed_ = true; | |
618 // We won't paint the contents of the current backing store again so we might | |
619 // as well toss it out and save memory. | |
620 backing_store_.reset(); | |
621 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | |
622 // NULL so we shouldn't attempt to access it. | |
623 if (container_) | |
624 container_->invalidate(); | |
625 } | |
626 | |
627 void BrowserPlugin::GuestUnresponsive(int process_id) { | |
628 std::map<std::string, base::Value*> props; | |
629 props[kProcessId] = base::Value::CreateIntegerValue(process_id); | |
630 TriggerEvent(kEventUnresponsive, &props); | |
631 } | |
632 | |
633 void BrowserPlugin::GuestResponsive(int process_id) { | |
634 std::map<std::string, base::Value*> props; | |
635 props[kProcessId] = base::Value::CreateIntegerValue(process_id); | |
636 TriggerEvent(kEventResponsive, &props); | |
637 } | |
638 | |
639 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { | |
640 std::map<std::string, base::Value*> props; | |
641 props[kURL] = base::Value::CreateStringValue(url.spec()); | |
642 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); | |
643 | |
644 TriggerEvent(kEventLoadStart, &props); | |
645 } | |
646 | |
647 void BrowserPlugin::LoadCommit( | |
648 const BrowserPluginMsg_LoadCommit_Params& params) { | |
649 // If the guest has just committed a new navigation then it is no longer | |
650 // crashed. | |
651 guest_crashed_ = false; | |
652 if (params.is_top_level) { | |
653 src_ = params.url.spec(); | |
654 UpdateDOMAttribute(kSrc, src_.c_str()); | |
655 } | |
656 process_id_ = params.process_id; | |
657 current_nav_entry_index_ = params.current_entry_index; | |
658 nav_entry_count_ = params.entry_count; | |
659 | |
660 std::map<std::string, base::Value*> props; | |
661 props[kURL] = base::Value::CreateStringValue(params.url.spec()); | |
662 props[kIsTopLevel] = base::Value::CreateBooleanValue(params.is_top_level); | |
663 TriggerEvent(kEventLoadCommit, &props); | |
664 } | |
665 | |
666 void BrowserPlugin::LoadStop() { | |
667 // Construct the loadStop event object. | |
668 TriggerEvent(kEventLoadStop, NULL); | |
669 } | |
670 | |
671 void BrowserPlugin::LoadAbort(const GURL& url, | |
672 bool is_top_level, | |
673 const std::string& type) { | |
674 std::map<std::string, base::Value*> props; | |
675 props[kURL] = base::Value::CreateStringValue(url.spec()); | |
676 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); | |
677 props[kReason] = base::Value::CreateStringValue(type); | |
678 TriggerEvent(kEventLoadAbort, &props); | |
679 } | |
680 | |
681 void BrowserPlugin::LoadRedirect(const GURL& old_url, | |
682 const GURL& new_url, | |
683 bool is_top_level) { | |
684 std::map<std::string, base::Value*> props; | |
685 props[kOldURL] = base::Value::CreateStringValue(old_url.spec()); | |
686 props[kNewURL] = base::Value::CreateStringValue(new_url.spec()); | |
687 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); | |
688 TriggerEvent(kEventLoadRedirect, &props); | |
689 } | |
690 | |
691 void BrowserPlugin::AdvanceFocus(bool reverse) { | |
692 DCHECK(render_view_); | |
693 render_view_->GetWebView()->advanceFocus(reverse); | |
694 } | |
695 | |
696 void BrowserPlugin::SetEmbedderFocus(bool focused) { | 740 void BrowserPlugin::SetEmbedderFocus(bool focused) { |
697 if (embedder_focused_ == focused) | 741 if (embedder_focused_ == focused) |
698 return; | 742 return; |
699 | 743 |
700 bool old_guest_focus_state = ShouldGuestBeFocused(); | 744 bool old_guest_focus_state = ShouldGuestBeFocused(); |
701 embedder_focused_ = focused; | 745 embedder_focused_ = focused; |
702 | 746 |
703 if (ShouldGuestBeFocused() != old_guest_focus_state) | 747 if (ShouldGuestBeFocused() != old_guest_focus_state) |
704 UpdateGuestFocusState(); | 748 UpdateGuestFocusState(); |
705 } | 749 } |
706 | 750 |
707 void BrowserPlugin::UpdateGuestFocusState() { | 751 void BrowserPlugin::UpdateGuestFocusState() { |
708 if (!navigate_src_sent_) | 752 if (!navigate_src_sent_) |
709 return; | 753 return; |
710 bool should_be_focused = ShouldGuestBeFocused(); | 754 bool should_be_focused = ShouldGuestBeFocused(); |
711 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( | 755 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( |
712 render_view_routing_id_, | 756 render_view_routing_id_, |
713 instance_id_, | 757 instance_id_, |
714 should_be_focused)); | 758 should_be_focused)); |
715 } | 759 } |
716 | 760 |
717 bool BrowserPlugin::ShouldGuestBeFocused() const { | 761 bool BrowserPlugin::ShouldGuestBeFocused() const { |
718 return plugin_focused_ && embedder_focused_; | 762 return plugin_focused_ && embedder_focused_; |
719 } | 763 } |
720 | 764 |
721 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) { | |
722 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); | |
723 content_window_routing_id_ = content_window_routing_id; | |
724 } | |
725 | |
726 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { | |
727 if (container()) { | |
728 container()->requestTouchEventType(accept ? | |
729 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : | |
730 WebKit::WebPluginContainer::TouchEventRequestTypeNone); | |
731 } | |
732 } | |
733 | |
734 WebKit::WebPluginContainer* BrowserPlugin::container() const { | 765 WebKit::WebPluginContainer* BrowserPlugin::container() const { |
735 return container_; | 766 return container_; |
736 } | 767 } |
737 | 768 |
738 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 769 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
739 container_ = container; | 770 container_ = container; |
740 container_->setWantsWheelEvents(true); | 771 container_->setWantsWheelEvents(true); |
741 return true; | 772 return true; |
742 } | 773 } |
743 | 774 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 void* notify_data) { | 1047 void* notify_data) { |
1017 } | 1048 } |
1018 | 1049 |
1019 void BrowserPlugin::didFailLoadingFrameRequest( | 1050 void BrowserPlugin::didFailLoadingFrameRequest( |
1020 const WebKit::WebURL& url, | 1051 const WebKit::WebURL& url, |
1021 void* notify_data, | 1052 void* notify_data, |
1022 const WebKit::WebURLError& error) { | 1053 const WebKit::WebURLError& error) { |
1023 } | 1054 } |
1024 | 1055 |
1025 } // namespace content | 1056 } // namespace content |
OLD | NEW |