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

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

Issue 1112833004: Add HTMLResourcePreloader preconnect unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed crash Created 5 years, 4 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/fetch/FetchInitiatorInfo.h" 30 #include "core/fetch/FetchInitiatorInfo.h"
31 #include "core/fetch/ResourceFetcher.h" 31 #include "core/fetch/ResourceFetcher.h"
32 #include "core/loader/DocumentLoader.h" 32 #include "core/loader/DocumentLoader.h"
33 #include "platform/network/NetworkHints.h"
34 #include "public/platform/Platform.h" 33 #include "public/platform/Platform.h"
35 34
36 namespace blink { 35 namespace blink {
37 36
38 inline HTMLResourcePreloader::HTMLResourcePreloader(Document& document) 37 inline HTMLResourcePreloader::HTMLResourcePreloader(Document& document)
39 : m_document(document) 38 : m_document(document)
40 { 39 {
41 } 40 }
42 41
43 PassOwnPtrWillBeRawPtr<HTMLResourcePreloader> HTMLResourcePreloader::create(Docu ment& document) 42 PassOwnPtrWillBeRawPtr<HTMLResourcePreloader> HTMLResourcePreloader::create(Docu ment& document)
44 { 43 {
45 return adoptPtrWillBeNoop(new HTMLResourcePreloader(document)); 44 return adoptPtrWillBeNoop(new HTMLResourcePreloader(document));
46 } 45 }
47 46
48 DEFINE_TRACE(HTMLResourcePreloader) 47 DEFINE_TRACE(HTMLResourcePreloader)
49 { 48 {
50 visitor->trace(m_document); 49 visitor->trace(m_document);
51 } 50 }
52 51
53 static void preconnectHost(PreloadRequest* request) 52 static void preconnectHost(PreloadRequest* request, const NetworkHintsInterface& networkHintsInterface)
54 { 53 {
55 ASSERT(request); 54 ASSERT(request);
56 ASSERT(request->isPreconnect()); 55 ASSERT(request->isPreconnect());
57 KURL host(request->baseURL(), request->resourceURL()); 56 KURL host(request->baseURL(), request->resourceURL());
58 if (!host.isValid() || !host.protocolIsInHTTPFamily()) 57 if (!host.isValid() || !host.protocolIsInHTTPFamily())
59 return; 58 return;
60 CrossOriginAttributeValue crossOrigin = CrossOriginAttributeNotSet; 59 CrossOriginAttributeValue crossOrigin = CrossOriginAttributeNotSet;
61 if (request->isCORS()) { 60 if (request->isCORS()) {
62 if (request->isAllowCredentials()) 61 if (request->isAllowCredentials())
63 crossOrigin = CrossOriginAttributeUseCredentials; 62 crossOrigin = CrossOriginAttributeUseCredentials;
64 else 63 else
65 crossOrigin = CrossOriginAttributeAnonymous; 64 crossOrigin = CrossOriginAttributeAnonymous;
66 } 65 }
67 preconnect(host, crossOrigin); 66 networkHintsInterface.preconnectHost(host, crossOrigin);
68 } 67 }
69 68
70 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload) 69 void HTMLResourcePreloader::preload(PassOwnPtr<PreloadRequest> preload, const Ne tworkHintsInterface& networkHintsInterface)
71 { 70 {
72 if (preload->isPreconnect()) { 71 if (preload->isPreconnect()) {
73 preconnectHost(preload.get()); 72 preconnectHost(preload.get(), networkHintsInterface);
74 return; 73 return;
75 } 74 }
76 // TODO(yoichio): Should preload if document is imported. 75 // TODO(yoichio): Should preload if document is imported.
77 if (!m_document->loader()) 76 if (!m_document->loader())
78 return; 77 return;
79 FetchRequest request = preload->resourceRequest(m_document); 78 FetchRequest request = preload->resourceRequest(m_document);
80 // TODO(dgozman): This check should go to HTMLPreloadScanner, but this requi res 79 // TODO(dgozman): This check should go to HTMLPreloadScanner, but this requi res
81 // making Document::completeURLWithOverride logic to be statically accessibl e. 80 // making Document::completeURLWithOverride logic to be statically accessibl e.
82 if (request.url().protocolIsData()) 81 if (request.url().protocolIsData())
83 return; 82 return;
84 if (preload->resourceType() == Resource::Script || preload->resourceType() = = Resource::CSSStyleSheet || preload->resourceType() == Resource::ImportResource ) 83 if (preload->resourceType() == Resource::Script || preload->resourceType() = = Resource::CSSStyleSheet || preload->resourceType() == Resource::ImportResource )
85 request.setCharset(preload->charset().isEmpty() ? m_document->charset(). string() : preload->charset()); 84 request.setCharset(preload->charset().isEmpty() ? m_document->charset(). string() : preload->charset());
86 request.setForPreload(true); 85 request.setForPreload(true);
87 Platform::current()->histogramCustomCounts("WebCore.PreloadDelayMs", static_ cast<int>(1000 * (monotonicallyIncreasingTime() - preload->discoveryTime())), 0, 2000, 20); 86 Platform::current()->histogramCustomCounts("WebCore.PreloadDelayMs", static_ cast<int>(1000 * (monotonicallyIncreasingTime() - preload->discoveryTime())), 0, 2000, 20);
88 m_document->loader()->startPreload(preload->resourceType(), request); 87 m_document->loader()->startPreload(preload->resourceType(), request);
89 } 88 }
90 89
91 } // namespace blink 90 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLResourcePreloader.h ('k') | Source/core/html/parser/HTMLResourcePreloaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698