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/time.h" | 7 #include "base/time.h" |
| 8 #include "chrome/browser/content_settings/cookie_settings.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/browser_ppapi_host.h" | 11 #include "content/public/browser/browser_ppapi_host.h" |
| 10 #include "content/public/browser/browser_thread.h" | 12 #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/render_process_host.h" |
| 13 #include "content/public/browser/resource_context.h" | |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 #include "ipc/ipc_message_macros.h" | 15 #include "ipc/ipc_message_macros.h" |
| 16 #include "ppapi/c/pp_errors.h" | 16 #include "ppapi/c/pp_errors.h" |
| 17 #include "ppapi/c/private/ppb_flash.h" | 17 #include "ppapi/c/private/ppb_flash.h" |
| 18 #include "ppapi/host/dispatch_host_message.h" | 18 #include "ppapi/host/dispatch_host_message.h" |
| 19 #include "ppapi/proxy/ppapi_messages.h" | 19 #include "ppapi/proxy/ppapi_messages.h" |
| 20 #include "ppapi/proxy/resource_message_params.h" | 20 #include "ppapi/proxy/resource_message_params.h" |
| 21 #include "ppapi/shared_impl/time_conversion.h" | 21 #include "ppapi/shared_impl/time_conversion.h" |
| 22 | 22 |
| 23 #ifdef OS_WIN | 23 #ifdef OS_WIN |
| 24 #include <windows.h> | 24 #include <windows.h> |
| 25 #elif defined(OS_MACOSX) | 25 #elif defined(OS_MACOSX) |
| 26 #include <CoreServices/CoreServices.h> | 26 #include <CoreServices/CoreServices.h> |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 using content::BrowserPpapiHost; | 29 using content::BrowserPpapiHost; |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 using content::RenderProcessHost; | 31 using content::RenderProcessHost; |
| 32 using content::ResourceContext; | |
| 33 | 32 |
| 34 namespace chrome { | 33 namespace chrome { |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 // Get the ResourceContext on the UI thread for the given render process ID. | 37 // Get the CookieSettings on the UI thread for the given render process ID. |
| 39 ResourceContext* GetResourceContext(int render_process_id) { | 38 scoped_refptr<CookieSettings> GetCookieSettings(int render_process_id) { |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 41 RenderProcessHost* render_process_host = RenderProcessHost::FromID( | 40 RenderProcessHost* render_process_host = RenderProcessHost::FromID( |
| 42 render_process_id); | 41 render_process_id); |
| 43 if (render_process_host && render_process_host->GetBrowserContext()) | 42 if (render_process_host && render_process_host->GetBrowserContext()) { |
| 44 return render_process_host->GetBrowserContext()->GetResourceContext(); | 43 Profile* profile = |
| 44 Profile::FromBrowserContext(render_process_host->GetBrowserContext()); | |
| 45 return CookieSettings::Factory::GetForProfile(profile); | |
| 46 } | |
| 45 return NULL; | 47 return NULL; |
| 46 } | 48 } |
| 47 | 49 |
| 48 } // namespace | 50 } // namespace |
| 49 | 51 |
| 50 PepperFlashBrowserHost::PepperFlashBrowserHost( | 52 PepperFlashBrowserHost::PepperFlashBrowserHost( |
| 51 BrowserPpapiHost* host, | 53 BrowserPpapiHost* host, |
| 52 PP_Instance instance, | 54 PP_Instance instance, |
| 53 PP_Resource resource) | 55 PP_Resource resource) |
| 54 : ResourceHost(host->GetPpapiHost(), instance, resource), | 56 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 55 host_(host), | 57 host_(host), |
| 56 resource_context_(NULL), | |
| 57 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 58 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 58 int unused; | 59 int unused; |
| 59 host->GetRenderViewIDsForInstance(instance, &render_process_id_, &unused); | 60 host->GetRenderViewIDsForInstance(instance, &render_process_id_, &unused); |
| 60 } | 61 } |
| 61 | 62 |
| 62 PepperFlashBrowserHost::~PepperFlashBrowserHost() { | 63 PepperFlashBrowserHost::~PepperFlashBrowserHost() { |
| 63 } | 64 } |
| 64 | 65 |
| 65 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( | 66 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( |
| 66 const IPC::Message& msg, | 67 const IPC::Message& msg, |
| (...skipping 34 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 | 102 // The reason for this processing being in the browser process is that on |
| 102 // Linux, the localtime calls require filesystem access prohibited by the | 103 // Linux, the localtime calls require filesystem access prohibited by the |
| 103 // sandbox. | 104 // sandbox. |
| 104 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( | 105 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( |
| 105 ppapi::PPGetLocalTimeZoneOffset(t)); | 106 ppapi::PPGetLocalTimeZoneOffset(t)); |
| 106 return PP_OK; | 107 return PP_OK; |
| 107 } | 108 } |
| 108 | 109 |
| 109 int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions( | 110 int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions( |
| 110 ppapi::host::HostMessageContext* context) { | 111 ppapi::host::HostMessageContext* context) { |
| 111 // Getting the LocalDataRestrictions needs to be done on the IO thread, | 112 // Getting the Flash LSO settings requires using the CookieSettings which |
| 112 // however it relies on the ResourceContext which can only be accessed from | 113 // belong to the profile which lives on the UI thread. We lazily initialize |
| 113 // the UI thread. We lazily initialize |resource_context_| by grabbing the | 114 // |cookie_settings_| by grabbing the reference from the UI thread and then |
| 114 // pointer from the UI thread and then call |GetLocalDataRestrictions| with | 115 // call |GetLocalDataRestrictions| with it. |
| 115 // it. | |
| 116 GURL document_url = host_->GetDocumentURLForInstance(pp_instance()); | 116 GURL document_url = host_->GetDocumentURLForInstance(pp_instance()); |
| 117 GURL plugin_url = host_->GetPluginURLForInstance(pp_instance()); | 117 GURL plugin_url = host_->GetPluginURLForInstance(pp_instance()); |
| 118 if (resource_context_) { | 118 if (cookie_settings_.get()) { |
| 119 GetLocalDataRestrictions(context->MakeReplyMessageContext(), document_url, | 119 GetLocalDataRestrictions(context->MakeReplyMessageContext(), document_url, |
| 120 plugin_url, resource_context_); | 120 plugin_url, cookie_settings_); |
| 121 } else { | 121 } else { |
| 122 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE, | 122 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::UI, FROM_HERE, |
| 123 base::Bind(&GetResourceContext, render_process_id_), | 123 base::Bind(&GetCookieSettings, render_process_id_), |
| 124 base::Bind(&PepperFlashBrowserHost::GetLocalDataRestrictions, | 124 base::Bind(&PepperFlashBrowserHost::GetLocalDataRestrictions, |
| 125 weak_factory_.GetWeakPtr(), | 125 weak_factory_.GetWeakPtr(), |
| 126 context->MakeReplyMessageContext(), | 126 context->MakeReplyMessageContext(), |
| 127 document_url, plugin_url)); | 127 document_url, plugin_url)); |
| 128 } | 128 } |
| 129 return PP_OK_COMPLETIONPENDING; | 129 return PP_OK_COMPLETIONPENDING; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void PepperFlashBrowserHost::GetLocalDataRestrictions( | 132 void PepperFlashBrowserHost::GetLocalDataRestrictions( |
| 133 ppapi::host::ReplyMessageContext reply_context, | 133 ppapi::host::ReplyMessageContext reply_context, |
| 134 const GURL& document_url, | 134 const GURL& document_url, |
| 135 const GURL& plugin_url, | 135 const GURL& plugin_url, |
| 136 ResourceContext* resource_context) { | 136 scoped_refptr<CookieSettings> cookie_settings) { |
| 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 138 // Note that the resource context lives on the IO thread and is owned by the | 138 |
| 139 // browser profile so its lifetime should outlast ours. | 139 // Lazily initialize |cookie_settings_|. The cookie settings are thread-safe |
| 140 if (!resource_context_) | 140 // ref-counted so as long as we hold a reference to them we can safely access |
| 141 resource_context_ = resource_context; | 141 // them on the IO thread. |
| 142 if (!cookie_settings_.get()) | |
| 143 cookie_settings_ = cookie_settings; | |
|
Bernhard Bauer
2012/12/30 02:19:00
Could you DCHECK that these variables are equal in
raymes
2012/12/30 05:39:19
Done.
| |
| 142 | 144 |
| 143 PP_FlashLSORestrictions restrictions = PP_FLASHLSORESTRICTIONS_NONE; | 145 PP_FlashLSORestrictions restrictions = PP_FLASHLSORESTRICTIONS_NONE; |
| 144 if (resource_context_ && document_url.is_valid() && plugin_url.is_valid()) { | 146 if (cookie_settings_.get() && document_url.is_valid() && |
| 145 content::ContentBrowserClient* client = | 147 plugin_url.is_valid()) { |
| 146 content::GetContentClient()->browser(); | 148 if (!cookie_settings_->IsReadingCookieAllowed(document_url, plugin_url)) |
| 147 if (!client->AllowPluginLocalDataAccess(document_url, plugin_url, | |
| 148 resource_context_)) { | |
| 149 restrictions = PP_FLASHLSORESTRICTIONS_BLOCK; | 149 restrictions = PP_FLASHLSORESTRICTIONS_BLOCK; |
| 150 } else if (client->AllowPluginLocalDataSessionOnly(plugin_url, | 150 else if (cookie_settings_->IsCookieSessionOnly(plugin_url)) |
| 151 resource_context_)) { | |
| 152 restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY; | 151 restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY; |
| 153 } | |
| 154 } | 152 } |
| 155 SendReply(reply_context, PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply( | 153 SendReply(reply_context, PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply( |
| 156 static_cast<int32_t>(restrictions))); | 154 static_cast<int32_t>(restrictions))); |
| 157 } | 155 } |
| 158 | 156 |
| 159 } // namespace chrome | 157 } // namespace chrome |
| OLD | NEW |