Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 8493017: Cleanup extension permissions module. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "chrome/browser/extensions/extension_processes_api.h" 51 #include "chrome/browser/extensions/extension_processes_api.h"
52 #include "chrome/browser/extensions/extension_special_storage_policy.h" 52 #include "chrome/browser/extensions/extension_special_storage_policy.h"
53 #include "chrome/browser/extensions/extension_sync_data.h" 53 #include "chrome/browser/extensions/extension_sync_data.h"
54 #include "chrome/browser/extensions/extension_updater.h" 54 #include "chrome/browser/extensions/extension_updater.h"
55 #include "chrome/browser/extensions/extension_web_ui.h" 55 #include "chrome/browser/extensions/extension_web_ui.h"
56 #include "chrome/browser/extensions/extension_webnavigation_api.h" 56 #include "chrome/browser/extensions/extension_webnavigation_api.h"
57 #include "chrome/browser/extensions/external_extension_provider_impl.h" 57 #include "chrome/browser/extensions/external_extension_provider_impl.h"
58 #include "chrome/browser/extensions/external_extension_provider_interface.h" 58 #include "chrome/browser/extensions/external_extension_provider_interface.h"
59 #include "chrome/browser/extensions/installed_loader.h" 59 #include "chrome/browser/extensions/installed_loader.h"
60 #include "chrome/browser/extensions/pending_extension_manager.h" 60 #include "chrome/browser/extensions/pending_extension_manager.h"
61 #include "chrome/browser/extensions/permissions_updater.h"
61 #include "chrome/browser/extensions/settings/settings_frontend.h" 62 #include "chrome/browser/extensions/settings/settings_frontend.h"
62 #include "chrome/browser/extensions/unpacked_installer.h" 63 #include "chrome/browser/extensions/unpacked_installer.h"
63 #include "chrome/browser/history/history_extension_api.h" 64 #include "chrome/browser/history/history_extension_api.h"
64 #include "chrome/browser/net/chrome_url_request_context.h" 65 #include "chrome/browser/net/chrome_url_request_context.h"
65 #include "chrome/browser/prefs/pref_service.h" 66 #include "chrome/browser/prefs/pref_service.h"
66 #include "chrome/browser/profiles/profile.h" 67 #include "chrome/browser/profiles/profile.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"
70 #include "chrome/browser/themes/theme_service.h" 71 #include "chrome/browser/themes/theme_service.h"
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 extension_prefs_(extension_prefs), 382 extension_prefs_(extension_prefs),
382 settings_frontend_(extensions::SettingsFrontend::Create(profile)), 383 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
383 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), 384 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
384 install_directory_(install_directory), 385 install_directory_(install_directory),
385 extensions_enabled_(extensions_enabled), 386 extensions_enabled_(extensions_enabled),
386 show_extensions_prompts_(true), 387 show_extensions_prompts_(true),
387 ready_(false), 388 ready_(false),
388 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 389 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
389 menu_manager_(profile), 390 menu_manager_(profile),
390 app_notification_manager_(new AppNotificationManager(profile)), 391 app_notification_manager_(new AppNotificationManager(profile)),
391 permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
392 apps_promo_(profile->GetPrefs()), 392 apps_promo_(profile->GetPrefs()),
393 event_routers_initialized_(false), 393 event_routers_initialized_(false),
394 extension_warnings_(profile), 394 extension_warnings_(profile),
395 socket_controller_(new extensions::SocketController()), 395 socket_controller_(new extensions::SocketController()),
396 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 396 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
397 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 397 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
398 398
399 // Figure out if extension installation should be enabled. 399 // Figure out if extension installation should be enabled.
400 if (command_line->HasSwitch(switches::kDisableExtensions)) { 400 if (command_line->HasSwitch(switches::kDisableExtensions)) {
401 extensions_enabled_ = false; 401 extensions_enabled_ = false;
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 855
856 SyncExtensionChangeIfNeeded(*extension); 856 SyncExtensionChangeIfNeeded(*extension);
857 857
858 // Deactivating one extension might have solved the problems of others. 858 // Deactivating one extension might have solved the problems of others.
859 // Therefore, we clear warnings of this type for all extensions. 859 // Therefore, we clear warnings of this type for all extensions.
860 std::set<ExtensionWarningSet::WarningType> warnings; 860 std::set<ExtensionWarningSet::WarningType> warnings;
861 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); 861 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
862 extension_warnings_.ClearWarnings(warnings); 862 extension_warnings_.ClearWarnings(warnings);
863 } 863 }
864 864
865 void ExtensionService::GrantPermissions(const Extension* extension) {
866 CHECK(extension);
867
868 // We only maintain the granted permissions prefs for extensions that can't
869 // silently increase their permissions.
870 if (extension->CanSilentlyIncreasePermissions())
871 return;
872
873 extension_prefs_->AddGrantedPermissions(extension->id(),
874 extension->GetActivePermissions());
875 }
876
877 void ExtensionService::GrantPermissionsAndEnableExtension( 865 void ExtensionService::GrantPermissionsAndEnableExtension(
878 const Extension* extension) { 866 const Extension* extension) {
879 CHECK(extension); 867 CHECK(extension);
880 RecordPermissionMessagesHistogram( 868 RecordPermissionMessagesHistogram(
881 extension, "Extensions.Permissions_ReEnable"); 869 extension, "Extensions.Permissions_ReEnable");
882 GrantPermissions(extension); 870 extensions::PermissionsUpdater perms_updater(profile());
871 perms_updater.GrantActivePermissions(extension);
883 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); 872 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
884 EnableExtension(extension->id()); 873 EnableExtension(extension->id());
885 } 874 }
886 875
887 void ExtensionService::UpdateActivePermissions(
888 const Extension* extension,
889 const ExtensionPermissionSet* permissions) {
890 extension_prefs()->SetActivePermissions(extension->id(), permissions);
891 extension->SetActivePermissions(permissions);
892 }
893
894 // static 876 // static
895 void ExtensionService::RecordPermissionMessagesHistogram( 877 void ExtensionService::RecordPermissionMessagesHistogram(
896 const Extension* e, const char* histogram) { 878 const Extension* e, const char* histogram) {
897 // Since this is called from multiple sources, and since the Histogram macros 879 // Since this is called from multiple sources, and since the Histogram macros
898 // use statics, we need to manually lookup the Histogram ourselves. 880 // use statics, we need to manually lookup the Histogram ourselves.
899 base::Histogram* counter = base::LinearHistogram::FactoryGet( 881 base::Histogram* counter = base::LinearHistogram::FactoryGet(
900 histogram, 882 histogram,
901 1, 883 1,
902 ExtensionPermissionMessage::kEnumBoundary, 884 ExtensionPermissionMessage::kEnumBoundary,
903 ExtensionPermissionMessage::kEnumBoundary + 1, 885 ExtensionPermissionMessage::kEnumBoundary + 1,
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 1922
1941 // Make sure the active permissions contain no more than optional + default. 1923 // Make sure the active permissions contain no more than optional + default.
1942 scoped_refptr<ExtensionPermissionSet> adjusted_active = 1924 scoped_refptr<ExtensionPermissionSet> adjusted_active =
1943 ExtensionPermissionSet::CreateIntersection( 1925 ExtensionPermissionSet::CreateIntersection(
1944 total_permissions.get(), active_permissions.get()); 1926 total_permissions.get(), active_permissions.get());
1945 1927
1946 // Make sure the active permissions contain the default permissions. 1928 // Make sure the active permissions contain the default permissions.
1947 adjusted_active = ExtensionPermissionSet::CreateUnion( 1929 adjusted_active = ExtensionPermissionSet::CreateUnion(
1948 extension->required_permission_set(), adjusted_active.get()); 1930 extension->required_permission_set(), adjusted_active.get());
1949 1931
1950 UpdateActivePermissions(extension, adjusted_active); 1932 extensions::PermissionsUpdater perms_updater(profile());
1933 perms_updater.UpdateActivePermissions(extension, adjusted_active);
1951 } 1934 }
1952 1935
1953 // We keep track of all permissions the user has granted each extension. 1936 // We keep track of all permissions the user has granted each extension.
1954 // This allows extensions to gracefully support backwards compatibility 1937 // This allows extensions to gracefully support backwards compatibility
1955 // by including unknown permissions in their manifests. When the user 1938 // by including unknown permissions in their manifests. When the user
1956 // installs the extension, only the recognized permissions are recorded. 1939 // installs the extension, only the recognized permissions are recorded.
1957 // When the unknown permissions become recognized (e.g., through browser 1940 // When the unknown permissions become recognized (e.g., through browser
1958 // upgrade), we can prompt the user to accept these new permissions. 1941 // upgrade), we can prompt the user to accept these new permissions.
1959 // Extensions can also silently upgrade to less permissions, and then 1942 // Extensions can also silently upgrade to less permissions, and then
1960 // silently upgrade to a version that adds these permissions back. 1943 // silently upgrade to a version that adds these permissions back.
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
2580 const ExtensionResource &resource, 2563 const ExtensionResource &resource,
2581 int index) { 2564 int index) {
2582 // If the image failed to load (e.g. if the resource being loaded was empty) 2565 // If the image failed to load (e.g. if the resource being loaded was empty)
2583 // use the standard application icon. 2566 // use the standard application icon.
2584 if (!image || image->isNull()) 2567 if (!image || image->isNull())
2585 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); 2568 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON);
2586 2569
2587 shortcut_info_.favicon = *image; 2570 shortcut_info_.favicon = *image;
2588 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); 2571 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_);
2589 } 2572 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698