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