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/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" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // Returns either the test sync service, or the real one from |profile|. | 64 // Returns either the test sync service, or the real one from |profile|. |
65 ProfileSyncService* GetSyncService(Profile* profile) { | 65 ProfileSyncService* GetSyncService(Profile* profile) { |
66 // TODO(webstore): It seems |test_sync_service| is not used anywhere. It | 66 // TODO(webstore): It seems |test_sync_service| is not used anywhere. It |
67 // should be removed. | 67 // should be removed. |
68 if (test_sync_service) | 68 if (test_sync_service) |
69 return test_sync_service; | 69 return test_sync_service; |
70 else | 70 else |
71 return ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 71 return ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
72 } | 72 } |
73 | 73 |
74 // Whitelists extension IDs for use by webstorePrivate.silentlyInstall. | |
75 bool trust_test_ids = false; | |
76 | |
77 bool IsTrustedForSilentInstall(const std::string& id) { | |
78 // Trust the extensions in api_test/webstore_private/bundle when the flag | |
79 // is set. | |
80 if (trust_test_ids && | |
81 (id == "begfmnajjkbjdgmffnjaojchoncnmngg" || | |
82 id == "bmfoocgfinpmkmlbjhcbofejhkhlbchk" || | |
83 id == "mpneghmdnmaolkljkipbhaienajcflfe")) | |
84 return true; | |
85 | |
86 return | |
87 id == "jgoepmocgafhnchmokaimcmlojpnlkhp" || // +1 Extension | |
88 id == "cpembckmhnjipbgbnfiocbgnkpjdokdd" || // +1 Extension - dev | |
89 id == "boemmnepglcoinjcdlfcpcbmhiecichi" || // Notifications | |
90 id == "flibmgiapaohcbondaoopaalfejliklp" || // Notifications - dev | |
91 id == "nckgahadagoaajjgafhacjanaoiihapd" || // Talk | |
92 id == "eggnbpckecmjlblplehfpjjdhhidfdoj" || // Talk Beta | |
93 id == "dlppkpafhbajpcmmoheippocdidnckmm" || // Remaining are placeholders | |
94 id == "hmglfmpefabcafaimbpldpambdfomanl" || | |
95 id == "idfijlieiecpfcjckpkliefekpokhhnd" || | |
96 id == "jaokjbijaokooelpahnlmbciccldmfla" || | |
97 id == "kdjeommiakphmeionoojjljlecmpaldd" || | |
98 id == "lpdeojkfhenboeibhkjhiancceeboknd"; | |
99 } | |
100 | |
101 // Helper to create a dictionary with login and token properties set from | 74 // Helper to create a dictionary with login and token properties set from |
102 // the appropriate values in the passed-in |profile|. | 75 // the appropriate values in the passed-in |profile|. |
103 DictionaryValue* CreateLoginResult(Profile* profile) { | 76 DictionaryValue* CreateLoginResult(Profile* profile) { |
104 DictionaryValue* dictionary = new DictionaryValue(); | 77 DictionaryValue* dictionary = new DictionaryValue(); |
105 std::string username = profile->GetPrefs()->GetString( | 78 std::string username = profile->GetPrefs()->GetString( |
106 prefs::kGoogleServicesUsername); | 79 prefs::kGoogleServicesUsername); |
107 dictionary->SetString(kLoginKey, username); | 80 dictionary->SetString(kLoginKey, username); |
108 if (!username.empty()) { | 81 if (!username.empty()) { |
109 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 82 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
110 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); | 83 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); |
(...skipping 16 matching lines...) Expand all Loading... |
127 ProfileSyncService* service) { | 100 ProfileSyncService* service) { |
128 test_sync_service = service; | 101 test_sync_service = service; |
129 } | 102 } |
130 | 103 |
131 // static | 104 // static |
132 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting( | 105 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting( |
133 WebstoreInstaller::Delegate* delegate) { | 106 WebstoreInstaller::Delegate* delegate) { |
134 test_webstore_installer_delegate = delegate; | 107 test_webstore_installer_delegate = delegate; |
135 } | 108 } |
136 | 109 |
137 // static | |
138 void WebstorePrivateApi::SetTrustTestIDsForTesting(bool allow) { | |
139 trust_test_ids = allow; | |
140 } | |
141 | |
142 InstallBundleFunction::InstallBundleFunction() {} | 110 InstallBundleFunction::InstallBundleFunction() {} |
143 InstallBundleFunction::~InstallBundleFunction() {} | 111 InstallBundleFunction::~InstallBundleFunction() {} |
144 | 112 |
145 bool InstallBundleFunction::RunImpl() { | 113 bool InstallBundleFunction::RunImpl() { |
146 ListValue* extensions = NULL; | 114 ListValue* extensions = NULL; |
147 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); | 115 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); |
148 | 116 |
149 BundleInstaller::ItemList items; | 117 BundleInstaller::ItemList items; |
150 if (!ReadBundleInfo(extensions, &items)) | 118 if (!ReadBundleInfo(extensions, &items)) |
151 return false; | 119 return false; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 // the whitelist entry will bypass the normal permissions install dialog. | 389 // the whitelist entry will bypass the normal permissions install dialog. |
422 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | 390 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
423 profile(), test_webstore_installer_delegate, | 391 profile(), test_webstore_installer_delegate, |
424 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), | 392 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), |
425 id, WebstoreInstaller::FLAG_NONE); | 393 id, WebstoreInstaller::FLAG_NONE); |
426 installer->Start(); | 394 installer->Start(); |
427 | 395 |
428 return true; | 396 return true; |
429 } | 397 } |
430 | 398 |
431 SilentlyInstallFunction::SilentlyInstallFunction() {} | |
432 SilentlyInstallFunction::~SilentlyInstallFunction() {} | |
433 | |
434 bool SilentlyInstallFunction::RunImpl() { | |
435 DictionaryValue* details = NULL; | |
436 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | |
437 CHECK(details); | |
438 | |
439 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_)); | |
440 if (!IsTrustedForSilentInstall(id_)) { | |
441 error_ = kInvalidIdError; | |
442 return false; | |
443 } | |
444 | |
445 EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest_)); | |
446 | |
447 // Matched in OnWebstoreParseFailure, OnExtensionInstall{Success,Failure}. | |
448 AddRef(); | |
449 | |
450 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( | |
451 this, id_, manifest_, std::string(), GURL(), NULL); | |
452 helper->Start(); | |
453 | |
454 return true; | |
455 } | |
456 | |
457 void SilentlyInstallFunction::OnWebstoreParseSuccess( | |
458 const std::string& id, | |
459 const SkBitmap& icon, | |
460 base::DictionaryValue* parsed_manifest) { | |
461 CHECK_EQ(id_, id); | |
462 | |
463 // This lets CrxInstaller bypass the permission confirmation UI for the | |
464 // extension. The whitelist entry gets cleared in | |
465 // CrxInstaller::ConfirmInstall. | |
466 CrxInstaller::WhitelistEntry* entry = new CrxInstaller::WhitelistEntry; | |
467 entry->parsed_manifest.reset(parsed_manifest); | |
468 entry->use_app_installed_bubble = false; | |
469 entry->skip_post_install_ui = true; | |
470 CrxInstaller::SetWhitelistEntry(id_, entry); | |
471 | |
472 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | |
473 profile(), this, | |
474 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), | |
475 id_, WebstoreInstaller::FLAG_NONE); | |
476 installer->Start(); | |
477 } | |
478 | |
479 void SilentlyInstallFunction::OnWebstoreParseFailure( | |
480 const std::string& id, | |
481 InstallHelperResultCode result_code, | |
482 const std::string& error_message) { | |
483 CHECK_EQ(id_, id); | |
484 | |
485 error_ = error_message; | |
486 SendResponse(false); | |
487 | |
488 Release(); // Matches the AddRef() in RunImpl(). | |
489 } | |
490 | |
491 void SilentlyInstallFunction::OnExtensionInstallSuccess(const std::string& id) { | |
492 CHECK_EQ(id_, id); | |
493 | |
494 SendResponse(true); | |
495 | |
496 Release(); // Matches the AddRef() in RunImpl(). | |
497 } | |
498 | |
499 void SilentlyInstallFunction::OnExtensionInstallFailure( | |
500 const std::string& id, const std::string& error) { | |
501 CHECK_EQ(id_, id); | |
502 | |
503 error_ = error; | |
504 SendResponse(false); | |
505 | |
506 Release(); // Matches the AddRef() in RunImpl(). | |
507 } | |
508 | |
509 bool GetBrowserLoginFunction::RunImpl() { | 399 bool GetBrowserLoginFunction::RunImpl() { |
510 result_.reset(CreateLoginResult(profile_->GetOriginalProfile())); | 400 result_.reset(CreateLoginResult(profile_->GetOriginalProfile())); |
511 return true; | 401 return true; |
512 } | 402 } |
513 | 403 |
514 bool GetStoreLoginFunction::RunImpl() { | 404 bool GetStoreLoginFunction::RunImpl() { |
515 ExtensionService* service = profile_->GetExtensionService(); | 405 ExtensionService* service = profile_->GetExtensionService(); |
516 ExtensionPrefs* prefs = service->extension_prefs(); | 406 ExtensionPrefs* prefs = service->extension_prefs(); |
517 std::string login; | 407 std::string login; |
518 if (prefs->GetWebStoreLogin(&login)) { | 408 if (prefs->GetWebStoreLogin(&login)) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 SendResponse(true); | 476 SendResponse(true); |
587 } else { | 477 } else { |
588 // Matched with a Release in OnGpuInfoUpdate. | 478 // Matched with a Release in OnGpuInfoUpdate. |
589 AddRef(); | 479 AddRef(); |
590 | 480 |
591 manager->AddObserver(this); | 481 manager->AddObserver(this); |
592 manager->RequestCompleteGpuInfoIfNeeded(); | 482 manager->RequestCompleteGpuInfoIfNeeded(); |
593 } | 483 } |
594 return true; | 484 return true; |
595 } | 485 } |
OLD | NEW |