OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "components/dom_distiller/core/url_utils.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/guid.h" | |
10 #include "components/dom_distiller/core/url_constants.h" | |
11 #include "net/base/url_util.h" | |
12 #include "url/gurl.h" | |
13 | |
14 namespace dom_distiller { | |
15 | |
16 namespace url_utils { | |
17 | |
18 namespace { | |
19 | |
20 const char kDummyInternalUrlPrefix[] = "chrome-distiller-internal://dummy/"; | |
21 | |
22 } // namespace | |
23 | |
24 const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme, | |
25 const std::string& entry_id) { | |
26 GURL url(scheme + "://" + base::GenerateGUID()); | |
27 return net::AppendOrReplaceQueryParameter(url, kEntryIdKey, entry_id); | |
28 } | |
29 | |
30 const GURL GetDistillerViewUrlFromUrl(const std::string& scheme, | |
31 const GURL& view_url) { | |
32 GURL url(scheme + "://" + base::GenerateGUID()); | |
33 return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec()); | |
34 } | |
35 | |
36 std::string GetValueForKeyInURLPathQuery(const std::string& path, | |
shashi
2014/02/27 04:29:08
Should it be Url instead of URL?
nyquist
2014/02/27 19:50:19
Done.
| |
37 const std::string& key) { | |
38 // Tools for retrieving a value in a query only works with full GURLs, so | |
39 // using a dummy scheme and host to create a fake URL which can be parsed. | |
40 GURL dummy_url(kDummyInternalUrlPrefix + path); | |
41 std::string value; | |
42 net::GetValueForKeyInQuery(dummy_url, key, &value); | |
43 return value; | |
44 } | |
45 | |
46 bool IsDistillableUrl(const GURL& url) { | |
47 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); | |
48 } | |
49 | |
50 } // namespace url_utils | |
51 | |
52 } // namespace dom_distiller | |
OLD | NEW |