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

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

Issue 18328028: Enable MQ evaluation off the main thread (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@threaded_mqe_rebase
Patch Set: Created 7 years, 5 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
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 12 matching lines...) Expand all
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 "core/html/parser/HTMLResourcePreloader.h" 27 #include "core/html/parser/HTMLResourcePreloader.h"
28 28
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/loader/cache/CachedResourceInitiatorInfo.h" 30 #include "core/loader/cache/CachedResourceInitiatorInfo.h"
31 #include "core/loader/cache/CachedResourceLoader.h" 31 #include "core/loader/cache/CachedResourceLoader.h"
32 32
33 #include "core/css/MediaList.h"
34 #include "core/css/MediaQueryEvaluator.h"
35 #include "core/rendering/RenderObject.h"
36
37 namespace WebCore { 33 namespace WebCore {
38 34
39 bool PreloadRequest::isSafeToSendToAnotherThread() const 35 bool PreloadRequest::isSafeToSendToAnotherThread() const
40 { 36 {
41 return m_initiatorName.isSafeToSendToAnotherThread() 37 return m_initiatorName.isSafeToSendToAnotherThread()
42 && m_charset.isSafeToSendToAnotherThread() 38 && m_charset.isSafeToSendToAnotherThread()
43 && m_resourceURL.isSafeToSendToAnotherThread() 39 && m_resourceURL.isSafeToSendToAnotherThread()
44 && m_mediaAttribute.isSafeToSendToAnotherThread()
45 && m_baseURL.isSafeToSendToAnotherThread(); 40 && m_baseURL.isSafeToSendToAnotherThread();
46 } 41 }
47 42
48 KURL PreloadRequest::completeURL(Document* document) 43 KURL PreloadRequest::completeURL(Document* document)
49 { 44 {
50 return document->completeURL(m_resourceURL, m_baseURL.isEmpty() ? document-> url() : m_baseURL); 45 return document->completeURL(m_resourceURL, m_baseURL.isEmpty() ? document-> url() : m_baseURL);
51 } 46 }
52 47
53 CachedResourceRequest PreloadRequest::resourceRequest(Document* document) 48 CachedResourceRequest PreloadRequest::resourceRequest(Document* document)
54 { 49 {
(...skipping 11 matching lines...) Expand all
66 61
67 void HTMLResourcePreloader::takeAndPreload(PreloadRequestStream& r) 62 void HTMLResourcePreloader::takeAndPreload(PreloadRequestStream& r)
68 { 63 {
69 PreloadRequestStream requests; 64 PreloadRequestStream requests;
70 requests.swap(r); 65 requests.swap(r);
71 66
72 for (PreloadRequestStream::iterator it = requests.begin(); it != requests.en d(); ++it) 67 for (PreloadRequestStream::iterator it = requests.begin(); it != requests.en d(); ++it)
73 preload(it->release()); 68 preload(it->release());
74 } 69 }
75 70
76 static bool mediaAttributeMatches(Frame* frame, RenderStyle* renderStyle, const String& attributeValue)
77 {
78 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(attributeValue);
79 MediaQueryEvaluator mediaQueryEvaluator("screen", frame, renderStyle);
80 return mediaQueryEvaluator.eval(mediaQueries.get());
81 }
82
83 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload) 71 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload)
84 { 72 {
85 ASSERT(m_document->frame());
86 ASSERT(m_document->renderer());
87 ASSERT(m_document->renderer()->style());
88 if (!preload->media().isEmpty() && !mediaAttributeMatches(m_document->frame( ), m_document->renderer()->style(), preload->media()))
89 return;
90
91 CachedResourceRequest request = preload->resourceRequest(m_document); 73 CachedResourceRequest request = preload->resourceRequest(m_document);
92 m_document->cachedResourceLoader()->preload(preload->resourceType(), request , preload->charset()); 74 m_document->cachedResourceLoader()->preload(preload->resourceType(), request , preload->charset());
93 } 75 }
94 76
95 77
96 } 78 }
OLDNEW
« Source/core/css/MediaQueryExp.cpp ('K') | « Source/core/html/parser/HTMLResourcePreloader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698