Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome/browser/ui/webui/app_launcher_handler.cc

Issue 6721013: extensions: Refactor ExtensionInstallUI class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove the file Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 extension_dialog_type_(ExtensionGenericDialog::DIALOG_UNSET),
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
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 extension_dialog_type_ = ExtensionGenericDialog::DIALOG_UNINSTALL;
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
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 extension_dialog_type_ = ExtensionGenericDialog::DIALOG_RE_ENABLE;
542 GetExtensionInstallUI()->ConfirmReEnable(this, extension); 542 GetExtensionGenericDialog()->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 switch (extension_dialog_type_) {
556 case ExtensionInstallUI::UNINSTALL_PROMPT: 556 case ExtensionGenericDialog::DIALOG_UNINSTALL:
557 extensions_service_->UninstallExtension(extension_id_prompting_, 557 extensions_service_->UninstallExtension(extension_id_prompting_,
558 false /* external_uninstall */); 558 false /* external_uninstall */);
559 break; 559 break;
560 case ExtensionInstallUI::RE_ENABLE_PROMPT: { 560 case ExtensionGenericDialog::DIALOG_RE_ENABLE: {
561 extensions_service_->GrantPermissionsAndEnableExtension(extension); 561 extensions_service_->GrantPermissionsAndEnableExtension(extension);
562 562
563 // We bounce this off the NTP so the browser can update the apps icon. 563 // 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 564 // 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 565 // icon disappears but isn't replaced by the enabled icon, making a poor
566 // visual experience. 566 // visual experience.
567 StringValue* app_id = Value::CreateStringValue(extension->id()); 567 StringValue* app_id = Value::CreateStringValue(extension->id());
568 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); 568 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id);
569 break; 569 break;
570 } 570 }
571 default: 571 default:
572 NOTREACHED(); 572 NOTREACHED();
573 break; 573 break;
574 } 574 }
575 575
576 extension_id_prompting_ = ""; 576 extension_id_prompting_ = "";
577 } 577 }
578 578
579 void AppLauncherHandler::InstallUIAbort() { 579 void AppLauncherHandler::ExtensionDialogCanceled() {
580 extension_id_prompting_ = ""; 580 extension_id_prompting_ = "";
581 } 581 }
582 582
583 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { 583 ExtensionGenericDialog* AppLauncherHandler::GetExtensionGenericDialog() {
584 if (!install_ui_.get()) 584 if (!extension_generic_dialog_.get()) {
585 install_ui_.reset(new ExtensionInstallUI(web_ui_->GetProfile())); 585 extension_generic_dialog_.reset(
586 return install_ui_.get(); 586 new ExtensionGenericDialog(web_ui_->GetProfile()));
587 }
588 return extension_generic_dialog_.get();
587 } 589 }
588 590
589 void AppLauncherHandler::UninstallDefaultApps() { 591 void AppLauncherHandler::UninstallDefaultApps() {
590 DefaultApps* default_apps = extensions_service_->default_apps(); 592 DefaultApps* default_apps = extensions_service_->default_apps();
591 const ExtensionIdSet& app_ids = default_apps->default_apps(); 593 const ExtensionIdSet& app_ids = default_apps->default_apps();
592 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); 594 for (ExtensionIdSet::const_iterator iter = app_ids.begin();
593 iter != app_ids.end(); ++iter) { 595 iter != app_ids.end(); ++iter) {
594 if (extensions_service_->GetExtensionById(*iter, true)) 596 if (extensions_service_->GetExtensionById(*iter, true))
595 extensions_service_->UninstallExtension(*iter, false); 597 extensions_service_->UninstallExtension(*iter, false);
596 } 598 }
597 } 599 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698