Chromium Code Reviews| 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" | |
| 12 #include "content/public/browser/render_process_host.h" | |
| 11 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
| 12 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.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 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 77 |
| 76 // Returns the name of the plugin. | 78 // Returns the name of the plugin. |
| 77 virtual const std::string& GetPluginName() = 0; | 79 virtual const std::string& GetPluginName() = 0; |
| 78 | 80 |
| 79 // Returns the user's profile data directory. | 81 // Returns the user's profile data directory. |
| 80 virtual const FilePath& GetProfileDataDirectory() = 0; | 82 virtual const FilePath& GetProfileDataDirectory() = 0; |
| 81 | 83 |
| 82 // Get the Document/Plugin URLs for the given PP_Instance. | 84 // Get the Document/Plugin URLs for the given PP_Instance. |
| 83 virtual GURL GetDocumentURLForInstance(PP_Instance instance) = 0; | 85 virtual GURL GetDocumentURLForInstance(PP_Instance instance) = 0; |
| 84 virtual GURL GetPluginURLForInstance(PP_Instance instance) = 0; | 86 virtual GURL GetPluginURLForInstance(PP_Instance instance) = 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( | |
|
dmichael (off chromium)
2013/01/10 17:30:47
This is cool, but I think it probably doesn't belo
ygorshenin1
2013/01/11 11:42:45
OK, I'll move these methods to pepper_socket_utils
| |
| 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 } | |
| 85 }; | 139 }; |
| 86 | 140 |
| 87 } // namespace content | 141 } // namespace content |
| 88 | 142 |
| 89 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ | 143 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ |
| OLD | NEW |