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
3// found in the LICENSE file.
4
5#include "chrome/common/extensions/extension_constants.h"
6#include "chrome/common/extensions/extension_manifest_constants.h"
7
8#include <vector>
9
10#include "base/command_line.h"
11#include "base/strings/string_util.h"
12#include "chrome/common/chrome_switches.h"
13#include "net/base/escape.h"
14#include "net/base/url_util.h"
15
16namespace extension_urls {
17
18std::string GetWebstoreLaunchURL() {
19  std::string gallery_prefix = kGalleryBrowsePrefix;
20  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAppsGalleryURL))
21    gallery_prefix = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
22        switches::kAppsGalleryURL);
23  if (EndsWith(gallery_prefix, "/", true))
24    gallery_prefix = gallery_prefix.substr(0, gallery_prefix.length() - 1);
25  return gallery_prefix;
26}
27
28std::string GetExtensionGalleryURL() {
29  return GetWebstoreLaunchURL() + "/category/extensions";
30}
31
32std::string GetWebstoreItemDetailURLPrefix() {
33  return GetWebstoreLaunchURL() + "/detail/";
34}
35
36GURL GetWebstoreItemJsonDataURL(const std::string& extension_id) {
37  return GURL(GetWebstoreLaunchURL() + "/inlineinstall/detail/" + extension_id);
38}
39
40GURL GetWebstoreJsonSearchUrl(const std::string& query, const std::string& hl) {
41  GURL url(GetWebstoreLaunchURL() + "/jsonsearch");
42  url = net::AppendQueryParameter(url, "q", query);
43  url = net::AppendQueryParameter(url, "hl", hl);
44  return url;
45}
46
47GURL GetWebstoreSearchPageUrl(const std::string& query) {
48  return GURL(GetWebstoreLaunchURL() + "/search/" +
49              net::EscapeQueryParamValue(query, false));
50}
51
52const char kGalleryUpdateHttpsUrl[] =
53    "https://clients2.google.com/service/update2/crx";
54// TODO(battre): Delete the HTTP URL once the blacklist is downloaded via HTTPS.
55const char kExtensionBlocklistUrlPrefix[] =
56    "http://www.gstatic.com/chrome/extensions/blacklist";
57const char kExtensionBlocklistHttpsUrlPrefix[] =
58    "https://www.gstatic.com/chrome/extensions/blacklist";
59
60GURL GetWebstoreUpdateUrl() {
61  CommandLine* cmdline = CommandLine::ForCurrentProcess();
62  if (cmdline->HasSwitch(switches::kAppsGalleryUpdateURL))
63    return GURL(cmdline->GetSwitchValueASCII(switches::kAppsGalleryUpdateURL));
64  else
65    return GURL(kGalleryUpdateHttpsUrl);
66}
67
68bool IsWebstoreUpdateUrl(const GURL& update_url) {
69  GURL store_url = GetWebstoreUpdateUrl();
70  if (update_url == store_url) {
71    return true;
72  } else {
73    return (update_url.host() == store_url.host() &&
74            update_url.path() == store_url.path());
75  }
76}
77
78bool IsBlacklistUpdateUrl(const GURL& url) {
79  // The extension blacklist URL is returned from the update service and
80  // therefore not determined by Chromium. If the location of the blacklist file
81  // ever changes, we need to update this function. A DCHECK in the
82  // ExtensionUpdater ensures that we notice a change. This is the full URL
83  // of a blacklist:
84  // http://www.gstatic.com/chrome/extensions/blacklist/l_0_0_0_7.txt
85  return StartsWithASCII(url.spec(), kExtensionBlocklistUrlPrefix, true) ||
86      StartsWithASCII(url.spec(), kExtensionBlocklistHttpsUrlPrefix, true);
87}
88
89const char kGalleryBrowsePrefix[] = "https://chrome.google.com/webstore";
90
91}  // namespace extension_urls
92
93namespace extension_misc {
94
95const char kBookmarkManagerId[] = "eemcgdkfndhakfknompkggombfjjjeno";
96const char kChromeAppId[] = "mgndgikekgjfcpckkfioiadnlibdjbkf";
97const char kCitrixReceiverAppId[] = "haiffjcadagjlijoggckpgfnoeiflnem";
98const char kCitrixReceiverAppBetaId[] = "gnedhmakppccajfpfiihfcdlnpgomkcf";
99const char kCitrixReceiverAppDevId[] = "fjcibdnjlbfnbfdjneajpipnlcppleek";
100const char kCloudPrintAppId[] = "mfehgcgbbipciphmccgaenjidiccnmng";
101const char kEnterpriseWebStoreAppId[] = "afchcafgojfnemjkcbhfekplkmjaldaa";
102const char kGmailAppId[] = "pjkljhegncpnkpknbcohdijeoejaedia";
103const char kGoogleDocAppId[] = "aohghmighlieiainnegkcijnfilokake";
104const char kGooglePlayMusicAppId[] = "icppfcnhkcmnfdhfhphakoifcfokfdhg";
105const char kGoogleSearchAppId[] = "coobgpohoikkiipiblmjeljniedjpjpf";
106const char kGoogleSheetsAppId[] = "felcaaldnbdncclmgdcncolpebgiejap";
107const char kGoogleSlidesAppId[] = "aapocclcgogkmnckokdopfmhonfmgoek";
108const char kHTermAppId[] = "pnhechapfaindjhompbnflcldabbghjo";
109const char kHTermDevAppId[] = "okddffdblfhhnmhodogpojmfkjmhinfp";
110const char kIdentityApiUiAppId[] = "ahjaciijnoiaklcomgnblndopackapon";
111const char kCroshBuiltinAppId[] = "nkoccljplnhpfnfiajclkommnmllphnl";
112const char kQuickOfficeComponentExtensionId[] =
113    "bpmcpldpdmajfigpchkicefoigmkfalc";
114const char kQuickOfficeDevExtensionId[] = "ionpfmkccalenbmnddpbmocokhaknphg";
115const char kQuickOfficeExtensionId[] = "gbkeegbaiigmenfmjfclcdgdpimamgkj";
116const char kSettingsAppId[] = "ennkphjdgehloodpbhlhldgbnhmacadg";
117const char kStreamsPrivateTestExtensionId[] =
118    "oickdpebdnfbgkcaoklfcdhjniefkcji";
119const char kWebStoreAppId[] = "ahfgeienlihckogmohjhadlkjgocpleb";
120const char kYoutubeAppId[] = "blpcfgokakmgnkcojhhkbfbldkacnbeo";
121const char kInAppPaymentsSupportAppId[] = "nmmhkkegccagdldgiimedpiccmgmieda";
122
123const char kAppLaunchHistogram[] = "Extensions.AppLaunch";
124const char kPlatformAppLaunchHistogram[] = "Apps.AppLaunch";
125#if defined(OS_CHROMEOS)
126const char kChromeVoxExtensionPath[] =
127    "/usr/share/chromeos-assets/accessibility/extensions/access_chromevox";
128// The extension id for the built-in component extension.
129const char kChromeVoxExtensionId[] =
130    "mndnfokpggljbaajbnioimlmbfngpief";
131const char kConnectivityDiagnosticsPath[] =
132    "/usr/share/chromeos-assets/connectivity_diagnostics";
133const char kConnectivityDiagnosticsLauncherPath[] =
134    "/usr/share/chromeos-assets/connectivity_diagnostics_launcher";
135const char kSpeechSynthesisExtensionPath[] =
136    "/usr/share/chromeos-assets/speech_synthesis/patts";
137const char kSpeechSynthesisExtensionId[] =
138    "gjjabgpgjpampikjhjpfhneeoapjbjaf";
139const char kWallpaperManagerId[] = "obklkkbkpaoaejdabbfldmcfplpdgolj";
140#else
141// The extension id for the web store extension.
142const char kChromeVoxExtensionId[] =
143    "kgejglhpjiefppelpmljglcjbhoiplfn";
144#endif
145
146const char kAppStateNotInstalled[] = "not_installed";
147const char kAppStateInstalled[] = "installed";
148const char kAppStateDisabled[] = "disabled";
149const char kAppStateRunning[] = "running";
150const char kAppStateCannotRun[] = "cannot_run";
151const char kAppStateReadyToRun[] = "ready_to_run";
152
153const char kMediaFileSystemPathPart[] = "_";
154
155const int kExtensionIconSizes[] = {
156  EXTENSION_ICON_GIGANTOR,  // 512
157  EXTENSION_ICON_EXTRA_LARGE,  // 256
158  EXTENSION_ICON_LARGE,  // 128
159  EXTENSION_ICON_MEDIUM,  // 48
160  EXTENSION_ICON_SMALL,  // 32
161  EXTENSION_ICON_SMALLISH,  // 24
162  EXTENSION_ICON_BITTY,  // 16
163  // Additional 2x resources to load.
164  2 * EXTENSION_ICON_MEDIUM,  // 96
165  2 * EXTENSION_ICON_SMALL  // 64
166};
167
168const size_t kNumExtensionIconSizes =
169    arraysize(kExtensionIconSizes);
170
171const int kExtensionActionIconSizes[] = {
172  EXTENSION_ICON_ACTION,  // 19,
173  2 * EXTENSION_ICON_ACTION  // 38
174};
175
176const size_t kNumExtensionActionIconSizes =
177    arraysize(kExtensionActionIconSizes);
178
179const int kScriptBadgeIconSizes[] = {
180  EXTENSION_ICON_BITTY,  // 16
181  2 * EXTENSION_ICON_BITTY  // 32
182};
183
184const size_t kNumScriptBadgeIconSizes =
185    arraysize(kScriptBadgeIconSizes);
186
187}  // namespace extension_misc
188