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"
10 #include "components/dom_distiller/core/url_constants.h"
11 #include "net/base/url_util.h"
14 namespace dom_distiller
{
20 const char kDummyInternalUrlPrefix
[] = "chrome-distiller-internal://dummy/";
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
);
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());
36 std::string
GetValueForKeyInUrlPathQuery(const std::string
& path
,
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
);
42 net::GetValueForKeyInQuery(dummy_url
, key
, &value
);
46 bool IsUrlDistillable(const GURL
& url
) {
47 return url
.is_valid() && url
.SchemeIsHTTPOrHTTPS();
50 } // namespace url_utils
52 } // namespace dom_distiller