Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: extensions/common/extension_urls.cc

Issue 2506713002: Avoid parsing the webstore base url so much. (Closed)
Patch Set: don't assume cmd line urls canonical Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "extensions/common/constants.h" 10 #include "extensions/common/constants.h"
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 } // namespace extensions 28 } // namespace extensions
29 29
30 namespace extension_urls { 30 namespace extension_urls {
31 31
32 const char kChromeWebstoreBaseURL[] = "https://chrome.google.com/webstore"; 32 const char kChromeWebstoreBaseURL[] = "https://chrome.google.com/webstore";
33 const char kChromeWebstoreUpdateURL[] = 33 const char kChromeWebstoreUpdateURL[] =
34 "https://clients2.google.com/service/update2/crx"; 34 "https://clients2.google.com/service/update2/crx";
35 35
36 std::string GetWebstoreLaunchURL() { 36 GURL GetWebstoreLaunchURL() {
37 extensions::ExtensionsClient* client = extensions::ExtensionsClient::Get(); 37 extensions::ExtensionsClient* client = extensions::ExtensionsClient::Get();
38 if (client) 38 if (client)
39 return client->GetWebstoreBaseURL(); 39 return client->GetWebstoreBaseURL();
40 return kChromeWebstoreBaseURL; 40 return GURL(kChromeWebstoreBaseURL);
41 } 41 }
42 42
43 std::string GetWebstoreExtensionsCategoryURL() { 43 std::string GetWebstoreExtensionsCategoryURL() {
44 return GetWebstoreLaunchURL() + "/category/extensions"; 44 return GetWebstoreLaunchURL().spec() + "/category/extensions";
Devlin 2016/11/16 19:11:52 Can we a) Add a TODO to convert these to return GU
Charlie Harrison 2016/11/16 21:45:19 Done, though using Resolve() is more expensive, be
45 } 45 }
46 46
47 std::string GetWebstoreItemDetailURLPrefix() { 47 std::string GetWebstoreItemDetailURLPrefix() {
48 return GetWebstoreLaunchURL() + "/detail/"; 48 return GetWebstoreLaunchURL().spec() + "/detail/";
49 } 49 }
50 50
51 GURL GetWebstoreItemJsonDataURL(const std::string& extension_id) { 51 GURL GetWebstoreItemJsonDataURL(const std::string& extension_id) {
52 return GURL(GetWebstoreLaunchURL() + "/inlineinstall/detail/" + extension_id); 52 return GURL(GetWebstoreLaunchURL().spec() + "/inlineinstall/detail/" +
53 extension_id);
53 } 54 }
54 55
55 GURL GetWebstoreJsonSearchUrl(const std::string& query, 56 GURL GetWebstoreJsonSearchUrl(const std::string& query,
56 const std::string& host_language_code) { 57 const std::string& host_language_code) {
57 GURL url(GetWebstoreLaunchURL() + "/jsonsearch"); 58 GURL url(GetWebstoreLaunchURL().spec() + "/jsonsearch");
58 url = net::AppendQueryParameter(url, "q", query); 59 url = net::AppendQueryParameter(url, "q", query);
59 url = net::AppendQueryParameter(url, "hl", host_language_code); 60 url = net::AppendQueryParameter(url, "hl", host_language_code);
60 return url; 61 return url;
61 } 62 }
62 63
63 GURL GetWebstoreSearchPageUrl(const std::string& query) { 64 GURL GetWebstoreSearchPageUrl(const std::string& query) {
64 return GURL(GetWebstoreLaunchURL() + "/search/" + 65 return GURL(GetWebstoreLaunchURL().spec() + "/search/" +
65 net::EscapeQueryParamValue(query, false)); 66 net::EscapeQueryParamValue(query, false));
66 } 67 }
67 68
68 GURL GetWebstoreUpdateUrl() { 69 GURL GetWebstoreUpdateUrl() {
69 extensions::ExtensionsClient* client = extensions::ExtensionsClient::Get(); 70 extensions::ExtensionsClient* client = extensions::ExtensionsClient::Get();
70 if (client) 71 if (client)
71 return client->GetWebstoreUpdateURL(); 72 return client->GetWebstoreUpdateURL();
72 return GURL(kChromeWebstoreUpdateURL); 73 return GURL(kChromeWebstoreUpdateURL);
73 } 74 }
74 75
75 GURL GetWebstoreReportAbuseUrl(const std::string& extension_id, 76 GURL GetWebstoreReportAbuseUrl(const std::string& extension_id,
76 const std::string& referrer_id) { 77 const std::string& referrer_id) {
77 return GURL(base::StringPrintf("%s/report/%s?utm_source=%s", 78 return GURL(base::StringPrintf("%s/report/%s?utm_source=%s",
78 GetWebstoreLaunchURL().c_str(), 79 GetWebstoreLaunchURL().spec().c_str(),
79 extension_id.c_str(), referrer_id.c_str())); 80 extension_id.c_str(), referrer_id.c_str()));
80 } 81 }
81 82
82 bool IsWebstoreUpdateUrl(const GURL& update_url) { 83 bool IsWebstoreUpdateUrl(const GURL& update_url) {
83 GURL store_url = GetWebstoreUpdateUrl(); 84 GURL store_url = GetWebstoreUpdateUrl();
84 return (update_url.host_piece() == store_url.host_piece() && 85 return (update_url.host_piece() == store_url.host_piece() &&
85 update_url.path_piece() == store_url.path_piece()); 86 update_url.path_piece() == store_url.path_piece());
86 } 87 }
87 88
88 bool IsBlacklistUpdateUrl(const GURL& url) { 89 bool IsBlacklistUpdateUrl(const GURL& url) {
89 extensions::ExtensionsClient* client = extensions::ExtensionsClient::Get(); 90 extensions::ExtensionsClient* client = extensions::ExtensionsClient::Get();
90 if (client) 91 if (client)
91 return client->IsBlacklistUpdateURL(url); 92 return client->IsBlacklistUpdateURL(url);
92 return false; 93 return false;
93 } 94 }
94 95
95 } // namespace extension_urls 96 } // namespace extension_urls
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698