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/ppapi_plugin/broker_process_dispatcher.h" | 5 #include "content/ppapi_plugin/broker_process_dispatcher.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" |
11 #include "content/child/child_process.h" | 14 #include "content/child/child_process.h" |
12 #include "ppapi/c/pp_bool.h" | 15 #include "ppapi/c/pp_bool.h" |
13 #include "ppapi/c/private/ppp_flash_browser_operations.h" | 16 #include "ppapi/c/private/ppp_flash_browser_operations.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
15 | 18 |
16 namespace content { | 19 namespace content { |
17 namespace { | 20 namespace { |
18 | 21 |
19 // How long we wait before releasing the broker process. | 22 // How long we wait before releasing the broker process. |
20 const int kBrokerReleaseTimeSeconds = 30; | 23 const int kBrokerReleaseTimeSeconds = 30; |
21 | 24 |
22 std::string ConvertPluginDataPath(const base::FilePath& plugin_data_path) { | 25 std::string ConvertPluginDataPath(const base::FilePath& plugin_data_path) { |
23 // The string is always 8-bit, convert on Windows. | 26 // The string is always 8-bit, convert on Windows. |
24 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
25 return base::WideToUTF8(plugin_data_path.value()); | 28 return base::WideToUTF8(plugin_data_path.value()); |
26 #else | 29 #else |
27 return plugin_data_path.value(); | 30 return plugin_data_path.value(); |
28 #endif | 31 #endif |
29 } | 32 } |
30 | 33 |
31 struct GetPermissionSettingsContext { | 34 struct GetPermissionSettingsContext { |
32 GetPermissionSettingsContext( | 35 GetPermissionSettingsContext( |
33 const base::WeakPtr<BrokerProcessDispatcher> in_dispatcher, | 36 const base::WeakPtr<BrokerProcessDispatcher> in_dispatcher, |
34 uint32 in_request_id) | 37 uint32_t in_request_id) |
35 : dispatcher(in_dispatcher), | 38 : dispatcher(in_dispatcher), request_id(in_request_id) {} |
36 request_id(in_request_id) { | |
37 } | |
38 | 39 |
39 base::WeakPtr<BrokerProcessDispatcher> dispatcher; | 40 base::WeakPtr<BrokerProcessDispatcher> dispatcher; |
40 uint32 request_id; | 41 uint32_t request_id; |
41 }; | 42 }; |
42 | 43 |
43 void GetPermissionSettingsCallback( | 44 void GetPermissionSettingsCallback( |
44 void* user_data, | 45 void* user_data, |
45 PP_Bool success, | 46 PP_Bool success, |
46 PP_Flash_BrowserOperations_Permission default_permission, | 47 PP_Flash_BrowserOperations_Permission default_permission, |
47 uint32_t site_count, | 48 uint32_t site_count, |
48 const PP_Flash_BrowserOperations_SiteSetting sites[]) { | 49 const PP_Flash_BrowserOperations_SiteSetting sites[]) { |
49 scoped_ptr<GetPermissionSettingsContext> context( | 50 scoped_ptr<GetPermissionSettingsContext> context( |
50 reinterpret_cast<GetPermissionSettingsContext*>(user_data)); | 51 reinterpret_cast<GetPermissionSettingsContext*>(user_data)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 OnDeauthorizeContentLicenses) | 116 OnDeauthorizeContentLicenses) |
116 IPC_MESSAGE_HANDLER(PpapiMsg_GetPermissionSettings, OnGetPermissionSettings) | 117 IPC_MESSAGE_HANDLER(PpapiMsg_GetPermissionSettings, OnGetPermissionSettings) |
117 IPC_MESSAGE_HANDLER(PpapiMsg_SetDefaultPermission, OnSetDefaultPermission) | 118 IPC_MESSAGE_HANDLER(PpapiMsg_SetDefaultPermission, OnSetDefaultPermission) |
118 IPC_MESSAGE_HANDLER(PpapiMsg_SetSitePermission, OnSetSitePermission) | 119 IPC_MESSAGE_HANDLER(PpapiMsg_SetSitePermission, OnSetSitePermission) |
119 IPC_MESSAGE_UNHANDLED(return BrokerSideDispatcher::OnMessageReceived(msg)) | 120 IPC_MESSAGE_UNHANDLED(return BrokerSideDispatcher::OnMessageReceived(msg)) |
120 IPC_END_MESSAGE_MAP() | 121 IPC_END_MESSAGE_MAP() |
121 return true; | 122 return true; |
122 } | 123 } |
123 | 124 |
124 void BrokerProcessDispatcher::OnGetPermissionSettingsCompleted( | 125 void BrokerProcessDispatcher::OnGetPermissionSettingsCompleted( |
125 uint32 request_id, | 126 uint32_t request_id, |
126 bool success, | 127 bool success, |
127 PP_Flash_BrowserOperations_Permission default_permission, | 128 PP_Flash_BrowserOperations_Permission default_permission, |
128 const ppapi::FlashSiteSettings& sites) { | 129 const ppapi::FlashSiteSettings& sites) { |
129 Send(new PpapiHostMsg_GetPermissionSettingsResult( | 130 Send(new PpapiHostMsg_GetPermissionSettingsResult( |
130 request_id, success, default_permission, sites)); | 131 request_id, success, default_permission, sites)); |
131 } | 132 } |
132 | 133 |
133 void BrokerProcessDispatcher::OnGetSitesWithData( | 134 void BrokerProcessDispatcher::OnGetSitesWithData( |
134 uint32 request_id, | 135 uint32_t request_id, |
135 const base::FilePath& plugin_data_path) { | 136 const base::FilePath& plugin_data_path) { |
136 std::vector<std::string> sites; | 137 std::vector<std::string> sites; |
137 GetSitesWithData(plugin_data_path, &sites); | 138 GetSitesWithData(plugin_data_path, &sites); |
138 Send(new PpapiHostMsg_GetSitesWithDataResult(request_id, sites)); | 139 Send(new PpapiHostMsg_GetSitesWithDataResult(request_id, sites)); |
139 } | 140 } |
140 | 141 |
141 void BrokerProcessDispatcher::OnClearSiteData( | 142 void BrokerProcessDispatcher::OnClearSiteData( |
142 uint32 request_id, | 143 uint32_t request_id, |
143 const base::FilePath& plugin_data_path, | 144 const base::FilePath& plugin_data_path, |
144 const std::string& site, | 145 const std::string& site, |
145 uint64 flags, | 146 uint64_t flags, |
146 uint64 max_age) { | 147 uint64_t max_age) { |
147 Send(new PpapiHostMsg_ClearSiteDataResult( | 148 Send(new PpapiHostMsg_ClearSiteDataResult( |
148 request_id, ClearSiteData(plugin_data_path, site, flags, max_age))); | 149 request_id, ClearSiteData(plugin_data_path, site, flags, max_age))); |
149 } | 150 } |
150 | 151 |
151 void BrokerProcessDispatcher::OnDeauthorizeContentLicenses( | 152 void BrokerProcessDispatcher::OnDeauthorizeContentLicenses( |
152 uint32 request_id, | 153 uint32_t request_id, |
153 const base::FilePath& plugin_data_path) { | 154 const base::FilePath& plugin_data_path) { |
154 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult( | 155 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult( |
155 request_id, DeauthorizeContentLicenses(plugin_data_path))); | 156 request_id, DeauthorizeContentLicenses(plugin_data_path))); |
156 } | 157 } |
157 | 158 |
158 void BrokerProcessDispatcher::OnGetPermissionSettings( | 159 void BrokerProcessDispatcher::OnGetPermissionSettings( |
159 uint32 request_id, | 160 uint32_t request_id, |
160 const base::FilePath& plugin_data_path, | 161 const base::FilePath& plugin_data_path, |
161 PP_Flash_BrowserOperations_SettingType setting_type) { | 162 PP_Flash_BrowserOperations_SettingType setting_type) { |
162 if (flash_browser_operations_1_3_) { | 163 if (flash_browser_operations_1_3_) { |
163 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 164 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
164 // The GetPermissionSettingsContext object will be deleted in | 165 // The GetPermissionSettingsContext object will be deleted in |
165 // GetPermissionSettingsCallback(). | 166 // GetPermissionSettingsCallback(). |
166 flash_browser_operations_1_3_->GetPermissionSettings( | 167 flash_browser_operations_1_3_->GetPermissionSettings( |
167 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, | 168 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, |
168 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); | 169 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); |
169 return; | 170 return; |
170 } | 171 } |
171 | 172 |
172 if (flash_browser_operations_1_2_) { | 173 if (flash_browser_operations_1_2_) { |
173 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 174 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
174 // The GetPermissionSettingsContext object will be deleted in | 175 // The GetPermissionSettingsContext object will be deleted in |
175 // GetPermissionSettingsCallback(). | 176 // GetPermissionSettingsCallback(). |
176 flash_browser_operations_1_2_->GetPermissionSettings( | 177 flash_browser_operations_1_2_->GetPermissionSettings( |
177 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, | 178 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, |
178 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); | 179 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); |
179 return; | 180 return; |
180 } | 181 } |
181 | 182 |
182 OnGetPermissionSettingsCompleted( | 183 OnGetPermissionSettingsCompleted( |
183 request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, | 184 request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, |
184 ppapi::FlashSiteSettings()); | 185 ppapi::FlashSiteSettings()); |
185 return; | 186 return; |
186 } | 187 } |
187 | 188 |
188 void BrokerProcessDispatcher::OnSetDefaultPermission( | 189 void BrokerProcessDispatcher::OnSetDefaultPermission( |
189 uint32 request_id, | 190 uint32_t request_id, |
190 const base::FilePath& plugin_data_path, | 191 const base::FilePath& plugin_data_path, |
191 PP_Flash_BrowserOperations_SettingType setting_type, | 192 PP_Flash_BrowserOperations_SettingType setting_type, |
192 PP_Flash_BrowserOperations_Permission permission, | 193 PP_Flash_BrowserOperations_Permission permission, |
193 bool clear_site_specific) { | 194 bool clear_site_specific) { |
194 Send(new PpapiHostMsg_SetDefaultPermissionResult( | 195 Send(new PpapiHostMsg_SetDefaultPermissionResult( |
195 request_id, | 196 request_id, |
196 SetDefaultPermission(plugin_data_path, setting_type, permission, | 197 SetDefaultPermission(plugin_data_path, setting_type, permission, |
197 clear_site_specific))); | 198 clear_site_specific))); |
198 } | 199 } |
199 | 200 |
200 void BrokerProcessDispatcher::OnSetSitePermission( | 201 void BrokerProcessDispatcher::OnSetSitePermission( |
201 uint32 request_id, | 202 uint32_t request_id, |
202 const base::FilePath& plugin_data_path, | 203 const base::FilePath& plugin_data_path, |
203 PP_Flash_BrowserOperations_SettingType setting_type, | 204 PP_Flash_BrowserOperations_SettingType setting_type, |
204 const ppapi::FlashSiteSettings& sites) { | 205 const ppapi::FlashSiteSettings& sites) { |
205 Send(new PpapiHostMsg_SetSitePermissionResult( | 206 Send(new PpapiHostMsg_SetSitePermissionResult( |
206 request_id, SetSitePermission(plugin_data_path, setting_type, sites))); | 207 request_id, SetSitePermission(plugin_data_path, setting_type, sites))); |
207 } | 208 } |
208 | 209 |
209 void BrokerProcessDispatcher::GetSitesWithData( | 210 void BrokerProcessDispatcher::GetSitesWithData( |
210 const base::FilePath& plugin_data_path, | 211 const base::FilePath& plugin_data_path, |
211 std::vector<std::string>* site_vector) { | 212 std::vector<std::string>* site_vector) { |
212 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 213 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
213 if (flash_browser_operations_1_3_) { | 214 if (flash_browser_operations_1_3_) { |
214 char** sites = NULL; | 215 char** sites = NULL; |
215 flash_browser_operations_1_3_->GetSitesWithData(data_str.c_str(), &sites); | 216 flash_browser_operations_1_3_->GetSitesWithData(data_str.c_str(), &sites); |
216 if (!sites) | 217 if (!sites) |
217 return; | 218 return; |
218 | 219 |
219 for (size_t i = 0; sites[i]; ++i) | 220 for (size_t i = 0; sites[i]; ++i) |
220 site_vector->push_back(sites[i]); | 221 site_vector->push_back(sites[i]); |
221 | 222 |
222 flash_browser_operations_1_3_->FreeSiteList(sites); | 223 flash_browser_operations_1_3_->FreeSiteList(sites); |
223 } | 224 } |
224 } | 225 } |
225 | 226 |
226 bool BrokerProcessDispatcher::ClearSiteData( | 227 bool BrokerProcessDispatcher::ClearSiteData( |
227 const base::FilePath& plugin_data_path, | 228 const base::FilePath& plugin_data_path, |
228 const std::string& site, | 229 const std::string& site, |
229 uint64 flags, | 230 uint64_t flags, |
230 uint64 max_age) { | 231 uint64_t max_age) { |
231 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 232 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
232 if (flash_browser_operations_1_3_) { | 233 if (flash_browser_operations_1_3_) { |
233 flash_browser_operations_1_3_->ClearSiteData( | 234 flash_browser_operations_1_3_->ClearSiteData( |
234 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); | 235 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); |
235 return true; | 236 return true; |
236 } | 237 } |
237 | 238 |
238 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21 | 239 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21 |
239 // goes to Stable. | 240 // goes to Stable. |
240 if (flash_browser_operations_1_2_) { | 241 if (flash_browser_operations_1_2_) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 data_str.c_str(), setting_type, | 321 data_str.c_str(), setting_type, |
321 static_cast<uint32_t>(sites.size()), site_array.get()); | 322 static_cast<uint32_t>(sites.size()), site_array.get()); |
322 | 323 |
323 return PP_ToBool(result); | 324 return PP_ToBool(result); |
324 } | 325 } |
325 | 326 |
326 return false; | 327 return false; |
327 } | 328 } |
328 | 329 |
329 } // namespace content | 330 } // namespace content |
OLD | NEW |