1 /* 2 * Copyright (C) 2013 Google Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26 #ifndef HTMLResourcePreloader_h 27 #define HTMLResourcePreloader_h 28 29 #include "core/fetch/FetchRequest.h" 30 #include "core/fetch/Resource.h" 31 #include "wtf/CurrentTime.h" 32 #include "wtf/text/TextPosition.h" 33 34 namespace WebCore { 35 36 class PreloadRequest { 37 public: 38 static PassOwnPtr<PreloadRequest> create(const String& initiatorName, const TextPosition& initiatorPosition, const String& resourceURL, const KURL& baseURL, Resource::Type resourceType) 39 { 40 return adoptPtr(new PreloadRequest(initiatorName, initiatorPosition, resourceURL, baseURL, resourceType)); 41 } 42 43 bool isSafeToSendToAnotherThread() const; 44 45 FetchRequest resourceRequest(Document*); 46 47 const String& charset() const { return m_charset; } 48 double discoveryTime() const { return m_discoveryTime; } 49 void setCharset(const String& charset) { m_charset = charset.isolatedCopy(); } 50 void setCrossOriginEnabled(StoredCredentials allowCredentials) 51 { 52 m_isCORSEnabled = true; 53 m_allowCredentials = allowCredentials; 54 } 55 56 Resource::Type resourceType() const { return m_resourceType; } 57 58 private: 59 PreloadRequest(const String& initiatorName, const TextPosition& initiatorPosition, const String& resourceURL, const KURL& baseURL, Resource::Type resourceType) 60 : m_initiatorName(initiatorName) 61 , m_initiatorPosition(initiatorPosition) 62 , m_resourceURL(resourceURL.isolatedCopy()) 63 , m_baseURL(baseURL.copy()) 64 , m_resourceType(resourceType) 65 , m_isCORSEnabled(false) 66 , m_allowCredentials(DoNotAllowStoredCredentials) 67 , m_discoveryTime(monotonicallyIncreasingTime()) 68 { 69 } 70 71 KURL completeURL(Document*); 72 73 String m_initiatorName; 74 TextPosition m_initiatorPosition; 75 String m_resourceURL; 76 KURL m_baseURL; 77 String m_charset; 78 Resource::Type m_resourceType; 79 bool m_isCORSEnabled; 80 StoredCredentials m_allowCredentials; 81 double m_discoveryTime; 82 }; 83 84 typedef Vector<OwnPtr<PreloadRequest> > PreloadRequestStream; 85 86 class HTMLResourcePreloader { 87 WTF_MAKE_NONCOPYABLE(HTMLResourcePreloader); WTF_MAKE_FAST_ALLOCATED; 88 public: 89 explicit HTMLResourcePreloader(Document* document) 90 : m_document(document) 91 { 92 } 93 94 void takeAndPreload(PreloadRequestStream&); 95 void preload(PassOwnPtr<PreloadRequest>); 96 97 private: 98 Document* m_document; 99 }; 100 101 } 102 103 #endif 104