| 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/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 OAuth2Info::GetOAuth2Info(extension).client_id, |
| 54 extension->oauth2_info().scopes, | 55 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 OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension); |
| 147 if (!oauth2_info.client_id.empty() && !oauth2_info.scopes.empty()) { | 148 if (!oauth2_info.client_id.empty() && !oauth2_info.scopes.empty()) { |
| 148 TokenService* token_service = TokenServiceFactory::GetForProfile( | 149 TokenService* token_service = TokenServiceFactory::GetForProfile( |
| 149 profile_); | 150 profile_); |
| 150 if (token_service && token_service->HasOAuthLoginToken()) { | 151 if (token_service && token_service->HasOAuthLoginToken()) { |
| 151 new OAuth2GrantRecorder(profile_, extension); | 152 new OAuth2GrantRecorder(profile_, extension); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 } | 155 } |
| 155 | 156 |
| 156 GetExtensionPrefs()->AddGrantedPermissions(extension->id(), | 157 GetExtensionPrefs()->AddGrantedPermissions(extension->id(), |
| 157 extension->GetActivePermissions()); | 158 extension->GetActivePermissions()); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void PermissionsUpdater::UpdateActivePermissions( | 161 void PermissionsUpdater::UpdateActivePermissions( |
| 161 const Extension* extension, const PermissionSet* permissions) { | 162 const Extension* extension, const PermissionSet* permissions) { |
| 162 GetExtensionPrefs()->SetActivePermissions(extension->id(), permissions); | 163 GetExtensionPrefs()->SetActivePermissions(extension->id(), permissions); |
| 163 extension->SetActivePermissions(permissions); | 164 extension->SetActivePermissions(permissions); |
| 164 } | 165 } |
| 165 | 166 |
| 166 void PermissionsUpdater::DispatchEvent( | 167 void PermissionsUpdater::DispatchEvent( |
| 167 const std::string& extension_id, | 168 const std::string& extension_id, |
| 168 const char* event_name, | 169 const char* event_name, |
| 169 const PermissionSet* changed_permissions) { | 170 const PermissionSet* changed_permissions) { |
| 170 if (!profile_ || | 171 if (!profile_ || |
| 171 !extensions::ExtensionSystem::Get(profile_)->event_router()) | 172 !ExtensionSystem::Get(profile_)->event_router()) |
| 172 return; | 173 return; |
| 173 | 174 |
| 174 scoped_ptr<ListValue> value(new ListValue()); | 175 scoped_ptr<ListValue> value(new ListValue()); |
| 175 scoped_ptr<api::permissions::Permissions> permissions = | 176 scoped_ptr<api::permissions::Permissions> permissions = |
| 176 PackPermissionSet(changed_permissions); | 177 PackPermissionSet(changed_permissions); |
| 177 value->Append(permissions->ToValue().release()); | 178 value->Append(permissions->ToValue().release()); |
| 178 scoped_ptr<Event> event(new Event(event_name, value.Pass())); | 179 scoped_ptr<Event> event(new Event(event_name, value.Pass())); |
| 179 event->restrict_to_profile = profile_; | 180 event->restrict_to_profile = profile_; |
| 180 ExtensionSystem::Get(profile_)->event_router()-> | 181 ExtensionSystem::Get(profile_)->event_router()-> |
| 181 DispatchEventToExtension(extension_id, event.Pass()); | 182 DispatchEventToExtension(extension_id, event.Pass()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 changed->apis(), | 221 changed->apis(), |
| 221 changed->explicit_hosts(), | 222 changed->explicit_hosts(), |
| 222 changed->scriptable_hosts())); | 223 changed->scriptable_hosts())); |
| 223 } | 224 } |
| 224 | 225 |
| 225 // Trigger the onAdded and onRemoved events in the extension. | 226 // Trigger the onAdded and onRemoved events in the extension. |
| 226 DispatchEvent(extension->id(), event_name, changed); | 227 DispatchEvent(extension->id(), event_name, changed); |
| 227 } | 228 } |
| 228 | 229 |
| 229 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() { | 230 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() { |
| 230 return extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 231 return ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); |
| 231 extension_prefs(); | |
| 232 } | 232 } |
| 233 | 233 |
| 234 } // namespace extensions | 234 } // namespace extensions |
| OLD | NEW |