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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 #include "grit/theme_resources.h" | 68 #include "grit/theme_resources.h" |
69 #include "ui/base/l10n/l10n_util.h" | 69 #include "ui/base/l10n/l10n_util.h" |
70 #include "ui/base/resource/resource_bundle.h" | 70 #include "ui/base/resource/resource_bundle.h" |
71 | 71 |
72 using content::RenderViewHost; | 72 using content::RenderViewHost; |
73 using content::WebContents; | 73 using content::WebContents; |
74 using extensions::Extension; | 74 using extensions::Extension; |
75 using extensions::ExtensionUpdater; | 75 using extensions::ExtensionUpdater; |
76 using extensions::ExtensionWarning; | 76 using extensions::ExtensionWarning; |
77 using extensions::ManagementPolicy; | 77 using extensions::ManagementPolicy; |
| 78 using extensions::Manifest; |
78 | 79 |
79 /////////////////////////////////////////////////////////////////////////////// | 80 /////////////////////////////////////////////////////////////////////////////// |
80 // | 81 // |
81 // ExtensionSettingsHandler | 82 // ExtensionSettingsHandler |
82 // | 83 // |
83 /////////////////////////////////////////////////////////////////////////////// | 84 /////////////////////////////////////////////////////////////////////////////// |
84 | 85 |
85 ExtensionSettingsHandler::ExtensionSettingsHandler() | 86 ExtensionSettingsHandler::ExtensionSettingsHandler() |
86 : extension_service_(NULL), | 87 : extension_service_(NULL), |
87 management_policy_(NULL), | 88 management_policy_(NULL), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 extension->GetBasicInfo(enabled, extension_data); | 125 extension->GetBasicInfo(enabled, extension_data); |
125 | 126 |
126 extension_data->SetBoolean("userModifiable", | 127 extension_data->SetBoolean("userModifiable", |
127 management_policy_->UserMayModifySettings(extension, NULL)); | 128 management_policy_->UserMayModifySettings(extension, NULL)); |
128 | 129 |
129 GURL icon = | 130 GURL icon = |
130 ExtensionIconSource::GetIconURL(extension, | 131 ExtensionIconSource::GetIconURL(extension, |
131 extension_misc::EXTENSION_ICON_MEDIUM, | 132 extension_misc::EXTENSION_ICON_MEDIUM, |
132 ExtensionIconSet::MATCH_BIGGER, | 133 ExtensionIconSet::MATCH_BIGGER, |
133 !enabled, NULL); | 134 !enabled, NULL); |
134 if (extension->location() == Extension::LOAD) | 135 if (extension->location() == Manifest::LOAD) |
135 extension_data->SetString("path", extension->path().value()); | 136 extension_data->SetString("path", extension->path().value()); |
136 extension_data->SetString("icon", icon.spec()); | 137 extension_data->SetString("icon", icon.spec()); |
137 extension_data->SetBoolean("isUnpacked", | 138 extension_data->SetBoolean("isUnpacked", |
138 extension->location() == Extension::LOAD); | 139 extension->location() == Manifest::LOAD); |
139 extension_data->SetBoolean("terminated", | 140 extension_data->SetBoolean("terminated", |
140 extension_service_->terminated_extensions()->Contains(extension->id())); | 141 extension_service_->terminated_extensions()->Contains(extension->id())); |
141 extension_data->SetBoolean("enabledIncognito", | 142 extension_data->SetBoolean("enabledIncognito", |
142 extension_service_->IsIncognitoEnabled(extension->id())); | 143 extension_service_->IsIncognitoEnabled(extension->id())); |
143 extension_data->SetBoolean("incognitoCanBeEnabled", | 144 extension_data->SetBoolean("incognitoCanBeEnabled", |
144 extension->can_be_incognito_enabled()); | 145 extension->can_be_incognito_enabled()); |
145 extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); | 146 extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); |
146 extension_data->SetBoolean("allowFileAccess", | 147 extension_data->SetBoolean("allowFileAccess", |
147 extension_service_->AllowFileAccess(extension)); | 148 extension_service_->AllowFileAccess(extension)); |
148 extension_data->SetBoolean("allow_activity", | 149 extension_data->SetBoolean("allow_activity", |
149 enabled && CommandLine::ForCurrentProcess()->HasSwitch( | 150 enabled && CommandLine::ForCurrentProcess()->HasSwitch( |
150 switches::kEnableExtensionActivityUI)); | 151 switches::kEnableExtensionActivityUI)); |
151 extension_data->SetBoolean("allow_reload", | 152 extension_data->SetBoolean("allow_reload", |
152 extension->location() == Extension::LOAD); | 153 extension->location() == Manifest::LOAD); |
153 extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); | 154 extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); |
154 extension_data->SetBoolean("is_platform_app", extension->is_platform_app()); | 155 extension_data->SetBoolean("is_platform_app", extension->is_platform_app()); |
155 extension_data->SetBoolean("homepageProvided", | 156 extension_data->SetBoolean("homepageProvided", |
156 extensions::ManifestURL::GetHomepageURL(extension).is_valid()); | 157 extensions::ManifestURL::GetHomepageURL(extension).is_valid()); |
157 | 158 |
158 string16 automatically_disabled_text; | 159 string16 automatically_disabled_text; |
159 int disable_reasons = | 160 int disable_reasons = |
160 extension_service_->extension_prefs()->GetDisableReasons(extension->id()); | 161 extension_service_->extension_prefs()->GetDisableReasons(extension->id()); |
161 if ((disable_reasons & Extension::DISABLE_SIDELOAD_WIPEOUT) != 0) { | 162 if ((disable_reasons & Extension::DISABLE_SIDELOAD_WIPEOUT) != 0) { |
162 automatically_disabled_text = l10n_util::GetStringUTF16( | 163 automatically_disabled_text = l10n_util::GetStringUTF16( |
163 IDS_OPTIONS_SIDELOAD_WIPEOUT_AUTOMATIC_DISABLE); | 164 IDS_OPTIONS_SIDELOAD_WIPEOUT_AUTOMATIC_DISABLE); |
164 } | 165 } |
165 extension_data->SetString("disableReason", automatically_disabled_text); | 166 extension_data->SetString("disableReason", automatically_disabled_text); |
166 | 167 |
167 string16 location_text; | 168 string16 location_text; |
168 if (extension->location() == Extension::INTERNAL && | 169 if (extension->location() == Manifest::INTERNAL && |
169 !extension->UpdatesFromGallery()) { | 170 !extension->UpdatesFromGallery()) { |
170 location_text = l10n_util::GetStringUTF16( | 171 location_text = l10n_util::GetStringUTF16( |
171 IDS_OPTIONS_SIDELOAD_WIPEOUT_DISABLE_REASON_UNKNOWN); | 172 IDS_OPTIONS_SIDELOAD_WIPEOUT_DISABLE_REASON_UNKNOWN); |
172 } else if (extension->location() == Extension::EXTERNAL_REGISTRY) { | 173 } else if (extension->location() == Manifest::EXTERNAL_REGISTRY) { |
173 location_text = l10n_util::GetStringUTF16( | 174 location_text = l10n_util::GetStringUTF16( |
174 IDS_OPTIONS_SIDELOAD_WIPEOUT_DISABLE_REASON_3RD_PARTY); | 175 IDS_OPTIONS_SIDELOAD_WIPEOUT_DISABLE_REASON_3RD_PARTY); |
175 } | 176 } |
176 extension_data->SetString("locationText", location_text); | 177 extension_data->SetString("locationText", location_text); |
177 | 178 |
178 // Determine the sort order: Extensions loaded through --load-extensions show | 179 // Determine the sort order: Extensions loaded through --load-extensions show |
179 // up at the top. Disabled extensions show up at the bottom. | 180 // up at the top. Disabled extensions show up at the bottom. |
180 if (extension->location() == Extension::LOAD) | 181 if (extension->location() == Manifest::LOAD) |
181 extension_data->SetInteger("order", 1); | 182 extension_data->SetInteger("order", 1); |
182 else | 183 else |
183 extension_data->SetInteger("order", 2); | 184 extension_data->SetInteger("order", 2); |
184 | 185 |
185 if (!extension_service_->extension_prefs()-> | 186 if (!extension_service_->extension_prefs()-> |
186 GetBrowserActionVisibility(extension)) { | 187 GetBrowserActionVisibility(extension)) { |
187 extension_data->SetBoolean("enable_show_button", true); | 188 extension_data->SetBoolean("enable_show_button", true); |
188 } | 189 } |
189 | 190 |
190 // Add views | 191 // Add views |
(...skipping 30 matching lines...) Expand all Loading... |
221 ListValue* warnings_list = new ListValue; | 222 ListValue* warnings_list = new ListValue; |
222 for (std::vector<std::string>::const_iterator iter = warnings.begin(); | 223 for (std::vector<std::string>::const_iterator iter = warnings.begin(); |
223 iter != warnings.end(); ++iter) { | 224 iter != warnings.end(); ++iter) { |
224 warnings_list->Append(Value::CreateStringValue(*iter)); | 225 warnings_list->Append(Value::CreateStringValue(*iter)); |
225 } | 226 } |
226 extension_data->Set("warnings", warnings_list); | 227 extension_data->Set("warnings", warnings_list); |
227 } | 228 } |
228 } | 229 } |
229 | 230 |
230 // Add install warnings (these are not the same as warnings!). | 231 // Add install warnings (these are not the same as warnings!). |
231 if (extension->location() == Extension::LOAD) { | 232 if (extension->location() == Manifest::LOAD) { |
232 const Extension::InstallWarningVector& install_warnings = | 233 const std::vector<extensions::InstallWarning>& install_warnings = |
233 extension->install_warnings(); | 234 extension->install_warnings(); |
234 if (!install_warnings.empty()) { | 235 if (!install_warnings.empty()) { |
235 scoped_ptr<ListValue> list(new ListValue()); | 236 scoped_ptr<ListValue> list(new ListValue()); |
236 for (Extension::InstallWarningVector::const_iterator it = | 237 for (std::vector<extensions::InstallWarning>::const_iterator it = |
237 install_warnings.begin(); it != install_warnings.end(); ++it) { | 238 install_warnings.begin(); it != install_warnings.end(); ++it) { |
238 DictionaryValue* item = new DictionaryValue(); | 239 DictionaryValue* item = new DictionaryValue(); |
239 item->SetBoolean("isHTML", | 240 item->SetBoolean("isHTML", |
240 it->format == Extension::InstallWarning::FORMAT_HTML); | 241 it->format == extensions::InstallWarning::FORMAT_HTML); |
241 item->SetString("message", it->message); | 242 item->SetString("message", it->message); |
242 list->Append(item); | 243 list->Append(item); |
243 } | 244 } |
244 extension_data->Set("installWarnings", list.release()); | 245 extension_data->Set("installWarnings", list.release()); |
245 } | 246 } |
246 } | 247 } |
247 | 248 |
248 return extension_data; | 249 return extension_data; |
249 } | 250 } |
250 | 251 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 500 |
500 void ExtensionSettingsHandler::ExtensionWarningsChanged() { | 501 void ExtensionSettingsHandler::ExtensionWarningsChanged() { |
501 MaybeUpdateAfterNotification(); | 502 MaybeUpdateAfterNotification(); |
502 } | 503 } |
503 | 504 |
504 void ExtensionSettingsHandler::ReloadUnpackedExtensions() { | 505 void ExtensionSettingsHandler::ReloadUnpackedExtensions() { |
505 const ExtensionSet* extensions = extension_service_->extensions(); | 506 const ExtensionSet* extensions = extension_service_->extensions(); |
506 std::vector<const Extension*> unpacked_extensions; | 507 std::vector<const Extension*> unpacked_extensions; |
507 for (ExtensionSet::const_iterator extension = extensions->begin(); | 508 for (ExtensionSet::const_iterator extension = extensions->begin(); |
508 extension != extensions->end(); ++extension) { | 509 extension != extensions->end(); ++extension) { |
509 if ((*extension)->location() == Extension::LOAD) | 510 if ((*extension)->location() == Manifest::LOAD) |
510 unpacked_extensions.push_back(*extension); | 511 unpacked_extensions.push_back(*extension); |
511 } | 512 } |
512 | 513 |
513 for (std::vector<const Extension*>::iterator iter = | 514 for (std::vector<const Extension*>::iterator iter = |
514 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 515 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
515 extension_service_->ReloadExtension((*iter)->id()); | 516 extension_service_->ReloadExtension((*iter)->id()); |
516 } | 517 } |
517 } | 518 } |
518 | 519 |
519 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 520 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 std::vector<std::string> requirement_errors) { | 1008 std::vector<std::string> requirement_errors) { |
1008 if (requirement_errors.empty()) { | 1009 if (requirement_errors.empty()) { |
1009 extension_service_->EnableExtension(extension_id); | 1010 extension_service_->EnableExtension(extension_id); |
1010 } else { | 1011 } else { |
1011 ExtensionErrorReporter::GetInstance()->ReportError( | 1012 ExtensionErrorReporter::GetInstance()->ReportError( |
1012 UTF8ToUTF16(JoinString(requirement_errors, ' ')), | 1013 UTF8ToUTF16(JoinString(requirement_errors, ' ')), |
1013 true /* be noisy */); | 1014 true /* be noisy */); |
1014 } | 1015 } |
1015 requirements_checker_.reset(); | 1016 requirements_checker_.reset(); |
1016 } | 1017 } |
OLD | NEW |