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/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 #include "content/public/browser/notification_service.h" | 99 #include "content/public/browser/notification_service.h" |
100 #include "content/public/browser/notification_types.h" | 100 #include "content/public/browser/notification_types.h" |
101 #include "content/public/browser/plugin_service.h" | 101 #include "content/public/browser/plugin_service.h" |
102 #include "content/public/browser/render_process_host.h" | 102 #include "content/public/browser/render_process_host.h" |
103 #include "content/public/common/pepper_plugin_info.h" | 103 #include "content/public/common/pepper_plugin_info.h" |
104 #include "googleurl/src/gurl.h" | 104 #include "googleurl/src/gurl.h" |
105 #include "grit/generated_resources.h" | 105 #include "grit/generated_resources.h" |
106 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 106 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
107 #include "sync/api/sync_change.h" | 107 #include "sync/api/sync_change.h" |
108 #include "sync/api/sync_error_factory.h" | 108 #include "sync/api/sync_error_factory.h" |
109 #include "ui/base/l10n/l10n_util.h" | |
110 #include "webkit/database/database_tracker.h" | 109 #include "webkit/database/database_tracker.h" |
111 #include "webkit/database/database_util.h" | 110 #include "webkit/database/database_util.h" |
112 | 111 |
113 #if defined(OS_CHROMEOS) | 112 #if defined(OS_CHROMEOS) |
114 #include "chrome/browser/chromeos/cros/cros_library.h" | 113 #include "chrome/browser/chromeos/cros/cros_library.h" |
115 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" | 114 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" |
116 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 115 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
117 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 116 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
118 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" | 117 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
119 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 118 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
120 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" | 119 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
121 #include "webkit/fileapi/file_system_context.h" | 120 #include "webkit/fileapi/file_system_context.h" |
122 #include "webkit/fileapi/file_system_mount_point_provider.h" | 121 #include "webkit/fileapi/file_system_mount_point_provider.h" |
123 #endif | 122 #endif |
124 | 123 |
125 using base::Time; | |
126 using content::BrowserContext; | 124 using content::BrowserContext; |
127 using content::BrowserThread; | 125 using content::BrowserThread; |
128 using content::DevToolsAgentHost; | 126 using content::DevToolsAgentHost; |
129 using content::DevToolsAgentHostRegistry; | 127 using content::DevToolsAgentHostRegistry; |
130 using content::PluginService; | 128 using content::PluginService; |
131 using extensions::CrxInstaller; | 129 using extensions::CrxInstaller; |
132 using extensions::Extension; | 130 using extensions::Extension; |
133 using extensions::ExtensionIdSet; | 131 using extensions::ExtensionIdSet; |
134 using extensions::ExtensionInfo; | 132 using extensions::ExtensionInfo; |
135 using extensions::UnloadedExtensionInfo; | 133 using extensions::UnloadedExtensionInfo; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // source. In this case, signal that this extension will not be | 252 // source. In this case, signal that this extension will not be |
255 // installed by returning false. | 253 // installed by returning false. |
256 if (!pending_extension_manager()->AddFromExternalUpdateUrl( | 254 if (!pending_extension_manager()->AddFromExternalUpdateUrl( |
257 id, update_url, location)) | 255 id, update_url, location)) |
258 return false; | 256 return false; |
259 | 257 |
260 update_once_all_providers_are_ready_ = true; | 258 update_once_all_providers_are_ready_ = true; |
261 return true; | 259 return true; |
262 } | 260 } |
263 | 261 |
264 const Extension* ExtensionService::GetInstalledApp(const GURL& url) { | 262 const Extension* ExtensionService::GetInstalledApp(const GURL& url) const { |
265 const Extension* extension = extensions_.GetExtensionOrAppByURL( | 263 const Extension* extension = extensions_.GetExtensionOrAppByURL( |
266 ExtensionURLInfo(url)); | 264 ExtensionURLInfo(url)); |
267 if (extension && extension->is_app()) | 265 return (extension && extension->is_app()) ? extension : NULL; |
268 return extension; | |
269 | |
270 return NULL; | |
271 } | 266 } |
272 | 267 |
273 bool ExtensionService::IsInstalledApp(const GURL& url) { | 268 bool ExtensionService::IsInstalledApp(const GURL& url) const { |
274 return !!GetInstalledApp(url); | 269 return !!GetInstalledApp(url); |
275 } | 270 } |
276 | 271 |
277 void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id, | 272 void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id, |
278 const Extension* app) { | 273 const Extension* app) { |
279 installed_app_hosts_[renderer_child_id] = app; | 274 installed_app_hosts_[renderer_child_id] = app; |
280 } | 275 } |
281 | 276 |
282 const Extension* ExtensionService::GetInstalledAppForRenderer( | 277 const Extension* ExtensionService::GetInstalledAppForRenderer( |
283 int renderer_child_id) { | 278 int renderer_child_id) const { |
284 InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id); | 279 InstalledAppMap::const_iterator i = |
285 if (i == installed_app_hosts_.end()) | 280 installed_app_hosts_.find(renderer_child_id); |
286 return NULL; | 281 return i == installed_app_hosts_.end() ? NULL : i->second; |
287 return i->second; | |
288 } | 282 } |
289 | 283 |
290 // static | 284 // static |
291 // This function is used to implement the command-line switch | 285 // This function is used to implement the command-line switch |
292 // --uninstall-extension, and to uninstall an extension via sync. The LOG | 286 // --uninstall-extension, and to uninstall an extension via sync. The LOG |
293 // statements within this function are used to inform the user if the uninstall | 287 // statements within this function are used to inform the user if the uninstall |
294 // cannot be done. | 288 // cannot be done. |
295 bool ExtensionService::UninstallExtensionHelper( | 289 bool ExtensionService::UninstallExtensionHelper( |
296 ExtensionService* extensions_service, | 290 ExtensionService* extensions_service, |
297 const std::string& extension_id) { | 291 const std::string& extension_id) { |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 std::set<ExtensionWarningSet::WarningType> warnings; | 796 std::set<ExtensionWarningSet::WarningType> warnings; |
803 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); | 797 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); |
804 extension_warnings_.ClearWarnings(warnings); | 798 extension_warnings_.ClearWarnings(warnings); |
805 | 799 |
806 return true; | 800 return true; |
807 } | 801 } |
808 | 802 |
809 bool ExtensionService::IsExtensionEnabled( | 803 bool ExtensionService::IsExtensionEnabled( |
810 const std::string& extension_id) const { | 804 const std::string& extension_id) const { |
811 if (extensions_.Contains(extension_id) || | 805 if (extensions_.Contains(extension_id) || |
812 terminated_extensions_.Contains(extension_id)) | 806 terminated_extensions_.Contains(extension_id)) { |
813 return true; | 807 return true; |
| 808 } |
814 | 809 |
815 if (disabled_extensions_.Contains(extension_id)) | 810 if (disabled_extensions_.Contains(extension_id)) |
816 return false; | 811 return false; |
817 | 812 |
818 // If the extension hasn't been loaded yet, check the prefs for it. Assume | 813 // If the extension hasn't been loaded yet, check the prefs for it. Assume |
819 // enabled unless otherwise noted. | 814 // enabled unless otherwise noted. |
820 return !extension_prefs_->IsExtensionDisabled(extension_id) && | 815 return !extension_prefs_->IsExtensionDisabled(extension_id) && |
821 !extension_prefs_->IsExternalExtensionUninstalled(extension_id); | 816 !extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
822 } | 817 } |
823 | 818 |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 return; | 1572 return; |
1578 } | 1573 } |
1579 if (value) | 1574 if (value) |
1580 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsDisabled", 1); | 1575 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsDisabled", 1); |
1581 else | 1576 else |
1582 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsEnabled", 1); | 1577 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsEnabled", 1); |
1583 extension_prefs_->SetAppNotificationDisabled(extension_id, value); | 1578 extension_prefs_->SetAppNotificationDisabled(extension_id, value); |
1584 SyncExtensionChangeIfNeeded(*extension); | 1579 SyncExtensionChangeIfNeeded(*extension); |
1585 } | 1580 } |
1586 | 1581 |
1587 bool ExtensionService::CanCrossIncognito(const Extension* extension) { | 1582 bool ExtensionService::CanCrossIncognito(const Extension* extension) const { |
1588 // We allow the extension to see events and data from another profile iff it | 1583 // We allow the extension to see events and data from another profile iff it |
1589 // uses "spanning" behavior and it has incognito access. "split" mode | 1584 // uses "spanning" behavior and it has incognito access. "split" mode |
1590 // extensions only see events for a matching profile. | 1585 // extensions only see events for a matching profile. |
1591 CHECK(extension); | 1586 CHECK(extension); |
1592 return IsIncognitoEnabled(extension->id()) && | 1587 return IsIncognitoEnabled(extension->id()) && |
1593 !extension->incognito_split_mode(); | 1588 !extension->incognito_split_mode(); |
1594 } | 1589 } |
1595 | 1590 |
1596 bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { | 1591 bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { |
1597 if (extension->is_hosted_app()) | 1592 if (extension->is_hosted_app()) |
(...skipping 11 matching lines...) Expand all Loading... |
1609 extension_prefs_->extension_sorting()->OnExtensionMoved( | 1604 extension_prefs_->extension_sorting()->OnExtensionMoved( |
1610 moved_extension_id, | 1605 moved_extension_id, |
1611 predecessor_extension_id, | 1606 predecessor_extension_id, |
1612 successor_extension_id); | 1607 successor_extension_id); |
1613 | 1608 |
1614 const Extension* extension = GetInstalledExtension(moved_extension_id); | 1609 const Extension* extension = GetInstalledExtension(moved_extension_id); |
1615 if (extension) | 1610 if (extension) |
1616 SyncExtensionChangeIfNeeded(*extension); | 1611 SyncExtensionChangeIfNeeded(*extension); |
1617 } | 1612 } |
1618 | 1613 |
1619 bool ExtensionService::AllowFileAccess(const Extension* extension) { | 1614 bool ExtensionService::AllowFileAccess(const Extension* extension) const { |
1620 return (CommandLine::ForCurrentProcess()->HasSwitch( | 1615 return (CommandLine::ForCurrentProcess()->HasSwitch( |
1621 switches::kDisableExtensionsFileAccessCheck) || | 1616 switches::kDisableExtensionsFileAccessCheck) || |
1622 extension_prefs_->AllowFileAccess(extension->id())); | 1617 extension_prefs_->AllowFileAccess(extension->id())); |
1623 } | 1618 } |
1624 | 1619 |
1625 void ExtensionService::SetAllowFileAccess(const Extension* extension, | 1620 void ExtensionService::SetAllowFileAccess(const Extension* extension, |
1626 bool allow) { | 1621 bool allow) { |
1627 // Reload to update browser state. Only bother if the value changed and the | 1622 // Reload to update browser state. Only bother if the value changed and the |
1628 // extension is actually enabled, since there is no UI otherwise. | 1623 // extension is actually enabled, since there is no UI otherwise. |
1629 bool old_allow = AllowFileAccess(extension); | 1624 bool old_allow = AllowFileAccess(extension); |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2458 ExtensionIdSet result; | 2453 ExtensionIdSet result; |
2459 for (ExtensionSet::const_iterator it = extensions_.begin(); | 2454 for (ExtensionSet::const_iterator it = extensions_.begin(); |
2460 it != extensions_.end(); ++it) { | 2455 it != extensions_.end(); ++it) { |
2461 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) | 2456 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) |
2462 result.insert((*it)->id()); | 2457 result.insert((*it)->id()); |
2463 } | 2458 } |
2464 | 2459 |
2465 return result; | 2460 return result; |
2466 } | 2461 } |
2467 | 2462 |
2468 bool ExtensionService::IsBackgroundPageReady(const Extension* extension) { | 2463 bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const { |
2469 return (!extension->has_persistent_background_page() || | 2464 if (!extension->has_persistent_background_page()) |
2470 extension_runtime_data_[extension->id()].background_page_ready); | 2465 return true; |
| 2466 ExtensionRuntimeDataMap::const_iterator it = |
| 2467 extension_runtime_data_.find(extension->id()); |
| 2468 return it == extension_runtime_data_.end() ? false : |
| 2469 it->second.background_page_ready; |
2471 } | 2470 } |
2472 | 2471 |
2473 void ExtensionService::SetBackgroundPageReady(const Extension* extension) { | 2472 void ExtensionService::SetBackgroundPageReady(const Extension* extension) { |
2474 DCHECK(extension->has_background_page()); | 2473 DCHECK(extension->has_background_page()); |
2475 extension_runtime_data_[extension->id()].background_page_ready = true; | 2474 extension_runtime_data_[extension->id()].background_page_ready = true; |
2476 content::NotificationService::current()->Notify( | 2475 content::NotificationService::current()->Notify( |
2477 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, | 2476 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
2478 content::Source<const Extension>(extension), | 2477 content::Source<const Extension>(extension), |
2479 content::NotificationService::NoDetails()); | 2478 content::NotificationService::NoDetails()); |
2480 } | 2479 } |
2481 | 2480 |
2482 bool ExtensionService::IsBeingUpgraded(const Extension* extension) { | 2481 bool ExtensionService::IsBeingUpgraded(const Extension* extension) const { |
2483 return extension_runtime_data_[extension->id()].being_upgraded; | 2482 ExtensionRuntimeDataMap::const_iterator it = |
| 2483 extension_runtime_data_.find(extension->id()); |
| 2484 return it == extension_runtime_data_.end() ? false : |
| 2485 it->second.being_upgraded; |
2484 } | 2486 } |
2485 | 2487 |
2486 void ExtensionService::SetBeingUpgraded(const Extension* extension, | 2488 void ExtensionService::SetBeingUpgraded(const Extension* extension, |
2487 bool value) { | 2489 bool value) { |
2488 extension_runtime_data_[extension->id()].being_upgraded = value; | 2490 extension_runtime_data_[extension->id()].being_upgraded = value; |
2489 } | 2491 } |
2490 | 2492 |
2491 bool ExtensionService::HasUsedWebRequest(const Extension* extension) { | 2493 bool ExtensionService::HasUsedWebRequest(const Extension* extension) const { |
2492 return extension_runtime_data_[extension->id()].has_used_webrequest; | 2494 ExtensionRuntimeDataMap::const_iterator it = |
| 2495 extension_runtime_data_.find(extension->id()); |
| 2496 return it == extension_runtime_data_.end() ? false : |
| 2497 it->second.has_used_webrequest; |
2493 } | 2498 } |
2494 | 2499 |
2495 void ExtensionService::SetHasUsedWebRequest(const Extension* extension, | 2500 void ExtensionService::SetHasUsedWebRequest(const Extension* extension, |
2496 bool value) { | 2501 bool value) { |
2497 extension_runtime_data_[extension->id()].has_used_webrequest = value; | 2502 extension_runtime_data_[extension->id()].has_used_webrequest = value; |
2498 } | 2503 } |
2499 | 2504 |
2500 base::PropertyBag* ExtensionService::GetPropertyBag( | 2505 base::PropertyBag* ExtensionService::GetPropertyBag( |
2501 const Extension* extension) { | 2506 const Extension* extension) { |
2502 return &extension_runtime_data_[extension->id()].property_bag; | 2507 return &extension_runtime_data_[extension->id()].property_bag; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2568 | 2573 |
2569 ExtensionService::NaClModuleInfoList::iterator | 2574 ExtensionService::NaClModuleInfoList::iterator |
2570 ExtensionService::FindNaClModule(const GURL& url) { | 2575 ExtensionService::FindNaClModule(const GURL& url) { |
2571 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2576 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
2572 iter != nacl_module_list_.end(); ++iter) { | 2577 iter != nacl_module_list_.end(); ++iter) { |
2573 if (iter->url == url) | 2578 if (iter->url == url) |
2574 return iter; | 2579 return iter; |
2575 } | 2580 } |
2576 return nacl_module_list_.end(); | 2581 return nacl_module_list_.end(); |
2577 } | 2582 } |
OLD | NEW |