| 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/ntp/app_launcher_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 dictionary->SetString("body", notification.body()); | 86 dictionary->SetString("body", notification.body()); |
| 87 if (!notification.link_url().is_empty()) { | 87 if (!notification.link_url().is_empty()) { |
| 88 dictionary->SetString("linkUrl", notification.link_url().spec()); | 88 dictionary->SetString("linkUrl", notification.link_url().spec()); |
| 89 dictionary->SetString("linkText", notification.link_text()); | 89 dictionary->SetString("linkText", notification.link_text()); |
| 90 } | 90 } |
| 91 return dictionary; | 91 return dictionary; |
| 92 } | 92 } |
| 93 | 93 |
| 94 // static | 94 // static |
| 95 bool AppLauncherHandler::IsAppExcludedFromList(const Extension* extension) { | 95 bool AppLauncherHandler::IsAppExcludedFromList(const Extension* extension) { |
| 96 // Don't include the WebStore and the Cloud Print app. | |
| 97 // The WebStore launcher gets special treatment in ntp/apps.js. | |
| 98 // The Cloud Print app should never be displayed in the NTP. | 96 // The Cloud Print app should never be displayed in the NTP. |
| 99 bool ntp3 = | |
| 100 !NewTabUI::NTP4Enabled(); | |
| 101 if (!extension->is_app() || | 97 if (!extension->is_app() || |
| 102 (ntp3 && extension->id() == extension_misc::kWebStoreAppId) || | |
| 103 (extension->id() == extension_misc::kCloudPrintAppId)) { | 98 (extension->id() == extension_misc::kCloudPrintAppId)) { |
| 104 return true; | 99 return true; |
| 105 } | 100 } |
| 106 return false; | 101 return false; |
| 107 } | 102 } |
| 108 | 103 |
| 109 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 104 void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
| 110 const AppNotification* notification, | 105 const AppNotification* notification, |
| 111 ExtensionService* service, | 106 ExtensionService* service, |
| 112 DictionaryValue* value) { | 107 DictionaryValue* value) { |
| 113 bool enabled = service->IsExtensionEnabled(extension->id()) && | 108 bool enabled = service->IsExtensionEnabled(extension->id()) && |
| 114 !service->GetTerminatedExtension(extension->id()); | 109 !service->GetTerminatedExtension(extension->id()); |
| 115 bool icon_big_exists = true; | 110 bool icon_big_exists = true; |
| 116 // Instead of setting grayscale here, we do it in apps_page.js in NTP4. | 111 // Instead of setting grayscale here, we do it in apps_page.js. |
| 117 bool grayscale = NewTabUI::NTP4Enabled() ? false : !enabled; | |
| 118 GURL icon_big = | 112 GURL icon_big = |
| 119 ExtensionIconSource::GetIconURL(extension, | 113 ExtensionIconSource::GetIconURL(extension, |
| 120 Extension::EXTENSION_ICON_LARGE, | 114 Extension::EXTENSION_ICON_LARGE, |
| 121 ExtensionIconSet::MATCH_EXACTLY, | 115 ExtensionIconSet::MATCH_EXACTLY, |
| 122 grayscale, &icon_big_exists); | 116 false, &icon_big_exists); |
| 123 bool icon_small_exists = true; | 117 bool icon_small_exists = true; |
| 124 GURL icon_small = | 118 GURL icon_small = |
| 125 ExtensionIconSource::GetIconURL(extension, | 119 ExtensionIconSource::GetIconURL(extension, |
| 126 Extension::EXTENSION_ICON_BITTY, | 120 Extension::EXTENSION_ICON_BITTY, |
| 127 ExtensionIconSet::MATCH_BIGGER, | 121 ExtensionIconSet::MATCH_BIGGER, |
| 128 grayscale, &icon_small_exists); | 122 false, &icon_small_exists); |
| 129 | 123 |
| 130 value->Clear(); | 124 value->Clear(); |
| 131 | 125 |
| 132 // The Extension class 'helpfully' wraps bidi control characters that | 126 // The Extension class 'helpfully' wraps bidi control characters that |
| 133 // impede our ability to determine directionality. | 127 // impede our ability to determine directionality. |
| 134 string16 name = UTF8ToUTF16(extension->name()); | 128 string16 name = UTF8ToUTF16(extension->name()); |
| 135 base::i18n::UnadjustStringForLocaleDirection(&name); | 129 base::i18n::UnadjustStringForLocaleDirection(&name); |
| 136 NewTabUI::SetURLTitleAndDirection(value, name, extension->GetFullLaunchURL()); | 130 NewTabUI::SetURLTitleAndDirection(value, name, extension->GetFullLaunchURL()); |
| 137 | 131 |
| 138 value->SetString("id", extension->id()); | 132 value->SetString("id", extension->id()); |
| 139 value->SetString("description", extension->description()); | 133 value->SetString("description", extension->description()); |
| 140 value->SetBoolean("enabled", enabled); | 134 value->SetBoolean("enabled", enabled); |
| 141 if (NewTabUI::NTP4Enabled() || enabled) | 135 value->SetString("options_url", extension->options_url().spec()); |
| 142 value->SetString("options_url", extension->options_url().spec()); | |
| 143 value->SetBoolean("can_uninstall", | 136 value->SetBoolean("can_uninstall", |
| 144 Extension::UserMayDisable(extension->location())); | 137 Extension::UserMayDisable(extension->location())); |
| 145 value->SetString("icon_big", icon_big.spec()); | 138 value->SetString("icon_big", icon_big.spec()); |
| 146 value->SetBoolean("icon_big_exists", icon_big_exists); | 139 value->SetBoolean("icon_big_exists", icon_big_exists); |
| 147 value->SetString("icon_small", icon_small.spec()); | 140 value->SetString("icon_small", icon_small.spec()); |
| 148 value->SetBoolean("icon_small_exists", icon_small_exists); | 141 value->SetBoolean("icon_small_exists", icon_small_exists); |
| 149 value->SetInteger("launch_container", extension->launch_container()); | 142 value->SetInteger("launch_container", extension->launch_container()); |
| 150 ExtensionPrefs* prefs = service->extension_prefs(); | 143 ExtensionPrefs* prefs = service->extension_prefs(); |
| 151 value->SetInteger("launch_type", | 144 value->SetInteger("launch_type", |
| 152 prefs->GetLaunchType(extension->id(), | 145 prefs->GetLaunchType(extension->id(), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, | 220 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, |
| 228 base::Unretained(this))); | 221 base::Unretained(this))); |
| 229 web_ui_->RegisterMessageCallback("closeNotification", | 222 web_ui_->RegisterMessageCallback("closeNotification", |
| 230 base::Bind(&AppLauncherHandler::HandleNotificationClose, | 223 base::Bind(&AppLauncherHandler::HandleNotificationClose, |
| 231 base::Unretained(this))); | 224 base::Unretained(this))); |
| 232 } | 225 } |
| 233 | 226 |
| 234 void AppLauncherHandler::Observe(int type, | 227 void AppLauncherHandler::Observe(int type, |
| 235 const content::NotificationSource& source, | 228 const content::NotificationSource& source, |
| 236 const content::NotificationDetails& details) { | 229 const content::NotificationDetails& details) { |
| 237 if (type == chrome::NOTIFICATION_APP_INSTALLED_TO_NTP && | 230 if (type == chrome::NOTIFICATION_APP_INSTALLED_TO_NTP) { |
| 238 NewTabUI::NTP4Enabled()) { | |
| 239 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); | 231 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); |
| 240 if (has_loaded_apps_) | 232 if (has_loaded_apps_) |
| 241 SetAppToBeHighlighted(); | 233 SetAppToBeHighlighted(); |
| 242 return; | 234 return; |
| 243 } | 235 } |
| 244 | 236 |
| 245 if (ignore_changes_ || !has_loaded_apps_) | 237 if (ignore_changes_ || !has_loaded_apps_) |
| 246 return; | 238 return; |
| 247 | 239 |
| 248 switch (type) { | 240 switch (type) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 266 } | 258 } |
| 267 break; | 259 break; |
| 268 } | 260 } |
| 269 | 261 |
| 270 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 262 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 271 const Extension* extension = | 263 const Extension* extension = |
| 272 content::Details<const Extension>(details).ptr(); | 264 content::Details<const Extension>(details).ptr(); |
| 273 if (!extension->is_app()) | 265 if (!extension->is_app()) |
| 274 return; | 266 return; |
| 275 | 267 |
| 276 if (!NewTabUI::NTP4Enabled()) { | |
| 277 HandleGetApps(NULL); | |
| 278 break; | |
| 279 } | |
| 280 | |
| 281 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); | 268 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); |
| 282 if (app_info.get()) { | 269 if (app_info.get()) { |
| 283 ExtensionPrefs* prefs = extension_service_->extension_prefs(); | 270 ExtensionPrefs* prefs = extension_service_->extension_prefs(); |
| 284 scoped_ptr<base::FundamentalValue> highlight(Value::CreateBooleanValue( | 271 scoped_ptr<base::FundamentalValue> highlight(Value::CreateBooleanValue( |
| 285 prefs->IsFromBookmark(extension->id()) && | 272 prefs->IsFromBookmark(extension->id()) && |
| 286 attempted_bookmark_app_install_)); | 273 attempted_bookmark_app_install_)); |
| 287 attempted_bookmark_app_install_ = false; | 274 attempted_bookmark_app_install_ = false; |
| 288 web_ui_->CallJavascriptFunction("ntp4.appAdded", *app_info, *highlight); | 275 web_ui_->CallJavascriptFunction("ntp4.appAdded", *app_info, *highlight); |
| 289 } | 276 } |
| 290 | 277 |
| 291 break; | 278 break; |
| 292 } | 279 } |
| 293 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 280 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 294 const Extension* extension = | 281 const Extension* extension = |
| 295 content::Details<UnloadedExtensionInfo>(details)->extension; | 282 content::Details<UnloadedExtensionInfo>(details)->extension; |
| 296 if (!extension->is_app()) | 283 if (!extension->is_app()) |
| 297 return; | 284 return; |
| 298 | 285 |
| 299 if (!NewTabUI::NTP4Enabled()) { | |
| 300 HandleGetApps(NULL); | |
| 301 break; | |
| 302 } | |
| 303 | |
| 304 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); | 286 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); |
| 305 scoped_ptr<base::FundamentalValue> uninstall_value( | 287 scoped_ptr<base::FundamentalValue> uninstall_value( |
| 306 Value::CreateBooleanValue( | 288 Value::CreateBooleanValue( |
| 307 content::Details<UnloadedExtensionInfo>(details)->reason == | 289 content::Details<UnloadedExtensionInfo>(details)->reason == |
| 308 extension_misc::UNLOAD_REASON_UNINSTALL)); | 290 extension_misc::UNLOAD_REASON_UNINSTALL)); |
| 309 if (app_info.get()) { | 291 if (app_info.get()) { |
| 310 web_ui_->CallJavascriptFunction( | 292 web_ui_->CallJavascriptFunction( |
| 311 "ntp4.appRemoved", *app_info, *uninstall_value); | 293 "ntp4.appRemoved", *app_info, *uninstall_value); |
| 312 } | 294 } |
| 313 break; | 295 break; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 // Making shortcut does not make sense on ChromeOS because it does not have | 382 // Making shortcut does not make sense on ChromeOS because it does not have |
| 401 // a desktop. | 383 // a desktop. |
| 402 dictionary->SetBoolean("disableCreateAppShortcut", true); | 384 dictionary->SetBoolean("disableCreateAppShortcut", true); |
| 403 #endif | 385 #endif |
| 404 | 386 |
| 405 dictionary->SetBoolean( | 387 dictionary->SetBoolean( |
| 406 "showLauncher", | 388 "showLauncher", |
| 407 extension_service_->apps_promo()->ShouldShowAppLauncher( | 389 extension_service_->apps_promo()->ShouldShowAppLauncher( |
| 408 extension_service_->GetAppIds())); | 390 extension_service_->GetAppIds())); |
| 409 | 391 |
| 410 if (NewTabUI::NTP4Enabled()) { | 392 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); |
| 411 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | 393 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); |
| 412 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); | 394 if (!app_page_names || !app_page_names->GetSize()) { |
| 413 if (!app_page_names || !app_page_names->GetSize()) { | 395 ListPrefUpdate update(prefs, prefs::kNTPAppPageNames); |
| 414 ListPrefUpdate update(prefs, prefs::kNTPAppPageNames); | 396 ListValue* list = update.Get(); |
| 415 ListValue* list = update.Get(); | 397 list->Set(0, Value::CreateStringValue( |
| 416 list->Set(0, Value::CreateStringValue( | 398 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); |
| 417 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); | 399 dictionary->Set("appPageNames", |
| 418 dictionary->Set("appPageNames", | 400 static_cast<ListValue*>(list->DeepCopy())); |
| 419 static_cast<ListValue*>(list->DeepCopy())); | 401 } else { |
| 420 } else { | 402 dictionary->Set("appPageNames", |
| 421 dictionary->Set("appPageNames", | 403 static_cast<ListValue*>(app_page_names->DeepCopy())); |
| 422 static_cast<ListValue*>(app_page_names->DeepCopy())); | |
| 423 } | |
| 424 } | 404 } |
| 425 } | 405 } |
| 426 | 406 |
| 427 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { | 407 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { |
| 428 AppNotificationManager* notification_manager = | 408 AppNotificationManager* notification_manager = |
| 429 extension_service_->app_notification_manager(); | 409 extension_service_->app_notification_manager(); |
| 430 DictionaryValue* app_info = new DictionaryValue(); | 410 DictionaryValue* app_info = new DictionaryValue(); |
| 431 // CreateAppInfo can change the extension prefs. | 411 // CreateAppInfo can change the extension prefs. |
| 432 AutoReset<bool> auto_reset(&ignore_changes_, true); | 412 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 433 CreateAppInfo(extension, | 413 CreateAppInfo(extension, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 // If the user pressed special keys when clicking, override the saved | 529 // If the user pressed special keys when clicking, override the saved |
| 550 // preference for launch container. | 530 // preference for launch container. |
| 551 bool middle_button = (button == 1.0); | 531 bool middle_button = (button == 1.0); |
| 552 WindowOpenDisposition disposition = | 532 WindowOpenDisposition disposition = |
| 553 disposition_utils::DispositionFromClick(middle_button, alt_key, | 533 disposition_utils::DispositionFromClick(middle_button, alt_key, |
| 554 ctrl_key, meta_key, shift_key); | 534 ctrl_key, meta_key, shift_key); |
| 555 | 535 |
| 556 if (extension_id != extension_misc::kWebStoreAppId) { | 536 if (extension_id != extension_misc::kWebStoreAppId) { |
| 557 RecordAppLaunchByID(launch_bucket); | 537 RecordAppLaunchByID(launch_bucket); |
| 558 extension_service_->apps_promo()->ExpireDefaultApps(); | 538 extension_service_->apps_promo()->ExpireDefaultApps(); |
| 559 } else if (NewTabUI::NTP4Enabled()) { | 539 } else { |
| 560 RecordWebStoreLaunch(url.find("chrome-ntp-promo") != std::string::npos); | 540 RecordWebStoreLaunch(url.find("chrome-ntp-promo") != std::string::npos); |
| 561 } | 541 } |
| 562 | 542 |
| 563 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 543 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
| 564 // TODO(jamescook): Proper support for background tabs. | 544 // TODO(jamescook): Proper support for background tabs. |
| 565 Browser::OpenApplication( | 545 Browser::OpenApplication( |
| 566 profile, extension, extension_misc::LAUNCH_TAB, GURL(url), disposition); | 546 profile, extension, extension_misc::LAUNCH_TAB, GURL(url), disposition); |
| 567 } else if (disposition == NEW_WINDOW) { | 547 } else if (disposition == NEW_WINDOW) { |
| 568 // Force a new window open. | 548 // Force a new window open. |
| 569 Browser::OpenApplication( | 549 Browser::OpenApplication( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 598 double launch_type; | 578 double launch_type; |
| 599 CHECK(args->GetString(0, &extension_id)); | 579 CHECK(args->GetString(0, &extension_id)); |
| 600 CHECK(args->GetDouble(1, &launch_type)); | 580 CHECK(args->GetDouble(1, &launch_type)); |
| 601 | 581 |
| 602 const Extension* extension = | 582 const Extension* extension = |
| 603 extension_service_->GetExtensionById(extension_id, true); | 583 extension_service_->GetExtensionById(extension_id, true); |
| 604 if (!extension) | 584 if (!extension) |
| 605 return; | 585 return; |
| 606 | 586 |
| 607 // Don't update the page; it already knows about the launch type change. | 587 // Don't update the page; it already knows about the launch type change. |
| 608 scoped_ptr<AutoReset<bool> > auto_reset; | 588 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 609 if (NewTabUI::NTP4Enabled()) | |
| 610 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | |
| 611 | 589 |
| 612 extension_service_->extension_prefs()->SetLaunchType( | 590 extension_service_->extension_prefs()->SetLaunchType( |
| 613 extension_id, | 591 extension_id, |
| 614 static_cast<ExtensionPrefs::LaunchType>( | 592 static_cast<ExtensionPrefs::LaunchType>( |
| 615 static_cast<int>(launch_type))); | 593 static_cast<int>(launch_type))); |
| 616 } | 594 } |
| 617 | 595 |
| 618 void AppLauncherHandler::HandleUninstallApp(const ListValue* args) { | 596 void AppLauncherHandler::HandleUninstallApp(const ListValue* args) { |
| 619 std::string extension_id; | 597 std::string extension_id; |
| 620 CHECK(args->GetString(0, &extension_id)); | 598 CHECK(args->GetString(0, &extension_id)); |
| 621 | 599 |
| 622 const Extension* extension = extension_service_->GetExtensionById( | 600 const Extension* extension = extension_service_->GetExtensionById( |
| 623 extension_id, true); | 601 extension_id, true); |
| 624 if (!extension) | 602 if (!extension) |
| 625 return; | 603 return; |
| 626 | 604 |
| 627 if (!Extension::UserMayDisable(extension->location())) { | 605 if (!Extension::UserMayDisable(extension->location())) { |
| 628 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " | 606 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " |
| 629 << "was made. Extension id : " << extension->id(); | 607 << "was made. Extension id : " << extension->id(); |
| 630 return; | 608 return; |
| 631 } | 609 } |
| 632 if (!extension_id_prompting_.empty()) | 610 if (!extension_id_prompting_.empty()) |
| 633 return; // Only one prompt at a time. | 611 return; // Only one prompt at a time. |
| 634 | 612 |
| 635 extension_id_prompting_ = extension_id; | 613 extension_id_prompting_ = extension_id; |
| 636 | 614 |
| 637 bool dont_confirm = false; | 615 bool dont_confirm = false; |
| 638 if (args->GetBoolean(1, &dont_confirm) && dont_confirm) { | 616 if (args->GetBoolean(1, &dont_confirm) && dont_confirm) { |
| 639 scoped_ptr<AutoReset<bool> > auto_reset; | 617 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 640 if (NewTabUI::NTP4Enabled()) | |
| 641 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | |
| 642 ExtensionUninstallAccepted(); | 618 ExtensionUninstallAccepted(); |
| 643 } else { | 619 } else { |
| 644 GetExtensionUninstallDialog()->ConfirmUninstall(extension); | 620 GetExtensionUninstallDialog()->ConfirmUninstall(extension); |
| 645 } | 621 } |
| 646 } | 622 } |
| 647 | 623 |
| 648 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { | 624 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { |
| 649 // If the user has intentionally hidden the promotion, we'll uninstall all the | 625 // If the user has intentionally hidden the promotion, we'll uninstall all the |
| 650 // default apps (we know the user hasn't installed any apps on their own at | 626 // default apps (we know the user hasn't installed any apps on their own at |
| 651 // this point, or the promotion wouldn't have been shown). | 627 // this point, or the promotion wouldn't have been shown). |
| 652 // TODO(estade): this isn't used right now as we sort out the future of the | 628 // TODO(estade): this isn't used right now as we sort out the future of the |
| 653 // apps promo on ntp4. | 629 // apps promo on ntp4. |
| 654 if (NewTabUI::NTP4Enabled()) { | 630 UninstallDefaultApps(); |
| 655 UninstallDefaultApps(); | 631 extension_service_->apps_promo()->HidePromo(); |
| 656 extension_service_->apps_promo()->HidePromo(); | |
| 657 } else { | |
| 658 // TODO(estade): remove all this. NTP3 uninstalled all the default apps then | |
| 659 // refreshed the entire NTP, we don't have to jump through these hoops for | |
| 660 // NTP4 because each app uninstall is handled separately without reloading | |
| 661 // the entire page. | |
| 662 ignore_changes_ = true; | |
| 663 UninstallDefaultApps(); | |
| 664 extension_service_->apps_promo()->HidePromo(); | |
| 665 ignore_changes_ = false; | |
| 666 HandleGetApps(NULL); | |
| 667 } | |
| 668 } | 632 } |
| 669 | 633 |
| 670 void AppLauncherHandler::HandleCreateAppShortcut(const ListValue* args) { | 634 void AppLauncherHandler::HandleCreateAppShortcut(const ListValue* args) { |
| 671 std::string extension_id; | 635 std::string extension_id; |
| 672 CHECK(args->GetString(0, &extension_id)); | 636 CHECK(args->GetString(0, &extension_id)); |
| 673 | 637 |
| 674 const Extension* extension = | 638 const Extension* extension = |
| 675 extension_service_->GetExtensionById(extension_id, true); | 639 extension_service_->GetExtensionById(extension_id, true); |
| 676 if (!extension) | 640 if (!extension) |
| 677 return; | 641 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 693 CHECK(args->GetList(1, &app_order)); | 657 CHECK(args->GetList(1, &app_order)); |
| 694 | 658 |
| 695 std::vector<std::string> extension_ids; | 659 std::vector<std::string> extension_ids; |
| 696 for (size_t i = 0; i < app_order->GetSize(); ++i) { | 660 for (size_t i = 0; i < app_order->GetSize(); ++i) { |
| 697 std::string value; | 661 std::string value; |
| 698 if (app_order->GetString(i, &value)) | 662 if (app_order->GetString(i, &value)) |
| 699 extension_ids.push_back(value); | 663 extension_ids.push_back(value); |
| 700 } | 664 } |
| 701 | 665 |
| 702 // Don't update the page; it already knows the apps have been reordered. | 666 // Don't update the page; it already knows the apps have been reordered. |
| 703 scoped_ptr<AutoReset<bool> > auto_reset; | 667 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 704 if (NewTabUI::NTP4Enabled()) | |
| 705 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | |
| 706 | |
| 707 extension_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id); | 668 extension_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id); |
| 708 extension_service_->extension_prefs()->SetAppLauncherOrder(extension_ids); | 669 extension_service_->extension_prefs()->SetAppLauncherOrder(extension_ids); |
| 709 } | 670 } |
| 710 | 671 |
| 711 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { | 672 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { |
| 712 std::string extension_id; | 673 std::string extension_id; |
| 713 double page_index; | 674 double page_index; |
| 714 CHECK(args->GetString(0, &extension_id)); | 675 CHECK(args->GetString(0, &extension_id)); |
| 715 CHECK(args->GetDouble(1, &page_index)); | 676 CHECK(args->GetDouble(1, &page_index)); |
| 716 | 677 |
| 717 // Don't update the page; it already knows the apps have been reordered. | 678 // Don't update the page; it already knows the apps have been reordered. |
| 718 scoped_ptr<AutoReset<bool> > auto_reset; | 679 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 719 if (NewTabUI::NTP4Enabled()) | |
| 720 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | |
| 721 | |
| 722 extension_service_->extension_prefs()->SetPageIndex(extension_id, | 680 extension_service_->extension_prefs()->SetPageIndex(extension_id, |
| 723 static_cast<int>(page_index)); | 681 static_cast<int>(page_index)); |
| 724 } | 682 } |
| 725 | 683 |
| 726 void AppLauncherHandler::HandlePromoSeen(const ListValue* args) { | 684 void AppLauncherHandler::HandlePromoSeen(const ListValue* args) { |
| 727 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, | 685 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
| 728 extension_misc::PROMO_SEEN, | 686 extension_misc::PROMO_SEEN, |
| 729 extension_misc::PROMO_BUCKET_BOUNDARY); | 687 extension_misc::PROMO_BUCKET_BOUNDARY); |
| 730 } | 688 } |
| 731 | 689 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 953 |
| 996 void AppLauncherHandler::UninstallDefaultApps() { | 954 void AppLauncherHandler::UninstallDefaultApps() { |
| 997 AppsPromo* apps_promo = extension_service_->apps_promo(); | 955 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 998 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 956 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 999 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 957 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 1000 iter != app_ids.end(); ++iter) { | 958 iter != app_ids.end(); ++iter) { |
| 1001 if (extension_service_->GetExtensionById(*iter, true)) | 959 if (extension_service_->GetExtensionById(*iter, true)) |
| 1002 extension_service_->UninstallExtension(*iter, false, NULL); | 960 extension_service_->UninstallExtension(*iter, false, NULL); |
| 1003 } | 961 } |
| 1004 } | 962 } |
| OLD | NEW |