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 "chrome/browser/renderer_host/pepper/pepper_flash_browser_host.h" | 5 #include "chrome/browser/renderer_host/pepper/pepper_flash_browser_host.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | |
| 7 #include "base/time.h" | 8 #include "base/time.h" |
| 8 #include "content/public/browser/browser_context.h" | 9 #include "chrome/browser/renderer_host/pepper/flash_lso_settings_helper.h" |
| 9 #include "content/public/browser/browser_ppapi_host.h" | 10 #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" | 11 #include "googleurl/src/gurl.h" |
| 15 #include "ipc/ipc_message_macros.h" | 12 #include "ipc/ipc_message_macros.h" |
| 16 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
| 17 #include "ppapi/c/private/ppb_flash.h" | 14 #include "ppapi/c/private/ppb_flash.h" |
| 18 #include "ppapi/host/dispatch_host_message.h" | 15 #include "ppapi/host/dispatch_host_message.h" |
| 19 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
| 20 #include "ppapi/proxy/resource_message_params.h" | 17 #include "ppapi/proxy/resource_message_params.h" |
| 21 #include "ppapi/shared_impl/time_conversion.h" | 18 #include "ppapi/shared_impl/time_conversion.h" |
| 22 | 19 |
| 23 #ifdef OS_WIN | 20 #ifdef OS_WIN |
| 24 #include <windows.h> | 21 #include <windows.h> |
| 25 #elif defined(OS_MACOSX) | 22 #elif defined(OS_MACOSX) |
| 26 #include <CoreServices/CoreServices.h> | 23 #include <CoreServices/CoreServices.h> |
| 27 #endif | 24 #endif |
| 28 | 25 |
| 29 using content::BrowserPpapiHost; | 26 using content::BrowserPpapiHost; |
| 30 using content::BrowserThread; | |
| 31 using content::RenderProcessHost; | |
| 32 using content::ResourceContext; | |
| 33 | 27 |
| 34 namespace chrome { | 28 namespace chrome { |
| 35 | 29 |
| 36 namespace { | |
| 37 | |
| 38 // Get the ResourceContext on the UI thread for the given render process ID. | |
| 39 ResourceContext* GetResourceContext(int render_process_id) { | |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 41 RenderProcessHost* render_process_host = RenderProcessHost::FromID( | |
| 42 render_process_id); | |
| 43 if (render_process_host && render_process_host->GetBrowserContext()) | |
| 44 return render_process_host->GetBrowserContext()->GetResourceContext(); | |
| 45 return NULL; | |
| 46 } | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 PepperFlashBrowserHost::PepperFlashBrowserHost( | 30 PepperFlashBrowserHost::PepperFlashBrowserHost( |
| 51 BrowserPpapiHost* host, | 31 BrowserPpapiHost* host, |
| 52 PP_Instance instance, | 32 PP_Instance instance, |
| 53 PP_Resource resource) | 33 PP_Resource resource) |
| 54 : ResourceHost(host->GetPpapiHost(), instance, resource), | 34 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 55 host_(host), | 35 host_(host), |
| 56 resource_context_(NULL), | |
| 57 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 36 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 58 int unused; | 37 int render_process_id, unused; |
| 59 host->GetRenderViewIDsForInstance(instance, &render_process_id_, &unused); | 38 host->GetRenderViewIDsForInstance(instance, &render_process_id, &unused); |
| 39 lso_settings_helper_ = new FlashLSOSettingsHelper(render_process_id); | |
| 60 } | 40 } |
| 61 | 41 |
| 62 PepperFlashBrowserHost::~PepperFlashBrowserHost() { | 42 PepperFlashBrowserHost::~PepperFlashBrowserHost() { |
| 63 } | 43 } |
| 64 | 44 |
| 65 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( | 45 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( |
| 66 const IPC::Message& msg, | 46 const IPC::Message& msg, |
| 67 ppapi::host::HostMessageContext* context) { | 47 ppapi::host::HostMessageContext* context) { |
| 68 IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) | 48 IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) |
| 69 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, | 49 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 // The reason for this processing being in the browser process is that on | 81 // The reason for this processing being in the browser process is that on |
| 102 // Linux, the localtime calls require filesystem access prohibited by the | 82 // Linux, the localtime calls require filesystem access prohibited by the |
| 103 // sandbox. | 83 // sandbox. |
| 104 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( | 84 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( |
| 105 ppapi::PPGetLocalTimeZoneOffset(t)); | 85 ppapi::PPGetLocalTimeZoneOffset(t)); |
| 106 return PP_OK; | 86 return PP_OK; |
| 107 } | 87 } |
| 108 | 88 |
| 109 int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions( | 89 int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions( |
| 110 ppapi::host::HostMessageContext* context) { | 90 ppapi::host::HostMessageContext* context) { |
| 111 // Getting the LocalDataRestrictions needs to be done on the IO thread, | 91 lso_settings_helper_->GetLocalDataRestrictions( |
| 112 // however it relies on the ResourceContext which can only be accessed from | 92 host_->GetDocumentURLForInstance(pp_instance()), |
| 113 // the UI thread. We lazily initialize |resource_context_| by grabbing the | 93 host_->GetPluginURLForInstance(pp_instance()), |
| 114 // pointer from the UI thread and then call |GetLocalDataRestrictions| with | 94 base::Bind(&PepperFlashBrowserHost::OnGetLocalDataRestrictions, |
| 115 // it. | 95 weak_factory_.GetWeakPtr(), |
| 116 GURL document_url = host_->GetDocumentURLForInstance(pp_instance()); | 96 context->MakeReplyMessageContext())); |
| 117 GURL plugin_url = host_->GetPluginURLForInstance(pp_instance()); | |
| 118 if (resource_context_) { | |
| 119 GetLocalDataRestrictions(context->MakeReplyMessageContext(), document_url, | |
| 120 plugin_url, resource_context_); | |
| 121 } else { | |
| 122 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE, | |
| 123 base::Bind(&GetResourceContext, render_process_id_), | |
| 124 base::Bind(&PepperFlashBrowserHost::GetLocalDataRestrictions, | |
| 125 weak_factory_.GetWeakPtr(), | |
| 126 context->MakeReplyMessageContext(), | |
| 127 document_url, plugin_url)); | |
| 128 } | |
| 129 return PP_OK_COMPLETIONPENDING; | 97 return PP_OK_COMPLETIONPENDING; |
| 130 } | 98 } |
| 131 | 99 |
| 132 void PepperFlashBrowserHost::GetLocalDataRestrictions( | 100 void PepperFlashBrowserHost::OnGetLocalDataRestrictions( |
|
yzshen1
2012/12/29 02:04:05
Nit, optional: maybe OnLocalDataRestrictionsRetrie
raymes
2012/12/29 21:15:40
Done.
| |
| 133 ppapi::host::ReplyMessageContext reply_context, | 101 ppapi::host::ReplyMessageContext reply_context, |
| 134 const GURL& document_url, | 102 PP_FlashLSORestrictions restrictions) { |
| 135 const GURL& plugin_url, | |
| 136 ResourceContext* resource_context) { | |
| 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 138 // Note that the resource context lives on the IO thread and is owned by the | |
| 139 // browser profile so its lifetime should outlast ours. | |
| 140 if (!resource_context_) | |
| 141 resource_context_ = resource_context; | |
| 142 | |
| 143 PP_FlashLSORestrictions restrictions = PP_FLASHLSORESTRICTIONS_NONE; | |
| 144 if (resource_context_ && document_url.is_valid() && plugin_url.is_valid()) { | |
| 145 content::ContentBrowserClient* client = | |
| 146 content::GetContentClient()->browser(); | |
| 147 if (!client->AllowPluginLocalDataAccess(document_url, plugin_url, | |
| 148 resource_context_)) { | |
| 149 restrictions = PP_FLASHLSORESTRICTIONS_BLOCK; | |
| 150 } else if (client->AllowPluginLocalDataSessionOnly(plugin_url, | |
| 151 resource_context_)) { | |
| 152 restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY; | |
| 153 } | |
| 154 } | |
| 155 SendReply(reply_context, PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply( | 103 SendReply(reply_context, PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply( |
| 156 static_cast<int32_t>(restrictions))); | 104 static_cast<int32_t>(restrictions))); |
| 157 } | 105 } |
| 158 | 106 |
| 159 } // namespace chrome | 107 } // namespace chrome |
| OLD | NEW |