1 // Copyright (c) 2021 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #include "libcef/common/net/url_util.h" 6 7 #include "base/logging.h" 8 #include "components/url_formatter/url_fixer.h" 9 10 namespace url_util { 11 MakeGURL(const CefString & url,bool fixup)12GURL MakeGURL(const CefString& url, bool fixup) { 13 GURL gurl = GURL(url.ToString()); 14 if (!url.empty() && !gurl.is_valid() && !gurl.has_scheme()) { 15 std::string fixed_scheme(url::kHttpScheme); 16 fixed_scheme.append(url::kStandardSchemeSeparator); 17 std::string new_url = url; 18 new_url.insert(0, fixed_scheme); 19 gurl = GURL(new_url); 20 } 21 if (fixup) 22 FixupGURL(gurl); 23 return gurl; 24 } 25 FixupGURL(GURL & gurl)26bool FixupGURL(GURL& gurl) { 27 if (!gurl.is_empty()) { 28 GURL fixup_url = 29 url_formatter::FixupURL(gurl.possibly_invalid_spec(), std::string()); 30 if (fixup_url.is_valid()) { 31 gurl = fixup_url; 32 } else { 33 LOG(ERROR) << "Invalid URL: " << gurl.possibly_invalid_spec(); 34 gurl = GURL(); 35 return false; 36 } 37 } 38 return true; 39 } 40 41 } // namespace url_util 42