| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/dom_distiller/core/url_utils.h" | 5 #include "components/dom_distiller/core/url_utils.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "components/dom_distiller/core/url_constants.h" | 10 #include "components/dom_distiller/core/url_constants.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 GURL url(scheme + "://" + base::GenerateGUID()); | 28 GURL url(scheme + "://" + base::GenerateGUID()); |
| 29 return net::AppendOrReplaceQueryParameter(url, kEntryIdKey, entry_id); | 29 return net::AppendOrReplaceQueryParameter(url, kEntryIdKey, entry_id); |
| 30 } | 30 } |
| 31 | 31 |
| 32 const GURL GetDistillerViewUrlFromUrl(const std::string& scheme, | 32 const GURL GetDistillerViewUrlFromUrl(const std::string& scheme, |
| 33 const GURL& view_url) { | 33 const GURL& view_url) { |
| 34 GURL url(scheme + "://" + base::GenerateGUID()); | 34 GURL url(scheme + "://" + base::GenerateGUID()); |
| 35 return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec()); | 35 return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 std::string GetValueForKeyInUrl(const GURL& url, const std::string& key) { |
| 39 if (!url.is_valid()) |
| 40 return ""; |
| 41 std::string value; |
| 42 if (net::GetValueForKeyInQuery(url, key, &value)) { |
| 43 return value; |
| 44 } |
| 45 return ""; |
| 46 } |
| 47 |
| 38 std::string GetValueForKeyInUrlPathQuery(const std::string& path, | 48 std::string GetValueForKeyInUrlPathQuery(const std::string& path, |
| 39 const std::string& key) { | 49 const std::string& key) { |
| 40 // Tools for retrieving a value in a query only works with full GURLs, so | 50 // Tools for retrieving a value in a query only works with full GURLs, so |
| 41 // using a dummy scheme and host to create a fake URL which can be parsed. | 51 // using a dummy scheme and host to create a fake URL which can be parsed. |
| 42 GURL dummy_url(kDummyInternalUrlPrefix + path); | 52 GURL dummy_url(kDummyInternalUrlPrefix + path); |
| 43 std::string value; | 53 return GetValueForKeyInUrl(dummy_url, key); |
| 44 net::GetValueForKeyInQuery(dummy_url, key, &value); | |
| 45 return value; | |
| 46 } | 54 } |
| 47 | 55 |
| 48 bool IsUrlDistillable(const GURL& url) { | 56 bool IsUrlDistillable(const GURL& url) { |
| 49 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); | 57 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); |
| 50 } | 58 } |
| 51 | 59 |
| 52 bool IsDistilledPage(const GURL& url) { | 60 bool IsDistilledPage(const GURL& url) { |
| 53 return url.is_valid() && url.scheme() == kDomDistillerScheme; | 61 return url.is_valid() && url.scheme() == kDomDistillerScheme; |
| 54 } | 62 } |
| 55 | 63 |
| 56 std::string GetIsDistillableJs() { | 64 std::string GetIsDistillableJs() { |
| 57 return ResourceBundle::GetSharedInstance() | 65 return ResourceBundle::GetSharedInstance() |
| 58 .GetRawDataResource(IDR_IS_DISTILLABLE_JS).as_string(); | 66 .GetRawDataResource(IDR_IS_DISTILLABLE_JS).as_string(); |
| 59 } | 67 } |
| 60 | 68 |
| 61 } // namespace url_utils | 69 } // namespace url_utils |
| 62 | 70 |
| 63 } // namespace dom_distiller | 71 } // namespace dom_distiller |
| OLD | NEW |