OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ | 3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ |
4 * Copyright (C) 2010 Google Inc. All Rights Reserved. | 4 * Copyright (C) 2010 Google Inc. All Rights Reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "config.h" | 28 #include "config.h" |
29 #include "core/html/parser/CSSPreloadScanner.h" | 29 #include "core/html/parser/CSSPreloadScanner.h" |
30 | 30 |
31 #include "core/fetch/FetchInitiatorTypeNames.h" | 31 #include "core/fetch/FetchInitiatorTypeNames.h" |
32 #include "core/html/parser/HTMLParserIdioms.h" | 32 #include "core/html/parser/HTMLParserIdioms.h" |
33 #include "platform/text/SegmentedString.h" | 33 #include "platform/text/SegmentedString.h" |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 CSSPreloadScanner::CSSPreloadScanner() | 37 CSSPreloadScanner::CSSPreloadScanner() |
38 : m_state(Initial) | |
39 , m_requests(0) | |
40 , m_referrerPolicy(ReferrerPolicyDefault) | |
41 { | 38 { |
42 } | 39 } |
43 | 40 |
44 CSSPreloadScanner::~CSSPreloadScanner() | 41 CSSPreloadScanner::~CSSPreloadScanner() |
45 { | 42 { |
46 } | 43 } |
47 | 44 |
48 void CSSPreloadScanner::reset() | 45 void CSSPreloadScanner::reset() |
49 { | 46 { |
50 m_state = Initial; | 47 m_state = Initial; |
51 m_rule.clear(); | 48 m_rule.clear(); |
52 m_ruleValue.clear(); | 49 m_ruleValue.clear(); |
53 } | 50 } |
54 | 51 |
55 template<typename Char> | 52 template<typename Char> |
56 void CSSPreloadScanner::scanCommon(const Char* begin, const Char* end, const Seg
mentedString& source, PreloadRequestStream& requests) | 53 void CSSPreloadScanner::scanCommon(const Char* begin, const Char* end, const Seg
mentedString& source, PreloadRequestStream& requests, const KURL& predictedBaseE
lementURL) |
57 { | 54 { |
58 m_requests = &requests; | 55 m_requests = &requests; |
| 56 m_predictedBaseElementURL = &predictedBaseElementURL; |
| 57 |
59 for (const Char* it = begin; it != end && m_state != DoneParsingImportRules;
++it) | 58 for (const Char* it = begin; it != end && m_state != DoneParsingImportRules;
++it) |
60 tokenize(*it, source); | 59 tokenize(*it, source); |
61 m_requests = 0; | 60 |
| 61 m_requests = nullptr; |
| 62 m_predictedBaseElementURL = nullptr; |
62 } | 63 } |
63 | 64 |
64 void CSSPreloadScanner::scan(const HTMLToken::DataVector& data, const SegmentedS
tring& source, PreloadRequestStream& requests) | 65 void CSSPreloadScanner::scan(const HTMLToken::DataVector& data, const SegmentedS
tring& source, PreloadRequestStream& requests, const KURL& predictedBaseElementU
RL) |
65 { | 66 { |
66 scanCommon(data.data(), data.data() + data.size(), source, requests); | 67 scanCommon(data.data(), data.data() + data.size(), source, requests, predict
edBaseElementURL); |
67 } | 68 } |
68 | 69 |
69 void CSSPreloadScanner::scan(const String& tagName, const SegmentedString& sour
ce, PreloadRequestStream& requests) | 70 void CSSPreloadScanner::scan(const String& tagName, const SegmentedString& sourc
e, PreloadRequestStream& requests, const KURL& predictedBaseElementURL) |
70 { | 71 { |
71 if (tagName.is8Bit()) { | 72 if (tagName.is8Bit()) { |
72 const LChar* begin = tagName.characters8(); | 73 const LChar* begin = tagName.characters8(); |
73 scanCommon(begin, begin + tagName.length(), source, requests); | 74 scanCommon(begin, begin + tagName.length(), source, requests, predictedB
aseElementURL); |
74 return; | 75 return; |
75 } | 76 } |
76 const UChar* begin = tagName.characters16(); | 77 const UChar* begin = tagName.characters16(); |
77 scanCommon(begin, begin + tagName.length(), source, requests); | 78 scanCommon(begin, begin + tagName.length(), source, requests, predictedBaseE
lementURL); |
78 } | 79 } |
79 | 80 |
80 void CSSPreloadScanner::setReferrerPolicy(const ReferrerPolicy policy) | 81 void CSSPreloadScanner::setReferrerPolicy(const ReferrerPolicy policy) |
81 { | 82 { |
82 m_referrerPolicy = policy; | 83 m_referrerPolicy = policy; |
83 } | 84 } |
84 | 85 |
85 inline void CSSPreloadScanner::tokenize(UChar c, const SegmentedString& source) | 86 inline void CSSPreloadScanner::tokenize(UChar c, const SegmentedString& source) |
86 { | 87 { |
87 // We are just interested in @import rules, no need for real tokenization he
re | 88 // We are just interested in @import rules, no need for real tokenization he
re |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 --reducedLength; | 213 --reducedLength; |
213 | 214 |
214 return string.substring(offset, reducedLength); | 215 return string.substring(offset, reducedLength); |
215 } | 216 } |
216 | 217 |
217 void CSSPreloadScanner::emitRule(const SegmentedString& source) | 218 void CSSPreloadScanner::emitRule(const SegmentedString& source) |
218 { | 219 { |
219 if (equalIgnoringCase(m_rule, "import")) { | 220 if (equalIgnoringCase(m_rule, "import")) { |
220 String url = parseCSSStringOrURL(m_ruleValue.toString()); | 221 String url = parseCSSStringOrURL(m_ruleValue.toString()); |
221 if (!url.isEmpty()) { | 222 if (!url.isEmpty()) { |
222 KURL baseElementURL; // FIXME: This should be passed in from the HTM
LPreloadScaner via scan()! | |
223 TextPosition position = TextPosition(source.currentLine(), source.cu
rrentColumn()); | 223 TextPosition position = TextPosition(source.currentLine(), source.cu
rrentColumn()); |
224 OwnPtr<PreloadRequest> request = PreloadRequest::create(FetchInitiat
orTypeNames::css, position, url, baseElementURL, Resource::CSSStyleSheet, m_refe
rrerPolicy); | 224 OwnPtr<PreloadRequest> request = PreloadRequest::create(FetchInitiat
orTypeNames::css, position, url, *m_predictedBaseElementURL, Resource::CSSStyleS
heet, m_referrerPolicy); |
225 // FIXME: Should this be including the charset in the preload reques
t? | 225 // FIXME: Should this be including the charset in the preload reques
t? |
226 m_requests->append(request.release()); | 226 m_requests->append(request.release()); |
227 } | 227 } |
228 m_state = Initial; | 228 m_state = Initial; |
229 } else if (equalIgnoringCase(m_rule, "charset")) | 229 } else if (equalIgnoringCase(m_rule, "charset")) |
230 m_state = Initial; | 230 m_state = Initial; |
231 else | 231 else |
232 m_state = DoneParsingImportRules; | 232 m_state = DoneParsingImportRules; |
233 m_rule.clear(); | 233 m_rule.clear(); |
234 m_ruleValue.clear(); | 234 m_ruleValue.clear(); |
235 } | 235 } |
236 | 236 |
237 } | 237 } |
OLD | NEW |