Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2952)

Unified Diff: content/renderer/pepper/renderer_ppapi_host_impl.cc

Issue 10815073: Refactoring of new IPC-only pepper implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/pepper/renderer_ppapi_host_impl.cc
diff --git a/content/renderer/pepper/renderer_ppapi_host_impl.cc b/content/renderer/pepper/renderer_ppapi_host_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..08161a15c90ad5e3b640a52d4b615f7c7af6ccaf
--- /dev/null
+++ b/content/renderer/pepper/renderer_ppapi_host_impl.cc
@@ -0,0 +1,123 @@
+// Copyright (c) 2012 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/renderer/pepper/renderer_ppapi_host_impl.h"
+
+#include "base/logging.h"
+#include "content/renderer/pepper/pepper_in_process_resource_creation.h"
+#include "content/renderer/pepper/pepper_in_process_router.h"
+#include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
+#include "content/renderer/render_view_impl.h"
+#include "ppapi/proxy/host_dispatcher.h"
+#include "webkit/plugins/ppapi/host_globals.h"
+#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+
+using webkit::ppapi::HostGlobals;
+using webkit::ppapi::PluginInstance;
+
+namespace content {
+
+// Out-of-process constructor.
+RendererPpapiHostImpl::RendererPpapiHostImpl(
+ webkit::ppapi::PluginModule* module,
+ ppapi::proxy::HostDispatcher* dispatcher,
+ const ppapi::PpapiPermissions& permissions)
+ : module_(module),
+ host_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ // Hook the PpapiHost up to the dispatcher for out-of-process communication.
+ ppapi_host_.reset(
+ new ppapi::host::PpapiHost(dispatcher, &host_factory_, permissions));
+ dispatcher->AddFilter(ppapi_host_.get());
+}
+
+// In-process constructor.
+RendererPpapiHostImpl::RendererPpapiHostImpl(
+ webkit::ppapi::PluginModule* module,
+ const ppapi::PpapiPermissions& permissions)
+ : module_(module),
+ host_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ // Hook the host up to the in-process router.
+ in_process_router_.reset(new PepperInProcessRouter(this));
+ ppapi_host_.reset(new ppapi::host::PpapiHost(
+ in_process_router_->GetRendererToPluginSender(),
+ &host_factory_, permissions));
+}
+
+RendererPpapiHostImpl::~RendererPpapiHostImpl() {
+}
+
+// static
+RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForOutOfProcess(
+ webkit::ppapi::PluginModule* module,
+ ppapi::proxy::HostDispatcher* dispatcher,
+ const ppapi::PpapiPermissions& permissions) {
+ DCHECK(!module->GetEmbedderState());
+ RendererPpapiHostImpl* result = new RendererPpapiHostImpl(
+ module, dispatcher, permissions);
+
+ // Takes ownership of pointer.
+ module->SetEmbedderState(
+ scoped_ptr<webkit::ppapi::PluginModule::EmbedderState>(result));
+
+ return result;
+}
+
+// static
+RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForInProcess(
+ webkit::ppapi::PluginModule* module,
+ const ppapi::PpapiPermissions& permissions) {
+ DCHECK(!module->GetEmbedderState());
+ RendererPpapiHostImpl* result = new RendererPpapiHostImpl(
+ module, permissions);
+
+ // Takes ownership of pointer.
+ module->SetEmbedderState(
+ scoped_ptr<webkit::ppapi::PluginModule::EmbedderState>(result));
+
+ return result;
+}
+
+scoped_ptr<::ppapi::thunk::ResourceCreationAPI>
+RendererPpapiHostImpl::CreateInProcessResourceCreationAPI(
+ webkit::ppapi::PluginInstance* instance) {
+ return scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>(
+ new PepperInProcessResourceCreation(this, instance));
+}
+
+ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() {
+ return ppapi_host_.get();
+}
+
+RenderView* RendererPpapiHostImpl::GetRenderViewForInstance(
+ PP_Instance instance) const {
+ PluginInstance* instance_object = GetAndValidateInstance(instance);
+ if (!instance_object)
+ return NULL;
+
+ // Since we're the embedder, we can make assumptions about the delegate on
+ // the instance and get back to our RenderView.
+ return static_cast<PepperPluginDelegateImpl*>(
+ instance_object->delegate())->render_view();
+}
+
+bool RendererPpapiHostImpl::IsValidInstance(
+ PP_Instance instance) const {
+ return !!GetAndValidateInstance(instance);
+}
+
+bool RendererPpapiHostImpl::HasUserGesture(PP_Instance instance) const {
+ return !!GetAndValidateInstance(instance);
raymes 2012/07/25 16:53:22 Looks like you forgot to implement this properly?
brettw 2012/07/30 05:46:37 Whoops! Copied from the old implementation.
+}
+
+PluginInstance* RendererPpapiHostImpl::GetAndValidateInstance(
+ PP_Instance pp_instance) const {
+ PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
+ if (!instance)
+ return NULL;
+ if (instance->module() != module_)
+ return NULL;
+ return instance;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698