| 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/api/webstore_private/webstore_private_api.h" | 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
| 6 | 6 |
| 7 #include "apps/app_launcher.h" | 7 #include "apps/app_launcher.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 41 #include "extensions/common/error_utils.h" | 41 #include "extensions/common/error_utils.h" |
| 42 #include "grit/chromium_strings.h" | 42 #include "grit/chromium_strings.h" |
| 43 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
| 44 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 45 | 45 |
| 46 using content::GpuDataManager; | 46 using content::GpuDataManager; |
| 47 | 47 |
| 48 namespace extensions { | 48 namespace extensions { |
| 49 | 49 |
| 50 namespace BeginInstallWithManifest3 = |
| 51 api::webstore_private::BeginInstallWithManifest3; |
| 52 namespace CompleteInstall = api::webstore_private::CompleteInstall; |
| 53 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; |
| 54 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; |
| 55 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; |
| 56 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
| 57 namespace InstallBundle = api::webstore_private::InstallBundle; |
| 58 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
| 59 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
| 60 |
| 50 namespace { | 61 namespace { |
| 51 | 62 |
| 52 // Holds the Approvals between the time we prompt and start the installs. | 63 // Holds the Approvals between the time we prompt and start the installs. |
| 53 class PendingApprovals { | 64 class PendingApprovals { |
| 54 public: | 65 public: |
| 55 PendingApprovals(); | 66 PendingApprovals(); |
| 56 ~PendingApprovals(); | 67 ~PendingApprovals(); |
| 57 | 68 |
| 58 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval); | 69 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval); |
| 59 scoped_ptr<WebstoreInstaller::Approval> PopApproval( | 70 scoped_ptr<WebstoreInstaller::Approval> PopApproval( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return (installs_.begin() + i); | 146 return (installs_.begin() + i); |
| 136 } | 147 } |
| 137 return installs_.end(); | 148 return installs_.end(); |
| 138 } | 149 } |
| 139 | 150 |
| 140 static base::LazyInstance<PendingApprovals> g_pending_approvals = | 151 static base::LazyInstance<PendingApprovals> g_pending_approvals = |
| 141 LAZY_INSTANCE_INITIALIZER; | 152 LAZY_INSTANCE_INITIALIZER; |
| 142 static base::LazyInstance<PendingInstalls> g_pending_installs = | 153 static base::LazyInstance<PendingInstalls> g_pending_installs = |
| 143 LAZY_INSTANCE_INITIALIZER; | 154 LAZY_INSTANCE_INITIALIZER; |
| 144 | 155 |
| 145 const char kAppInstallBubbleKey[] = "appInstallBubble"; | |
| 146 const char kEnableLauncherKey[] = "enableLauncher"; | |
| 147 const char kIconDataKey[] = "iconData"; | |
| 148 const char kIconUrlKey[] = "iconUrl"; | |
| 149 const char kIdKey[] = "id"; | |
| 150 const char kLocalizedNameKey[] = "localizedName"; | |
| 151 const char kLoginKey[] = "login"; | |
| 152 const char kManifestKey[] = "manifest"; | |
| 153 | |
| 154 // A preference set by the web store to indicate login information for | 156 // A preference set by the web store to indicate login information for |
| 155 // purchased apps. | 157 // purchased apps. |
| 156 const char kWebstoreLogin[] = "extensions.webstore_login"; | 158 const char kWebstoreLogin[] = "extensions.webstore_login"; |
| 157 const char kAlreadyInstalledError[] = "This item is already installed"; | 159 const char kAlreadyInstalledError[] = "This item is already installed"; |
| 158 const char kCannotSpecifyIconDataAndUrlError[] = | 160 const char kCannotSpecifyIconDataAndUrlError[] = |
| 159 "You cannot specify both icon data and an icon url"; | 161 "You cannot specify both icon data and an icon url"; |
| 160 const char kInvalidIconUrlError[] = "Invalid icon url"; | 162 const char kInvalidIconUrlError[] = "Invalid icon url"; |
| 161 const char kInvalidIdError[] = "Invalid id"; | 163 const char kInvalidIdError[] = "Invalid id"; |
| 162 const char kInvalidManifestError[] = "Invalid manifest"; | 164 const char kInvalidManifestError[] = "Invalid manifest"; |
| 163 const char kNoPreviousBeginInstallWithManifestError[] = | 165 const char kNoPreviousBeginInstallWithManifestError[] = |
| 164 "* does not match a previous call to beginInstallWithManifest3"; | 166 "* does not match a previous call to beginInstallWithManifest3"; |
| 165 const char kUserCancelledError[] = "User cancelled install"; | 167 const char kUserCancelledError[] = "User cancelled install"; |
| 166 | 168 |
| 167 // Helper to create a dictionary with login properties set from the appropriate | |
| 168 // values in the passed-in |profile|. | |
| 169 base::DictionaryValue* CreateLoginResult(Profile* profile) { | |
| 170 base::DictionaryValue* dictionary = new base::DictionaryValue(); | |
| 171 std::string username = profile->GetPrefs()->GetString( | |
| 172 prefs::kGoogleServicesUsername); | |
| 173 dictionary->SetString(kLoginKey, username); | |
| 174 return dictionary; | |
| 175 } | |
| 176 | |
| 177 WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; | 169 WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; |
| 178 | 170 |
| 179 // We allow the web store to set a string containing login information when a | 171 // We allow the web store to set a string containing login information when a |
| 180 // purchase is made, so that when a user logs into sync with a different | 172 // purchase is made, so that when a user logs into sync with a different |
| 181 // account we can recognize the situation. The Get function returns the login if | 173 // account we can recognize the situation. The Get function returns the login if |
| 182 // there was previously stored data, or an empty string otherwise. The Set will | 174 // there was previously stored data, or an empty string otherwise. The Set will |
| 183 // overwrite any previous login. | 175 // overwrite any previous login. |
| 184 std::string GetWebstoreLogin(Profile* profile) { | 176 std::string GetWebstoreLogin(Profile* profile) { |
| 185 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin)) | 177 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin)) |
| 186 return profile->GetPrefs()->GetString(kWebstoreLogin); | 178 return profile->GetPrefs()->GetString(kWebstoreLogin); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 203 scoped_ptr<WebstoreInstaller::Approval> | 195 scoped_ptr<WebstoreInstaller::Approval> |
| 204 WebstorePrivateApi::PopApprovalForTesting( | 196 WebstorePrivateApi::PopApprovalForTesting( |
| 205 Profile* profile, const std::string& extension_id) { | 197 Profile* profile, const std::string& extension_id) { |
| 206 return g_pending_approvals.Get().PopApproval(profile, extension_id); | 198 return g_pending_approvals.Get().PopApproval(profile, extension_id); |
| 207 } | 199 } |
| 208 | 200 |
| 209 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() {} | 201 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() {} |
| 210 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {} | 202 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {} |
| 211 | 203 |
| 212 bool WebstorePrivateInstallBundleFunction::RunImpl() { | 204 bool WebstorePrivateInstallBundleFunction::RunImpl() { |
| 213 base::ListValue* extensions = NULL; | 205 scoped_ptr<InstallBundle::Params> params( |
| 214 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); | 206 InstallBundle::Params::Create(*args_)); |
| 207 EXTENSION_FUNCTION_VALIDATE(params); |
| 215 | 208 |
| 216 BundleInstaller::ItemList items; | 209 BundleInstaller::ItemList items; |
| 217 if (!ReadBundleInfo(extensions, &items)) | 210 if (!ReadBundleInfo(*params, &items)) |
| 218 return false; | 211 return false; |
| 219 | 212 |
| 220 bundle_ = new BundleInstaller(GetCurrentBrowser(), items); | 213 bundle_ = new BundleInstaller(GetCurrentBrowser(), items); |
| 221 | 214 |
| 222 AddRef(); // Balanced in OnBundleInstallCompleted / OnBundleInstallCanceled. | 215 AddRef(); // Balanced in OnBundleInstallCompleted / OnBundleInstallCanceled. |
| 223 | 216 |
| 224 bundle_->PromptForApproval(this); | 217 bundle_->PromptForApproval(this); |
| 225 return true; | 218 return true; |
| 226 } | 219 } |
| 227 | 220 |
| 228 bool WebstorePrivateInstallBundleFunction:: | 221 bool WebstorePrivateInstallBundleFunction:: |
| 229 ReadBundleInfo(base::ListValue* extensions, | 222 ReadBundleInfo(const InstallBundle::Params& params, |
| 230 BundleInstaller::ItemList* items) { | 223 BundleInstaller::ItemList* items) { |
| 231 for (size_t i = 0; i < extensions->GetSize(); ++i) { | 224 for (size_t i = 0; i < params.details.size(); ++i) { |
| 232 base::DictionaryValue* details = NULL; | |
| 233 EXTENSION_FUNCTION_VALIDATE(extensions->GetDictionary(i, &details)); | |
| 234 | |
| 235 BundleInstaller::Item item; | 225 BundleInstaller::Item item; |
| 236 EXTENSION_FUNCTION_VALIDATE(details->GetString( | 226 item.id = params.details[i]->id; |
| 237 kIdKey, &item.id)); | 227 item.manifest = params.details[i]->manifest; |
| 238 EXTENSION_FUNCTION_VALIDATE(details->GetString( | 228 item.localized_name = params.details[i]->localized_name; |
| 239 kManifestKey, &item.manifest)); | |
| 240 EXTENSION_FUNCTION_VALIDATE(details->GetString( | |
| 241 kLocalizedNameKey, &item.localized_name)); | |
| 242 | |
| 243 items->push_back(item); | 229 items->push_back(item); |
| 244 } | 230 } |
| 245 | 231 |
| 246 return true; | 232 return true; |
| 247 } | 233 } |
| 248 | 234 |
| 249 void WebstorePrivateInstallBundleFunction::OnBundleInstallApproved() { | 235 void WebstorePrivateInstallBundleFunction::OnBundleInstallApproved() { |
| 250 bundle_->CompleteInstall( | 236 bundle_->CompleteInstall( |
| 251 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), | 237 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), |
| 252 this); | 238 this); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 264 Release(); // Balanced in RunImpl(). | 250 Release(); // Balanced in RunImpl(). |
| 265 } | 251 } |
| 266 | 252 |
| 267 void WebstorePrivateInstallBundleFunction::OnBundleInstallCompleted() { | 253 void WebstorePrivateInstallBundleFunction::OnBundleInstallCompleted() { |
| 268 SendResponse(true); | 254 SendResponse(true); |
| 269 | 255 |
| 270 Release(); // Balanced in RunImpl(). | 256 Release(); // Balanced in RunImpl(). |
| 271 } | 257 } |
| 272 | 258 |
| 273 WebstorePrivateBeginInstallWithManifest3Function:: | 259 WebstorePrivateBeginInstallWithManifest3Function:: |
| 274 WebstorePrivateBeginInstallWithManifest3Function() | 260 WebstorePrivateBeginInstallWithManifest3Function() {} |
| 275 : use_app_installed_bubble_(false), enable_launcher_(false) {} | |
| 276 | 261 |
| 277 WebstorePrivateBeginInstallWithManifest3Function:: | 262 WebstorePrivateBeginInstallWithManifest3Function:: |
| 278 ~WebstorePrivateBeginInstallWithManifest3Function() {} | 263 ~WebstorePrivateBeginInstallWithManifest3Function() {} |
| 279 | 264 |
| 280 bool WebstorePrivateBeginInstallWithManifest3Function::RunImpl() { | 265 bool WebstorePrivateBeginInstallWithManifest3Function::RunImpl() { |
| 281 base::DictionaryValue* details = NULL; | 266 params_ = BeginInstallWithManifest3::Params::Create(*args_); |
| 282 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 267 EXTENSION_FUNCTION_VALIDATE(params_); |
| 283 CHECK(details); | |
| 284 | 268 |
| 285 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_)); | 269 if (!extensions::Extension::IdIsValid(params_->details.id)) { |
| 286 if (!extensions::Extension::IdIsValid(id_)) { | |
| 287 SetResultCode(INVALID_ID); | 270 SetResultCode(INVALID_ID); |
| 288 error_ = kInvalidIdError; | 271 error_ = kInvalidIdError; |
| 289 return false; | 272 return false; |
| 290 } | 273 } |
| 291 | 274 |
| 292 EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest_)); | 275 if (params_->details.icon_data && params_->details.icon_url) { |
| 293 | |
| 294 if (details->HasKey(kIconDataKey) && details->HasKey(kIconUrlKey)) { | |
| 295 SetResultCode(ICON_ERROR); | 276 SetResultCode(ICON_ERROR); |
| 296 error_ = kCannotSpecifyIconDataAndUrlError; | 277 error_ = kCannotSpecifyIconDataAndUrlError; |
| 297 return false; | 278 return false; |
| 298 } | 279 } |
| 299 | 280 |
| 300 if (details->HasKey(kIconDataKey)) | |
| 301 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconDataKey, &icon_data_)); | |
| 302 | |
| 303 GURL icon_url; | 281 GURL icon_url; |
| 304 if (details->HasKey(kIconUrlKey)) { | 282 if (params_->details.icon_url) { |
| 305 std::string tmp_url; | 283 std::string tmp_url; |
| 306 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconUrlKey, &tmp_url)); | 284 icon_url = source_url().Resolve(*params_->details.icon_url); |
| 307 icon_url = source_url().Resolve(tmp_url); | |
| 308 if (!icon_url.is_valid()) { | 285 if (!icon_url.is_valid()) { |
| 309 SetResultCode(INVALID_ICON_URL); | 286 SetResultCode(INVALID_ICON_URL); |
| 310 error_ = kInvalidIconUrlError; | 287 error_ = kInvalidIconUrlError; |
| 311 return false; | 288 return false; |
| 312 } | 289 } |
| 313 } | 290 } |
| 314 | 291 |
| 315 if (details->HasKey(kLocalizedNameKey)) | 292 std::string icon_data = params_->details.icon_data ? |
| 316 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLocalizedNameKey, | 293 *params_->details.icon_data : std::string(); |
| 317 &localized_name_)); | |
| 318 | |
| 319 if (details->HasKey(kAppInstallBubbleKey)) | |
| 320 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean( | |
| 321 kAppInstallBubbleKey, &use_app_installed_bubble_)); | |
| 322 | |
| 323 if (details->HasKey(kEnableLauncherKey)) | |
| 324 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean( | |
| 325 kEnableLauncherKey, &enable_launcher_)); | |
| 326 | 294 |
| 327 ExtensionService* service = | 295 ExtensionService* service = |
| 328 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 296 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 329 if (service->GetInstalledExtension(id_) || | 297 if (service->GetInstalledExtension(params_->details.id) || |
| 330 !g_pending_installs.Get().InsertInstall(profile_, id_)) { | 298 !g_pending_installs.Get().InsertInstall(profile_, params_->details.id)) { |
| 331 SetResultCode(ALREADY_INSTALLED); | 299 SetResultCode(ALREADY_INSTALLED); |
| 332 error_ = kAlreadyInstalledError; | 300 error_ = kAlreadyInstalledError; |
| 333 return false; | 301 return false; |
| 334 } | 302 } |
| 335 | 303 |
| 336 net::URLRequestContextGetter* context_getter = NULL; | 304 net::URLRequestContextGetter* context_getter = NULL; |
| 337 if (!icon_url.is_empty()) | 305 if (!icon_url.is_empty()) |
| 338 context_getter = profile()->GetRequestContext(); | 306 context_getter = profile()->GetRequestContext(); |
| 339 | 307 |
| 340 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( | 308 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( |
| 341 this, id_, manifest_, icon_data_, icon_url, context_getter); | 309 this, params_->details.id, params_->details.manifest, icon_data, icon_url, |
| 310 context_getter); |
| 342 | 311 |
| 343 // The helper will call us back via OnWebstoreParseSuccess or | 312 // The helper will call us back via OnWebstoreParseSuccess or |
| 344 // OnWebstoreParseFailure. | 313 // OnWebstoreParseFailure. |
| 345 helper->Start(); | 314 helper->Start(); |
| 346 | 315 |
| 347 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. | 316 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. |
| 348 AddRef(); | 317 AddRef(); |
| 349 | 318 |
| 350 // The response is sent asynchronously in OnWebstoreParseSuccess/ | 319 // The response is sent asynchronously in OnWebstoreParseSuccess/ |
| 351 // OnWebstoreParseFailure. | 320 // OnWebstoreParseFailure. |
| 352 return true; | 321 return true; |
| 353 } | 322 } |
| 354 | 323 |
| 324 const char* WebstorePrivateBeginInstallWithManifest3Function:: |
| 325 ResultCodeToString(ResultCode code) { |
| 326 switch (code) { |
| 327 case ERROR_NONE: |
| 328 return ""; |
| 329 case UNKNOWN_ERROR: |
| 330 return "unknown_error"; |
| 331 case USER_CANCELLED: |
| 332 return "user_cancelled"; |
| 333 case MANIFEST_ERROR: |
| 334 return "manifest_error"; |
| 335 case ICON_ERROR: |
| 336 return "icon_error"; |
| 337 case INVALID_ID: |
| 338 return "invalid_id"; |
| 339 case PERMISSION_DENIED: |
| 340 return "permission_denied"; |
| 341 case INVALID_ICON_URL: |
| 342 return "invalid_icon_url"; |
| 343 case SIGNIN_FAILED: |
| 344 return "signin_failed"; |
| 345 case ALREADY_INSTALLED: |
| 346 return "already_installed"; |
| 347 } |
| 348 NOTREACHED(); |
| 349 return ""; |
| 350 } |
| 355 | 351 |
| 356 void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode( | 352 void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode( |
| 357 ResultCode code) { | 353 ResultCode code) { |
| 358 switch (code) { | 354 results_ = BeginInstallWithManifest3::Results::Create( |
| 359 case ERROR_NONE: | 355 ResultCodeToString(code)); |
| 360 SetResult(new base::StringValue(std::string())); | |
| 361 break; | |
| 362 case UNKNOWN_ERROR: | |
| 363 SetResult(new base::StringValue("unknown_error")); | |
| 364 break; | |
| 365 case USER_CANCELLED: | |
| 366 SetResult(new base::StringValue("user_cancelled")); | |
| 367 break; | |
| 368 case MANIFEST_ERROR: | |
| 369 SetResult(new base::StringValue("manifest_error")); | |
| 370 break; | |
| 371 case ICON_ERROR: | |
| 372 SetResult(new base::StringValue("icon_error")); | |
| 373 break; | |
| 374 case INVALID_ID: | |
| 375 SetResult(new base::StringValue("invalid_id")); | |
| 376 break; | |
| 377 case PERMISSION_DENIED: | |
| 378 SetResult(new base::StringValue("permission_denied")); | |
| 379 break; | |
| 380 case INVALID_ICON_URL: | |
| 381 SetResult(new base::StringValue("invalid_icon_url")); | |
| 382 break; | |
| 383 case SIGNIN_FAILED: | |
| 384 SetResult(new base::StringValue("signin_failed")); | |
| 385 break; | |
| 386 case ALREADY_INSTALLED: | |
| 387 SetResult(new base::StringValue("already_installed")); | |
| 388 break; | |
| 389 default: | |
| 390 CHECK(false); | |
| 391 } | |
| 392 } | 356 } |
| 393 | 357 |
| 394 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess( | 358 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess( |
| 395 const std::string& id, | 359 const std::string& id, |
| 396 const SkBitmap& icon, | 360 const SkBitmap& icon, |
| 397 base::DictionaryValue* parsed_manifest) { | 361 base::DictionaryValue* parsed_manifest) { |
| 398 CHECK_EQ(id_, id); | 362 CHECK_EQ(params_->details.id, id); |
| 399 CHECK(parsed_manifest); | 363 CHECK(parsed_manifest); |
| 400 icon_ = icon; | 364 icon_ = icon; |
| 401 parsed_manifest_.reset(parsed_manifest); | 365 parsed_manifest_.reset(parsed_manifest); |
| 402 | 366 |
| 367 std::string localized_name = params_->details.localized_name ? |
| 368 *params_->details.localized_name : std::string(); |
| 369 |
| 403 std::string error; | 370 std::string error; |
| 404 dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( | 371 dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
| 405 parsed_manifest_.get(), | 372 parsed_manifest_.get(), |
| 406 Extension::FROM_WEBSTORE, | 373 Extension::FROM_WEBSTORE, |
| 407 id, | 374 id, |
| 408 localized_name_, | 375 localized_name, |
| 409 std::string(), | 376 std::string(), |
| 410 &error); | 377 &error); |
| 411 | 378 |
| 412 if (!dummy_extension_.get()) { | 379 if (!dummy_extension_.get()) { |
| 413 OnWebstoreParseFailure(id_, | 380 OnWebstoreParseFailure(params_->details.id, |
| 414 WebstoreInstallHelper::Delegate::MANIFEST_ERROR, | 381 WebstoreInstallHelper::Delegate::MANIFEST_ERROR, |
| 415 kInvalidManifestError); | 382 kInvalidManifestError); |
| 416 return; | 383 return; |
| 417 } | 384 } |
| 418 | 385 |
| 419 SigninManagerBase* signin_manager = | 386 SigninManagerBase* signin_manager = |
| 420 SigninManagerFactory::GetForProfile(profile()); | 387 SigninManagerFactory::GetForProfile(profile()); |
| 421 if (dummy_extension_->is_platform_app() && | 388 if (dummy_extension_->is_platform_app() && |
| 422 signin_manager && | 389 signin_manager && |
| 423 signin_manager->GetAuthenticatedUsername().empty() && | 390 signin_manager->GetAuthenticatedUsername().empty() && |
| 424 signin_manager->AuthInProgress()) { | 391 signin_manager->AuthInProgress()) { |
| 425 signin_tracker_.reset(new SigninTracker(profile(), this)); | 392 signin_tracker_.reset(new SigninTracker(profile(), this)); |
| 426 return; | 393 return; |
| 427 } | 394 } |
| 428 | 395 |
| 429 SigninCompletedOrNotNeeded(); | 396 SigninCompletedOrNotNeeded(); |
| 430 } | 397 } |
| 431 | 398 |
| 432 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( | 399 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( |
| 433 const std::string& id, | 400 const std::string& id, |
| 434 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, | 401 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, |
| 435 const std::string& error_message) { | 402 const std::string& error_message) { |
| 436 CHECK_EQ(id_, id); | 403 CHECK_EQ(params_->details.id, id); |
| 437 | 404 |
| 438 // Map from WebstoreInstallHelper's result codes to ours. | 405 // Map from WebstoreInstallHelper's result codes to ours. |
| 439 switch (result_code) { | 406 switch (result_code) { |
| 440 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: | 407 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: |
| 441 SetResultCode(UNKNOWN_ERROR); | 408 SetResultCode(UNKNOWN_ERROR); |
| 442 break; | 409 break; |
| 443 case WebstoreInstallHelper::Delegate::ICON_ERROR: | 410 case WebstoreInstallHelper::Delegate::ICON_ERROR: |
| 444 SetResultCode(ICON_ERROR); | 411 SetResultCode(ICON_ERROR); |
| 445 break; | 412 break; |
| 446 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: | 413 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
| 447 SetResultCode(MANIFEST_ERROR); | 414 SetResultCode(MANIFEST_ERROR); |
| 448 break; | 415 break; |
| 449 default: | 416 default: |
| 450 CHECK(false); | 417 CHECK(false); |
| 451 } | 418 } |
| 452 error_ = error_message; | 419 error_ = error_message; |
| 453 g_pending_installs.Get().EraseInstall(profile_, id); | 420 g_pending_installs.Get().EraseInstall(profile_, id); |
| 454 SendResponse(false); | 421 SendResponse(false); |
| 455 | 422 |
| 456 // Matches the AddRef in RunImpl(). | 423 // Matches the AddRef in RunImpl(). |
| 457 Release(); | 424 Release(); |
| 458 } | 425 } |
| 459 | 426 |
| 460 void WebstorePrivateBeginInstallWithManifest3Function::SigninFailed( | 427 void WebstorePrivateBeginInstallWithManifest3Function::SigninFailed( |
| 461 const GoogleServiceAuthError& error) { | 428 const GoogleServiceAuthError& error) { |
| 462 signin_tracker_.reset(); | 429 signin_tracker_.reset(); |
| 463 | 430 |
| 464 SetResultCode(SIGNIN_FAILED); | 431 SetResultCode(SIGNIN_FAILED); |
| 465 error_ = error.ToString(); | 432 error_ = error.ToString(); |
| 466 g_pending_installs.Get().EraseInstall(profile_, id_); | 433 g_pending_installs.Get().EraseInstall(profile_, params_->details.id); |
| 467 SendResponse(false); | 434 SendResponse(false); |
| 468 | 435 |
| 469 // Matches the AddRef in RunImpl(). | 436 // Matches the AddRef in RunImpl(). |
| 470 Release(); | 437 Release(); |
| 471 } | 438 } |
| 472 | 439 |
| 473 void WebstorePrivateBeginInstallWithManifest3Function::SigninSuccess() { | 440 void WebstorePrivateBeginInstallWithManifest3Function::SigninSuccess() { |
| 474 signin_tracker_.reset(); | 441 signin_tracker_.reset(); |
| 475 | 442 |
| 476 SigninCompletedOrNotNeeded(); | 443 SigninCompletedOrNotNeeded(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 489 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); | 456 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 490 // Control flow finishes up in InstallUIProceed or InstallUIAbort. | 457 // Control flow finishes up in InstallUIProceed or InstallUIAbort. |
| 491 } | 458 } |
| 492 | 459 |
| 493 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { | 460 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { |
| 494 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in | 461 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in |
| 495 // the future we may also want to add time-based expiration, where a whitelist | 462 // the future we may also want to add time-based expiration, where a whitelist |
| 496 // entry is only valid for some number of minutes. | 463 // entry is only valid for some number of minutes. |
| 497 scoped_ptr<WebstoreInstaller::Approval> approval( | 464 scoped_ptr<WebstoreInstaller::Approval> approval( |
| 498 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 465 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
| 499 profile(), id_, parsed_manifest_.Pass())); | 466 profile(), params_->details.id, parsed_manifest_.Pass())); |
| 500 approval->use_app_installed_bubble = use_app_installed_bubble_; | 467 approval->use_app_installed_bubble = params_->details.app_install_bubble; |
| 501 approval->enable_launcher = enable_launcher_; | 468 approval->enable_launcher = params_->details.enable_launcher; |
| 502 // If we are enabling the launcher, we should not show the app list in order | 469 // If we are enabling the launcher, we should not show the app list in order |
| 503 // to train the user to open it themselves at least once. | 470 // to train the user to open it themselves at least once. |
| 504 approval->skip_post_install_ui = enable_launcher_; | 471 approval->skip_post_install_ui = params_->details.enable_launcher; |
| 505 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); | 472 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); |
| 506 g_pending_approvals.Get().PushApproval(approval.Pass()); | 473 g_pending_approvals.Get().PushApproval(approval.Pass()); |
| 507 | 474 |
| 508 SetResultCode(ERROR_NONE); | 475 SetResultCode(ERROR_NONE); |
| 509 SendResponse(true); | 476 SendResponse(true); |
| 510 | 477 |
| 511 // The Permissions_Install histogram is recorded from the ExtensionService | 478 // The Permissions_Install histogram is recorded from the ExtensionService |
| 512 // for all extension installs, so we only need to record the web store | 479 // for all extension installs, so we only need to record the web store |
| 513 // specific histogram here. | 480 // specific histogram here. |
| 514 ExtensionService::RecordPermissionMessagesHistogram( | 481 ExtensionService::RecordPermissionMessagesHistogram( |
| 515 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall"); | 482 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall"); |
| 516 | 483 |
| 517 // Matches the AddRef in RunImpl(). | 484 // Matches the AddRef in RunImpl(). |
| 518 Release(); | 485 Release(); |
| 519 } | 486 } |
| 520 | 487 |
| 521 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( | 488 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( |
| 522 bool user_initiated) { | 489 bool user_initiated) { |
| 523 error_ = kUserCancelledError; | 490 error_ = kUserCancelledError; |
| 524 SetResultCode(USER_CANCELLED); | 491 SetResultCode(USER_CANCELLED); |
| 525 g_pending_installs.Get().EraseInstall(profile_, id_); | 492 g_pending_installs.Get().EraseInstall(profile_, params_->details.id); |
| 526 SendResponse(false); | 493 SendResponse(false); |
| 527 | 494 |
| 528 // The web store install histograms are a subset of the install histograms. | 495 // The web store install histograms are a subset of the install histograms. |
| 529 // We need to record both histograms here since CrxInstaller::InstallUIAbort | 496 // We need to record both histograms here since CrxInstaller::InstallUIAbort |
| 530 // is never called for web store install cancellations. | 497 // is never called for web store install cancellations. |
| 531 std::string histogram_name = user_initiated ? | 498 std::string histogram_name = user_initiated ? |
| 532 "Extensions.Permissions_WebStoreInstallCancel" : | 499 "Extensions.Permissions_WebStoreInstallCancel" : |
| 533 "Extensions.Permissions_WebStoreInstallAbort"; | 500 "Extensions.Permissions_WebStoreInstallAbort"; |
| 534 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), | 501 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), |
| 535 histogram_name.c_str()); | 502 histogram_name.c_str()); |
| 536 | 503 |
| 537 histogram_name = user_initiated ? | 504 histogram_name = user_initiated ? |
| 538 "Extensions.Permissions_InstallCancel" : | 505 "Extensions.Permissions_InstallCancel" : |
| 539 "Extensions.Permissions_InstallAbort"; | 506 "Extensions.Permissions_InstallAbort"; |
| 540 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), | 507 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), |
| 541 histogram_name.c_str()); | 508 histogram_name.c_str()); |
| 542 | 509 |
| 543 // Matches the AddRef in RunImpl(). | 510 // Matches the AddRef in RunImpl(). |
| 544 Release(); | 511 Release(); |
| 545 } | 512 } |
| 546 | 513 |
| 547 WebstorePrivateCompleteInstallFunction:: | 514 WebstorePrivateCompleteInstallFunction:: |
| 548 WebstorePrivateCompleteInstallFunction() {} | 515 WebstorePrivateCompleteInstallFunction() {} |
| 549 | 516 |
| 550 WebstorePrivateCompleteInstallFunction:: | 517 WebstorePrivateCompleteInstallFunction:: |
| 551 ~WebstorePrivateCompleteInstallFunction() {} | 518 ~WebstorePrivateCompleteInstallFunction() {} |
| 552 | 519 |
| 553 bool WebstorePrivateCompleteInstallFunction::RunImpl() { | 520 bool WebstorePrivateCompleteInstallFunction::RunImpl() { |
| 554 std::string id; | 521 scoped_ptr<CompleteInstall::Params> params( |
| 555 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id)); | 522 CompleteInstall::Params::Create(*args_)); |
| 556 if (!extensions::Extension::IdIsValid(id)) { | 523 EXTENSION_FUNCTION_VALIDATE(params); |
| 524 if (!extensions::Extension::IdIsValid(params->expected_id)) { |
| 557 error_ = kInvalidIdError; | 525 error_ = kInvalidIdError; |
| 558 return false; | 526 return false; |
| 559 } | 527 } |
| 560 | 528 |
| 561 approval_ = g_pending_approvals.Get().PopApproval(profile(), id).Pass(); | 529 approval_ = g_pending_approvals.Get().PopApproval(profile(), |
| 530 params->expected_id).Pass(); |
| 562 if (!approval_) { | 531 if (!approval_) { |
| 563 error_ = ErrorUtils::FormatErrorMessage( | 532 error_ = ErrorUtils::FormatErrorMessage( |
| 564 kNoPreviousBeginInstallWithManifestError, id); | 533 kNoPreviousBeginInstallWithManifestError, params->expected_id); |
| 565 return false; | 534 return false; |
| 566 } | 535 } |
| 567 | 536 |
| 568 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure(). | 537 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure(). |
| 569 AddRef(); | 538 AddRef(); |
| 570 | 539 |
| 571 if (approval_->enable_launcher) | 540 if (approval_->enable_launcher) |
| 572 AppListService::Get()->EnableAppList(profile()); | 541 AppListService::Get()->EnableAppList(profile()); |
| 573 | 542 |
| 574 if (apps::IsAppLauncherEnabled() && approval_->manifest->is_app()) { | 543 if (apps::IsAppLauncherEnabled() && approval_->manifest->is_app()) { |
| 575 // Show the app list to show download is progressing. Don't show the app | 544 // Show the app list to show download is progressing. Don't show the app |
| 576 // list on first app install so users can be trained to open it themselves. | 545 // list on first app install so users can be trained to open it themselves. |
| 577 if (approval_->enable_launcher) | 546 if (approval_->enable_launcher) |
| 578 AppListService::Get()->CreateForProfile(profile()); | 547 AppListService::Get()->CreateForProfile(profile()); |
| 579 else | 548 else |
| 580 AppListService::Get()->ShowForProfile(profile()); | 549 AppListService::Get()->ShowForProfile(profile()); |
| 581 } | 550 } |
| 582 | 551 |
| 583 // The extension will install through the normal extension install flow, but | 552 // The extension will install through the normal extension install flow, but |
| 584 // the whitelist entry will bypass the normal permissions install dialog. | 553 // the whitelist entry will bypass the normal permissions install dialog. |
| 585 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | 554 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
| 586 profile(), this, | 555 profile(), this, |
| 587 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), | 556 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), |
| 588 id, approval_.Pass(), WebstoreInstaller::FLAG_NONE); | 557 params->expected_id, approval_.Pass(), WebstoreInstaller::FLAG_NONE); |
| 589 installer->Start(); | 558 installer->Start(); |
| 590 | 559 |
| 591 return true; | 560 return true; |
| 592 } | 561 } |
| 593 | 562 |
| 594 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallSuccess( | 563 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallSuccess( |
| 595 const std::string& id) { | 564 const std::string& id) { |
| 596 if (test_webstore_installer_delegate) | 565 if (test_webstore_installer_delegate) |
| 597 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); | 566 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); |
| 598 | 567 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 623 } | 592 } |
| 624 | 593 |
| 625 WebstorePrivateEnableAppLauncherFunction:: | 594 WebstorePrivateEnableAppLauncherFunction:: |
| 626 WebstorePrivateEnableAppLauncherFunction() {} | 595 WebstorePrivateEnableAppLauncherFunction() {} |
| 627 | 596 |
| 628 WebstorePrivateEnableAppLauncherFunction:: | 597 WebstorePrivateEnableAppLauncherFunction:: |
| 629 ~WebstorePrivateEnableAppLauncherFunction() {} | 598 ~WebstorePrivateEnableAppLauncherFunction() {} |
| 630 | 599 |
| 631 bool WebstorePrivateEnableAppLauncherFunction::RunImpl() { | 600 bool WebstorePrivateEnableAppLauncherFunction::RunImpl() { |
| 632 AppListService::Get()->EnableAppList(profile()); | 601 AppListService::Get()->EnableAppList(profile()); |
| 633 SendResponse(true); | |
| 634 return true; | 602 return true; |
| 635 } | 603 } |
| 636 | 604 |
| 637 bool WebstorePrivateGetBrowserLoginFunction::RunImpl() { | 605 bool WebstorePrivateGetBrowserLoginFunction::RunImpl() { |
| 638 SetResult(CreateLoginResult(profile_->GetOriginalProfile())); | 606 GetBrowserLogin::Results::Info info; |
| 607 info.login = profile_->GetOriginalProfile()->GetPrefs()->GetString( |
| 608 prefs::kGoogleServicesUsername); |
| 609 results_ = GetBrowserLogin::Results::Create(info); |
| 639 return true; | 610 return true; |
| 640 } | 611 } |
| 641 | 612 |
| 642 bool WebstorePrivateGetStoreLoginFunction::RunImpl() { | 613 bool WebstorePrivateGetStoreLoginFunction::RunImpl() { |
| 643 SetResult(new base::StringValue(GetWebstoreLogin(profile_))); | 614 results_ = GetStoreLogin::Results::Create(GetWebstoreLogin(profile_)); |
| 644 return true; | 615 return true; |
| 645 } | 616 } |
| 646 | 617 |
| 647 bool WebstorePrivateSetStoreLoginFunction::RunImpl() { | 618 bool WebstorePrivateSetStoreLoginFunction::RunImpl() { |
| 648 std::string login; | 619 scoped_ptr<SetStoreLogin::Params> params( |
| 649 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); | 620 SetStoreLogin::Params::Create(*args_)); |
| 650 SetWebstoreLogin(profile_, login); | 621 EXTENSION_FUNCTION_VALIDATE(params); |
| 622 SetWebstoreLogin(profile_, params->login); |
| 651 return true; | 623 return true; |
| 652 } | 624 } |
| 653 | 625 |
| 654 WebstorePrivateGetWebGLStatusFunction::WebstorePrivateGetWebGLStatusFunction() { | 626 WebstorePrivateGetWebGLStatusFunction::WebstorePrivateGetWebGLStatusFunction() { |
| 655 feature_checker_ = new GPUFeatureChecker( | 627 feature_checker_ = new GPUFeatureChecker( |
| 656 gpu::GPU_FEATURE_TYPE_WEBGL, | 628 gpu::GPU_FEATURE_TYPE_WEBGL, |
| 657 base::Bind(&WebstorePrivateGetWebGLStatusFunction::OnFeatureCheck, | 629 base::Bind(&WebstorePrivateGetWebGLStatusFunction::OnFeatureCheck, |
| 658 base::Unretained(this))); | 630 base::Unretained(this))); |
| 659 } | 631 } |
| 660 | 632 |
| 661 WebstorePrivateGetWebGLStatusFunction:: | 633 WebstorePrivateGetWebGLStatusFunction:: |
| 662 ~WebstorePrivateGetWebGLStatusFunction() {} | 634 ~WebstorePrivateGetWebGLStatusFunction() {} |
| 663 | 635 |
| 664 void WebstorePrivateGetWebGLStatusFunction::CreateResult(bool webgl_allowed) { | 636 void WebstorePrivateGetWebGLStatusFunction::CreateResult(bool webgl_allowed) { |
| 665 SetResult(new base::StringValue( | 637 results_ = GetWebGLStatus::Results::Create(GetWebGLStatus::Results:: |
| 666 webgl_allowed ? "webgl_allowed" : "webgl_blocked")); | 638 ParseWebgl_status(webgl_allowed ? "webgl_allowed" : "webgl_blocked")); |
| 667 } | 639 } |
| 668 | 640 |
| 669 bool WebstorePrivateGetWebGLStatusFunction::RunImpl() { | 641 bool WebstorePrivateGetWebGLStatusFunction::RunImpl() { |
| 670 feature_checker_->CheckGPUFeatureAvailability(); | 642 feature_checker_->CheckGPUFeatureAvailability(); |
| 671 return true; | 643 return true; |
| 672 } | 644 } |
| 673 | 645 |
| 674 void WebstorePrivateGetWebGLStatusFunction:: | 646 void WebstorePrivateGetWebGLStatusFunction:: |
| 675 OnFeatureCheck(bool feature_allowed) { | 647 OnFeatureCheck(bool feature_allowed) { |
| 676 CreateResult(feature_allowed); | 648 CreateResult(feature_allowed); |
| 677 SendResponse(true); | 649 SendResponse(true); |
| 678 } | 650 } |
| 679 | 651 |
| 680 bool WebstorePrivateGetIsLauncherEnabledFunction::RunImpl() { | 652 bool WebstorePrivateGetIsLauncherEnabledFunction::RunImpl() { |
| 681 SetResult(new base::FundamentalValue(apps::IsAppLauncherEnabled())); | 653 results_ = GetIsLauncherEnabled::Results::Create( |
| 682 SendResponse(true); | 654 apps::IsAppLauncherEnabled()); |
| 683 return true; | 655 return true; |
| 684 } | 656 } |
| 685 | 657 |
| 686 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { | 658 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { |
| 687 SetResult( | 659 results_ = IsInIncognitoMode::Results::Create( |
| 688 new base::FundamentalValue(profile_ != profile_->GetOriginalProfile())); | 660 profile_ != profile_->GetOriginalProfile()); |
| 689 SendResponse(true); | |
| 690 return true; | 661 return true; |
| 691 } | 662 } |
| 692 | 663 |
| 693 } // namespace extensions | 664 } // namespace extensions |
| OLD | NEW |