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
3 // found in the LICENSE file.
5 #include "content/renderer/browser_plugin/mock_browser_plugin_manager.h"
7 #include "base/message_loop/message_loop.h"
8 #include "content/common/browser_plugin/browser_plugin_messages.h"
9 #include "content/renderer/browser_plugin/mock_browser_plugin.h"
10 #include "ipc/ipc_message.h"
14 MockBrowserPluginManager::MockBrowserPluginManager(
15 RenderViewImpl* render_view)
16 : BrowserPluginManager(render_view),
17 guest_instance_id_counter_(0) {
20 MockBrowserPluginManager::~MockBrowserPluginManager() {
23 BrowserPlugin* MockBrowserPluginManager::CreateBrowserPlugin(
24 RenderViewImpl* render_view,
25 blink::WebFrame* frame,
27 return new MockBrowserPlugin(render_view, frame, auto_navigate);
30 void MockBrowserPluginManager::AllocateInstanceID(
31 const base::WeakPtr<BrowserPlugin>& browser_plugin) {
32 int guest_instance_id = ++guest_instance_id_counter_;
33 base::MessageLoop::current()->PostTask(
35 base::Bind(&MockBrowserPluginManager::AllocateInstanceIDACK,
41 void MockBrowserPluginManager::AllocateInstanceIDACK(
42 BrowserPlugin* browser_plugin,
43 int guest_instance_id) {
44 scoped_ptr<base::DictionaryValue> extra_params(new base::DictionaryValue());
45 browser_plugin->Attach(guest_instance_id, extra_params.Pass());
48 bool MockBrowserPluginManager::Send(IPC::Message* msg) {
49 // This is a copy-and-paste from MockRenderThread::Send.
50 // We need to simulate a synchronous channel, thus we are going to receive
51 // through this function messages, messages with reply and reply messages.
52 // We can only handle one synchronous message at a time.
53 if (msg->is_reply()) {
54 if (reply_deserializer_) {
55 reply_deserializer_->SerializeOutputParameters(*msg);
56 reply_deserializer_.reset();
60 // We actually need to handle deleting the reply deserializer for sync
62 reply_deserializer_.reset(
63 static_cast<IPC::SyncMessage*>(msg)->GetReplyDeserializer());
65 OnMessageReceived(*msg);
71 bool MockBrowserPluginManager::OnMessageReceived(
72 const IPC::Message& message) {
73 // Save the message in the sink.
74 sink_.OnMessageReceived(message);
78 } // namespace content