| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "chrome/browser/extensions/extension_processes_api.h" | 50 #include "chrome/browser/extensions/extension_processes_api.h" |
| 51 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 51 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 52 #include "chrome/browser/extensions/extension_sync_data.h" | 52 #include "chrome/browser/extensions/extension_sync_data.h" |
| 53 #include "chrome/browser/extensions/extension_updater.h" | 53 #include "chrome/browser/extensions/extension_updater.h" |
| 54 #include "chrome/browser/extensions/extension_web_ui.h" | 54 #include "chrome/browser/extensions/extension_web_ui.h" |
| 55 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 55 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
| 56 #include "chrome/browser/extensions/external_extension_provider_impl.h" | 56 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
| 57 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 57 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
| 58 #include "chrome/browser/extensions/installed_loader.h" | 58 #include "chrome/browser/extensions/installed_loader.h" |
| 59 #include "chrome/browser/extensions/pending_extension_manager.h" | 59 #include "chrome/browser/extensions/pending_extension_manager.h" |
| 60 #include "chrome/browser/extensions/permissions_updater.h" |
| 60 #include "chrome/browser/extensions/settings/settings_frontend.h" | 61 #include "chrome/browser/extensions/settings/settings_frontend.h" |
| 61 #include "chrome/browser/extensions/unpacked_installer.h" | 62 #include "chrome/browser/extensions/unpacked_installer.h" |
| 62 #include "chrome/browser/history/history_extension_api.h" | 63 #include "chrome/browser/history/history_extension_api.h" |
| 63 #include "chrome/browser/net/chrome_url_request_context.h" | 64 #include "chrome/browser/net/chrome_url_request_context.h" |
| 64 #include "chrome/browser/prefs/pref_service.h" | 65 #include "chrome/browser/prefs/pref_service.h" |
| 65 #include "chrome/browser/profiles/profile.h" | 66 #include "chrome/browser/profiles/profile.h" |
| 66 #include "chrome/browser/profiles/profile_manager.h" | 67 #include "chrome/browser/profiles/profile_manager.h" |
| 67 #include "chrome/browser/search_engines/template_url_service.h" | 68 #include "chrome/browser/search_engines/template_url_service.h" |
| 68 #include "chrome/browser/search_engines/template_url_service_factory.h" | 69 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 69 #include "chrome/browser/sync/api/sync_change.h" | 70 #include "chrome/browser/sync/api/sync_change.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 extension_prefs_(extension_prefs), | 378 extension_prefs_(extension_prefs), |
| 378 settings_frontend_(extensions::SettingsFrontend::Create(profile)), | 379 settings_frontend_(extensions::SettingsFrontend::Create(profile)), |
| 379 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 380 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 380 install_directory_(install_directory), | 381 install_directory_(install_directory), |
| 381 extensions_enabled_(extensions_enabled), | 382 extensions_enabled_(extensions_enabled), |
| 382 show_extensions_prompts_(true), | 383 show_extensions_prompts_(true), |
| 383 ready_(false), | 384 ready_(false), |
| 384 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 385 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 385 menu_manager_(profile), | 386 menu_manager_(profile), |
| 386 app_notification_manager_(new AppNotificationManager(profile)), | 387 app_notification_manager_(new AppNotificationManager(profile)), |
| 387 permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
| 388 apps_promo_(profile->GetPrefs()), | 388 apps_promo_(profile->GetPrefs()), |
| 389 event_routers_initialized_(false), | 389 event_routers_initialized_(false), |
| 390 extension_warnings_(profile), | 390 extension_warnings_(profile), |
| 391 socket_controller_(NULL), | 391 socket_controller_(NULL), |
| 392 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 392 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 393 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 393 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 394 | 394 |
| 395 // Figure out if extension installation should be enabled. | 395 // Figure out if extension installation should be enabled. |
| 396 if (command_line->HasSwitch(switches::kDisableExtensions)) { | 396 if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 397 extensions_enabled_ = false; | 397 extensions_enabled_ = false; |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 | 898 |
| 899 SyncExtensionChangeIfNeeded(*extension); | 899 SyncExtensionChangeIfNeeded(*extension); |
| 900 | 900 |
| 901 // Deactivating one extension might have solved the problems of others. | 901 // Deactivating one extension might have solved the problems of others. |
| 902 // Therefore, we clear warnings of this type for all extensions. | 902 // Therefore, we clear warnings of this type for all extensions. |
| 903 std::set<ExtensionWarningSet::WarningType> warnings; | 903 std::set<ExtensionWarningSet::WarningType> warnings; |
| 904 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); | 904 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); |
| 905 extension_warnings_.ClearWarnings(warnings); | 905 extension_warnings_.ClearWarnings(warnings); |
| 906 } | 906 } |
| 907 | 907 |
| 908 void ExtensionService::GrantPermissions(const Extension* extension) { | |
| 909 CHECK(extension); | |
| 910 | |
| 911 // We only maintain the granted permissions prefs for extensions that can't | |
| 912 // silently increase their permissions. | |
| 913 if (extension->CanSilentlyIncreasePermissions()) | |
| 914 return; | |
| 915 | |
| 916 extension_prefs_->AddGrantedPermissions(extension->id(), | |
| 917 extension->GetActivePermissions()); | |
| 918 } | |
| 919 | |
| 920 void ExtensionService::GrantPermissionsAndEnableExtension( | 908 void ExtensionService::GrantPermissionsAndEnableExtension( |
| 921 const Extension* extension) { | 909 const Extension* extension) { |
| 922 CHECK(extension); | 910 CHECK(extension); |
| 923 RecordPermissionMessagesHistogram( | 911 RecordPermissionMessagesHistogram( |
| 924 extension, "Extensions.Permissions_ReEnable"); | 912 extension, "Extensions.Permissions_ReEnable"); |
| 925 GrantPermissions(extension); | 913 extensions::PermissionsUpdater perms_updater(profile()); |
| 914 perms_updater.GrantActivePermissions(extension); |
| 926 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); | 915 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 927 EnableExtension(extension->id()); | 916 EnableExtension(extension->id()); |
| 928 } | 917 } |
| 929 | 918 |
| 930 void ExtensionService::UpdateActivePermissions( | |
| 931 const Extension* extension, | |
| 932 const ExtensionPermissionSet* permissions) { | |
| 933 extension_prefs()->SetActivePermissions(extension->id(), permissions); | |
| 934 extension->SetActivePermissions(permissions); | |
| 935 } | |
| 936 | |
| 937 // static | 919 // static |
| 938 void ExtensionService::RecordPermissionMessagesHistogram( | 920 void ExtensionService::RecordPermissionMessagesHistogram( |
| 939 const Extension* e, const char* histogram) { | 921 const Extension* e, const char* histogram) { |
| 940 // Since this is called from multiple sources, and since the Histogram macros | 922 // Since this is called from multiple sources, and since the Histogram macros |
| 941 // use statics, we need to manually lookup the Histogram ourselves. | 923 // use statics, we need to manually lookup the Histogram ourselves. |
| 942 base::Histogram* counter = base::LinearHistogram::FactoryGet( | 924 base::Histogram* counter = base::LinearHistogram::FactoryGet( |
| 943 histogram, | 925 histogram, |
| 944 1, | 926 1, |
| 945 ExtensionPermissionMessage::kEnumBoundary, | 927 ExtensionPermissionMessage::kEnumBoundary, |
| 946 ExtensionPermissionMessage::kEnumBoundary + 1, | 928 ExtensionPermissionMessage::kEnumBoundary + 1, |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 | 2029 |
| 2048 // Make sure the active permissions contain no more than optional + default. | 2030 // Make sure the active permissions contain no more than optional + default. |
| 2049 scoped_refptr<ExtensionPermissionSet> adjusted_active = | 2031 scoped_refptr<ExtensionPermissionSet> adjusted_active = |
| 2050 ExtensionPermissionSet::CreateIntersection( | 2032 ExtensionPermissionSet::CreateIntersection( |
| 2051 total_permissions.get(), active_permissions.get()); | 2033 total_permissions.get(), active_permissions.get()); |
| 2052 | 2034 |
| 2053 // Make sure the active permissions contain the default permissions. | 2035 // Make sure the active permissions contain the default permissions. |
| 2054 adjusted_active = ExtensionPermissionSet::CreateUnion( | 2036 adjusted_active = ExtensionPermissionSet::CreateUnion( |
| 2055 extension->required_permission_set(), adjusted_active.get()); | 2037 extension->required_permission_set(), adjusted_active.get()); |
| 2056 | 2038 |
| 2057 UpdateActivePermissions(extension, adjusted_active); | 2039 extensions::PermissionsUpdater perms_updater(profile()); |
| 2040 perms_updater.UpdateActivePermissions(extension, adjusted_active); |
| 2058 } | 2041 } |
| 2059 | 2042 |
| 2060 // We keep track of all permissions the user has granted each extension. | 2043 // We keep track of all permissions the user has granted each extension. |
| 2061 // This allows extensions to gracefully support backwards compatibility | 2044 // This allows extensions to gracefully support backwards compatibility |
| 2062 // by including unknown permissions in their manifests. When the user | 2045 // by including unknown permissions in their manifests. When the user |
| 2063 // installs the extension, only the recognized permissions are recorded. | 2046 // installs the extension, only the recognized permissions are recorded. |
| 2064 // When the unknown permissions become recognized (e.g., through browser | 2047 // When the unknown permissions become recognized (e.g., through browser |
| 2065 // upgrade), we can prompt the user to accept these new permissions. | 2048 // upgrade), we can prompt the user to accept these new permissions. |
| 2066 // Extensions can also silently upgrade to less permissions, and then | 2049 // Extensions can also silently upgrade to less permissions, and then |
| 2067 // silently upgrade to a version that adds these permissions back. | 2050 // silently upgrade to a version that adds these permissions back. |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 // | 2643 // |
| 2661 // To coexist with certain unit tests that don't have an IO thread message | 2644 // To coexist with certain unit tests that don't have an IO thread message |
| 2662 // loop available at ExtensionService shutdown, we lazy-initialize this | 2645 // loop available at ExtensionService shutdown, we lazy-initialize this |
| 2663 // object so that those cases neither create nor destroy a SocketController. | 2646 // object so that those cases neither create nor destroy a SocketController. |
| 2664 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2647 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2665 if (!socket_controller_) { | 2648 if (!socket_controller_) { |
| 2666 socket_controller_ = new extensions::SocketController(); | 2649 socket_controller_ = new extensions::SocketController(); |
| 2667 } | 2650 } |
| 2668 return socket_controller_; | 2651 return socket_controller_; |
| 2669 } | 2652 } |
| OLD | NEW |