mock_browser_plugin_manager.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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. 4 5#include "content/renderer/browser_plugin/mock_browser_plugin_manager.h" 6 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" 11 12namespace content { 13 14MockBrowserPluginManager::MockBrowserPluginManager( 15 RenderViewImpl* render_view) 16 : BrowserPluginManager(render_view), 17 guest_instance_id_counter_(0) { 18} 19 20MockBrowserPluginManager::~MockBrowserPluginManager() { 21} 22 23BrowserPlugin* MockBrowserPluginManager::CreateBrowserPlugin( 24 RenderViewImpl* render_view, blink::WebFrame* frame) { 25 return new MockBrowserPlugin(render_view, frame); 26} 27 28void MockBrowserPluginManager::AllocateInstanceID( 29 const base::WeakPtr<BrowserPlugin>& browser_plugin) { 30 int guest_instance_id = ++guest_instance_id_counter_; 31 base::MessageLoop::current()->PostTask( 32 FROM_HERE, 33 base::Bind(&MockBrowserPluginManager::AllocateInstanceIDACK, 34 this, 35 browser_plugin.get(), 36 guest_instance_id)); 37} 38 39void MockBrowserPluginManager::AllocateInstanceIDACK( 40 BrowserPlugin* browser_plugin, 41 int guest_instance_id) { 42 browser_plugin->OnInstanceIDAllocated(guest_instance_id); 43 scoped_ptr<base::DictionaryValue> extra_params(new base::DictionaryValue()); 44 browser_plugin->Attach(extra_params.Pass()); 45} 46 47bool MockBrowserPluginManager::Send(IPC::Message* msg) { 48 // This is a copy-and-paste from MockRenderThread::Send. 49 // We need to simulate a synchronous channel, thus we are going to receive 50 // through this function messages, messages with reply and reply messages. 51 // We can only handle one synchronous message at a time. 52 if (msg->is_reply()) { 53 if (reply_deserializer_) { 54 reply_deserializer_->SerializeOutputParameters(*msg); 55 reply_deserializer_.reset(); 56 } 57 } else { 58 if (msg->is_sync()) { 59 // We actually need to handle deleting the reply deserializer for sync 60 // messages. 61 reply_deserializer_.reset( 62 static_cast<IPC::SyncMessage*>(msg)->GetReplyDeserializer()); 63 } 64 OnMessageReceived(*msg); 65 } 66 delete msg; 67 return true; 68} 69 70bool MockBrowserPluginManager::OnMessageReceived( 71 const IPC::Message& message) { 72 // Save the message in the sink. 73 sink_.OnMessageReceived(message); 74 return false; 75} 76 77} // namespace content 78