Chromium Code Reviews| Index: content/browser/renderer_host/pepper/pepper_flash_browser_host.cc |
| diff --git a/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc b/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc |
| index ba4f75f6e4946d9e231f1a2112360f9a89639d98..52c3845d1ad7a5e80b30ac4ecce9474a2afa4ea0 100644 |
| --- a/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc |
| +++ b/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc |
| @@ -4,9 +4,16 @@ |
| #include "content/browser/renderer_host/pepper/pepper_flash_browser_host.h" |
| +#include "content/public/browser/browser_context.h" |
| #include "content/public/browser/browser_ppapi_host.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/content_browser_client.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/resource_context.h" |
| +#include "googleurl/src/gurl.h" |
| #include "ipc/ipc_message_macros.h" |
| #include "ppapi/c/pp_errors.h" |
| +#include "ppapi/c/private/ppb_flash.h" |
| #include "ppapi/host/dispatch_host_message.h" |
| #include "ppapi/proxy/ppapi_messages.h" |
| #include "ppapi/proxy/resource_message_params.h" |
| @@ -19,11 +26,29 @@ |
| namespace content { |
| +namespace { |
| + |
| +// Get the ResourceContext on the UI thread for the given render process ID. |
| +ResourceContext* GetResourceContext(int render_process_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + RenderProcessHost* render_process_host = RenderProcessHost::FromID( |
| + render_process_id); |
| + if (render_process_host && render_process_host->GetBrowserContext()) |
| + return render_process_host->GetBrowserContext()->GetResourceContext(); |
| + return NULL; |
| +} |
| + |
| +} // namespace |
| + |
| PepperFlashBrowserHost::PepperFlashBrowserHost( |
| BrowserPpapiHost* host, |
| PP_Instance instance, |
| PP_Resource resource) |
| - : ResourceHost(host->GetPpapiHost(), instance, resource) { |
| + : ResourceHost(host->GetPpapiHost(), instance, resource), |
| + host_(host), |
| + resource_context_(NULL) { |
| + int unused; |
| + host->GetRenderViewIDsForInstance(instance, &render_process_id_, &unused); |
| } |
| PepperFlashBrowserHost::~PepperFlashBrowserHost() { |
| @@ -35,6 +60,9 @@ int32_t PepperFlashBrowserHost::OnResourceMessageReceived( |
| IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) |
| PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, |
| OnMsgUpdateActivity); |
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
| + PpapiHostMsg_Flash_GetLocalDataRestrictions, |
| + OnMsgGetLocalDataRestrictions); |
| IPC_END_MESSAGE_MAP() |
| return PP_ERROR_FAILED; |
| } |
| @@ -57,4 +85,52 @@ int32_t PepperFlashBrowserHost::OnMsgUpdateActivity( |
| return PP_OK; |
| } |
| +int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions( |
| + ppapi::host::HostMessageContext* context) { |
| + // Getting the LocalDataRestrictions needs to be done on the IO thread, |
| + // however it relies on the ResourceContext which can only be accessed from |
| + // the UI thread. We lazily initialize |resource_context_| by grabbing the |
| + // pointer from the UI thread and then call |GetLocalDataRestrictions| with |
| + // it. |
| + GURL document_url = host_->GetDocumentURLForInstance(pp_instance()); |
| + GURL plugin_url = host_->GetPluginURLForInstance(pp_instance()); |
| + if (resource_context_) { |
| + GetLocalDataRestrictions(context->MakeReplyMessageContext(), document_url, |
| + plugin_url, resource_context_); |
| + } else { |
| + BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&GetResourceContext, render_process_id_), |
| + base::Bind(&PepperFlashBrowserHost::GetLocalDataRestrictions, |
| + AsWeakPtr(), context->MakeReplyMessageContext(), |
|
dmichael (off chromium)
2012/12/13 17:39:00
Is this the only place you take advantage of Suppo
raymes
2012/12/14 17:43:53
Done.
|
| + document_url, plugin_url)); |
| + } |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +void PepperFlashBrowserHost::GetLocalDataRestrictions( |
| + ppapi::host::ReplyMessageContext reply_context, |
| + const GURL& document_url, |
| + const GURL& plugin_url, |
| + ResourceContext* resource_context) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + // Note that the resource context lives on the IO thread and is owned by the |
| + // browser profile so its lifetime should outlast ours. |
| + if (!resource_context_) |
| + resource_context_ = resource_context; |
| + |
| + PP_FlashLSORestrictions restrictions = PP_FLASHLSORESTRICTIONS_NONE; |
| + if (resource_context_ && document_url.is_valid() && plugin_url.is_valid()) { |
| + ContentBrowserClient* client = GetContentClient()->browser(); |
| + if (!client->AllowPluginLocalDataAccess(document_url, plugin_url, |
| + resource_context_)) { |
| + restrictions = PP_FLASHLSORESTRICTIONS_BLOCK; |
| + } else if (client->AllowPluginLocalDataSessionOnly(plugin_url, |
| + resource_context_)) { |
| + restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY; |
| + } |
| + } |
| + SendReply(reply_context, PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply( |
| + static_cast<int32_t>(restrictions))); |
| +} |
| + |
| } // namespace content |