summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/sync_helper.cc
blob: 1219073330969ca44992c268680f19db97540e7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/extensions/sync_helper.h"

#include "base/logging.h"
#include "chrome/common/extensions/api/plugins/plugins_handler.h"
#include "chrome/common/extensions/extension_constants.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/features/behavior_feature.h"
#include "extensions/common/features/feature_provider.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_url_handlers.h"
#include "extensions/common/permissions/permissions_data.h"

namespace extensions {
namespace sync_helper {

bool IsSyncable(const Extension* extension) {
  if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kDoNotSync)
          ->IsAvailableToExtension(extension)
          .is_available()) {
    return false;
  }

  // Default apps are not synced because otherwise they will pollute profiles
  // that don't already have them. Specially, if a user doesn't have default
  // apps, creates a new profile (which get default apps) and then enables sync
  // for it, then their profile everywhere gets the default apps.
  bool is_syncable = (extension->location() == Manifest::INTERNAL &&
                      !extension->was_installed_by_default());
  if (!is_syncable && !IsSyncableComponentExtension(extension)) {
    // We have a non-standard location.
    return false;
  }

  // Disallow extensions with non-gallery auto-update URLs for now.
  //
  // TODO(akalin): Relax this restriction once we've put in UI to
  // approve synced extensions.
  if (!ManifestURL::GetUpdateURL(extension).is_empty() &&
      !ManifestURL::UpdatesFromGallery(extension)) {
    return false;
  }

  // Disallow extensions with native code plugins.
  //
  // TODO(akalin): Relax this restriction once we've put in UI to
  // approve synced extensions.
  if (PluginInfo::HasPlugins(extension) ||
      extension->permissions_data()->HasAPIPermission(APIPermission::kPlugin)) {
    return false;
  }

  switch (extension->GetType()) {
    case Manifest::TYPE_EXTENSION:
    case Manifest::TYPE_HOSTED_APP:
    case Manifest::TYPE_LEGACY_PACKAGED_APP:
    case Manifest::TYPE_PLATFORM_APP:
    case Manifest::TYPE_THEME:
      return true;

    case Manifest::TYPE_USER_SCRIPT:
      // We only want to sync user scripts with gallery update URLs.
      if (ManifestURL::UpdatesFromGallery(extension))
        return true;
      return false;

    case Manifest::TYPE_UNKNOWN:
    case Manifest::TYPE_SHARED_MODULE:
      return false;

    case Manifest::NUM_LOAD_TYPES:
      NOTREACHED();
  }
  NOTREACHED();
  return false;
}

bool IsSyncableComponentExtension(const Extension* extension) {
  if (!Manifest::IsComponentLocation(extension->location()))
    return false;
  return (extension->id() == extensions::kWebStoreAppId) ||
         (extension->id() == extension_misc::kChromeAppId);
}

}  // namespace sync_helper
}  // namespace extensions