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 11 matching lines...) Expand all Loading... |
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
24 * DAMAGE. | 24 * DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "modules/navigatorcontentutils/NavigatorContentUtils.h" | 28 #include "modules/navigatorcontentutils/NavigatorContentUtils.h" |
29 | 29 |
30 #if ENABLE(NAVIGATOR_CONTENT_UTILS) | 30 #if ENABLE(NAVIGATOR_CONTENT_UTILS) |
31 | 31 |
32 #include "bindings/v8/ExceptionState.h" | |
33 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
34 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
35 #include "core/page/Frame.h" | 34 #include "core/page/Frame.h" |
36 #include "core/page/Navigator.h" | 35 #include "core/page/Navigator.h" |
37 #include "core/page/Page.h" | 36 #include "core/page/Page.h" |
38 #include "wtf/HashSet.h" | 37 #include "wtf/HashSet.h" |
39 | 38 |
40 namespace WebCore { | 39 namespace WebCore { |
41 | 40 |
42 static HashSet<String>* protocolWhitelist; | 41 static HashSet<String>* protocolWhitelist; |
(...skipping 16 matching lines...) Expand all Loading... |
59 "ssh", | 58 "ssh", |
60 "tel", | 59 "tel", |
61 "urn", | 60 "urn", |
62 "webcal", | 61 "webcal", |
63 "xmpp", | 62 "xmpp", |
64 }; | 63 }; |
65 for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i) | 64 for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i) |
66 protocolWhitelist->add(protocols[i]); | 65 protocolWhitelist->add(protocols[i]); |
67 } | 66 } |
68 | 67 |
69 static bool verifyCustomHandlerURL(const String& baseURL, const String& url, Exc
eptionState& es) | 68 static bool verifyCustomHandlerURL(const String& baseURL, const String& url, Exc
eptionCode& ec) |
70 { | 69 { |
71 // The specification requires that it is a SyntaxError if the "%s" token is | 70 // The specification requires that it is a SyntaxError if the "%s" token is |
72 // not present. | 71 // not present. |
73 static const char token[] = "%s"; | 72 static const char token[] = "%s"; |
74 int index = url.find(token); | 73 int index = url.find(token); |
75 if (-1 == index) { | 74 if (-1 == index) { |
76 es.throwDOMException(SyntaxError); | 75 ec = SyntaxError; |
77 return false; | 76 return false; |
78 } | 77 } |
79 | 78 |
80 // It is also a SyntaxError if the custom handler URL, as created by removin
g | 79 // It is also a SyntaxError if the custom handler URL, as created by removin
g |
81 // the "%s" token and prepending the base url, does not resolve. | 80 // the "%s" token and prepending the base url, does not resolve. |
82 String newURL = url; | 81 String newURL = url; |
83 newURL.remove(index, WTF_ARRAY_LENGTH(token) - 1); | 82 newURL.remove(index, WTF_ARRAY_LENGTH(token) - 1); |
84 | 83 |
85 KURL base(ParsedURLString, baseURL); | 84 KURL base(ParsedURLString, baseURL); |
86 KURL kurl(base, newURL); | 85 KURL kurl(base, newURL); |
87 | 86 |
88 if (kurl.isEmpty() || !kurl.isValid()) { | 87 if (kurl.isEmpty() || !kurl.isValid()) { |
89 es.throwDOMException(SyntaxError); | 88 ec = SyntaxError; |
90 return false; | 89 return false; |
91 } | 90 } |
92 | 91 |
93 return true; | 92 return true; |
94 } | 93 } |
95 | 94 |
96 static bool isProtocolWhitelisted(const String& scheme) | 95 static bool isProtocolWhitelisted(const String& scheme) |
97 { | 96 { |
98 if (!protocolWhitelist) | 97 if (!protocolWhitelist) |
99 initProtocolHandlerWhitelist(); | 98 initProtocolHandlerWhitelist(); |
100 return protocolWhitelist->contains(scheme); | 99 return protocolWhitelist->contains(scheme); |
101 } | 100 } |
102 | 101 |
103 static bool verifyProtocolHandlerScheme(const String& scheme, ExceptionState& es
) | 102 static bool verifyProtocolHandlerScheme(const String& scheme, ExceptionCode& ec) |
104 { | 103 { |
105 if (scheme.startsWith("web+")) { | 104 if (scheme.startsWith("web+")) { |
106 if (isValidProtocol(scheme)) | 105 if (isValidProtocol(scheme)) |
107 return true; | 106 return true; |
108 es.throwDOMException(SecurityError); | 107 ec = SecurityError; |
109 return false; | 108 return false; |
110 } | 109 } |
111 | 110 |
112 if (isProtocolWhitelisted(scheme)) | 111 if (isProtocolWhitelisted(scheme)) |
113 return true; | 112 return true; |
114 es.throwDOMException(SecurityError); | 113 ec = SecurityError; |
115 return false; | 114 return false; |
116 } | 115 } |
117 | 116 |
118 NavigatorContentUtils* NavigatorContentUtils::from(Page* page) | 117 NavigatorContentUtils* NavigatorContentUtils::from(Page* page) |
119 { | 118 { |
120 return static_cast<NavigatorContentUtils*>(RefCountedSupplement<Page, Naviga
torContentUtils>::from(page, NavigatorContentUtils::supplementName())); | 119 return static_cast<NavigatorContentUtils*>(RefCountedSupplement<Page, Naviga
torContentUtils>::from(page, NavigatorContentUtils::supplementName())); |
121 } | 120 } |
122 | 121 |
123 NavigatorContentUtils::~NavigatorContentUtils() | 122 NavigatorContentUtils::~NavigatorContentUtils() |
124 { | 123 { |
125 } | 124 } |
126 | 125 |
127 PassRefPtr<NavigatorContentUtils> NavigatorContentUtils::create(NavigatorContent
UtilsClient* client) | 126 PassRefPtr<NavigatorContentUtils> NavigatorContentUtils::create(NavigatorContent
UtilsClient* client) |
128 { | 127 { |
129 return adoptRef(new NavigatorContentUtils(client)); | 128 return adoptRef(new NavigatorContentUtils(client)); |
130 } | 129 } |
131 | 130 |
132 void NavigatorContentUtils::registerProtocolHandler(Navigator* navigator, const
String& scheme, const String& url, const String& title, ExceptionState& es) | 131 void NavigatorContentUtils::registerProtocolHandler(Navigator* navigator, const
String& scheme, const String& url, const String& title, ExceptionCode& ec) |
133 { | 132 { |
134 if (!navigator->frame()) | 133 if (!navigator->frame()) |
135 return; | 134 return; |
136 | 135 |
137 Document* document = navigator->frame()->document(); | 136 Document* document = navigator->frame()->document(); |
138 if (!document) | 137 if (!document) |
139 return; | 138 return; |
140 | 139 |
141 String baseURL = document->baseURL().baseAsString(); | 140 String baseURL = document->baseURL().baseAsString(); |
142 | 141 |
143 if (!verifyCustomHandlerURL(baseURL, url, es)) | 142 if (!verifyCustomHandlerURL(baseURL, url, ec)) |
144 return; | 143 return; |
145 | 144 |
146 if (!verifyProtocolHandlerScheme(scheme, es)) | 145 if (!verifyProtocolHandlerScheme(scheme, ec)) |
147 return; | 146 return; |
148 | 147 |
149 NavigatorContentUtils::from(navigator->frame()->page())->client()->registerP
rotocolHandler(scheme, baseURL, url, navigator->frame()->displayStringModifiedBy
Encoding(title)); | 148 NavigatorContentUtils::from(navigator->frame()->page())->client()->registerP
rotocolHandler(scheme, baseURL, url, navigator->frame()->displayStringModifiedBy
Encoding(title)); |
150 } | 149 } |
151 | 150 |
152 #if ENABLE(CUSTOM_SCHEME_HANDLER) | 151 #if ENABLE(CUSTOM_SCHEME_HANDLER) |
153 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo
mHandlersState state) | 152 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo
mHandlersState state) |
154 { | 153 { |
155 DEFINE_STATIC_LOCAL(const String, newHandler, (ASCIILiteral("new"))); | 154 DEFINE_STATIC_LOCAL(const String, newHandler, (ASCIILiteral("new"))); |
156 DEFINE_STATIC_LOCAL(const String, registeredHandler, (ASCIILiteral("register
ed"))); | 155 DEFINE_STATIC_LOCAL(const String, registeredHandler, (ASCIILiteral("register
ed"))); |
157 DEFINE_STATIC_LOCAL(const String, declinedHandler, (ASCIILiteral("declined")
)); | 156 DEFINE_STATIC_LOCAL(const String, declinedHandler, (ASCIILiteral("declined")
)); |
158 | 157 |
159 switch (state) { | 158 switch (state) { |
160 case NavigatorContentUtilsClient::CustomHandlersNew: | 159 case NavigatorContentUtilsClient::CustomHandlersNew: |
161 return newHandler; | 160 return newHandler; |
162 case NavigatorContentUtilsClient::CustomHandlersRegistered: | 161 case NavigatorContentUtilsClient::CustomHandlersRegistered: |
163 return registeredHandler; | 162 return registeredHandler; |
164 case NavigatorContentUtilsClient::CustomHandlersDeclined: | 163 case NavigatorContentUtilsClient::CustomHandlersDeclined: |
165 return declinedHandler; | 164 return declinedHandler; |
166 } | 165 } |
167 | 166 |
168 ASSERT_NOT_REACHED(); | 167 ASSERT_NOT_REACHED(); |
169 return String(); | 168 return String(); |
170 } | 169 } |
171 | 170 |
172 String NavigatorContentUtils::isProtocolHandlerRegistered(Navigator* navigator,
const String& scheme, const String& url, ExceptionState& es) | 171 String NavigatorContentUtils::isProtocolHandlerRegistered(Navigator* navigator,
const String& scheme, const String& url, ExceptionCode& ec) |
173 { | 172 { |
174 DEFINE_STATIC_LOCAL(const String, declined, ("declined")); | 173 DEFINE_STATIC_LOCAL(const String, declined, ("declined")); |
175 | 174 |
176 if (!navigator->frame()) | 175 if (!navigator->frame()) |
177 return declined; | 176 return declined; |
178 | 177 |
179 Document* document = navigator->frame()->document(); | 178 Document* document = navigator->frame()->document(); |
180 String baseURL = document->baseURL().baseAsString(); | 179 String baseURL = document->baseURL().baseAsString(); |
181 | 180 |
182 if (!verifyCustomHandlerURL(baseURL, url, es)) | 181 if (!verifyCustomHandlerURL(baseURL, url, ec)) |
183 return declined; | 182 return declined; |
184 | 183 |
185 if (!verifyProtocolHandlerScheme(scheme, es)) | 184 if (!verifyProtocolHandlerScheme(scheme, ec)) |
186 return declined; | 185 return declined; |
187 | 186 |
188 return customHandlersStateString(NavigatorContentUtils::from(navigator->fram
e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, url)); | 187 return customHandlersStateString(NavigatorContentUtils::from(navigator->fram
e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, url)); |
189 } | 188 } |
190 | 189 |
191 void NavigatorContentUtils::unregisterProtocolHandler(Navigator* navigator, cons
t String& scheme, const String& url, ExceptionState& es) | 190 void NavigatorContentUtils::unregisterProtocolHandler(Navigator* navigator, cons
t String& scheme, const String& url, ExceptionCode& ec) |
192 { | 191 { |
193 if (!navigator->frame()) | 192 if (!navigator->frame()) |
194 return; | 193 return; |
195 | 194 |
196 Document* document = navigator->frame()->document(); | 195 Document* document = navigator->frame()->document(); |
197 String baseURL = document->baseURL().baseAsString(); | 196 String baseURL = document->baseURL().baseAsString(); |
198 | 197 |
199 if (!verifyCustomHandlerURL(baseURL, url, es)) | 198 if (!verifyCustomHandlerURL(baseURL, url, ec)) |
200 return; | 199 return; |
201 | 200 |
202 if (!verifyProtocolHandlerScheme(scheme, es)) | 201 if (!verifyProtocolHandlerScheme(scheme, ec)) |
203 return; | 202 return; |
204 | 203 |
205 NavigatorContentUtils::from(navigator->frame()->page())->client()->unregiste
rProtocolHandler(scheme, baseURL, url); | 204 NavigatorContentUtils::from(navigator->frame()->page())->client()->unregiste
rProtocolHandler(scheme, baseURL, url); |
206 } | 205 } |
207 #endif | 206 #endif |
208 | 207 |
209 const char* NavigatorContentUtils::supplementName() | 208 const char* NavigatorContentUtils::supplementName() |
210 { | 209 { |
211 return "NavigatorContentUtils"; | 210 return "NavigatorContentUtils"; |
212 } | 211 } |
213 | 212 |
214 void provideNavigatorContentUtilsTo(Page* page, NavigatorContentUtilsClient* cli
ent) | 213 void provideNavigatorContentUtilsTo(Page* page, NavigatorContentUtilsClient* cli
ent) |
215 { | 214 { |
216 RefCountedSupplement<Page, NavigatorContentUtils>::provideTo(page, Navigator
ContentUtils::supplementName(), NavigatorContentUtils::create(client)); | 215 RefCountedSupplement<Page, NavigatorContentUtils>::provideTo(page, Navigator
ContentUtils::supplementName(), NavigatorContentUtils::create(client)); |
217 } | 216 } |
218 | 217 |
219 } // namespace WebCore | 218 } // namespace WebCore |
220 | 219 |
221 #endif // ENABLE(NAVIGATOR_CONTENT_UTILS) | 220 #endif // ENABLE(NAVIGATOR_CONTENT_UTILS) |
222 | 221 |
OLD | NEW |