OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for ") + href.string())); | 157 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for ") + href.string())); |
158 if (crossOrigin != CrossOriginAttributeNotSet) { | 158 if (crossOrigin != CrossOriginAttributeNotSet) { |
159 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, | 159 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, |
160 String("Preconnect CORS setting is ") + String((crossOrigin == CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); | 160 String("Preconnect CORS setting is ") + String((crossOrigin == CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); |
161 } | 161 } |
162 } | 162 } |
163 networkHintsInterface.preconnectHost(href, crossOrigin); | 163 networkHintsInterface.preconnectHost(href, crossOrigin); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 static Resource::Type getTypeFromAsAttribute(const String& as, Document& documen t) | 167 Resource::Type LinkLoader::getTypeFromAsAttribute(const String& as, Document* do cument) |
168 { | 168 { |
169 if (equalIgnoringCase(as, "image")) | 169 if (equalIgnoringCase(as, "image")) |
170 return Resource::Image; | 170 return Resource::Image; |
171 if (equalIgnoringCase(as, "script")) | 171 if (equalIgnoringCase(as, "script")) |
172 return Resource::Script; | 172 return Resource::Script; |
173 if (equalIgnoringCase(as, "style")) | 173 if (equalIgnoringCase(as, "style")) |
174 return Resource::CSSStyleSheet; | 174 return Resource::CSSStyleSheet; |
175 if (equalIgnoringCase(as, "audio") || equalIgnoringCase(as, "video")) | 175 if (equalIgnoringCase(as, "audio") || equalIgnoringCase(as, "video")) |
176 return Resource::Media; | 176 return Resource::Media; |
177 if (equalIgnoringCase(as, "font")) | 177 if (equalIgnoringCase(as, "font")) |
178 return Resource::Font; | 178 return Resource::Font; |
179 if (equalIgnoringCase(as, "track")) | 179 if (equalIgnoringCase(as, "track")) |
180 return Resource::TextTrack; | 180 return Resource::TextTrack; |
181 if (!as.isEmpty()) | 181 if (document && !as.isEmpty()) |
182 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> must have a valid `as` value"))); | 182 document->addConsoleMessage(ConsoleMessage::create(OtherMessageSource, W arningMessageLevel, String("<link rel=preload> must have a valid `as` value"))); |
183 // TODO(yoav): Is this correct? If as is missing or invalid, it should be su bject to "connect-src" CSP directives. | |
igrigorik
2016/01/12 22:11:54
(sorry for late review). To answer the question: y
| |
183 return Resource::LinkSubresource; | 184 return Resource::LinkSubresource; |
184 } | 185 } |
185 | 186 |
186 static void preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& hr ef, Document& document, const String& as) | 187 static void preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& hr ef, Document& document, const String& as) |
187 { | 188 { |
188 if (!document.loader()) | 189 if (!document.loader()) |
189 return; | 190 return; |
190 | 191 |
191 if (relAttribute.isLinkPreload()) { | 192 if (relAttribute.isLinkPreload()) { |
192 UseCounter::count(document, UseCounter::LinkRelPreload); | 193 UseCounter::count(document, UseCounter::LinkRelPreload); |
193 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); | 194 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); |
194 if (!href.isValid() || href.isEmpty()) { | 195 if (!href.isValid() || href.isEmpty()) { |
195 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , WarningMessageLevel, String("<link rel=preload> has an invalid `href` value")) ); | 196 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , WarningMessageLevel, String("<link rel=preload> has an invalid `href` value")) ); |
196 return; | 197 return; |
197 } | 198 } |
198 Resource::Type type = getTypeFromAsAttribute(as, document); | 199 Resource::Type type = LinkLoader::getTypeFromAsAttribute(as, &document); |
199 ResourceRequest resourceRequest(document.completeURL(href)); | 200 ResourceRequest resourceRequest(document.completeURL(href)); |
200 ResourceFetcher::determineRequestContext(resourceRequest, type, false); | 201 ResourceFetcher::determineRequestContext(resourceRequest, type, false); |
201 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link) ; | 202 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link) ; |
202 | 203 |
203 linkRequest.setPriority(document.fetcher()->loadPriority(type, linkReque st)); | 204 linkRequest.setPriority(document.fetcher()->loadPriority(type, linkReque st)); |
204 Settings* settings = document.settings(); | 205 Settings* settings = document.settings(); |
205 if (settings && settings->logPreload()) | 206 if (settings && settings->logPreload()) |
206 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preload triggered for " + href.host() + href.path() ))); | 207 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preload triggered for " + href.host() + href.path() ))); |
207 linkRequest.setForPreload(true); | 208 linkRequest.setForPreload(true); |
208 linkRequest.setAvoidBlockingOnLoad(true); | 209 linkRequest.setAvoidBlockingOnLoad(true); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 m_prerender.clear(); | 292 m_prerender.clear(); |
292 } | 293 } |
293 } | 294 } |
294 | 295 |
295 DEFINE_TRACE(LinkLoader) | 296 DEFINE_TRACE(LinkLoader) |
296 { | 297 { |
297 visitor->trace(m_prerender); | 298 visitor->trace(m_prerender); |
298 } | 299 } |
299 | 300 |
300 } | 301 } |
OLD | NEW |