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 #include "content/browser/renderer_host/pepper/pepper_flash_browser_host.h" | 5 #include "content/browser/renderer_host/pepper/pepper_flash_browser_host.h" |
| 6 | 6 |
| 7 #include "content/public/browser/browser_context.h" | |
| 7 #include "content/public/browser/browser_ppapi_host.h" | 8 #include "content/public/browser/browser_ppapi_host.h" |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/content_browser_client.h" | |
| 11 #include "content/public/browser/render_process_host.h" | |
| 12 #include "content/public/browser/resource_context.h" | |
| 13 #include "googleurl/src/gurl.h" | |
| 8 #include "ipc/ipc_message_macros.h" | 14 #include "ipc/ipc_message_macros.h" |
| 9 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
| 16 #include "ppapi/c/private/ppb_flash.h" | |
| 10 #include "ppapi/host/dispatch_host_message.h" | 17 #include "ppapi/host/dispatch_host_message.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" | 18 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/proxy/resource_message_params.h" | 19 #include "ppapi/proxy/resource_message_params.h" |
| 13 | 20 |
| 14 #ifdef OS_WIN | 21 #ifdef OS_WIN |
| 15 #include <windows.h> | 22 #include <windows.h> |
| 16 #elif defined(OS_MACOSX) | 23 #elif defined(OS_MACOSX) |
| 17 #include <CoreServices/CoreServices.h> | 24 #include <CoreServices/CoreServices.h> |
| 18 #endif | 25 #endif |
| 19 | 26 |
| 20 namespace content { | 27 namespace content { |
| 21 | 28 |
| 29 namespace { | |
| 30 | |
| 31 // Get the ResourceContext on the UI thread for the given render process ID. | |
| 32 ResourceContext* GetResourceContext(int render_process_id) { | |
| 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 34 RenderProcessHost* render_process_host = RenderProcessHost::FromID( | |
| 35 render_process_id); | |
| 36 if (render_process_host && render_process_host->GetBrowserContext()) | |
| 37 return render_process_host->GetBrowserContext()->GetResourceContext(); | |
| 38 return NULL; | |
| 39 } | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 22 PepperFlashBrowserHost::PepperFlashBrowserHost( | 43 PepperFlashBrowserHost::PepperFlashBrowserHost( |
| 23 BrowserPpapiHost* host, | 44 BrowserPpapiHost* host, |
| 24 PP_Instance instance, | 45 PP_Instance instance, |
| 25 PP_Resource resource) | 46 PP_Resource resource) |
| 26 : ResourceHost(host->GetPpapiHost(), instance, resource) { | 47 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 48 host_(host), | |
| 49 resource_context_(NULL) { | |
| 50 int unused; | |
| 51 host->GetRenderViewIDsForInstance(instance, &render_process_id_, &unused); | |
| 27 } | 52 } |
| 28 | 53 |
| 29 PepperFlashBrowserHost::~PepperFlashBrowserHost() { | 54 PepperFlashBrowserHost::~PepperFlashBrowserHost() { |
| 30 } | 55 } |
| 31 | 56 |
| 32 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( | 57 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( |
| 33 const IPC::Message& msg, | 58 const IPC::Message& msg, |
| 34 ppapi::host::HostMessageContext* context) { | 59 ppapi::host::HostMessageContext* context) { |
| 35 IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) | 60 IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) |
| 36 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, | 61 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, |
| 37 OnMsgUpdateActivity); | 62 OnMsgUpdateActivity); |
| 63 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | |
| 64 PpapiHostMsg_Flash_GetLocalDataRestrictions, | |
| 65 OnMsgGetLocalDataRestrictions); | |
| 38 IPC_END_MESSAGE_MAP() | 66 IPC_END_MESSAGE_MAP() |
| 39 return PP_ERROR_FAILED; | 67 return PP_ERROR_FAILED; |
| 40 } | 68 } |
| 41 | 69 |
| 42 int32_t PepperFlashBrowserHost::OnMsgUpdateActivity( | 70 int32_t PepperFlashBrowserHost::OnMsgUpdateActivity( |
| 43 ppapi::host::HostMessageContext* host_context) { | 71 ppapi::host::HostMessageContext* host_context) { |
| 44 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
| 45 // Reading then writing back the same value to the screensaver timeout system | 73 // Reading then writing back the same value to the screensaver timeout system |
| 46 // setting resets the countdown which prevents the screensaver from turning | 74 // setting resets the countdown which prevents the screensaver from turning |
| 47 // on "for a while". As long as the plugin pings us with this message faster | 75 // on "for a while". As long as the plugin pings us with this message faster |
| 48 // than the screensaver timeout, it won't go on. | 76 // than the screensaver timeout, it won't go on. |
| 49 int value = 0; | 77 int value = 0; |
| 50 if (SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &value, 0)) | 78 if (SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &value, 0)) |
| 51 SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, value, NULL, 0); | 79 SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, value, NULL, 0); |
| 52 #elif defined(OS_MACOSX) | 80 #elif defined(OS_MACOSX) |
| 53 UpdateSystemActivity(OverallAct); | 81 UpdateSystemActivity(OverallAct); |
| 54 #else | 82 #else |
| 55 // TODO(brettw) implement this for other platforms. | 83 // TODO(brettw) implement this for other platforms. |
| 56 #endif | 84 #endif |
| 57 return PP_OK; | 85 return PP_OK; |
| 58 } | 86 } |
| 59 | 87 |
| 88 int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions( | |
| 89 ppapi::host::HostMessageContext* context) { | |
| 90 // Getting the LocalDataRestrictions needs to be done on the IO thread, | |
| 91 // however it relies on the ResourceContext which can only be accessed from | |
| 92 // the UI thread. We lazily initialize |resource_context_| by grabbing the | |
| 93 // pointer from the UI thread and then call |GetLocalDataRestrictions| with | |
| 94 // it. | |
| 95 GURL document_url = host_->GetDocumentURLForInstance(pp_instance()); | |
| 96 GURL plugin_url = host_->GetPluginURLForInstance(pp_instance()); | |
| 97 if (resource_context_) { | |
| 98 GetLocalDataRestrictions(context->MakeReplyMessageContext(), document_url, | |
| 99 plugin_url, resource_context_); | |
| 100 } else { | |
| 101 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE, | |
| 102 base::Bind(&GetResourceContext, render_process_id_), | |
| 103 base::Bind(&PepperFlashBrowserHost::GetLocalDataRestrictions, | |
| 104 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.
| |
| 105 document_url, plugin_url)); | |
| 106 } | |
| 107 return PP_OK_COMPLETIONPENDING; | |
| 108 } | |
| 109 | |
| 110 void PepperFlashBrowserHost::GetLocalDataRestrictions( | |
| 111 ppapi::host::ReplyMessageContext reply_context, | |
| 112 const GURL& document_url, | |
| 113 const GURL& plugin_url, | |
| 114 ResourceContext* resource_context) { | |
| 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 116 // Note that the resource context lives on the IO thread and is owned by the | |
| 117 // browser profile so its lifetime should outlast ours. | |
| 118 if (!resource_context_) | |
| 119 resource_context_ = resource_context; | |
| 120 | |
| 121 PP_FlashLSORestrictions restrictions = PP_FLASHLSORESTRICTIONS_NONE; | |
| 122 if (resource_context_ && document_url.is_valid() && plugin_url.is_valid()) { | |
| 123 ContentBrowserClient* client = GetContentClient()->browser(); | |
| 124 if (!client->AllowPluginLocalDataAccess(document_url, plugin_url, | |
| 125 resource_context_)) { | |
| 126 restrictions = PP_FLASHLSORESTRICTIONS_BLOCK; | |
| 127 } else if (client->AllowPluginLocalDataSessionOnly(plugin_url, | |
| 128 resource_context_)) { | |
| 129 restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY; | |
| 130 } | |
| 131 } | |
| 132 SendReply(reply_context, PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply( | |
| 133 static_cast<int32_t>(restrictions))); | |
| 134 } | |
| 135 | |
| 60 } // namespace content | 136 } // namespace content |
| OLD | NEW |