| 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 #include "ppapi/shared_impl/ppapi_globals.h" | |
| 16 #include "ppapi/shared_impl/var.h" | |
| 17 #include "ppapi/shared_impl/var_tracker.h" | |
| 18 | 15 |
| 19 namespace { | 16 namespace { |
| 20 | 17 |
| 21 // How long we wait before releasing the broker process. | 18 // How long we wait before releasing the broker process. |
| 22 const int kBrokerReleaseTimeSeconds = 30; | 19 const int kBrokerReleaseTimeSeconds = 30; |
| 23 | 20 |
| 24 std::string ConvertPluginDataPath(const FilePath& plugin_data_path) { | 21 std::string ConvertPluginDataPath(const FilePath& plugin_data_path) { |
| 25 // The string is always 8-bit, convert on Windows. | 22 // The string is always 8-bit, convert on Windows. |
| 26 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 27 return WideToUTF8(plugin_data_path.value()); | 24 return WideToUTF8(plugin_data_path.value()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 51 scoped_ptr<GetPermissionSettingsContext> context( | 48 scoped_ptr<GetPermissionSettingsContext> context( |
| 52 reinterpret_cast<GetPermissionSettingsContext*>(user_data)); | 49 reinterpret_cast<GetPermissionSettingsContext*>(user_data)); |
| 53 | 50 |
| 54 if (!context->dispatcher) | 51 if (!context->dispatcher) |
| 55 return; | 52 return; |
| 56 | 53 |
| 57 ppapi::FlashSiteSettings site_vector; | 54 ppapi::FlashSiteSettings site_vector; |
| 58 if (success) { | 55 if (success) { |
| 59 site_vector.reserve(site_count); | 56 site_vector.reserve(site_count); |
| 60 for (uint32_t i = 0; i < site_count; ++i) { | 57 for (uint32_t i = 0; i < site_count; ++i) { |
| 61 ppapi::StringVar* string_var = ppapi::StringVar::FromPPVar(sites[i].site); | 58 if (!sites[i].site) { |
| 62 if (!string_var) { | |
| 63 success = PP_FALSE; | 59 success = PP_FALSE; |
| 64 break; | 60 break; |
| 65 } | 61 } |
| 66 site_vector.push_back( | 62 site_vector.push_back( |
| 67 ppapi::FlashSiteSetting(string_var->value(), sites[i].permission)); | 63 ppapi::FlashSiteSetting(sites[i].site, sites[i].permission)); |
| 68 } | 64 } |
| 69 | 65 |
| 70 if (!success) | 66 if (!success) |
| 71 site_vector.clear(); | 67 site_vector.clear(); |
| 72 } | 68 } |
| 73 context->dispatcher->OnGetPermissionSettingsCompleted( | 69 context->dispatcher->OnGetPermissionSettingsCompleted( |
| 74 context->request_id, PP_ToBool(success), default_permission, site_vector); | 70 context->request_id, PP_ToBool(success), default_permission, site_vector); |
| 75 } | 71 } |
| 76 | 72 |
| 77 } // namespace | 73 } // namespace |
| 78 | 74 |
| 79 BrokerProcessDispatcher::BrokerProcessDispatcher( | 75 BrokerProcessDispatcher::BrokerProcessDispatcher( |
| 80 PP_GetInterface_Func get_plugin_interface, | 76 PP_GetInterface_Func get_plugin_interface, |
| 81 PP_ConnectInstance_Func connect_instance) | 77 PP_ConnectInstance_Func connect_instance) |
| 82 : ppapi::proxy::BrokerSideDispatcher(connect_instance), | 78 : ppapi::proxy::BrokerSideDispatcher(connect_instance), |
| 83 get_plugin_interface_(get_plugin_interface), | 79 get_plugin_interface_(get_plugin_interface), |
| 84 flash_browser_operations_1_1_(NULL), | 80 flash_browser_operations_1_2_(NULL), |
| 85 flash_browser_operations_1_0_(NULL) { | 81 flash_browser_operations_1_0_(NULL) { |
| 86 ChildProcess::current()->AddRefProcess(); | 82 ChildProcess::current()->AddRefProcess(); |
| 87 | 83 |
| 88 if (get_plugin_interface) { | 84 if (get_plugin_interface) { |
| 89 flash_browser_operations_1_0_ = | 85 flash_browser_operations_1_0_ = |
| 90 static_cast<const PPP_Flash_BrowserOperations_1_0*>( | 86 static_cast<const PPP_Flash_BrowserOperations_1_0*>( |
| 91 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0)); | 87 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0)); |
| 92 | 88 |
| 93 flash_browser_operations_1_1_ = | 89 flash_browser_operations_1_2_ = |
| 94 static_cast<const PPP_Flash_BrowserOperations_1_1*>( | 90 static_cast<const PPP_Flash_BrowserOperations_1_2*>( |
| 95 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_1)); | 91 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_2)); |
| 96 } | 92 } |
| 97 } | 93 } |
| 98 | 94 |
| 99 BrokerProcessDispatcher::~BrokerProcessDispatcher() { | 95 BrokerProcessDispatcher::~BrokerProcessDispatcher() { |
| 100 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()"; | 96 DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()"; |
| 101 // Don't free the process right away. This timer allows the child process | 97 // Don't free the process right away. This timer allows the child process |
| 102 // to be re-used if the user rapidly goes to a new page that requires this | 98 // to be re-used if the user rapidly goes to a new page that requires this |
| 103 // plugin. This is the case for common plugins where they may be used on a | 99 // plugin. This is the case for common plugins where they may be used on a |
| 104 // source and destination page of a navigation. We don't want to tear down | 100 // source and destination page of a navigation. We don't want to tear down |
| 105 // and re-start processes each time in these cases. | 101 // and re-start processes each time in these cases. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 uint32 request_id, | 143 uint32 request_id, |
| 148 const FilePath& plugin_data_path) { | 144 const FilePath& plugin_data_path) { |
| 149 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult( | 145 Send(new PpapiHostMsg_DeauthorizeContentLicensesResult( |
| 150 request_id, DeauthorizeContentLicenses(plugin_data_path))); | 146 request_id, DeauthorizeContentLicenses(plugin_data_path))); |
| 151 } | 147 } |
| 152 | 148 |
| 153 void BrokerProcessDispatcher::OnMsgGetPermissionSettings( | 149 void BrokerProcessDispatcher::OnMsgGetPermissionSettings( |
| 154 uint32 request_id, | 150 uint32 request_id, |
| 155 const FilePath& plugin_data_path, | 151 const FilePath& plugin_data_path, |
| 156 PP_Flash_BrowserOperations_SettingType setting_type) { | 152 PP_Flash_BrowserOperations_SettingType setting_type) { |
| 157 if (!flash_browser_operations_1_1_) { | 153 if (!flash_browser_operations_1_2_) { |
| 158 OnGetPermissionSettingsCompleted( | 154 OnGetPermissionSettingsCompleted( |
| 159 request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, | 155 request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, |
| 160 ppapi::FlashSiteSettings()); | 156 ppapi::FlashSiteSettings()); |
| 161 return; | 157 return; |
| 162 } | 158 } |
| 163 | 159 |
| 164 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 160 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 165 // The GetPermissionSettingsContext object will be deleted in | 161 // The GetPermissionSettingsContext object will be deleted in |
| 166 // GetPermissionSettingsCallback(). | 162 // GetPermissionSettingsCallback(). |
| 167 flash_browser_operations_1_1_->GetPermissionSettings( | 163 flash_browser_operations_1_2_->GetPermissionSettings( |
| 168 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, | 164 data_str.c_str(), setting_type, &GetPermissionSettingsCallback, |
| 169 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); | 165 new GetPermissionSettingsContext(AsWeakPtr(), request_id)); |
| 170 } | 166 } |
| 171 | 167 |
| 172 void BrokerProcessDispatcher::OnMsgSetDefaultPermission( | 168 void BrokerProcessDispatcher::OnMsgSetDefaultPermission( |
| 173 uint32 request_id, | 169 uint32 request_id, |
| 174 const FilePath& plugin_data_path, | 170 const FilePath& plugin_data_path, |
| 175 PP_Flash_BrowserOperations_SettingType setting_type, | 171 PP_Flash_BrowserOperations_SettingType setting_type, |
| 176 PP_Flash_BrowserOperations_Permission permission, | 172 PP_Flash_BrowserOperations_Permission permission, |
| 177 bool clear_site_specific) { | 173 bool clear_site_specific) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 188 const ppapi::FlashSiteSettings& sites) { | 184 const ppapi::FlashSiteSettings& sites) { |
| 189 Send(new PpapiHostMsg_SetSitePermissionResult( | 185 Send(new PpapiHostMsg_SetSitePermissionResult( |
| 190 request_id, SetSitePermission(plugin_data_path, setting_type, sites))); | 186 request_id, SetSitePermission(plugin_data_path, setting_type, sites))); |
| 191 } | 187 } |
| 192 | 188 |
| 193 bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path, | 189 bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path, |
| 194 const std::string& site, | 190 const std::string& site, |
| 195 uint64 flags, | 191 uint64 flags, |
| 196 uint64 max_age) { | 192 uint64 max_age) { |
| 197 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 193 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 198 if (flash_browser_operations_1_1_) { | 194 if (flash_browser_operations_1_2_) { |
| 199 flash_browser_operations_1_1_->ClearSiteData( | 195 flash_browser_operations_1_2_->ClearSiteData( |
| 200 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); | 196 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); |
| 201 return true; | 197 return true; |
| 202 } | 198 } |
| 203 | 199 |
| 204 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21 | 200 // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21 |
| 205 // goes to Stable. | 201 // goes to Stable. |
| 206 if (flash_browser_operations_1_0_) { | 202 if (flash_browser_operations_1_0_) { |
| 207 flash_browser_operations_1_0_->ClearSiteData( | 203 flash_browser_operations_1_0_->ClearSiteData( |
| 208 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); | 204 data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); |
| 209 return true; | 205 return true; |
| 210 } | 206 } |
| 211 | 207 |
| 212 return false; | 208 return false; |
| 213 } | 209 } |
| 214 | 210 |
| 215 bool BrokerProcessDispatcher::DeauthorizeContentLicenses( | 211 bool BrokerProcessDispatcher::DeauthorizeContentLicenses( |
| 216 const FilePath& plugin_data_path) { | 212 const FilePath& plugin_data_path) { |
| 217 if (!flash_browser_operations_1_1_) | 213 if (!flash_browser_operations_1_2_) |
| 218 return false; | 214 return false; |
| 219 | 215 |
| 220 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 216 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 221 return PP_ToBool(flash_browser_operations_1_1_->DeauthorizeContentLicenses( | 217 return PP_ToBool(flash_browser_operations_1_2_->DeauthorizeContentLicenses( |
| 222 data_str.c_str())); | 218 data_str.c_str())); |
| 223 } | 219 } |
| 224 | 220 |
| 225 bool BrokerProcessDispatcher::SetDefaultPermission( | 221 bool BrokerProcessDispatcher::SetDefaultPermission( |
| 226 const FilePath& plugin_data_path, | 222 const FilePath& plugin_data_path, |
| 227 PP_Flash_BrowserOperations_SettingType setting_type, | 223 PP_Flash_BrowserOperations_SettingType setting_type, |
| 228 PP_Flash_BrowserOperations_Permission permission, | 224 PP_Flash_BrowserOperations_Permission permission, |
| 229 bool clear_site_specific) { | 225 bool clear_site_specific) { |
| 230 if (!flash_browser_operations_1_1_) | 226 if (!flash_browser_operations_1_2_) |
| 231 return false; | 227 return false; |
| 232 | 228 |
| 233 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 229 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 234 return PP_ToBool(flash_browser_operations_1_1_->SetDefaultPermission( | 230 return PP_ToBool(flash_browser_operations_1_2_->SetDefaultPermission( |
| 235 data_str.c_str(), setting_type, permission, | 231 data_str.c_str(), setting_type, permission, |
| 236 PP_FromBool(clear_site_specific))); | 232 PP_FromBool(clear_site_specific))); |
| 237 } | 233 } |
| 238 | 234 |
| 239 bool BrokerProcessDispatcher::SetSitePermission( | 235 bool BrokerProcessDispatcher::SetSitePermission( |
| 240 const FilePath& plugin_data_path, | 236 const FilePath& plugin_data_path, |
| 241 PP_Flash_BrowserOperations_SettingType setting_type, | 237 PP_Flash_BrowserOperations_SettingType setting_type, |
| 242 const ppapi::FlashSiteSettings& sites) { | 238 const ppapi::FlashSiteSettings& sites) { |
| 243 if (!flash_browser_operations_1_1_) | 239 if (!flash_browser_operations_1_2_) |
| 244 return false; | 240 return false; |
| 245 | 241 |
| 246 if (sites.empty()) | 242 if (sites.empty()) |
| 247 return true; | 243 return true; |
| 248 | 244 |
| 249 std::string data_str = ConvertPluginDataPath(plugin_data_path); | 245 std::string data_str = ConvertPluginDataPath(plugin_data_path); |
| 250 scoped_array<PP_Flash_BrowserOperations_SiteSetting> site_array( | 246 scoped_array<PP_Flash_BrowserOperations_SiteSetting> site_array( |
| 251 new PP_Flash_BrowserOperations_SiteSetting[sites.size()]); | 247 new PP_Flash_BrowserOperations_SiteSetting[sites.size()]); |
| 252 | 248 |
| 253 for (size_t i = 0; i < sites.size(); ++i) { | 249 for (size_t i = 0; i < sites.size(); ++i) { |
| 254 site_array[i].site = ppapi::StringVar::StringToPPVar(sites[i].site); | 250 site_array[i].site = sites[i].site.c_str(); |
| 255 site_array[i].permission = sites[i].permission; | 251 site_array[i].permission = sites[i].permission; |
| 256 } | 252 } |
| 257 | 253 |
| 258 PP_Bool result = flash_browser_operations_1_1_->SetSitePermission( | 254 PP_Bool result = flash_browser_operations_1_2_->SetSitePermission( |
| 259 data_str.c_str(), setting_type, sites.size(), site_array.get()); | 255 data_str.c_str(), setting_type, sites.size(), site_array.get()); |
| 260 | 256 |
| 261 for (size_t i = 0; i < sites.size(); ++i) | |
| 262 ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(site_array[i].site); | |
| 263 | |
| 264 return PP_ToBool(result); | 257 return PP_ToBool(result); |
| 265 } | 258 } |
| OLD | NEW |