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/browser/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
13 #include "base/pickle.h" | 14 #include "base/pickle.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "cc/surfaces/surface.h" | 17 #include "cc/surfaces/surface.h" |
17 #include "cc/surfaces/surface_manager.h" | 18 #include "cc/surfaces/surface_manager.h" |
18 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 19 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
19 #include "content/browser/browser_thread_impl.h" | 20 #include "content/browser/browser_thread_impl.h" |
20 #include "content/browser/child_process_security_policy_impl.h" | 21 #include "content/browser/child_process_security_policy_impl.h" |
21 #include "content/browser/compositor/surface_utils.h" | 22 #include "content/browser/compositor/surface_utils.h" |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 gfx::Point BrowserPluginGuest::GetScreenCoordinates( | 486 gfx::Point BrowserPluginGuest::GetScreenCoordinates( |
486 const gfx::Point& relative_position) const { | 487 const gfx::Point& relative_position) const { |
487 if (!attached()) | 488 if (!attached()) |
488 return relative_position; | 489 return relative_position; |
489 | 490 |
490 gfx::Point screen_pos(relative_position); | 491 gfx::Point screen_pos(relative_position); |
491 screen_pos += guest_window_rect_.OffsetFromOrigin(); | 492 screen_pos += guest_window_rect_.OffsetFromOrigin(); |
492 return screen_pos; | 493 return screen_pos; |
493 } | 494 } |
494 | 495 |
495 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 496 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
Avi (use Gerrit)
2016/10/19 18:10:32
Does it make sense, rather than doing a WrapUnique
| |
496 // During tests, attache() may be true when there is no owner_web_contents_; | 497 // During tests, attache() may be true when there is no owner_web_contents_; |
497 // in this case just queue any messages we receive. | 498 // in this case just queue any messages we receive. |
498 if (!attached() || !owner_web_contents_) { | 499 if (!attached() || !owner_web_contents_) { |
499 // Some pages such as data URLs, javascript URLs, and about:blank | 500 // Some pages such as data URLs, javascript URLs, and about:blank |
500 // do not load external resources and so they load prior to attachment. | 501 // do not load external resources and so they load prior to attachment. |
501 // As a result, we must save all these IPCs until attachment and then | 502 // As a result, we must save all these IPCs until attachment and then |
502 // forward them so that the embedder gets a chance to see and process | 503 // forward them so that the embedder gets a chance to see and process |
503 // the load events. | 504 // the load events. |
504 pending_messages_.push_back(linked_ptr<IPC::Message>(msg)); | 505 pending_messages_.push_back(base::WrapUnique(msg)); |
505 return; | 506 return; |
506 } | 507 } |
507 owner_web_contents_->Send(msg); | 508 owner_web_contents_->Send(msg); |
508 } | 509 } |
509 | 510 |
510 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, | 511 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, |
511 int screen_x, int screen_y, blink::WebDragOperation operation) { | 512 int screen_x, int screen_y, blink::WebDragOperation operation) { |
512 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, | 513 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, |
513 screen_x, screen_y, operation); | 514 screen_x, screen_y, operation); |
514 seen_embedder_drag_source_ended_at_ = true; | 515 seen_embedder_drag_source_ended_at_ = true; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 | 550 |
550 void BrowserPluginGuest::EmbedderSystemDragEnded() { | 551 void BrowserPluginGuest::EmbedderSystemDragEnded() { |
551 seen_embedder_system_drag_ended_ = true; | 552 seen_embedder_system_drag_ended_ = true; |
552 EndSystemDragIfApplicable(); | 553 EndSystemDragIfApplicable(); |
553 } | 554 } |
554 | 555 |
555 // TODO(wjmaclean): Replace this approach with ones based on std::function | 556 // TODO(wjmaclean): Replace this approach with ones based on std::function |
556 // as in https://codereview.chromium.org/1404353004/ once all Chrome platforms | 557 // as in https://codereview.chromium.org/1404353004/ once all Chrome platforms |
557 // support this. https://crbug.com/544212 | 558 // support this. https://crbug.com/544212 |
558 IPC::Message* BrowserPluginGuest::UpdateInstanceIdIfNecessary( | 559 IPC::Message* BrowserPluginGuest::UpdateInstanceIdIfNecessary( |
559 IPC::Message* msg) const { | 560 std::unique_ptr<IPC::Message> msg) const { |
560 DCHECK(msg); | 561 DCHECK(msg.get()); |
561 | 562 |
562 int msg_browser_plugin_instance_id = browser_plugin::kInstanceIDNone; | 563 int msg_browser_plugin_instance_id = browser_plugin::kInstanceIDNone; |
563 base::PickleIterator iter(*msg); | 564 base::PickleIterator iter(*msg.get()); |
564 if (!iter.ReadInt(&msg_browser_plugin_instance_id) || | 565 if (!iter.ReadInt(&msg_browser_plugin_instance_id) || |
565 msg_browser_plugin_instance_id != browser_plugin::kInstanceIDNone) { | 566 msg_browser_plugin_instance_id != browser_plugin::kInstanceIDNone) { |
566 return msg; | 567 return msg.release(); |
Avi (use Gerrit)
2016/10/19 18:08:23
What?
It makes little sense to have the parameter
| |
567 } | 568 } |
568 | 569 |
569 // This method may be called with no browser_plugin_instance_id in tests. | 570 // This method may be called with no browser_plugin_instance_id in tests. |
570 if (!browser_plugin_instance_id()) | 571 if (!browser_plugin_instance_id()) |
571 return msg; | 572 return msg.release(); |
Avi (use Gerrit)
2016/10/19 18:08:23
ditto
| |
572 | 573 |
573 std::unique_ptr<IPC::Message> new_msg( | 574 std::unique_ptr<IPC::Message> new_msg( |
574 new IPC::Message(msg->routing_id(), msg->type(), msg->priority())); | 575 new IPC::Message(msg->routing_id(), msg->type(), msg->priority())); |
575 new_msg->WriteInt(browser_plugin_instance_id()); | 576 new_msg->WriteInt(browser_plugin_instance_id()); |
576 | 577 |
577 // Copy remaining payload from original message. | 578 // Copy remaining payload from original message. |
578 // TODO(wjmaclean): it would be nice if IPC::PickleIterator had a method | 579 // TODO(wjmaclean): it would be nice if IPC::PickleIterator had a method |
579 // like 'RemainingBytes()' so that we don't have to include implementation- | 580 // like 'RemainingBytes()' so that we don't have to include implementation- |
580 // specific details like sizeof() in the next line. | 581 // specific details like sizeof() in the next line. |
581 DCHECK(msg->payload_size() > sizeof(int)); | 582 DCHECK(msg->payload_size() > sizeof(int)); |
582 size_t remaining_bytes = msg->payload_size() - sizeof(int); | 583 size_t remaining_bytes = msg->payload_size() - sizeof(int); |
583 const char* data = nullptr; | 584 const char* data = nullptr; |
584 bool read_success = iter.ReadBytes(&data, remaining_bytes); | 585 bool read_success = iter.ReadBytes(&data, remaining_bytes); |
585 CHECK(read_success) | 586 CHECK(read_success) |
586 << "Unexpected failure reading remaining IPC::Message payload."; | 587 << "Unexpected failure reading remaining IPC::Message payload."; |
587 bool write_success = new_msg->WriteBytes(data, remaining_bytes); | 588 bool write_success = new_msg->WriteBytes(data, remaining_bytes); |
588 CHECK(write_success) | 589 CHECK(write_success) |
589 << "Unexpected failure writing remaining IPC::Message payload."; | 590 << "Unexpected failure writing remaining IPC::Message payload."; |
590 | 591 |
591 delete msg; | |
592 return new_msg.release(); | 592 return new_msg.release(); |
Avi (use Gerrit)
2016/10/19 18:08:23
All paths out of this function return a unique_ptr
limasdf
2016/10/20 12:09:02
Done.
| |
593 } | 593 } |
594 | 594 |
595 void BrowserPluginGuest::SendQueuedMessages() { | 595 void BrowserPluginGuest::SendQueuedMessages() { |
596 if (!attached()) | 596 if (!attached()) |
597 return; | 597 return; |
598 | 598 |
599 while (!pending_messages_.empty()) { | 599 while (!pending_messages_.empty()) { |
600 linked_ptr<IPC::Message> message_ptr = pending_messages_.front(); | 600 std::unique_ptr<IPC::Message> message_ptr = |
601 std::move(pending_messages_.front()); | |
601 pending_messages_.pop_front(); | 602 pending_messages_.pop_front(); |
602 SendMessageToEmbedder( | 603 SendMessageToEmbedder(UpdateInstanceIdIfNecessary(std::move(message_ptr))); |
Avi (use Gerrit)
2016/10/19 18:10:32
And it all comes together here. Have UpdateInstanc
limasdf
2016/10/20 12:09:02
Done.
| |
603 UpdateInstanceIdIfNecessary(message_ptr.release())); | |
604 } | 604 } |
605 } | 605 } |
606 | 606 |
607 void BrowserPluginGuest::SendTextInputTypeChangedToView( | 607 void BrowserPluginGuest::SendTextInputTypeChangedToView( |
608 RenderWidgetHostViewBase* guest_rwhv) { | 608 RenderWidgetHostViewBase* guest_rwhv) { |
609 if (!guest_rwhv) | 609 if (!guest_rwhv) |
610 return; | 610 return; |
611 | 611 |
612 if (!owner_web_contents_) { | 612 if (!owner_web_contents_) { |
613 // If we were showing an interstitial, then we can end up here during | 613 // If we were showing an interstitial, then we can end up here during |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1034 range, character_bounds); | 1034 range, character_bounds); |
1035 } | 1035 } |
1036 #endif | 1036 #endif |
1037 | 1037 |
1038 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) { | 1038 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) { |
1039 if (delegate_) | 1039 if (delegate_) |
1040 delegate_->SetContextMenuPosition(position); | 1040 delegate_->SetContextMenuPosition(position); |
1041 } | 1041 } |
1042 | 1042 |
1043 } // namespace content | 1043 } // namespace content |
OLD | NEW |