Chromium Code Reviews

Side by Side Diff: chrome_frame/html_utils.cc

Issue 5708007: Have Chrome Frame "support" IE conditional comment tags (of the downlevel-hid... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « chrome_frame/html_utils.h ('k') | chrome_frame/test/html_util_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 197 matching lines...)
208 bool in_quote; 208 bool in_quote;
209 bool in_escape; 209 bool in_escape;
210 wchar_t quote_char; 210 wchar_t quote_char;
211 ScanState() : in_quote(false), in_escape(false) {} 211 ScanState() : in_quote(false), in_escape(false) {}
212 }; 212 };
213 213
214 bool HTMLScanner::IsQuote(wchar_t c) { 214 bool HTMLScanner::IsQuote(wchar_t c) {
215 return quotes_.find(c) != std::wstring::npos; 215 return quotes_.find(c) != std::wstring::npos;
216 } 216 }
217 217
218 bool HTMLScanner::IsHTMLCommentClose(StringRange* html_string, StrPos pos) { 218 bool HTMLScanner::IsHTMLCommentClose(const StringRange* html_string,
219 StrPos pos) {
219 if (pos < html_string->end_ && pos > html_string->start_ + 2 && 220 if (pos < html_string->end_ && pos > html_string->start_ + 2 &&
220 *pos == L'>') { 221 *pos == L'>') {
221 return *(pos-1) == L'-' && *(pos-2) == L'-'; 222 return *(pos-1) == L'-' && *(pos-2) == L'-';
222 } 223 }
223 return false; 224 return false;
224 } 225 }
225 226
227 bool HTMLScanner::IsIEConditionalCommentClose(const StringRange* html_string,
228 StrPos pos) {
229 if (pos < html_string->end_ && pos > html_string->start_ + 2 &&
230 *pos == L'>') {
231 return *(pos-1) == L']';
232 }
233 return false;
234 }
235
236
226 bool HTMLScanner::NextTag(StringRange* html_string, StringRange* tag) { 237 bool HTMLScanner::NextTag(StringRange* html_string, StringRange* tag) {
227 DCHECK(NULL != html_string); 238 DCHECK(NULL != html_string);
228 DCHECK(NULL != tag); 239 DCHECK(NULL != tag);
229 240
230 tag->start_ = html_string->start_; 241 tag->start_ = html_string->start_;
231 while (tag->start_ < html_string->end_ && *tag->start_ != L'<') { 242 while (tag->start_ < html_string->end_ && *tag->start_ != L'<') {
232 tag->start_++; 243 tag->start_++;
233 } 244 }
234 245
235 // we went past the end of the string. 246 // we went past the end of the string.
236 if (tag->start_ >= html_string->end_) { 247 if (tag->start_ >= html_string->end_) {
237 return false; 248 return false;
238 } 249 }
239 250
240 tag->end_ = tag->start_ + 1; 251 tag->end_ = tag->start_ + 1;
241 252
242 // Get the tag name to see if we are in an HTML comment. If we are, then 253 // 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: 254 // don't consider quotes. This should work for example:
244 // <!-- foo ' --> <meta foo='bar'> 255 // <!-- foo ' --> <meta foo='bar'>
245 std::wstring tag_name; 256 std::wstring tag_name;
246 StringRange start_range(tag->start_, html_string->end_); 257 StringRange start_range(tag->start_, html_string->end_);
247 start_range.GetTagName(&tag_name); 258 start_range.GetTagName(&tag_name);
248 if (StartsWith(tag_name, L"!--", true)) { 259 if (StartsWith(tag_name, L"!--[if", true)) {
249 // We're inside a comment tag, keep going until we get out of it. 260 // This looks like the beginning of an IE conditional comment, scan until
261 // we hit the end which always looks like ']>'. For now we disregard the
262 // contents of the condition, and always assume true.
263 // TODO(robertshield): Optionally support the grammar defined by
264 // http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx#syntax.
250 while (tag->end_ < html_string->end_ && 265 while (tag->end_ < html_string->end_ &&
266 !IsIEConditionalCommentClose(html_string, tag->end_)) {
267 tag->end_++;
268 }
269 } else if (StartsWith(tag_name, L"!--", true)) {
270 // We're inside a comment tag which ends in '-->'. Keep going until we
271 // reach the end.
272 while (tag->end_ < html_string->end_ &&
273 !IsHTMLCommentClose(html_string, tag->end_)) {
274 tag->end_++;
275 }
276 } else if (StartsWith(tag_name, L"![endif", true)) {
277 // We're inside the closing tag of an IE conditional comment which ends in
278 // either '-->' of ']>'. Keep going until we reach the end.
279 while (tag->end_ < html_string->end_ &&
280 !IsIEConditionalCommentClose(html_string, tag->end_) &&
251 !IsHTMLCommentClose(html_string, tag->end_)) { 281 !IsHTMLCommentClose(html_string, tag->end_)) {
252 tag->end_++; 282 tag->end_++;
253 } 283 }
254 } else { 284 } else {
255 // Properly handle quoted strings within non-comment tags by maintaining 285 // Properly handle quoted strings within non-comment tags by maintaining
256 // some state while scanning. Specifically, we have to maintain state on 286 // some state while scanning. Specifically, we have to maintain state on
257 // whether we are inside a string, what the string terminating character 287 // whether we are inside a string, what the string terminating character
258 // will be and whether we are inside an escape sequence. 288 // will be and whether we are inside an escape sequence.
259 ScanState state; 289 ScanState state;
260 while (tag->end_ < html_string->end_) { 290 while (tag->end_ < html_string->end_) {
(...skipping 130 matching lines...)
391 const std::string& headers) { 421 const std::string& headers) {
392 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); 422 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n");
393 while (it.GetNext()) { 423 while (it.GetNext()) {
394 if (!lstrcmpiA(it.name().c_str(), header.c_str())) 424 if (!lstrcmpiA(it.name().c_str(), header.c_str()))
395 return std::string(it.values_begin(), it.values_end()); 425 return std::string(it.values_begin(), it.values_end());
396 } 426 }
397 return std::string(); 427 return std::string();
398 } 428 }
399 429
400 } // namespace http_utils 430 } // namespace http_utils
OLDNEW
« no previous file with comments | « chrome_frame/html_utils.h ('k') | chrome_frame/test/html_util_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine