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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 1410753003: Update IPC browser_plugin_instance_id before sending queued messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move computation outside CHECK(). Created 5 years, 2 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
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.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/browser/browser_plugin/browser_plugin_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 seen_embedder_drag_source_ended_at_ = false; 557 seen_embedder_drag_source_ended_at_ = false;
558 dragged_url_ = GURL(); 558 dragged_url_ = GURL();
559 } 559 }
560 } 560 }
561 561
562 void BrowserPluginGuest::EmbedderSystemDragEnded() { 562 void BrowserPluginGuest::EmbedderSystemDragEnded() {
563 seen_embedder_system_drag_ended_ = true; 563 seen_embedder_system_drag_ended_ = true;
564 EndSystemDragIfApplicable(); 564 EndSystemDragIfApplicable();
565 } 565 }
566 566
567 // TODO(wjmaclean): Replace this approach with ones based on std::function
568 // as in https://codereview.chromium.org/1404353004/ once all Chrome platforms
569 // support this. https://crbug.com/544212
570 IPC::Message* BrowserPluginGuest::UpdateInstanceIdIfNecessary(
571 IPC::Message* msg) const {
572 DCHECK(msg);
573
574 int msg_browser_plugin_instance_id = browser_plugin::kInstanceIDNone;
575 base::PickleIterator iter(*msg);
576 if (!iter.ReadInt(&msg_browser_plugin_instance_id) ||
577 msg_browser_plugin_instance_id != browser_plugin::kInstanceIDNone) {
578 return msg;
579 }
580
581 // This method may be called with no browser_plugin_instance_id in tests.
582 if (!browser_plugin_instance_id())
583 return msg;
584
585 scoped_ptr<IPC::Message> new_msg(
586 new IPC::Message(msg->routing_id(), msg->type(), msg->priority()));
587 new_msg->WriteInt(browser_plugin_instance_id());
588
589 // Copy remaining payload from original message.
590 // TODO(wjmaclean): it would be nice if IPC::PickleIterator had a method
591 // like 'RemainingBytes()' so that we don't have to include implementation-
592 // specific details like sizeof() in the next line.
593 DCHECK(msg->payload_size() > sizeof(int));
594 size_t remaining_bytes = msg->payload_size() - sizeof(int);
595 const char* data = nullptr;
596 bool read_success = iter.ReadBytes(&data, remaining_bytes);
597 CHECK(read_success)
598 << "Unexpected failure reading remaining IPC::Message payload.";
599 bool write_success = new_msg->WriteBytes(data, remaining_bytes);
600 CHECK(write_success)
601 << "Unexpected failure writing remaining IPC::Message payload.";
602
603 delete msg;
604 return new_msg.release();
605 }
606
567 void BrowserPluginGuest::SendQueuedMessages() { 607 void BrowserPluginGuest::SendQueuedMessages() {
568 if (!attached()) 608 if (!attached())
569 return; 609 return;
570 610
571 while (!pending_messages_.empty()) { 611 while (!pending_messages_.empty()) {
572 linked_ptr<IPC::Message> message_ptr = pending_messages_.front(); 612 linked_ptr<IPC::Message> message_ptr = pending_messages_.front();
573 pending_messages_.pop_front(); 613 pending_messages_.pop_front();
574 SendMessageToEmbedder(message_ptr.release()); 614 SendMessageToEmbedder(
615 UpdateInstanceIdIfNecessary(message_ptr.release()));
575 } 616 }
576 } 617 }
577 618
578 void BrowserPluginGuest::SendTextInputTypeChangedToView( 619 void BrowserPluginGuest::SendTextInputTypeChangedToView(
579 RenderWidgetHostViewBase* guest_rwhv) { 620 RenderWidgetHostViewBase* guest_rwhv) {
580 if (!guest_rwhv) 621 if (!guest_rwhv)
581 return; 622 return;
582 623
583 if (!owner_web_contents_) { 624 if (!owner_web_contents_) {
584 // If we were showing an interstitial, then we can end up here during 625 // If we were showing an interstitial, then we can end up here during
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 range, character_bounds); 1052 range, character_bounds);
1012 } 1053 }
1013 #endif 1054 #endif
1014 1055
1015 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) { 1056 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) {
1016 if (delegate_) 1057 if (delegate_)
1017 delegate_->SetContextMenuPosition(position); 1058 delegate_->SetContextMenuPosition(position);
1018 } 1059 }
1019 1060
1020 } // namespace content 1061 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698