Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: Source/WebCore/html/parser/HTMLResourcePreloader.cpp

Issue 13945017: External Stylesheets preloaded according to their media attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/WebCore/html/parser/HTMLResourcePreloader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All Rights Reserved. 2 * Copyright (C) 2013 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 11 matching lines...) Expand all
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "HTMLResourcePreloader.h" 27 #include "HTMLResourcePreloader.h"
28 28
29 #include "CachedResourceLoader.h" 29 #include "CachedResourceLoader.h"
30 #include "Document.h" 30 #include "Document.h"
31 31
32 #include "MediaList.h"
33 #include "MediaQueryEvaluator.h"
34 #include "RenderObject.h"
35
32 namespace WebCore { 36 namespace WebCore {
33 37
34 bool PreloadRequest::isSafeToSendToAnotherThread() const 38 bool PreloadRequest::isSafeToSendToAnotherThread() const
35 { 39 {
36 return m_initiator.isSafeToSendToAnotherThread() 40 return m_initiator.isSafeToSendToAnotherThread()
37 && m_charset.isSafeToSendToAnotherThread() 41 && m_charset.isSafeToSendToAnotherThread()
38 && m_resourceURL.isSafeToSendToAnotherThread() 42 && m_resourceURL.isSafeToSendToAnotherThread()
43 && m_mediaAttribute.isSafeToSendToAnotherThread()
39 && m_baseURL.isSafeToSendToAnotherThread(); 44 && m_baseURL.isSafeToSendToAnotherThread();
40 } 45 }
41 46
42 KURL PreloadRequest::completeURL(Document* document) 47 KURL PreloadRequest::completeURL(Document* document)
43 { 48 {
44 return document->completeURL(m_resourceURL, m_baseURL.isEmpty() ? document-> url() : m_baseURL); 49 return document->completeURL(m_resourceURL, m_baseURL.isEmpty() ? document-> url() : m_baseURL);
45 } 50 }
46 51
47 CachedResourceRequest PreloadRequest::resourceRequest(Document* document) 52 CachedResourceRequest PreloadRequest::resourceRequest(Document* document)
48 { 53 {
49 ASSERT(isMainThread()); 54 ASSERT(isMainThread());
50 CachedResourceRequest request(ResourceRequest(completeURL(document))); 55 CachedResourceRequest request(ResourceRequest(completeURL(document)));
51 request.setInitiator(m_initiator); 56 request.setInitiator(m_initiator);
52 57
53 // FIXME: It's possible CORS should work for other request types? 58 // FIXME: It's possible CORS should work for other request types?
54 if (m_resourceType == CachedResource::Script) 59 if (m_resourceType == CachedResource::Script)
55 request.mutableResourceRequest().setAllowCookies(m_crossOriginModeAllows Cookies); 60 request.mutableResourceRequest().setAllowCookies(m_crossOriginModeAllows Cookies);
56 return request; 61 return request;
57 } 62 }
58 63
59 void HTMLResourcePreloader::takeAndPreload(PreloadRequestStream& r) 64 void HTMLResourcePreloader::takeAndPreload(PreloadRequestStream& r)
60 { 65 {
61 PreloadRequestStream requests; 66 PreloadRequestStream requests;
62 requests.swap(r); 67 requests.swap(r);
63 68
64 for (PreloadRequestStream::iterator it = requests.begin(); it != requests.en d(); ++it) 69 for (PreloadRequestStream::iterator it = requests.begin(); it != requests.en d(); ++it)
65 preload(it->release()); 70 preload(it->release());
66 } 71 }
67 72
73 static bool mediaAttributeMatches(Frame* frame, RenderStyle* renderStyle, const String& attributeValue)
74 {
75 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::createAllowingDescriptio nSyntax(attributeValue);
76 MediaQueryEvaluator mediaQueryEvaluator("screen", frame, renderStyle);
77 return mediaQueryEvaluator.eval(mediaQueries.get());
78 }
79
68 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload) 80 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload)
69 { 81 {
82 ASSERT(m_document->frame());
83 ASSERT(m_document->renderer());
84 ASSERT(m_document->renderer()->style());
85 if (!preload->media().isEmpty() && !mediaAttributeMatches(m_document->frame( ), m_document->renderer()->style(), preload->media()))
86 return;
87
70 CachedResourceRequest request = preload->resourceRequest(m_document); 88 CachedResourceRequest request = preload->resourceRequest(m_document);
71 m_document->cachedResourceLoader()->preload(preload->resourceType(), request , preload->charset()); 89 m_document->cachedResourceLoader()->preload(preload->resourceType(), request , preload->charset());
72 } 90 }
73 91
92
74 } 93 }
OLDNEW
« no previous file with comments | « Source/WebCore/html/parser/HTMLResourcePreloader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698