Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / dom_distiller / core / url_utils.cc
blobcfe4fcb9a21398cec21c8f68c5cf8d9b13147cb7
1 // Copyright 2014 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 "components/dom_distiller/core/url_utils.h"
7 #include <string>
9 #include "base/guid.h"
10 #include "components/dom_distiller/core/url_constants.h"
11 #include "grit/components_resources.h"
12 #include "net/base/url_util.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "url/gurl.h"
16 namespace dom_distiller {
18 namespace url_utils {
20 namespace {
22 const char kDummyInternalUrlPrefix[] = "chrome-distiller-internal://dummy/";
24 } // namespace
26 const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme,
27 const std::string& entry_id) {
28 GURL url(scheme + "://" + base::GenerateGUID());
29 return net::AppendOrReplaceQueryParameter(url, kEntryIdKey, entry_id);
32 const GURL GetDistillerViewUrlFromUrl(const std::string& scheme,
33 const GURL& view_url) {
34 GURL url(scheme + "://" + base::GenerateGUID());
35 return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec());
38 const GURL GetOriginalUrlFromDistillerUrl(const GURL& url) {
39 if (!dom_distiller::url_utils::IsDistilledPage(url))
40 return url;
42 std::string original_url_str;
43 net::GetValueForKeyInQuery(url, kUrlKey, &original_url_str);
45 return GURL(original_url_str);
48 std::string GetValueForKeyInUrl(const GURL& url, const std::string& key) {
49 if (!url.is_valid())
50 return "";
51 std::string value;
52 if (net::GetValueForKeyInQuery(url, key, &value)) {
53 return value;
55 return "";
58 std::string GetValueForKeyInUrlPathQuery(const std::string& path,
59 const std::string& key) {
60 // Tools for retrieving a value in a query only works with full GURLs, so
61 // using a dummy scheme and host to create a fake URL which can be parsed.
62 GURL dummy_url(kDummyInternalUrlPrefix + path);
63 return GetValueForKeyInUrl(dummy_url, key);
66 bool IsUrlDistillable(const GURL& url) {
67 return url.is_valid() && url.SchemeIsHTTPOrHTTPS();
70 bool IsDistilledPage(const GURL& url) {
71 return url.is_valid() && url.scheme() == kDomDistillerScheme;
74 std::string GetIsDistillableJs() {
75 return ResourceBundle::GetSharedInstance()
76 .GetRawDataResource(IDR_IS_DISTILLABLE_JS).as_string();
79 } // namespace url_utils
81 } // namespace dom_distiller