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/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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) | 68 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) |
| 69 : extensions_service_(extension_service), | 69 : extensions_service_(extension_service), |
| 70 promo_active_(false), | 70 promo_active_(false), |
| 71 ignore_changes_(false) { | 71 ignore_changes_(false) { |
| 72 } | 72 } |
| 73 | 73 |
| 74 AppLauncherHandler::~AppLauncherHandler() {} | 74 AppLauncherHandler::~AppLauncherHandler() {} |
| 75 | 75 |
| 76 // static | 76 // static |
| 77 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 77 void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
| 78 const AppNotificationList* notifications, | |
| 78 ExtensionPrefs* prefs, | 79 ExtensionPrefs* prefs, |
| 79 DictionaryValue* value) { | 80 DictionaryValue* value) { |
| 80 bool enabled = | 81 bool enabled = |
| 81 prefs->GetExtensionState(extension->id()) != Extension::DISABLED; | 82 prefs->GetExtensionState(extension->id()) != Extension::DISABLED; |
| 82 GURL icon_big = | 83 GURL icon_big = |
| 83 ExtensionIconSource::GetIconURL(extension, | 84 ExtensionIconSource::GetIconURL(extension, |
| 84 Extension::EXTENSION_ICON_LARGE, | 85 Extension::EXTENSION_ICON_LARGE, |
| 85 ExtensionIconSet::MATCH_EXACTLY, | 86 ExtensionIconSet::MATCH_EXACTLY, |
| 86 !enabled); | 87 !enabled); |
| 87 GURL icon_small = | 88 GURL icon_small = |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 102 Extension::UserMayDisable(extension->location())); | 103 Extension::UserMayDisable(extension->location())); |
| 103 value->SetString("icon_big", icon_big.spec()); | 104 value->SetString("icon_big", icon_big.spec()); |
| 104 value->SetString("icon_small", icon_small.spec()); | 105 value->SetString("icon_small", icon_small.spec()); |
| 105 value->SetInteger("launch_container", extension->launch_container()); | 106 value->SetInteger("launch_container", extension->launch_container()); |
| 106 value->SetInteger("launch_type", | 107 value->SetInteger("launch_type", |
| 107 prefs->GetLaunchType(extension->id(), | 108 prefs->GetLaunchType(extension->id(), |
| 108 ExtensionPrefs::LAUNCH_DEFAULT)); | 109 ExtensionPrefs::LAUNCH_DEFAULT)); |
| 109 value->SetBoolean("is_component", | 110 value->SetBoolean("is_component", |
| 110 extension->location() == Extension::COMPONENT); | 111 extension->location() == Extension::COMPONENT); |
| 111 | 112 |
| 113 if (notifications && !notifications->empty()) { | |
| 114 AppNotification* n = (*notifications->rbegin()).get(); | |
|
Evan Stade
2011/06/22 19:36:23
is this not the same as notifications->rbegin()->g
asargent_no_longer_on_chrome
2011/06/23 22:36:24
Yes, good point. (I reworked the code - this moved
| |
| 115 value->SetString("title", n->title); | |
| 116 value->SetString("body", n->body); | |
| 117 if (!n->linkUrl.is_empty()) { | |
| 118 value->SetString("linkUrl", n->linkUrl.spec()); | |
| 119 value->SetString("linkText", n->linkText); | |
| 120 } | |
| 121 } | |
| 122 | |
| 112 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); | 123 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); |
| 113 if (app_launch_index == -1) { | 124 if (app_launch_index == -1) { |
| 114 // Make sure every app has a launch index (some predate the launch index). | 125 // Make sure every app has a launch index (some predate the launch index). |
| 115 app_launch_index = prefs->GetNextAppLaunchIndex(); | 126 app_launch_index = prefs->GetNextAppLaunchIndex(); |
| 116 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); | 127 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); |
| 117 } | 128 } |
| 118 value->SetInteger("app_launch_index", app_launch_index); | 129 value->SetInteger("app_launch_index", app_launch_index); |
| 119 | 130 |
| 120 int page_index = prefs->GetPageIndex(extension->id()); | 131 int page_index = prefs->GetPageIndex(extension->id()); |
| 121 if (page_index >= 0) { | 132 if (page_index >= 0) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 NewCallback(this, &AppLauncherHandler::HandlePromoSeen)); | 202 NewCallback(this, &AppLauncherHandler::HandlePromoSeen)); |
| 192 } | 203 } |
| 193 | 204 |
| 194 void AppLauncherHandler::Observe(NotificationType type, | 205 void AppLauncherHandler::Observe(NotificationType type, |
| 195 const NotificationSource& source, | 206 const NotificationSource& source, |
| 196 const NotificationDetails& details) { | 207 const NotificationDetails& details) { |
| 197 if (ignore_changes_) | 208 if (ignore_changes_) |
| 198 return; | 209 return; |
| 199 | 210 |
| 200 switch (type.value) { | 211 switch (type.value) { |
| 212 case NotificationType::APP_NOTIFICATION_STATE_CHANGED: | |
|
Evan Stade
2011/06/22 19:36:23
I don't think you want to nuke the entirety of the
asargent_no_longer_on_chrome
2011/06/23 22:36:24
Good catch - I had thrown this in there as a quick
| |
| 201 case NotificationType::EXTENSION_LOADED: | 213 case NotificationType::EXTENSION_LOADED: |
| 202 case NotificationType::EXTENSION_UNLOADED: | 214 case NotificationType::EXTENSION_UNLOADED: |
| 203 case NotificationType::EXTENSION_LAUNCHER_REORDERED: | 215 case NotificationType::EXTENSION_LAUNCHER_REORDERED: |
| 204 // The promo may not load until a couple seconds after the first NTP view, | 216 // The promo may not load until a couple seconds after the first NTP view, |
| 205 // so we listen for the load notification and notify the NTP when ready. | 217 // so we listen for the load notification and notify the NTP when ready. |
| 206 case NotificationType::WEB_STORE_PROMO_LOADED: | 218 case NotificationType::WEB_STORE_PROMO_LOADED: |
| 207 if (web_ui_->tab_contents()) | 219 if (web_ui_->tab_contents()) |
| 208 HandleGetApps(NULL); | 220 HandleGetApps(NULL); |
| 209 break; | 221 break; |
| 210 case NotificationType::PREF_CHANGED: { | 222 case NotificationType::PREF_CHANGED: { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 221 } | 233 } |
| 222 } | 234 } |
| 223 | 235 |
| 224 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { | 236 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { |
| 225 ListValue* list = new ListValue(); | 237 ListValue* list = new ListValue(); |
| 226 const ExtensionList* extensions = extensions_service_->extensions(); | 238 const ExtensionList* extensions = extensions_service_->extensions(); |
| 227 ExtensionList::const_iterator it; | 239 ExtensionList::const_iterator it; |
| 228 for (it = extensions->begin(); it != extensions->end(); ++it) { | 240 for (it = extensions->begin(); it != extensions->end(); ++it) { |
| 229 // Don't include the WebStore. | 241 // Don't include the WebStore. |
| 230 // The WebStore launcher gets special treatment in ntp/apps.js. | 242 // The WebStore launcher gets special treatment in ntp/apps.js. |
| 231 if ((*it)->is_app() && | 243 const Extension* extension = *it; |
| 232 (*it)->id() != extension_misc::kWebStoreAppId) { | 244 if (extension->is_app() && |
| 245 extension->id() != extension_misc::kWebStoreAppId) { | |
| 233 DictionaryValue* app_info = new DictionaryValue(); | 246 DictionaryValue* app_info = new DictionaryValue(); |
| 234 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); | 247 AppNotificationManager* notification_manager = |
| 248 extensions_service_->app_notification_manager(); | |
| 249 CreateAppInfo(extension, | |
| 250 notification_manager->GetAll(extension->id()), | |
| 251 extensions_service_->extension_prefs(), | |
| 252 app_info); | |
| 235 list->Append(app_info); | 253 list->Append(app_info); |
| 236 } | 254 } |
| 237 } | 255 } |
| 238 | 256 |
| 239 extensions = extensions_service_->disabled_extensions(); | 257 extensions = extensions_service_->disabled_extensions(); |
| 240 for (it = extensions->begin(); it != extensions->end(); ++it) { | 258 for (it = extensions->begin(); it != extensions->end(); ++it) { |
| 241 if ((*it)->is_app() && | 259 if ((*it)->is_app() && |
| 242 (*it)->id() != extension_misc::kWebStoreAppId) { | 260 (*it)->id() != extension_misc::kWebStoreAppId) { |
| 243 DictionaryValue* app_info = new DictionaryValue(); | 261 DictionaryValue* app_info = new DictionaryValue(); |
| 244 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); | 262 CreateAppInfo(*it, |
| 263 NULL, | |
| 264 extensions_service_->extension_prefs(), | |
| 265 app_info); | |
| 245 list->Append(app_info); | 266 list->Append(app_info); |
| 246 } | 267 } |
| 247 } | 268 } |
| 248 | 269 |
| 249 dictionary->Set("apps", list); | 270 dictionary->Set("apps", list); |
| 250 | 271 |
| 251 #if defined(OS_MACOSX) | 272 #if defined(OS_MACOSX) |
| 252 // App windows are not yet implemented on mac. | 273 // App windows are not yet implemented on mac. |
| 253 dictionary->SetBoolean("disableAppWindowLaunch", true); | 274 dictionary->SetBoolean("disableAppWindowLaunch", true); |
| 254 dictionary->SetBoolean("disableCreateAppShortcut", true); | 275 dictionary->SetBoolean("disableCreateAppShortcut", true); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 ignore_changes_ = false; | 328 ignore_changes_ = false; |
| 308 ShownSectionsHandler::SetShownSection(prefs, THUMB); | 329 ShownSectionsHandler::SetShownSection(prefs, THUMB); |
| 309 } | 330 } |
| 310 | 331 |
| 311 FillAppDictionary(&dictionary); | 332 FillAppDictionary(&dictionary); |
| 312 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary); | 333 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary); |
| 313 | 334 |
| 314 // First time we get here we set up the observer so that we can tell update | 335 // First time we get here we set up the observer so that we can tell update |
| 315 // the apps as they change. | 336 // the apps as they change. |
| 316 if (registrar_.IsEmpty()) { | 337 if (registrar_.IsEmpty()) { |
| 338 registrar_.Add(this, NotificationType::APP_NOTIFICATION_STATE_CHANGED, | |
| 339 NotificationService::AllSources()); | |
| 317 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 340 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 318 NotificationService::AllSources()); | 341 NotificationService::AllSources()); |
| 319 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 342 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 320 NotificationService::AllSources()); | 343 NotificationService::AllSources()); |
| 321 registrar_.Add(this, NotificationType::EXTENSION_LAUNCHER_REORDERED, | 344 registrar_.Add(this, NotificationType::EXTENSION_LAUNCHER_REORDERED, |
| 322 NotificationService::AllSources()); | 345 NotificationService::AllSources()); |
| 323 registrar_.Add(this, NotificationType::WEB_STORE_PROMO_LOADED, | 346 registrar_.Add(this, NotificationType::WEB_STORE_PROMO_LOADED, |
| 324 NotificationService::AllSources()); | 347 NotificationService::AllSources()); |
| 325 } | 348 } |
| 326 if (pref_change_registrar_.IsEmpty()) { | 349 if (pref_change_registrar_.IsEmpty()) { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 | 675 |
| 653 void AppLauncherHandler::UninstallDefaultApps() { | 676 void AppLauncherHandler::UninstallDefaultApps() { |
| 654 AppsPromo* apps_promo = extensions_service_->apps_promo(); | 677 AppsPromo* apps_promo = extensions_service_->apps_promo(); |
| 655 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 678 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 656 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 679 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 657 iter != app_ids.end(); ++iter) { | 680 iter != app_ids.end(); ++iter) { |
| 658 if (extensions_service_->GetExtensionById(*iter, true)) | 681 if (extensions_service_->GetExtensionById(*iter, true)) |
| 659 extensions_service_->UninstallExtension(*iter, false, NULL); | 682 extensions_service_->UninstallExtension(*iter, false, NULL); |
| 660 } | 683 } |
| 661 } | 684 } |
| OLD | NEW |