| 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/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "base/version.h" | 18 #include "base/version.h" |
| 19 #include "chrome/browser/background/background_contents.h" | 19 #include "chrome/browser/background/background_contents.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/extensions/extension_management.h" | 22 #include "chrome/browser/extensions/extension_management.h" |
| 23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/extensions/extension_tab_util.h" | |
| 25 #include "chrome/browser/extensions/extension_ui_util.h" | 24 #include "chrome/browser/extensions/extension_ui_util.h" |
| 26 #include "chrome/browser/extensions/updater/extension_updater.h" | |
| 27 #include "chrome/browser/extensions/webstore_reinstaller.h" | |
| 28 #include "chrome/browser/platform_util.h" | |
| 29 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/ui/apps/app_info_dialog.h" | 26 #include "chrome/browser/ui/apps/app_info_dialog.h" |
| 31 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/browser/ui/browser_finder.h" | |
| 33 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 34 #include "chrome/browser/ui/extensions/app_launch_params.h" | 29 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 35 #include "chrome/browser/ui/extensions/application_launch.h" | 30 #include "chrome/browser/ui/extensions/application_launch.h" |
| 36 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" | 31 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" |
| 37 #include "chrome/common/chrome_version_info.h" | 32 #include "chrome/common/chrome_version_info.h" |
| 38 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 40 #include "chrome/grit/chromium_strings.h" | 35 #include "chrome/grit/chromium_strings.h" |
| 41 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
| 42 #include "components/google/core/browser/google_util.h" | 37 #include "components/google/core/browser/google_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 57 #include "extensions/browser/extension_system.h" | 52 #include "extensions/browser/extension_system.h" |
| 58 #include "extensions/browser/management_policy.h" | 53 #include "extensions/browser/management_policy.h" |
| 59 #include "extensions/browser/pref_names.h" | 54 #include "extensions/browser/pref_names.h" |
| 60 #include "extensions/browser/warning_set.h" | 55 #include "extensions/browser/warning_set.h" |
| 61 #include "extensions/common/constants.h" | 56 #include "extensions/common/constants.h" |
| 62 #include "extensions/common/extension.h" | 57 #include "extensions/common/extension.h" |
| 63 #include "extensions/common/extension_icon_set.h" | 58 #include "extensions/common/extension_icon_set.h" |
| 64 #include "extensions/common/extension_set.h" | 59 #include "extensions/common/extension_set.h" |
| 65 #include "extensions/common/extension_urls.h" | 60 #include "extensions/common/extension_urls.h" |
| 66 #include "extensions/common/manifest.h" | 61 #include "extensions/common/manifest.h" |
| 67 #include "extensions/common/manifest_handlers/options_page_info.h" | |
| 68 #include "extensions/common/permissions/permissions_data.h" | 62 #include "extensions/common/permissions/permissions_data.h" |
| 69 #include "grit/browser_resources.h" | 63 #include "grit/browser_resources.h" |
| 70 #include "grit/components_strings.h" | 64 #include "grit/components_strings.h" |
| 71 #include "grit/theme_resources.h" | 65 #include "grit/theme_resources.h" |
| 72 #include "ui/base/l10n/l10n_util.h" | 66 #include "ui/base/l10n/l10n_util.h" |
| 73 #include "url/gurl.h" | 67 #include "url/gurl.h" |
| 74 | 68 |
| 75 namespace extensions { | 69 namespace extensions { |
| 76 | 70 |
| 77 /////////////////////////////////////////////////////////////////////////////// | 71 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 content::NavigationController::ReloadType reload_type) { | 302 content::NavigationController::ReloadType reload_type) { |
| 309 if (reload_type != content::NavigationController::NO_RELOAD) | 303 if (reload_type != content::NavigationController::NO_RELOAD) |
| 310 ReloadUnpackedExtensions(); | 304 ReloadUnpackedExtensions(); |
| 311 } | 305 } |
| 312 | 306 |
| 313 void ExtensionSettingsHandler::RegisterMessages() { | 307 void ExtensionSettingsHandler::RegisterMessages() { |
| 314 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); | 308 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); |
| 315 extension_service_ = | 309 extension_service_ = |
| 316 extensions::ExtensionSystem::Get(profile)->extension_service(); | 310 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 317 | 311 |
| 318 web_ui()->RegisterMessageCallback("extensionSettingsLaunch", | |
| 319 base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage, | |
| 320 AsWeakPtr())); | |
| 321 web_ui()->RegisterMessageCallback("extensionSettingsRepair", | |
| 322 base::Bind(&ExtensionSettingsHandler::HandleRepairMessage, | |
| 323 AsWeakPtr())); | |
| 324 web_ui()->RegisterMessageCallback("extensionSettingsOptions", | |
| 325 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, | |
| 326 AsWeakPtr())); | |
| 327 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", | |
| 328 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, | |
| 329 AsWeakPtr())); | |
| 330 web_ui()->RegisterMessageCallback("extensionSettingsShowPath", | |
| 331 base::Bind(&ExtensionSettingsHandler::HandleShowPath, | |
| 332 AsWeakPtr())); | |
| 333 web_ui()->RegisterMessageCallback("extensionSettingsRegister", | 312 web_ui()->RegisterMessageCallback("extensionSettingsRegister", |
| 334 base::Bind(&ExtensionSettingsHandler::HandleRegisterMessage, | 313 base::Bind(&ExtensionSettingsHandler::HandleRegisterMessage, |
| 335 AsWeakPtr())); | 314 AsWeakPtr())); |
| 336 } | 315 } |
| 337 | 316 |
| 338 void ExtensionSettingsHandler::Observe( | 317 void ExtensionSettingsHandler::Observe( |
| 339 int type, | 318 int type, |
| 340 const content::NotificationSource& source, | 319 const content::NotificationSource& source, |
| 341 const content::NotificationDetails& details) { | 320 const content::NotificationDetails& details) { |
| 342 Profile* profile = Profile::FromWebUI(web_ui()); | 321 Profile* profile = Profile::FromWebUI(web_ui()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 if (Manifest::IsUnpackedLocation(extension->location())) | 389 if (Manifest::IsUnpackedLocation(extension->location())) |
| 411 unpacked_extensions.push_back(extension.get()); | 390 unpacked_extensions.push_back(extension.get()); |
| 412 } | 391 } |
| 413 | 392 |
| 414 for (std::vector<const Extension*>::iterator iter = | 393 for (std::vector<const Extension*>::iterator iter = |
| 415 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 394 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
| 416 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); | 395 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); |
| 417 } | 396 } |
| 418 } | 397 } |
| 419 | 398 |
| 420 void ExtensionSettingsHandler::HandleLaunchMessage( | |
| 421 const base::ListValue* args) { | |
| 422 CHECK_EQ(1U, args->GetSize()); | |
| 423 std::string extension_id; | |
| 424 CHECK(args->GetString(0, &extension_id)); | |
| 425 const Extension* extension = | |
| 426 extension_service_->GetExtensionById(extension_id, false); | |
| 427 OpenApplication(AppLaunchParams(extension_service_->profile(), extension, | |
| 428 extensions::LAUNCH_CONTAINER_WINDOW, | |
| 429 NEW_WINDOW, | |
| 430 extensions::SOURCE_EXTENSIONS_PAGE)); | |
| 431 } | |
| 432 | |
| 433 void ExtensionSettingsHandler::HandleRepairMessage( | |
| 434 const base::ListValue* args) { | |
| 435 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args)); | |
| 436 CHECK(!extension_id.empty()); | |
| 437 scoped_refptr<WebstoreReinstaller> reinstaller(new WebstoreReinstaller( | |
| 438 web_contents(), | |
| 439 extension_id, | |
| 440 base::Bind(&ExtensionSettingsHandler::OnReinstallComplete, | |
| 441 AsWeakPtr()))); | |
| 442 reinstaller->BeginReinstall(); | |
| 443 } | |
| 444 | |
| 445 void ExtensionSettingsHandler::HandleOptionsMessage( | |
| 446 const base::ListValue* args) { | |
| 447 const Extension* extension = GetActiveExtension(args); | |
| 448 if (!extension || OptionsPageInfo::GetOptionsPage(extension).is_empty()) | |
| 449 return; | |
| 450 ExtensionTabUtil::OpenOptionsPage(extension, | |
| 451 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); | |
| 452 } | |
| 453 | |
| 454 void ExtensionSettingsHandler::HandleAutoUpdateMessage( | |
| 455 const base::ListValue* args) { | |
| 456 ExtensionUpdater* updater = extension_service_->updater(); | |
| 457 if (updater) { | |
| 458 ExtensionUpdater::CheckParams params; | |
| 459 params.install_immediately = true; | |
| 460 updater->CheckNow(params); | |
| 461 } | |
| 462 } | |
| 463 | |
| 464 void ExtensionSettingsHandler::HandleShowPath(const base::ListValue* args) { | |
| 465 DCHECK(!args->empty()); | |
| 466 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args)); | |
| 467 | |
| 468 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 469 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); | |
| 470 const Extension* extension = registry->GetExtensionById( | |
| 471 extension_id, | |
| 472 ExtensionRegistry::EVERYTHING); | |
| 473 CHECK(extension); | |
| 474 // We explicitly show manifest.json in order to work around an issue in OSX | |
| 475 // where opening the directory doesn't focus the Finder. | |
| 476 platform_util::ShowItemInFolder(profile, | |
| 477 extension->path().Append(kManifestFilename)); | |
| 478 } | |
| 479 | |
| 480 void ExtensionSettingsHandler::HandleRegisterMessage( | 399 void ExtensionSettingsHandler::HandleRegisterMessage( |
| 481 const base::ListValue* args) { | 400 const base::ListValue* args) { |
| 482 if (!registrar_.IsEmpty()) | 401 if (!registrar_.IsEmpty()) |
| 483 return; // Only register once. | 402 return; // Only register once. |
| 484 | 403 |
| 485 Profile* profile = Profile::FromWebUI(web_ui()); | 404 Profile* profile = Profile::FromWebUI(web_ui()); |
| 486 | 405 |
| 487 // Register for notifications that we need to reload the page. | 406 // Register for notifications that we need to reload the page. |
| 488 registrar_.Add(this, | 407 registrar_.Add(this, |
| 489 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 408 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 513 warning_service_observer_.Add(WarningService::Get(profile)); | 432 warning_service_observer_.Add(WarningService::Get(profile)); |
| 514 | 433 |
| 515 extension_management_observer_.Add( | 434 extension_management_observer_.Add( |
| 516 ExtensionManagementFactory::GetForBrowserContext(profile)); | 435 ExtensionManagementFactory::GetForBrowserContext(profile)); |
| 517 | 436 |
| 518 // Clear the preference for the ADT Promo before fully removing it. | 437 // Clear the preference for the ADT Promo before fully removing it. |
| 519 // TODO(devlin): Take this out when everyone's been updated. | 438 // TODO(devlin): Take this out when everyone's been updated. |
| 520 profile->GetPrefs()->ClearPref(prefs::kExtensionsUIDismissedADTPromo); | 439 profile->GetPrefs()->ClearPref(prefs::kExtensionsUIDismissedADTPromo); |
| 521 } | 440 } |
| 522 | 441 |
| 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() { | 442 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { |
| 531 content::WebContents* contents = web_ui()->GetWebContents(); | 443 content::WebContents* contents = web_ui()->GetWebContents(); |
| 532 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) { | 444 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) { |
| 533 web_ui()->CallJavascriptFunction( | 445 web_ui()->CallJavascriptFunction( |
| 534 "extensions.ExtensionSettings.onExtensionsChanged"); | 446 "extensions.ExtensionSettings.onExtensionsChanged"); |
| 535 } | 447 } |
| 536 deleting_rvh_ = NULL; | 448 deleting_rvh_ = NULL; |
| 537 } | 449 } |
| 538 | 450 |
| 539 void ExtensionSettingsHandler::OnReinstallComplete( | |
| 540 bool success, | |
| 541 const std::string& error, | |
| 542 webstore_install::Result result) { | |
| 543 MaybeUpdateAfterNotification(); | |
| 544 } | |
| 545 | |
| 546 } // namespace extensions | 451 } // namespace extensions |
| OLD | NEW |