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_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ |
6 #define CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ | 6 #define CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/process.h" | 9 #include "base/process.h" |
10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
| 14 #include "content/public/common/process_type.h" |
13 #include "ppapi/c/pp_instance.h" | 15 #include "ppapi/c/pp_instance.h" |
14 | 16 |
15 namespace IPC { | 17 namespace IPC { |
16 class ChannelProxy; | 18 class ChannelProxy; |
17 struct ChannelHandle; | 19 struct ChannelHandle; |
18 class Sender; | 20 class Sender; |
19 } | 21 } |
20 | 22 |
21 namespace net { | 23 namespace net { |
22 class HostResolver; | 24 class HostResolver; |
(...skipping 15 matching lines...) Expand all Loading... |
38 // lives entirely on the I/O thread. | 40 // lives entirely on the I/O thread. |
39 class CONTENT_EXPORT BrowserPpapiHost { | 41 class CONTENT_EXPORT BrowserPpapiHost { |
40 public: | 42 public: |
41 // Creates a browser host and sets up an out-of-process proxy for an external | 43 // Creates a browser host and sets up an out-of-process proxy for an external |
42 // pepper plugin process. | 44 // pepper plugin process. |
43 static BrowserPpapiHost* CreateExternalPluginProcess( | 45 static BrowserPpapiHost* CreateExternalPluginProcess( |
44 IPC::Sender* sender, | 46 IPC::Sender* sender, |
45 ppapi::PpapiPermissions permissions, | 47 ppapi::PpapiPermissions permissions, |
46 base::ProcessHandle plugin_child_process, | 48 base::ProcessHandle plugin_child_process, |
47 int plugin_child_process_id, | 49 int plugin_child_process_id, |
| 50 ProcessType process_type, |
48 IPC::ChannelProxy* channel, | 51 IPC::ChannelProxy* channel, |
49 net::HostResolver* host_resolver, | 52 net::HostResolver* host_resolver, |
50 int render_process_id, | 53 int render_process_id, |
51 int render_view_id); | 54 int render_view_id); |
52 | 55 |
53 virtual ~BrowserPpapiHost() {} | 56 virtual ~BrowserPpapiHost() {} |
54 | 57 |
55 // Returns the PpapiHost object. | 58 // Returns the PpapiHost object. |
56 virtual ppapi::host::PpapiHost* GetPpapiHost() = 0; | 59 virtual ppapi::host::PpapiHost* GetPpapiHost() = 0; |
57 | 60 |
(...skipping 16 matching lines...) Expand all Loading... |
74 int* render_process_id, | 77 int* render_process_id, |
75 int* render_view_id) const = 0; | 78 int* render_view_id) const = 0; |
76 // Returns the name of the plugin. | 79 // Returns the name of the plugin. |
77 virtual const std::string& GetPluginName() = 0; | 80 virtual const std::string& GetPluginName() = 0; |
78 | 81 |
79 // Returns the user's profile data directory. | 82 // Returns the user's profile data directory. |
80 virtual const FilePath& GetProfileDataDirectory() = 0; | 83 virtual const FilePath& GetProfileDataDirectory() = 0; |
81 | 84 |
82 // Returns the unique id of the child plugin process (this is NOT the pid). | 85 // Returns the unique id of the child plugin process (this is NOT the pid). |
83 virtual int GetPluginProcessID() = 0; | 86 virtual int GetPluginProcessID() = 0; |
| 87 |
| 88 // Schedules the given callback to execute on the UI thread of the browser, |
| 89 // passing the RenderViewHost associated with the given instance as a |
| 90 // parameter. |
| 91 // |
| 92 // Normally this would be called from a ResourceHost with the reply using |
| 93 // a weak pointer to itself. |
| 94 // |
| 95 // Importantly, the task will not be run if the RenderView is destroyed by |
| 96 // the time we get to the UI thread, or if the PP_Instance is invalid, but |
| 97 // the reply will still be run. The return type in this case will be a |
| 98 // default-constructed |ReturnType|. |
| 99 // |
| 100 // So you may want to make sure you don't do silly things in the reply |
| 101 // handler if the task on the UI thread is never run and you get a |
| 102 // default-constructed result. |
| 103 template<typename ReturnType> |
| 104 bool PostOnUIThreadWithRenderViewHostAndReply( |
| 105 const tracked_objects::Location& from_here, |
| 106 PP_Instance instance, |
| 107 const base::Callback<ReturnType(RenderViewHost*)>& task, |
| 108 const base::Callback<void(ReturnType)>& reply) const { |
| 109 int render_process_id, render_view_id; |
| 110 bool success = GetRenderViewIDsForInstance(instance, |
| 111 &render_process_id, |
| 112 &render_view_id); |
| 113 if (!success) |
| 114 return false; |
| 115 BrowserThread::PostTaskAndReplyWithResult( |
| 116 BrowserThread::UI, |
| 117 from_here, |
| 118 base::Bind(&CallWithRenderViewHost<ReturnType>, |
| 119 render_process_id, render_view_id, task), |
| 120 reply); |
| 121 return true; |
| 122 } |
| 123 |
| 124 protected: |
| 125 // Backend for PostOnUIThreadWithRenderViewAndReply. This converts the IDs |
| 126 // to a RenderViewHost and calls the function, or returns a |
| 127 // default-constructed return value on error. |
| 128 template<typename ReturnType> |
| 129 static ReturnType CallWithRenderViewHost( |
| 130 int render_process_id, |
| 131 int render_view_id, |
| 132 const base::Callback<ReturnType(RenderViewHost*)>& task) { |
| 133 RenderViewHost* render_view_host = RenderViewHost::FromID(render_process_id, |
| 134 render_view_id); |
| 135 if (render_view_host) |
| 136 return task.Run(render_view_host); |
| 137 return ReturnType(); |
| 138 } |
84 }; | 139 }; |
85 | 140 |
86 } // namespace content | 141 } // namespace content |
87 | 142 |
88 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ | 143 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ |
OLD | NEW |