| 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 "base/bind_helpers.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "base/version.h" | 15 #include "base/version.h" |
| 16 #include "chrome/browser/apps/ephemeral_app_launcher.h" | 16 #include "chrome/browser/apps/ephemeral_app_launcher.h" |
| 17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 45 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; | 45 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; |
| 46 namespace GetEphemeralAppsEnabled = | 46 namespace GetEphemeralAppsEnabled = |
| 47 api::webstore_private::GetEphemeralAppsEnabled; | 47 api::webstore_private::GetEphemeralAppsEnabled; |
| 48 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; | 48 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; |
| 49 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; | 49 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; |
| 50 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; | 50 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
| 51 namespace InstallBundle = api::webstore_private::InstallBundle; | 51 namespace InstallBundle = api::webstore_private::InstallBundle; |
| 52 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; | 52 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
| 53 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; | 53 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; |
| 54 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; | 54 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
| 55 namespace ShowPermissionPromptForDelegatedInstall = | |
| 56 api::webstore_private::ShowPermissionPromptForDelegatedInstall; | |
| 57 namespace ShowPermissionPromptForDelegatedBundleInstall = | |
| 58 api::webstore_private::ShowPermissionPromptForDelegatedBundleInstall; | |
| 59 | 55 |
| 60 namespace { | 56 namespace { |
| 61 | 57 |
| 62 // Holds the Approvals between the time we prompt and start the installs. | 58 // Holds the Approvals between the time we prompt and start the installs. |
| 63 class PendingApprovals { | 59 class PendingApprovals { |
| 64 public: | 60 public: |
| 65 PendingApprovals(); | 61 PendingApprovals(); |
| 66 ~PendingApprovals(); | 62 ~PendingApprovals(); |
| 67 | 63 |
| 68 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval); | 64 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 test_webstore_installer_delegate = delegate; | 201 test_webstore_installer_delegate = delegate; |
| 206 } | 202 } |
| 207 | 203 |
| 208 // static | 204 // static |
| 209 scoped_ptr<WebstoreInstaller::Approval> | 205 scoped_ptr<WebstoreInstaller::Approval> |
| 210 WebstorePrivateApi::PopApprovalForTesting( | 206 WebstorePrivateApi::PopApprovalForTesting( |
| 211 Profile* profile, const std::string& extension_id) { | 207 Profile* profile, const std::string& extension_id) { |
| 212 return g_pending_approvals.Get().PopApproval(profile, extension_id); | 208 return g_pending_approvals.Get().PopApproval(profile, extension_id); |
| 213 } | 209 } |
| 214 | 210 |
| 215 template<typename Params> | 211 WebstorePrivateBeginInstallWithManifest3Function:: |
| 216 WebstorePrivateFunctionWithPermissionPrompt<Params>:: | 212 WebstorePrivateBeginInstallWithManifest3Function() : chrome_details_(this) { |
| 217 WebstorePrivateFunctionWithPermissionPrompt() { | |
| 218 } | 213 } |
| 219 | 214 |
| 220 template<typename Params> | 215 WebstorePrivateBeginInstallWithManifest3Function:: |
| 221 WebstorePrivateFunctionWithPermissionPrompt<Params>:: | 216 ~WebstorePrivateBeginInstallWithManifest3Function() { |
| 222 ~WebstorePrivateFunctionWithPermissionPrompt() { | |
| 223 } | 217 } |
| 224 | 218 |
| 225 template<typename Params> | |
| 226 ExtensionFunction::ResponseValue | |
| 227 WebstorePrivateFunctionWithPermissionPrompt<Params>::RunExtraForResponse() { | |
| 228 return ExtensionFunction::ResponseValue(); | |
| 229 } | |
| 230 | |
| 231 template<typename Params> | |
| 232 ExtensionFunction::ResponseValue | |
| 233 WebstorePrivateFunctionWithPermissionPrompt<Params>::BuildResponse( | |
| 234 api::webstore_private::Result result, const std::string& error) { | |
| 235 if (result != api::webstore_private::RESULT_SUCCESS) | |
| 236 return ErrorWithArguments(CreateResults(result), error); | |
| 237 | |
| 238 // The web store expects an empty string on success, so don't use | |
| 239 // RESULT_SUCCESS here. | |
| 240 return ArgumentList( | |
| 241 CreateResults(api::webstore_private::RESULT_EMPTY_STRING)); | |
| 242 } | |
| 243 | |
| 244 template<typename Params> | |
| 245 scoped_ptr<base::DictionaryValue> | |
| 246 WebstorePrivateFunctionWithPermissionPrompt<Params>::PassParsedManifest() { | |
| 247 return parsed_manifest_.Pass(); | |
| 248 } | |
| 249 | |
| 250 template<typename Params> | |
| 251 ExtensionFunction::ResponseAction | 219 ExtensionFunction::ResponseAction |
| 252 WebstorePrivateFunctionWithPermissionPrompt<Params>::Run() { | 220 WebstorePrivateBeginInstallWithManifest3Function::Run() { |
| 253 params_ = Params::Create(*args_); | 221 params_ = Params::Create(*args_); |
| 254 EXTENSION_FUNCTION_VALIDATE(params_); | 222 EXTENSION_FUNCTION_VALIDATE(params_); |
| 255 | 223 |
| 256 if (!crx_file::id_util::IdIsValid(params_->details.id)) { | 224 if (!crx_file::id_util::IdIsValid(details().id)) { |
| 257 return RespondNow(BuildResponse(api::webstore_private::RESULT_INVALID_ID, | 225 return RespondNow(BuildResponse(api::webstore_private::RESULT_INVALID_ID, |
| 258 kInvalidIdError)); | 226 kInvalidIdError)); |
| 259 } | 227 } |
| 260 | 228 |
| 261 if (params_->details.icon_data && params_->details.icon_url) { | 229 if (details().icon_data && details().icon_url) { |
| 262 return RespondNow(BuildResponse(api::webstore_private::RESULT_ICON_ERROR, | 230 return RespondNow(BuildResponse(api::webstore_private::RESULT_ICON_ERROR, |
| 263 kCannotSpecifyIconDataAndUrlError)); | 231 kCannotSpecifyIconDataAndUrlError)); |
| 264 } | 232 } |
| 265 | 233 |
| 266 GURL icon_url; | 234 GURL icon_url; |
| 267 if (params_->details.icon_url) { | 235 if (details().icon_url) { |
| 268 icon_url = source_url().Resolve(*params_->details.icon_url); | 236 icon_url = source_url().Resolve(*details().icon_url); |
| 269 if (!icon_url.is_valid()) { | 237 if (!icon_url.is_valid()) { |
| 270 return RespondNow(BuildResponse( | 238 return RespondNow(BuildResponse( |
| 271 api::webstore_private::RESULT_INVALID_ICON_URL, | 239 api::webstore_private::RESULT_INVALID_ICON_URL, |
| 272 kInvalidIconUrlError)); | 240 kInvalidIconUrlError)); |
| 273 } | 241 } |
| 274 } | 242 } |
| 275 | 243 |
| 276 ExtensionFunction::ResponseValue response = RunExtraForResponse(); | 244 InstallTracker* tracker = InstallTracker::Get(browser_context()); |
| 277 if (response) | 245 DCHECK(tracker); |
| 278 return RespondNow(response.Pass()); | 246 if (util::IsExtensionInstalledPermanently(details().id, browser_context()) || |
| 247 tracker->GetActiveInstall(details().id)) { |
| 248 return RespondNow(BuildResponse( |
| 249 api::webstore_private::RESULT_ALREADY_INSTALLED, |
| 250 kAlreadyInstalledError)); |
| 251 } |
| 252 ActiveInstallData install_data(details().id); |
| 253 scoped_active_install_.reset(new ScopedActiveInstall(tracker, install_data)); |
| 279 | 254 |
| 280 net::URLRequestContextGetter* context_getter = nullptr; | 255 net::URLRequestContextGetter* context_getter = nullptr; |
| 281 if (!icon_url.is_empty()) | 256 if (!icon_url.is_empty()) |
| 282 context_getter = browser_context()->GetRequestContext(); | 257 context_getter = browser_context()->GetRequestContext(); |
| 283 | 258 |
| 284 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( | 259 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( |
| 285 this, params_->details.id, params_->details.manifest, icon_url, | 260 this, details().id, details().manifest, icon_url, context_getter); |
| 286 context_getter); | |
| 287 | 261 |
| 288 // The helper will call us back via OnWebstoreParseSuccess or | 262 // The helper will call us back via OnWebstoreParseSuccess or |
| 289 // OnWebstoreParseFailure. | 263 // OnWebstoreParseFailure. |
| 290 helper->Start(); | 264 helper->Start(); |
| 291 | 265 |
| 292 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. | 266 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. |
| 293 AddRef(); | 267 AddRef(); |
| 294 | 268 |
| 295 // The response is sent asynchronously in OnWebstoreParseSuccess/ | 269 // The response is sent asynchronously in OnWebstoreParseSuccess/ |
| 296 // OnWebstoreParseFailure. | 270 // OnWebstoreParseFailure. |
| 297 return RespondLater(); | 271 return RespondLater(); |
| 298 } | 272 } |
| 299 | 273 |
| 300 template<typename Params> | 274 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess( |
| 301 void | |
| 302 WebstorePrivateFunctionWithPermissionPrompt<Params>::OnWebstoreParseSuccess( | |
| 303 const std::string& id, | 275 const std::string& id, |
| 304 const SkBitmap& icon, | 276 const SkBitmap& icon, |
| 305 base::DictionaryValue* parsed_manifest) { | 277 base::DictionaryValue* parsed_manifest) { |
| 306 CHECK_EQ(params_->details.id, id); | 278 CHECK_EQ(details().id, id); |
| 307 CHECK(parsed_manifest); | 279 CHECK(parsed_manifest); |
| 280 parsed_manifest_.reset(parsed_manifest); |
| 308 icon_ = icon; | 281 icon_ = icon; |
| 309 parsed_manifest_.reset(parsed_manifest); | |
| 310 | 282 |
| 311 std::string localized_name = params_->details.localized_name ? | 283 std::string localized_name = |
| 312 *params_->details.localized_name : std::string(); | 284 details().localized_name ? *details().localized_name : std::string(); |
| 313 | 285 |
| 314 std::string error; | 286 std::string error; |
| 315 dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( | 287 dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
| 316 parsed_manifest_.get(), | 288 parsed_manifest_.get(), |
| 317 Extension::FROM_WEBSTORE, | 289 Extension::FROM_WEBSTORE, |
| 318 id, | 290 id, |
| 319 localized_name, | 291 localized_name, |
| 320 std::string(), | 292 std::string(), |
| 321 &error); | 293 &error); |
| 322 | 294 |
| 323 if (!dummy_extension_.get()) { | 295 if (!dummy_extension_.get()) { |
| 324 OnWebstoreParseFailure(params_->details.id, | 296 OnWebstoreParseFailure(details().id, |
| 325 WebstoreInstallHelper::Delegate::MANIFEST_ERROR, | 297 WebstoreInstallHelper::Delegate::MANIFEST_ERROR, |
| 326 kInvalidManifestError); | 298 kInvalidManifestError); |
| 327 return; | 299 return; |
| 328 } | 300 } |
| 329 | 301 |
| 330 content::WebContents* web_contents = GetAssociatedWebContents(); | 302 content::WebContents* web_contents = GetAssociatedWebContents(); |
| 331 if (!web_contents) { | 303 if (!web_contents) { |
| 332 // The browser window has gone away. | 304 // The browser window has gone away. |
| 333 Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED, | 305 Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED, |
| 334 kUserCancelledError)); | 306 kUserCancelledError)); |
| 335 // Matches the AddRef in Run(). | 307 // Matches the AddRef in Run(). |
| 336 Release(); | 308 Release(); |
| 337 return; | 309 return; |
| 338 } | 310 } |
| 339 install_prompt_.reset(new ExtensionInstallPrompt(web_contents)); | 311 install_prompt_.reset(new ExtensionInstallPrompt(web_contents)); |
| 340 ShowPrompt(install_prompt_.get()); | 312 install_prompt_->ConfirmWebstoreInstall( |
| 313 this, dummy_extension_.get(), &icon_, |
| 314 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 341 // Control flow finishes up in InstallUIProceed or InstallUIAbort. | 315 // Control flow finishes up in InstallUIProceed or InstallUIAbort. |
| 342 } | 316 } |
| 343 | 317 |
| 344 template<typename Params> | 318 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( |
| 345 void | |
| 346 WebstorePrivateFunctionWithPermissionPrompt<Params>::OnWebstoreParseFailure( | |
| 347 const std::string& id, | 319 const std::string& id, |
| 348 WebstoreInstallHelper::Delegate::InstallHelperResultCode result, | 320 WebstoreInstallHelper::Delegate::InstallHelperResultCode result, |
| 349 const std::string& error_message) { | 321 const std::string& error_message) { |
| 350 CHECK_EQ(params_->details.id, id); | 322 CHECK_EQ(details().id, id); |
| 351 | 323 |
| 352 Respond(BuildResponse(WebstoreInstallHelperResultToApiResult(result), | 324 Respond(BuildResponse(WebstoreInstallHelperResultToApiResult(result), |
| 353 error_message)); | 325 error_message)); |
| 354 | 326 |
| 355 // Matches the AddRef in Run(). | 327 // Matches the AddRef in Run(). |
| 356 Release(); | 328 Release(); |
| 357 } | 329 } |
| 358 | 330 |
| 359 template<typename Params> | 331 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { |
| 360 void WebstorePrivateFunctionWithPermissionPrompt<Params>::InstallUIProceed() { | |
| 361 InstallUIProceedHook(); | |
| 362 | |
| 363 Respond(BuildResponse(api::webstore_private::RESULT_SUCCESS, std::string())); | |
| 364 | |
| 365 // Matches the AddRef in Run(). | |
| 366 Release(); | |
| 367 } | |
| 368 | |
| 369 template<typename Params> | |
| 370 void WebstorePrivateFunctionWithPermissionPrompt<Params>::InstallUIAbort( | |
| 371 bool user_initiated) { | |
| 372 InstallUIAbortHook(user_initiated); | |
| 373 | |
| 374 Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED, | |
| 375 kUserCancelledError)); | |
| 376 | |
| 377 // Matches the AddRef in Run(). | |
| 378 Release(); | |
| 379 } | |
| 380 | |
| 381 WebstorePrivateBeginInstallWithManifest3Function:: | |
| 382 WebstorePrivateBeginInstallWithManifest3Function() : chrome_details_(this) { | |
| 383 } | |
| 384 | |
| 385 WebstorePrivateBeginInstallWithManifest3Function:: | |
| 386 ~WebstorePrivateBeginInstallWithManifest3Function() { | |
| 387 } | |
| 388 | |
| 389 ExtensionFunction::ResponseValue | |
| 390 WebstorePrivateBeginInstallWithManifest3Function::RunExtraForResponse() { | |
| 391 InstallTracker* tracker = InstallTracker::Get(browser_context()); | |
| 392 DCHECK(tracker); | |
| 393 if (util::IsExtensionInstalledPermanently(details().id, browser_context()) || | |
| 394 tracker->GetActiveInstall(details().id)) { | |
| 395 return BuildResponse(api::webstore_private::RESULT_ALREADY_INSTALLED, | |
| 396 kAlreadyInstalledError); | |
| 397 } | |
| 398 ActiveInstallData install_data(details().id); | |
| 399 scoped_active_install_.reset(new ScopedActiveInstall(tracker, install_data)); | |
| 400 return ExtensionFunction::ResponseValue(); | |
| 401 } | |
| 402 | |
| 403 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceedHook() { | |
| 404 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in | 332 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in |
| 405 // the future we may also want to add time-based expiration, where a whitelist | 333 // the future we may also want to add time-based expiration, where a whitelist |
| 406 // entry is only valid for some number of minutes. | 334 // entry is only valid for some number of minutes. |
| 407 scoped_ptr<WebstoreInstaller::Approval> approval( | 335 scoped_ptr<WebstoreInstaller::Approval> approval( |
| 408 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 336 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
| 409 chrome_details_.GetProfile(), | 337 chrome_details_.GetProfile(), |
| 410 details().id, | 338 details().id, |
| 411 PassParsedManifest(), | 339 parsed_manifest_.Pass(), |
| 412 false)); | 340 false)); |
| 413 approval->use_app_installed_bubble = details().app_install_bubble; | 341 approval->use_app_installed_bubble = details().app_install_bubble; |
| 414 approval->enable_launcher = details().enable_launcher; | 342 approval->enable_launcher = details().enable_launcher; |
| 415 // If we are enabling the launcher, we should not show the app list in order | 343 // If we are enabling the launcher, we should not show the app list in order |
| 416 // to train the user to open it themselves at least once. | 344 // to train the user to open it themselves at least once. |
| 417 approval->skip_post_install_ui = details().enable_launcher; | 345 approval->skip_post_install_ui = details().enable_launcher; |
| 418 approval->dummy_extension = dummy_extension(); | 346 approval->dummy_extension = dummy_extension_.get(); |
| 419 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon()); | 347 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); |
| 420 if (details().authuser) | 348 if (details().authuser) |
| 421 approval->authuser = *details().authuser; | 349 approval->authuser = *details().authuser; |
| 422 g_pending_approvals.Get().PushApproval(approval.Pass()); | 350 g_pending_approvals.Get().PushApproval(approval.Pass()); |
| 423 | 351 |
| 424 DCHECK(scoped_active_install_.get()); | 352 DCHECK(scoped_active_install_.get()); |
| 425 scoped_active_install_->CancelDeregister(); | 353 scoped_active_install_->CancelDeregister(); |
| 426 | 354 |
| 427 // The Permissions_Install histogram is recorded from the ExtensionService | 355 // The Permissions_Install histogram is recorded from the ExtensionService |
| 428 // for all extension installs, so we only need to record the web store | 356 // for all extension installs, so we only need to record the web store |
| 429 // specific histogram here. | 357 // specific histogram here. |
| 430 ExtensionService::RecordPermissionMessagesHistogram( | 358 ExtensionService::RecordPermissionMessagesHistogram( |
| 431 dummy_extension().get(), "WebStoreInstall"); | 359 dummy_extension_.get(), "WebStoreInstall"); |
| 360 |
| 361 Respond(BuildResponse(api::webstore_private::RESULT_SUCCESS, std::string())); |
| 362 |
| 363 // Matches the AddRef in Run(). |
| 364 Release(); |
| 432 } | 365 } |
| 433 | 366 |
| 434 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbortHook( | 367 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( |
| 435 bool user_initiated) { | 368 bool user_initiated) { |
| 436 // The web store install histograms are a subset of the install histograms. | 369 // The web store install histograms are a subset of the install histograms. |
| 437 // We need to record both histograms here since CrxInstaller::InstallUIAbort | 370 // We need to record both histograms here since CrxInstaller::InstallUIAbort |
| 438 // is never called for web store install cancellations. | 371 // is never called for web store install cancellations. |
| 439 std::string histogram_name = user_initiated ? "WebStoreInstallCancel" | 372 std::string histogram_name = user_initiated ? "WebStoreInstallCancel" |
| 440 : "WebStoreInstallAbort"; | 373 : "WebStoreInstallAbort"; |
| 441 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension().get(), | 374 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), |
| 442 histogram_name.c_str()); | 375 histogram_name.c_str()); |
| 443 | 376 |
| 444 histogram_name = user_initiated ? "InstallCancel" : "InstallAbort"; | 377 histogram_name = user_initiated ? "InstallCancel" : "InstallAbort"; |
| 445 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension().get(), | 378 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), |
| 446 histogram_name.c_str()); | 379 histogram_name.c_str()); |
| 380 |
| 381 Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED, |
| 382 kUserCancelledError)); |
| 383 |
| 384 // Matches the AddRef in Run(). |
| 385 Release(); |
| 447 } | 386 } |
| 448 | 387 |
| 449 void WebstorePrivateBeginInstallWithManifest3Function::ShowPrompt( | 388 ExtensionFunction::ResponseValue |
| 450 ExtensionInstallPrompt* install_prompt) { | 389 WebstorePrivateBeginInstallWithManifest3Function::BuildResponse( |
| 451 install_prompt->ConfirmWebstoreInstall( | 390 api::webstore_private::Result result, const std::string& error) { |
| 452 this, dummy_extension().get(), &icon(), | 391 if (result != api::webstore_private::RESULT_SUCCESS) |
| 453 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); | 392 return ErrorWithArguments(CreateResults(result), error); |
| 393 |
| 394 // The web store expects an empty string on success, so don't use |
| 395 // RESULT_SUCCESS here. |
| 396 return ArgumentList( |
| 397 CreateResults(api::webstore_private::RESULT_EMPTY_STRING)); |
| 454 } | 398 } |
| 455 | 399 |
| 456 scoped_ptr<base::ListValue> | 400 scoped_ptr<base::ListValue> |
| 457 WebstorePrivateBeginInstallWithManifest3Function::CreateResults( | 401 WebstorePrivateBeginInstallWithManifest3Function::CreateResults( |
| 458 api::webstore_private::Result result) const { | 402 api::webstore_private::Result result) const { |
| 459 return BeginInstallWithManifest3::Results::Create(result); | 403 return BeginInstallWithManifest3::Results::Create(result); |
| 460 } | 404 } |
| 461 | 405 |
| 462 WebstorePrivateCompleteInstallFunction:: | 406 WebstorePrivateCompleteInstallFunction:: |
| 463 WebstorePrivateCompleteInstallFunction() : chrome_details_(this) {} | 407 WebstorePrivateCompleteInstallFunction() : chrome_details_(this) {} |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 // Matches the AddRef in Run(). | 511 // Matches the AddRef in Run(). |
| 568 Release(); | 512 Release(); |
| 569 } | 513 } |
| 570 | 514 |
| 571 void WebstorePrivateCompleteInstallFunction::OnInstallSuccess( | 515 void WebstorePrivateCompleteInstallFunction::OnInstallSuccess( |
| 572 const std::string& id) { | 516 const std::string& id) { |
| 573 if (test_webstore_installer_delegate) | 517 if (test_webstore_installer_delegate) |
| 574 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); | 518 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); |
| 575 } | 519 } |
| 576 | 520 |
| 577 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: | 521 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() |
| 578 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() { | 522 : chrome_details_(this) { |
| 579 } | 523 } |
| 580 | 524 |
| 581 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: | 525 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() { |
| 582 ~WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() { | |
| 583 } | 526 } |
| 584 | 527 |
| 585 void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::ShowPrompt( | 528 ExtensionFunction::ResponseAction WebstorePrivateInstallBundleFunction::Run() { |
| 586 ExtensionInstallPrompt* install_prompt) { | |
| 587 install_prompt->ConfirmPermissionsForDelegatedInstall( | |
| 588 this, dummy_extension().get(), details().delegated_user, &icon()); | |
| 589 } | |
| 590 | |
| 591 scoped_ptr<base::ListValue> | |
| 592 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::CreateResults( | |
| 593 api::webstore_private::Result result) const { | |
| 594 return ShowPermissionPromptForDelegatedInstall::Results::Create(result); | |
| 595 } | |
| 596 | |
| 597 template<typename Params> | |
| 598 WebstorePrivateFunctionWithBundle<Params>::WebstorePrivateFunctionWithBundle() | |
| 599 : chrome_details_(this) { | |
| 600 } | |
| 601 | |
| 602 template<typename Params> | |
| 603 WebstorePrivateFunctionWithBundle<Params>:: | |
| 604 ~WebstorePrivateFunctionWithBundle() { | |
| 605 } | |
| 606 | |
| 607 template<typename Params> | |
| 608 ExtensionFunction::ResponseAction | |
| 609 WebstorePrivateFunctionWithBundle<Params>::Run() { | |
| 610 params_ = Params::Create(*args_); | 529 params_ = Params::Create(*args_); |
| 611 EXTENSION_FUNCTION_VALIDATE(params_); | 530 EXTENSION_FUNCTION_VALIDATE(params_); |
| 612 | 531 |
| 613 if (params_->contents.empty()) | 532 if (params_->contents.empty()) |
| 614 return RespondNow(Error(kInvalidBundleError)); | 533 return RespondNow(Error(kInvalidBundleError)); |
| 615 | 534 |
| 616 if (params_->details.icon_url) { | 535 if (details().icon_url) { |
| 617 GURL icon_url = source_url().Resolve(*params_->details.icon_url); | 536 GURL icon_url = source_url().Resolve(*details().icon_url); |
| 618 if (!icon_url.is_valid()) | 537 if (!icon_url.is_valid()) |
| 619 return RespondNow(Error(kInvalidIconUrlError)); | 538 return RespondNow(Error(kInvalidIconUrlError)); |
| 620 | 539 |
| 621 // The bitmap fetcher will call us back via OnFetchComplete. | 540 // The bitmap fetcher will call us back via OnFetchComplete. |
| 622 icon_fetcher_.reset(new chrome::BitmapFetcher(icon_url, this)); | 541 icon_fetcher_.reset(new chrome::BitmapFetcher(icon_url, this)); |
| 623 icon_fetcher_->Init( | 542 icon_fetcher_->Init( |
| 624 browser_context()->GetRequestContext(), std::string(), | 543 browser_context()->GetRequestContext(), std::string(), |
| 625 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 544 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 626 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES); | 545 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES); |
| 627 icon_fetcher_->Start(); | 546 icon_fetcher_->Start(); |
| 628 } else { | 547 } else { |
| 629 base::ThreadTaskRunnerHandle::Get()->PostTask( | 548 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 630 FROM_HERE, | 549 FROM_HERE, |
| 631 base::Bind(&WebstorePrivateFunctionWithBundle::OnFetchComplete, | 550 base::Bind(&WebstorePrivateInstallBundleFunction::OnFetchComplete, |
| 632 this, GURL(), nullptr)); | 551 this, GURL(), nullptr)); |
| 633 } | 552 } |
| 634 | 553 |
| 635 AddRef(); // Balanced in OnFetchComplete. | 554 AddRef(); // Balanced in OnFetchComplete. |
| 636 | 555 |
| 637 // The response is sent asynchronously in OnFetchComplete, OnInstallApproval, | 556 // The response is sent asynchronously in OnFetchComplete, OnInstallApproval, |
| 638 // or OnInstallComplete. | 557 // or OnInstallComplete. |
| 639 return RespondLater(); | 558 return RespondLater(); |
| 640 } | 559 } |
| 641 | 560 |
| 642 template<typename Params> | 561 void WebstorePrivateInstallBundleFunction::OnFetchComplete( |
| 643 void WebstorePrivateFunctionWithBundle<Params>::OnFetchComplete( | |
| 644 const GURL& url, const SkBitmap* bitmap) { | 562 const GURL& url, const SkBitmap* bitmap) { |
| 645 BundleInstaller::ItemList items; | 563 BundleInstaller::ItemList items; |
| 646 for (const auto& entry : params_->contents) { | 564 for (const auto& entry : params_->contents) { |
| 647 if (ShouldSkipItem(entry->id)) | 565 // Skip already-installed items. |
| 566 if (util::IsExtensionInstalledPermanently(entry->id, browser_context()) || |
| 567 InstallTracker::Get(browser_context())->GetActiveInstall(entry->id)) { |
| 648 continue; | 568 continue; |
| 569 } |
| 649 BundleInstaller::Item item; | 570 BundleInstaller::Item item; |
| 650 item.id = entry->id; | 571 item.id = entry->id; |
| 651 item.manifest = entry->manifest; | 572 item.manifest = entry->manifest; |
| 652 item.localized_name = entry->localized_name; | 573 item.localized_name = entry->localized_name; |
| 653 if (entry->icon_url) | 574 if (entry->icon_url) |
| 654 item.icon_url = source_url().Resolve(*entry->icon_url); | 575 item.icon_url = source_url().Resolve(*entry->icon_url); |
| 655 items.push_back(item); | 576 items.push_back(item); |
| 656 } | 577 } |
| 657 if (items.empty()) { | 578 if (items.empty()) { |
| 658 Respond(Error(kAlreadyInstalledError)); | 579 Respond(Error(kAlreadyInstalledError)); |
| 659 Release(); // Matches the AddRef in Run. | 580 Release(); // Matches the AddRef in Run. |
| 660 return; | 581 return; |
| 661 } | 582 } |
| 662 | 583 |
| 584 std::string authuser = |
| 585 details().authuser ? *details().authuser : std::string(); |
| 663 bundle_.reset(new BundleInstaller(chrome_details_.GetCurrentBrowser(), | 586 bundle_.reset(new BundleInstaller(chrome_details_.GetCurrentBrowser(), |
| 664 params_->details.localized_name, | 587 details().localized_name, |
| 665 bitmap ? *bitmap : SkBitmap(), | 588 bitmap ? *bitmap : SkBitmap(), authuser, |
| 666 auth_user_, delegated_user_, items)); | 589 std::string(), items)); |
| 667 | 590 |
| 668 bundle_->PromptForApproval( | 591 bundle_->PromptForApproval(base::Bind( |
| 669 base::Bind(&WebstorePrivateFunctionWithBundle::OnInstallApproval, this)); | 592 &WebstorePrivateInstallBundleFunction::OnInstallApproval, this)); |
| 670 | 593 |
| 671 Release(); // Matches the AddRef in Run. | 594 Release(); // Matches the AddRef in Run. |
| 672 } | 595 } |
| 673 | 596 |
| 674 template<typename Params> | 597 void WebstorePrivateInstallBundleFunction::OnInstallApproval( |
| 675 void WebstorePrivateFunctionWithBundle<Params>::OnInstallApproval( | |
| 676 BundleInstaller::ApprovalState state) { | 598 BundleInstaller::ApprovalState state) { |
| 677 if (state != BundleInstaller::APPROVED) { | 599 if (state != BundleInstaller::APPROVED) { |
| 678 Respond(Error(state == BundleInstaller::USER_CANCELED | 600 Respond(Error(state == BundleInstaller::USER_CANCELED |
| 679 ? kUserCancelledError | 601 ? kUserCancelledError |
| 680 : kInvalidBundleError)); | 602 : kInvalidBundleError)); |
| 681 return; | 603 return; |
| 682 } | 604 } |
| 683 | 605 |
| 684 OnInstallApprovalHook(); | |
| 685 } | |
| 686 | |
| 687 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() { | |
| 688 } | |
| 689 | |
| 690 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() { | |
| 691 } | |
| 692 | |
| 693 void WebstorePrivateInstallBundleFunction::ProcessParams() { | |
| 694 if (details().authuser) | |
| 695 set_auth_user(*details().authuser); | |
| 696 } | |
| 697 | |
| 698 bool WebstorePrivateInstallBundleFunction::ShouldSkipItem( | |
| 699 const std::string& id) const { | |
| 700 // Skip already-installed items. | |
| 701 return util::IsExtensionInstalledPermanently(id, browser_context()) || | |
| 702 InstallTracker::Get(browser_context())->GetActiveInstall(id); | |
| 703 } | |
| 704 | |
| 705 void WebstorePrivateInstallBundleFunction::OnInstallApprovalHook() { | |
| 706 // The bundle installer will call us back via OnInstallComplete. | 606 // The bundle installer will call us back via OnInstallComplete. |
| 707 bundle()->CompleteInstall( | 607 bundle_->CompleteInstall( |
| 708 GetSenderWebContents(), | 608 GetSenderWebContents(), |
| 709 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallComplete, | 609 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallComplete, |
| 710 this)); | 610 this)); |
| 711 } | 611 } |
| 712 | 612 |
| 713 void WebstorePrivateInstallBundleFunction::OnInstallComplete() { | 613 void WebstorePrivateInstallBundleFunction::OnInstallComplete() { |
| 714 Respond(NoArguments()); | 614 Respond(NoArguments()); |
| 715 } | 615 } |
| 716 | 616 |
| 717 WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction:: | |
| 718 WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction() { | |
| 719 } | |
| 720 | |
| 721 WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction:: | |
| 722 ~WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction() { | |
| 723 } | |
| 724 | |
| 725 void WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction:: | |
| 726 ProcessParams() { | |
| 727 set_delegated_user(details().delegated_user); | |
| 728 } | |
| 729 | |
| 730 bool WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction:: | |
| 731 ShouldSkipItem(const std::string& id) const { | |
| 732 // For delegated installs, don't skip any items (we don't know if any are | |
| 733 // installed already). | |
| 734 return false; | |
| 735 } | |
| 736 | |
| 737 void WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction:: | |
| 738 OnInstallApprovalHook() { | |
| 739 Respond(NoArguments()); | |
| 740 } | |
| 741 | |
| 742 WebstorePrivateEnableAppLauncherFunction:: | 617 WebstorePrivateEnableAppLauncherFunction:: |
| 743 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {} | 618 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {} |
| 744 | 619 |
| 745 WebstorePrivateEnableAppLauncherFunction:: | 620 WebstorePrivateEnableAppLauncherFunction:: |
| 746 ~WebstorePrivateEnableAppLauncherFunction() {} | 621 ~WebstorePrivateEnableAppLauncherFunction() {} |
| 747 | 622 |
| 748 ExtensionFunction::ResponseAction | 623 ExtensionFunction::ResponseAction |
| 749 WebstorePrivateEnableAppLauncherFunction::Run() { | 624 WebstorePrivateEnableAppLauncherFunction::Run() { |
| 750 AppListService* app_list_service = AppListService::Get( | 625 AppListService* app_list_service = AppListService::Get( |
| 751 GetHostDesktopTypeForWebContents( | 626 GetHostDesktopTypeForWebContents( |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 WebstorePrivateGetEphemeralAppsEnabledFunction:: | 787 WebstorePrivateGetEphemeralAppsEnabledFunction:: |
| 913 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} | 788 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} |
| 914 | 789 |
| 915 ExtensionFunction::ResponseAction | 790 ExtensionFunction::ResponseAction |
| 916 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { | 791 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { |
| 917 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( | 792 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( |
| 918 EphemeralAppLauncher::IsFeatureEnabled()))); | 793 EphemeralAppLauncher::IsFeatureEnabled()))); |
| 919 } | 794 } |
| 920 | 795 |
| 921 } // namespace extensions | 796 } // namespace extensions |
| OLD | NEW |