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/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" | 12 #include "googleurl/src/gurl.h" |
15 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
16 #include "ppapi/c/pp_errors.h" | 14 #include "ppapi/c/pp_errors.h" |
17 #include "ppapi/c/private/ppb_flash.h" | 15 #include "ppapi/c/private/ppb_flash.h" |
18 #include "ppapi/host/dispatch_host_message.h" | 16 #include "ppapi/host/dispatch_host_message.h" |
19 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
20 #include "ppapi/proxy/resource_message_params.h" | 18 #include "ppapi/proxy/resource_message_params.h" |
21 #include "ppapi/shared_impl/time_conversion.h" | 19 #include "ppapi/shared_impl/time_conversion.h" |
22 | 20 |
23 #ifdef OS_WIN | 21 #ifdef OS_WIN |
24 #include <windows.h> | 22 #include <windows.h> |
25 #elif defined(OS_MACOSX) | 23 #elif defined(OS_MACOSX) |
26 #include <CoreServices/CoreServices.h> | 24 #include <CoreServices/CoreServices.h> |
27 #endif | 25 #endif |
28 | 26 |
29 using content::BrowserPpapiHost; | 27 using content::BrowserPpapiHost; |
30 using content::BrowserThread; | |
31 using content::RenderProcessHost; | |
32 using content::ResourceContext; | |
33 | 28 |
34 namespace chrome { | 29 namespace chrome { |
35 | 30 |
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( | 31 PepperFlashBrowserHost::PepperFlashBrowserHost( |
51 BrowserPpapiHost* host, | 32 BrowserPpapiHost* host, |
52 PP_Instance instance, | 33 PP_Instance instance, |
53 PP_Resource resource) | 34 PP_Resource resource) |
54 : ResourceHost(host->GetPpapiHost(), instance, resource), | 35 : ResourceHost(host->GetPpapiHost(), instance, resource), |
55 host_(host), | 36 host_(host), |
56 resource_context_(NULL), | |
57 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 37 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
58 int unused; | 38 int render_process_id, unused; |
59 host->GetRenderViewIDsForInstance(instance, &render_process_id_, &unused); | 39 host->GetRenderViewIDsForInstance(instance, &render_process_id, &unused); |
40 lso_settings_helper_ = new FlashLSOSettingsHelper(render_process_id); | |
60 } | 41 } |
61 | 42 |
62 PepperFlashBrowserHost::~PepperFlashBrowserHost() { | 43 PepperFlashBrowserHost::~PepperFlashBrowserHost() { |
44 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
yzshen1
2012/12/29 19:13:40
Please comment on why this is necessary.
This will
raymes
2012/12/29 21:15:40
Done.
raymes
2012/12/29 21:15:40
Done.
| |
45 base::Bind(&FlashLSOSettingsHelper::ShutdownOnUIThread, | |
46 lso_settings_helper_)); | |
63 } | 47 } |
64 | 48 |
65 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( | 49 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( |
66 const IPC::Message& msg, | 50 const IPC::Message& msg, |
67 ppapi::host::HostMessageContext* context) { | 51 ppapi::host::HostMessageContext* context) { |
68 IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) | 52 IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) |
69 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, | 53 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, |
70 OnMsgUpdateActivity); | 54 OnMsgUpdateActivity); |
71 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset, | 55 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset, |
72 OnMsgGetLocalTimeZoneOffset); | 56 OnMsgGetLocalTimeZoneOffset); |
(...skipping 28 matching lines...) Expand all Loading... | |
101 // The reason for this processing being in the browser process is that on | 85 // The reason for this processing being in the browser process is that on |
102 // Linux, the localtime calls require filesystem access prohibited by the | 86 // Linux, the localtime calls require filesystem access prohibited by the |
103 // sandbox. | 87 // sandbox. |
104 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( | 88 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( |
105 ppapi::PPGetLocalTimeZoneOffset(t)); | 89 ppapi::PPGetLocalTimeZoneOffset(t)); |
106 return PP_OK; | 90 return PP_OK; |
107 } | 91 } |
108 | 92 |
109 int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions( | 93 int32_t PepperFlashBrowserHost::OnMsgGetLocalDataRestrictions( |
110 ppapi::host::HostMessageContext* context) { | 94 ppapi::host::HostMessageContext* context) { |
111 // Getting the LocalDataRestrictions needs to be done on the IO thread, | 95 lso_settings_helper_->GetLocalDataRestrictions( |
112 // however it relies on the ResourceContext which can only be accessed from | 96 host_->GetDocumentURLForInstance(pp_instance()), |
113 // the UI thread. We lazily initialize |resource_context_| by grabbing the | 97 host_->GetPluginURLForInstance(pp_instance()), |
114 // pointer from the UI thread and then call |GetLocalDataRestrictions| with | 98 base::Bind(&PepperFlashBrowserHost::OnGetLocalDataRestrictions, |
115 // it. | 99 weak_factory_.GetWeakPtr(), |
116 GURL document_url = host_->GetDocumentURLForInstance(pp_instance()); | 100 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; | 101 return PP_OK_COMPLETIONPENDING; |
130 } | 102 } |
131 | 103 |
132 void PepperFlashBrowserHost::GetLocalDataRestrictions( | 104 void PepperFlashBrowserHost::OnGetLocalDataRestrictions( |
133 ppapi::host::ReplyMessageContext reply_context, | 105 ppapi::host::ReplyMessageContext reply_context, |
134 const GURL& document_url, | 106 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( | 107 SendReply(reply_context, PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply( |
156 static_cast<int32_t>(restrictions))); | 108 static_cast<int32_t>(restrictions))); |
157 } | 109 } |
158 | 110 |
159 } // namespace chrome | 111 } // namespace chrome |
OLD | NEW |