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 "grit/component_resources.h"
12 #include "net/base/url_util.h"
13 #include "ui/base/resource/resource_bundle.h"
16 namespace dom_distiller
{
22 const char kDummyInternalUrlPrefix
[] = "chrome-distiller-internal://dummy/";
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 std::string
GetValueForKeyInUrl(const GURL
& url
, const std::string
& key
) {
42 if (net::GetValueForKeyInQuery(url
, key
, &value
)) {
48 std::string
GetValueForKeyInUrlPathQuery(const std::string
& path
,
49 const std::string
& key
) {
50 // Tools for retrieving a value in a query only works with full GURLs, so
51 // using a dummy scheme and host to create a fake URL which can be parsed.
52 GURL
dummy_url(kDummyInternalUrlPrefix
+ path
);
53 return GetValueForKeyInUrl(dummy_url
, key
);
56 bool IsUrlDistillable(const GURL
& url
) {
57 return url
.is_valid() && url
.SchemeIsHTTPOrHTTPS();
60 bool IsDistilledPage(const GURL
& url
) {
61 return url
.is_valid() && url
.scheme() == kDomDistillerScheme
;
64 std::string
GetIsDistillableJs() {
65 return ResourceBundle::GetSharedInstance()
66 .GetRawDataResource(IDR_IS_DISTILLABLE_JS
).as_string();
69 } // namespace url_utils
71 } // namespace dom_distiller