This source file includes following definitions.
- GetDistillerViewUrlFromEntryId
- GetDistillerViewUrlFromUrl
- GetValueForKeyInUrlPathQuery
- IsUrlDistillable
- IsUrlReportable
#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/";
}
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) {
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();
}
bool IsUrlReportable(const std::string& scheme, const GURL& url) {
return url.is_valid() && url.scheme() == scheme;
}
}
}