Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_settings_handler.cc

Issue 1083573002: Revert https://codereview.chromium.org/1060993003 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
14 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 18 #include "base/values.h"
18 #include "base/version.h" 19 #include "base/version.h"
19 #include "chrome/browser/background/background_contents.h" 20 #include "chrome/browser/background/background_contents.h"
20 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/extensions/extension_management.h" 23 #include "chrome/browser/extensions/extension_management.h"
23 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
24 #include "chrome/browser/extensions/extension_tab_util.h" 25 #include "chrome/browser/extensions/extension_tab_util.h"
25 #include "chrome/browser/extensions/extension_ui_util.h" 26 #include "chrome/browser/extensions/extension_ui_util.h"
27 #include "chrome/browser/extensions/install_verifier.h"
26 #include "chrome/browser/extensions/updater/extension_updater.h" 28 #include "chrome/browser/extensions/updater/extension_updater.h"
27 #include "chrome/browser/extensions/webstore_reinstaller.h" 29 #include "chrome/browser/extensions/webstore_reinstaller.h"
28 #include "chrome/browser/platform_util.h" 30 #include "chrome/browser/platform_util.h"
31 #include "chrome/browser/prefs/incognito_mode_prefs.h"
29 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/ui/apps/app_info_dialog.h" 33 #include "chrome/browser/ui/apps/app_info_dialog.h"
31 #include "chrome/browser/ui/browser.h" 34 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_finder.h" 35 #include "chrome/browser/ui/browser_finder.h"
33 #include "chrome/browser/ui/browser_window.h" 36 #include "chrome/browser/ui/browser_window.h"
34 #include "chrome/browser/ui/extensions/app_launch_params.h" 37 #include "chrome/browser/ui/extensions/app_launch_params.h"
35 #include "chrome/browser/ui/extensions/application_launch.h" 38 #include "chrome/browser/ui/extensions/application_launch.h"
36 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" 39 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h"
37 #include "chrome/common/chrome_version_info.h" 40 #include "chrome/common/chrome_version_info.h"
38 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // ExtensionSettingsHandler 82 // ExtensionSettingsHandler
80 // 83 //
81 /////////////////////////////////////////////////////////////////////////////// 84 ///////////////////////////////////////////////////////////////////////////////
82 85
83 ExtensionSettingsHandler::ExtensionSettingsHandler() 86 ExtensionSettingsHandler::ExtensionSettingsHandler()
84 : extension_service_(NULL), 87 : extension_service_(NULL),
85 ignore_notifications_(false), 88 ignore_notifications_(false),
86 deleting_rvh_(NULL), 89 deleting_rvh_(NULL),
87 deleting_rwh_id_(-1), 90 deleting_rwh_id_(-1),
88 deleting_rph_id_(-1), 91 deleting_rph_id_(-1),
92 registered_for_notifications_(false),
89 warning_service_observer_(this), 93 warning_service_observer_(this),
90 extension_prefs_observer_(this), 94 extension_prefs_observer_(this),
91 extension_management_observer_(this) { 95 extension_management_observer_(this) {
92 } 96 }
93 97
94 ExtensionSettingsHandler::~ExtensionSettingsHandler() { 98 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
95 } 99 }
96 100
97 // static 101 // static
98 void ExtensionSettingsHandler::RegisterProfilePrefs( 102 void ExtensionSettingsHandler::RegisterProfilePrefs(
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 content::NavigationController::ReloadType reload_type) { 312 content::NavigationController::ReloadType reload_type) {
309 if (reload_type != content::NavigationController::NO_RELOAD) 313 if (reload_type != content::NavigationController::NO_RELOAD)
310 ReloadUnpackedExtensions(); 314 ReloadUnpackedExtensions();
311 } 315 }
312 316
313 void ExtensionSettingsHandler::RegisterMessages() { 317 void ExtensionSettingsHandler::RegisterMessages() {
314 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); 318 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile();
315 extension_service_ = 319 extension_service_ =
316 extensions::ExtensionSystem::Get(profile)->extension_service(); 320 extensions::ExtensionSystem::Get(profile)->extension_service();
317 321
322 web_ui()->RegisterMessageCallback("extensionSettingsRequestExtensionsData",
323 base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData,
324 AsWeakPtr()));
325 web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode",
326 base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode,
327 AsWeakPtr()));
318 web_ui()->RegisterMessageCallback("extensionSettingsLaunch", 328 web_ui()->RegisterMessageCallback("extensionSettingsLaunch",
319 base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage, 329 base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage,
320 AsWeakPtr())); 330 AsWeakPtr()));
321 web_ui()->RegisterMessageCallback("extensionSettingsRepair", 331 web_ui()->RegisterMessageCallback("extensionSettingsRepair",
322 base::Bind(&ExtensionSettingsHandler::HandleRepairMessage, 332 base::Bind(&ExtensionSettingsHandler::HandleRepairMessage,
323 AsWeakPtr())); 333 AsWeakPtr()));
324 web_ui()->RegisterMessageCallback("extensionSettingsOptions", 334 web_ui()->RegisterMessageCallback("extensionSettingsOptions",
325 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, 335 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage,
326 AsWeakPtr())); 336 AsWeakPtr()));
327 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", 337 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate",
328 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage, 338 base::Bind(&ExtensionSettingsHandler::HandleAutoUpdateMessage,
329 AsWeakPtr())); 339 AsWeakPtr()));
330 web_ui()->RegisterMessageCallback("extensionSettingsShowPath", 340 web_ui()->RegisterMessageCallback("extensionSettingsShowPath",
331 base::Bind(&ExtensionSettingsHandler::HandleShowPath, 341 base::Bind(&ExtensionSettingsHandler::HandleShowPath,
332 AsWeakPtr())); 342 AsWeakPtr()));
333 web_ui()->RegisterMessageCallback("extensionSettingsRegister",
334 base::Bind(&ExtensionSettingsHandler::HandleRegisterMessage,
335 AsWeakPtr()));
336 } 343 }
337 344
338 void ExtensionSettingsHandler::Observe( 345 void ExtensionSettingsHandler::Observe(
339 int type, 346 int type,
340 const content::NotificationSource& source, 347 const content::NotificationSource& source,
341 const content::NotificationDetails& details) { 348 const content::NotificationDetails& details) {
342 Profile* profile = Profile::FromWebUI(web_ui()); 349 Profile* profile = Profile::FromWebUI(web_ui());
343 Profile* source_profile = NULL; 350 Profile* source_profile = NULL;
344 switch (type) { 351 switch (type) {
345 // We listen for notifications that will result in the page being 352 // We listen for notifications that will result in the page being
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 if (Manifest::IsUnpackedLocation(extension->location())) 417 if (Manifest::IsUnpackedLocation(extension->location()))
411 unpacked_extensions.push_back(extension.get()); 418 unpacked_extensions.push_back(extension.get());
412 } 419 }
413 420
414 for (std::vector<const Extension*>::iterator iter = 421 for (std::vector<const Extension*>::iterator iter =
415 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { 422 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) {
416 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); 423 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id());
417 } 424 }
418 } 425 }
419 426
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
420 void ExtensionSettingsHandler::HandleLaunchMessage( 494 void ExtensionSettingsHandler::HandleLaunchMessage(
421 const base::ListValue* args) { 495 const base::ListValue* args) {
422 CHECK_EQ(1U, args->GetSize()); 496 CHECK_EQ(1U, args->GetSize());
423 std::string extension_id; 497 std::string extension_id;
424 CHECK(args->GetString(0, &extension_id)); 498 CHECK(args->GetString(0, &extension_id));
425 const Extension* extension = 499 const Extension* extension =
426 extension_service_->GetExtensionById(extension_id, false); 500 extension_service_->GetExtensionById(extension_id, false);
427 OpenApplication(AppLaunchParams(extension_service_->profile(), extension, 501 OpenApplication(AppLaunchParams(extension_service_->profile(), extension,
428 extensions::LAUNCH_CONTAINER_WINDOW, 502 extensions::LAUNCH_CONTAINER_WINDOW,
429 NEW_WINDOW, 503 NEW_WINDOW,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 const Extension* extension = registry->GetExtensionById( 544 const Extension* extension = registry->GetExtensionById(
471 extension_id, 545 extension_id,
472 ExtensionRegistry::EVERYTHING); 546 ExtensionRegistry::EVERYTHING);
473 CHECK(extension); 547 CHECK(extension);
474 // We explicitly show manifest.json in order to work around an issue in OSX 548 // We explicitly show manifest.json in order to work around an issue in OSX
475 // where opening the directory doesn't focus the Finder. 549 // where opening the directory doesn't focus the Finder.
476 platform_util::ShowItemInFolder(profile, 550 platform_util::ShowItemInFolder(profile,
477 extension->path().Append(kManifestFilename)); 551 extension->path().Append(kManifestFilename));
478 } 552 }
479 553
480 void ExtensionSettingsHandler::HandleRegisterMessage( 554 const Extension* ExtensionSettingsHandler::GetActiveExtension(
481 const base::ListValue* args) { 555 const base::ListValue* args) {
482 if (!registrar_.IsEmpty()) 556 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args));
483 return; // Only register once. 557 CHECK(!extension_id.empty());
558 return extension_service_->GetExtensionById(extension_id, false);
559 }
484 560
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;
485 Profile* profile = Profile::FromWebUI(web_ui()); 573 Profile* profile = Profile::FromWebUI(web_ui());
486 574
487 // Register for notifications that we need to reload the page. 575 // Register for notifications that we need to reload the page.
488 registrar_.Add(this, 576 registrar_.Add(this,
489 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 577 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
490 content::Source<Profile>(profile)); 578 content::Source<Profile>(profile));
491 registrar_.Add(this, 579 registrar_.Add(this,
492 extensions::NOTIFICATION_EXTENSION_HOST_CREATED, 580 extensions::NOTIFICATION_EXTENSION_HOST_CREATED,
493 content::NotificationService::AllBrowserContextsAndSources()); 581 content::NotificationService::AllBrowserContextsAndSources());
494 registrar_.Add(this, 582 registrar_.Add(this,
(...skipping 18 matching lines...) Expand all
513 warning_service_observer_.Add(WarningService::Get(profile)); 601 warning_service_observer_.Add(WarningService::Get(profile));
514 602
515 extension_management_observer_.Add( 603 extension_management_observer_.Add(
516 ExtensionManagementFactory::GetForBrowserContext(profile)); 604 ExtensionManagementFactory::GetForBrowserContext(profile));
517 605
518 // Clear the preference for the ADT Promo before fully removing it. 606 // Clear the preference for the ADT Promo before fully removing it.
519 // TODO(devlin): Take this out when everyone's been updated. 607 // TODO(devlin): Take this out when everyone's been updated.
520 profile->GetPrefs()->ClearPref(prefs::kExtensionsUIDismissedADTPromo); 608 profile->GetPrefs()->ClearPref(prefs::kExtensionsUIDismissedADTPromo);
521 } 609 }
522 610
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
539 void ExtensionSettingsHandler::OnReinstallComplete( 611 void ExtensionSettingsHandler::OnReinstallComplete(
540 bool success, 612 bool success,
541 const std::string& error, 613 const std::string& error,
542 webstore_install::Result result) { 614 webstore_install::Result result) {
543 MaybeUpdateAfterNotification(); 615 MaybeUpdateAfterNotification();
544 } 616 }
545 617
546 } // namespace extensions 618 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_settings_handler.h ('k') | chrome/common/extensions/api/developer_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698