2021-04-15 01:28:22 +02:00
|
|
|
// Copyright (c) 2021 The Chromium Embedded Framework 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 "libcef/common/net/url_util.h"
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "components/url_formatter/url_fixer.h"
|
|
|
|
|
|
|
|
namespace url_util {
|
|
|
|
|
|
|
|
GURL MakeGURL(const CefString& url, bool fixup) {
|
|
|
|
GURL gurl = GURL(url.ToString());
|
|
|
|
if (!url.empty() && !gurl.is_valid() && !gurl.has_scheme()) {
|
|
|
|
std::string fixed_scheme(url::kHttpScheme);
|
|
|
|
fixed_scheme.append(url::kStandardSchemeSeparator);
|
|
|
|
std::string new_url = url;
|
|
|
|
new_url.insert(0, fixed_scheme);
|
|
|
|
gurl = GURL(new_url);
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (fixup) {
|
2021-04-15 01:28:22 +02:00
|
|
|
FixupGURL(gurl);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-15 01:28:22 +02:00
|
|
|
return gurl;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FixupGURL(GURL& gurl) {
|
|
|
|
if (!gurl.is_empty()) {
|
|
|
|
GURL fixup_url =
|
|
|
|
url_formatter::FixupURL(gurl.possibly_invalid_spec(), std::string());
|
|
|
|
if (fixup_url.is_valid()) {
|
|
|
|
gurl = fixup_url;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Invalid URL: " << gurl.possibly_invalid_spec();
|
|
|
|
gurl = GURL();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace url_util
|