Chromium Code Reviews| 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..a10565b2da70a8f5fc740f6865aed8c72cad48a6 100644 |
| --- a/content/browser/browser_plugin/browser_plugin_guest.cc |
| +++ b/content/browser/browser_plugin/browser_plugin_guest.cc |
| @@ -564,6 +564,44 @@ 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; |
| + CHECK(iter.ReadBytes(&data, remaining_bytes)) |
|
lfg
2015/10/16 18:25:49
It's not a good idea to have the code inside the C
lazyboy
2015/10/16 18:27:15
+1 Thanks for noticing this.
|
| + << "Unexpected failure reading remaining IPC::Message payload."; |
| + CHECK(new_msg->WriteBytes(data, remaining_bytes)) |
| + << "Unexpected failure writing remaining IPC::Message payload."; |
| + |
| + delete msg; |
| + return new_msg.release(); |
| +} |
| + |
| void BrowserPluginGuest::SendQueuedMessages() { |
| if (!attached()) |
| return; |
| @@ -571,7 +609,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())); |
| } |
| } |