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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/auto_reset.h" | |
10 #include "base/bind.h" | |
11 #include "base/bind_helpers.h" | |
12 #include "base/location.h" | |
13 #include "base/message_loop/message_loop.h" | |
14 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
17 #include "base/values.h" | |
18 #include "base/version.h" | |
19 #include "chrome/browser/background/background_contents.h" | |
20 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/extensions/extension_management.h" | |
22 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/browser/extensions/extension_ui_util.h" | |
24 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/apps/app_info_dialog.h" | 15 #include "chrome/browser/ui/apps/app_info_dialog.h" |
26 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_window.h" | |
28 #include "chrome/browser/ui/extensions/app_launch_params.h" | |
29 #include "chrome/browser/ui/extensions/application_launch.h" | |
30 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" | |
31 #include "chrome/common/chrome_version_info.h" | |
32 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
34 #include "chrome/grit/chromium_strings.h" | 19 #include "chrome/grit/chromium_strings.h" |
35 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
36 #include "components/google/core/browser/google_util.h" | 21 #include "components/google/core/browser/google_util.h" |
37 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
38 #include "content/public/browser/render_process_host.h" | |
39 #include "content/public/browser/render_view_host.h" | |
40 #include "content/public/browser/site_instance.h" | |
41 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
42 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
43 #include "content/public/browser/web_ui_data_source.h" | 25 #include "content/public/browser/web_ui_data_source.h" |
44 #include "extensions/browser/api/device_permissions_manager.h" | |
45 #include "extensions/browser/blacklist_state.h" | |
46 #include "extensions/browser/extension_prefs.h" | |
47 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
48 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
49 #include "extensions/browser/management_policy.h" | |
50 #include "extensions/browser/notification_types.h" | |
51 #include "extensions/browser/pref_names.h" | |
52 #include "extensions/browser/warning_set.h" | |
53 #include "extensions/common/constants.h" | |
54 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
55 #include "extensions/common/extension_icon_set.h" | |
56 #include "extensions/common/extension_set.h" | 29 #include "extensions/common/extension_set.h" |
57 #include "extensions/common/extension_urls.h" | 30 #include "extensions/common/extension_urls.h" |
58 #include "extensions/common/manifest.h" | 31 #include "extensions/common/manifest.h" |
59 #include "extensions/common/permissions/permissions_data.h" | |
60 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
61 #include "grit/components_strings.h" | 33 #include "grit/components_strings.h" |
62 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
63 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
64 #include "url/gurl.h" | 36 #include "url/gurl.h" |
65 | 37 |
66 namespace extensions { | 38 namespace extensions { |
67 | 39 |
68 /////////////////////////////////////////////////////////////////////////////// | |
69 // | |
70 // ExtensionSettingsHandler | |
71 // | |
72 /////////////////////////////////////////////////////////////////////////////// | |
73 | |
74 ExtensionSettingsHandler::ExtensionSettingsHandler() | 40 ExtensionSettingsHandler::ExtensionSettingsHandler() |
75 : extension_service_(NULL), | 41 : extension_service_(nullptr) { |
76 warning_service_observer_(this), | |
77 extension_prefs_observer_(this), | |
78 extension_management_observer_(this) { | |
79 } | 42 } |
80 | 43 |
81 ExtensionSettingsHandler::~ExtensionSettingsHandler() { | 44 ExtensionSettingsHandler::~ExtensionSettingsHandler() { |
82 } | 45 } |
83 | 46 |
84 // static | 47 // static |
85 void ExtensionSettingsHandler::RegisterProfilePrefs( | 48 void ExtensionSettingsHandler::RegisterProfilePrefs( |
86 user_prefs::PrefRegistrySyncable* registry) { | 49 user_prefs::PrefRegistrySyncable* registry) { |
87 registry->RegisterBooleanPref( | 50 registry->RegisterBooleanPref( |
88 prefs::kExtensionsUIDeveloperMode, | 51 prefs::kExtensionsUIDeveloperMode, |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 "extensionErrorOverlayLaunchDevtools", | 233 "extensionErrorOverlayLaunchDevtools", |
271 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_LAUNCH_DEVTOOLS)); | 234 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_LAUNCH_DEVTOOLS)); |
272 source->AddString( | 235 source->AddString( |
273 "extensionErrorOverlayContextUnknown", | 236 "extensionErrorOverlayContextUnknown", |
274 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT_UNKNOWN)); | 237 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT_UNKNOWN)); |
275 source->AddString( | 238 source->AddString( |
276 "extensionErrorOverlayNoCodeToDisplay", | 239 "extensionErrorOverlayNoCodeToDisplay", |
277 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_CODE_TO_DISPLAY)); | 240 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_CODE_TO_DISPLAY)); |
278 } | 241 } |
279 | 242 |
280 void ExtensionSettingsHandler::RenderViewDeleted( | |
281 content::RenderViewHost* render_view_host) { | |
282 Profile* source_profile = Profile::FromBrowserContext( | |
283 render_view_host->GetSiteInstance()->GetBrowserContext()); | |
284 if (!Profile::FromWebUI(web_ui())->IsSameProfile(source_profile)) | |
285 return; | |
286 MaybeUpdateAfterNotification(); | |
287 } | |
288 | |
289 void ExtensionSettingsHandler::DidStartNavigationToPendingEntry( | 243 void ExtensionSettingsHandler::DidStartNavigationToPendingEntry( |
290 const GURL& url, | 244 const GURL& url, |
291 content::NavigationController::ReloadType reload_type) { | 245 content::NavigationController::ReloadType reload_type) { |
292 if (reload_type != content::NavigationController::NO_RELOAD) | 246 if (reload_type != content::NavigationController::NO_RELOAD) |
293 ReloadUnpackedExtensions(); | 247 ReloadUnpackedExtensions(); |
294 } | 248 } |
295 | 249 |
296 void ExtensionSettingsHandler::RegisterMessages() { | 250 void ExtensionSettingsHandler::RegisterMessages() { |
297 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); | 251 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile(); |
298 extension_service_ = | 252 extension_service_ = |
299 extensions::ExtensionSystem::Get(profile)->extension_service(); | 253 extensions::ExtensionSystem::Get(profile)->extension_service(); |
300 | 254 // Clear the preference for the ADT Promo before fully removing it. |
301 web_ui()->RegisterMessageCallback("extensionSettingsRegister", | 255 // TODO(devlin): Take this out when everyone's been updated. |
302 base::Bind(&ExtensionSettingsHandler::HandleRegisterMessage, | 256 Profile::FromWebUI(web_ui())->GetPrefs()->ClearPref( |
303 AsWeakPtr())); | 257 prefs::kExtensionsUIDismissedADTPromo); |
304 } | |
305 | |
306 void ExtensionSettingsHandler::OnExtensionDisableReasonsChanged( | |
307 const std::string& extension_id, int disable_reasons) { | |
308 MaybeUpdateAfterNotification(); | |
309 } | |
310 | |
311 void ExtensionSettingsHandler::OnExtensionManagementSettingsChanged() { | |
312 MaybeUpdateAfterNotification(); | |
313 } | |
314 | |
315 void ExtensionSettingsHandler::ExtensionWarningsChanged() { | |
316 MaybeUpdateAfterNotification(); | |
317 } | 258 } |
318 | 259 |
319 void ExtensionSettingsHandler::ReloadUnpackedExtensions() { | 260 void ExtensionSettingsHandler::ReloadUnpackedExtensions() { |
320 ExtensionRegistry* registry = | 261 ExtensionRegistry* registry = |
321 ExtensionRegistry::Get(extension_service_->profile()); | 262 ExtensionRegistry::Get(extension_service_->profile()); |
322 std::vector<const Extension*> unpacked_extensions; | 263 std::vector<const Extension*> unpacked_extensions; |
323 for (const scoped_refptr<const extensions::Extension>& extension : | 264 for (const scoped_refptr<const extensions::Extension>& extension : |
324 registry->enabled_extensions()) { | 265 registry->enabled_extensions()) { |
325 if (Manifest::IsUnpackedLocation(extension->location())) | 266 if (Manifest::IsUnpackedLocation(extension->location())) |
326 unpacked_extensions.push_back(extension.get()); | 267 unpacked_extensions.push_back(extension.get()); |
327 } | 268 } |
328 | 269 |
329 for (std::vector<const Extension*>::iterator iter = | 270 for (std::vector<const Extension*>::iterator iter = |
330 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 271 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
331 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); | 272 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id()); |
332 } | 273 } |
333 } | 274 } |
334 | 275 |
335 void ExtensionSettingsHandler::HandleRegisterMessage( | |
336 const base::ListValue* args) { | |
337 if (content::WebContentsObserver::web_contents()) | |
338 return; // Only register once. | |
339 | |
340 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); | |
341 | |
342 Profile* profile = Profile::FromWebUI(web_ui()); | |
343 warning_service_observer_.Add(WarningService::Get(profile)); | |
344 extension_management_observer_.Add( | |
345 ExtensionManagementFactory::GetForBrowserContext(profile)); | |
346 | |
347 // Clear the preference for the ADT Promo before fully removing it. | |
348 // TODO(devlin): Take this out when everyone's been updated. | |
349 profile->GetPrefs()->ClearPref(prefs::kExtensionsUIDismissedADTPromo); | |
350 } | |
351 | |
352 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { | |
353 content::WebContents* contents = web_ui()->GetWebContents(); | |
354 if (contents && contents->GetRenderViewHost()) { | |
355 web_ui()->CallJavascriptFunction( | |
356 "extensions.ExtensionSettings.onExtensionsChanged"); | |
357 } | |
358 } | |
359 | |
360 } // namespace extensions | 276 } // namespace extensions |
OLD | NEW |