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 2082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2093 extension_prefs_->extension_sorting()->EnsureValidOrdinals( | 2093 extension_prefs_->extension_sorting()->EnsureValidOrdinals( |
2094 extension->id(), syncer::StringOrdinal()); | 2094 extension->id(), syncer::StringOrdinal()); |
2095 } | 2095 } |
2096 | 2096 |
2097 extensions_.Insert(scoped_extension); | 2097 extensions_.Insert(scoped_extension); |
2098 SyncExtensionChangeIfNeeded(*extension); | 2098 SyncExtensionChangeIfNeeded(*extension); |
2099 NotifyExtensionLoaded(extension); | 2099 NotifyExtensionLoaded(extension); |
2100 DoPostLoadTasks(extension); | 2100 DoPostLoadTasks(extension); |
2101 } | 2101 } |
2102 | 2102 |
2103 void ExtensionService::AddComponentExtension(const Extension* extension) { | |
2104 const Version old_version( | |
2105 extension_prefs_->GetVersionString(extension->id())); | |
2106 | |
2107 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { | |
2108 VLOG(1) << "Component extension " << extension->name() << " (" | |
2109 << extension->id() << ") installing/upgrading from " | |
2110 << (old_version.IsValid() ? old_version.GetString() : "<none>") | |
Yoyo Zhou
2012/11/27 23:54:18
GetVersionString gives you a string; you might as
tapted
2012/11/28 06:21:14
Done. (I think that's what you had in mind).
| |
2111 << " to " << extension->version()->GetString(); | |
2112 | |
2113 AddNewOrUpdatedExtension(extension, | |
2114 syncer::StringOrdinal(), | |
2115 Extension::ENABLED_COMPONENT); | |
2116 return; | |
2117 } | |
2118 | |
2119 AddExtension(extension); | |
2120 } | |
2121 | |
2103 void ExtensionService::InitializePermissions(const Extension* extension) { | 2122 void ExtensionService::InitializePermissions(const Extension* extension) { |
2104 // If the extension has used the optional permissions API, it will have a | 2123 // If the extension has used the optional permissions API, it will have a |
2105 // custom set of active permissions defined in the extension prefs. Here, | 2124 // custom set of active permissions defined in the extension prefs. Here, |
2106 // we update the extension's active permissions based on the prefs. | 2125 // we update the extension's active permissions based on the prefs. |
2107 scoped_refptr<PermissionSet> active_permissions = | 2126 scoped_refptr<PermissionSet> active_permissions = |
2108 extension_prefs()->GetActivePermissions(extension->id()); | 2127 extension_prefs()->GetActivePermissions(extension->id()); |
2109 | 2128 |
2110 if (active_permissions.get()) { | 2129 if (active_permissions.get()) { |
2111 // We restrict the active permissions to be within the bounds defined in the | 2130 // We restrict the active permissions to be within the bounds defined in the |
2112 // extension's manifest. | 2131 // extension's manifest. |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2368 | 2387 |
2369 // Transfer ownership of |extension|. | 2388 // Transfer ownership of |extension|. |
2370 pending_extension_updates_.Insert(scoped_extension); | 2389 pending_extension_updates_.Insert(scoped_extension); |
2371 | 2390 |
2372 // Notify extension of available update. | 2391 // Notify extension of available update. |
2373 extensions::RuntimeEventRouter::DispatchOnUpdateAvailableEvent( | 2392 extensions::RuntimeEventRouter::DispatchOnUpdateAvailableEvent( |
2374 profile_, id, extension->manifest()->value()); | 2393 profile_, id, extension->manifest()->value()); |
2375 return; | 2394 return; |
2376 } | 2395 } |
2377 | 2396 |
2397 // Transfer ownership of |extension|. | |
2398 AddNewOrUpdatedExtension( | |
2399 scoped_extension, | |
2400 page_ordinal, | |
2401 initial_enable ? Extension::ENABLED : Extension::DISABLED); | |
2402 } | |
2403 | |
2404 void ExtensionService::AddNewOrUpdatedExtension( | |
2405 const Extension* extension, | |
2406 const syncer::StringOrdinal& page_ordinal, | |
2407 Extension::State initial_state) { | |
2408 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2409 | |
2378 extension_prefs_->OnExtensionInstalled( | 2410 extension_prefs_->OnExtensionInstalled( |
2379 extension, | 2411 extension, |
2380 initial_enable ? Extension::ENABLED : Extension::DISABLED, | 2412 initial_state, |
2381 page_ordinal); | 2413 page_ordinal); |
2382 | 2414 |
2383 // Unpacked extensions default to allowing file access, but if that has been | 2415 // Unpacked extensions default to allowing file access, but if that has been |
2384 // overridden, don't reset the value. | 2416 // overridden, don't reset the value. |
2385 if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) && | 2417 if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) && |
2386 !extension_prefs_->HasAllowFileAccessSetting(id)) { | 2418 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { |
2387 extension_prefs_->SetAllowFileAccess(id, true); | 2419 extension_prefs_->SetAllowFileAccess(extension->id(), true); |
2388 } | 2420 } |
2389 | 2421 |
2390 content::NotificationService::current()->Notify( | 2422 content::NotificationService::current()->Notify( |
2391 chrome::NOTIFICATION_EXTENSION_INSTALLED, | 2423 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
2392 content::Source<Profile>(profile_), | 2424 content::Source<Profile>(profile_), |
2393 content::Details<const Extension>(extension)); | 2425 content::Details<const Extension>(extension)); |
2394 | 2426 |
2395 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension); | 2427 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension); |
2396 | 2428 |
2397 // Transfer ownership of |extension| to AddExtension. | 2429 // Transfer ownership of |extension| to AddExtension. |
2398 AddExtension(scoped_extension); | 2430 AddExtension(extension); |
2399 | 2431 |
2400 // If this is a new external extension that was disabled, alert the user | 2432 // If this is a new external extension that was disabled, alert the user |
2401 // so he can reenable it. We do this last so that it has already been | 2433 // so he can reenable it. We do this last so that it has already been |
2402 // added to our list of extensions. | 2434 // added to our list of extensions. |
2403 if (unacknowledged_external) { | 2435 if (unacknowledged_external) { |
2404 UpdateExternalExtensionAlert(); | 2436 UpdateExternalExtensionAlert(); |
2405 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", | 2437 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
2406 EXTERNAL_EXTENSION_INSTALLED, | 2438 EXTERNAL_EXTENSION_INSTALLED, |
2407 EXTERNAL_EXTENSION_BUCKET_BOUNDARY); | 2439 EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
2408 } | 2440 } |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2970 ExtensionProcessManager* process_manager = system_->process_manager(); | 3002 ExtensionProcessManager* process_manager = system_->process_manager(); |
2971 DCHECK(process_manager); | 3003 DCHECK(process_manager); |
2972 extensions::ExtensionHost* host = | 3004 extensions::ExtensionHost* host = |
2973 process_manager->GetBackgroundHostForExtension(extension_id); | 3005 process_manager->GetBackgroundHostForExtension(extension_id); |
2974 return !host; | 3006 return !host; |
2975 } | 3007 } |
2976 | 3008 |
2977 void ExtensionService::OnBlacklistUpdated() { | 3009 void ExtensionService::OnBlacklistUpdated() { |
2978 CheckManagementPolicy(); | 3010 CheckManagementPolicy(); |
2979 } | 3011 } |
OLD | NEW |