OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/event_router.h" | 11 #include "chrome/browser/extensions/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/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/signin/token_service.h" | 16 #include "chrome/browser/signin/token_service.h" |
17 #include "chrome/browser/signin/token_service_factory.h" | 17 #include "chrome/browser/signin/token_service_factory.h" |
18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" | |
19 #include "chrome/common/extensions/api/permissions.h" | 20 #include "chrome/common/extensions/api/permissions.h" |
20 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/extensions/extension_messages.h" | 22 #include "chrome/common/extensions/extension_messages.h" |
22 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
26 #include "google_apis/gaia/oauth2_mint_token_flow.h" | 27 #include "google_apis/gaia/oauth2_mint_token_flow.h" |
27 | 28 |
28 using content::RenderProcessHost; | 29 using content::RenderProcessHost; |
(...skipping 14 matching lines...) Expand all Loading... | |
43 public content::NotificationObserver { | 44 public content::NotificationObserver { |
44 public: | 45 public: |
45 OAuth2GrantRecorder(Profile* profile, const Extension* extension) | 46 OAuth2GrantRecorder(Profile* profile, const Extension* extension) |
46 : ALLOW_THIS_IN_INITIALIZER_LIST(flow_( | 47 : ALLOW_THIS_IN_INITIALIZER_LIST(flow_( |
47 profile->GetRequestContext(), | 48 profile->GetRequestContext(), |
48 this, | 49 this, |
49 OAuth2MintTokenFlow::Parameters( | 50 OAuth2MintTokenFlow::Parameters( |
50 TokenServiceFactory::GetForProfile(profile)-> | 51 TokenServiceFactory::GetForProfile(profile)-> |
51 GetOAuth2LoginRefreshToken(), | 52 GetOAuth2LoginRefreshToken(), |
52 extension->id(), | 53 extension->id(), |
53 extension->oauth2_info().client_id, | 54 extensions::OAuth2Info::GetOAuth2Info(extension).client_id, |
Devlin
2013/01/17 22:53:05
nit: don't need to have extensions:: prefix in thi
SanjoyPal
2013/01/18 02:08:50
Done.
| |
54 extension->oauth2_info().scopes, | 55 extensions::OAuth2Info::GetOAuth2Info(extension).scopes, |
55 OAuth2MintTokenFlow::MODE_RECORD_GRANT))) { | 56 OAuth2MintTokenFlow::MODE_RECORD_GRANT))) { |
56 notification_registrar_.Add(this, | 57 notification_registrar_.Add(this, |
57 chrome::NOTIFICATION_PROFILE_DESTROYED, | 58 chrome::NOTIFICATION_PROFILE_DESTROYED, |
58 content::Source<Profile>(profile)); | 59 content::Source<Profile>(profile)); |
59 | 60 |
60 flow_.Start(); | 61 flow_.Start(); |
61 } | 62 } |
62 | 63 |
63 // content::NotificationObserver: | 64 // content::NotificationObserver: |
64 void Observe(int type, | 65 void Observe(int type, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 // We only maintain the granted permissions prefs for INTERNAL and LOAD | 137 // We only maintain the granted permissions prefs for INTERNAL and LOAD |
137 // extensions. | 138 // extensions. |
138 if (extension->location() != Extension::LOAD && | 139 if (extension->location() != Extension::LOAD && |
139 extension->location() != Extension::INTERNAL) | 140 extension->location() != Extension::INTERNAL) |
140 return; | 141 return; |
141 | 142 |
142 if (record_oauth2_grant) { | 143 if (record_oauth2_grant) { |
143 // Only record OAuth grant if: | 144 // Only record OAuth grant if: |
144 // 1. The extension has client id and scopes. | 145 // 1. The extension has client id and scopes. |
145 // 2. The user is signed in to Chrome. | 146 // 2. The user is signed in to Chrome. |
146 const Extension::OAuth2Info& oauth2_info = extension->oauth2_info(); | 147 const extensions::OAuth2Info& oauth2_info = |
148 extensions::OAuth2Info::GetOAuth2Info(extension); | |
147 if (!oauth2_info.client_id.empty() && !oauth2_info.scopes.empty()) { | 149 if (!oauth2_info.client_id.empty() && !oauth2_info.scopes.empty()) { |
148 TokenService* token_service = TokenServiceFactory::GetForProfile( | 150 TokenService* token_service = TokenServiceFactory::GetForProfile( |
149 profile_); | 151 profile_); |
150 if (token_service && token_service->HasOAuthLoginToken()) { | 152 if (token_service && token_service->HasOAuthLoginToken()) { |
151 new OAuth2GrantRecorder(profile_, extension); | 153 new OAuth2GrantRecorder(profile_, extension); |
152 } | 154 } |
153 } | 155 } |
154 } | 156 } |
155 | 157 |
156 GetExtensionPrefs()->AddGrantedPermissions(extension->id(), | 158 GetExtensionPrefs()->AddGrantedPermissions(extension->id(), |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 // Trigger the onAdded and onRemoved events in the extension. | 227 // Trigger the onAdded and onRemoved events in the extension. |
226 DispatchEvent(extension->id(), event_name, changed); | 228 DispatchEvent(extension->id(), event_name, changed); |
227 } | 229 } |
228 | 230 |
229 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() { | 231 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() { |
230 return extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 232 return extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
231 extension_prefs(); | 233 extension_prefs(); |
232 } | 234 } |
233 | 235 |
234 } // namespace extensions | 236 } // namespace extensions |
OLD | NEW |