OLD | NEW |
---|---|
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(protocols); ++i) |
68 protocolWhitelist->add(protocols[i]); | 68 protocolWhitelist->add(protocols[i]); |
69 } | 69 } |
70 | 70 |
71 static bool verifyCustomHandlerURL(const KURL& baseURL, const String& url, Excep tionState& exceptionState) | 71 static bool verifyCustomHandlerURL(const Document& document, const KURL& baseURL , const String& url, ExceptionState& 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 // The specification says that the API throws SecurityError exception if the URL's origin differs from the document's origin. | |
95 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(kurl); | |
96 if (!origin->isSameSchemeHostPort(document.securityOrigin())) { | |
abarth-chromium
2014/07/16 16:32:39
You don't really ever want to call isSameSchemeHos
pals
2014/07/18 14:17:54
Done.
| |
97 exceptionState.throwSecurityError("Can only register handler in the docu ment's origin."); | |
gyuyoung-inactive
2014/07/16 06:20:17
Isn't it better mention "custom handler" instead o
pals
2014/07/18 14:17:54
Done.
| |
98 return false; | |
99 } | |
100 | |
94 return true; | 101 return true; |
95 } | 102 } |
96 | 103 |
97 static bool isProtocolWhitelisted(const String& scheme) | 104 static bool isProtocolWhitelisted(const String& scheme) |
98 { | 105 { |
99 if (!protocolWhitelist) | 106 if (!protocolWhitelist) |
100 initProtocolHandlerWhitelist(); | 107 initProtocolHandlerWhitelist(); |
101 | 108 |
102 StringBuilder builder; | 109 StringBuilder builder; |
103 unsigned length = scheme.length(); | 110 unsigned length = scheme.length(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 PassOwnPtrWillBeRawPtr<NavigatorContentUtils> NavigatorContentUtils::create(Pass OwnPtr<NavigatorContentUtilsClient> client) | 149 PassOwnPtrWillBeRawPtr<NavigatorContentUtils> NavigatorContentUtils::create(Pass OwnPtr<NavigatorContentUtilsClient> client) |
143 { | 150 { |
144 return adoptPtrWillBeNoop(new NavigatorContentUtils(client)); | 151 return adoptPtrWillBeNoop(new NavigatorContentUtils(client)); |
145 } | 152 } |
146 | 153 |
147 void NavigatorContentUtils::registerProtocolHandler(Navigator& navigator, const String& scheme, const String& url, const String& title, ExceptionState& exceptio nState) | 154 void NavigatorContentUtils::registerProtocolHandler(Navigator& navigator, const String& scheme, const String& url, const String& title, ExceptionState& exceptio nState) |
148 { | 155 { |
149 if (!navigator.frame()) | 156 if (!navigator.frame()) |
150 return; | 157 return; |
151 | 158 |
152 ASSERT(navigator.frame()->document()); | 159 Document* document = navigator.frame()->document(); |
153 KURL baseURL = navigator.frame()->document()->baseURL(); | 160 ASSERT(document); |
161 KURL baseURL = document->baseURL(); | |
154 | 162 |
155 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) | 163 if (!verifyCustomHandlerURL(*document, baseURL, url, exceptionState)) |
abarth-chromium
2014/07/16 16:32:39
Why don't we just pass in the complete URL to veri
gyuyoung-inactive
2014/07/17 07:01:19
We are passing baseURL and registered url to clien
pals
2014/07/18 14:17:53
Done.
| |
156 return; | 164 return; |
157 | 165 |
158 if (!verifyProtocolHandlerScheme(scheme, "registerProtocolHandler", exceptio nState)) | 166 if (!verifyProtocolHandlerScheme(scheme, "registerProtocolHandler", exceptio nState)) |
159 return; | 167 return; |
160 | 168 |
161 ASSERT(navigator.frame()->page()); | 169 ASSERT(navigator.frame()->page()); |
162 NavigatorContentUtils::from(*navigator.frame()->page())->client()->registerP rotocolHandler(scheme, baseURL, KURL(ParsedURLString, url), title); | 170 NavigatorContentUtils::from(*navigator.frame()->page())->client()->registerP rotocolHandler(scheme, baseURL, KURL(ParsedURLString, url), title); |
163 } | 171 } |
164 | 172 |
165 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo mHandlersState state) | 173 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo mHandlersState state) |
(...skipping 22 matching lines...) Expand all Loading... | |
188 if (!navigator.frame()) | 196 if (!navigator.frame()) |
189 return declined; | 197 return declined; |
190 | 198 |
191 Document* document = navigator.frame()->document(); | 199 Document* document = navigator.frame()->document(); |
192 ASSERT(document); | 200 ASSERT(document); |
193 if (document->activeDOMObjectsAreStopped()) | 201 if (document->activeDOMObjectsAreStopped()) |
194 return declined; | 202 return declined; |
195 | 203 |
196 KURL baseURL = document->baseURL(); | 204 KURL baseURL = document->baseURL(); |
197 | 205 |
198 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) | 206 if (!verifyCustomHandlerURL(*document, baseURL, url, exceptionState)) |
199 return declined; | 207 return declined; |
200 | 208 |
201 if (!verifyProtocolHandlerScheme(scheme, "isProtocolHandlerRegistered", exce ptionState)) | 209 if (!verifyProtocolHandlerScheme(scheme, "isProtocolHandlerRegistered", exce ptionState)) |
202 return declined; | 210 return declined; |
203 | 211 |
204 ASSERT(navigator.frame()->page()); | 212 ASSERT(navigator.frame()->page()); |
205 return customHandlersStateString(NavigatorContentUtils::from(*navigator.fram e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, KURL(Parsed URLString, url))); | 213 return customHandlersStateString(NavigatorContentUtils::from(*navigator.fram e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, KURL(Parsed URLString, url))); |
206 } | 214 } |
207 | 215 |
208 void NavigatorContentUtils::unregisterProtocolHandler(Navigator& navigator, cons t String& scheme, const String& url, ExceptionState& exceptionState) | 216 void NavigatorContentUtils::unregisterProtocolHandler(Navigator& navigator, cons t String& scheme, const String& url, ExceptionState& exceptionState) |
209 { | 217 { |
210 if (!navigator.frame()) | 218 if (!navigator.frame()) |
211 return; | 219 return; |
212 | 220 |
213 ASSERT(navigator.frame()->document()); | 221 Document* document = navigator.frame()->document(); |
214 KURL baseURL = navigator.frame()->document()->baseURL(); | 222 ASSERT(document); |
223 KURL baseURL = document->baseURL(); | |
215 | 224 |
216 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) | 225 if (!verifyCustomHandlerURL(*document, baseURL, url, exceptionState)) |
217 return; | 226 return; |
218 | 227 |
219 if (!verifyProtocolHandlerScheme(scheme, "unregisterProtocolHandler", except ionState)) | 228 if (!verifyProtocolHandlerScheme(scheme, "unregisterProtocolHandler", except ionState)) |
220 return; | 229 return; |
221 | 230 |
222 ASSERT(navigator.frame()->page()); | 231 ASSERT(navigator.frame()->page()); |
223 NavigatorContentUtils::from(*navigator.frame()->page())->client()->unregiste rProtocolHandler(scheme, baseURL, KURL(ParsedURLString, url)); | 232 NavigatorContentUtils::from(*navigator.frame()->page())->client()->unregiste rProtocolHandler(scheme, baseURL, KURL(ParsedURLString, url)); |
224 } | 233 } |
225 | 234 |
226 const char* NavigatorContentUtils::supplementName() | 235 const char* NavigatorContentUtils::supplementName() |
227 { | 236 { |
228 return "NavigatorContentUtils"; | 237 return "NavigatorContentUtils"; |
229 } | 238 } |
230 | 239 |
231 void provideNavigatorContentUtilsTo(Page& page, PassOwnPtr<NavigatorContentUtils Client> client) | 240 void provideNavigatorContentUtilsTo(Page& page, PassOwnPtr<NavigatorContentUtils Client> client) |
232 { | 241 { |
233 NavigatorContentUtils::provideTo(page, NavigatorContentUtils::supplementName (), NavigatorContentUtils::create(client)); | 242 NavigatorContentUtils::provideTo(page, NavigatorContentUtils::supplementName (), NavigatorContentUtils::create(client)); |
234 } | 243 } |
235 | 244 |
236 } // namespace WebCore | 245 } // namespace WebCore |
OLD | NEW |