2 * Copyright (C) 2013 Google Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
26 #ifndef HTMLResourcePreloader_h
27 #define HTMLResourcePreloader_h
29 #include "core/fetch/FetchRequest.h"
30 #include "core/fetch/Resource.h"
31 #include "wtf/CurrentTime.h"
32 #include "wtf/text/TextPosition.h"
36 class PreloadRequest {
38 static PassOwnPtr<PreloadRequest> create(const String& initiatorName, const TextPosition& initiatorPosition, const String& resourceURL, const KURL& baseURL, Resource::Type resourceType)
40 return adoptPtr(new PreloadRequest(initiatorName, initiatorPosition, resourceURL, baseURL, resourceType));
43 bool isSafeToSendToAnotherThread() const;
45 FetchRequest resourceRequest(Document*);
47 const String& charset() const { return m_charset; }
48 double discoveryTime() const { return m_discoveryTime; }
49 FetchRequest::DeferOption defer() const { return m_defer; }
50 void setDefer(FetchRequest::DeferOption defer) { m_defer = defer; }
51 void setCharset(const String& charset) { m_charset = charset.isolatedCopy(); }
52 void setCrossOriginEnabled(StoredCredentials allowCredentials)
54 m_isCORSEnabled = true;
55 m_allowCredentials = allowCredentials;
58 Resource::Type resourceType() const { return m_resourceType; }
61 PreloadRequest(const String& initiatorName, const TextPosition& initiatorPosition, const String& resourceURL, const KURL& baseURL, Resource::Type resourceType)
62 : m_initiatorName(initiatorName)
63 , m_initiatorPosition(initiatorPosition)
64 , m_resourceURL(resourceURL.isolatedCopy())
65 , m_baseURL(baseURL.copy())
66 , m_resourceType(resourceType)
67 , m_isCORSEnabled(false)
68 , m_allowCredentials(DoNotAllowStoredCredentials)
69 , m_discoveryTime(monotonicallyIncreasingTime())
70 , m_defer(FetchRequest::NoDefer)
74 KURL completeURL(Document*);
76 String m_initiatorName;
77 TextPosition m_initiatorPosition;
81 Resource::Type m_resourceType;
83 StoredCredentials m_allowCredentials;
84 double m_discoveryTime;
85 FetchRequest::DeferOption m_defer;
88 typedef Vector<OwnPtr<PreloadRequest> > PreloadRequestStream;
90 class HTMLResourcePreloader FINAL : public NoBaseWillBeGarbageCollected<HTMLResourcePreloader> {
91 WTF_MAKE_NONCOPYABLE(HTMLResourcePreloader); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
93 static PassOwnPtrWillBeRawPtr<HTMLResourcePreloader> create(Document&);
96 void takeAndPreload(PreloadRequestStream&);
97 void preload(PassOwnPtr<PreloadRequest>);
100 explicit HTMLResourcePreloader(Document&);
102 RawPtrWillBeMember<Document> m_document;