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