Chromium Code Reviews| 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), | 66 is_uninstall_dialog_(false), |
| 67 promo_active_(false), | 67 promo_active_(false), |
| 68 ignore_changes_(false) { | 68 ignore_changes_(false) { |
| 69 } | 69 } |
| 70 | 70 |
| 71 AppLauncherHandler::~AppLauncherHandler() {} | 71 AppLauncherHandler::~AppLauncherHandler() {} |
| 72 | 72 |
| 73 // static | 73 // static |
| 74 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 74 void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
| 75 ExtensionPrefs* prefs, | 75 ExtensionPrefs* prefs, |
| 76 DictionaryValue* value) { | 76 DictionaryValue* value) { |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); | 399 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| 400 const Extension* extension = extensions_service_->GetExtensionById( | 400 const Extension* extension = extensions_service_->GetExtensionById( |
| 401 extension_id, false); | 401 extension_id, false); |
| 402 if (!extension) | 402 if (!extension) |
| 403 return; | 403 return; |
| 404 | 404 |
| 405 if (!extension_id_prompting_.empty()) | 405 if (!extension_id_prompting_.empty()) |
| 406 return; // Only one prompt at a time. | 406 return; // Only one prompt at a time. |
| 407 | 407 |
| 408 extension_id_prompting_ = extension_id; | 408 extension_id_prompting_ = extension_id; |
| 409 extension_prompt_type_ = ExtensionInstallUI::UNINSTALL_PROMPT; | 409 is_uninstall_dialog_ = true; |
| 410 GetExtensionInstallUI()->ConfirmUninstall(this, extension); | 410 GetExtensionGenericDialog()->ConfirmUninstall(this, extension); |
| 411 } | 411 } |
| 412 | 412 |
| 413 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { | 413 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { |
| 414 // If the user has intentionally hidden the promotion, we'll uninstall all the | 414 // 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 | 415 // 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). | 416 // this point, or the promotion wouldn't have been shown). |
| 417 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, | 417 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
| 418 extension_misc::PROMO_CLOSE, | 418 extension_misc::PROMO_CLOSE, |
| 419 extension_misc::PROMO_BUCKET_BOUNDARY); | 419 extension_misc::PROMO_BUCKET_BOUNDARY); |
| 420 | 420 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 // Launch app asynchronously so the image will update. | 531 // Launch app asynchronously so the image will update. |
| 532 StringValue* app_id = Value::CreateStringValue(extension->id()); | 532 StringValue* app_id = Value::CreateStringValue(extension->id()); |
| 533 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); | 533 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); |
| 534 return; | 534 return; |
| 535 } | 535 } |
| 536 | 536 |
| 537 if (!extension_id_prompting_.empty()) | 537 if (!extension_id_prompting_.empty()) |
| 538 return; // Only one prompt at a time. | 538 return; // Only one prompt at a time. |
| 539 | 539 |
| 540 extension_id_prompting_ = extension_id; | 540 extension_id_prompting_ = extension_id; |
| 541 extension_prompt_type_ = ExtensionInstallUI::RE_ENABLE_PROMPT; | 541 is_uninstall_dialog_ = false; |
| 542 GetExtensionInstallUI()->ConfirmReEnable(this, extension); | 542 GetExtensionInstallUI()->ConfirmReEnable(this, extension); |
| 543 } | 543 } |
| 544 | 544 |
| 545 void AppLauncherHandler::InstallUIProceed() { | 545 void AppLauncherHandler::ExtensionDialogAccepted() { |
| 546 DCHECK(!extension_id_prompting_.empty()); | 546 DCHECK(!extension_id_prompting_.empty()); |
| 547 | 547 |
| 548 // The extension can be uninstalled in another window while the UI was | 548 // The extension can be uninstalled in another window while the UI was |
| 549 // showing. Do nothing in that case. | 549 // showing. Do nothing in that case. |
| 550 const Extension* extension = | 550 const Extension* extension = |
| 551 extensions_service_->GetExtensionById(extension_id_prompting_, true); | 551 extensions_service_->GetExtensionById(extension_id_prompting_, true); |
| 552 if (!extension) | 552 if (!extension) |
| 553 return; | 553 return; |
| 554 | 554 |
| 555 switch (extension_prompt_type_) { | 555 if (is_uninstall_dialog_) { |
| 556 case ExtensionInstallUI::UNINSTALL_PROMPT: | |
| 557 extensions_service_->UninstallExtension(extension_id_prompting_, | 556 extensions_service_->UninstallExtension(extension_id_prompting_, |
| 558 false /* external_uninstall */); | 557 false /* external_uninstall */); |
| 559 break; | 558 } else { |
| 560 case ExtensionInstallUI::RE_ENABLE_PROMPT: { | |
| 561 extensions_service_->GrantPermissionsAndEnableExtension(extension); | 559 extensions_service_->GrantPermissionsAndEnableExtension(extension); |
| 562 | 560 |
| 563 // We bounce this off the NTP so the browser can update the apps icon. | 561 // 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 | 562 // 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 | 563 // icon disappears but isn't replaced by the enabled icon, making a poor |
| 566 // visual experience. | 564 // visual experience. |
| 567 StringValue* app_id = Value::CreateStringValue(extension->id()); | 565 StringValue* app_id = Value::CreateStringValue(extension->id()); |
| 568 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); | 566 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); |
| 569 break; | |
| 570 } | |
| 571 default: | |
| 572 NOTREACHED(); | |
| 573 break; | |
| 574 } | 567 } |
| 575 | 568 |
| 576 extension_id_prompting_ = ""; | 569 extension_id_prompting_ = ""; |
| 577 } | 570 } |
| 578 | 571 |
| 579 void AppLauncherHandler::InstallUIAbort() { | 572 void AppLauncherHandler::ExtensionDialogCanceled() { |
| 580 extension_id_prompting_ = ""; | 573 extension_id_prompting_ = ""; |
| 581 } | 574 } |
| 582 | 575 |
| 576 void AppLauncherHandler::InstallUIProceed() { | |
| 577 ExtensionDialogAccepted(); | |
|
Aaron Boodman
2011/03/24 19:22:03
Since the code to run in the uninstall case and th
tfarina
2011/03/24 21:39:47
Done.
| |
| 578 } | |
| 579 | |
| 580 void AppLauncherHandler::InstallUIAbort() { | |
| 581 ExtensionDialogCanceled(); | |
| 582 } | |
| 583 | |
| 584 ExtensionGenericDialog* AppLauncherHandler::GetExtensionGenericDialog() { | |
| 585 if (!extension_generic_dialog_.get()) { | |
| 586 extension_generic_dialog_.reset( | |
| 587 new ExtensionGenericDialog(web_ui_->GetProfile())); | |
| 588 } | |
| 589 return extension_generic_dialog_.get(); | |
| 590 } | |
| 591 | |
| 583 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { | 592 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { |
| 584 if (!install_ui_.get()) | 593 if (!extension_install_ui_.get()) { |
| 585 install_ui_.reset(new ExtensionInstallUI(web_ui_->GetProfile())); | 594 extension_install_ui_.reset( |
| 586 return install_ui_.get(); | 595 new ExtensionInstallUI(web_ui_->GetProfile())); |
| 596 } | |
| 597 return extension_install_ui_.get(); | |
| 587 } | 598 } |
| 588 | 599 |
| 589 void AppLauncherHandler::UninstallDefaultApps() { | 600 void AppLauncherHandler::UninstallDefaultApps() { |
| 590 DefaultApps* default_apps = extensions_service_->default_apps(); | 601 DefaultApps* default_apps = extensions_service_->default_apps(); |
| 591 const ExtensionIdSet& app_ids = default_apps->default_apps(); | 602 const ExtensionIdSet& app_ids = default_apps->default_apps(); |
| 592 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 603 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 593 iter != app_ids.end(); ++iter) { | 604 iter != app_ids.end(); ++iter) { |
| 594 if (extensions_service_->GetExtensionById(*iter, true)) | 605 if (extensions_service_->GetExtensionById(*iter, true)) |
| 595 extensions_service_->UninstallExtension(*iter, false); | 606 extensions_service_->UninstallExtension(*iter, false); |
| 596 } | 607 } |
| 597 } | 608 } |
| OLD | NEW |