Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 "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/fetch/FetchInitiatorInfo.h" | 30 #include "core/fetch/FetchInitiatorInfo.h" |
| 31 #include "core/fetch/ResourceFetcher.h" | 31 #include "core/fetch/ResourceFetcher.h" |
| 32 #include "core/html/imports/HTMLImport.h" | |
| 33 #include "core/layout/LayoutObject.h" | |
| 34 #include "public/platform/Platform.h" | 32 #include "public/platform/Platform.h" |
| 35 | 33 |
| 36 namespace blink { | 34 namespace blink { |
| 37 | 35 |
| 38 bool PreloadRequest::isSafeToSendToAnotherThread() const | |
| 39 { | |
| 40 return m_initiatorName.isSafeToSendToAnotherThread() | |
| 41 && m_charset.isSafeToSendToAnotherThread() | |
| 42 && m_resourceURL.isSafeToSendToAnotherThread() | |
| 43 && m_baseURL.isSafeToSendToAnotherThread(); | |
| 44 } | |
| 45 | |
| 46 KURL PreloadRequest::completeURL(Document* document) | |
| 47 { | |
| 48 return document->completeURLWithOverride(m_resourceURL, m_baseURL.isEmpty() ? document->url() : m_baseURL); | |
| 49 } | |
| 50 | |
| 51 FetchRequest PreloadRequest::resourceRequest(Document* document) | |
| 52 { | |
| 53 ASSERT(isMainThread()); | |
| 54 FetchInitiatorInfo initiatorInfo; | |
| 55 initiatorInfo.name = AtomicString(m_initiatorName); | |
| 56 initiatorInfo.position = m_initiatorPosition; | |
| 57 FetchRequest request(ResourceRequest(completeURL(document)), initiatorInfo); | |
| 58 | |
| 59 if (m_isCORSEnabled) | |
| 60 request.setCrossOriginAccessControl(document->securityOrigin(), m_allowC redentials); | |
| 61 | |
| 62 request.setDefer(m_defer); | |
| 63 request.setResourceWidth(m_resourceWidth); | |
| 64 | |
| 65 return request; | |
| 66 } | |
| 67 | |
| 68 inline HTMLResourcePreloader::HTMLResourcePreloader(Document& document) | 36 inline HTMLResourcePreloader::HTMLResourcePreloader(Document& document) |
| 69 : m_document(document) | 37 : m_document(document) |
| 70 { | 38 { |
| 71 } | 39 } |
| 72 | 40 |
| 73 PassOwnPtrWillBeRawPtr<HTMLResourcePreloader> HTMLResourcePreloader::create(Docu ment& document) | 41 PassOwnPtrWillBeRawPtr<HTMLResourcePreloader> HTMLResourcePreloader::create(Docu ment& document) |
| 74 { | 42 { |
| 75 return adoptPtrWillBeNoop(new HTMLResourcePreloader(document)); | 43 return adoptPtrWillBeNoop(new HTMLResourcePreloader(document)); |
| 76 } | 44 } |
| 77 | 45 |
| 78 DEFINE_TRACE(HTMLResourcePreloader) | 46 DEFINE_TRACE(HTMLResourcePreloader) |
| 79 { | 47 { |
| 80 visitor->trace(m_document); | 48 visitor->trace(m_document); |
| 81 } | 49 } |
| 82 | 50 |
| 83 void HTMLResourcePreloader::takeAndPreload(PreloadRequestStream& r) | 51 void HTMLResourcePreloader::takeAndPreload(PreloadRequestStream& r) |
|
kouhei (in TOK)
2015/04/30 12:59:21
Remove this. This implementation seems idential to
| |
| 84 { | 52 { |
| 85 PreloadRequestStream requests; | 53 PreloadRequestStream requests; |
| 86 requests.swap(r); | 54 requests.swap(r); |
| 87 | 55 |
| 88 for (PreloadRequestStream::iterator it = requests.begin(); it != requests.en d(); ++it) | 56 for (PreloadRequestStream::iterator it = requests.begin(); it != requests.en d(); ++it) |
| 89 preload(it->release()); | 57 preload(it->release()); |
| 90 } | 58 } |
| 91 | 59 |
| 92 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload) | 60 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload) |
| 93 { | 61 { |
| 94 FetchRequest request = preload->resourceRequest(m_document); | 62 FetchRequest request = preload->resourceRequest(m_document); |
| 95 blink::Platform::current()->histogramCustomCounts("WebCore.PreloadDelayMs", static_cast<int>(1000 * (monotonicallyIncreasingTime() - preload->discoveryTime( ))), 0, 2000, 20); | 63 blink::Platform::current()->histogramCustomCounts("WebCore.PreloadDelayMs", static_cast<int>(1000 * (monotonicallyIncreasingTime() - preload->discoveryTime( ))), 0, 2000, 20); |
| 96 m_document->fetcher()->preload(preload->resourceType(), request, preload->ch arset()); | 64 m_document->fetcher()->preload(preload->resourceType(), request, preload->ch arset()); |
| 97 } | 65 } |
| 98 | 66 |
| 99 } | 67 } |
| OLD | NEW |