Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: Source/modules/navigatorcontentutils/NavigatorContentUtils.cpp

Issue 440833006: Use a consistent scheme name in navigatorcontentutils tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « LayoutTests/navigatorcontentutils/unregister-protocol-handler-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, Google Inc. All rights reserved. 2 * Copyright (C) 2011, Google Inc. All rights reserved.
3 * Copyright (C) 2014, Samsung Electronics. All rights reserved. 3 * Copyright (C) 2014, Samsung Electronics. 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 are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
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 20 matching lines...) Expand all
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "core/dom/ExceptionCode.h" 32 #include "core/dom/ExceptionCode.h"
33 #include "core/frame/LocalFrame.h" 33 #include "core/frame/LocalFrame.h"
34 #include "core/frame/Navigator.h" 34 #include "core/frame/Navigator.h"
35 #include "core/page/Page.h" 35 #include "core/page/Page.h"
36 #include "wtf/HashSet.h" 36 #include "wtf/HashSet.h"
37 #include "wtf/text/StringBuilder.h" 37 #include "wtf/text/StringBuilder.h"
38 38
39 namespace blink { 39 namespace blink {
40 40
41 static HashSet<String>* protocolWhitelist; 41 static HashSet<String>* schemeWhitelist;
42 42
43 static void initProtocolHandlerWhitelist() 43 static void initCustomSchemeHandlerWhitelist()
44 { 44 {
45 protocolWhitelist = new HashSet<String>; 45 schemeWhitelist = new HashSet<String>;
46 static const char* const protocols[] = { 46 static const char* const schemes[] = {
47 "bitcoin", 47 "bitcoin",
48 "geo", 48 "geo",
49 "im", 49 "im",
50 "irc", 50 "irc",
51 "ircs", 51 "ircs",
52 "magnet", 52 "magnet",
53 "mailto", 53 "mailto",
54 "mms", 54 "mms",
55 "news", 55 "news",
56 "nntp", 56 "nntp",
57 "sip", 57 "sip",
58 "sms", 58 "sms",
59 "smsto", 59 "smsto",
60 "ssh", 60 "ssh",
61 "tel", 61 "tel",
62 "urn", 62 "urn",
63 "webcal", 63 "webcal",
64 "wtai", 64 "wtai",
65 "xmpp", 65 "xmpp",
66 }; 66 };
67 for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i) 67 for (size_t i = 0; i < WTF_ARRAY_LENGTH(schemes); ++i)
68 protocolWhitelist->add(protocols[i]); 68 schemeWhitelist->add(schemes[i]);
69 } 69 }
70 70
71 static bool verifyCustomHandlerURL(const KURL& baseURL, const String& url, Excep tionState& exceptionState) 71 static bool verifyCustomHandlerURL(const KURL& baseURL, const String& url, Excep tionState& exceptionState)
72 { 72 {
73 // The specification requires that it is a SyntaxError if the "%s" token is 73 // The specification requires that it is a SyntaxError if the "%s" token is
74 // not present. 74 // not present.
75 static const char token[] = "%s"; 75 static const char token[] = "%s";
76 int index = url.find(token); 76 int index = url.find(token);
77 if (-1 == index) { 77 if (-1 == index) {
78 exceptionState.throwDOMException(SyntaxError, "The url provided ('" + ur l + "') does not contain '%s'."); 78 exceptionState.throwDOMException(SyntaxError, "The url provided ('" + ur l + "') does not contain '%s'.");
79 return false; 79 return false;
80 } 80 }
81 81
82 // It is also a SyntaxError if the custom handler URL, as created by removin g 82 // It is also a SyntaxError if the custom handler URL, as created by removin g
83 // the "%s" token and prepending the base url, does not resolve. 83 // the "%s" token and prepending the base url, does not resolve.
84 String newURL = url; 84 String newURL = url;
85 newURL.remove(index, WTF_ARRAY_LENGTH(token) - 1); 85 newURL.remove(index, WTF_ARRAY_LENGTH(token) - 1);
86 86
87 KURL kurl(baseURL, newURL); 87 KURL kurl(baseURL, newURL);
88 88
89 if (kurl.isEmpty() || !kurl.isValid()) { 89 if (kurl.isEmpty() || !kurl.isValid()) {
90 exceptionState.throwDOMException(SyntaxError, "The custom handler URL cr eated by removing '%s' and prepending '" + baseURL.string() + "' is invalid."); 90 exceptionState.throwDOMException(SyntaxError, "The custom handler URL cr eated by removing '%s' and prepending '" + baseURL.string() + "' is invalid.");
91 return false; 91 return false;
92 } 92 }
93 93
94 return true; 94 return true;
95 } 95 }
96 96
97 static bool isProtocolWhitelisted(const String& scheme) 97 static bool isSchemeWhitelisted(const String& scheme)
98 { 98 {
99 if (!protocolWhitelist) 99 if (!schemeWhitelist)
100 initProtocolHandlerWhitelist(); 100 initCustomSchemeHandlerWhitelist();
101 101
102 StringBuilder builder; 102 StringBuilder builder;
103 unsigned length = scheme.length(); 103 unsigned length = scheme.length();
104 for (unsigned i = 0; i < length; ++i) 104 for (unsigned i = 0; i < length; ++i)
105 builder.append(toASCIILower(scheme[i])); 105 builder.append(toASCIILower(scheme[i]));
106 106
107 return protocolWhitelist->contains(builder.toString()); 107 return schemeWhitelist->contains(builder.toString());
108 } 108 }
109 109
110 static bool verifyCustomHandlerScheme(const String& scheme, ExceptionState& exce ptionState) 110 static bool verifyCustomHandlerScheme(const String& scheme, ExceptionState& exce ptionState)
111 { 111 {
112 if (!isValidProtocol(scheme)) { 112 if (!isValidProtocol(scheme)) {
113 exceptionState.throwSecurityError("The scheme '" + scheme + "' is not va lid protocol"); 113 exceptionState.throwSecurityError("The scheme '" + scheme + "' is not va lid protocol");
114 return false; 114 return false;
115 } 115 }
116 116
117 if (scheme.startsWith("web+")) { 117 if (scheme.startsWith("web+")) {
118 // The specification requires that the length of scheme is at least five characteres (including 'web+' prefix). 118 // The specification requires that the length of scheme is at least five characteres (including 'web+' prefix).
119 if (scheme.length() >= 5) 119 if (scheme.length() >= 5)
120 return true; 120 return true;
121 121
122 exceptionState.throwSecurityError("The scheme '" + scheme + "' is less t han five characters long."); 122 exceptionState.throwSecurityError("The scheme '" + scheme + "' is less t han five characters long.");
123 return false; 123 return false;
124 } 124 }
125 125
126 if (isProtocolWhitelisted(scheme)) 126 if (isSchemeWhitelisted(scheme))
127 return true; 127 return true;
128 128
129 exceptionState.throwSecurityError("The scheme '" + scheme + "' doesn't belon g to the protocol whitelist. Please prefix non-whitelisted schemes with the stri ng 'web+'."); 129 exceptionState.throwSecurityError("The scheme '" + scheme + "' doesn't belon g to the scheme whitelist. Please prefix non-whitelisted schemes with the string 'web+'.");
130 return false; 130 return false;
131 } 131 }
132 132
133 NavigatorContentUtils* NavigatorContentUtils::from(Page& page) 133 NavigatorContentUtils* NavigatorContentUtils::from(Page& page)
134 { 134 {
135 return static_cast<NavigatorContentUtils*>(WillBeHeapSupplement<Page>::from( page, supplementName())); 135 return static_cast<NavigatorContentUtils*>(WillBeHeapSupplement<Page>::from( page, supplementName()));
136 } 136 }
137 137
138 NavigatorContentUtils::~NavigatorContentUtils() 138 NavigatorContentUtils::~NavigatorContentUtils()
139 { 139 {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 { 227 {
228 return "NavigatorContentUtils"; 228 return "NavigatorContentUtils";
229 } 229 }
230 230
231 void provideNavigatorContentUtilsTo(Page& page, PassOwnPtr<NavigatorContentUtils Client> client) 231 void provideNavigatorContentUtilsTo(Page& page, PassOwnPtr<NavigatorContentUtils Client> client)
232 { 232 {
233 NavigatorContentUtils::provideTo(page, NavigatorContentUtils::supplementName (), NavigatorContentUtils::create(client)); 233 NavigatorContentUtils::provideTo(page, NavigatorContentUtils::supplementName (), NavigatorContentUtils::create(client));
234 } 234 }
235 235
236 } // namespace blink 236 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/navigatorcontentutils/unregister-protocol-handler-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698