| 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/extensions/extension_settings_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | |
| 15 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/values.h" | 17 #include "base/values.h" |
| 19 #include "base/version.h" | 18 #include "base/version.h" |
| 20 #include "chrome/browser/background/background_contents.h" | 19 #include "chrome/browser/background/background_contents.h" |
| 21 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 23 #include "chrome/browser/extensions/extension_management.h" | 22 #include "chrome/browser/extensions/extension_management.h" |
| 24 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 25 #include "chrome/browser/extensions/extension_tab_util.h" | 24 #include "chrome/browser/extensions/extension_tab_util.h" |
| 26 #include "chrome/browser/extensions/extension_ui_util.h" | 25 #include "chrome/browser/extensions/extension_ui_util.h" |
| 27 #include "chrome/browser/extensions/install_verifier.h" | |
| 28 #include "chrome/browser/extensions/updater/extension_updater.h" | 26 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 29 #include "chrome/browser/extensions/webstore_reinstaller.h" | 27 #include "chrome/browser/extensions/webstore_reinstaller.h" |
| 30 #include "chrome/browser/platform_util.h" | 28 #include "chrome/browser/platform_util.h" |
| 31 #include "chrome/browser/prefs/incognito_mode_prefs.h" | |
| 32 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/ui/apps/app_info_dialog.h" | 30 #include "chrome/browser/ui/apps/app_info_dialog.h" |
| 34 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 35 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
| 36 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
| 37 #include "chrome/browser/ui/extensions/app_launch_params.h" | 34 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 38 #include "chrome/browser/ui/extensions/application_launch.h" | 35 #include "chrome/browser/ui/extensions/application_launch.h" |
| 39 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" | 36 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" |
| 40 #include "chrome/common/chrome_version_info.h" | 37 #include "chrome/common/chrome_version_info.h" |
| 41 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // ExtensionSettingsHandler | 79 // ExtensionSettingsHandler |
| 83 // | 80 // |
| 84 /////////////////////////////////////////////////////////////////////////////// | 81 /////////////////////////////////////////////////////////////////////////////// |
| 85 | 82 |
| 86 ExtensionSettingsHandler::ExtensionSettingsHandler() | 83 ExtensionSettingsHandler::ExtensionSettingsHandler() |
| 87 : extension_service_(NULL), | 84 : extension_service_(NULL), |
| 88 ignore_notifications_(false), | 85 ignore_notifications_(false), |
| 89 deleting_rvh_(NULL), | 86 deleting_rvh_(NULL), |
| 90 deleting_rwh_id_(-1), | 87 deleting_rwh_id_(-1), |
| 91 deleting_rph_id_(-1), | 88 deleting_rph_id_(-1), |
| 92 registered_for_notifications_(false), | |
| 93 warning_service_observer_(this), | 89 warning_service_observer_(this), |
| 94 extension_prefs_observer_(this), | 90 extension_prefs_observer_(this), |
| 95 extension_management_observer_(this) { | 91 extension_management_observer_(this) { |
| 96 } | 92 } |
| 97 | 93 |
| 98 ExtensionSettingsHandler::~ExtensionSettingsHandler() { | 94 ExtensionSettingsHandler::~ExtensionSettingsHandler() { |
| 99 } | 95 } |
| 100 | 96 |
| 101 // static | 97 // static |
| 102 void ExtensionSettingsHandler::RegisterProfilePrefs( | 98 void ExtensionSettingsHandler::RegisterProfilePrefs( |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 content::NavigationController::ReloadType reload_type) { | 308 content::NavigationController::ReloadType reload_type) { |
| 313 if (reload_type != content::NavigationController::NO_RELOAD) | 309 if (reload_type != content::NavigationController::NO_RELOAD) |
| 314 ReloadUnpackedExtensions(); | 310 ReloadUnpackedExtensions(); |
| 315 } | 311 } |
| 316 | 312 |
| 317 void ExtensionSettingsHandler::RegisterMessages() { | 313 void ExtensionSettingsHandler::RegisterMessages() { |
| 318 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); | 314 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); |
| 319 extension_service_ = | 315 extension_service_ = |
| 320 extensions::ExtensionSystem::Get(profile)->extension_service(); | 316 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 321 | 317 |
| 322 web_ui()->RegisterMessageCallback("extensionSettingsRequestExtensionsData", | |
| 323 base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData, | |
| 324 AsWeakPtr())); | |
| 325 web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode", | |
| 326 base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode, | |
| 327 AsWeakPtr())); | |
| 328 web_ui()->RegisterMessageCallback("extensionSettingsLaunch", | 318 web_ui()->RegisterMessageCallback("extensionSettingsLaunch", |
| 329 base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage, | 319 base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage, |
| 330 AsWeakPtr())); | 320 AsWeakPtr())); |
| 331 web_ui()->RegisterMessageCallback("extensionSettingsRepair", | 321 web_ui()->RegisterMessageCallback("extensionSettingsRepair", |
| 332 base::Bind(&ExtensionSettingsHandler::HandleRepairMessage, | 322 base::Bind(&ExtensionSettingsHandler::HandleRepairMessage, |
| 333 AsWeakPtr())); | 323 AsWeakPtr())); |
| 334 web_ui()->RegisterMessageCallback("extensionSettingsOptions", | 324 web_ui()->RegisterMessageCallback("extensionSettingsOptions", |
| 335 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, | 325 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, |
| 336 AsWeakPtr())); | 326 AsWeakPtr())); |
| 337 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", | 327 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", |
| 338 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, | 328 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, |
| 339 AsWeakPtr())); | 329 AsWeakPtr())); |
| 340 web_ui()->RegisterMessageCallback("extensionSettingsShowPath", | 330 web_ui()->RegisterMessageCallback("extensionSettingsShowPath", |
| 341 base::Bind(&ExtensionSettingsHandler::HandleShowPath, | 331 base::Bind(&ExtensionSettingsHandler::HandleShowPath, |
| 342 AsWeakPtr())); | 332 AsWeakPtr())); |
| 333 web_ui()->RegisterMessageCallback("extensionSettingsRegister", |
| 334 base::Bind(&ExtensionSettingsHandler::HandleRegisterMessage, |
| 335 AsWeakPtr())); |
| 343 } | 336 } |
| 344 | 337 |
| 345 void ExtensionSettingsHandler::Observe( | 338 void ExtensionSettingsHandler::Observe( |
| 346 int type, | 339 int type, |
| 347 const content::NotificationSource& source, | 340 const content::NotificationSource& source, |
| 348 const content::NotificationDetails& details) { | 341 const content::NotificationDetails& details) { |
| 349 Profile* profile = Profile::FromWebUI(web_ui()); | 342 Profile* profile = Profile::FromWebUI(web_ui()); |
| 350 Profile* source_profile = NULL; | 343 Profile* source_profile = NULL; |
| 351 switch (type) { | 344 switch (type) { |
| 352 // We listen for notifications that will result in the page being | 345 // We listen for notifications that will result in the page being |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 if (Manifest::IsUnpackedLocation(extension->location())) | 410 if (Manifest::IsUnpackedLocation(extension->location())) |
| 418 unpacked_extensions.push_back(extension.get()); | 411 unpacked_extensions.push_back(extension.get()); |
| 419 } | 412 } |
| 420 | 413 |
| 421 for (std::vector<const Extension*>::iterator iter = | 414 for (std::vector<const Extension*>::iterator iter = |
| 422 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 415 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
| 423 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); | 416 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); |
| 424 } | 417 } |
| 425 } | 418 } |
| 426 | 419 |
| 427 void ExtensionSettingsHandler::HandleRequestExtensionsData( | |
| 428 const base::ListValue* args) { | |
| 429 // The items which are to be written into results are also described in | |
| 430 // chrome/browser/resources/extensions/extensions.js in @typedef for | |
| 431 // ExtensionDataResponse. Please update it whenever you add or remove any keys | |
| 432 // here. | |
| 433 base::DictionaryValue results; | |
| 434 | |
| 435 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 436 | |
| 437 bool is_supervised = profile->IsSupervised(); | |
| 438 bool incognito_available = | |
| 439 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) != | |
| 440 IncognitoModePrefs::DISABLED; | |
| 441 bool developer_mode = | |
| 442 !is_supervised && | |
| 443 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | |
| 444 results.SetBoolean("profileIsSupervised", is_supervised); | |
| 445 results.SetBoolean("incognitoAvailable", incognito_available); | |
| 446 results.SetBoolean("developerMode", developer_mode); | |
| 447 results.SetBoolean("enableAppInfoDialog", CanShowAppInfoDialog()); | |
| 448 | |
| 449 const bool load_unpacked_disabled = | |
| 450 ExtensionManagementFactory::GetForBrowserContext(profile) | |
| 451 ->BlacklistedByDefault(); | |
| 452 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); | |
| 453 | |
| 454 web_ui()->CallJavascriptFunction( | |
| 455 "extensions.ExtensionSettings.returnExtensionsData", results); | |
| 456 | |
| 457 MaybeRegisterForNotifications(); | |
| 458 | |
| 459 scoped_ptr<ExtensionSet> extensions = | |
| 460 ExtensionRegistry::Get(profile)->GenerateInstalledExtensionsSet( | |
| 461 ExtensionRegistry::ENABLED | | |
| 462 ExtensionRegistry::DISABLED | | |
| 463 ExtensionRegistry::TERMINATED); | |
| 464 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile); | |
| 465 bool should_do_verification_check = false; | |
| 466 for (const scoped_refptr<const Extension>& extension : *extensions) { | |
| 467 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), profile)) { | |
| 468 int disable_reasons = prefs->GetDisableReasons(extension->id()); | |
| 469 if ((disable_reasons & Extension::DISABLE_NOT_VERIFIED)) { | |
| 470 should_do_verification_check = true; | |
| 471 break; | |
| 472 } | |
| 473 } | |
| 474 } | |
| 475 | |
| 476 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck", | |
| 477 should_do_verification_check); | |
| 478 if (should_do_verification_check) | |
| 479 ExtensionSystem::Get(profile)->install_verifier()->VerifyAllExtensions(); | |
| 480 } | |
| 481 | |
| 482 void ExtensionSettingsHandler::HandleToggleDeveloperMode( | |
| 483 const base::ListValue* args) { | |
| 484 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 485 if (profile->IsSupervised()) | |
| 486 return; | |
| 487 | |
| 488 bool developer_mode_on; | |
| 489 CHECK(args->GetBoolean(0, &developer_mode_on)); | |
| 490 profile->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, | |
| 491 developer_mode_on); | |
| 492 } | |
| 493 | |
| 494 void ExtensionSettingsHandler::HandleLaunchMessage( | 420 void ExtensionSettingsHandler::HandleLaunchMessage( |
| 495 const base::ListValue* args) { | 421 const base::ListValue* args) { |
| 496 CHECK_EQ(1U, args->GetSize()); | 422 CHECK_EQ(1U, args->GetSize()); |
| 497 std::string extension_id; | 423 std::string extension_id; |
| 498 CHECK(args->GetString(0, &extension_id)); | 424 CHECK(args->GetString(0, &extension_id)); |
| 499 const Extension* extension = | 425 const Extension* extension = |
| 500 extension_service_->GetExtensionById(extension_id, false); | 426 extension_service_->GetExtensionById(extension_id, false); |
| 501 OpenApplication(AppLaunchParams(extension_service_->profile(), extension, | 427 OpenApplication(AppLaunchParams(extension_service_->profile(), extension, |
| 502 extensions::LAUNCH_CONTAINER_WINDOW, | 428 extensions::LAUNCH_CONTAINER_WINDOW, |
| 503 NEW_WINDOW, | 429 NEW_WINDOW, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 const Extension* extension = registry->GetExtensionById( | 470 const Extension* extension = registry->GetExtensionById( |
| 545 extension_id, | 471 extension_id, |
| 546 ExtensionRegistry::EVERYTHING); | 472 ExtensionRegistry::EVERYTHING); |
| 547 CHECK(extension); | 473 CHECK(extension); |
| 548 // We explicitly show manifest.json in order to work around an issue in OSX | 474 // We explicitly show manifest.json in order to work around an issue in OSX |
| 549 // where opening the directory doesn't focus the Finder. | 475 // where opening the directory doesn't focus the Finder. |
| 550 platform_util::ShowItemInFolder(profile, | 476 platform_util::ShowItemInFolder(profile, |
| 551 extension->path().Append(kManifestFilename)); | 477 extension->path().Append(kManifestFilename)); |
| 552 } | 478 } |
| 553 | 479 |
| 554 const Extension* ExtensionSettingsHandler::GetActiveExtension( | 480 void ExtensionSettingsHandler::HandleRegisterMessage( |
| 555 const base::ListValue* args) { | 481 const base::ListValue* args) { |
| 556 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args)); | 482 if (!registrar_.IsEmpty()) |
| 557 CHECK(!extension_id.empty()); | 483 return; // Only register once. |
| 558 return extension_service_->GetExtensionById(extension_id, false); | |
| 559 } | |
| 560 | 484 |
| 561 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { | |
| 562 content::WebContents* contents = web_ui()->GetWebContents(); | |
| 563 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) | |
| 564 HandleRequestExtensionsData(NULL); | |
| 565 deleting_rvh_ = NULL; | |
| 566 } | |
| 567 | |
| 568 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { | |
| 569 if (registered_for_notifications_) | |
| 570 return; | |
| 571 | |
| 572 registered_for_notifications_ = true; | |
| 573 Profile* profile = Profile::FromWebUI(web_ui()); | 485 Profile* profile = Profile::FromWebUI(web_ui()); |
| 574 | 486 |
| 575 // Register for notifications that we need to reload the page. | 487 // Register for notifications that we need to reload the page. |
| 576 registrar_.Add(this, | 488 registrar_.Add(this, |
| 577 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 489 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 578 content::Source<Profile>(profile)); | 490 content::Source<Profile>(profile)); |
| 579 registrar_.Add(this, | 491 registrar_.Add(this, |
| 580 extensions::NOTIFICATION_EXTENSION_HOST_CREATED, | 492 extensions::NOTIFICATION_EXTENSION_HOST_CREATED, |
| 581 content::NotificationService::AllBrowserContextsAndSources()); | 493 content::NotificationService::AllBrowserContextsAndSources()); |
| 582 registrar_.Add(this, | 494 registrar_.Add(this, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 601 warning_service_observer_.Add(WarningService::Get(profile)); | 513 warning_service_observer_.Add(WarningService::Get(profile)); |
| 602 | 514 |
| 603 extension_management_observer_.Add( | 515 extension_management_observer_.Add( |
| 604 ExtensionManagementFactory::GetForBrowserContext(profile)); | 516 ExtensionManagementFactory::GetForBrowserContext(profile)); |
| 605 | 517 |
| 606 // Clear the preference for the ADT Promo before fully removing it. | 518 // Clear the preference for the ADT Promo before fully removing it. |
| 607 // TODO(devlin): Take this out when everyone's been updated. | 519 // TODO(devlin): Take this out when everyone's been updated. |
| 608 profile->GetPrefs()->ClearPref(prefs::kExtensionsUIDismissedADTPromo); | 520 profile->GetPrefs()->ClearPref(prefs::kExtensionsUIDismissedADTPromo); |
| 609 } | 521 } |
| 610 | 522 |
| 523 const Extension* ExtensionSettingsHandler::GetActiveExtension( |
| 524 const base::ListValue* args) { |
| 525 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args)); |
| 526 CHECK(!extension_id.empty()); |
| 527 return extension_service_->GetExtensionById(extension_id, false); |
| 528 } |
| 529 |
| 530 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { |
| 531 content::WebContents* contents = web_ui()->GetWebContents(); |
| 532 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) { |
| 533 web_ui()->CallJavascriptFunction( |
| 534 "extensions.ExtensionSettings.onExtensionsChanged"); |
| 535 } |
| 536 deleting_rvh_ = NULL; |
| 537 } |
| 538 |
| 611 void ExtensionSettingsHandler::OnReinstallComplete( | 539 void ExtensionSettingsHandler::OnReinstallComplete( |
| 612 bool success, | 540 bool success, |
| 613 const std::string& error, | 541 const std::string& error, |
| 614 webstore_install::Result result) { | 542 webstore_install::Result result) { |
| 615 MaybeUpdateAfterNotification(); | 543 MaybeUpdateAfterNotification(); |
| 616 } | 544 } |
| 617 | 545 |
| 618 } // namespace extensions | 546 } // namespace extensions |
| OLD | NEW |