| 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "webkit/glue/window_open_disposition.h" | 40 #include "webkit/glue/window_open_disposition.h" |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // The URL prefixes used by the NTP to signal when the web store or an app | 44 // The URL prefixes used by the NTP to signal when the web store or an app |
| 45 // has launched so we can record the proper histogram. | 45 // has launched so we can record the proper histogram. |
| 46 const char* kPingLaunchAppByID = "record-app-launch-by-id"; | 46 const char* kPingLaunchAppByID = "record-app-launch-by-id"; |
| 47 const char* kPingLaunchWebStore = "record-webstore-launch"; | 47 const char* kPingLaunchWebStore = "record-webstore-launch"; |
| 48 const char* kPingLaunchAppByURL = "record-app-launch-by-url"; | 48 const char* kPingLaunchAppByURL = "record-app-launch-by-url"; |
| 49 | 49 |
| 50 const char* kChromeWebStoreUrl = "https://chrome.google.com/webstore"; |
| 51 |
| 50 const UnescapeRule::Type kUnescapeRules = | 52 const UnescapeRule::Type kUnescapeRules = |
| 51 UnescapeRule::NORMAL | UnescapeRule::URL_SPECIAL_CHARS; | 53 UnescapeRule::NORMAL | UnescapeRule::URL_SPECIAL_CHARS; |
| 52 | 54 |
| 53 extension_misc::AppLaunchBucket ParseLaunchSource( | 55 extension_misc::AppLaunchBucket ParseLaunchSource( |
| 54 const std::string& launch_source) { | 56 const std::string& launch_source) { |
| 55 int bucket_num = extension_misc::APP_LAUNCH_BUCKET_INVALID; | 57 int bucket_num = extension_misc::APP_LAUNCH_BUCKET_INVALID; |
| 56 base::StringToInt(launch_source, &bucket_num); | 58 base::StringToInt(launch_source, &bucket_num); |
| 57 extension_misc::AppLaunchBucket bucket = | 59 extension_misc::AppLaunchBucket bucket = |
| 58 static_cast<extension_misc::AppLaunchBucket>(bucket_num); | 60 static_cast<extension_misc::AppLaunchBucket>(bucket_num); |
| 59 CHECK(bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 61 CHECK(bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 value->SetString("options_url", extension->options_url().spec()); | 98 value->SetString("options_url", extension->options_url().spec()); |
| 97 } | 99 } |
| 98 value->SetBoolean("can_uninstall", | 100 value->SetBoolean("can_uninstall", |
| 99 Extension::UserMayDisable(extension->location())); | 101 Extension::UserMayDisable(extension->location())); |
| 100 value->SetString("icon_big", icon_big.spec()); | 102 value->SetString("icon_big", icon_big.spec()); |
| 101 value->SetString("icon_small", icon_small.spec()); | 103 value->SetString("icon_small", icon_small.spec()); |
| 102 value->SetInteger("launch_container", extension->launch_container()); | 104 value->SetInteger("launch_container", extension->launch_container()); |
| 103 value->SetInteger("launch_type", | 105 value->SetInteger("launch_type", |
| 104 prefs->GetLaunchType(extension->id(), | 106 prefs->GetLaunchType(extension->id(), |
| 105 ExtensionPrefs::LAUNCH_DEFAULT)); | 107 ExtensionPrefs::LAUNCH_DEFAULT)); |
| 108 value->SetBoolean("is_component", |
| 109 extension->location() == Extension::COMPONENT); |
| 106 | 110 |
| 107 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); | 111 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); |
| 108 if (app_launch_index == -1) { | 112 if (app_launch_index == -1) { |
| 109 // Make sure every app has a launch index (some predate the launch index). | 113 // Make sure every app has a launch index (some predate the launch index). |
| 110 app_launch_index = prefs->GetNextAppLaunchIndex(); | 114 app_launch_index = prefs->GetNextAppLaunchIndex(); |
| 111 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); | 115 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); |
| 112 } | 116 } |
| 113 value->SetInteger("app_launch_index", app_launch_index); | 117 value->SetInteger("app_launch_index", app_launch_index); |
| 114 | 118 |
| 115 int page_index = prefs->GetPageIndex(extension->id()); | 119 int page_index = prefs->GetPageIndex(extension->id()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 default: | 218 default: |
| 215 NOTREACHED(); | 219 NOTREACHED(); |
| 216 } | 220 } |
| 217 } | 221 } |
| 218 | 222 |
| 219 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { | 223 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { |
| 220 ListValue* list = new ListValue(); | 224 ListValue* list = new ListValue(); |
| 221 const ExtensionList* extensions = extensions_service_->extensions(); | 225 const ExtensionList* extensions = extensions_service_->extensions(); |
| 222 ExtensionList::const_iterator it; | 226 ExtensionList::const_iterator it; |
| 223 for (it = extensions->begin(); it != extensions->end(); ++it) { | 227 for (it = extensions->begin(); it != extensions->end(); ++it) { |
| 224 // Don't include the WebStore and other component apps. | 228 // Don't include the WebStore. |
| 225 // The WebStore launcher gets special treatment in ntp/apps.js. | 229 // The WebStore launcher gets special treatment in ntp/apps.js. |
| 226 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) { | 230 if ((*it)->is_app() && |
| 231 (*it)->GetFullLaunchURL().spec() != kChromeWebStoreUrl) { |
| 227 DictionaryValue* app_info = new DictionaryValue(); | 232 DictionaryValue* app_info = new DictionaryValue(); |
| 228 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); | 233 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); |
| 229 list->Append(app_info); | 234 list->Append(app_info); |
| 230 } | 235 } |
| 231 } | 236 } |
| 232 | 237 |
| 233 extensions = extensions_service_->disabled_extensions(); | 238 extensions = extensions_service_->disabled_extensions(); |
| 234 for (it = extensions->begin(); it != extensions->end(); ++it) { | 239 for (it = extensions->begin(); it != extensions->end(); ++it) { |
| 235 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) { | 240 if ((*it)->is_app() && |
| 241 (*it)->GetFullLaunchURL().spec() != kChromeWebStoreUrl) { |
| 236 DictionaryValue* app_info = new DictionaryValue(); | 242 DictionaryValue* app_info = new DictionaryValue(); |
| 237 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); | 243 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); |
| 238 list->Append(app_info); | 244 list->Append(app_info); |
| 239 } | 245 } |
| 240 } | 246 } |
| 241 | 247 |
| 242 dictionary->Set("apps", list); | 248 dictionary->Set("apps", list); |
| 243 | 249 |
| 244 #if defined(OS_MACOSX) | 250 #if defined(OS_MACOSX) |
| 245 // App windows are not yet implemented on mac. | 251 // App windows are not yet implemented on mac. |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 646 |
| 641 void AppLauncherHandler::UninstallDefaultApps() { | 647 void AppLauncherHandler::UninstallDefaultApps() { |
| 642 AppsPromo* apps_promo = extensions_service_->apps_promo(); | 648 AppsPromo* apps_promo = extensions_service_->apps_promo(); |
| 643 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 649 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 644 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 650 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 645 iter != app_ids.end(); ++iter) { | 651 iter != app_ids.end(); ++iter) { |
| 646 if (extensions_service_->GetExtensionById(*iter, true)) | 652 if (extensions_service_->GetExtensionById(*iter, true)) |
| 647 extensions_service_->UninstallExtension(*iter, false, NULL); | 653 extensions_service_->UninstallExtension(*iter, false, NULL); |
| 648 } | 654 } |
| 649 } | 655 } |
| OLD | NEW |