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 "base/time.h" | 7 #include "base/time.h" |
| 8 #include "content/public/browser/browser_context.h" |
8 #include "content/public/browser/browser_ppapi_host.h" | 9 #include "content/public/browser/browser_ppapi_host.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/content_browser_client.h" |
| 12 #include "content/public/browser/render_process_host.h" |
| 13 #include "content/public/browser/resource_context.h" |
| 14 #include "googleurl/src/gurl.h" |
9 #include "ipc/ipc_message_macros.h" | 15 #include "ipc/ipc_message_macros.h" |
10 #include "ppapi/c/pp_errors.h" | 16 #include "ppapi/c/pp_errors.h" |
| 17 #include "ppapi/c/private/ppb_flash.h" |
11 #include "ppapi/host/dispatch_host_message.h" | 18 #include "ppapi/host/dispatch_host_message.h" |
12 #include "ppapi/proxy/ppapi_messages.h" | 19 #include "ppapi/proxy/ppapi_messages.h" |
13 #include "ppapi/proxy/resource_message_params.h" | 20 #include "ppapi/proxy/resource_message_params.h" |
14 #include "ppapi/shared_impl/time_conversion.h" | 21 #include "ppapi/shared_impl/time_conversion.h" |
15 | 22 |
16 #ifdef OS_WIN | 23 #ifdef OS_WIN |
17 #include <windows.h> | 24 #include <windows.h> |
18 #elif defined(OS_MACOSX) | 25 #elif defined(OS_MACOSX) |
19 #include <CoreServices/CoreServices.h> | 26 #include <CoreServices/CoreServices.h> |
20 #endif | 27 #endif |
21 | 28 |
22 namespace content { | 29 namespace content { |
23 | 30 |
| 31 namespace { |
| 32 |
| 33 // Get the ResourceContext on the UI thread for the given render process ID. |
| 34 ResourceContext* GetResourceContext(int render_process_id) { |
| 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 36 RenderProcessHost* render_process_host = RenderProcessHost::FromID( |
| 37 render_process_id); |
| 38 if (render_process_host && render_process_host->GetBrowserContext()) |
| 39 return render_process_host->GetBrowserContext()->GetResourceContext(); |
| 40 return NULL; |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
24 PepperFlashBrowserHost::PepperFlashBrowserHost( | 45 PepperFlashBrowserHost::PepperFlashBrowserHost( |
25 BrowserPpapiHost* host, | 46 BrowserPpapiHost* host, |
26 PP_Instance instance, | 47 PP_Instance instance, |
27 PP_Resource resource) | 48 PP_Resource resource) |
28 : ResourceHost(host->GetPpapiHost(), instance, resource) { | 49 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 50 host_(host), |
| 51 resource_context_(NULL), |
| 52 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 53 int unused; |
| 54 host->GetRenderViewIDsForInstance(instance, &render_process_id_, &unused); |
29 } | 55 } |
30 | 56 |
31 PepperFlashBrowserHost::~PepperFlashBrowserHost() { | 57 PepperFlashBrowserHost::~PepperFlashBrowserHost() { |
32 } | 58 } |
33 | 59 |
34 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( | 60 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( |
35 const IPC::Message& msg, | 61 const IPC::Message& msg, |
36 ppapi::host::HostMessageContext* context) { | 62 ppapi::host::HostMessageContext* context) { |
37 IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) | 63 IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) |
38 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, | 64 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, |
39 OnMsgUpdateActivity); | 65 OnMsgUpdateActivity); |
40 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset, | 66 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset, |
41 OnMsgGetLocalTimeZoneOffset); | 67 OnMsgGetLocalTimeZoneOffset); |
| 68 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
| 69 PpapiHostMsg_Flash_GetLocalDataRestrictions, |
| 70 OnMsgGetLocalDataRestrictions); |
42 IPC_END_MESSAGE_MAP() | 71 IPC_END_MESSAGE_MAP() |
43 return PP_ERROR_FAILED; | 72 return PP_ERROR_FAILED; |
44 } | 73 } |
45 | 74 |
46 int32_t PepperFlashBrowserHost::OnMsgUpdateActivity( | 75 int32_t PepperFlashBrowserHost::OnMsgUpdateActivity( |
47 ppapi::host::HostMessageContext* host_context) { | 76 ppapi::host::HostMessageContext* host_context) { |
48 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
49 // Reading then writing back the same value to the screensaver timeout system | 78 // Reading then writing back the same value to the screensaver timeout system |
50 // setting resets the countdown which prevents the screensaver from turning | 79 // setting resets the countdown which prevents the screensaver from turning |
51 // on "for a while". As long as the plugin pings us with this message faster | 80 // on "for a while". As long as the plugin pings us with this message faster |
(...skipping 13 matching lines...) Expand all Loading... |
65 ppapi::host::HostMessageContext* host_context, | 94 ppapi::host::HostMessageContext* host_context, |
66 const base::Time& t) { | 95 const base::Time& t) { |
67 // The reason for this processing being in the browser process is that on | 96 // The reason for this processing being in the browser process is that on |
68 // Linux, the localtime calls require filesystem access prohibited by the | 97 // Linux, the localtime calls require filesystem access prohibited by the |
69 // sandbox. | 98 // sandbox. |
70 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( | 99 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( |
71 ppapi::PPGetLocalTimeZoneOffset(t)); | 100 ppapi::PPGetLocalTimeZoneOffset(t)); |
72 return PP_OK; | 101 return PP_OK; |
73 } | 102 } |
74 | 103 |
| 104 int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions( |
| 105 ppapi::host::HostMessageContext* context) { |
| 106 // Getting the LocalDataRestrictions needs to be done on the IO thread, |
| 107 // however it relies on the ResourceContext which can only be accessed from |
| 108 // the UI thread. We lazily initialize |resource_context_| by grabbing the |
| 109 // pointer from the UI thread and then call |GetLocalDataRestrictions| with |
| 110 // it. |
| 111 GURL document_url = host_->GetDocumentURLForInstance(pp_instance()); |
| 112 GURL plugin_url = host_->GetPluginURLForInstance(pp_instance()); |
| 113 if (resource_context_) { |
| 114 GetLocalDataRestrictions(context->MakeReplyMessageContext(), document_url, |
| 115 plugin_url, resource_context_); |
| 116 } else { |
| 117 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE, |
| 118 base::Bind(&GetResourceContext, render_process_id_), |
| 119 base::Bind(&PepperFlashBrowserHost::GetLocalDataRestrictions, |
| 120 weak_factory_.GetWeakPtr(), |
| 121 context->MakeReplyMessageContext(), |
| 122 document_url, plugin_url)); |
| 123 } |
| 124 return PP_OK_COMPLETIONPENDING; |
| 125 } |
| 126 |
| 127 void PepperFlashBrowserHost::GetLocalDataRestrictions( |
| 128 ppapi::host::ReplyMessageContext reply_context, |
| 129 const GURL& document_url, |
| 130 const GURL& plugin_url, |
| 131 ResourceContext* resource_context) { |
| 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 133 // Note that the resource context lives on the IO thread and is owned by the |
| 134 // browser profile so its lifetime should outlast ours. |
| 135 if (!resource_context_) |
| 136 resource_context_ = resource_context; |
| 137 |
| 138 PP_FlashLSORestrictions restrictions = PP_FLASHLSORESTRICTIONS_NONE; |
| 139 if (resource_context_ && document_url.is_valid() && plugin_url.is_valid()) { |
| 140 ContentBrowserClient* client = GetContentClient()->browser(); |
| 141 if (!client->AllowPluginLocalDataAccess(document_url, plugin_url, |
| 142 resource_context_)) { |
| 143 restrictions = PP_FLASHLSORESTRICTIONS_BLOCK; |
| 144 } else if (client->AllowPluginLocalDataSessionOnly(plugin_url, |
| 145 resource_context_)) { |
| 146 restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY; |
| 147 } |
| 148 } |
| 149 SendReply(reply_context, PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply( |
| 150 static_cast<int32_t>(restrictions))); |
| 151 } |
| 152 |
75 } // namespace content | 153 } // namespace content |
OLD | NEW |