| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "grit/chromium_strings.h" | 55 #include "grit/chromium_strings.h" |
| 56 #include "grit/generated_resources.h" | 56 #include "grit/generated_resources.h" |
| 57 #include "grit/theme_resources.h" | 57 #include "grit/theme_resources.h" |
| 58 #include "ui/base/l10n/l10n_util.h" | 58 #include "ui/base/l10n/l10n_util.h" |
| 59 #include "ui/base/resource/resource_bundle.h" | 59 #include "ui/base/resource/resource_bundle.h" |
| 60 | 60 |
| 61 using content::RenderViewHost; | 61 using content::RenderViewHost; |
| 62 using content::WebContents; | 62 using content::WebContents; |
| 63 using extensions::Extension; | 63 using extensions::Extension; |
| 64 using extensions::ExtensionUpdater; | 64 using extensions::ExtensionUpdater; |
| 65 using extensions::ExtensionWarning; |
| 65 using extensions::ManagementPolicy; | 66 using extensions::ManagementPolicy; |
| 66 | 67 |
| 67 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
| 68 // | 69 // |
| 69 // ExtensionSettingsHandler | 70 // ExtensionSettingsHandler |
| 70 // | 71 // |
| 71 /////////////////////////////////////////////////////////////////////////////// | 72 /////////////////////////////////////////////////////////////////////////////// |
| 72 | 73 |
| 73 ExtensionSettingsHandler::ExtensionSettingsHandler() | 74 ExtensionSettingsHandler::ExtensionSettingsHandler() |
| 74 : extension_service_(NULL), | 75 : extension_service_(NULL), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 99 // static | 100 // static |
| 100 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { | 101 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { |
| 101 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, | 102 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, |
| 102 false, | 103 false, |
| 103 PrefService::SYNCABLE_PREF); | 104 PrefService::SYNCABLE_PREF); |
| 104 } | 105 } |
| 105 | 106 |
| 106 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( | 107 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
| 107 const Extension* extension, | 108 const Extension* extension, |
| 108 const std::vector<ExtensionPage>& pages, | 109 const std::vector<ExtensionPage>& pages, |
| 109 const ExtensionWarningSet* warnings_set) { | 110 const extensions::ExtensionWarningService* warnings_set) { |
| 110 DictionaryValue* extension_data = new DictionaryValue(); | 111 DictionaryValue* extension_data = new DictionaryValue(); |
| 111 bool enabled = extension_service_->IsExtensionEnabled(extension->id()); | 112 bool enabled = extension_service_->IsExtensionEnabled(extension->id()); |
| 112 extension->GetBasicInfo(enabled, extension_data); | 113 extension->GetBasicInfo(enabled, extension_data); |
| 113 | 114 |
| 114 extension_data->SetBoolean("userModifiable", | 115 extension_data->SetBoolean("userModifiable", |
| 115 management_policy_->UserMayModifySettings(extension, NULL)); | 116 management_policy_->UserMayModifySettings(extension, NULL)); |
| 116 | 117 |
| 117 GURL icon = | 118 GURL icon = |
| 118 ExtensionIconSource::GetIconURL(extension, | 119 ExtensionIconSource::GetIconURL(extension, |
| 119 extension_misc::EXTENSION_ICON_MEDIUM, | 120 extension_misc::EXTENSION_ICON_MEDIUM, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 view_value->SetInteger("renderProcessId", iter->render_process_id); | 169 view_value->SetInteger("renderProcessId", iter->render_process_id); |
| 169 view_value->SetBoolean("incognito", iter->incognito); | 170 view_value->SetBoolean("incognito", iter->incognito); |
| 170 views->Append(view_value); | 171 views->Append(view_value); |
| 171 } | 172 } |
| 172 extension_data->Set("views", views); | 173 extension_data->Set("views", views); |
| 173 extension_data->SetBoolean("hasPopupAction", | 174 extension_data->SetBoolean("hasPopupAction", |
| 174 extension->browser_action() || extension->page_action()); | 175 extension->browser_action() || extension->page_action()); |
| 175 | 176 |
| 176 // Add warnings. | 177 // Add warnings. |
| 177 if (warnings_set) { | 178 if (warnings_set) { |
| 178 std::set<ExtensionWarningSet::WarningType> warnings; | 179 std::vector<std::string> warnings; |
| 179 warnings_set->GetWarningsAffectingExtension(extension->id(), &warnings); | 180 warnings_set->GetWarningMessagesForExtension(extension->id(), &warnings); |
| 180 | 181 |
| 181 if (!warnings.empty()) { | 182 if (!warnings.empty()) { |
| 182 ListValue* warnings_list = new ListValue; | 183 ListValue* warnings_list = new ListValue; |
| 183 for (std::set<ExtensionWarningSet::WarningType>::const_iterator iter = | 184 for (std::vector<std::string>::const_iterator iter = warnings.begin(); |
| 184 warnings.begin(); | 185 iter != warnings.end(); ++iter) { |
| 185 iter != warnings.end(); | 186 warnings_list->Append(Value::CreateStringValue(*iter)); |
| 186 ++iter) { | |
| 187 string16 warning_string( | |
| 188 ExtensionWarningSet::GetLocalizedWarning(*iter)); | |
| 189 warnings_list->Append(Value::CreateStringValue(warning_string)); | |
| 190 } | 187 } |
| 191 extension_data->Set("warnings", warnings_list); | 188 extension_data->Set("warnings", warnings_list); |
| 192 } | 189 } |
| 193 } | 190 } |
| 194 | 191 |
| 195 // Add install warnings (these are not the same as warnings!). | 192 // Add install warnings (these are not the same as warnings!). |
| 196 if (extension->location() == Extension::LOAD) { | 193 if (extension->location() == Extension::LOAD) { |
| 197 const Extension::InstallWarningVector& install_warnings = | 194 const Extension::InstallWarningVector& install_warnings = |
| 198 extension->install_warnings(); | 195 extension->install_warnings(); |
| 199 if (!install_warnings.empty()) { | 196 if (!install_warnings.empty()) { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 for (std::vector<const Extension*>::iterator iter = | 461 for (std::vector<const Extension*>::iterator iter = |
| 465 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 462 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
| 466 extension_service_->ReloadExtension((*iter)->id()); | 463 extension_service_->ReloadExtension((*iter)->id()); |
| 467 } | 464 } |
| 468 } | 465 } |
| 469 | 466 |
| 470 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 467 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| 471 const ListValue* args) { | 468 const ListValue* args) { |
| 472 DictionaryValue results; | 469 DictionaryValue results; |
| 473 | 470 |
| 471 Profile* profile = Profile::FromWebUI(web_ui()); |
| 472 |
| 474 // Add the extensions to the results structure. | 473 // Add the extensions to the results structure. |
| 475 ListValue *extensions_list = new ListValue(); | 474 ListValue *extensions_list = new ListValue(); |
| 476 | 475 |
| 477 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); | 476 extensions::ExtensionWarningService* warnings = |
| 477 extensions::ExtensionSystem::Get(profile)->warning_service(); |
| 478 | 478 |
| 479 const ExtensionSet* extensions = extension_service_->extensions(); | 479 const ExtensionSet* extensions = extension_service_->extensions(); |
| 480 for (ExtensionSet::const_iterator extension = extensions->begin(); | 480 for (ExtensionSet::const_iterator extension = extensions->begin(); |
| 481 extension != extensions->end(); ++extension) { | 481 extension != extensions->end(); ++extension) { |
| 482 if ((*extension)->ShouldDisplayInExtensionSettings()) { | 482 if ((*extension)->ShouldDisplayInExtensionSettings()) { |
| 483 extensions_list->Append(CreateExtensionDetailValue( | 483 extensions_list->Append(CreateExtensionDetailValue( |
| 484 *extension, | 484 *extension, |
| 485 GetInspectablePagesForExtension(*extension, true), | 485 GetInspectablePagesForExtension(*extension, true), |
| 486 warnings)); | 486 warnings)); |
| 487 } | 487 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 507 warnings)); | 507 warnings)); |
| 508 } | 508 } |
| 509 } | 509 } |
| 510 results.Set("extensions", extensions_list); | 510 results.Set("extensions", extensions_list); |
| 511 | 511 |
| 512 if (ManagedMode::IsInManagedMode()) { | 512 if (ManagedMode::IsInManagedMode()) { |
| 513 results.SetBoolean("managedMode", true); | 513 results.SetBoolean("managedMode", true); |
| 514 results.SetBoolean("developerMode", false); | 514 results.SetBoolean("developerMode", false); |
| 515 } else { | 515 } else { |
| 516 results.SetBoolean("managedMode", false); | 516 results.SetBoolean("managedMode", false); |
| 517 Profile* profile = Profile::FromWebUI(web_ui()); | 517 |
| 518 bool developer_mode = | 518 bool developer_mode = |
| 519 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 519 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 520 results.SetBoolean("developerMode", developer_mode); | 520 results.SetBoolean("developerMode", developer_mode); |
| 521 } | 521 } |
| 522 | 522 |
| 523 bool load_unpacked_disabled = | 523 bool load_unpacked_disabled = |
| 524 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault(); | 524 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault(); |
| 525 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); | 525 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); |
| 526 | 526 |
| 527 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", | 527 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", |
| 528 results); | 528 results); |
| 529 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); | 529 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); |
| 530 | 530 |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 #else | 880 #else |
| 881 return NULL; | 881 return NULL; |
| 882 #endif // !defined(OS_ANDROID) | 882 #endif // !defined(OS_ANDROID) |
| 883 } | 883 } |
| 884 | 884 |
| 885 void ExtensionSettingsHandler::InspectExtensionHost( | 885 void ExtensionSettingsHandler::InspectExtensionHost( |
| 886 extensions::ExtensionHost* host) { | 886 extensions::ExtensionHost* host) { |
| 887 if (host) | 887 if (host) |
| 888 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); | 888 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); |
| 889 } | 889 } |
| OLD | NEW |