| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "apps/metrics_names.h" | 9 #include "apps/metrics_names.h" |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); | 247 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); |
| 248 if (has_loaded_apps_) | 248 if (has_loaded_apps_) |
| 249 SetAppToBeHighlighted(); | 249 SetAppToBeHighlighted(); |
| 250 return; | 250 return; |
| 251 } | 251 } |
| 252 | 252 |
| 253 if (ignore_changes_ || !has_loaded_apps_) | 253 if (ignore_changes_ || !has_loaded_apps_) |
| 254 return; | 254 return; |
| 255 | 255 |
| 256 switch (type) { | 256 switch (type) { |
| 257 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | 257 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { |
| 258 const Extension* extension = | 258 const Extension* extension = |
| 259 content::Details<const Extension>(details).ptr(); | 259 content::Details<const Extension>(details).ptr(); |
| 260 if (!extension->is_app()) | 260 if (!extension->is_app()) |
| 261 return; | 261 return; |
| 262 | 262 |
| 263 if (!extensions::ui_util::ShouldDisplayInNewTabPage( | 263 if (!extensions::ui_util::ShouldDisplayInNewTabPage( |
| 264 extension, Profile::FromWebUI(web_ui()))) { | 264 extension, Profile::FromWebUI(web_ui()))) { |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 | 267 |
| 268 scoped_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); | 268 scoped_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); |
| 269 if (app_info.get()) { | 269 if (app_info.get()) { |
| 270 visible_apps_.insert(extension->id()); | 270 visible_apps_.insert(extension->id()); |
| 271 | 271 |
| 272 ExtensionPrefs* prefs = | 272 ExtensionPrefs* prefs = |
| 273 ExtensionPrefs::Get(extension_service_->profile()); | 273 ExtensionPrefs::Get(extension_service_->profile()); |
| 274 base::FundamentalValue highlight( | 274 base::FundamentalValue highlight( |
| 275 prefs->IsFromBookmark(extension->id()) && | 275 prefs->IsFromBookmark(extension->id()) && |
| 276 attempted_bookmark_app_install_); | 276 attempted_bookmark_app_install_); |
| 277 attempted_bookmark_app_install_ = false; | 277 attempted_bookmark_app_install_ = false; |
| 278 web_ui()->CallJavascriptFunction("ntp.appAdded", *app_info, highlight); | 278 web_ui()->CallJavascriptFunction("ntp.appAdded", *app_info, highlight); |
| 279 } | 279 } |
| 280 | 280 |
| 281 break; | 281 break; |
| 282 } | 282 } |
| 283 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: | 283 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: |
| 284 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: { | 284 case extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: { |
| 285 const Extension* extension = NULL; | 285 const Extension* extension = NULL; |
| 286 bool uninstalled = false; | 286 bool uninstalled = false; |
| 287 if (type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED) { | 287 if (type == extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED) { |
| 288 extension = content::Details<const Extension>(details).ptr(); | 288 extension = content::Details<const Extension>(details).ptr(); |
| 289 uninstalled = true; | 289 uninstalled = true; |
| 290 } else { // NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED | 290 } else { // NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED |
| 291 if (content::Details<UnloadedExtensionInfo>(details)->reason == | 291 if (content::Details<UnloadedExtensionInfo>(details)->reason == |
| 292 UnloadedExtensionInfo::REASON_UNINSTALL) { | 292 UnloadedExtensionInfo::REASON_UNINSTALL) { |
| 293 // Uninstalls are tracked by | 293 // Uninstalls are tracked by |
| 294 // NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED. | 294 // NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED. |
| 295 return; | 295 return; |
| 296 } | 296 } |
| 297 extension = content::Details<extensions::UnloadedExtensionInfo>( | 297 extension = content::Details<extensions::UnloadedExtensionInfo>( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 312 visible_apps_.erase(extension->id()); | 312 visible_apps_.erase(extension->id()); |
| 313 | 313 |
| 314 web_ui()->CallJavascriptFunction( | 314 web_ui()->CallJavascriptFunction( |
| 315 "ntp.appRemoved", | 315 "ntp.appRemoved", |
| 316 *app_info, | 316 *app_info, |
| 317 base::FundamentalValue(uninstalled), | 317 base::FundamentalValue(uninstalled), |
| 318 base::FundamentalValue(!extension_id_prompting_.empty())); | 318 base::FundamentalValue(!extension_id_prompting_.empty())); |
| 319 } | 319 } |
| 320 break; | 320 break; |
| 321 } | 321 } |
| 322 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: { | 322 case chrome::NOTIFICATION_APP_LAUNCHER_REORDERED: { |
| 323 const std::string* id = | 323 const std::string* id = |
| 324 content::Details<const std::string>(details).ptr(); | 324 content::Details<const std::string>(details).ptr(); |
| 325 if (id) { | 325 if (id) { |
| 326 const Extension* extension = | 326 const Extension* extension = |
| 327 extension_service_->GetInstalledExtension(*id); | 327 extension_service_->GetInstalledExtension(*id); |
| 328 if (!extension) { | 328 if (!extension) { |
| 329 // Extension could still be downloading or installing. | 329 // Extension could still be downloading or installing. |
| 330 return; | 330 return; |
| 331 } | 331 } |
| 332 | 332 |
| 333 base::DictionaryValue app_info; | 333 base::DictionaryValue app_info; |
| 334 CreateAppInfo(extension, | 334 CreateAppInfo(extension, |
| 335 extension_service_, | 335 extension_service_, |
| 336 &app_info); | 336 &app_info); |
| 337 web_ui()->CallJavascriptFunction("ntp.appMoved", app_info); | 337 web_ui()->CallJavascriptFunction("ntp.appMoved", app_info); |
| 338 } else { | 338 } else { |
| 339 HandleGetApps(NULL); | 339 HandleGetApps(NULL); |
| 340 } | 340 } |
| 341 break; | 341 break; |
| 342 } | 342 } |
| 343 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: { | 343 case extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR: { |
| 344 CrxInstaller* crx_installer = content::Source<CrxInstaller>(source).ptr(); | 344 CrxInstaller* crx_installer = content::Source<CrxInstaller>(source).ptr(); |
| 345 if (!Profile::FromWebUI(web_ui())->IsSameProfile( | 345 if (!Profile::FromWebUI(web_ui())->IsSameProfile( |
| 346 crx_installer->profile())) { | 346 crx_installer->profile())) { |
| 347 return; | 347 return; |
| 348 } | 348 } |
| 349 // Fall through. | 349 // Fall through. |
| 350 } | 350 } |
| 351 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: { | 351 case extensions::NOTIFICATION_EXTENSION_LOAD_ERROR: { |
| 352 attempted_bookmark_app_install_ = false; | 352 attempted_bookmark_app_install_ = false; |
| 353 break; | 353 break; |
| 354 } | 354 } |
| 355 default: | 355 default: |
| 356 NOTREACHED(); | 356 NOTREACHED(); |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 | 359 |
| 360 void AppLauncherHandler::FillAppDictionary(base::DictionaryValue* dictionary) { | 360 void AppLauncherHandler::FillAppDictionary(base::DictionaryValue* dictionary) { |
| 361 // CreateAppInfo and ClearOrdinals can change the extension prefs. | 361 // CreateAppInfo and ClearOrdinals can change the extension prefs. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 base::Closure callback = base::Bind( | 449 base::Closure callback = base::Bind( |
| 450 &AppLauncherHandler::OnExtensionPreferenceChanged, | 450 &AppLauncherHandler::OnExtensionPreferenceChanged, |
| 451 base::Unretained(this)); | 451 base::Unretained(this)); |
| 452 extension_pref_change_registrar_.Init( | 452 extension_pref_change_registrar_.Init( |
| 453 ExtensionPrefs::Get(profile)->pref_service()); | 453 ExtensionPrefs::Get(profile)->pref_service()); |
| 454 extension_pref_change_registrar_.Add( | 454 extension_pref_change_registrar_.Add( |
| 455 extensions::pref_names::kExtensions, callback); | 455 extensions::pref_names::kExtensions, callback); |
| 456 extension_pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); | 456 extension_pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); |
| 457 | 457 |
| 458 registrar_.Add(this, | 458 registrar_.Add(this, |
| 459 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 459 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 460 content::Source<Profile>(profile)); | |
| 461 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 462 content::Source<Profile>(profile)); | |
| 463 registrar_.Add(this, | |
| 464 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, | |
| 465 content::Source<Profile>(profile)); | 460 content::Source<Profile>(profile)); |
| 466 registrar_.Add(this, | 461 registrar_.Add(this, |
| 467 chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, | 462 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 463 content::Source<Profile>(profile)); |
| 464 registrar_.Add(this, |
| 465 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, |
| 466 content::Source<Profile>(profile)); |
| 467 registrar_.Add(this, |
| 468 chrome::NOTIFICATION_APP_LAUNCHER_REORDERED, |
| 468 content::Source<AppSorting>( | 469 content::Source<AppSorting>( |
| 469 ExtensionPrefs::Get(profile)->app_sorting())); | 470 ExtensionPrefs::Get(profile)->app_sorting())); |
| 470 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 471 registrar_.Add(this, |
| 471 content::Source<CrxInstaller>(NULL)); | 472 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| 472 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, | 473 content::Source<CrxInstaller>(NULL)); |
| 473 content::Source<Profile>(profile)); | 474 registrar_.Add(this, |
| 475 extensions::NOTIFICATION_EXTENSION_LOAD_ERROR, |
| 476 content::Source<Profile>(profile)); |
| 474 } | 477 } |
| 475 | 478 |
| 476 has_loaded_apps_ = true; | 479 has_loaded_apps_ = true; |
| 477 } | 480 } |
| 478 | 481 |
| 479 void AppLauncherHandler::HandleLaunchApp(const base::ListValue* args) { | 482 void AppLauncherHandler::HandleLaunchApp(const base::ListValue* args) { |
| 480 std::string extension_id; | 483 std::string extension_id; |
| 481 CHECK(args->GetString(0, &extension_id)); | 484 CHECK(args->GetString(0, &extension_id)); |
| 482 double source = -1.0; | 485 double source = -1.0; |
| 483 CHECK(args->GetDouble(1, &source)); | 486 CHECK(args->GetDouble(1, &source)); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 Browser* browser = chrome::FindBrowserWithWebContents( | 842 Browser* browser = chrome::FindBrowserWithWebContents( |
| 840 web_ui()->GetWebContents()); | 843 web_ui()->GetWebContents()); |
| 841 extension_uninstall_dialog_.reset( | 844 extension_uninstall_dialog_.reset( |
| 842 extensions::ExtensionUninstallDialog::Create( | 845 extensions::ExtensionUninstallDialog::Create( |
| 843 extension_service_->profile(), | 846 extension_service_->profile(), |
| 844 browser->window()->GetNativeWindow(), | 847 browser->window()->GetNativeWindow(), |
| 845 this)); | 848 this)); |
| 846 } | 849 } |
| 847 return extension_uninstall_dialog_.get(); | 850 return extension_uninstall_dialog_.get(); |
| 848 } | 851 } |
| OLD | NEW |