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

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

Issue 1060993003: [Extensions UI] Use developerPrivate API for profile configuration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ben's 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"
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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 content::NavigationController::ReloadType reload_type) { 309 content::NavigationController::ReloadType reload_type) {
313 if (reload_type != content::NavigationController::NO_RELOAD) 310 if (reload_type != content::NavigationController::NO_RELOAD)
314 ReloadUnpackedExtensions(); 311 ReloadUnpackedExtensions();
315 } 312 }
316 313
317 void ExtensionSettingsHandler::RegisterMessages() { 314 void ExtensionSettingsHandler::RegisterMessages() {
318 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); 315 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile();
319 extension_service_ = 316 extension_service_ =
320 extensions::ExtensionSystem::Get(profile)->extension_service(); 317 extensions::ExtensionSystem::Get(profile)->extension_service();
321 318
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", 319 web_ui()->RegisterMessageCallback("extensionSettingsLaunch",
329 base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage, 320 base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage,
330 AsWeakPtr())); 321 AsWeakPtr()));
331 web_ui()->RegisterMessageCallback("extensionSettingsRepair", 322 web_ui()->RegisterMessageCallback("extensionSettingsRepair",
332 base::Bind(&ExtensionSettingsHandler::HandleRepairMessage, 323 base::Bind(&ExtensionSettingsHandler::HandleRepairMessage,
333 AsWeakPtr())); 324 AsWeakPtr()));
334 web_ui()->RegisterMessageCallback("extensionSettingsOptions", 325 web_ui()->RegisterMessageCallback("extensionSettingsOptions",
335 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage, 326 base::Bind(&ExtensionSettingsHandler::HandleOptionsMessage,
336 AsWeakPtr())); 327 AsWeakPtr()));
337 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate", 328 web_ui()->RegisterMessageCallback("extensionSettingsAutoupdate",
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 if (Manifest::IsUnpackedLocation(extension->location())) 408 if (Manifest::IsUnpackedLocation(extension->location()))
418 unpacked_extensions.push_back(extension.get()); 409 unpacked_extensions.push_back(extension.get());
419 } 410 }
420 411
421 for (std::vector<const Extension*>::iterator iter = 412 for (std::vector<const Extension*>::iterator iter =
422 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { 413 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) {
423 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); 414 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id());
424 } 415 }
425 } 416 }
426 417
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( 418 void ExtensionSettingsHandler::HandleLaunchMessage(
495 const base::ListValue* args) { 419 const base::ListValue* args) {
496 CHECK_EQ(1U, args->GetSize()); 420 CHECK_EQ(1U, args->GetSize());
497 std::string extension_id; 421 std::string extension_id;
498 CHECK(args->GetString(0, &extension_id)); 422 CHECK(args->GetString(0, &extension_id));
499 const Extension* extension = 423 const Extension* extension =
500 extension_service_->GetExtensionById(extension_id, false); 424 extension_service_->GetExtensionById(extension_id, false);
501 OpenApplication(AppLaunchParams(extension_service_->profile(), extension, 425 OpenApplication(AppLaunchParams(extension_service_->profile(), extension,
502 extensions::LAUNCH_CONTAINER_WINDOW, 426 extensions::LAUNCH_CONTAINER_WINDOW,
503 NEW_WINDOW, 427 NEW_WINDOW,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 477
554 const Extension* ExtensionSettingsHandler::GetActiveExtension( 478 const Extension* ExtensionSettingsHandler::GetActiveExtension(
555 const base::ListValue* args) { 479 const base::ListValue* args) {
556 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args)); 480 std::string extension_id = base::UTF16ToUTF8(ExtractStringValue(args));
557 CHECK(!extension_id.empty()); 481 CHECK(!extension_id.empty());
558 return extension_service_->GetExtensionById(extension_id, false); 482 return extension_service_->GetExtensionById(extension_id, false);
559 } 483 }
560 484
561 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { 485 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() {
562 content::WebContents* contents = web_ui()->GetWebContents(); 486 content::WebContents* contents = web_ui()->GetWebContents();
563 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) 487 if (!ignore_notifications_ && contents && contents->GetRenderViewHost()) {
564 HandleRequestExtensionsData(NULL); 488 web_ui()->CallJavascriptFunction(
489 "extensions.ExtensionSettings.onExtensionsChanged");
490 }
565 deleting_rvh_ = NULL; 491 deleting_rvh_ = NULL;
566 } 492 }
567 493
568 void ExtensionSettingsHandler::MaybeRegisterForNotifications() { 494 void ExtensionSettingsHandler::MaybeRegisterForNotifications() {
569 if (registered_for_notifications_) 495 if (registered_for_notifications_)
570 return; 496 return;
571 497
572 registered_for_notifications_ = true; 498 registered_for_notifications_ = true;
573 Profile* profile = Profile::FromWebUI(web_ui()); 499 Profile* profile = Profile::FromWebUI(web_ui());
574 500
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } 535 }
610 536
611 void ExtensionSettingsHandler::OnReinstallComplete( 537 void ExtensionSettingsHandler::OnReinstallComplete(
612 bool success, 538 bool success,
613 const std::string& error, 539 const std::string& error,
614 webstore_install::Result result) { 540 webstore_install::Result result) {
615 MaybeUpdateAfterNotification(); 541 MaybeUpdateAfterNotification();
616 } 542 }
617 543
618 } // namespace extensions 544 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698