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

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

Issue 10630021: Modify experimental identity flow to display scope descriptions and details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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) 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/permissions_updater.h" 5 #include "chrome/browser/extensions/permissions_updater.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" 10 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h"
11 #include "chrome/browser/extensions/extension_event_router.h" 11 #include "chrome/browser/extensions/extension_event_router.h"
12 #include "chrome/browser/extensions/extension_prefs.h" 12 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/signin/token_service.h"
16 #include "chrome/browser/signin/token_service_factory.h"
15 #include "chrome/common/extensions/api/permissions.h" 17 #include "chrome/common/extensions/api/permissions.h"
16 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_messages.h" 20 #include "chrome/common/extensions/extension_messages.h"
19 #include "chrome/common/extensions/extension_permission_set.h" 21 #include "chrome/common/extensions/extension_permission_set.h"
22 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h"
20 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
22 25
23 using content::RenderProcessHost; 26 using content::RenderProcessHost;
24 using extensions::permissions_api_helpers::PackPermissionSet; 27 using extensions::permissions_api_helpers::PackPermissionSet;
25 28
26 namespace extensions { 29 namespace extensions {
27 30
28 namespace { 31 namespace {
29 32
(...skipping 12 matching lines...) Expand all
42 scoped_refptr<const ExtensionPermissionSet> existing( 45 scoped_refptr<const ExtensionPermissionSet> existing(
43 extension->GetActivePermissions()); 46 extension->GetActivePermissions());
44 scoped_refptr<ExtensionPermissionSet> total( 47 scoped_refptr<ExtensionPermissionSet> total(
45 ExtensionPermissionSet::CreateUnion(existing, permissions)); 48 ExtensionPermissionSet::CreateUnion(existing, permissions));
46 scoped_refptr<ExtensionPermissionSet> added( 49 scoped_refptr<ExtensionPermissionSet> added(
47 ExtensionPermissionSet::CreateDifference(total.get(), existing)); 50 ExtensionPermissionSet::CreateDifference(total.get(), existing));
48 51
49 UpdateActivePermissions(extension, total.get()); 52 UpdateActivePermissions(extension, total.get());
50 53
51 // Update the granted permissions so we don't auto-disable the extension. 54 // Update the granted permissions so we don't auto-disable the extension.
52 GrantActivePermissions(extension); 55 GrantActivePermissions(extension, false);
53 56
54 NotifyPermissionsUpdated(ADDED, extension, added.get()); 57 NotifyPermissionsUpdated(ADDED, extension, added.get());
55 } 58 }
56 59
57 void PermissionsUpdater::RemovePermissions( 60 void PermissionsUpdater::RemovePermissions(
58 const Extension* extension, const ExtensionPermissionSet* permissions) { 61 const Extension* extension, const ExtensionPermissionSet* permissions) {
59 scoped_refptr<const ExtensionPermissionSet> existing( 62 scoped_refptr<const ExtensionPermissionSet> existing(
60 extension->GetActivePermissions()); 63 extension->GetActivePermissions());
61 scoped_refptr<ExtensionPermissionSet> total( 64 scoped_refptr<ExtensionPermissionSet> total(
62 ExtensionPermissionSet::CreateDifference(existing, permissions)); 65 ExtensionPermissionSet::CreateDifference(existing, permissions));
63 scoped_refptr<ExtensionPermissionSet> removed( 66 scoped_refptr<ExtensionPermissionSet> removed(
64 ExtensionPermissionSet::CreateDifference(existing, total.get())); 67 ExtensionPermissionSet::CreateDifference(existing, total.get()));
65 68
66 // We update the active permissions, and not the granted permissions, because 69 // We update the active permissions, and not the granted permissions, because
67 // the extension, not the user, removed the permissions. This allows the 70 // the extension, not the user, removed the permissions. This allows the
68 // extension to add them again without prompting the user. 71 // extension to add them again without prompting the user.
69 UpdateActivePermissions(extension, total.get()); 72 UpdateActivePermissions(extension, total.get());
70 73
71 NotifyPermissionsUpdated(REMOVED, extension, removed.get()); 74 NotifyPermissionsUpdated(REMOVED, extension, removed.get());
72 } 75 }
73 76
74 void PermissionsUpdater::GrantActivePermissions(const Extension* extension) { 77 void PermissionsUpdater::GrantActivePermissions(const Extension* extension,
78 bool record_oauth2_grant) {
75 CHECK(extension); 79 CHECK(extension);
76 80
77 // We only maintain the granted permissions prefs for INTERNAL and LOAD 81 // We only maintain the granted permissions prefs for INTERNAL and LOAD
78 // extensions. 82 // extensions.
79 if (extension->location() != Extension::LOAD && 83 if (extension->location() != Extension::LOAD &&
80 extension->location() != Extension::INTERNAL) 84 extension->location() != Extension::INTERNAL)
81 return; 85 return;
82 86
83 GetExtensionPrefs()->AddGrantedPermissions( 87 scoped_refptr<const ExtensionPermissionSet> permissions =
84 extension->id(), extension->GetActivePermissions()); 88 extension->GetActivePermissions();
89 if (record_oauth2_grant) {
90 RecordOAuth2Grant(extension);
91 } else {
92 scoped_refptr<ExtensionPermissionSet> scopes =
93 new ExtensionPermissionSet(permissions->scopes());
94 permissions = ExtensionPermissionSet::CreateDifference(permissions, scopes);
95 }
96
97 GetExtensionPrefs()->AddGrantedPermissions(extension->id(), permissions);
85 } 98 }
86 99
87 void PermissionsUpdater::UpdateActivePermissions( 100 void PermissionsUpdater::UpdateActivePermissions(
88 const Extension* extension, const ExtensionPermissionSet* permissions) { 101 const Extension* extension, const ExtensionPermissionSet* permissions) {
89 GetExtensionPrefs()->SetActivePermissions(extension->id(), permissions); 102 GetExtensionPrefs()->SetActivePermissions(extension->id(), permissions);
90 extension->SetActivePermissions(permissions); 103 extension->SetActivePermissions(permissions);
91 } 104 }
92 105
106 void PermissionsUpdater::RecordOAuth2Grant(const Extension* extension) {
107 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
108 scoped_refptr<OAuth2MintTokenFlow> flow(new OAuth2MintTokenFlow(
109 profile_->GetRequestContext(), NULL, OAuth2MintTokenFlow::Parameters(
110 token_service->GetOAuth2LoginRefreshToken(),
111 extension->id(),
112 extension->oauth2_info().client_id,
113 extension->oauth2_info().scopes,
114 OAuth2MintTokenFlow::MODE_RECORD_GRANT)));
115 flow->Start();
116 }
117
93 void PermissionsUpdater::DispatchEvent( 118 void PermissionsUpdater::DispatchEvent(
94 const std::string& extension_id, 119 const std::string& extension_id,
95 const char* event_name, 120 const char* event_name,
96 const ExtensionPermissionSet* changed_permissions) { 121 const ExtensionPermissionSet* changed_permissions) {
97 if (!profile_ || !profile_->GetExtensionEventRouter()) 122 if (!profile_ || !profile_->GetExtensionEventRouter())
98 return; 123 return;
99 124
100 ListValue value; 125 ListValue value;
101 scoped_ptr<api::permissions::Permissions> permissions = 126 scoped_ptr<api::permissions::Permissions> permissions =
102 PackPermissionSet(changed_permissions); 127 PackPermissionSet(changed_permissions);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 175
151 // Trigger the onAdded and onRemoved events in the extension. 176 // Trigger the onAdded and onRemoved events in the extension.
152 DispatchEvent(extension->id(), event_name, changed); 177 DispatchEvent(extension->id(), event_name, changed);
153 } 178 }
154 179
155 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() { 180 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() {
156 return profile_->GetExtensionService()->extension_prefs(); 181 return profile_->GetExtensionService()->extension_prefs();
157 } 182 }
158 183
159 } // namespace extensions 184 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698