1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/common/extensions/sync_helper.h"
7 #include "base/logging.h"
8 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
9 #include "chrome/common/extensions/extension_constants.h"
10 #include "extensions/common/constants.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/features/behavior_feature.h"
13 #include "extensions/common/features/feature_provider.h"
14 #include "extensions/common/manifest.h"
15 #include "extensions/common/manifest_url_handlers.h"
16 #include "extensions/common/permissions/permissions_data.h"
18 namespace extensions
{
19 namespace sync_helper
{
21 bool IsSyncable(const Extension
* extension
) {
22 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kDoNotSync
)
23 ->IsAvailableToExtension(extension
)
28 // Default apps are not synced because otherwise they will pollute profiles
29 // that don't already have them. Specially, if a user doesn't have default
30 // apps, creates a new profile (which get default apps) and then enables sync
31 // for it, then their profile everywhere gets the default apps.
32 bool is_syncable
= (extension
->location() == Manifest::INTERNAL
&&
33 !extension
->was_installed_by_default());
34 if (!is_syncable
&& !IsSyncableComponentExtension(extension
)) {
35 // We have a non-standard location.
39 // Disallow extensions with non-gallery auto-update URLs for now.
41 // TODO(akalin): Relax this restriction once we've put in UI to
42 // approve synced extensions.
43 if (!ManifestURL::GetUpdateURL(extension
).is_empty() &&
44 !ManifestURL::UpdatesFromGallery(extension
)) {
48 // Disallow extensions with native code plugins.
50 // TODO(akalin): Relax this restriction once we've put in UI to
51 // approve synced extensions.
52 if (PluginInfo::HasPlugins(extension
) ||
53 extension
->permissions_data()->HasAPIPermission(APIPermission::kPlugin
)) {
57 switch (extension
->GetType()) {
58 case Manifest::TYPE_EXTENSION
:
59 case Manifest::TYPE_HOSTED_APP
:
60 case Manifest::TYPE_LEGACY_PACKAGED_APP
:
61 case Manifest::TYPE_PLATFORM_APP
:
62 case Manifest::TYPE_THEME
:
65 case Manifest::TYPE_USER_SCRIPT
:
66 // We only want to sync user scripts with gallery update URLs.
67 if (ManifestURL::UpdatesFromGallery(extension
))
71 case Manifest::TYPE_UNKNOWN
:
72 case Manifest::TYPE_SHARED_MODULE
:
75 case Manifest::NUM_LOAD_TYPES
:
82 bool IsSyncableComponentExtension(const Extension
* extension
) {
83 if (!Manifest::IsComponentLocation(extension
->location()))
85 return (extension
->id() == extensions::kWebStoreAppId
) ||
86 (extension
->id() == extension_misc::kChromeAppId
);
89 } // namespace sync_helper
90 } // namespace extensions