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/process.h" | 9 #include "base/process.h" |
| 9 #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_view_host.h" | |
| 13 #include "ppapi/c/pp_instance.h" | |
| 10 | 14 |
| 11 namespace ppapi { | 15 namespace ppapi { |
| 12 namespace host { | 16 namespace host { |
| 13 class PpapiHost; | 17 class PpapiHost; |
| 14 } | 18 } |
| 15 } | 19 } |
| 16 | 20 |
| 17 namespace content { | 21 namespace content { |
| 18 | 22 |
| 19 // Interface that allows components in the embedder app to talk to the | 23 // Interface that allows components in the embedder app to talk to the |
| 20 // PpapiHost in the browser process. | 24 // PpapiHost in the browser process. |
| 21 // | 25 // |
| 22 // There will be one of these objects in the browser per plugin process. It | 26 // There will be one of these objects in the browser per plugin process. It |
| 23 // lives entirely on the I/O thread. | 27 // lives entirely on the I/O thread. |
| 24 class CONTENT_EXPORT BrowserPpapiHost { | 28 class CONTENT_EXPORT BrowserPpapiHost { |
| 25 public: | 29 public: |
| 30 struct RenderViewIDs { | |
|
jam
2012/09/10 16:22:21
nit: we've avoied a struct for these two so far af
brettw
2012/09/11 20:25:20
I insert these into a map. I can use a pair but th
| |
| 31 int process_id; | |
| 32 int view_id; | |
| 33 }; | |
| 34 | |
| 26 // Returns the PpapiHost object. | 35 // Returns the PpapiHost object. |
| 27 virtual ppapi::host::PpapiHost* GetPpapiHost() = 0; | 36 virtual ppapi::host::PpapiHost* GetPpapiHost() = 0; |
| 28 | 37 |
| 29 // Returns the handle to the plugin process. | 38 // Returns the handle to the plugin process. |
| 30 virtual base::ProcessHandle GetPluginProcessHandle() const = 0; | 39 virtual base::ProcessHandle GetPluginProcessHandle() const = 0; |
| 31 | 40 |
| 41 // Returns true if the given PP_Instance is valid. | |
| 42 virtual bool IsValidInstance(PP_Instance instance) const = 0; | |
| 43 | |
| 44 // Returns the process/view Ids associated with the RenderView containing the | |
| 45 // given instance. If the instance is invalid, the ids will be 0. | |
| 46 // | |
| 47 // The PP_Instance should be already validated by the host before creating | |
|
yzshen1
2012/09/11 00:53:17
I don't understand this comment. Is it out-dated o
brettw
2012/09/11 20:25:20
I clarified this a bit. I just didn't want everybo
| |
| 48 // any resources with the PP_Instance, so you should not generally need to | |
| 49 // check for errors. | |
| 50 virtual RenderViewIDs GetRenderViewIDsForInstance( | |
| 51 PP_Instance instance) const = 0; | |
| 52 | |
| 53 // Schedules the given callback to execute on the UI thread of the browser, | |
| 54 // passing the RenderView associated with the given instance as a parameter. | |
| 55 // | |
| 56 // Normally this would be called from a ResourceHost with the reply using | |
| 57 // a weak pointer to itself. | |
| 58 // | |
| 59 // Importantly, the task will not be run if the RenderView is destroyed by | |
| 60 // the time we get to the UI thread, or if the PP_Instance is invalid, but | |
| 61 // the reply will still be run. The return type in this case will be a | |
| 62 // default-constructed |ReturnType|. | |
| 63 // | |
| 64 // So you may want to make sure you don't do silly things in the reply | |
| 65 // handler if the task on the UI thread is never run and you get a | |
| 66 // default-constructed result. | |
| 67 template<typename ReturnType> | |
| 68 void PostOnUIThreadWithRenderViewAndReply( | |
|
yzshen1
2012/09/11 00:53:17
This method is not used in this CL. Is it obsolete
brettw
2012/09/11 20:25:20
Yeah, I removed this and stashed it for when we ne
| |
| 69 const tracked_objects::Location& from_here, | |
| 70 PP_Instance instance, | |
| 71 const base::Callback<ReturnType(RenderViewHost*)>& task, | |
| 72 const base::Callback<void(ReturnType)>& reply) const { | |
| 73 BrowserThread::PostTaskAndReplyWithResult( | |
| 74 BrowserThread::UI, | |
| 75 from_here, | |
| 76 base::Bind(&CallWithRenderViewHost, | |
| 77 GetRenderViewIDsForInstance(instance), task), | |
| 78 reply); | |
| 79 } | |
| 80 | |
| 32 protected: | 81 protected: |
| 33 virtual ~BrowserPpapiHost() {} | 82 virtual ~BrowserPpapiHost() {} |
| 83 | |
| 84 // Backend for PostOnUIThreadWithRenderViewAndReply. This converts the IDs | |
| 85 // to a RenderViewHost and calls the function, or returns a | |
| 86 // default-constructed return value on error. | |
| 87 template<typename ReturnType> | |
| 88 static ReturnType CallWithRenderViewHost( | |
| 89 const RenderViewIDs& ids, | |
| 90 const base::Callback<ReturnType(RenderViewHost*)>& task) { | |
| 91 RenderViewHost* render_view_host = | |
| 92 RenderViewHost::FromID(ids.process_id, ids.view_id); | |
| 93 if (render_view_host) | |
| 94 return task.Run(render_view_host); | |
| 95 return ReturnType(); | |
| 96 } | |
| 34 }; | 97 }; |
| 35 | 98 |
| 36 } // namespace content | 99 } // namespace content |
| 37 | 100 |
| 38 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ | 101 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_ |
| OLD | NEW |