| 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) 2012, Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2012, 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 "tel", | 63 "tel", |
| 64 "urn", | 64 "urn", |
| 65 "webcal", | 65 "webcal", |
| 66 "wtai", | 66 "wtai", |
| 67 "xmpp", | 67 "xmpp", |
| 68 }; | 68 }; |
| 69 for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i) | 69 for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i) |
| 70 protocolWhitelist->add(protocols[i]); | 70 protocolWhitelist->add(protocols[i]); |
| 71 } | 71 } |
| 72 | 72 |
| 73 static bool verifyCustomHandlerURL(const String& baseURL, const String& url, Exc
eptionState& es) | 73 static bool verifyCustomHandlerURL(const String& baseURL, const String& url, Exc
eptionState& exceptionState) |
| 74 { | 74 { |
| 75 // The specification requires that it is a SyntaxError if the "%s" token is | 75 // The specification requires that it is a SyntaxError if the "%s" token is |
| 76 // not present. | 76 // not present. |
| 77 static const char token[] = "%s"; | 77 static const char token[] = "%s"; |
| 78 int index = url.find(token); | 78 int index = url.find(token); |
| 79 if (-1 == index) { | 79 if (-1 == index) { |
| 80 es.throwUninformativeAndGenericDOMException(SyntaxError); | 80 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); |
| 81 return false; | 81 return false; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // It is also a SyntaxError if the custom handler URL, as created by removin
g | 84 // It is also a SyntaxError if the custom handler URL, as created by removin
g |
| 85 // the "%s" token and prepending the base url, does not resolve. | 85 // the "%s" token and prepending the base url, does not resolve. |
| 86 String newURL = url; | 86 String newURL = url; |
| 87 newURL.remove(index, WTF_ARRAY_LENGTH(token) - 1); | 87 newURL.remove(index, WTF_ARRAY_LENGTH(token) - 1); |
| 88 | 88 |
| 89 KURL base(ParsedURLString, baseURL); | 89 KURL base(ParsedURLString, baseURL); |
| 90 KURL kurl(base, newURL); | 90 KURL kurl(base, newURL); |
| 91 | 91 |
| 92 if (kurl.isEmpty() || !kurl.isValid()) { | 92 if (kurl.isEmpty() || !kurl.isValid()) { |
| 93 es.throwUninformativeAndGenericDOMException(SyntaxError); | 93 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); |
| 94 return false; | 94 return false; |
| 95 } | 95 } |
| 96 | 96 |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 static bool isProtocolWhitelisted(const String& scheme) | 100 static bool isProtocolWhitelisted(const String& scheme) |
| 101 { | 101 { |
| 102 if (!protocolWhitelist) | 102 if (!protocolWhitelist) |
| 103 initProtocolHandlerWhitelist(); | 103 initProtocolHandlerWhitelist(); |
| 104 return protocolWhitelist->contains(scheme); | 104 return protocolWhitelist->contains(scheme); |
| 105 } | 105 } |
| 106 | 106 |
| 107 static bool verifyProtocolHandlerScheme(const String& scheme, const String& meth
od, ExceptionState& es) | 107 static bool verifyProtocolHandlerScheme(const String& scheme, const String& meth
od, ExceptionState& exceptionState) |
| 108 { | 108 { |
| 109 if (scheme.startsWith("web+")) { | 109 if (scheme.startsWith("web+")) { |
| 110 // The specification requires that the length of scheme is at least five
characteres (including 'web+' prefix). | 110 // The specification requires that the length of scheme is at least five
characteres (including 'web+' prefix). |
| 111 if (scheme.length() >= 5 && isValidProtocol(scheme)) | 111 if (scheme.length() >= 5 && isValidProtocol(scheme)) |
| 112 return true; | 112 return true; |
| 113 if (!isValidProtocol(scheme)) | 113 if (!isValidProtocol(scheme)) |
| 114 es.throwSecurityError(ExceptionMessages::failedToExecute(method, "Na
vigator", "The scheme '" + scheme + "' is not a valid protocol.")); | 114 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute
(method, "Navigator", "The scheme '" + scheme + "' is not a valid protocol.")); |
| 115 else | 115 else |
| 116 es.throwSecurityError(ExceptionMessages::failedToExecute(method, "Na
vigator", "The scheme '" + scheme + "' is less than five characters long.")); | 116 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute
(method, "Navigator", "The scheme '" + scheme + "' is less than five characters
long.")); |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 if (isProtocolWhitelisted(scheme)) | 120 if (isProtocolWhitelisted(scheme)) |
| 121 return true; | 121 return true; |
| 122 es.throwSecurityError(ExceptionMessages::failedToExecute(method, "Navigator"
, "The scheme '" + scheme + "' doesn't belong to the protocol whitelist. Please
prefix non-whitelisted schemes with the string 'web+'.")); | 122 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute(method,
"Navigator", "The scheme '" + scheme + "' doesn't belong to the protocol whitel
ist. Please prefix non-whitelisted schemes with the string 'web+'.")); |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 NavigatorContentUtils* NavigatorContentUtils::from(Page* page) | 126 NavigatorContentUtils* NavigatorContentUtils::from(Page* page) |
| 127 { | 127 { |
| 128 return static_cast<NavigatorContentUtils*>(RefCountedSupplement<Page, Naviga
torContentUtils>::from(page, NavigatorContentUtils::supplementName())); | 128 return static_cast<NavigatorContentUtils*>(RefCountedSupplement<Page, Naviga
torContentUtils>::from(page, NavigatorContentUtils::supplementName())); |
| 129 } | 129 } |
| 130 | 130 |
| 131 NavigatorContentUtils::~NavigatorContentUtils() | 131 NavigatorContentUtils::~NavigatorContentUtils() |
| 132 { | 132 { |
| 133 } | 133 } |
| 134 | 134 |
| 135 PassRefPtr<NavigatorContentUtils> NavigatorContentUtils::create(NavigatorContent
UtilsClient* client) | 135 PassRefPtr<NavigatorContentUtils> NavigatorContentUtils::create(NavigatorContent
UtilsClient* client) |
| 136 { | 136 { |
| 137 return adoptRef(new NavigatorContentUtils(client)); | 137 return adoptRef(new NavigatorContentUtils(client)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void NavigatorContentUtils::registerProtocolHandler(Navigator* navigator, const
String& scheme, const String& url, const String& title, ExceptionState& es) | 140 void NavigatorContentUtils::registerProtocolHandler(Navigator* navigator, const
String& scheme, const String& url, const String& title, ExceptionState& exceptio
nState) |
| 141 { | 141 { |
| 142 if (!navigator->frame()) | 142 if (!navigator->frame()) |
| 143 return; | 143 return; |
| 144 | 144 |
| 145 Document* document = navigator->frame()->document(); | 145 Document* document = navigator->frame()->document(); |
| 146 if (!document) | 146 if (!document) |
| 147 return; | 147 return; |
| 148 | 148 |
| 149 String baseURL = document->baseURL().baseAsString(); | 149 String baseURL = document->baseURL().baseAsString(); |
| 150 | 150 |
| 151 if (!verifyCustomHandlerURL(baseURL, url, es)) | 151 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) |
| 152 return; | 152 return; |
| 153 | 153 |
| 154 if (!verifyProtocolHandlerScheme(scheme, "registerProtocolHandler", es)) | 154 if (!verifyProtocolHandlerScheme(scheme, "registerProtocolHandler", exceptio
nState)) |
| 155 return; | 155 return; |
| 156 | 156 |
| 157 NavigatorContentUtils::from(navigator->frame()->page())->client()->registerP
rotocolHandler(scheme, baseURL, url, title); | 157 NavigatorContentUtils::from(navigator->frame()->page())->client()->registerP
rotocolHandler(scheme, baseURL, url, title); |
| 158 } | 158 } |
| 159 | 159 |
| 160 #if ENABLE(CUSTOM_SCHEME_HANDLER) | 160 #if ENABLE(CUSTOM_SCHEME_HANDLER) |
| 161 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo
mHandlersState state) | 161 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo
mHandlersState state) |
| 162 { | 162 { |
| 163 DEFINE_STATIC_LOCAL(const String, newHandler, ("new")); | 163 DEFINE_STATIC_LOCAL(const String, newHandler, ("new")); |
| 164 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered")); | 164 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered")); |
| 165 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined")); | 165 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined")); |
| 166 | 166 |
| 167 switch (state) { | 167 switch (state) { |
| 168 case NavigatorContentUtilsClient::CustomHandlersNew: | 168 case NavigatorContentUtilsClient::CustomHandlersNew: |
| 169 return newHandler; | 169 return newHandler; |
| 170 case NavigatorContentUtilsClient::CustomHandlersRegistered: | 170 case NavigatorContentUtilsClient::CustomHandlersRegistered: |
| 171 return registeredHandler; | 171 return registeredHandler; |
| 172 case NavigatorContentUtilsClient::CustomHandlersDeclined: | 172 case NavigatorContentUtilsClient::CustomHandlersDeclined: |
| 173 return declinedHandler; | 173 return declinedHandler; |
| 174 } | 174 } |
| 175 | 175 |
| 176 ASSERT_NOT_REACHED(); | 176 ASSERT_NOT_REACHED(); |
| 177 return String(); | 177 return String(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 String NavigatorContentUtils::isProtocolHandlerRegistered(Navigator* navigator,
const String& scheme, const String& url, ExceptionState& es) | 180 String NavigatorContentUtils::isProtocolHandlerRegistered(Navigator* navigator,
const String& scheme, const String& url, ExceptionState& exceptionState) |
| 181 { | 181 { |
| 182 DEFINE_STATIC_LOCAL(const String, declined, ("declined")); | 182 DEFINE_STATIC_LOCAL(const String, declined, ("declined")); |
| 183 | 183 |
| 184 if (!navigator->frame()) | 184 if (!navigator->frame()) |
| 185 return declined; | 185 return declined; |
| 186 | 186 |
| 187 Document* document = navigator->frame()->document(); | 187 Document* document = navigator->frame()->document(); |
| 188 String baseURL = document->baseURL().baseAsString(); | 188 String baseURL = document->baseURL().baseAsString(); |
| 189 | 189 |
| 190 if (!verifyCustomHandlerURL(baseURL, url, es)) | 190 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) |
| 191 return declined; | 191 return declined; |
| 192 | 192 |
| 193 if (!verifyProtocolHandlerScheme(scheme, "isProtocolHandlerRegistered", es)) | 193 if (!verifyProtocolHandlerScheme(scheme, "isProtocolHandlerRegistered", exce
ptionState)) |
| 194 return declined; | 194 return declined; |
| 195 | 195 |
| 196 return customHandlersStateString(NavigatorContentUtils::from(navigator->fram
e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, url)); | 196 return customHandlersStateString(NavigatorContentUtils::from(navigator->fram
e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, url)); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void NavigatorContentUtils::unregisterProtocolHandler(Navigator* navigator, cons
t String& scheme, const String& url, ExceptionState& es) | 199 void NavigatorContentUtils::unregisterProtocolHandler(Navigator* navigator, cons
t String& scheme, const String& url, ExceptionState& exceptionState) |
| 200 { | 200 { |
| 201 if (!navigator->frame()) | 201 if (!navigator->frame()) |
| 202 return; | 202 return; |
| 203 | 203 |
| 204 Document* document = navigator->frame()->document(); | 204 Document* document = navigator->frame()->document(); |
| 205 String baseURL = document->baseURL().baseAsString(); | 205 String baseURL = document->baseURL().baseAsString(); |
| 206 | 206 |
| 207 if (!verifyCustomHandlerURL(baseURL, url, es)) | 207 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) |
| 208 return; | 208 return; |
| 209 | 209 |
| 210 if (!verifyProtocolHandlerScheme(scheme, "unregisterProtocolHandler", es)) | 210 if (!verifyProtocolHandlerScheme(scheme, "unregisterProtocolHandler", except
ionState)) |
| 211 return; | 211 return; |
| 212 | 212 |
| 213 NavigatorContentUtils::from(navigator->frame()->page())->client()->unregiste
rProtocolHandler(scheme, baseURL, url); | 213 NavigatorContentUtils::from(navigator->frame()->page())->client()->unregiste
rProtocolHandler(scheme, baseURL, url); |
| 214 } | 214 } |
| 215 #endif | 215 #endif |
| 216 | 216 |
| 217 const char* NavigatorContentUtils::supplementName() | 217 const char* NavigatorContentUtils::supplementName() |
| 218 { | 218 { |
| 219 return "NavigatorContentUtils"; | 219 return "NavigatorContentUtils"; |
| 220 } | 220 } |
| 221 | 221 |
| 222 void provideNavigatorContentUtilsTo(Page* page, NavigatorContentUtilsClient* cli
ent) | 222 void provideNavigatorContentUtilsTo(Page* page, NavigatorContentUtilsClient* cli
ent) |
| 223 { | 223 { |
| 224 RefCountedSupplement<Page, NavigatorContentUtils>::provideTo(page, Navigator
ContentUtils::supplementName(), NavigatorContentUtils::create(client)); | 224 RefCountedSupplement<Page, NavigatorContentUtils>::provideTo(page, Navigator
ContentUtils::supplementName(), NavigatorContentUtils::create(client)); |
| 225 } | 225 } |
| 226 | 226 |
| 227 } // namespace WebCore | 227 } // namespace WebCore |
| 228 | 228 |
| 229 #endif // ENABLE(NAVIGATOR_CONTENT_UTILS) | 229 #endif // ENABLE(NAVIGATOR_CONTENT_UTILS) |
| 230 | 230 |
| OLD | NEW |