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

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

Issue 10382149: Refactor the various ways to control what users can do to extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Addressing comments from partial review Created 8 years, 7 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 | Annotate | Revision Log
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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 using extensions::ExtensionUpdater; 58 using extensions::ExtensionUpdater;
59 59
60 /////////////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////////////
61 // 61 //
62 // ExtensionSettingsHandler 62 // ExtensionSettingsHandler
63 // 63 //
64 /////////////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////////////
65 65
66 ExtensionSettingsHandler::ExtensionSettingsHandler() 66 ExtensionSettingsHandler::ExtensionSettingsHandler()
67 : extension_service_(NULL), 67 : extension_service_(NULL),
68 management_policy_(NULL),
68 ignore_notifications_(false), 69 ignore_notifications_(false),
69 deleting_rvh_(NULL), 70 deleting_rvh_(NULL),
70 registered_for_notifications_(false) { 71 registered_for_notifications_(false) {
71 } 72 }
72 73
73 ExtensionSettingsHandler::~ExtensionSettingsHandler() { 74 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
74 // There may be pending file dialogs, we need to tell them that we've gone 75 // There may be pending file dialogs, we need to tell them that we've gone
75 // away so they don't try and call back to us. 76 // away so they don't try and call back to us.
76 if (load_extension_dialog_) 77 if (load_extension_dialog_)
77 load_extension_dialog_->ListenerDestroyed(); 78 load_extension_dialog_->ListenerDestroyed();
(...skipping 11 matching lines...) Expand all
89 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( 90 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue(
90 const Extension* extension, 91 const Extension* extension,
91 const std::vector<ExtensionPage>& pages, 92 const std::vector<ExtensionPage>& pages,
92 const ExtensionWarningSet* warnings_set) { 93 const ExtensionWarningSet* warnings_set) {
93 DictionaryValue* extension_data = new DictionaryValue(); 94 DictionaryValue* extension_data = new DictionaryValue();
94 bool enabled = extension_service_ ? 95 bool enabled = extension_service_ ?
95 extension_service_->IsExtensionEnabled(extension->id()) : 96 extension_service_->IsExtensionEnabled(extension->id()) :
96 true; 97 true;
97 extension->GetBasicInfo(enabled, extension_data); 98 extension->GetBasicInfo(enabled, extension_data);
98 99
100 if (management_policy_) {
101 extension_data->SetBoolean("mayModifySettings",
102 management_policy_->UserMayModifySettings(extension, NULL));
103 } else {
104 // This should only happen in testing.
Aaron Boodman 2012/05/29 03:03:08 Can we somehow make the management policy exist in
105 extension_data->SetBoolean("mayModifySettings", true);
106 }
107
99 GURL icon = 108 GURL icon =
100 ExtensionIconSource::GetIconURL(extension, 109 ExtensionIconSource::GetIconURL(extension,
101 ExtensionIconSet::EXTENSION_ICON_MEDIUM, 110 ExtensionIconSet::EXTENSION_ICON_MEDIUM,
102 ExtensionIconSet::MATCH_BIGGER, 111 ExtensionIconSet::MATCH_BIGGER,
103 !enabled, NULL); 112 !enabled, NULL);
104 if (extension->location() == Extension::LOAD) 113 if (extension->location() == Extension::LOAD)
105 extension_data->SetString("path", extension->path().value()); 114 extension_data->SetString("path", extension->path().value());
106 extension_data->SetString("icon", icon.spec()); 115 extension_data->SetString("icon", icon.spec());
107 extension_data->SetBoolean("isUnpacked", 116 extension_data->SetBoolean("isUnpacked",
108 extension->location() == Extension::LOAD); 117 extension->location() == Extension::LOAD);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 void ExtensionSettingsHandler::NavigateToPendingEntry(const GURL& url, 289 void ExtensionSettingsHandler::NavigateToPendingEntry(const GURL& url,
281 content::NavigationController::ReloadType reload_type) { 290 content::NavigationController::ReloadType reload_type) {
282 if (reload_type != content::NavigationController::NO_RELOAD) 291 if (reload_type != content::NavigationController::NO_RELOAD)
283 ReloadUnpackedExtensions(); 292 ReloadUnpackedExtensions();
284 } 293 }
285 294
286 void ExtensionSettingsHandler::RegisterMessages() { 295 void ExtensionSettingsHandler::RegisterMessages() {
287 extension_service_ = Profile::FromWebUI(web_ui())->GetOriginalProfile()-> 296 extension_service_ = Profile::FromWebUI(web_ui())->GetOriginalProfile()->
288 GetExtensionService(); 297 GetExtensionService();
289 298
299 if (extension_service_) {
Aaron Boodman 2012/05/29 03:03:08 Is this again because of testing? It would be nice
300 management_policy_ = ExtensionSystem::Get(
301 extension_service_->profile())->management_policy();
302 }
303
290 web_ui()->RegisterMessageCallback("extensionSettingsRequestExtensionsData", 304 web_ui()->RegisterMessageCallback("extensionSettingsRequestExtensionsData",
291 base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData, 305 base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData,
292 base::Unretained(this))); 306 base::Unretained(this)));
293 web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode", 307 web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode",
294 base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode, 308 base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode,
295 base::Unretained(this))); 309 base::Unretained(this)));
296 web_ui()->RegisterMessageCallback("extensionSettingsInspect", 310 web_ui()->RegisterMessageCallback("extensionSettingsInspect",
297 base::Bind(&ExtensionSettingsHandler::HandleInspectMessage, 311 base::Bind(&ExtensionSettingsHandler::HandleInspectMessage,
298 base::Unretained(this))); 312 base::Unretained(this)));
299 web_ui()->RegisterMessageCallback("extensionSettingsReload", 313 web_ui()->RegisterMessageCallback("extensionSettingsReload",
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 } 574 }
561 575
562 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { 576 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) {
563 CHECK_EQ(2U, args->GetSize()); 577 CHECK_EQ(2U, args->GetSize());
564 std::string extension_id, enable_str; 578 std::string extension_id, enable_str;
565 CHECK(args->GetString(0, &extension_id)); 579 CHECK(args->GetString(0, &extension_id));
566 CHECK(args->GetString(1, &enable_str)); 580 CHECK(args->GetString(1, &enable_str));
567 581
568 const Extension* extension = 582 const Extension* extension =
569 extension_service_->GetInstalledExtension(extension_id); 583 extension_service_->GetInstalledExtension(extension_id);
570 if (!extension || !Extension::UserMayDisable(extension->location())) { 584 if (!extension ||
585 !management_policy_->UserMayModifySettings(extension, NULL)) {
571 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" 586 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was"
572 << "made. Extension id: " << extension->id(); 587 << "made. Extension id: " << extension->id();
573 return; 588 return;
574 } 589 }
575 590
576 if (enable_str == "true") { 591 if (enable_str == "true") {
577 ExtensionPrefs* prefs = extension_service_->extension_prefs(); 592 ExtensionPrefs* prefs = extension_service_->extension_prefs();
578 if (prefs->DidExtensionEscalatePermissions(extension_id)) { 593 if (prefs->DidExtensionEscalatePermissions(extension_id)) {
579 extensions::ShowExtensionDisabledDialog( 594 extensions::ShowExtensionDisabledDialog(
580 extension_service_, Profile::FromWebUI(web_ui()), extension); 595 extension_service_, Profile::FromWebUI(web_ui()), extension);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 const ListValue* args) { 633 const ListValue* args) {
619 CHECK_EQ(2U, args->GetSize()); 634 CHECK_EQ(2U, args->GetSize());
620 std::string extension_id, allow_str; 635 std::string extension_id, allow_str;
621 CHECK(args->GetString(0, &extension_id)); 636 CHECK(args->GetString(0, &extension_id));
622 CHECK(args->GetString(1, &allow_str)); 637 CHECK(args->GetString(1, &allow_str));
623 const Extension* extension = 638 const Extension* extension =
624 extension_service_->GetInstalledExtension(extension_id); 639 extension_service_->GetInstalledExtension(extension_id);
625 if (!extension) 640 if (!extension)
626 return; 641 return;
627 642
628 if (!Extension::UserMayDisable(extension->location())) { 643 if (!management_policy_->UserMayModifySettings(extension, NULL)) {
629 LOG(ERROR) << "Attempt to change allow file access of an extension that is " 644 LOG(ERROR) << "Attempt to change allow file access of an extension that is "
630 << "non-usermanagable was made. Extension id : " 645 << "non-usermanagable was made. Extension id : "
631 << extension->id(); 646 << extension->id();
632 return; 647 return;
633 } 648 }
634 649
635 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); 650 extension_service_->SetAllowFileAccess(extension, allow_str == "true");
636 } 651 }
637 652
638 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { 653 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) {
639 CHECK_EQ(1U, args->GetSize()); 654 CHECK_EQ(1U, args->GetSize());
640 std::string extension_id; 655 std::string extension_id;
641 CHECK(args->GetString(0, &extension_id)); 656 CHECK(args->GetString(0, &extension_id));
642 const Extension* extension = 657 const Extension* extension =
643 extension_service_->GetInstalledExtension(extension_id); 658 extension_service_->GetInstalledExtension(extension_id);
644 if (!extension) 659 if (!extension)
645 return; 660 return;
646 661
647 if (!Extension::UserMayDisable(extension->location())) { 662 if (!management_policy_->UserMayModifySettings(extension, NULL)) {
648 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " 663 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable "
649 << "was made. Extension id : " << extension->id(); 664 << "was made. Extension id : " << extension->id();
650 return; 665 return;
651 } 666 }
652 667
653 if (!extension_id_prompting_.empty()) 668 if (!extension_id_prompting_.empty())
654 return; // Only one prompt at a time. 669 return; // Only one prompt at a time.
655 670
656 extension_id_prompting_ = extension_id; 671 extension_id_prompting_ = extension_id;
657 672
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 return extension_uninstall_dialog_.get(); 840 return extension_uninstall_dialog_.get();
826 #else 841 #else
827 return NULL; 842 return NULL;
828 #endif // !defined(OS_ANDROID) 843 #endif // !defined(OS_ANDROID)
829 } 844 }
830 845
831 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { 846 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) {
832 if (host) 847 if (host)
833 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); 848 DevToolsWindow::OpenDevToolsWindow(host->render_view_host());
834 } 849 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698