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/ui/webui/app_launcher_handler.h" | 5 #include "chrome/browser/ui/webui/app_launcher_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 extension_misc::AppLaunchBucket bucket = | 56 extension_misc::AppLaunchBucket bucket = |
57 static_cast<extension_misc::AppLaunchBucket>(bucket_num); | 57 static_cast<extension_misc::AppLaunchBucket>(bucket_num); |
58 CHECK(bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 58 CHECK(bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
59 return bucket; | 59 return bucket; |
60 } | 60 } |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) | 64 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) |
65 : extensions_service_(extension_service), | 65 : extensions_service_(extension_service), |
66 extension_prompt_type_(ExtensionInstallUI::UNSET_PROMPT_TYPE), | |
67 promo_active_(false), | 66 promo_active_(false), |
68 ignore_changes_(false) { | 67 ignore_changes_(false) { |
69 } | 68 } |
70 | 69 |
71 AppLauncherHandler::~AppLauncherHandler() {} | 70 AppLauncherHandler::~AppLauncherHandler() {} |
72 | 71 |
73 // static | 72 // static |
74 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 73 void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
75 ExtensionPrefs* prefs, | 74 ExtensionPrefs* prefs, |
76 DictionaryValue* value) { | 75 DictionaryValue* value) { |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); | 398 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
400 const Extension* extension = extensions_service_->GetExtensionById( | 399 const Extension* extension = extensions_service_->GetExtensionById( |
401 extension_id, false); | 400 extension_id, false); |
402 if (!extension) | 401 if (!extension) |
403 return; | 402 return; |
404 | 403 |
405 if (!extension_id_prompting_.empty()) | 404 if (!extension_id_prompting_.empty()) |
406 return; // Only one prompt at a time. | 405 return; // Only one prompt at a time. |
407 | 406 |
408 extension_id_prompting_ = extension_id; | 407 extension_id_prompting_ = extension_id; |
409 extension_prompt_type_ = ExtensionInstallUI::UNINSTALL_PROMPT; | 408 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension); |
410 GetExtensionInstallUI()->ConfirmUninstall(this, extension); | |
411 } | 409 } |
412 | 410 |
413 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { | 411 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { |
414 // If the user has intentionally hidden the promotion, we'll uninstall all the | 412 // If the user has intentionally hidden the promotion, we'll uninstall all the |
415 // default apps (we know the user hasn't installed any apps on their own at | 413 // default apps (we know the user hasn't installed any apps on their own at |
416 // this point, or the promotion wouldn't have been shown). | 414 // this point, or the promotion wouldn't have been shown). |
417 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, | 415 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
418 extension_misc::PROMO_CLOSE, | 416 extension_misc::PROMO_CLOSE, |
419 extension_misc::PROMO_BUCKET_BOUNDARY); | 417 extension_misc::PROMO_BUCKET_BOUNDARY); |
420 | 418 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 // Launch app asynchronously so the image will update. | 529 // Launch app asynchronously so the image will update. |
532 StringValue* app_id = Value::CreateStringValue(extension->id()); | 530 StringValue* app_id = Value::CreateStringValue(extension->id()); |
533 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); | 531 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); |
534 return; | 532 return; |
535 } | 533 } |
536 | 534 |
537 if (!extension_id_prompting_.empty()) | 535 if (!extension_id_prompting_.empty()) |
538 return; // Only one prompt at a time. | 536 return; // Only one prompt at a time. |
539 | 537 |
540 extension_id_prompting_ = extension_id; | 538 extension_id_prompting_ = extension_id; |
541 extension_prompt_type_ = ExtensionInstallUI::RE_ENABLE_PROMPT; | |
542 GetExtensionInstallUI()->ConfirmReEnable(this, extension); | 539 GetExtensionInstallUI()->ConfirmReEnable(this, extension); |
543 } | 540 } |
544 | 541 |
545 void AppLauncherHandler::InstallUIProceed() { | 542 void AppLauncherHandler::ExtensionDialogAccepted() { |
| 543 // Do the uninstall work here. |
546 DCHECK(!extension_id_prompting_.empty()); | 544 DCHECK(!extension_id_prompting_.empty()); |
547 | 545 |
548 // The extension can be uninstalled in another window while the UI was | 546 // The extension can be uninstalled in another window while the UI was |
| 547 // showing. Do nothing in that case. |
| 548 const Extension* extension = |
| 549 extensions_service_->GetExtensionById(extension_id_prompting_, true); |
| 550 if (!extension) |
| 551 return; |
| 552 |
| 553 extensions_service_->UninstallExtension(extension_id_prompting_, |
| 554 false /* external_uninstall */); |
| 555 |
| 556 extension_id_prompting_ = ""; |
| 557 } |
| 558 |
| 559 void AppLauncherHandler::ExtensionDialogCanceled() { |
| 560 extension_id_prompting_ = ""; |
| 561 } |
| 562 |
| 563 void AppLauncherHandler::InstallUIProceed() { |
| 564 // Do the re-enable work here. |
| 565 DCHECK(!extension_id_prompting_.empty()); |
| 566 |
| 567 // The extension can be uninstalled in another window while the UI was |
549 // showing. Do nothing in that case. | 568 // showing. Do nothing in that case. |
550 const Extension* extension = | 569 const Extension* extension = |
551 extensions_service_->GetExtensionById(extension_id_prompting_, true); | 570 extensions_service_->GetExtensionById(extension_id_prompting_, true); |
552 if (!extension) | 571 if (!extension) |
553 return; | 572 return; |
554 | 573 |
555 switch (extension_prompt_type_) { | 574 extensions_service_->GrantPermissionsAndEnableExtension(extension); |
556 case ExtensionInstallUI::UNINSTALL_PROMPT: | |
557 extensions_service_->UninstallExtension(extension_id_prompting_, | |
558 false /* external_uninstall */); | |
559 break; | |
560 case ExtensionInstallUI::RE_ENABLE_PROMPT: { | |
561 extensions_service_->GrantPermissionsAndEnableExtension(extension); | |
562 | 575 |
563 // We bounce this off the NTP so the browser can update the apps icon. | 576 // We bounce this off the NTP so the browser can update the apps icon. |
564 // If we don't launch the app asynchronously, then the app's disabled | 577 // If we don't launch the app asynchronously, then the app's disabled |
565 // icon disappears but isn't replaced by the enabled icon, making a poor | 578 // icon disappears but isn't replaced by the enabled icon, making a poor |
566 // visual experience. | 579 // visual experience. |
567 StringValue* app_id = Value::CreateStringValue(extension->id()); | 580 StringValue* app_id = Value::CreateStringValue(extension->id()); |
568 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); | 581 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); |
569 break; | |
570 } | |
571 default: | |
572 NOTREACHED(); | |
573 break; | |
574 } | |
575 | 582 |
576 extension_id_prompting_ = ""; | 583 extension_id_prompting_ = ""; |
577 } | 584 } |
578 | 585 |
579 void AppLauncherHandler::InstallUIAbort() { | 586 void AppLauncherHandler::InstallUIAbort() { |
580 extension_id_prompting_ = ""; | 587 ExtensionDialogCanceled(); |
| 588 } |
| 589 |
| 590 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
| 591 if (!extension_uninstall_dialog_.get()) { |
| 592 extension_uninstall_dialog_.reset( |
| 593 new ExtensionUninstallDialog(web_ui_->GetProfile())); |
| 594 } |
| 595 return extension_uninstall_dialog_.get(); |
581 } | 596 } |
582 | 597 |
583 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { | 598 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { |
584 if (!install_ui_.get()) | 599 if (!extension_install_ui_.get()) { |
585 install_ui_.reset(new ExtensionInstallUI(web_ui_->GetProfile())); | 600 extension_install_ui_.reset( |
586 return install_ui_.get(); | 601 new ExtensionInstallUI(web_ui_->GetProfile())); |
| 602 } |
| 603 return extension_install_ui_.get(); |
587 } | 604 } |
588 | 605 |
589 void AppLauncherHandler::UninstallDefaultApps() { | 606 void AppLauncherHandler::UninstallDefaultApps() { |
590 DefaultApps* default_apps = extensions_service_->default_apps(); | 607 DefaultApps* default_apps = extensions_service_->default_apps(); |
591 const ExtensionIdSet& app_ids = default_apps->default_apps(); | 608 const ExtensionIdSet& app_ids = default_apps->default_apps(); |
592 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 609 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
593 iter != app_ids.end(); ++iter) { | 610 iter != app_ids.end(); ++iter) { |
594 if (extensions_service_->GetExtensionById(*iter, true)) | 611 if (extensions_service_->GetExtensionById(*iter, true)) |
595 extensions_service_->UninstallExtension(*iter, false); | 612 extensions_service_->UninstallExtension(*iter, false); |
596 } | 613 } |
597 } | 614 } |
OLD | NEW |