| 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 const char kTokenKey[] = "token"; | 45 const char kTokenKey[] = "token"; |
| 46 | 46 |
| 47 const char kCannotSpecifyIconDataAndUrlError[] = | 47 const char kCannotSpecifyIconDataAndUrlError[] = |
| 48 "You cannot specify both icon data and an icon url"; | 48 "You cannot specify both icon data and an icon url"; |
| 49 const char kInvalidIconUrlError[] = "Invalid icon url"; | 49 const char kInvalidIconUrlError[] = "Invalid icon url"; |
| 50 const char kInvalidIdError[] = "Invalid id"; | 50 const char kInvalidIdError[] = "Invalid id"; |
| 51 const char kInvalidManifestError[] = "Invalid manifest"; | 51 const char kInvalidManifestError[] = "Invalid manifest"; |
| 52 const char kNoPreviousBeginInstallWithManifestError[] = | 52 const char kNoPreviousBeginInstallWithManifestError[] = |
| 53 "* does not match a previous call to beginInstallWithManifest3"; | 53 "* does not match a previous call to beginInstallWithManifest3"; |
| 54 const char kUserCancelledError[] = "User cancelled install"; | 54 const char kUserCancelledError[] = "User cancelled install"; |
| 55 const char kNoPermissionError[] = |
| 56 "You do not have permission to use this method."; |
| 55 | 57 |
| 56 ProfileSyncService* test_sync_service = NULL; | 58 ProfileSyncService* test_sync_service = NULL; |
| 57 | 59 |
| 58 // Returns either the test sync service, or the real one from |profile|. | 60 // Returns either the test sync service, or the real one from |profile|. |
| 59 ProfileSyncService* GetSyncService(Profile* profile) { | 61 ProfileSyncService* GetSyncService(Profile* profile) { |
| 60 if (test_sync_service) | 62 if (test_sync_service) |
| 61 return test_sync_service; | 63 return test_sync_service; |
| 62 else | 64 else |
| 63 return profile->GetProfileSyncService(); | 65 return profile->GetProfileSyncService(); |
| 64 } | 66 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 ProfileSyncService* service) { | 104 ProfileSyncService* service) { |
| 103 test_sync_service = service; | 105 test_sync_service = service; |
| 104 } | 106 } |
| 105 | 107 |
| 106 // static | 108 // static |
| 107 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting( | 109 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting( |
| 108 WebstoreInstaller::Delegate* delegate) { | 110 WebstoreInstaller::Delegate* delegate) { |
| 109 test_webstore_installer_delegate = delegate; | 111 test_webstore_installer_delegate = delegate; |
| 110 } | 112 } |
| 111 | 113 |
| 114 InstallBundleFunction::InstallBundleFunction() {} |
| 115 InstallBundleFunction::~InstallBundleFunction() {} |
| 116 |
| 117 bool InstallBundleFunction::RunImpl() { |
| 118 if (!IsWebStoreURL(profile_, source_url())) { |
| 119 SetResult(PERMISSION_DENIED); |
| 120 return false; |
| 121 } |
| 122 |
| 123 ListValue* extensions = NULL; |
| 124 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); |
| 125 |
| 126 WebstoreBundle::ItemList items; |
| 127 if (!ReadBundleInfo(extensions, &items)) |
| 128 return false; |
| 129 |
| 130 bundle_ = new WebstoreBundle(profile(), &items); |
| 131 |
| 132 AddRef(); // Balanced in OnBundleInstallApproved and OnBundleInstallCanceled. |
| 133 |
| 134 bundle_->PromptForApproval(this); |
| 135 return true; |
| 136 } |
| 137 |
| 138 bool InstallBundleFunction::ReadBundleInfo( |
| 139 ListValue* extensions, WebstoreBundle::ItemList* items) { |
| 140 for (size_t i = 0; i < extensions->GetSize(); ++i) { |
| 141 DictionaryValue* details = NULL; |
| 142 EXTENSION_FUNCTION_VALIDATE(extensions->GetDictionary(i, &details)); |
| 143 |
| 144 std::string id; |
| 145 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id)); |
| 146 |
| 147 std::string manifest; |
| 148 EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest)); |
| 149 |
| 150 std::string localized_name; |
| 151 EXTENSION_FUNCTION_VALIDATE(details->GetString( |
| 152 kLocalizedNameKey, &localized_name)); |
| 153 |
| 154 // WebstoreBundle::Item ownership will be passed to WebstoreBundle. |
| 155 items->push_back(new WebstoreBundle::Item(id, manifest, localized_name)); |
| 156 } |
| 157 |
| 158 return true; |
| 159 } |
| 160 |
| 161 void InstallBundleFunction::OnBundleInstallApproved() { |
| 162 bundle_->CompleteInstall( |
| 163 &(dispatcher()->delegate()->GetAssociatedTabContents()->controller()), |
| 164 this); |
| 165 } |
| 166 |
| 167 void InstallBundleFunction::OnBundleInstallCanceled(bool user_initiated) { |
| 168 SetResult(user_initiated ? USER_CANCELLED : UNKNOWN_ERROR); |
| 169 SendResponse(false); |
| 170 |
| 171 Release(); // Balanced in RunImpl(). |
| 172 } |
| 173 |
| 174 void InstallBundleFunction::OnBundleInstallCompleted() { |
| 175 SetResult(ERROR_NONE); |
| 176 SendResponse(true); |
| 177 |
| 178 Release(); // Balanced in RunImpl(). |
| 179 } |
| 180 |
| 181 void InstallBundleFunction::SetResult(ErrorCode code) { |
| 182 switch (code) { |
| 183 case ERROR_NONE: |
| 184 result_.reset(Value::CreateStringValue("")); |
| 185 break; |
| 186 case UNKNOWN_ERROR: |
| 187 result_.reset(Value::CreateStringValue("unknown_error")); |
| 188 break; |
| 189 case USER_CANCELLED: |
| 190 result_.reset(Value::CreateStringValue("user_cancelled")); |
| 191 break; |
| 192 case PERMISSION_DENIED: |
| 193 result_.reset(Value::CreateStringValue("permission_denied")); |
| 194 break; |
| 195 default: |
| 196 CHECK(false); |
| 197 } |
| 198 } |
| 199 |
| 112 BeginInstallWithManifestFunction::BeginInstallWithManifestFunction() | 200 BeginInstallWithManifestFunction::BeginInstallWithManifestFunction() |
| 113 : use_app_installed_bubble_(false) {} | 201 : use_app_installed_bubble_(false) {} |
| 114 | 202 |
| 115 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {} | 203 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {} |
| 116 | 204 |
| 117 bool BeginInstallWithManifestFunction::RunImpl() { | 205 bool BeginInstallWithManifestFunction::RunImpl() { |
| 118 if (!IsWebStoreURL(profile_, source_url())) { | 206 if (!IsWebStoreURL(profile_, source_url())) { |
| 119 SetResult(PERMISSION_DENIED); | 207 SetResult(PERMISSION_DENIED); |
| 120 return false; | 208 return false; |
| 121 } | 209 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 bool SetStoreLoginFunction::RunImpl() { | 457 bool SetStoreLoginFunction::RunImpl() { |
| 370 if (!IsWebStoreURL(profile_, source_url())) | 458 if (!IsWebStoreURL(profile_, source_url())) |
| 371 return false; | 459 return false; |
| 372 std::string login; | 460 std::string login; |
| 373 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); | 461 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); |
| 374 ExtensionService* service = profile_->GetExtensionService(); | 462 ExtensionService* service = profile_->GetExtensionService(); |
| 375 ExtensionPrefs* prefs = service->extension_prefs(); | 463 ExtensionPrefs* prefs = service->extension_prefs(); |
| 376 prefs->SetWebStoreLogin(login); | 464 prefs->SetWebStoreLogin(login); |
| 377 return true; | 465 return true; |
| 378 } | 466 } |
| OLD | NEW |