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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/browser_plugin/browser_plugin_guest.cc
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc
index 00529ffab22904afb2517c11d4d8eac2b82d20e6..55dd9bbf95f16d6d114100517579345d708cdf51 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc
@@ -564,6 +564,46 @@ void BrowserPluginGuest::EmbedderSystemDragEnded() {
EndSystemDragIfApplicable();
}
+// TODO(wjmaclean): Replace this approach with ones based on std::function
+// as in https://codereview.chromium.org/1404353004/ once all Chrome platforms
+// support this. https://crbug.com/544212
+IPC::Message* BrowserPluginGuest::UpdateInstanceIdIfNecessary(
+ IPC::Message* msg) const {
+ DCHECK(msg);
+
+ int msg_browser_plugin_instance_id = browser_plugin::kInstanceIDNone;
+ base::PickleIterator iter(*msg);
+ if (!iter.ReadInt(&msg_browser_plugin_instance_id) ||
+ msg_browser_plugin_instance_id != browser_plugin::kInstanceIDNone) {
+ return msg;
+ }
+
+ // This method may be called with no browser_plugin_instance_id in tests.
+ if (!browser_plugin_instance_id())
+ return msg;
+
+ scoped_ptr<IPC::Message> new_msg(
+ new IPC::Message(msg->routing_id(), msg->type(), msg->priority()));
+ new_msg->WriteInt(browser_plugin_instance_id());
+
+ // Copy remaining payload from original message.
+ // TODO(wjmaclean): it would be nice if IPC::PickleIterator had a method
+ // like 'RemainingBytes()' so that we don't have to include implementation-
+ // specific details like sizeof() in the next line.
+ DCHECK(msg->payload_size() > sizeof(int));
+ size_t remaining_bytes = msg->payload_size() - sizeof(int);
+ const char* data = nullptr;
+ bool read_success = iter.ReadBytes(&data, remaining_bytes);
+ CHECK(read_success)
+ << "Unexpected failure reading remaining IPC::Message payload.";
+ bool write_success = new_msg->WriteBytes(data, remaining_bytes);
+ CHECK(write_success)
+ << "Unexpected failure writing remaining IPC::Message payload.";
+
+ delete msg;
+ return new_msg.release();
+}
+
void BrowserPluginGuest::SendQueuedMessages() {
if (!attached())
return;
@@ -571,7 +611,8 @@ void BrowserPluginGuest::SendQueuedMessages() {
while (!pending_messages_.empty()) {
linked_ptr<IPC::Message> message_ptr = pending_messages_.front();
pending_messages_.pop_front();
- SendMessageToEmbedder(message_ptr.release());
+ SendMessageToEmbedder(
+ UpdateInstanceIdIfNecessary(message_ptr.release()));
}
}
« 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