Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: components/dom_distiller/core/url_utils.cc

Issue 151003006: Add support for distilling arbitrary URLs in DOM Distiller Viewer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added new strings to iOS whitelist Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/dom_distiller/core/url_utils.h ('k') | components/dom_distiller/core/url_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/dom_distiller/core/url_utils.cc
diff --git a/components/dom_distiller/core/url_utils.cc b/components/dom_distiller/core/url_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..814a4e7c81c8ff94816a48b493f88a804fb5e395
--- /dev/null
+++ b/components/dom_distiller/core/url_utils.cc
@@ -0,0 +1,52 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/dom_distiller/core/url_utils.h"
+
+#include <string>
+
+#include "base/guid.h"
+#include "components/dom_distiller/core/url_constants.h"
+#include "net/base/url_util.h"
+#include "url/gurl.h"
+
+namespace dom_distiller {
+
+namespace url_utils {
+
+namespace {
+
+const char kDummyInternalUrlPrefix[] = "chrome-distiller-internal://dummy/";
+
+} // namespace
+
+const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme,
+ const std::string& entry_id) {
+ GURL url(scheme + "://" + base::GenerateGUID());
+ return net::AppendOrReplaceQueryParameter(url, kEntryIdKey, entry_id);
+}
+
+const GURL GetDistillerViewUrlFromUrl(const std::string& scheme,
+ const GURL& view_url) {
+ GURL url(scheme + "://" + base::GenerateGUID());
+ return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec());
+}
+
+std::string GetValueForKeyInUrlPathQuery(const std::string& path,
+ const std::string& key) {
+ // Tools for retrieving a value in a query only works with full GURLs, so
+ // using a dummy scheme and host to create a fake URL which can be parsed.
+ GURL dummy_url(kDummyInternalUrlPrefix + path);
+ std::string value;
+ net::GetValueForKeyInQuery(dummy_url, key, &value);
+ return value;
+}
+
+bool IsUrlDistillable(const GURL& url) {
+ return url.is_valid() && url.SchemeIsHTTPOrHTTPS();
+}
+
+} // namespace url_utils
+
+} // namespace dom_distiller
« no previous file with comments | « components/dom_distiller/core/url_utils.h ('k') | components/dom_distiller/core/url_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698