| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 content::NavigationController::ReloadType reload_type) { | 328 content::NavigationController::ReloadType reload_type) { |
| 332 if (reload_type != content::NavigationController::NO_RELOAD) | 329 if (reload_type != content::NavigationController::NO_RELOAD) |
| 333 ReloadUnpackedExtensions(); | 330 ReloadUnpackedExtensions(); |
| 334 } | 331 } |
| 335 | 332 |
| 336 void ExtensionSettingsHandler::RegisterMessages() { | 333 void ExtensionSettingsHandler::RegisterMessages() { |
| 337 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); | 334 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); |
| 338 extension_service_ = | 335 extension_service_ = |
| 339 extensions::ExtensionSystem::Get(profile)->extension_service(); | 336 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 340 | 337 |
| 341 web_ui()->RegisterMessageCallback("extensionSettingsRequestExtensionsData", | |
| 342 base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData, | |
| 343 AsWeakPtr())); | |
| 344 web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode", | |
| 345 base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode, | |
| 346 AsWeakPtr())); | |
| 347 web_ui()->RegisterMessageCallback("extensionSettingsLaunch", | 338 web_ui()->RegisterMessageCallback("extensionSettingsLaunch", |
| 348 base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage, | 339 base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage, |
| 349 AsWeakPtr())); | 340 AsWeakPtr())); |
| 350 web_ui()->RegisterMessageCallback("extensionSettingsRepair", | 341 web_ui()->RegisterMessageCallback("extensionSettingsRepair", |
| 351 base::Bind(&ExtensionSettingsHandler::HandleRepairMessage, | 342 base::Bind(&ExtensionSettingsHandler::HandleRepairMessage, |
| 352 AsWeakPtr())); | 343 AsWeakPtr())); |
| 353 web_ui()->RegisterMessageCallback("extensionSettingsOptions", | 344 web_ui()->RegisterMessageCallback("extensionSettingsOptions", |
| 354 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, | 345 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, |
| 355 AsWeakPtr())); | 346 AsWeakPtr())); |
| 356 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", | 347 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", |
| 357 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, | 348 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, |
| 358 AsWeakPtr())); | 349 AsWeakPtr())); |
| 359 web_ui()->RegisterMessageCallback("extensionSettingsDismissADTPromo", | |
| 360 base::Bind(&ExtensionSettingsHandler::HandleDismissADTPromoMessage, | |
| 361 AsWeakPtr())); | |
| 362 web_ui()->RegisterMessageCallback("extensionSettingsShowPath", | 350 web_ui()->RegisterMessageCallback("extensionSettingsShowPath", |
| 363 base::Bind(&ExtensionSettingsHandler::HandleShowPath, | 351 base::Bind(&ExtensionSettingsHandler::HandleShowPath, |
| 364 AsWeakPtr())); | 352 AsWeakPtr())); |
| 365 } | 353 } |
| 366 | 354 |
| 367 void ExtensionSettingsHandler::Observe( | 355 void ExtensionSettingsHandler::Observe( |
| 368 int type, | 356 int type, |
| 369 const content::NotificationSource& source, | 357 const content::NotificationSource& source, |
| 370 const content::NotificationDetails& details) { | 358 const content::NotificationDetails& details) { |
| 371 Profile* profile = Profile::FromWebUI(web_ui()); | 359 Profile* profile = Profile::FromWebUI(web_ui()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 if (Manifest::IsUnpackedLocation(extension->location())) | 427 if (Manifest::IsUnpackedLocation(extension->location())) |
| 440 unpacked_extensions.push_back(extension.get()); | 428 unpacked_extensions.push_back(extension.get()); |
| 441 } | 429 } |
| 442 | 430 |
| 443 for (std::vector<const Extension*>::iterator iter = | 431 for (std::vector<const Extension*>::iterator iter = |
| 444 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 432 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
| 445 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); | 433 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); |
| 446 } | 434 } |
| 447 } | 435 } |
| 448 | 436 |
| 449 void ExtensionSettingsHandler::HandleRequestExtensionsData( | |
| 450 const base::ListValue* args) { | |
| 451 // The items which are to be written into results are also described in | |
| 452 // chrome/browser/resources/extensions/extensions.js in @typedef for | |
| 453 // ExtensionDataResponse. Please update it whenever you add or remove any keys | |
| 454 // here. | |
| 455 base::DictionaryValue results; | |
| 456 | |
| 457 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 458 | |
| 459 bool is_supervised = profile->IsSupervised(); | |
| 460 bool incognito_available = | |
| 461 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) != | |
| 462 IncognitoModePrefs::DISABLED; | |
| 463 bool developer_mode = | |
| 464 !is_supervised && | |
| 465 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | |
| 466 results.SetBoolean("profileIsSupervised", is_supervised); | |
| 467 results.SetBoolean("incognitoAvailable", incognito_available); | |
| 468 results.SetBoolean("developerMode", developer_mode); | |
| 469 results.SetBoolean("enableAppInfoDialog", CanShowAppInfoDialog()); | |
| 470 | |
| 471 // Promote the Chrome Apps & Extensions Developer Tools if they are not | |
| 472 // installed and the user has not previously dismissed the warning. | |
| 473 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); | |
| 474 bool promote_apps_dev_tools = false; | |
| 475 if (!registry->GetExtensionById(kAppsDeveloperToolsExtensionId, | |
| 476 ExtensionRegistry::EVERYTHING) && | |
| 477 !profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDismissedADTPromo)) { | |
| 478 promote_apps_dev_tools = true; | |
| 479 } | |
| 480 results.SetBoolean("promoteAppsDevTools", promote_apps_dev_tools); | |
| 481 | |
| 482 const bool load_unpacked_disabled = | |
| 483 ExtensionManagementFactory::GetForBrowserContext(profile) | |
| 484 ->BlacklistedByDefault(); | |
| 485 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); | |
| 486 | |
| 487 web_ui()->CallJavascriptFunction( | |
| 488 "extensions.ExtensionSettings.returnExtensionsData", results); | |
| 489 | |
| 490 MaybeRegisterForNotifications(); | |
| 491 | |
| 492 scoped_ptr<ExtensionSet> extensions = | |
| 493 registry->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED | | |
| 494 ExtensionRegistry::DISABLED | | |
| 495 ExtensionRegistry::TERMINATED); | |
| 496 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile); | |
| 497 bool should_do_verification_check = false; | |
| 498 for (const scoped_refptr<const Extension>& extension : *extensions) { | |
| 499 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), profile)) { | |
| 500 int disable_reasons = prefs->GetDisableReasons(extension->id()); | |
| 501 if ((disable_reasons & Extension::DISABLE_NOT_VERIFIED)) { | |
| 502 should_do_verification_check = true; | |
| 503 break; | |
| 504 } | |
| 505 } | |
| 506 } | |
| 507 | |
| 508 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck", | |
| 509 should_do_verification_check); | |
| 510 if (should_do_verification_check) | |
| 511 ExtensionSystem::Get(profile)->install_verifier()->VerifyAllExtensions(); | |
| 512 } | |
| 513 | |
| 514 void ExtensionSettingsHandler::HandleToggleDeveloperMode( | |
| 515 const base::ListValue* args) { | |
| 516 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 517 if (profile->IsSupervised()) | |
| 518 return; | |
| 519 | |
| 520 bool developer_mode_on; | |
| 521 CHECK(args->GetBoolean(0, &developer_mode_on)); | |
| 522 profile->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, | |
| 523 developer_mode_on); | |
| 524 } | |
| 525 | |
| 526 void ExtensionSettingsHandler::HandleLaunchMessage( | 437 void ExtensionSettingsHandler::HandleLaunchMessage( |
| 527 const base::ListValue* args) { | 438 const base::ListValue* args) { |
| 528 CHECK_EQ(1U, args->GetSize()); | 439 CHECK_EQ(1U, args->GetSize()); |
| 529 std::string extension_id; | 440 std::string extension_id; |
| 530 CHECK(args->GetString(0, &extension_id)); | 441 CHECK(args->GetString(0, &extension_id)); |
| 531 const Extension* extension = | 442 const Extension* extension = |
| 532 extension_service_->GetExtensionById(extension_id, false); | 443 extension_service_->GetExtensionById(extension_id, false); |
| 533 OpenApplication(AppLaunchParams(extension_service_->profile(), extension, | 444 OpenApplication(AppLaunchParams(extension_service_->profile(), extension, |
| 534 extensions::LAUNCH_CONTAINER_WINDOW, | 445 extensions::LAUNCH_CONTAINER_WINDOW, |
| 535 NEW_WINDOW, | 446 NEW_WINDOW, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 560 void ExtensionSettingsHandler::HandleAutoUpdateMessage( | 471 void ExtensionSettingsHandler::HandleAutoUpdateMessage( |
| 561 const base::ListValue* args) { | 472 const base::ListValue* args) { |
| 562 ExtensionUpdater* updater = extension_service_->updater(); | 473 ExtensionUpdater* updater = extension_service_->updater(); |
| 563 if (updater) { | 474 if (updater) { |
| 564 ExtensionUpdater::CheckParams params; | 475 ExtensionUpdater::CheckParams params; |
| 565 params.install_immediately = true; | 476 params.install_immediately = true; |
| 566 updater->CheckNow(params); | 477 updater->CheckNow(params); |
| 567 } | 478 } |
| 568 } | 479 } |
| 569 | 480 |
| 570 void ExtensionSettingsHandler::HandleDismissADTPromoMessage( | |
| 571 const base::ListValue* args) { | |
| 572 DCHECK(args->empty()); | |
| 573 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | |
| 574 prefs::kExtensionsUIDismissedADTPromo, true); | |
| 575 } | |
| 576 | |
| 577 void ExtensionSettingsHandler::HandleShowPath(const base::ListValue* args) { | 481 void ExtensionSettingsHandler::HandleShowPath(const base::ListValue* args) { |
| 578 DCHECK(!args->empty()); | 482 DCHECK(!args->empty()); |
| 579 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args)); | 483 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args)); |
| 580 | 484 |
| 581 Profile* profile = Profile::FromWebUI(web_ui()); | 485 Profile* profile = Profile::FromWebUI(web_ui()); |
| 582 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); | 486 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); |
| 583 const Extension* extension = registry->GetExtensionById( | 487 const Extension* extension = registry->GetExtensionById( |
| 584 extension_id, | 488 extension_id, |
| 585 ExtensionRegistry::EVERYTHING); | 489 ExtensionRegistry::EVERYTHING); |
| 586 CHECK(extension); | 490 CHECK(extension); |
| 587 // We explicitly show manifest.json in order to work around an issue in OSX | 491 // We explicitly show manifest.json in order to work around an issue in OSX |
| 588 // where opening the directory doesn't focus the Finder. | 492 // where opening the directory doesn't focus the Finder. |
| 589 platform_util::ShowItemInFolder(profile, | 493 platform_util::ShowItemInFolder(profile, |
| 590 extension->path().Append(kManifestFilename)); | 494 extension->path().Append(kManifestFilename)); |
| 591 } | 495 } |
| 592 | 496 |
| 593 const Extension* ExtensionSettingsHandler::GetActiveExtension( | 497 const Extension* ExtensionSettingsHandler::GetActiveExtension( |
| 594 const base::ListValue* args) { | 498 const base::ListValue* args) { |
| 595 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args)); | 499 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args)); |
| 596 CHECK(!extension_id.empty()); | 500 CHECK(!extension_id.empty()); |
| 597 return extension_service_->GetExtensionById(extension_id, false); | 501 return extension_service_->GetExtensionById(extension_id, false); |
| 598 } | 502 } |
| 599 | 503 |
| 600 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { | 504 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { |
| 601 content::WebContents* contents = web_ui()->GetWebContents(); | 505 content::WebContents* contents = web_ui()->GetWebContents(); |
| 602 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) | 506 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) { |
| 603 HandleRequestExtensionsData(NULL); | 507 web_ui()->CallJavascriptFunction( |
| 508 "extensions.ExtensionSettings.onExtensionsChanged"); |
| 509 } |
| 604 deleting_rvh_ = NULL; | 510 deleting_rvh_ = NULL; |
| 605 } | 511 } |
| 606 | 512 |
| 607 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { | 513 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { |
| 608 if (registered_for_notifications_) | 514 if (registered_for_notifications_) |
| 609 return; | 515 return; |
| 610 | 516 |
| 611 registered_for_notifications_ = true; | 517 registered_for_notifications_ = true; |
| 612 Profile* profile = Profile::FromWebUI(web_ui()); | 518 Profile* profile = Profile::FromWebUI(web_ui()); |
| 613 | 519 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 644 } | 550 } |
| 645 | 551 |
| 646 void ExtensionSettingsHandler::OnReinstallComplete( | 552 void ExtensionSettingsHandler::OnReinstallComplete( |
| 647 bool success, | 553 bool success, |
| 648 const std::string& error, | 554 const std::string& error, |
| 649 webstore_install::Result result) { | 555 webstore_install::Result result) { |
| 650 MaybeUpdateAfterNotification(); | 556 MaybeUpdateAfterNotification(); |
| 651 } | 557 } |
| 652 | 558 |
| 653 } // namespace extensions | 559 } // namespace extensions |
| OLD | NEW |