OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/common/extension_urls.h" | 5 #include "extensions/common/extension_urls.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "extensions/common/constants.h" | 9 #include "extensions/common/constants.h" |
| 10 #include "extensions/common/extensions_client.h" |
| 11 #include "net/base/escape.h" |
| 12 #include "net/base/url_util.h" |
10 #include "url/gurl.h" | 13 #include "url/gurl.h" |
11 | 14 |
12 namespace extensions { | 15 namespace extensions { |
13 | 16 |
14 const char kEventBindings[] = "event_bindings"; | 17 const char kEventBindings[] = "event_bindings"; |
15 | 18 |
16 const char kSchemaUtils[] = "schemaUtils"; | 19 const char kSchemaUtils[] = "schemaUtils"; |
17 | 20 |
18 bool IsSourceFromAnExtension(const base::string16& source) { | 21 bool IsSourceFromAnExtension(const base::string16& source) { |
19 return GURL(source).SchemeIs(kExtensionScheme) || | 22 return GURL(source).SchemeIs(kExtensionScheme) || |
20 StartsWith(source, | 23 StartsWith(source, |
21 base::ASCIIToUTF16("extensions::"), | 24 base::ASCIIToUTF16("extensions::"), |
22 true /* case-sensitive */); | 25 true /* case-sensitive */); |
23 } | 26 } |
24 | 27 |
25 } // namespace extensions | 28 } // namespace extensions |
| 29 |
| 30 namespace extension_urls { |
| 31 |
| 32 const char kChromeWebstoreBaseURL[] = "https://chrome.google.com/webstore"; |
| 33 const char kChromeWebstoreUpdateURL[] = |
| 34 "https://clients2.google.com/service/update2/crx"; |
| 35 |
| 36 std::string GetWebstoreLaunchURL() { |
| 37 extensions::ExtensionsClient* client = extensions::ExtensionsClient::Get(); |
| 38 if (client) |
| 39 return client->GetWebstoreBaseURL(); |
| 40 return kChromeWebstoreBaseURL; |
| 41 } |
| 42 |
| 43 std::string GetWebstoreExtensionsCategoryURL() { |
| 44 return GetWebstoreLaunchURL() + "/category/extensions"; |
| 45 } |
| 46 |
| 47 std::string GetWebstoreItemDetailURLPrefix() { |
| 48 return GetWebstoreLaunchURL() + "/detail/"; |
| 49 } |
| 50 |
| 51 GURL GetWebstoreItemJsonDataURL(const std::string& extension_id) { |
| 52 return GURL(GetWebstoreLaunchURL() + "/inlineinstall/detail/" + extension_id); |
| 53 } |
| 54 |
| 55 GURL GetWebstoreJsonSearchUrl(const std::string& query, |
| 56 const std::string& host_language_code) { |
| 57 GURL url(GetWebstoreLaunchURL() + "/jsonsearch"); |
| 58 url = net::AppendQueryParameter(url, "q", query); |
| 59 url = net::AppendQueryParameter(url, "hl", host_language_code); |
| 60 return url; |
| 61 } |
| 62 |
| 63 GURL GetWebstoreSearchPageUrl(const std::string& query) { |
| 64 return GURL(GetWebstoreLaunchURL() + "/search/" + |
| 65 net::EscapeQueryParamValue(query, false)); |
| 66 } |
| 67 |
| 68 GURL GetWebstoreUpdateUrl() { |
| 69 extensions::ExtensionsClient* client = extensions::ExtensionsClient::Get(); |
| 70 if (client) |
| 71 return GURL(client->GetWebstoreUpdateURL()); |
| 72 return GURL(kChromeWebstoreUpdateURL); |
| 73 } |
| 74 |
| 75 bool IsWebstoreUpdateUrl(const GURL& update_url) { |
| 76 GURL store_url = GetWebstoreUpdateUrl(); |
| 77 if (update_url == store_url) { |
| 78 return true; |
| 79 } else { |
| 80 return (update_url.host() == store_url.host() && |
| 81 update_url.path() == store_url.path()); |
| 82 } |
| 83 } |
| 84 |
| 85 bool IsBlacklistUpdateUrl(const GURL& url) { |
| 86 extensions::ExtensionsClient* client = extensions::ExtensionsClient::Get(); |
| 87 if (client) |
| 88 return client->IsBlacklistUpdateURL(url); |
| 89 return false; |
| 90 } |
| 91 |
| 92 } // namespace extension_urls |
OLD | NEW |