| 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 "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 Loading... |
| 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 Loading... |
| 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("userModifiable", |
| 102 management_policy_->UserMayModifySettings(extension, NULL)); |
| 103 } else { |
| 104 // This should only happen in testing. |
| 105 extension_data->SetBoolean("userModifiable", 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 void ExtensionSettingsHandler::NavigateToPendingEntry(const GURL& url, | 292 void ExtensionSettingsHandler::NavigateToPendingEntry(const GURL& url, |
| 284 content::NavigationController::ReloadType reload_type) { | 293 content::NavigationController::ReloadType reload_type) { |
| 285 if (reload_type != content::NavigationController::NO_RELOAD) | 294 if (reload_type != content::NavigationController::NO_RELOAD) |
| 286 ReloadUnpackedExtensions(); | 295 ReloadUnpackedExtensions(); |
| 287 } | 296 } |
| 288 | 297 |
| 289 void ExtensionSettingsHandler::RegisterMessages() { | 298 void ExtensionSettingsHandler::RegisterMessages() { |
| 290 extension_service_ = Profile::FromWebUI(web_ui())->GetOriginalProfile()-> | 299 extension_service_ = Profile::FromWebUI(web_ui())->GetOriginalProfile()-> |
| 291 GetExtensionService(); | 300 GetExtensionService(); |
| 292 | 301 |
| 302 if (extension_service_) { |
| 303 management_policy_ = ExtensionSystem::Get( |
| 304 extension_service_->profile())->management_policy(); |
| 305 } |
| 306 |
| 293 web_ui()->RegisterMessageCallback("extensionSettingsRequestExtensionsData", | 307 web_ui()->RegisterMessageCallback("extensionSettingsRequestExtensionsData", |
| 294 base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData, | 308 base::Bind(&ExtensionSettingsHandler::HandleRequestExtensionsData, |
| 295 base::Unretained(this))); | 309 base::Unretained(this))); |
| 296 web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode", | 310 web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode", |
| 297 base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode, | 311 base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode, |
| 298 base::Unretained(this))); | 312 base::Unretained(this))); |
| 299 web_ui()->RegisterMessageCallback("extensionSettingsInspect", | 313 web_ui()->RegisterMessageCallback("extensionSettingsInspect", |
| 300 base::Bind(&ExtensionSettingsHandler::HandleInspectMessage, | 314 base::Bind(&ExtensionSettingsHandler::HandleInspectMessage, |
| 301 base::Unretained(this))); | 315 base::Unretained(this))); |
| 302 web_ui()->RegisterMessageCallback("extensionSettingsReload", | 316 web_ui()->RegisterMessageCallback("extensionSettingsReload", |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } | 577 } |
| 564 | 578 |
| 565 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { | 579 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { |
| 566 CHECK_EQ(2U, args->GetSize()); | 580 CHECK_EQ(2U, args->GetSize()); |
| 567 std::string extension_id, enable_str; | 581 std::string extension_id, enable_str; |
| 568 CHECK(args->GetString(0, &extension_id)); | 582 CHECK(args->GetString(0, &extension_id)); |
| 569 CHECK(args->GetString(1, &enable_str)); | 583 CHECK(args->GetString(1, &enable_str)); |
| 570 | 584 |
| 571 const Extension* extension = | 585 const Extension* extension = |
| 572 extension_service_->GetInstalledExtension(extension_id); | 586 extension_service_->GetInstalledExtension(extension_id); |
| 573 if (!extension || !Extension::UserMayDisable(extension->location())) { | 587 if (!extension || |
| 588 !management_policy_->UserMayModifySettings(extension, NULL)) { |
| 574 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" | 589 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" |
| 575 << "made. Extension id: " << extension->id(); | 590 << "made. Extension id: " << extension->id(); |
| 576 return; | 591 return; |
| 577 } | 592 } |
| 578 | 593 |
| 579 if (enable_str == "true") { | 594 if (enable_str == "true") { |
| 580 ExtensionPrefs* prefs = extension_service_->extension_prefs(); | 595 ExtensionPrefs* prefs = extension_service_->extension_prefs(); |
| 581 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 596 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
| 582 extensions::ShowExtensionDisabledDialog( | 597 extensions::ShowExtensionDisabledDialog( |
| 583 extension_service_, Profile::FromWebUI(web_ui()), extension); | 598 extension_service_, Profile::FromWebUI(web_ui()), extension); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 const ListValue* args) { | 636 const ListValue* args) { |
| 622 CHECK_EQ(2U, args->GetSize()); | 637 CHECK_EQ(2U, args->GetSize()); |
| 623 std::string extension_id, allow_str; | 638 std::string extension_id, allow_str; |
| 624 CHECK(args->GetString(0, &extension_id)); | 639 CHECK(args->GetString(0, &extension_id)); |
| 625 CHECK(args->GetString(1, &allow_str)); | 640 CHECK(args->GetString(1, &allow_str)); |
| 626 const Extension* extension = | 641 const Extension* extension = |
| 627 extension_service_->GetInstalledExtension(extension_id); | 642 extension_service_->GetInstalledExtension(extension_id); |
| 628 if (!extension) | 643 if (!extension) |
| 629 return; | 644 return; |
| 630 | 645 |
| 631 if (!Extension::UserMayDisable(extension->location())) { | 646 if (!management_policy_->UserMayModifySettings(extension, NULL)) { |
| 632 LOG(ERROR) << "Attempt to change allow file access of an extension that is " | 647 LOG(ERROR) << "Attempt to change allow file access of an extension that is " |
| 633 << "non-usermanagable was made. Extension id : " | 648 << "non-usermanagable was made. Extension id : " |
| 634 << extension->id(); | 649 << extension->id(); |
| 635 return; | 650 return; |
| 636 } | 651 } |
| 637 | 652 |
| 638 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); | 653 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); |
| 639 } | 654 } |
| 640 | 655 |
| 641 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { | 656 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { |
| 642 CHECK_EQ(1U, args->GetSize()); | 657 CHECK_EQ(1U, args->GetSize()); |
| 643 std::string extension_id; | 658 std::string extension_id; |
| 644 CHECK(args->GetString(0, &extension_id)); | 659 CHECK(args->GetString(0, &extension_id)); |
| 645 const Extension* extension = | 660 const Extension* extension = |
| 646 extension_service_->GetInstalledExtension(extension_id); | 661 extension_service_->GetInstalledExtension(extension_id); |
| 647 if (!extension) | 662 if (!extension) |
| 648 return; | 663 return; |
| 649 | 664 |
| 650 if (!Extension::UserMayDisable(extension->location())) { | 665 if (!management_policy_->UserMayModifySettings(extension, NULL)) { |
| 651 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " | 666 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " |
| 652 << "was made. Extension id : " << extension->id(); | 667 << "was made. Extension id : " << extension->id(); |
| 653 return; | 668 return; |
| 654 } | 669 } |
| 655 | 670 |
| 656 if (!extension_id_prompting_.empty()) | 671 if (!extension_id_prompting_.empty()) |
| 657 return; // Only one prompt at a time. | 672 return; // Only one prompt at a time. |
| 658 | 673 |
| 659 extension_id_prompting_ = extension_id; | 674 extension_id_prompting_ = extension_id; |
| 660 | 675 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 return extension_uninstall_dialog_.get(); | 844 return extension_uninstall_dialog_.get(); |
| 830 #else | 845 #else |
| 831 return NULL; | 846 return NULL; |
| 832 #endif // !defined(OS_ANDROID) | 847 #endif // !defined(OS_ANDROID) |
| 833 } | 848 } |
| 834 | 849 |
| 835 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { | 850 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { |
| 836 if (host) | 851 if (host) |
| 837 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); | 852 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); |
| 838 } | 853 } |
| OLD | NEW |