Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. | 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 switch (port) { | 41 switch (port) { |
| 42 case 80: | 42 case 80: |
| 43 return protocol == "http" || protocol == "ws"; | 43 return protocol == "http" || protocol == "ws"; |
| 44 case 443: | 44 case 443: |
| 45 return protocol == "https" || protocol == "wss"; | 45 return protocol == "https" || protocol == "wss"; |
| 46 case 21: | 46 case 21: |
| 47 return protocol == "ftp"; | 47 return protocol == "ftp"; |
| 48 case 990: | 48 case 990: |
| 49 return protocol == "ftps"; | 49 return protocol == "ftps"; |
| 50 case 70: | |
| 51 return protocol == "gopher"; | |
|
Mike West
2016/10/11 08:38:33
This seems unrelated? Moreover, we don't actually
ncarter (slow)
2016/10/11 18:21:52
Agree, we don't handle gopher, and won't ever. I'v
| |
| 50 } | 52 } |
| 51 return false; | 53 return false; |
| 52 } | 54 } |
| 53 | 55 |
| 54 unsigned short defaultPortForProtocol(const WTF::String& protocol) { | 56 unsigned short defaultPortForProtocol(const WTF::String& protocol) { |
| 55 if (protocol == "http" || protocol == "ws") | 57 if (protocol == "http" || protocol == "ws") |
| 56 return 80; | 58 return 80; |
| 57 if (protocol == "https" || protocol == "wss") | 59 if (protocol == "https" || protocol == "wss") |
| 58 return 443; | 60 return 443; |
| 59 if (protocol == "ftp") | 61 if (protocol == "ftp") |
| 60 return 21; | 62 return 21; |
| 61 if (protocol == "ftps") | 63 if (protocol == "ftps") |
| 62 return 990; | 64 return 990; |
| 65 if (protocol == "gopher") | |
| 66 return 70; | |
| 63 | 67 |
| 64 return 0; | 68 return 0; |
| 65 } | 69 } |
| 66 | 70 |
| 67 bool isPortAllowedForScheme(const KURL& url) { | 71 bool isPortAllowedForScheme(const KURL& url) { |
| 68 // Returns true for URLs without a port specified. This is needed to let | 72 // Returns true for URLs without a port specified. This is needed to let |
| 69 // through non-network schemes that don't go over the network. | 73 // through non-network schemes that don't go over the network. |
| 70 if (!url.hasPort()) | 74 if (!url.hasPort()) |
| 71 return true; | 75 return true; |
| 72 String protocol = url.protocol().isNull() ? "" : url.protocol().lower(); | 76 String protocol = url.protocol().isNull() ? "" : url.protocol().lower(); |
| 73 unsigned short effectivePort = url.port(); | 77 unsigned short effectivePort = url.port(); |
| 74 if (!effectivePort) | 78 if (!effectivePort) |
| 75 effectivePort = defaultPortForProtocol(protocol); | 79 effectivePort = defaultPortForProtocol(protocol); |
| 76 StringUTF8Adaptor utf8(protocol); | 80 StringUTF8Adaptor utf8(protocol); |
| 77 return net::IsPortAllowedForScheme(effectivePort, | 81 return net::IsPortAllowedForScheme(effectivePort, |
| 78 std::string(utf8.data(), utf8.length())); | 82 std::string(utf8.data(), utf8.length())); |
| 79 } | 83 } |
| 80 | 84 |
| 81 } // namespace blink | 85 } // namespace blink |
| OLD | NEW |