OLD | NEW |
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 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_facto
ry.h" | 14 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_facto
ry.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
16 #include "content/public/browser/browser_ppapi_host.h" | 16 #include "content/public/browser/browser_ppapi_host.h" |
17 #include "ipc/ipc_channel_proxy.h" | 17 #include "ipc/ipc_channel_proxy.h" |
18 #include "ppapi/host/ppapi_host.h" | 18 #include "ppapi/host/ppapi_host.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
| 22 struct PepperRendererInstanceData; |
| 23 |
22 class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost { | 24 class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost { |
23 public: | 25 public: |
24 // The creator is responsible for calling set_plugin_process_handle as soon | 26 // The creator is responsible for calling set_plugin_process_handle as soon |
25 // as it is known (we start the process asynchronously so it won't be known | 27 // as it is known (we start the process asynchronously so it won't be known |
26 // when this object is created). | 28 // when this object is created). |
27 BrowserPpapiHostImpl(IPC::Sender* sender, | 29 BrowserPpapiHostImpl(IPC::Sender* sender, |
28 const ppapi::PpapiPermissions& permissions, | 30 const ppapi::PpapiPermissions& permissions, |
29 const std::string& plugin_name, | 31 const std::string& plugin_name, |
30 const FilePath& profile_data_directory); | 32 const FilePath& profile_data_directory); |
31 virtual ~BrowserPpapiHostImpl(); | 33 virtual ~BrowserPpapiHostImpl(); |
32 | 34 |
33 // BrowserPpapiHost. | 35 // BrowserPpapiHost. |
34 virtual ppapi::host::PpapiHost* GetPpapiHost() OVERRIDE; | 36 virtual ppapi::host::PpapiHost* GetPpapiHost() OVERRIDE; |
35 virtual base::ProcessHandle GetPluginProcessHandle() const OVERRIDE; | 37 virtual base::ProcessHandle GetPluginProcessHandle() const OVERRIDE; |
36 virtual bool IsValidInstance(PP_Instance instance) const OVERRIDE; | 38 virtual bool IsValidInstance(PP_Instance instance) const OVERRIDE; |
37 virtual bool GetRenderViewIDsForInstance(PP_Instance instance, | 39 virtual bool GetRenderViewIDsForInstance(PP_Instance instance, |
38 int* render_process_id, | 40 int* render_process_id, |
39 int* render_view_id) const OVERRIDE; | 41 int* render_view_id) const OVERRIDE; |
40 virtual const std::string& GetPluginName() OVERRIDE; | 42 virtual const std::string& GetPluginName() OVERRIDE; |
41 virtual const FilePath& GetProfileDataDirectory() OVERRIDE; | 43 virtual const FilePath& GetProfileDataDirectory() OVERRIDE; |
| 44 virtual GURL GetDocumentURLForInstance(PP_Instance instance) OVERRIDE; |
| 45 virtual GURL GetPluginURLForInstance(PP_Instance instance) OVERRIDE; |
42 | 46 |
43 void set_plugin_process_handle(base::ProcessHandle handle) { | 47 void set_plugin_process_handle(base::ProcessHandle handle) { |
44 plugin_process_handle_ = handle; | 48 plugin_process_handle_ = handle; |
45 } | 49 } |
46 | 50 |
47 // These two functions are notifications that an instance has been created | 51 // These two functions are notifications that an instance has been created |
48 // or destroyed. They allow us to maintain a mapping of PP_Instance to view | 52 // or destroyed. They allow us to maintain a mapping of PP_Instance to data |
49 // IDs in the browser process. | 53 // associated with the instance including view IDs in the browser process. |
50 void AddInstanceForView(PP_Instance instance, | 54 void AddInstance(PP_Instance instance, |
51 int render_process_id, | 55 const PepperRendererInstanceData& instance_data); |
52 int render_view_id); | 56 void DeleteInstance(PP_Instance instance); |
53 void DeleteInstanceForView(PP_Instance instance); | |
54 | 57 |
55 scoped_refptr<IPC::ChannelProxy::MessageFilter> message_filter() { | 58 scoped_refptr<IPC::ChannelProxy::MessageFilter> message_filter() { |
56 return message_filter_; | 59 return message_filter_; |
57 } | 60 } |
58 | 61 |
59 private: | 62 private: |
60 friend class BrowserPpapiHostTest; | 63 friend class BrowserPpapiHostTest; |
61 | 64 |
62 struct RenderViewIDs { | |
63 int process_id; | |
64 int view_id; | |
65 }; | |
66 typedef std::map<PP_Instance, RenderViewIDs> InstanceToViewMap; | |
67 | |
68 // Implementing MessageFilter on BrowserPpapiHostImpl makes it ref-counted, | 65 // Implementing MessageFilter on BrowserPpapiHostImpl makes it ref-counted, |
69 // preventing us from returning these to embedders without holding a | 66 // preventing us from returning these to embedders without holding a |
70 // reference. To avoid that, define a message filter object. | 67 // reference. To avoid that, define a message filter object. |
71 class HostMessageFilter : public IPC::ChannelProxy::MessageFilter { | 68 class HostMessageFilter : public IPC::ChannelProxy::MessageFilter { |
72 public: | 69 public: |
73 explicit HostMessageFilter(ppapi::host::PpapiHost* ppapi_host) | 70 explicit HostMessageFilter(ppapi::host::PpapiHost* ppapi_host) |
74 : ppapi_host_(ppapi_host) {} | 71 : ppapi_host_(ppapi_host) {} |
75 // IPC::ChannelProxy::MessageFilter. | 72 // IPC::ChannelProxy::MessageFilter. |
76 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 73 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
77 | 74 |
78 void OnHostDestroyed(); | 75 void OnHostDestroyed(); |
79 | 76 |
80 private: | 77 private: |
81 virtual ~HostMessageFilter() {} | 78 virtual ~HostMessageFilter() {} |
82 | 79 |
83 ppapi::host::PpapiHost* ppapi_host_; | 80 ppapi::host::PpapiHost* ppapi_host_; |
84 }; | 81 }; |
85 | 82 |
86 ppapi::host::PpapiHost ppapi_host_; | 83 ppapi::host::PpapiHost ppapi_host_; |
87 base::ProcessHandle plugin_process_handle_; | 84 base::ProcessHandle plugin_process_handle_; |
88 std::string plugin_name_; | 85 std::string plugin_name_; |
89 FilePath profile_data_directory_; | 86 FilePath profile_data_directory_; |
90 | 87 |
91 // Tracks all PP_Instances in this plugin and maps them to | 88 // Tracks all PP_Instances in this plugin and associated renderer-related |
92 // RenderProcess/RenderView IDs. | 89 // data. |
93 InstanceToViewMap instance_to_view_; | 90 typedef std::map<PP_Instance, PepperRendererInstanceData> InstanceMap; |
| 91 InstanceMap instance_map_; |
94 | 92 |
95 scoped_refptr<HostMessageFilter> message_filter_; | 93 scoped_refptr<HostMessageFilter> message_filter_; |
96 | 94 |
97 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl); | 95 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl); |
98 }; | 96 }; |
99 | 97 |
100 } // namespace content | 98 } // namespace content |
101 | 99 |
102 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ | 100 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ |
OLD | NEW |