| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "ios/web/public/origin_util.h" | 5 #import "ios/web/public/origin_util.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "net/base/url_util.h" | 11 #include "net/base/url_util.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 #include "url/scheme_host_port.h" | 13 #include "url/scheme_host_port.h" |
| 14 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." | 16 #error "This file requires ARC support." |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace web { | 19 namespace web { |
| 20 | 20 |
| 21 bool IsOriginSecure(const GURL& url) { | 21 bool IsOriginSecure(const GURL& url) { |
| 22 if (url.SchemeIsCryptographic() || url.SchemeIsFile()) | 22 if (url.SchemeIsCryptographic() || url.SchemeIsFile()) |
| 23 return true; | 23 return true; |
| 24 | 24 |
| 25 if (url.SchemeIsFileSystem() && url.inner_url() && | 25 if (url.SchemeIsFileSystem() && url.inner_url() && |
| 26 IsOriginSecure(*url.inner_url())) { | 26 IsOriginSecure(*url.inner_url())) { |
| 27 return true; | 27 return true; |
| 28 } | 28 } |
| 29 | 29 |
| 30 std::string hostname = url.HostNoBrackets(); | 30 if (net::IsLocalhost(url.HostNoBracketsPiece())) |
| 31 if (net::IsLocalhost(hostname)) | |
| 32 return true; | 31 return true; |
| 33 | 32 |
| 34 return false; | 33 return false; |
| 35 } | 34 } |
| 36 | 35 |
| 37 GURL GURLOriginWithWKSecurityOrigin(WKSecurityOrigin* origin) { | 36 GURL GURLOriginWithWKSecurityOrigin(WKSecurityOrigin* origin) { |
| 38 if (!origin) | 37 if (!origin) |
| 39 return GURL(); | 38 return GURL(); |
| 40 | 39 |
| 41 url::SchemeHostPort origin_tuple(base::SysNSStringToUTF8(origin.protocol), | 40 url::SchemeHostPort origin_tuple(base::SysNSStringToUTF8(origin.protocol), |
| 42 base::SysNSStringToUTF8(origin.host), | 41 base::SysNSStringToUTF8(origin.host), |
| 43 base::checked_cast<uint16_t>(origin.port)); | 42 base::checked_cast<uint16_t>(origin.port)); |
| 44 return origin_tuple.GetURL(); | 43 return origin_tuple.GetURL(); |
| 45 } | 44 } |
| 46 | 45 |
| 47 } // namespace web | 46 } // namespace web |
| OLD | NEW |