Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_webstore_private_api.h" | 5 #include "chrome/browser/extensions/extension_webstore_private_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/crx_installer.h" | 13 #include "chrome/browser/extensions/crx_installer.h" |
| 14 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 14 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 15 #include "chrome/browser/extensions/extension_install_dialog.h" | 15 #include "chrome/browser/extensions/extension_install_dialog.h" |
| 16 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/webstore_installer.h" | |
| 18 #include "chrome/browser/net/gaia/token_service.h" | 19 #include "chrome/browser/net/gaia/token_service.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/sync/profile_sync_service.h" | 21 #include "chrome/browser/sync/profile_sync_service.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
| 25 #include "chrome/common/extensions/extension_error_utils.h" | 26 #include "chrome/common/extensions/extension_error_utils.h" |
| 26 #include "chrome/common/extensions/extension_l10n_util.h" | 27 #include "chrome/common/extensions/extension_l10n_util.h" |
| 27 #include "chrome/common/net/gaia/gaia_constants.h" | 28 #include "chrome/common/net/gaia/gaia_constants.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 | 160 |
| 160 if (details->HasKey(kAppInstallBubbleKey)) | 161 if (details->HasKey(kAppInstallBubbleKey)) |
| 161 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean( | 162 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean( |
| 162 kAppInstallBubbleKey, &use_app_installed_bubble_)); | 163 kAppInstallBubbleKey, &use_app_installed_bubble_)); |
| 163 | 164 |
| 164 net::URLRequestContextGetter* context_getter = NULL; | 165 net::URLRequestContextGetter* context_getter = NULL; |
| 165 if (!icon_url.is_empty()) | 166 if (!icon_url.is_empty()) |
| 166 context_getter = profile()->GetRequestContext(); | 167 context_getter = profile()->GetRequestContext(); |
| 167 | 168 |
| 168 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( | 169 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( |
| 169 this, manifest_, icon_data_, icon_url, context_getter); | 170 this, id_, manifest_, icon_data_, icon_url, context_getter); |
| 170 | 171 |
| 171 // The helper will call us back via OnWebstoreParseSuccess or | 172 // The helper will call us back via OnWebstoreParseSuccess or |
| 172 // OnWebstoreParseFailure. | 173 // OnWebstoreParseFailure. |
| 173 helper->Start(); | 174 helper->Start(); |
| 174 | 175 |
| 175 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. | 176 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. |
| 176 AddRef(); | 177 AddRef(); |
| 177 | 178 |
| 178 // The response is sent asynchronously in OnWebstoreParseSuccess/ | 179 // The response is sent asynchronously in OnWebstoreParseSuccess/ |
| 179 // OnWebstoreParseFailure. | 180 // OnWebstoreParseFailure. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 206 break; | 207 break; |
| 207 case INVALID_ICON_URL: | 208 case INVALID_ICON_URL: |
| 208 result_.reset(Value::CreateStringValue("invalid_icon_url")); | 209 result_.reset(Value::CreateStringValue("invalid_icon_url")); |
| 209 break; | 210 break; |
| 210 default: | 211 default: |
| 211 CHECK(false); | 212 CHECK(false); |
| 212 } | 213 } |
| 213 } | 214 } |
| 214 | 215 |
| 215 void BeginInstallWithManifestFunction::OnWebstoreParseSuccess( | 216 void BeginInstallWithManifestFunction::OnWebstoreParseSuccess( |
| 216 const SkBitmap& icon, DictionaryValue* parsed_manifest) { | 217 const std::string& id, |
| 218 const SkBitmap& icon, | |
| 219 DictionaryValue* parsed_manifest) { | |
| 220 CHECK_EQ(id_, id); | |
| 217 CHECK(parsed_manifest); | 221 CHECK(parsed_manifest); |
| 218 icon_ = icon; | 222 icon_ = icon; |
| 219 parsed_manifest_.reset(parsed_manifest); | 223 parsed_manifest_.reset(parsed_manifest); |
| 220 | 224 |
| 221 ExtensionInstallUI::Prompt prompt(ExtensionInstallUI::INSTALL_PROMPT); | 225 ExtensionInstallUI::Prompt prompt(ExtensionInstallUI::INSTALL_PROMPT); |
| 222 | 226 |
| 223 if (!ShowExtensionInstallDialogForManifest( | 227 if (!ShowExtensionInstallDialogForManifest( |
| 224 profile(), | 228 profile(), |
| 225 this, | 229 this, |
| 226 parsed_manifest, | 230 parsed_manifest, |
| 227 id_, | 231 id_, |
| 228 localized_name_, | 232 localized_name_, |
| 229 "", // no localized description | 233 "", // no localized description |
| 230 &icon_, | 234 &icon_, |
| 231 prompt, | 235 prompt, |
| 232 &dummy_extension_)) { | 236 &dummy_extension_)) { |
| 233 OnWebstoreParseFailure(WebstoreInstallHelper::Delegate::MANIFEST_ERROR, | 237 OnWebstoreParseFailure(id_, WebstoreInstallHelper::Delegate::MANIFEST_ERROR, |
| 234 kInvalidManifestError); | 238 kInvalidManifestError); |
| 235 return; | 239 return; |
| 236 } | 240 } |
| 237 | 241 |
| 238 // Control flow finishes up in InstallUIProceed or InstallUIAbort. | 242 // Control flow finishes up in InstallUIProceed or InstallUIAbort. |
| 239 } | 243 } |
| 240 | 244 |
| 241 void BeginInstallWithManifestFunction::OnWebstoreParseFailure( | 245 void BeginInstallWithManifestFunction::OnWebstoreParseFailure( |
| 246 const std::string& id, | |
| 242 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, | 247 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, |
| 243 const std::string& error_message) { | 248 const std::string& error_message) { |
| 249 CHECK_EQ(id_, id); | |
| 250 | |
| 244 // Map from WebstoreInstallHelper's result codes to ours. | 251 // Map from WebstoreInstallHelper's result codes to ours. |
| 245 switch (result_code) { | 252 switch (result_code) { |
| 246 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: | 253 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: |
| 247 SetResult(UNKNOWN_ERROR); | 254 SetResult(UNKNOWN_ERROR); |
| 248 break; | 255 break; |
| 249 case WebstoreInstallHelper::Delegate::ICON_ERROR: | 256 case WebstoreInstallHelper::Delegate::ICON_ERROR: |
| 250 SetResult(ICON_ERROR); | 257 SetResult(ICON_ERROR); |
| 251 break; | 258 break; |
| 252 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: | 259 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
| 253 SetResult(MANIFEST_ERROR); | 260 SetResult(MANIFEST_ERROR); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 284 Release(); | 291 Release(); |
| 285 } | 292 } |
| 286 | 293 |
| 287 void BeginInstallWithManifestFunction::InstallUIAbort(bool user_initiated) { | 294 void BeginInstallWithManifestFunction::InstallUIAbort(bool user_initiated) { |
| 288 error_ = kUserCancelledError; | 295 error_ = kUserCancelledError; |
| 289 SetResult(USER_CANCELLED); | 296 SetResult(USER_CANCELLED); |
| 290 SendResponse(false); | 297 SendResponse(false); |
| 291 | 298 |
| 292 // The web store install histograms are a subset of the install histograms. | 299 // The web store install histograms are a subset of the install histograms. |
| 293 // We need to record both histograms here since CrxInstaller::InstallUIAbort | 300 // We need to record both histograms here since CrxInstaller::InstallUIAbort |
| 294 // is never called for web store install cancellations | 301 // is never called for web store install cancellations. |
| 295 std::string histogram_name = user_initiated ? | 302 std::string histogram_name = user_initiated ? |
| 296 "Extensions.Permissions_WebStoreInstallCancel" : | 303 "Extensions.Permissions_WebStoreInstallCancel" : |
| 297 "Extensions.Permissions_WebStoreInstallAbort"; | 304 "Extensions.Permissions_WebStoreInstallAbort"; |
| 298 ExtensionService::RecordPermissionMessagesHistogram( | 305 ExtensionService::RecordPermissionMessagesHistogram( |
| 299 dummy_extension_, histogram_name.c_str()); | 306 dummy_extension_, histogram_name.c_str()); |
| 300 | 307 |
| 301 histogram_name = user_initiated ? | 308 histogram_name = user_initiated ? |
| 302 "Extensions.Permissions_InstallCancel" : | 309 "Extensions.Permissions_InstallCancel" : |
| 303 "Extensions.Permissions_InstallAbort"; | 310 "Extensions.Permissions_InstallAbort"; |
| 304 ExtensionService::RecordPermissionMessagesHistogram( | 311 ExtensionService::RecordPermissionMessagesHistogram( |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 322 if (!CrxInstaller::IsIdWhitelisted(id) && | 329 if (!CrxInstaller::IsIdWhitelisted(id) && |
| 323 !CrxInstaller::GetWhitelistEntry(id)) { | 330 !CrxInstaller::GetWhitelistEntry(id)) { |
| 324 error_ = ExtensionErrorUtils::FormatErrorMessage( | 331 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 325 kNoPreviousBeginInstallWithManifestError, id); | 332 kNoPreviousBeginInstallWithManifestError, id); |
| 326 return false; | 333 return false; |
| 327 } | 334 } |
| 328 | 335 |
| 329 // The extension will install through the normal extension install flow, but | 336 // The extension will install through the normal extension install flow, but |
| 330 // the above call to SetWhitelistedInstallId will bypass the normal | 337 // the above call to SetWhitelistedInstallId will bypass the normal |
| 331 // permissions install dialog. | 338 // permissions install dialog. |
| 332 WebstoreInstaller* installer = | 339 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
| 333 profile()->GetExtensionService()->webstore_installer(); | 340 profile(), test_webstore_installer_delegate, |
| 334 installer->InstallExtension( | 341 &(dispatcher()->delegate()->GetAssociatedTabContents()->controller()), |
| 335 id, test_webstore_installer_delegate, WebstoreInstaller::FLAG_NONE); | 342 id, WebstoreInstaller::FLAG_NONE); |
| 343 installer->Start(); | |
| 336 | 344 |
| 337 return true; | 345 return true; |
| 338 } | 346 } |
| 339 | 347 |
| 348 | |
|
Mihai Parparita -not on Chrome
2011/10/24 22:36:18
Extra newline.
jstritar
2011/10/25 02:45:04
Done.
| |
| 340 bool GetBrowserLoginFunction::RunImpl() { | 349 bool GetBrowserLoginFunction::RunImpl() { |
| 341 if (!IsWebStoreURL(profile_, source_url())) | 350 if (!IsWebStoreURL(profile_, source_url())) |
| 342 return false; | 351 return false; |
| 343 result_.reset(CreateLoginResult(profile_->GetOriginalProfile())); | 352 result_.reset(CreateLoginResult(profile_->GetOriginalProfile())); |
| 344 return true; | 353 return true; |
| 345 } | 354 } |
| 346 | 355 |
| 347 bool GetStoreLoginFunction::RunImpl() { | 356 bool GetStoreLoginFunction::RunImpl() { |
| 348 if (!IsWebStoreURL(profile_, source_url())) | 357 if (!IsWebStoreURL(profile_, source_url())) |
| 349 return false; | 358 return false; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 361 bool SetStoreLoginFunction::RunImpl() { | 370 bool SetStoreLoginFunction::RunImpl() { |
| 362 if (!IsWebStoreURL(profile_, source_url())) | 371 if (!IsWebStoreURL(profile_, source_url())) |
| 363 return false; | 372 return false; |
| 364 std::string login; | 373 std::string login; |
| 365 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); | 374 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); |
| 366 ExtensionService* service = profile_->GetExtensionService(); | 375 ExtensionService* service = profile_->GetExtensionService(); |
| 367 ExtensionPrefs* prefs = service->extension_prefs(); | 376 ExtensionPrefs* prefs = service->extension_prefs(); |
| 368 prefs->SetWebStoreLogin(login); | 377 prefs->SetWebStoreLogin(login); |
| 369 return true; | 378 return true; |
| 370 } | 379 } |
| OLD | NEW |