| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "content/common/child_process.h" | 11 #include "content/common/child_process.h" |
| 12 #include "ppapi/c/pp_bool.h" | 12 #include "ppapi/c/pp_bool.h" |
| 13 #include "ppapi/c/private/ppp_flash_browser_operations.h" | 13 #include "ppapi/c/private/ppp_flash_browser_operations.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // How long we wait before releasing the broker process. | 19 // How long we wait before releasing the broker process. |
| 20 const int kBrokerReleaseTimeSeconds = 30; | 20 const int kBrokerReleaseTimeSeconds = 30; |
| 21 | 21 |
| 22 std::string ConvertPluginDataPath(const FilePath& plugin_data_path) { | 22 std::string ConvertPluginDataPath(const base::FilePath& plugin_data_path) { |
| 23 // The string is always 8-bit, convert on Windows. | 23 // The string is always 8-bit, convert on Windows. |
| 24 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 25 return WideToUTF8(plugin_data_path.value()); | 25 return WideToUTF8(plugin_data_path.value()); |
| 26 #else | 26 #else |
| 27 return plugin_data_path.value(); | 27 return plugin_data_path.value(); |
| 28 #endif | 28 #endif |
| 29 } | 29 } |
| 30 | 30 |
| 31 struct GetPermissionSettingsContext { | 31 struct GetPermissionSettingsContext { |
| 32 GetPermissionSettingsContext( | 32 GetPermissionSettingsContext( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 uint32 request_id, | 130 uint32 request_id, |
| 131 bool success, | 131 bool success, |
| 132 PP_Flash_BrowserOperations_Permission default_permission, | 132 PP_Flash_BrowserOperations_Permission default_permission, |
| 133 const ppapi::FlashSiteSettings& sites) { | 133 const ppapi::FlashSiteSettings& sites) { |
| 134 Send(new PpapiHostMsg_GetPermissionSettingsResult( | 134 Send(new PpapiHostMsg_GetPermissionSettingsResult( |
| 135 request_id, success, default_permission, sites)); | 135 request_id, success, default_permission, sites)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void BrokerProcessDispatcher::OnGetSitesWithData( | 138 void BrokerProcessDispatcher::OnGetSitesWithData( |
| 139 uint32 request_id, | 139 uint32 request_id, |
| 140 const FilePath& plugin_data_path) { | 140 const base::FilePath& plugin_data_path) { |
| 141 std::vector<std::string> sites; | 141 std::vector<std::string> sites; |
| 142 GetSitesWithData(plugin_data_path, &sites); | 142 GetSitesWithData(plugin_data_path, &sites); |
| 143 Send(new PpapiHostMsg_GetSitesWithDataResult(request_id, sites)); | 143 Send(new PpapiHostMsg_GetSitesWithDataResult(request_id, sites)); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void BrokerProcessDispatcher::OnClearSiteData( | 146 void BrokerProcessDispatcher::OnClearSiteData( |
| 147 uint32 request_id, | 147 uint32 request_id, |
| 148 const FilePath& plugin_data_path, | 148 const base::FilePath& plugin_data_path, |
| 149 const std::string& site, | 149 const std::string& site, |
| 150 uint64 flags, | 150 uint64 flags, |
| 151 uint64 max_age) { | 151 uint64 max_age) { |
| 152 Send(new PpapiHostMsg_ClearSiteDataResult( | 152 Send(new PpapiHostMsg_ClearSiteDataResult( |
| 153 request_id, ClearSiteData(plugin_data_path, site, flags, max_age))); | 153 request_id, ClearSiteData(plugin_data_path, site, flags, max_age))); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void BrokerProcessDispatcher::OnDeauthorizeContentLicenses( | 156 void BrokerProcessDispatcher::OnDeauthorizeContentLicenses( |
| 157 uint32 request_id, | 157 uint32 request_id, |
| 158 const FilePath& plugin_data_path) { | 158 const base::FilePath& plugin_data_path) { |
| 159 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult( | 159 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult( |
| 160 request_id, DeauthorizeContentLicenses(plugin_data_path))); | 160 request_id, DeauthorizeContentLicenses(plugin_data_path))); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void BrokerProcessDispatcher::OnGetPermissionSettings( | 163 void BrokerProcessDispatcher::OnGetPermissionSettings( |
| 164 uint32 request_id, | 164 uint32 request_id, |
| 165 const FilePath& plugin_data_path, | 165 const base::FilePath& plugin_data_path, |
| 166 PP_Flash_BrowserOperations_SettingType setting_type) { | 166 PP_Flash_BrowserOperations_SettingType setting_type) { |
| 167 if (flash_browser_operations_1_3_) { | 167 if (flash_browser_operations_1_3_) { |
| 168 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 168 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 169 // The GetPermissionSettingsContext object will be deleted in | 169 // The GetPermissionSettingsContext object will be deleted in |
| 170 // GetPermissionSettingsCallback(). | 170 // GetPermissionSettingsCallback(). |
| 171 flash_browser_operations_1_3_->GetPermissionSettings( | 171 flash_browser_operations_1_3_->GetPermissionSettings( |
| 172 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, | 172 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, |
| 173 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); | 173 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 | 176 |
| 177 if (flash_browser_operations_1_2_) { | 177 if (flash_browser_operations_1_2_) { |
| 178 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 178 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 179 // The GetPermissionSettingsContext object will be deleted in | 179 // The GetPermissionSettingsContext object will be deleted in |
| 180 // GetPermissionSettingsCallback(). | 180 // GetPermissionSettingsCallback(). |
| 181 flash_browser_operations_1_2_->GetPermissionSettings( | 181 flash_browser_operations_1_2_->GetPermissionSettings( |
| 182 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, | 182 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, |
| 183 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); | 183 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 | 186 |
| 187 OnGetPermissionSettingsCompleted( | 187 OnGetPermissionSettingsCompleted( |
| 188 request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, | 188 request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, |
| 189 ppapi::FlashSiteSettings()); | 189 ppapi::FlashSiteSettings()); |
| 190 return; | 190 return; |
| 191 } | 191 } |
| 192 | 192 |
| 193 void BrokerProcessDispatcher::OnSetDefaultPermission( | 193 void BrokerProcessDispatcher::OnSetDefaultPermission( |
| 194 uint32 request_id, | 194 uint32 request_id, |
| 195 const FilePath& plugin_data_path, | 195 const base::FilePath& plugin_data_path, |
| 196 PP_Flash_BrowserOperations_SettingType setting_type, | 196 PP_Flash_BrowserOperations_SettingType setting_type, |
| 197 PP_Flash_BrowserOperations_Permission permission, | 197 PP_Flash_BrowserOperations_Permission permission, |
| 198 bool clear_site_specific) { | 198 bool clear_site_specific) { |
| 199 Send(new PpapiHostMsg_SetDefaultPermissionResult( | 199 Send(new PpapiHostMsg_SetDefaultPermissionResult( |
| 200 request_id, | 200 request_id, |
| 201 SetDefaultPermission(plugin_data_path, setting_type, permission, | 201 SetDefaultPermission(plugin_data_path, setting_type, permission, |
| 202 clear_site_specific))); | 202 clear_site_specific))); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void BrokerProcessDispatcher::OnSetSitePermission( | 205 void BrokerProcessDispatcher::OnSetSitePermission( |
| 206 uint32 request_id, | 206 uint32 request_id, |
| 207 const FilePath& plugin_data_path, | 207 const base::FilePath& plugin_data_path, |
| 208 PP_Flash_BrowserOperations_SettingType setting_type, | 208 PP_Flash_BrowserOperations_SettingType setting_type, |
| 209 const ppapi::FlashSiteSettings& sites) { | 209 const ppapi::FlashSiteSettings& sites) { |
| 210 Send(new PpapiHostMsg_SetSitePermissionResult( | 210 Send(new PpapiHostMsg_SetSitePermissionResult( |
| 211 request_id, SetSitePermission(plugin_data_path, setting_type, sites))); | 211 request_id, SetSitePermission(plugin_data_path, setting_type, sites))); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void BrokerProcessDispatcher::GetSitesWithData( | 214 void BrokerProcessDispatcher::GetSitesWithData( |
| 215 const FilePath& plugin_data_path, | 215 const base::FilePath& plugin_data_path, |
| 216 std::vector<std::string>* site_vector) { | 216 std::vector<std::string>* site_vector) { |
| 217 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 217 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 218 if (flash_browser_operations_1_3_) { | 218 if (flash_browser_operations_1_3_) { |
| 219 char** sites = NULL; | 219 char** sites = NULL; |
| 220 flash_browser_operations_1_3_->GetSitesWithData(data_str.c_str(), &sites); | 220 flash_browser_operations_1_3_->GetSitesWithData(data_str.c_str(), &sites); |
| 221 if (!sites) | 221 if (!sites) |
| 222 return; | 222 return; |
| 223 | 223 |
| 224 for (size_t i = 0; sites[i]; ++i) | 224 for (size_t i = 0; sites[i]; ++i) |
| 225 site_vector->push_back(sites[i]); | 225 site_vector->push_back(sites[i]); |
| 226 | 226 |
| 227 flash_browser_operations_1_3_->FreeSiteList(sites); | 227 flash_browser_operations_1_3_->FreeSiteList(sites); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path, | 231 bool BrokerProcessDispatcher::ClearSiteData( |
| 232 const std::string& site, | 232 const base::FilePath& plugin_data_path, |
| 233 uint64 flags, | 233 const std::string& site, |
| 234 uint64 max_age) { | 234 uint64 flags, |
| 235 uint64 max_age) { |
| 235 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 236 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 236 if (flash_browser_operations_1_3_) { | 237 if (flash_browser_operations_1_3_) { |
| 237 flash_browser_operations_1_3_->ClearSiteData( | 238 flash_browser_operations_1_3_->ClearSiteData( |
| 238 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); | 239 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); |
| 239 return true; | 240 return true; |
| 240 } | 241 } |
| 241 | 242 |
| 242 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21 | 243 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21 |
| 243 // goes to Stable. | 244 // goes to Stable. |
| 244 if (flash_browser_operations_1_2_) { | 245 if (flash_browser_operations_1_2_) { |
| 245 flash_browser_operations_1_2_->ClearSiteData( | 246 flash_browser_operations_1_2_->ClearSiteData( |
| 246 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); | 247 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); |
| 247 return true; | 248 return true; |
| 248 } | 249 } |
| 249 | 250 |
| 250 if (flash_browser_operations_1_0_) { | 251 if (flash_browser_operations_1_0_) { |
| 251 flash_browser_operations_1_0_->ClearSiteData( | 252 flash_browser_operations_1_0_->ClearSiteData( |
| 252 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); | 253 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); |
| 253 return true; | 254 return true; |
| 254 } | 255 } |
| 255 | 256 |
| 256 return false; | 257 return false; |
| 257 } | 258 } |
| 258 | 259 |
| 259 bool BrokerProcessDispatcher::DeauthorizeContentLicenses( | 260 bool BrokerProcessDispatcher::DeauthorizeContentLicenses( |
| 260 const FilePath& plugin_data_path) { | 261 const base::FilePath& plugin_data_path) { |
| 261 if (flash_browser_operations_1_3_) { | 262 if (flash_browser_operations_1_3_) { |
| 262 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 263 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 263 return PP_ToBool(flash_browser_operations_1_3_->DeauthorizeContentLicenses( | 264 return PP_ToBool(flash_browser_operations_1_3_->DeauthorizeContentLicenses( |
| 264 data_str.c_str())); | 265 data_str.c_str())); |
| 265 } | 266 } |
| 266 | 267 |
| 267 if (flash_browser_operations_1_2_) { | 268 if (flash_browser_operations_1_2_) { |
| 268 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 269 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 269 return PP_ToBool(flash_browser_operations_1_2_->DeauthorizeContentLicenses( | 270 return PP_ToBool(flash_browser_operations_1_2_->DeauthorizeContentLicenses( |
| 270 data_str.c_str())); | 271 data_str.c_str())); |
| 271 } | 272 } |
| 272 | 273 |
| 273 return false; | 274 return false; |
| 274 } | 275 } |
| 275 | 276 |
| 276 bool BrokerProcessDispatcher::SetDefaultPermission( | 277 bool BrokerProcessDispatcher::SetDefaultPermission( |
| 277 const FilePath& plugin_data_path, | 278 const base::FilePath& plugin_data_path, |
| 278 PP_Flash_BrowserOperations_SettingType setting_type, | 279 PP_Flash_BrowserOperations_SettingType setting_type, |
| 279 PP_Flash_BrowserOperations_Permission permission, | 280 PP_Flash_BrowserOperations_Permission permission, |
| 280 bool clear_site_specific) { | 281 bool clear_site_specific) { |
| 281 if (flash_browser_operations_1_3_) { | 282 if (flash_browser_operations_1_3_) { |
| 282 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 283 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 283 return PP_ToBool(flash_browser_operations_1_3_->SetDefaultPermission( | 284 return PP_ToBool(flash_browser_operations_1_3_->SetDefaultPermission( |
| 284 data_str.c_str(), setting_type, permission, | 285 data_str.c_str(), setting_type, permission, |
| 285 PP_FromBool(clear_site_specific))); | 286 PP_FromBool(clear_site_specific))); |
| 286 } | 287 } |
| 287 | 288 |
| 288 if (flash_browser_operations_1_2_) { | 289 if (flash_browser_operations_1_2_) { |
| 289 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 290 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 290 return PP_ToBool(flash_browser_operations_1_2_->SetDefaultPermission( | 291 return PP_ToBool(flash_browser_operations_1_2_->SetDefaultPermission( |
| 291 data_str.c_str(), setting_type, permission, | 292 data_str.c_str(), setting_type, permission, |
| 292 PP_FromBool(clear_site_specific))); | 293 PP_FromBool(clear_site_specific))); |
| 293 } | 294 } |
| 294 | 295 |
| 295 return false; | 296 return false; |
| 296 } | 297 } |
| 297 | 298 |
| 298 bool BrokerProcessDispatcher::SetSitePermission( | 299 bool BrokerProcessDispatcher::SetSitePermission( |
| 299 const FilePath& plugin_data_path, | 300 const base::FilePath& plugin_data_path, |
| 300 PP_Flash_BrowserOperations_SettingType setting_type, | 301 PP_Flash_BrowserOperations_SettingType setting_type, |
| 301 const ppapi::FlashSiteSettings& sites) { | 302 const ppapi::FlashSiteSettings& sites) { |
| 302 if (sites.empty()) | 303 if (sites.empty()) |
| 303 return true; | 304 return true; |
| 304 | 305 |
| 305 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 306 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 306 scoped_array<PP_Flash_BrowserOperations_SiteSetting> site_array( | 307 scoped_array<PP_Flash_BrowserOperations_SiteSetting> site_array( |
| 307 new PP_Flash_BrowserOperations_SiteSetting[sites.size()]); | 308 new PP_Flash_BrowserOperations_SiteSetting[sites.size()]); |
| 308 | 309 |
| 309 for (size_t i = 0; i < sites.size(); ++i) { | 310 for (size_t i = 0; i < sites.size(); ++i) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 322 PP_Bool result = flash_browser_operations_1_2_->SetSitePermission( | 323 PP_Bool result = flash_browser_operations_1_2_->SetSitePermission( |
| 323 data_str.c_str(), setting_type, sites.size(), site_array.get()); | 324 data_str.c_str(), setting_type, sites.size(), site_array.get()); |
| 324 | 325 |
| 325 return PP_ToBool(result); | 326 return PP_ToBool(result); |
| 326 } | 327 } |
| 327 | 328 |
| 328 return false; | 329 return false; |
| 329 } | 330 } |
| 330 | 331 |
| 331 } // namespace content | 332 } // namespace content |
| OLD | NEW |