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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 base::StringToInt(launch_source, &bucket_num); | 67 base::StringToInt(launch_source, &bucket_num); |
| 68 extension_misc::AppLaunchBucket bucket = | 68 extension_misc::AppLaunchBucket bucket = |
| 69 static_cast<extension_misc::AppLaunchBucket>(bucket_num); | 69 static_cast<extension_misc::AppLaunchBucket>(bucket_num); |
| 70 CHECK(bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 70 CHECK(bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 71 return bucket; | 71 return bucket; |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) | 76 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) |
| 77 : extensions_service_(extension_service), | 77 : extension_service_(extension_service), |
| 78 promo_active_(false), | 78 promo_active_(false), |
| 79 ignore_changes_(false) { | 79 ignore_changes_(false) { |
| 80 } | 80 } |
| 81 | 81 |
| 82 AppLauncherHandler::~AppLauncherHandler() {} | 82 AppLauncherHandler::~AppLauncherHandler() {} |
| 83 | 83 |
| 84 // Serializes |notification| into a new DictionaryValue which the caller then | 84 // Serializes |notification| into a new DictionaryValue which the caller then |
| 85 // owns. | 85 // owns. |
| 86 static DictionaryValue* SerializeNotification( | 86 static DictionaryValue* SerializeNotification( |
| 87 const AppNotification& notification) { | 87 const AppNotification& notification) { |
| 88 DictionaryValue* dictionary = new DictionaryValue(); | 88 DictionaryValue* dictionary = new DictionaryValue(); |
| 89 dictionary->SetString("title", notification.title); | 89 dictionary->SetString("title", notification.title); |
| 90 dictionary->SetString("body", notification.body); | 90 dictionary->SetString("body", notification.body); |
| 91 if (!notification.linkUrl.is_empty()) { | 91 if (!notification.linkUrl.is_empty()) { |
| 92 dictionary->SetString("linkUrl", notification.linkUrl.spec()); | 92 dictionary->SetString("linkUrl", notification.linkUrl.spec()); |
| 93 dictionary->SetString("linkText", notification.linkText); | 93 dictionary->SetString("linkText", notification.linkText); |
| 94 } | 94 } |
| 95 return dictionary; | 95 return dictionary; |
| 96 } | 96 } |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 99 DictionaryValue* AppLauncherHandler::CreateAppInfo( |
| 100 const AppNotification* notification, | 100 const Extension* extension, |
| 101 ExtensionService* service, | 101 const AppNotification* notification, |
| 102 DictionaryValue* value) { | 102 ExtensionService* service) { |
| 103 // Don't include the WebStore and the Cloud Print app. | |
| 104 // The WebStore launcher gets special treatment in ntp/apps.js. | |
| 105 // The Cloud Print app should never be displayed in the NTP. | |
| 106 bool ntp3 = | |
| 107 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4); | |
| 108 if (!extension->is_app() || | |
| 109 (ntp3 && extension->id() == extension_misc::kWebStoreAppId) || | |
| 110 (extension->id() == extension_misc::kCloudPrintAppId)) { | |
| 111 return NULL; | |
| 112 } | |
| 113 | |
| 103 bool enabled = service->IsExtensionEnabled(extension->id()); | 114 bool enabled = service->IsExtensionEnabled(extension->id()); |
| 115 if (service->GetTerminatedExtension(extension->id())) { | |
| 116 enabled = false; | |
| 117 } | |
|
jstritar
2011/07/28 15:05:26
You don't need these { } braces, but you can keep
Evan Stade
2011/07/28 16:33:21
actually, you can't keep them because the preceden
Yoyo Zhou
2011/07/28 17:02:49
Done.
| |
| 104 GURL icon_big = | 118 GURL icon_big = |
| 105 ExtensionIconSource::GetIconURL(extension, | 119 ExtensionIconSource::GetIconURL(extension, |
| 106 Extension::EXTENSION_ICON_LARGE, | 120 Extension::EXTENSION_ICON_LARGE, |
| 107 ExtensionIconSet::MATCH_EXACTLY, | 121 ExtensionIconSet::MATCH_EXACTLY, |
| 108 !enabled); | 122 !enabled); |
| 109 GURL icon_small = | 123 GURL icon_small = |
| 110 ExtensionIconSource::GetIconURL(extension, | 124 ExtensionIconSource::GetIconURL(extension, |
| 111 Extension::EXTENSION_ICON_BITTY, | 125 Extension::EXTENSION_ICON_BITTY, |
| 112 ExtensionIconSet::MATCH_BIGGER, | 126 ExtensionIconSet::MATCH_BIGGER, |
| 113 !enabled); | 127 !enabled); |
| 114 | 128 |
| 129 DictionaryValue* value = new DictionaryValue(); | |
| 115 value->Clear(); | 130 value->Clear(); |
| 116 value->SetString("id", extension->id()); | 131 value->SetString("id", extension->id()); |
| 117 value->SetString("name", extension->name()); | 132 value->SetString("name", extension->name()); |
| 118 value->SetString("description", extension->description()); | 133 value->SetString("description", extension->description()); |
| 119 value->SetString("launch_url", extension->GetFullLaunchURL().spec()); | 134 value->SetString("launch_url", extension->GetFullLaunchURL().spec()); |
| 120 if (enabled) | 135 if (enabled) |
| 121 value->SetString("options_url", extension->options_url().spec()); | 136 value->SetString("options_url", extension->options_url().spec()); |
| 122 value->SetBoolean("can_uninstall", | 137 value->SetBoolean("can_uninstall", |
| 123 Extension::UserMayDisable(extension->location())); | 138 Extension::UserMayDisable(extension->location())); |
| 124 value->SetString("icon_big", icon_big.spec()); | 139 value->SetString("icon_big", icon_big.spec()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 140 app_launch_index = prefs->GetNextAppLaunchIndex(); | 155 app_launch_index = prefs->GetNextAppLaunchIndex(); |
| 141 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); | 156 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); |
| 142 } | 157 } |
| 143 value->SetInteger("app_launch_index", app_launch_index); | 158 value->SetInteger("app_launch_index", app_launch_index); |
| 144 | 159 |
| 145 int page_index = prefs->GetPageIndex(extension->id()); | 160 int page_index = prefs->GetPageIndex(extension->id()); |
| 146 if (page_index >= 0) { | 161 if (page_index >= 0) { |
| 147 // Only provide a value if one is stored | 162 // Only provide a value if one is stored |
| 148 value->SetInteger("page_index", page_index); | 163 value->SetInteger("page_index", page_index); |
| 149 } | 164 } |
| 165 return value; | |
| 150 } | 166 } |
| 151 | 167 |
| 152 // static | 168 // static |
| 153 bool AppLauncherHandler::HandlePing(Profile* profile, const std::string& path) { | 169 bool AppLauncherHandler::HandlePing(Profile* profile, const std::string& path) { |
| 154 std::vector<std::string> params; | 170 std::vector<std::string> params; |
| 155 base::SplitString(path, '+', ¶ms); | 171 base::SplitString(path, '+', ¶ms); |
| 156 | 172 |
| 157 // Check if the user launched an app from the most visited or recently | 173 // Check if the user launched an app from the most visited or recently |
| 158 // closed sections. | 174 // closed sections. |
| 159 if (kPingLaunchAppByURL == params.at(0)) { | 175 if (kPingLaunchAppByURL == params.at(0)) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 void AppLauncherHandler::Observe(int type, | 239 void AppLauncherHandler::Observe(int type, |
| 224 const NotificationSource& source, | 240 const NotificationSource& source, |
| 225 const NotificationDetails& details) { | 241 const NotificationDetails& details) { |
| 226 if (ignore_changes_) | 242 if (ignore_changes_) |
| 227 return; | 243 return; |
| 228 | 244 |
| 229 switch (type) { | 245 switch (type) { |
| 230 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { | 246 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { |
| 231 const std::string& id = *Details<const std::string>(details).ptr(); | 247 const std::string& id = *Details<const std::string>(details).ptr(); |
| 232 const AppNotification* notification = | 248 const AppNotification* notification = |
| 233 extensions_service_->app_notification_manager()->GetLast(id); | 249 extension_service_->app_notification_manager()->GetLast(id); |
| 234 ListValue args; | 250 ListValue args; |
| 235 args.Append(new StringValue(id)); | 251 args.Append(new StringValue(id)); |
| 236 if (notification) | 252 if (notification) |
| 237 args.Append(SerializeNotification(*notification)); | 253 args.Append(SerializeNotification(*notification)); |
| 238 web_ui_->CallJavascriptFunction("appNotificationChanged", args); | 254 web_ui_->CallJavascriptFunction("appNotificationChanged", args); |
| 239 break; | 255 break; |
| 240 } | 256 } |
| 241 case chrome::NOTIFICATION_EXTENSION_LOADED: | 257 case chrome::NOTIFICATION_EXTENSION_LOADED: |
| 242 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 258 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 243 const Extension* extension = | 259 const Extension* extension = |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 } | 300 } |
| 285 break; | 301 break; |
| 286 } | 302 } |
| 287 default: | 303 default: |
| 288 NOTREACHED(); | 304 NOTREACHED(); |
| 289 } | 305 } |
| 290 } | 306 } |
| 291 | 307 |
| 292 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { | 308 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { |
| 293 ListValue* list = new ListValue(); | 309 ListValue* list = new ListValue(); |
| 294 const ExtensionList* extensions = extensions_service_->extensions(); | 310 const ExtensionList* extensions = extension_service_->extensions(); |
| 295 ExtensionList::const_iterator it; | 311 ExtensionList::const_iterator it; |
| 296 for (it = extensions->begin(); it != extensions->end(); ++it) { | 312 for (it = extensions->begin(); it != extensions->end(); ++it) { |
| 297 // Don't include the WebStore and the Cloud Print app. | 313 DictionaryValue* app_info = GetAppInfo(*it); |
| 298 // The WebStore launcher gets special treatment in ntp/apps.js. | |
| 299 // The Cloud Print app should never be displayed in the NTP. | |
| 300 const Extension* extension = *it; | |
| 301 DictionaryValue* app_info = GetAppInfo(extension); | |
| 302 if (app_info) | 314 if (app_info) |
| 303 list->Append(app_info); | 315 list->Append(app_info); |
| 304 } | 316 } |
| 305 | 317 |
| 306 extensions = extensions_service_->disabled_extensions(); | 318 extensions = extension_service_->disabled_extensions(); |
| 307 for (it = extensions->begin(); it != extensions->end(); ++it) { | 319 for (it = extensions->begin(); it != extensions->end(); ++it) { |
| 308 bool ntp3 = | 320 DictionaryValue* app_info = CreateAppInfo(*it, |
|
jstritar
2011/07/28 15:05:26
Can all these call GetAppInfo?
Yoyo Zhou
2011/07/28 17:02:49
I'm not sure -- it was done this way even before G
| |
| 309 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4); | 321 NULL, |
| 310 if ((*it)->is_app() && | 322 extension_service_); |
| 311 !(ntp3 && (*it)->id() == extension_misc::kWebStoreAppId) && | 323 if (app_info) |
| 312 ((*it)->id() != extension_misc::kCloudPrintAppId)) { | |
| 313 DictionaryValue* app_info = new DictionaryValue(); | |
| 314 CreateAppInfo(*it, | |
| 315 NULL, | |
| 316 extensions_service_, | |
| 317 app_info); | |
| 318 list->Append(app_info); | 324 list->Append(app_info); |
| 319 } | 325 } |
| 326 | |
| 327 extensions = extension_service_->terminated_extensions(); | |
| 328 for (it = extensions->begin(); it != extensions->end(); ++it) { | |
| 329 DictionaryValue* app_info = CreateAppInfo(*it, | |
| 330 NULL, | |
| 331 extension_service_); | |
| 332 if (app_info) | |
| 333 list->Append(app_info); | |
| 320 } | 334 } |
| 321 | 335 |
| 322 dictionary->Set("apps", list); | 336 dictionary->Set("apps", list); |
| 323 | 337 |
| 324 // TODO(estade): remove these settings when the old NTP is removed. The new | 338 // TODO(estade): remove these settings when the old NTP is removed. The new |
| 325 // NTP does it in js. | 339 // NTP does it in js. |
| 326 #if defined(OS_MACOSX) | 340 #if defined(OS_MACOSX) |
| 327 // App windows are not yet implemented on mac. | 341 // App windows are not yet implemented on mac. |
| 328 dictionary->SetBoolean("disableAppWindowLaunch", true); | 342 dictionary->SetBoolean("disableAppWindowLaunch", true); |
| 329 dictionary->SetBoolean("disableCreateAppShortcut", true); | 343 dictionary->SetBoolean("disableCreateAppShortcut", true); |
| 330 #endif | 344 #endif |
| 331 | 345 |
| 332 #if defined(OS_CHROMEOS) | 346 #if defined(OS_CHROMEOS) |
| 333 // Making shortcut does not make sense on ChromeOS because it does not have | 347 // Making shortcut does not make sense on ChromeOS because it does not have |
| 334 // a desktop. | 348 // a desktop. |
| 335 dictionary->SetBoolean("disableCreateAppShortcut", true); | 349 dictionary->SetBoolean("disableCreateAppShortcut", true); |
| 336 #endif | 350 #endif |
| 337 | 351 |
| 338 dictionary->SetBoolean( | 352 dictionary->SetBoolean( |
| 339 "showLauncher", | 353 "showLauncher", |
| 340 extensions_service_->apps_promo()->ShouldShowAppLauncher( | 354 extension_service_->apps_promo()->ShouldShowAppLauncher( |
| 341 extensions_service_->GetAppIds())); | 355 extension_service_->GetAppIds())); |
| 342 | 356 |
| 343 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) { | 357 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) { |
| 344 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 358 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); |
| 345 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); | 359 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); |
| 346 if (app_page_names && app_page_names->GetSize()) { | 360 if (app_page_names && app_page_names->GetSize()) { |
| 347 dictionary->Set("appPageNames", | 361 dictionary->Set("appPageNames", |
| 348 static_cast<ListValue*>(app_page_names->DeepCopy())); | 362 static_cast<ListValue*>(app_page_names->DeepCopy())); |
| 349 } | 363 } |
| 350 } | 364 } |
| 351 } | 365 } |
| 352 | 366 |
| 353 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { | 367 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { |
| 354 bool ntp3 = | |
| 355 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4); | |
| 356 if (!extension->is_app() || | |
| 357 (ntp3 && extension->id() == extension_misc::kWebStoreAppId) || | |
| 358 (extension->id() == extension_misc::kCloudPrintAppId)) { | |
| 359 return NULL; | |
| 360 } | |
| 361 | |
| 362 DictionaryValue* app_info = new DictionaryValue(); | |
| 363 AppNotificationManager* notification_manager = | 368 AppNotificationManager* notification_manager = |
| 364 extensions_service_->app_notification_manager(); | 369 extension_service_->app_notification_manager(); |
| 365 CreateAppInfo(extension, | 370 return CreateAppInfo(extension, |
| 366 notification_manager->GetLast(extension->id()), | 371 notification_manager->GetLast(extension->id()), |
| 367 extensions_service_, | 372 extension_service_); |
| 368 app_info); | |
| 369 return app_info; | |
| 370 } | 373 } |
| 371 | 374 |
| 372 void AppLauncherHandler::FillPromoDictionary(DictionaryValue* dictionary) { | 375 void AppLauncherHandler::FillPromoDictionary(DictionaryValue* dictionary) { |
| 373 dictionary->SetString("promoHeader", AppsPromo::GetPromoHeaderText()); | 376 dictionary->SetString("promoHeader", AppsPromo::GetPromoHeaderText()); |
| 374 dictionary->SetString("promoButton", AppsPromo::GetPromoButtonText()); | 377 dictionary->SetString("promoButton", AppsPromo::GetPromoButtonText()); |
| 375 dictionary->SetString("promoLink", AppsPromo::GetPromoLink().spec()); | 378 dictionary->SetString("promoLink", AppsPromo::GetPromoLink().spec()); |
| 376 dictionary->SetString("promoLogo", AppsPromo::GetPromoLogo().spec()); | 379 dictionary->SetString("promoLogo", AppsPromo::GetPromoLogo().spec()); |
| 377 dictionary->SetString("promoExpire", AppsPromo::GetPromoExpireText()); | 380 dictionary->SetString("promoExpire", AppsPromo::GetPromoExpireText()); |
| 378 } | 381 } |
| 379 | 382 |
| 380 void AppLauncherHandler::HandleGetApps(const ListValue* args) { | 383 void AppLauncherHandler::HandleGetApps(const ListValue* args) { |
| 381 DictionaryValue dictionary; | 384 DictionaryValue dictionary; |
| 382 | 385 |
| 383 // Tell the client whether to show the promo for this view. We don't do this | 386 // Tell the client whether to show the promo for this view. We don't do this |
| 384 // in the case of PREF_CHANGED because: | 387 // in the case of PREF_CHANGED because: |
| 385 // | 388 // |
| 386 // a) At that point in time, depending on the pref that changed, it can look | 389 // a) At that point in time, depending on the pref that changed, it can look |
| 387 // like the set of apps installed has changed, and we will mark the promo | 390 // like the set of apps installed has changed, and we will mark the promo |
| 388 // expired. | 391 // expired. |
| 389 // b) Conceptually, it doesn't really make sense to count a | 392 // b) Conceptually, it doesn't really make sense to count a |
| 390 // prefchange-triggered refresh as a promo 'view'. | 393 // prefchange-triggered refresh as a promo 'view'. |
| 391 AppsPromo* apps_promo = extensions_service_->apps_promo(); | 394 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 392 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 395 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); |
| 393 bool apps_promo_just_expired = false; | 396 bool apps_promo_just_expired = false; |
| 394 if (apps_promo->ShouldShowPromo(extensions_service_->GetAppIds(), | 397 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(), |
| 395 &apps_promo_just_expired)) { | 398 &apps_promo_just_expired)) { |
| 396 apps_promo->MaximizeAppsIfNecessary(); | 399 apps_promo->MaximizeAppsIfNecessary(); |
| 397 dictionary.SetBoolean("showPromo", true); | 400 dictionary.SetBoolean("showPromo", true); |
| 398 FillPromoDictionary(&dictionary); | 401 FillPromoDictionary(&dictionary); |
| 399 promo_active_ = true; | 402 promo_active_ = true; |
| 400 } else { | 403 } else { |
| 401 dictionary.SetBoolean("showPromo", false); | 404 dictionary.SetBoolean("showPromo", false); |
| 402 promo_active_ = false; | 405 promo_active_ = false; |
| 403 } | 406 } |
| 404 | 407 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 423 NotificationService::AllSources()); | 426 NotificationService::AllSources()); |
| 424 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 427 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 425 NotificationService::AllSources()); | 428 NotificationService::AllSources()); |
| 426 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, | 429 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
| 427 NotificationService::AllSources()); | 430 NotificationService::AllSources()); |
| 428 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, | 431 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, |
| 429 NotificationService::AllSources()); | 432 NotificationService::AllSources()); |
| 430 } | 433 } |
| 431 if (pref_change_registrar_.IsEmpty()) { | 434 if (pref_change_registrar_.IsEmpty()) { |
| 432 pref_change_registrar_.Init( | 435 pref_change_registrar_.Init( |
| 433 extensions_service_->extension_prefs()->pref_service()); | 436 extension_service_->extension_prefs()->pref_service()); |
| 434 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); | 437 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); |
| 435 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this); | 438 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this); |
| 436 } | 439 } |
| 437 } | 440 } |
| 438 | 441 |
| 439 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) { | 442 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) { |
| 440 std::string extension_id; | 443 std::string extension_id; |
| 441 double source = -1.0; | 444 double source = -1.0; |
| 442 bool alt_key = false; | 445 bool alt_key = false; |
| 443 bool ctrl_key = false; | 446 bool ctrl_key = false; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 455 CHECK(args->GetDouble(6, &button)); | 458 CHECK(args->GetDouble(6, &button)); |
| 456 } | 459 } |
| 457 | 460 |
| 458 extension_misc::AppLaunchBucket launch_bucket = | 461 extension_misc::AppLaunchBucket launch_bucket = |
| 459 static_cast<extension_misc::AppLaunchBucket>( | 462 static_cast<extension_misc::AppLaunchBucket>( |
| 460 static_cast<int>(source)); | 463 static_cast<int>(source)); |
| 461 CHECK(launch_bucket >= 0 && | 464 CHECK(launch_bucket >= 0 && |
| 462 launch_bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 465 launch_bucket < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 463 | 466 |
| 464 const Extension* extension = | 467 const Extension* extension = |
| 465 extensions_service_->GetExtensionById(extension_id, false); | 468 extension_service_->GetExtensionById(extension_id, false); |
| 466 | 469 |
| 467 // Prompt the user to re-enable the application if disabled. | 470 // Prompt the user to re-enable the application if disabled. |
| 468 if (!extension) { | 471 if (!extension) { |
| 469 PromptToEnableApp(extension_id); | 472 PromptToEnableApp(extension_id); |
| 470 return; | 473 return; |
| 471 } | 474 } |
| 472 | 475 |
| 473 Profile* profile = extensions_service_->profile(); | 476 Profile* profile = extension_service_->profile(); |
| 474 | 477 |
| 475 // If the user pressed special keys when clicking, override the saved | 478 // If the user pressed special keys when clicking, override the saved |
| 476 // preference for launch container. | 479 // preference for launch container. |
| 477 bool middle_button = (button == 1.0); | 480 bool middle_button = (button == 1.0); |
| 478 WindowOpenDisposition disposition = | 481 WindowOpenDisposition disposition = |
| 479 disposition_utils::DispositionFromClick(middle_button, alt_key, | 482 disposition_utils::DispositionFromClick(middle_button, alt_key, |
| 480 ctrl_key, meta_key, shift_key); | 483 ctrl_key, meta_key, shift_key); |
| 481 | 484 |
| 482 if (extension_id != extension_misc::kWebStoreAppId) { | 485 if (extension_id != extension_misc::kWebStoreAppId) { |
| 483 RecordAppLaunchByID(promo_active_, launch_bucket); | 486 RecordAppLaunchByID(promo_active_, launch_bucket); |
| 484 extensions_service_->apps_promo()->ExpireDefaultApps(); | 487 extension_service_->apps_promo()->ExpireDefaultApps(); |
| 485 } | 488 } |
| 486 | 489 |
| 487 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 490 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
| 488 // TODO(jamescook): Proper support for background tabs. | 491 // TODO(jamescook): Proper support for background tabs. |
| 489 Browser::OpenApplication( | 492 Browser::OpenApplication( |
| 490 profile, extension, extension_misc::LAUNCH_TAB, disposition); | 493 profile, extension, extension_misc::LAUNCH_TAB, disposition); |
| 491 } else if (disposition == NEW_WINDOW) { | 494 } else if (disposition == NEW_WINDOW) { |
| 492 // Force a new window open. | 495 // Force a new window open. |
| 493 Browser::OpenApplication( | 496 Browser::OpenApplication( |
| 494 profile, extension, extension_misc::LAUNCH_WINDOW, disposition); | 497 profile, extension, extension_misc::LAUNCH_WINDOW, disposition); |
| 495 } else { | 498 } else { |
| 496 // Look at preference to find the right launch container. If no preference | 499 // Look at preference to find the right launch container. If no preference |
| 497 // is set, launch as a regular tab. | 500 // is set, launch as a regular tab. |
| 498 extension_misc::LaunchContainer launch_container = | 501 extension_misc::LaunchContainer launch_container = |
| 499 extensions_service_->extension_prefs()->GetLaunchContainer( | 502 extension_service_->extension_prefs()->GetLaunchContainer( |
| 500 extension, ExtensionPrefs::LAUNCH_REGULAR); | 503 extension, ExtensionPrefs::LAUNCH_REGULAR); |
| 501 | 504 |
| 502 // To give a more "launchy" experience when using the NTP launcher, we close | 505 // To give a more "launchy" experience when using the NTP launcher, we close |
| 503 // it automatically. | 506 // it automatically. |
| 504 Browser* browser = BrowserList::GetLastActive(); | 507 Browser* browser = BrowserList::GetLastActive(); |
| 505 TabContents* old_contents = NULL; | 508 TabContents* old_contents = NULL; |
| 506 if (browser) | 509 if (browser) |
| 507 old_contents = browser->GetSelectedTabContents(); | 510 old_contents = browser->GetSelectedTabContents(); |
| 508 | 511 |
| 509 TabContents* new_contents = Browser::OpenApplication( | 512 TabContents* new_contents = Browser::OpenApplication( |
| 510 profile, extension, launch_container, | 513 profile, extension, launch_container, |
| 511 old_contents ? CURRENT_TAB : NEW_FOREGROUND_TAB); | 514 old_contents ? CURRENT_TAB : NEW_FOREGROUND_TAB); |
| 512 | 515 |
| 513 // This will also destroy the handler, so do not perform any actions after. | 516 // This will also destroy the handler, so do not perform any actions after. |
| 514 if (new_contents != old_contents && browser && browser->tab_count() > 1) | 517 if (new_contents != old_contents && browser && browser->tab_count() > 1) |
| 515 browser->CloseTabContents(old_contents); | 518 browser->CloseTabContents(old_contents); |
| 516 } | 519 } |
| 517 } | 520 } |
| 518 | 521 |
| 519 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) { | 522 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) { |
| 520 std::string extension_id; | 523 std::string extension_id; |
| 521 double launch_type; | 524 double launch_type; |
| 522 CHECK(args->GetString(0, &extension_id)); | 525 CHECK(args->GetString(0, &extension_id)); |
| 523 CHECK(args->GetDouble(1, &launch_type)); | 526 CHECK(args->GetDouble(1, &launch_type)); |
| 524 | 527 |
| 525 const Extension* extension = | 528 const Extension* extension = |
| 526 extensions_service_->GetExtensionById(extension_id, true); | 529 extension_service_->GetExtensionById(extension_id, true); |
| 527 CHECK(extension); | 530 CHECK(extension); |
| 528 | 531 |
| 529 // Don't update the page; it already knows about the launch type change. | 532 // Don't update the page; it already knows about the launch type change. |
| 530 scoped_ptr<AutoReset<bool> > auto_reset; | 533 scoped_ptr<AutoReset<bool> > auto_reset; |
| 531 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) | 534 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) |
| 532 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | 535 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); |
| 533 | 536 |
| 534 extensions_service_->extension_prefs()->SetLaunchType( | 537 extension_service_->extension_prefs()->SetLaunchType( |
| 535 extension_id, | 538 extension_id, |
| 536 static_cast<ExtensionPrefs::LaunchType>( | 539 static_cast<ExtensionPrefs::LaunchType>( |
| 537 static_cast<int>(launch_type))); | 540 static_cast<int>(launch_type))); |
| 538 } | 541 } |
| 539 | 542 |
| 540 void AppLauncherHandler::HandleUninstallApp(const ListValue* args) { | 543 void AppLauncherHandler::HandleUninstallApp(const ListValue* args) { |
| 541 std::string extension_id; | 544 std::string extension_id; |
| 542 CHECK(args->GetString(0, &extension_id)); | 545 CHECK(args->GetString(0, &extension_id)); |
| 543 | 546 |
| 544 const Extension* extension = extensions_service_->GetExtensionById( | 547 const Extension* extension = extension_service_->GetExtensionById( |
| 545 extension_id, true); | 548 extension_id, true); |
| 546 if (!extension) | 549 if (!extension) |
| 547 return; | 550 return; |
| 548 | 551 |
| 549 if (!Extension::UserMayDisable(extension->location())) { | 552 if (!Extension::UserMayDisable(extension->location())) { |
| 550 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " | 553 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " |
| 551 << "was made. Extension id : " << extension->id(); | 554 << "was made. Extension id : " << extension->id(); |
| 552 return; | 555 return; |
| 553 } | 556 } |
| 554 if (!extension_id_prompting_.empty()) | 557 if (!extension_id_prompting_.empty()) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 566 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension); | 569 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension); |
| 567 } | 570 } |
| 568 } | 571 } |
| 569 | 572 |
| 570 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { | 573 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { |
| 571 // If the user has intentionally hidden the promotion, we'll uninstall all the | 574 // If the user has intentionally hidden the promotion, we'll uninstall all the |
| 572 // default apps (we know the user hasn't installed any apps on their own at | 575 // default apps (we know the user hasn't installed any apps on their own at |
| 573 // this point, or the promotion wouldn't have been shown). | 576 // this point, or the promotion wouldn't have been shown). |
| 574 ignore_changes_ = true; | 577 ignore_changes_ = true; |
| 575 UninstallDefaultApps(); | 578 UninstallDefaultApps(); |
| 576 extensions_service_->apps_promo()->HidePromo(); | 579 extension_service_->apps_promo()->HidePromo(); |
| 577 ignore_changes_ = false; | 580 ignore_changes_ = false; |
| 578 HandleGetApps(NULL); | 581 HandleGetApps(NULL); |
| 579 } | 582 } |
| 580 | 583 |
| 581 void AppLauncherHandler::HandleCreateAppShortcut(const ListValue* args) { | 584 void AppLauncherHandler::HandleCreateAppShortcut(const ListValue* args) { |
| 582 std::string extension_id; | 585 std::string extension_id; |
| 583 if (!args->GetString(0, &extension_id)) { | 586 if (!args->GetString(0, &extension_id)) { |
| 584 NOTREACHED(); | 587 NOTREACHED(); |
| 585 return; | 588 return; |
| 586 } | 589 } |
| 587 | 590 |
| 588 const Extension* extension = | 591 const Extension* extension = |
| 589 extensions_service_->GetExtensionById(extension_id, true); | 592 extension_service_->GetExtensionById(extension_id, true); |
| 590 CHECK(extension); | 593 CHECK(extension); |
| 591 | 594 |
| 592 Browser* browser = BrowserList::GetLastActive(); | 595 Browser* browser = BrowserList::GetLastActive(); |
| 593 if (!browser) | 596 if (!browser) |
| 594 return; | 597 return; |
| 595 browser->window()->ShowCreateChromeAppShortcutsDialog( | 598 browser->window()->ShowCreateChromeAppShortcutsDialog( |
| 596 browser->profile(), extension); | 599 browser->profile(), extension); |
| 597 } | 600 } |
| 598 | 601 |
| 599 void AppLauncherHandler::HandleReorderApps(const ListValue* args) { | 602 void AppLauncherHandler::HandleReorderApps(const ListValue* args) { |
| 600 CHECK(args->GetSize() == 2); | 603 CHECK(args->GetSize() == 2); |
| 601 | 604 |
| 602 std::string dragged_app_id; | 605 std::string dragged_app_id; |
| 603 ListValue* app_order; | 606 ListValue* app_order; |
| 604 CHECK(args->GetString(0, &dragged_app_id)); | 607 CHECK(args->GetString(0, &dragged_app_id)); |
| 605 CHECK(args->GetList(1, &app_order)); | 608 CHECK(args->GetList(1, &app_order)); |
| 606 | 609 |
| 607 std::vector<std::string> extension_ids; | 610 std::vector<std::string> extension_ids; |
| 608 for (size_t i = 0; i < app_order->GetSize(); ++i) { | 611 for (size_t i = 0; i < app_order->GetSize(); ++i) { |
| 609 std::string value; | 612 std::string value; |
| 610 if (app_order->GetString(i, &value)) | 613 if (app_order->GetString(i, &value)) |
| 611 extension_ids.push_back(value); | 614 extension_ids.push_back(value); |
| 612 } | 615 } |
| 613 | 616 |
| 614 // Don't update the page; it already knows the apps have been reordered. | 617 // Don't update the page; it already knows the apps have been reordered. |
| 615 scoped_ptr<AutoReset<bool> > auto_reset; | 618 scoped_ptr<AutoReset<bool> > auto_reset; |
| 616 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) | 619 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) |
| 617 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | 620 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); |
| 618 | 621 |
| 619 extensions_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id); | 622 extension_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id); |
| 620 extensions_service_->extension_prefs()->SetAppLauncherOrder(extension_ids); | 623 extension_service_->extension_prefs()->SetAppLauncherOrder(extension_ids); |
| 621 } | 624 } |
| 622 | 625 |
| 623 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { | 626 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { |
| 624 std::string extension_id; | 627 std::string extension_id; |
| 625 double page_index; | 628 double page_index; |
| 626 CHECK(args->GetString(0, &extension_id)); | 629 CHECK(args->GetString(0, &extension_id)); |
| 627 CHECK(args->GetDouble(1, &page_index)); | 630 CHECK(args->GetDouble(1, &page_index)); |
| 628 | 631 |
| 629 // Don't update the page; it already knows the apps have been reordered. | 632 // Don't update the page; it already knows the apps have been reordered. |
| 630 scoped_ptr<AutoReset<bool> > auto_reset; | 633 scoped_ptr<AutoReset<bool> > auto_reset; |
| 631 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) | 634 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) |
| 632 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | 635 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); |
| 633 | 636 |
| 634 extensions_service_->extension_prefs()->SetPageIndex(extension_id, | 637 extension_service_->extension_prefs()->SetPageIndex(extension_id, |
| 635 static_cast<int>(page_index)); | 638 static_cast<int>(page_index)); |
| 636 } | 639 } |
| 637 | 640 |
| 638 void AppLauncherHandler::HandlePromoSeen(const ListValue* args) { | 641 void AppLauncherHandler::HandlePromoSeen(const ListValue* args) { |
| 639 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, | 642 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
| 640 extension_misc::PROMO_SEEN, | 643 extension_misc::PROMO_SEEN, |
| 641 extension_misc::PROMO_BUCKET_BOUNDARY); | 644 extension_misc::PROMO_BUCKET_BOUNDARY); |
| 642 } | 645 } |
| 643 | 646 |
| 644 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) { | 647 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 672 icon.url = GURL(); | 675 icon.url = GURL(); |
| 673 icon.width = icon.height = 16; | 676 icon.width = icon.height = 16; |
| 674 web_app->icons.push_back(icon); | 677 web_app->icons.push_back(icon); |
| 675 | 678 |
| 676 Profile* profile = web_ui_->GetProfile(); | 679 Profile* profile = web_ui_->GetProfile(); |
| 677 FaviconService* favicon_service = | 680 FaviconService* favicon_service = |
| 678 profile->GetFaviconService(Profile::EXPLICIT_ACCESS); | 681 profile->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 679 if (!favicon_service) { | 682 if (!favicon_service) { |
| 680 LOG(ERROR) << "No favicon service"; | 683 LOG(ERROR) << "No favicon service"; |
| 681 scoped_refptr<CrxInstaller> installer( | 684 scoped_refptr<CrxInstaller> installer( |
| 682 extensions_service_->MakeCrxInstaller(NULL)); | 685 extension_service_->MakeCrxInstaller(NULL)); |
| 683 installer->InstallWebApp(*web_app); | 686 installer->InstallWebApp(*web_app); |
| 684 return; | 687 return; |
| 685 } | 688 } |
| 686 | 689 |
| 687 // TODO(gbillock): get page thumb from thumbnail db/history svc? | 690 // TODO(gbillock): get page thumb from thumbnail db/history svc? |
| 688 FaviconService::Handle h = favicon_service->GetFaviconForURL( | 691 FaviconService::Handle h = favicon_service->GetFaviconForURL( |
| 689 launch_url, history::FAVICON, &favicon_consumer_, | 692 launch_url, history::FAVICON, &favicon_consumer_, |
| 690 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); | 693 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); |
| 691 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); | 694 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); |
| 692 } | 695 } |
| 693 | 696 |
| 694 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, | 697 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, |
| 695 history::FaviconData data) { | 698 history::FaviconData data) { |
| 696 scoped_ptr<WebApplicationInfo> web_app( | 699 scoped_ptr<WebApplicationInfo> web_app( |
| 697 favicon_consumer_.GetClientDataForCurrentRequest()); | 700 favicon_consumer_.GetClientDataForCurrentRequest()); |
| 698 CHECK(!web_app->icons.empty()); | 701 CHECK(!web_app->icons.empty()); |
| 699 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), | 702 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), |
| 700 data.image_data->size(), | 703 data.image_data->size(), |
| 701 &(web_app->icons[0].data))) { | 704 &(web_app->icons[0].data))) { |
| 702 web_app->icons[0].url = GURL(); | 705 web_app->icons[0].url = GURL(); |
| 703 web_app->icons[0].width = web_app->icons[0].data.width(); | 706 web_app->icons[0].width = web_app->icons[0].data.width(); |
| 704 web_app->icons[0].height = web_app->icons[0].data.height(); | 707 web_app->icons[0].height = web_app->icons[0].data.height(); |
| 705 } | 708 } |
| 706 | 709 |
| 707 scoped_refptr<CrxInstaller> installer( | 710 scoped_refptr<CrxInstaller> installer( |
| 708 extensions_service_->MakeCrxInstaller(NULL)); | 711 extension_service_->MakeCrxInstaller(NULL)); |
| 709 installer->InstallWebApp(*web_app); | 712 installer->InstallWebApp(*web_app); |
| 710 } | 713 } |
| 711 | 714 |
| 712 // static | 715 // static |
| 713 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) { | 716 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) { |
| 714 // TODO(csilv): We will want this to be a syncable preference instead. | 717 // TODO(csilv): We will want this to be a syncable preference instead. |
| 715 pref_service->RegisterListPref(prefs::kNTPAppPageNames, | 718 pref_service->RegisterListPref(prefs::kNTPAppPageNames, |
| 716 PrefService::UNSYNCABLE_PREF); | 719 PrefService::UNSYNCABLE_PREF); |
| 717 } | 720 } |
| 718 | 721 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 GURL url(UnescapeURLComponent(escaped_url, kUnescapeRules)); | 757 GURL url(UnescapeURLComponent(escaped_url, kUnescapeRules)); |
| 755 DCHECK(profile->GetExtensionService()); | 758 DCHECK(profile->GetExtensionService()); |
| 756 if (!profile->GetExtensionService()->IsInstalledApp(url)) | 759 if (!profile->GetExtensionService()->IsInstalledApp(url)) |
| 757 return; | 760 return; |
| 758 | 761 |
| 759 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, bucket, | 762 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, bucket, |
| 760 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 763 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 761 } | 764 } |
| 762 | 765 |
| 763 void AppLauncherHandler::PromptToEnableApp(const std::string& extension_id) { | 766 void AppLauncherHandler::PromptToEnableApp(const std::string& extension_id) { |
| 767 bool was_terminated = false; | |
| 764 const Extension* extension = | 768 const Extension* extension = |
| 765 extensions_service_->GetExtensionById(extension_id, true); | 769 extension_service_->GetExtensionById(extension_id, true); |
| 770 if (!extension) { | |
| 771 extension = extension_service_->GetTerminatedExtension(extension_id); | |
| 772 was_terminated = true; | |
| 773 } | |
|
jstritar
2011/07/28 15:05:26
Maybe you don't need was_terminated?
if (!extensi
Yoyo Zhou
2011/07/28 17:02:49
Ah, yes, I changed this and didn't see this afterw
Yoyo Zhou
2011/07/28 17:15:00
Oh, also, Reloading invalidates the 'extension' po
Evan Stade
2011/07/28 17:35:16
yes
| |
| 766 CHECK(extension); | 774 CHECK(extension); |
| 767 | 775 |
| 768 ExtensionPrefs* extension_prefs = extensions_service_->extension_prefs(); | 776 if (was_terminated) { |
|
Evan Stade
2011/07/28 16:33:21
ditto
| |
| 777 extension_service_->ReloadExtension(extension_id); | |
| 778 } | |
| 779 | |
| 780 ExtensionPrefs* extension_prefs = extension_service_->extension_prefs(); | |
| 769 if (!extension_prefs->DidExtensionEscalatePermissions(extension_id)) { | 781 if (!extension_prefs->DidExtensionEscalatePermissions(extension_id)) { |
| 770 // Enable the extension immediately if its privileges weren't escalated. | 782 // Enable the extension immediately if its privileges weren't escalated. |
| 771 extensions_service_->EnableExtension(extension_id); | 783 // This is a no-op if the extension was previously terminated. |
| 784 extension_service_->EnableExtension(extension_id); | |
| 772 | 785 |
| 773 // Launch app asynchronously so the image will update. | 786 // Launch app asynchronously so the image will update. |
| 774 StringValue* app_id = Value::CreateStringValue(extension->id()); | 787 StringValue* app_id = Value::CreateStringValue(extension_id); |
| 775 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); | 788 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); |
| 776 return; | 789 return; |
| 777 } | 790 } |
| 778 | 791 |
| 779 if (!extension_id_prompting_.empty()) | 792 if (!extension_id_prompting_.empty()) |
| 780 return; // Only one prompt at a time. | 793 return; // Only one prompt at a time. |
| 781 | 794 |
| 782 extension_id_prompting_ = extension_id; | 795 extension_id_prompting_ = extension_id; |
| 783 GetExtensionInstallUI()->ConfirmReEnable(this, extension); | 796 GetExtensionInstallUI()->ConfirmReEnable(this, extension); |
| 784 } | 797 } |
| 785 | 798 |
| 786 void AppLauncherHandler::ExtensionDialogAccepted() { | 799 void AppLauncherHandler::ExtensionDialogAccepted() { |
| 787 // Do the uninstall work here. | 800 // Do the uninstall work here. |
| 788 DCHECK(!extension_id_prompting_.empty()); | 801 DCHECK(!extension_id_prompting_.empty()); |
| 789 | 802 |
| 790 // The extension can be uninstalled in another window while the UI was | 803 // The extension can be uninstalled in another window while the UI was |
| 791 // showing. Do nothing in that case. | 804 // showing. Do nothing in that case. |
| 792 const Extension* extension = | 805 const Extension* extension = |
| 793 extensions_service_->GetExtensionById(extension_id_prompting_, true); | 806 extension_service_->GetExtensionById(extension_id_prompting_, true); |
| 794 if (!extension) | 807 if (!extension) |
| 795 return; | 808 return; |
| 796 | 809 |
| 797 extensions_service_->UninstallExtension(extension_id_prompting_, | 810 extension_service_->UninstallExtension(extension_id_prompting_, |
| 798 false /* external_uninstall */, NULL); | 811 false /* external_uninstall */, NULL); |
|
Evan Stade
2011/07/28 16:33:21
indent changed
Yoyo Zhou
2011/07/28 17:02:49
fixed.
| |
| 799 | 812 |
| 800 extension_id_prompting_ = ""; | 813 extension_id_prompting_ = ""; |
| 801 } | 814 } |
| 802 | 815 |
| 803 void AppLauncherHandler::ExtensionDialogCanceled() { | 816 void AppLauncherHandler::ExtensionDialogCanceled() { |
| 804 extension_id_prompting_ = ""; | 817 extension_id_prompting_ = ""; |
| 805 } | 818 } |
| 806 | 819 |
| 807 void AppLauncherHandler::InstallUIProceed() { | 820 void AppLauncherHandler::InstallUIProceed() { |
| 808 // Do the re-enable work here. | 821 // Do the re-enable work here. |
| 809 DCHECK(!extension_id_prompting_.empty()); | 822 DCHECK(!extension_id_prompting_.empty()); |
| 810 | 823 |
| 811 // The extension can be uninstalled in another window while the UI was | 824 // The extension can be uninstalled in another window while the UI was |
| 812 // showing. Do nothing in that case. | 825 // showing. Do nothing in that case. |
| 813 const Extension* extension = | 826 const Extension* extension = |
| 814 extensions_service_->GetExtensionById(extension_id_prompting_, true); | 827 extension_service_->GetExtensionById(extension_id_prompting_, true); |
| 815 if (!extension) | 828 if (!extension) |
| 816 return; | 829 return; |
| 817 | 830 |
| 818 extensions_service_->GrantPermissionsAndEnableExtension(extension); | 831 extension_service_->GrantPermissionsAndEnableExtension(extension); |
| 819 | 832 |
| 820 // We bounce this off the NTP so the browser can update the apps icon. | 833 // We bounce this off the NTP so the browser can update the apps icon. |
| 821 // If we don't launch the app asynchronously, then the app's disabled | 834 // If we don't launch the app asynchronously, then the app's disabled |
| 822 // icon disappears but isn't replaced by the enabled icon, making a poor | 835 // icon disappears but isn't replaced by the enabled icon, making a poor |
| 823 // visual experience. | 836 // visual experience. |
| 824 StringValue* app_id = Value::CreateStringValue(extension->id()); | 837 StringValue* app_id = Value::CreateStringValue(extension->id()); |
| 825 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); | 838 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); |
| 826 | 839 |
| 827 extension_id_prompting_ = ""; | 840 extension_id_prompting_ = ""; |
| 828 } | 841 } |
| 829 | 842 |
| 830 void AppLauncherHandler::InstallUIAbort(bool user_initiated) { | 843 void AppLauncherHandler::InstallUIAbort(bool user_initiated) { |
| 831 // We record the histograms here because ExtensionDialogCanceled is also | 844 // We record the histograms here because ExtensionDialogCanceled is also |
| 832 // called when the extension uninstall dialog is canceled. | 845 // called when the extension uninstall dialog is canceled. |
| 833 const Extension* extension = | 846 const Extension* extension = |
| 834 extensions_service_->GetExtensionById(extension_id_prompting_, true); | 847 extension_service_->GetExtensionById(extension_id_prompting_, true); |
| 835 std::string histogram_name = user_initiated ? | 848 std::string histogram_name = user_initiated ? |
| 836 "Extensions.Permissions_ReEnableCancel" : | 849 "Extensions.Permissions_ReEnableCancel" : |
| 837 "Extensions.Permissions_ReEnableAbort"; | 850 "Extensions.Permissions_ReEnableAbort"; |
| 838 ExtensionService::RecordPermissionMessagesHistogram( | 851 ExtensionService::RecordPermissionMessagesHistogram( |
| 839 extension, histogram_name.c_str()); | 852 extension, histogram_name.c_str()); |
| 840 | 853 |
| 841 ExtensionDialogCanceled(); | 854 ExtensionDialogCanceled(); |
| 842 } | 855 } |
| 843 | 856 |
| 844 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { | 857 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
| 845 if (!extension_uninstall_dialog_.get()) { | 858 if (!extension_uninstall_dialog_.get()) { |
| 846 extension_uninstall_dialog_.reset( | 859 extension_uninstall_dialog_.reset( |
| 847 new ExtensionUninstallDialog(web_ui_->GetProfile())); | 860 new ExtensionUninstallDialog(web_ui_->GetProfile())); |
| 848 } | 861 } |
| 849 return extension_uninstall_dialog_.get(); | 862 return extension_uninstall_dialog_.get(); |
| 850 } | 863 } |
| 851 | 864 |
| 852 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { | 865 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { |
| 853 if (!extension_install_ui_.get()) { | 866 if (!extension_install_ui_.get()) { |
| 854 extension_install_ui_.reset( | 867 extension_install_ui_.reset( |
| 855 new ExtensionInstallUI(web_ui_->GetProfile())); | 868 new ExtensionInstallUI(web_ui_->GetProfile())); |
| 856 } | 869 } |
| 857 return extension_install_ui_.get(); | 870 return extension_install_ui_.get(); |
| 858 } | 871 } |
| 859 | 872 |
| 860 void AppLauncherHandler::UninstallDefaultApps() { | 873 void AppLauncherHandler::UninstallDefaultApps() { |
| 861 AppsPromo* apps_promo = extensions_service_->apps_promo(); | 874 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 862 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 875 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 863 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 876 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 864 iter != app_ids.end(); ++iter) { | 877 iter != app_ids.end(); ++iter) { |
| 865 if (extensions_service_->GetExtensionById(*iter, true)) | 878 if (extension_service_->GetExtensionById(*iter, true)) |
| 866 extensions_service_->UninstallExtension(*iter, false, NULL); | 879 extension_service_->UninstallExtension(*iter, false, NULL); |
| 867 } | 880 } |
| 868 } | 881 } |
| OLD | NEW |