OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 #include "chrome_frame/html_utils.h" | 5 #include "chrome_frame/html_utils.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <urlmon.h> | 8 #include <urlmon.h> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 } | 216 } |
217 | 217 |
218 bool HTMLScanner::IsHTMLCommentClose(StringRange* html_string, StrPos pos) { | 218 bool HTMLScanner::IsHTMLCommentClose(StringRange* html_string, StrPos pos) { |
219 if (pos < html_string->end_ && pos > html_string->start_ + 2 && | 219 if (pos < html_string->end_ && pos > html_string->start_ + 2 && |
220 *pos == L'>') { | 220 *pos == L'>') { |
221 return *(pos-1) == L'-' && *(pos-2) == L'-'; | 221 return *(pos-1) == L'-' && *(pos-2) == L'-'; |
222 } | 222 } |
223 return false; | 223 return false; |
224 } | 224 } |
225 | 225 |
226 bool HTMLScanner::IsIEConditionalCommentClose(StringRange* html_string, | |
amit
2010/12/13 22:19:56
nit: const StringRange*?
robertshield
2010/12/13 22:29:28
Done.
| |
227 StrPos pos) { | |
amit
2010/12/13 22:19:56
nit: indent
robertshield
2010/12/13 22:29:28
Done.
| |
228 if (pos < html_string->end_ && pos > html_string->start_ + 2 && | |
229 *pos == L'>') { | |
230 return *(pos-1) == L']'; | |
amit
2010/12/13 22:19:56
In the following expression: <!--[if IE 8]>, is wh
robertshield
2010/12/13 22:29:28
Not according to the spec http://msdn.microsoft.co
| |
231 } | |
232 return false; | |
233 } | |
234 | |
235 | |
226 bool HTMLScanner::NextTag(StringRange* html_string, StringRange* tag) { | 236 bool HTMLScanner::NextTag(StringRange* html_string, StringRange* tag) { |
227 DCHECK(NULL != html_string); | 237 DCHECK(NULL != html_string); |
228 DCHECK(NULL != tag); | 238 DCHECK(NULL != tag); |
229 | 239 |
230 tag->start_ = html_string->start_; | 240 tag->start_ = html_string->start_; |
231 while (tag->start_ < html_string->end_ && *tag->start_ != L'<') { | 241 while (tag->start_ < html_string->end_ && *tag->start_ != L'<') { |
232 tag->start_++; | 242 tag->start_++; |
233 } | 243 } |
234 | 244 |
235 // we went past the end of the string. | 245 // we went past the end of the string. |
236 if (tag->start_ >= html_string->end_) { | 246 if (tag->start_ >= html_string->end_) { |
237 return false; | 247 return false; |
238 } | 248 } |
239 | 249 |
240 tag->end_ = tag->start_ + 1; | 250 tag->end_ = tag->start_ + 1; |
241 | 251 |
242 // Get the tag name to see if we are in an HTML comment. If we are, then | 252 // Get the tag name to see if we are in an HTML comment. If we are, then |
243 // don't consider quotes. This should work for example: | 253 // don't consider quotes. This should work for example: |
244 // <!-- foo ' --> <meta foo='bar'> | 254 // <!-- foo ' --> <meta foo='bar'> |
245 std::wstring tag_name; | 255 std::wstring tag_name; |
246 StringRange start_range(tag->start_, html_string->end_); | 256 StringRange start_range(tag->start_, html_string->end_); |
247 start_range.GetTagName(&tag_name); | 257 start_range.GetTagName(&tag_name); |
248 if (StartsWith(tag_name, L"!--", true)) { | 258 if (StartsWith(tag_name, L"!--[if", true)) { |
amit
2010/12/13 22:19:56
Is white space allowed between '!--' and '['?
robertshield
2010/12/13 22:29:28
Again, not according to the spec.
| |
249 // We're inside a comment tag, keep going until we get out of it. | 259 // This looks like the beginning of an IE conditional comment, scan until |
260 // we hit the end which always looks like ']>'. For now we disregard the | |
261 // contents of the condition, and always assume true. | |
262 // TODO(robertshield): Optionally support the grammar defined by | |
263 // http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx#syntax. | |
250 while (tag->end_ < html_string->end_ && | 264 while (tag->end_ < html_string->end_ && |
265 !IsIEConditionalCommentClose(html_string, tag->end_)) { | |
266 tag->end_++; | |
267 } | |
268 } else if (StartsWith(tag_name, L"!--", true)) { | |
269 // We're inside a comment tag which ends in '-->'. Keep going until we | |
270 // reach the end. | |
271 while (tag->end_ < html_string->end_ && | |
272 !IsHTMLCommentClose(html_string, tag->end_)) { | |
273 tag->end_++; | |
274 } | |
275 } else if (StartsWith(tag_name, L"![endif", true)) { | |
276 // We're inside the closing tag of an IE conditional comment which ends in | |
277 // either '-->' of ']>'. Keep going until we reach the end. | |
278 while (tag->end_ < html_string->end_ && | |
279 !IsIEConditionalCommentClose(html_string, tag->end_) && | |
251 !IsHTMLCommentClose(html_string, tag->end_)) { | 280 !IsHTMLCommentClose(html_string, tag->end_)) { |
252 tag->end_++; | 281 tag->end_++; |
253 } | 282 } |
254 } else { | 283 } else { |
255 // Properly handle quoted strings within non-comment tags by maintaining | 284 // Properly handle quoted strings within non-comment tags by maintaining |
256 // some state while scanning. Specifically, we have to maintain state on | 285 // some state while scanning. Specifically, we have to maintain state on |
257 // whether we are inside a string, what the string terminating character | 286 // whether we are inside a string, what the string terminating character |
258 // will be and whether we are inside an escape sequence. | 287 // will be and whether we are inside an escape sequence. |
259 ScanState state; | 288 ScanState state; |
260 while (tag->end_ < html_string->end_) { | 289 while (tag->end_ < html_string->end_) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 const std::string& headers) { | 420 const std::string& headers) { |
392 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); | 421 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
393 while (it.GetNext()) { | 422 while (it.GetNext()) { |
394 if (!lstrcmpiA(it.name().c_str(), header.c_str())) | 423 if (!lstrcmpiA(it.name().c_str(), header.c_str())) |
395 return std::string(it.values_begin(), it.values_end()); | 424 return std::string(it.values_begin(), it.values_end()); |
396 } | 425 } |
397 return std::string(); | 426 return std::string(); |
398 } | 427 } |
399 | 428 |
400 } // namespace http_utils | 429 } // namespace http_utils |
OLD | NEW |