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