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

Side by Side Diff: content/browser/renderer_host/pepper/browser_ppapi_host_impl.h

Issue 11368019: Add support for external out-of-process PPAPI plugins in the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_facto ry.h" 12 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_facto ry.h"
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "content/public/browser/browser_ppapi_host.h" 14 #include "content/public/browser/browser_ppapi_host.h"
15 #include "ipc/ipc_channel_proxy.h" 15 #include "ipc/ipc_channel_proxy.h"
16 #include "ppapi/host/ppapi_host.h" 16 #include "ppapi/host/ppapi_host.h"
17 17
18 namespace IPC {
19 class Sender;
20 }
21
22 namespace content { 18 namespace content {
23 19
24 class CONTENT_EXPORT BrowserPpapiHostImpl 20 class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost {
25 : public BrowserPpapiHost,
26 public IPC::ChannelProxy::MessageFilter {
27 public: 21 public:
28 // The creator is responsible for calling set_plugin_process_handle as soon 22 // The creator is responsible for calling set_plugin_process_handle as soon
29 // as it is known (we start the process asynchronously so it won't be known 23 // as it is known (we start the process asynchronously so it won't be known
30 // when this object is created). 24 // when this object is created).
31 BrowserPpapiHostImpl(IPC::Sender* sender, 25 BrowserPpapiHostImpl(IPC::Sender* sender,
32 const ppapi::PpapiPermissions& permissions); 26 const ppapi::PpapiPermissions& permissions);
33 27 virtual ~BrowserPpapiHostImpl();
34 // IPC::ChannelProxy::MessageFilter.
35 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
36 28
37 // BrowserPpapiHost. 29 // BrowserPpapiHost.
38 virtual ppapi::host::PpapiHost* GetPpapiHost() OVERRIDE; 30 virtual ppapi::host::PpapiHost* GetPpapiHost() OVERRIDE;
39 virtual base::ProcessHandle GetPluginProcessHandle() const OVERRIDE; 31 virtual base::ProcessHandle GetPluginProcessHandle() const OVERRIDE;
40 virtual bool IsValidInstance(PP_Instance instance) const OVERRIDE; 32 virtual bool IsValidInstance(PP_Instance instance) const OVERRIDE;
41 virtual bool GetRenderViewIDsForInstance(PP_Instance instance, 33 virtual bool GetRenderViewIDsForInstance(PP_Instance instance,
42 int* render_process_id, 34 int* render_process_id,
43 int* render_view_id) const OVERRIDE; 35 int* render_view_id) const OVERRIDE;
44 36
45 void set_plugin_process_handle(base::ProcessHandle handle) { 37 void set_plugin_process_handle(base::ProcessHandle handle) {
46 plugin_process_handle_ = handle; 38 plugin_process_handle_ = handle;
47 } 39 }
48 40
49 // These two functions are notifications that an instance has been created 41 // These two functions are notifications that an instance has been created
50 // or destroyed. They allow us to maintain a mapping of PP_Instance to view 42 // or destroyed. They allow us to maintain a mapping of PP_Instance to view
51 // IDs in the browser process. 43 // IDs in the browser process.
52 void AddInstanceForView(PP_Instance instance, 44 void AddInstanceForView(PP_Instance instance,
53 int render_process_id, 45 int render_process_id,
54 int render_view_id); 46 int render_view_id);
55 void DeleteInstanceForView(PP_Instance instance); 47 void DeleteInstanceForView(PP_Instance instance);
56 48
49 scoped_refptr<IPC::ChannelProxy::MessageFilter> message_filter() {
50 return message_filter_;
51 }
52
57 private: 53 private:
58 friend class BrowserPpapiHostTest; 54 friend class BrowserPpapiHostTest;
59 55
60 struct RenderViewIDs { 56 struct RenderViewIDs {
61 int process_id; 57 int process_id;
62 int view_id; 58 int view_id;
63 }; 59 };
64 typedef std::map<PP_Instance, RenderViewIDs> InstanceToViewMap; 60 typedef std::map<PP_Instance, RenderViewIDs> InstanceToViewMap;
65 61
66 virtual ~BrowserPpapiHostImpl(); 62 // Implementing MessageFilter on BrowserPpapiHostImpl makes it ref-counted,
63 // preventing us from returning these to embedders without holding a
64 // reference. To avoid that, define a message filter object.
65 class HostMessageFilter : public IPC::ChannelProxy::MessageFilter {
66 public:
67 explicit HostMessageFilter(ppapi::host::PpapiHost* ppapi_host)
68 : ppapi_host_(ppapi_host) {}
69 // IPC::ChannelProxy::MessageFilter.
70 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
71
72 private:
73 virtual ~HostMessageFilter() {}
74
75 ppapi::host::PpapiHost* ppapi_host_;
brettw 2012/11/07 00:18:11 You should have a way for this back pointer to be
bbudge 2012/11/07 00:51:46 Good catch. Done.
76 };
67 77
68 ppapi::host::PpapiHost ppapi_host_; 78 ppapi::host::PpapiHost ppapi_host_;
69 base::ProcessHandle plugin_process_handle_; 79 base::ProcessHandle plugin_process_handle_;
70 80
71 // Tracks all PP_Instances in this plugin and maps them to 81 // Tracks all PP_Instances in this plugin and maps them to
72 // RenderProcess/RenderView IDs. 82 // RenderProcess/RenderView IDs.
73 InstanceToViewMap instance_to_view_; 83 InstanceToViewMap instance_to_view_;
74 84
85 scoped_refptr<HostMessageFilter> message_filter_;
86
75 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl); 87 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl);
76 }; 88 };
77 89
78 } // namespace content 90 } // namespace content
79 91
80 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ 92 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698