summaryrefslogtreecommitdiffstats
path: root/content/plugin
diff options
context:
space:
mode:
authorsteveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-20 00:40:50 +0000
committersteveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-20 00:40:50 +0000
commit099587b7a8bf441af62251275197973203e2f11a (patch)
treea8e0711b152925dbc2102b692d6ceec19e881fa3 /content/plugin
parent79311e89bc4fbd952d5ce872011f8360bfa5e6e6 (diff)
downloadchromium_src-099587b7a8bf441af62251275197973203e2f11a.zip
chromium_src-099587b7a8bf441af62251275197973203e2f11a.tar.gz
chromium_src-099587b7a8bf441af62251275197973203e2f11a.tar.bz2
Move NPObjectBase and PluginChannelBase from content/plugin to content/common
Also rename PluginChannelBase to NPChannelBase, fix variable naming to be agnostic of plugins, and fix a comment in NPChannelBase. This change is refactoring only and introduces no change in behaviour. BUG=96703 Review URL: http://codereview.chromium.org/7891003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101874 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/plugin')
-rw-r--r--content/plugin/npobject_base.h27
-rw-r--r--content/plugin/npobject_proxy.cc14
-rw-r--r--content/plugin/npobject_proxy.h14
-rw-r--r--content/plugin/npobject_stub.cc5
-rw-r--r--content/plugin/npobject_stub.h8
-rw-r--r--content/plugin/npobject_util.cc9
-rw-r--r--content/plugin/npobject_util.h8
-rw-r--r--content/plugin/plugin_channel.cc12
-rw-r--r--content/plugin/plugin_channel.h8
-rw-r--r--content/plugin/plugin_channel_base.cc272
-rw-r--r--content/plugin/plugin_channel_base.h192
-rw-r--r--content/plugin/plugin_thread.cc2
12 files changed, 40 insertions, 531 deletions
diff --git a/content/plugin/npobject_base.h b/content/plugin/npobject_base.h
deleted file mode 100644
index fc6117a..0000000
--- a/content/plugin/npobject_base.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-// Base interface implemented by NPObjectProxy and NPObjectStub
-
-#ifndef CONTENT_PLUGIN_NPOBJECT_BASE_H_
-#define CONTENT_PLUGIN_NPOBJECT_BASE_H_
-#pragma once
-
-#include "ipc/ipc_channel.h"
-#include "third_party/npapi/bindings/npruntime.h"
-
-struct NPObject;
-
-class NPObjectBase {
- public:
- virtual ~NPObjectBase() {}
-
- // Returns the underlying NPObject handled by this NPObjectBase instance.
- virtual NPObject* GetUnderlyingNPObject() = 0;
-
- // Returns the channel listener for this NPObjectBase instance.
- virtual IPC::Channel::Listener* GetChannelListener() = 0;
-};
-
-#endif // CONTENT_PLUGIN_NPOBJECT_BASE_H_
diff --git a/content/plugin/npobject_proxy.cc b/content/plugin/npobject_proxy.cc
index 8772b2a..cb0ed89 100644
--- a/content/plugin/npobject_proxy.cc
+++ b/content/plugin/npobject_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -55,7 +55,7 @@ IPC::Channel::Listener* NPObjectProxy::GetChannelListener() {
}
NPObjectProxy::NPObjectProxy(
- PluginChannelBase* channel,
+ NPChannelBase* channel,
int route_id,
gfx::NativeViewId containing_window,
const GURL& page_url)
@@ -79,7 +79,7 @@ NPObjectProxy::~NPObjectProxy() {
}
}
-NPObject* NPObjectProxy::Create(PluginChannelBase* channel,
+NPObject* NPObjectProxy::Create(NPChannelBase* channel,
int route_id,
gfx::NativeViewId containing_window,
const GURL& page_url) {
@@ -187,7 +187,7 @@ bool NPObjectProxy::NPInvokePrivate(NPP npp,
// Note: This instance can get destroyed in the context of
// Send so addref the channel in this scope.
- scoped_refptr<PluginChannelBase> channel_copy = proxy->channel_;
+ scoped_refptr<NPChannelBase> channel_copy = proxy->channel_;
std::vector<NPVariant_Param> args_param;
for (unsigned int i = 0; i < arg_count; ++i) {
NPVariant_Param param;
@@ -277,7 +277,7 @@ bool NPObjectProxy::NPGetProperty(NPObject *obj,
CreateNPIdentifierParam(name, &name_param);
NPVariant_Param param;
- scoped_refptr<PluginChannelBase> channel(proxy->channel_);
+ scoped_refptr<NPChannelBase> channel(proxy->channel_);
GURL page_url = proxy->page_url_;
proxy->Send(new NPObjectMsg_GetProperty(
@@ -415,7 +415,7 @@ bool NPObjectProxy::NPNConstruct(NPObject *obj,
// Note: This instance can get destroyed in the context of
// Send so addref the channel in this scope.
- scoped_refptr<PluginChannelBase> channel_copy = proxy->channel_;
+ scoped_refptr<NPChannelBase> channel_copy = proxy->channel_;
std::vector<NPVariant_Param> args_param;
for (unsigned int i = 0; i < arg_count; ++i) {
NPVariant_Param param;
@@ -490,7 +490,7 @@ bool NPObjectProxy::NPNEvaluate(NPP npp,
channel->GetModalDialogEvent(proxy->containing_window_));
}
}
- scoped_refptr<PluginChannelBase> channel(proxy->channel_);
+ scoped_refptr<NPChannelBase> channel(proxy->channel_);
GURL page_url = proxy->page_url_;
proxy->Send(msg);
diff --git a/content/plugin/npobject_proxy.h b/content/plugin/npobject_proxy.h
index dccd531..fea41ff 100644
--- a/content/plugin/npobject_proxy.h
+++ b/content/plugin/npobject_proxy.h
@@ -10,13 +10,13 @@
#pragma once
#include "base/memory/ref_counted.h"
-#include "content/plugin/npobject_base.h"
+#include "content/common/npobject_base.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_channel.h"
#include "third_party/npapi/bindings/npruntime.h"
#include "ui/gfx/native_widget_types.h"
-class PluginChannelBase;
+class NPChannelBase;
struct NPObject;
// When running a plugin in a different process from the renderer, we need to
@@ -24,7 +24,7 @@ struct NPObject;
// as a plugin can get an NPObject for the window, and a page can get an
// NPObject for the plugin. In the process that interacts with the NPobject we
// give it an NPObjectProxy instead. All calls to it are sent across an IPC
-// channel (specifically, a PluginChannelBase). The NPObjectStub on the other
+// channel (specifically, a NPChannelBase). The NPObjectStub on the other
// side translates the IPC messages into calls to the actual NPObject, and
// returns the marshalled result.
class NPObjectProxy : public IPC::Channel::Listener,
@@ -33,7 +33,7 @@ class NPObjectProxy : public IPC::Channel::Listener,
public:
virtual ~NPObjectProxy();
- static NPObject* Create(PluginChannelBase* channel,
+ static NPObject* Create(NPChannelBase* channel,
int route_id,
gfx::NativeViewId containing_window,
const GURL& page_url);
@@ -41,7 +41,7 @@ class NPObjectProxy : public IPC::Channel::Listener,
// IPC::Message::Sender implementation:
virtual bool Send(IPC::Message* msg);
int route_id() { return route_id_; }
- PluginChannelBase* channel() { return channel_; }
+ NPChannelBase* channel() { return channel_; }
// The next 9 functions are called on NPObjects from the plugin and browser.
static bool NPHasMethod(NPObject *obj,
@@ -96,7 +96,7 @@ class NPObjectProxy : public IPC::Channel::Listener,
virtual IPC::Channel::Listener* GetChannelListener();
private:
- NPObjectProxy(PluginChannelBase* channel,
+ NPObjectProxy(NPChannelBase* channel,
int route_id,
gfx::NativeViewId containing_window,
const GURL& page_url);
@@ -112,7 +112,7 @@ class NPObjectProxy : public IPC::Channel::Listener,
static void NPPInvalidate(NPObject *obj);
static NPClass npclass_proxy_;
- scoped_refptr<PluginChannelBase> channel_;
+ scoped_refptr<NPChannelBase> channel_;
int route_id_;
gfx::NativeViewId containing_window_;
diff --git a/content/plugin/npobject_stub.cc b/content/plugin/npobject_stub.cc
index b3e1441..5b50a7b 100644
--- a/content/plugin/npobject_stub.cc
+++ b/content/plugin/npobject_stub.cc
@@ -7,18 +7,19 @@
#include "content/common/content_client.h"
#include "content/common/plugin_messages.h"
#include "content/plugin/npobject_util.h"
-#include "content/plugin/plugin_channel_base.h"
#include "content/plugin/plugin_thread.h"
#include "third_party/npapi/bindings/npapi.h"
#include "third_party/npapi/bindings/npruntime.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "webkit/plugins/npapi/plugin_constants_win.h"
+class NPChannelBase;
+
using WebKit::WebBindings;
NPObjectStub::NPObjectStub(
NPObject* npobject,
- PluginChannelBase* channel,
+ NPChannelBase* channel,
int route_id,
gfx::NativeViewId containing_window,
const GURL& page_url)
diff --git a/content/plugin/npobject_stub.h b/content/plugin/npobject_stub.h
index d48fa09..7dbc32f 100644
--- a/content/plugin/npobject_stub.h
+++ b/content/plugin/npobject_stub.h
@@ -13,12 +13,12 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
-#include "content/plugin/npobject_base.h"
+#include "content/common/npobject_base.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_channel.h"
#include "ui/gfx/native_widget_types.h"
-class PluginChannelBase;
+class NPChannelBase;
struct NPIdentifier_Param;
struct NPObject;
struct NPVariant_Param;
@@ -32,7 +32,7 @@ class NPObjectStub : public IPC::Channel::Listener,
public NPObjectBase {
public:
NPObjectStub(NPObject* npobject,
- PluginChannelBase* channel,
+ NPChannelBase* channel,
int route_id,
gfx::NativeViewId containing_window,
const GURL& page_url);
@@ -84,7 +84,7 @@ class NPObjectStub : public IPC::Channel::Listener,
private:
NPObject* npobject_;
- scoped_refptr<PluginChannelBase> channel_;
+ scoped_refptr<NPChannelBase> channel_;
int route_id_;
gfx::NativeViewId containing_window_;
diff --git a/content/plugin/npobject_util.cc b/content/plugin/npobject_util.cc
index f9aba8a0c..8890280 100644
--- a/content/plugin/npobject_util.cc
+++ b/content/plugin/npobject_util.cc
@@ -5,9 +5,9 @@
#include "content/plugin/npobject_util.h"
#include "base/string_util.h"
+#include "content/common/np_channel_base.h"
#include "content/common/plugin_messages.h"
#include "content/plugin/npobject_proxy.h"
-#include "content/plugin/plugin_channel_base.h"
#include "third_party/npapi/bindings/nphostapi.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "webkit/plugins/npapi/plugin_host.h"
@@ -87,8 +87,7 @@ static bool NPN_EvaluatePatch(NPP npp,
static void NPN_SetExceptionPatch(NPObject *obj, const NPUTF8 *message) {
std::string message_str(message);
if (IsPluginProcess()) {
- PluginChannelBase* renderer_channel =
- PluginChannelBase::GetCurrentChannel();
+ NPChannelBase* renderer_channel = NPChannelBase::GetCurrentChannel();
if (renderer_channel)
renderer_channel->Send(new PluginHostMsg_SetException(message_str));
} else {
@@ -145,7 +144,7 @@ NPIdentifier CreateNPIdentifier(const NPIdentifier_Param& param) {
}
void CreateNPVariantParam(const NPVariant& variant,
- PluginChannelBase* channel,
+ NPChannelBase* channel,
NPVariant_Param* param,
bool release,
gfx::NativeViewId containing_window,
@@ -219,7 +218,7 @@ void CreateNPVariantParam(const NPVariant& variant,
}
bool CreateNPVariant(const NPVariant_Param& param,
- PluginChannelBase* channel,
+ NPChannelBase* channel,
NPVariant* result,
gfx::NativeViewId containing_window,
const GURL& page_url) {
diff --git a/content/plugin/npobject_util.h b/content/plugin/npobject_util.h
index cca210d..7e5cb07 100644
--- a/content/plugin/npobject_util.h
+++ b/content/plugin/npobject_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -18,7 +18,7 @@
class GURL;
class NPObjectProxy;
-class PluginChannelBase;
+class NPChannelBase;
struct _NPVariant;
struct NPIdentifier_Param;
@@ -47,7 +47,7 @@ NPIdentifier CreateNPIdentifier(const NPIdentifier_Param& param);
// If release is true, the NPVariant object is released (except if
// it contains an NPObject, since the stub will manage its lifetime).
void CreateNPVariantParam(const NPVariant& variant,
- PluginChannelBase* channel,
+ NPChannelBase* channel,
NPVariant_Param* param,
bool release,
gfx::NativeViewId containing_window,
@@ -56,7 +56,7 @@ void CreateNPVariantParam(const NPVariant& variant,
// Creates an NPVariant from the marshalled object.
// Returns true on success.
bool CreateNPVariant(const NPVariant_Param& param,
- PluginChannelBase* channel,
+ NPChannelBase* channel,
NPVariant* result,
gfx::NativeViewId containing_window,
const GURL& page_url);
diff --git a/content/plugin/plugin_channel.cc b/content/plugin/plugin_channel.cc
index cd2e99f..6d428cf 100644
--- a/content/plugin/plugin_channel.cc
+++ b/content/plugin/plugin_channel.cc
@@ -143,7 +143,7 @@ PluginChannel* PluginChannel::GetPluginChannel(
"%d.r%d", base::GetCurrentProcId(), renderer_id);
PluginChannel* channel =
- static_cast<PluginChannel*>(PluginChannelBase::GetChannel(
+ static_cast<PluginChannel*>(NPChannelBase::GetChannel(
channel_key,
IPC::Channel::MODE_SERVER,
ClassFactory,
@@ -187,7 +187,7 @@ bool PluginChannel::Send(IPC::Message* msg) {
VLOG(1) << "sending message @" << msg << " on channel @" << this
<< " with type " << msg->type();
}
- bool result = PluginChannelBase::Send(msg);
+ bool result = NPChannelBase::Send(msg);
in_send_--;
return result;
}
@@ -197,7 +197,7 @@ bool PluginChannel::OnMessageReceived(const IPC::Message& msg) {
VLOG(1) << "received message @" << &msg << " on channel @" << this
<< " with type " << msg.type();
}
- return PluginChannelBase::OnMessageReceived(msg);
+ return NPChannelBase::OnMessageReceived(msg);
}
bool PluginChannel::OnControlMessageReceived(const IPC::Message& msg) {
@@ -297,13 +297,13 @@ void PluginChannel::OnChannelConnected(int32 peer_pid) {
NOTREACHED();
}
renderer_handle_ = handle;
- PluginChannelBase::OnChannelConnected(peer_pid);
+ NPChannelBase::OnChannelConnected(peer_pid);
}
void PluginChannel::OnChannelError() {
base::CloseProcessHandle(renderer_handle_);
renderer_handle_ = 0;
- PluginChannelBase::OnChannelError();
+ NPChannelBase::OnChannelError();
CleanUp();
}
@@ -325,7 +325,7 @@ void PluginChannel::CleanUp() {
bool PluginChannel::Init(base::MessageLoopProxy* ipc_message_loop,
bool create_pipe_now) {
- if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now))
+ if (!NPChannelBase::Init(ipc_message_loop, create_pipe_now))
return false;
channel_->AddFilter(filter_.get());
diff --git a/content/plugin/plugin_channel.h b/content/plugin/plugin_channel.h
index 6a5bb74..87afb8c 100644
--- a/content/plugin/plugin_channel.h
+++ b/content/plugin/plugin_channel.h
@@ -11,7 +11,7 @@
#include "base/memory/scoped_handle.h"
#include "base/process.h"
#include "build/build_config.h"
-#include "content/plugin/plugin_channel_base.h"
+#include "content/common/np_channel_base.h"
#include "content/plugin/webplugin_delegate_stub.h"
namespace base {
@@ -20,7 +20,7 @@ class WaitableEvent;
// Encapsulates an IPC channel between the plugin process and one renderer
// process. On the renderer side there's a corresponding PluginChannelHost.
-class PluginChannel : public PluginChannelBase {
+class PluginChannel : public NPChannelBase {
public:
// Get a new PluginChannel object for the current process to talk to the
// given renderer process. The renderer ID is an opaque unique ID generated
@@ -63,7 +63,7 @@ class PluginChannel : public PluginChannelBase {
virtual void CleanUp();
- // Overrides PluginChannelBase::Init.
+ // Overrides NPChannelBase::Init.
virtual bool Init(base::MessageLoopProxy* ipc_message_loop,
bool create_pipe_now);
@@ -75,7 +75,7 @@ class PluginChannel : public PluginChannelBase {
virtual bool OnControlMessageReceived(const IPC::Message& msg);
- static PluginChannelBase* ClassFactory() { return new PluginChannel(); }
+ static NPChannelBase* ClassFactory() { return new PluginChannel(); }
void OnCreateInstance(const std::string& mime_type, int* instance_id);
void OnDestroyInstance(int instance_id, IPC::Message* reply_msg);
diff --git a/content/plugin/plugin_channel_base.cc b/content/plugin/plugin_channel_base.cc
deleted file mode 100644
index 7db967a..0000000
--- a/content/plugin/plugin_channel_base.cc
+++ /dev/null
@@ -1,272 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/plugin/plugin_channel_base.h"
-
-#include <stack>
-
-#include "base/auto_reset.h"
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "base/string_number_conversions.h"
-#include "content/common/child_process.h"
-#include "ipc/ipc_sync_message.h"
-
-#if defined(OS_POSIX)
-#include "ipc/ipc_channel_posix.h"
-#endif
-
-typedef base::hash_map<std::string, scoped_refptr<PluginChannelBase> >
- PluginChannelMap;
-
-static PluginChannelMap g_plugin_channels_;
-
-static base::LazyInstance<std::stack<scoped_refptr<PluginChannelBase> > >
- lazy_plugin_channel_stack_(base::LINKER_INITIALIZED);
-
-static int next_pipe_id = 0;
-
-PluginChannelBase* PluginChannelBase::GetChannel(
- const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode,
- PluginChannelFactory factory, base::MessageLoopProxy* ipc_message_loop,
- bool create_pipe_now) {
- scoped_refptr<PluginChannelBase> channel;
- std::string channel_key = channel_handle.name;
- PluginChannelMap::const_iterator iter = g_plugin_channels_.find(channel_key);
- if (iter == g_plugin_channels_.end()) {
- channel = factory();
- } else {
- channel = iter->second;
- }
-
- DCHECK(channel != NULL);
-
- if (!channel->channel_valid()) {
- channel->channel_handle_ = channel_handle;
- if (mode & IPC::Channel::MODE_SERVER_FLAG) {
- channel->channel_handle_.name.append(".");
- channel->channel_handle_.name.append(base::IntToString(next_pipe_id++));
- }
- channel->mode_ = mode;
- if (channel->Init(ipc_message_loop, create_pipe_now)) {
- g_plugin_channels_[channel_key] = channel;
- } else {
- channel = NULL;
- }
- }
-
- return channel;
-}
-
-void PluginChannelBase::Broadcast(IPC::Message* message) {
- for (PluginChannelMap::iterator iter = g_plugin_channels_.begin();
- iter != g_plugin_channels_.end();
- ++iter) {
- iter->second->Send(new IPC::Message(*message));
- }
- delete message;
-}
-
-PluginChannelBase::PluginChannelBase()
- : mode_(IPC::Channel::MODE_NONE),
- plugin_count_(0),
- peer_pid_(0),
- in_remove_route_(false),
- channel_valid_(false),
- in_unblock_dispatch_(0),
- send_unblocking_only_during_unblock_dispatch_(false) {
-}
-
-PluginChannelBase::~PluginChannelBase() {
-}
-
-PluginChannelBase* PluginChannelBase::GetCurrentChannel() {
- return lazy_plugin_channel_stack_.Pointer()->top();
-}
-
-void PluginChannelBase::CleanupChannels() {
- // Make a copy of the references as we can't iterate the map since items will
- // be removed from it as we clean them up.
- std::vector<scoped_refptr<PluginChannelBase> > channels;
- for (PluginChannelMap::const_iterator iter = g_plugin_channels_.begin();
- iter != g_plugin_channels_.end();
- ++iter) {
- channels.push_back(iter->second);
- }
-
- for (size_t i = 0; i < channels.size(); ++i)
- channels[i]->CleanUp();
-
- // This will clean up channels added to the map for which subsequent
- // AddRoute wasn't called
- g_plugin_channels_.clear();
-}
-
-NPObjectBase* PluginChannelBase::GetNPObjectListenerForRoute(int route_id) {
- ListenerMap::iterator iter = npobject_listeners_.find(route_id);
- if (iter == npobject_listeners_.end()) {
- DLOG(WARNING) << "Invalid route id passed in:" << route_id;
- return NULL;
- }
- return iter->second;
-}
-
-bool PluginChannelBase::Init(base::MessageLoopProxy* ipc_message_loop,
- bool create_pipe_now) {
- channel_.reset(new IPC::SyncChannel(
- channel_handle_, mode_, this, ipc_message_loop, create_pipe_now,
- ChildProcess::current()->GetShutDownEvent()));
- channel_valid_ = true;
- return true;
-}
-
-bool PluginChannelBase::Send(IPC::Message* message) {
- if (!channel_.get()) {
- delete message;
- return false;
- }
-
- if (send_unblocking_only_during_unblock_dispatch_ &&
- in_unblock_dispatch_ == 0 &&
- message->is_sync()) {
- message->set_unblock(false);
- }
-
- return channel_->Send(message);
-}
-
-int PluginChannelBase::Count() {
- return static_cast<int>(g_plugin_channels_.size());
-}
-
-bool PluginChannelBase::OnMessageReceived(const IPC::Message& message) {
- // This call might cause us to be deleted, so keep an extra reference to
- // ourself so that we can send the reply and decrement back in_dispatch_.
- lazy_plugin_channel_stack_.Pointer()->push(
- scoped_refptr<PluginChannelBase>(this));
-
- bool handled;
- if (message.should_unblock())
- in_unblock_dispatch_++;
- if (message.routing_id() == MSG_ROUTING_CONTROL) {
- handled = OnControlMessageReceived(message);
- } else {
- handled = router_.RouteMessage(message);
- if (!handled && message.is_sync()) {
- // The listener has gone away, so we must respond or else the caller will
- // hang waiting for a reply.
- IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message);
- reply->set_reply_error();
- Send(reply);
- }
- }
- if (message.should_unblock())
- in_unblock_dispatch_--;
-
- lazy_plugin_channel_stack_.Pointer()->pop();
- return handled;
-}
-
-void PluginChannelBase::OnChannelConnected(int32 peer_pid) {
- peer_pid_ = peer_pid;
-}
-
-void PluginChannelBase::AddRoute(int route_id,
- IPC::Channel::Listener* listener,
- NPObjectBase* npobject) {
- if (npobject) {
- npobject_listeners_[route_id] = npobject;
- } else {
- plugin_count_++;
- }
-
- router_.AddRoute(route_id, listener);
-}
-
-void PluginChannelBase::RemoveRoute(int route_id) {
- router_.RemoveRoute(route_id);
-
- ListenerMap::iterator iter = npobject_listeners_.find(route_id);
- if (iter != npobject_listeners_.end()) {
- // This was an NPObject proxy or stub, it's not involved in the refcounting.
-
- // If this RemoveRoute call from the NPObject is a result of us calling
- // OnChannelError below, don't call erase() here because that'll corrupt
- // the iterator below.
- if (in_remove_route_) {
- iter->second = NULL;
- } else {
- npobject_listeners_.erase(iter);
- }
-
- return;
- }
-
- plugin_count_--;
- DCHECK(plugin_count_ >= 0);
-
- if (!plugin_count_) {
- AutoReset<bool> auto_reset_in_remove_route(&in_remove_route_, true);
- for (ListenerMap::iterator npobj_iter = npobject_listeners_.begin();
- npobj_iter != npobject_listeners_.end(); ++npobj_iter) {
- if (npobj_iter->second) {
- IPC::Channel::Listener* channel_listener =
- npobj_iter->second->GetChannelListener();
- DCHECK(channel_listener != NULL);
- channel_listener->OnChannelError();
- }
- }
-
- for (PluginChannelMap::iterator iter = g_plugin_channels_.begin();
- iter != g_plugin_channels_.end(); ++iter) {
- if (iter->second == this) {
- g_plugin_channels_.erase(iter);
- return;
- }
- }
-
- NOTREACHED();
- }
-}
-
-bool PluginChannelBase::OnControlMessageReceived(const IPC::Message& msg) {
- NOTREACHED() <<
- "should override in subclass if you care about control messages";
- return false;
-}
-
-void PluginChannelBase::OnChannelError() {
- channel_valid_ = false;
-}
-
-NPObject* PluginChannelBase::GetExistingNPObjectProxy(int route_id) {
- ProxyMap::iterator iter = proxy_map_.find(route_id);
- return iter != proxy_map_.end() ? iter->second : NULL;
-}
-
-int PluginChannelBase::GetExistingRouteForNPObjectStub(NPObject* npobject) {
- StubMap::iterator iter = stub_map_.find(npobject);
- return iter != stub_map_.end() ? iter->second : MSG_ROUTING_NONE;
-}
-
-void PluginChannelBase::AddMappingForNPObjectProxy(int route_id,
- NPObject* object) {
- proxy_map_[route_id] = object;
-}
-
-void PluginChannelBase::AddMappingForNPObjectStub(int route_id,
- NPObject* object) {
- DCHECK(object != NULL);
- stub_map_[object] = route_id;
-}
-
-void PluginChannelBase::RemoveMappingForNPObjectStub(int route_id,
- NPObject* object) {
- DCHECK(object != NULL);
- stub_map_.erase(object);
-}
-
-void PluginChannelBase::RemoveMappingForNPObjectProxy(int route_id) {
- proxy_map_.erase(route_id);
-}
diff --git a/content/plugin/plugin_channel_base.h b/content/plugin/plugin_channel_base.h
deleted file mode 100644
index f7f5693..0000000
--- a/content/plugin/plugin_channel_base.h
+++ /dev/null
@@ -1,192 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_
-#define CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_
-#pragma once
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/hash_tables.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
-#include "content/common/message_router.h"
-#include "content/plugin/npobject_base.h"
-#include "ipc/ipc_channel_handle.h"
-#include "ipc/ipc_sync_channel.h"
-#include "ui/gfx/native_widget_types.h"
-
-namespace base {
-class MessageLoopProxy;
-}
-
-#if defined(COMPILER_GCC)
-namespace __gnu_cxx {
-
-template<>
-struct hash<NPObject*> {
- std::size_t operator()(NPObject* const& ptr) const {
- return hash<size_t>()(reinterpret_cast<size_t>(ptr));
- }
-};
-
-} // namespace __gnu_cxx
-#elif defined(COMPILER_MSVC)
-namespace stdext {
-
-template<>
-inline size_t hash_value(NPObject* const& ptr) {
- return hash_value(reinterpret_cast<size_t>(ptr));
-}
-
-} // namespace stdext
-#endif // COMPILER
-
-// Encapsulates an IPC channel between a renderer and a plugin process.
-class PluginChannelBase : public IPC::Channel::Listener,
- public IPC::Message::Sender,
- public base::RefCountedThreadSafe<PluginChannelBase> {
- public:
-
- // WebPlugin[Delegate] call these on construction and destruction to setup
- // the routing and manage lifetime of this object. This is also called by
- // NPObjectProxy and NPObjectStub. However the latter don't control the
- // lifetime of this object (by passing true for npobject) because we don't
- // want a leak of an NPObject in a plugin to keep the channel around longer
- // than necessary.
- void AddRoute(int route_id, IPC::Channel::Listener* listener,
- NPObjectBase* npobject);
- void RemoveRoute(int route_id);
-
-
- void AddMappingForNPObjectProxy(int route_id, NPObject* object);
- void RemoveMappingForNPObjectProxy(int route_id);
-
- void AddMappingForNPObjectStub(int route_id, NPObject* object);
- void RemoveMappingForNPObjectStub(int route_id, NPObject* object);
-
- NPObject* GetExistingNPObjectProxy(int route_id);
- int GetExistingRouteForNPObjectStub(NPObject* npobject);
-
-
- // IPC::Message::Sender implementation:
- virtual bool Send(IPC::Message* msg);
-
- int peer_pid() { return peer_pid_; }
- IPC::ChannelHandle channel_handle() const { return channel_handle_; }
-
- // Returns the number of open plugin channels in this process.
- static int Count();
-
- // Returns a new route id.
- virtual int GenerateRouteID() = 0;
-
- // Returns whether the channel is valid or not. A channel is invalid
- // if it is disconnected due to a channel error.
- bool channel_valid() {
- return channel_valid_;
- }
-
- // Returns the most recent PluginChannelBase to have received a message
- // in this process.
- static PluginChannelBase* GetCurrentChannel();
-
- static void CleanupChannels();
-
- // Returns the NPObjectBase object for the route id passed in.
- // Returns NULL on failure.
- NPObjectBase* GetNPObjectListenerForRoute(int route_id);
-
- protected:
- typedef PluginChannelBase* (*PluginChannelFactory)();
-
- friend class base::RefCountedThreadSafe<PluginChannelBase>;
-
- virtual ~PluginChannelBase();
-
- // Returns a PluginChannelBase derived object for the given channel name.
- // If an existing channel exists returns that object, otherwise creates a
- // new one. Even though on creation the object is refcounted, each caller
- // must still ref count the returned value. When there are no more routes
- // on the channel and its ref count is 0, the object deletes itself.
- static PluginChannelBase* GetChannel(
- const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode,
- PluginChannelFactory factory, base::MessageLoopProxy* ipc_message_loop,
- bool create_pipe_now);
-
- // Sends a message to all instances.
- static void Broadcast(IPC::Message* message);
-
- // Called on the worker thread
- PluginChannelBase();
-
- virtual void CleanUp() { }
-
- // Implemented by derived classes to handle control messages
- virtual bool OnControlMessageReceived(const IPC::Message& msg);
-
- // IPC::Channel::Listener implementation:
- virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
- virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
- virtual void OnChannelError() OVERRIDE;
-
- void set_send_unblocking_only_during_unblock_dispatch() {
- send_unblocking_only_during_unblock_dispatch_ = true;
- }
-
- virtual bool Init(base::MessageLoopProxy* ipc_message_loop,
- bool create_pipe_now);
-
- scoped_ptr<IPC::SyncChannel> channel_;
-
- private:
- IPC::Channel::Mode mode_;
- IPC::ChannelHandle channel_handle_;
- int plugin_count_;
- int peer_pid_;
-
- // true when in the middle of a RemoveRoute call
- bool in_remove_route_;
-
- // Keep track of all the registered NPObjects proxies/stubs so that when the
- // channel is closed we can inform them.
- typedef base::hash_map<int, NPObjectBase*> ListenerMap;
- ListenerMap npobject_listeners_;
-
- typedef base::hash_map<int, NPObject*> ProxyMap;
- ProxyMap proxy_map_;
-
- typedef base::hash_map<NPObject*, int> StubMap;
- StubMap stub_map_;
-
- // Used to implement message routing functionality to WebPlugin[Delegate]
- // objects
- MessageRouter router_;
-
- // A channel is invalid if it is disconnected as a result of a channel
- // error. This flag is used to indicate the same.
- bool channel_valid_;
-
- // Track whether we're dispatching a message with the unblock flag; works like
- // a refcount, 0 when we're not.
- int in_unblock_dispatch_;
-
- // If true, sync messages will only be marked as unblocking if the channel is
- // in the middle of dispatching an unblocking message.
- // The plugin process wants to avoid setting the unblock flag on its sync
- // messages unless necessary, since it can potentially introduce reentrancy
- // into WebKit in ways that it doesn't expect (i.e. causing layout during
- // paint). However to avoid deadlock, we must ensure that any message that's
- // sent as a result of a sync call from the renderer must unblock the
- // renderer. We additionally have to do this for async messages from the
- // renderer that have the unblock flag set, since they could be followed by a
- // sync message that won't get dispatched until the call to the renderer is
- // complete.
- bool send_unblocking_only_during_unblock_dispatch_;
-
- DISALLOW_COPY_AND_ASSIGN(PluginChannelBase);
-};
-
-#endif // CONTENT_PLUGIN_PLUGIN_CHANNEL_BASE_H_
diff --git a/content/plugin/plugin_thread.cc b/content/plugin/plugin_thread.cc
index 75252c6..af66f09 100644
--- a/content/plugin/plugin_thread.cc
+++ b/content/plugin/plugin_thread.cc
@@ -126,7 +126,7 @@ PluginThread::~PluginThread() {
base::UnloadNativeLibrary(preloaded_plugin_module_);
preloaded_plugin_module_ = NULL;
}
- PluginChannelBase::CleanupChannels();
+ NPChannelBase::CleanupChannels();
webkit::npapi::PluginLib::UnloadAllPlugins();
if (webkit_glue::ShouldForcefullyTerminatePluginProcess())