OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google, Inc. All rights reserved. | 2 * Copyright (C) 2012 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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 "core/fetch/FetchRequest.h" | 26 #include "core/fetch/FetchRequest.h" |
27 | 27 |
28 #include "core/fetch/CrossOriginAccessControl.h" | 28 #include "core/fetch/CrossOriginAccessControl.h" |
29 #include "core/fetch/ResourceFetcher.h" | 29 #include "core/fetch/ResourceFetcher.h" |
| 30 #include "platform/weborigin/KURL.h" |
30 | 31 |
31 namespace blink { | 32 namespace blink { |
32 | 33 |
33 FetchRequest::FetchRequest(const ResourceRequest& resourceRequest, | 34 FetchRequest::FetchRequest(const ResourceRequest& resourceRequest, |
34 const AtomicString& initiator, | 35 const AtomicString& initiator, |
35 const String& charset) | 36 const String& charset) |
36 : m_resourceRequest(resourceRequest), | 37 : m_resourceRequest(resourceRequest), |
37 m_charset(charset), | 38 m_charset(charset), |
38 m_options(ResourceFetcher::defaultResourceOptions()), | 39 m_options(ResourceFetcher::defaultResourceOptions()), |
39 m_forPreload(false), | 40 m_forPreload(false), |
40 m_linkPreload(false), | 41 m_linkPreload(false), |
41 m_preloadDiscoveryTime(0.0), | 42 m_preloadDiscoveryTime(0.0), |
42 m_defer(NoDefer), | 43 m_defer(NoDefer), |
43 m_originRestriction(UseDefaultOriginRestrictionForType) { | 44 m_originRestriction(UseDefaultOriginRestrictionForType), |
| 45 m_placeholderImageRequestType(DisallowPlaceholder) { |
44 m_options.initiatorInfo.name = initiator; | 46 m_options.initiatorInfo.name = initiator; |
45 } | 47 } |
46 | 48 |
47 FetchRequest::FetchRequest(const ResourceRequest& resourceRequest, | 49 FetchRequest::FetchRequest(const ResourceRequest& resourceRequest, |
48 const AtomicString& initiator, | 50 const AtomicString& initiator, |
49 const ResourceLoaderOptions& options) | 51 const ResourceLoaderOptions& options) |
50 : m_resourceRequest(resourceRequest), | 52 : m_resourceRequest(resourceRequest), |
51 m_options(options), | 53 m_options(options), |
52 m_forPreload(false), | 54 m_forPreload(false), |
53 m_linkPreload(false), | 55 m_linkPreload(false), |
54 m_preloadDiscoveryTime(0.0), | 56 m_preloadDiscoveryTime(0.0), |
55 m_defer(NoDefer), | 57 m_defer(NoDefer), |
56 m_originRestriction(UseDefaultOriginRestrictionForType) { | 58 m_originRestriction(UseDefaultOriginRestrictionForType), |
| 59 m_placeholderImageRequestType( |
| 60 PlaceholderImageRequestType::DisallowPlaceholder) { |
57 m_options.initiatorInfo.name = initiator; | 61 m_options.initiatorInfo.name = initiator; |
58 } | 62 } |
59 | 63 |
60 FetchRequest::FetchRequest(const ResourceRequest& resourceRequest, | 64 FetchRequest::FetchRequest(const ResourceRequest& resourceRequest, |
61 const FetchInitiatorInfo& initiator) | 65 const FetchInitiatorInfo& initiator) |
62 : m_resourceRequest(resourceRequest), | 66 : m_resourceRequest(resourceRequest), |
63 m_options(ResourceFetcher::defaultResourceOptions()), | 67 m_options(ResourceFetcher::defaultResourceOptions()), |
64 m_forPreload(false), | 68 m_forPreload(false), |
65 m_linkPreload(false), | 69 m_linkPreload(false), |
66 m_preloadDiscoveryTime(0.0), | 70 m_preloadDiscoveryTime(0.0), |
67 m_defer(NoDefer), | 71 m_defer(NoDefer), |
68 m_originRestriction(UseDefaultOriginRestrictionForType) { | 72 m_originRestriction(UseDefaultOriginRestrictionForType), |
| 73 m_placeholderImageRequestType( |
| 74 PlaceholderImageRequestType::DisallowPlaceholder) { |
69 m_options.initiatorInfo = initiator; | 75 m_options.initiatorInfo = initiator; |
70 } | 76 } |
71 | 77 |
72 FetchRequest::~FetchRequest() {} | 78 FetchRequest::~FetchRequest() {} |
73 | 79 |
74 void FetchRequest::setCrossOriginAccessControl( | 80 void FetchRequest::setCrossOriginAccessControl( |
75 SecurityOrigin* origin, | 81 SecurityOrigin* origin, |
76 CrossOriginAttributeValue crossOrigin) { | 82 CrossOriginAttributeValue crossOrigin) { |
77 DCHECK_NE(crossOrigin, CrossOriginAttributeNotSet); | 83 DCHECK_NE(crossOrigin, CrossOriginAttributeNotSet); |
78 const bool useCredentials = crossOrigin == CrossOriginAttributeUseCredentials; | 84 const bool useCredentials = crossOrigin == CrossOriginAttributeUseCredentials; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 118 } |
113 | 119 |
114 void FetchRequest::makeSynchronous() { | 120 void FetchRequest::makeSynchronous() { |
115 // Synchronous requests should always be max priority, lest they hang the | 121 // Synchronous requests should always be max priority, lest they hang the |
116 // renderer. | 122 // renderer. |
117 m_resourceRequest.setPriority(ResourceLoadPriorityHighest); | 123 m_resourceRequest.setPriority(ResourceLoadPriorityHighest); |
118 m_resourceRequest.setTimeoutInterval(10); | 124 m_resourceRequest.setTimeoutInterval(10); |
119 m_options.synchronousPolicy = RequestSynchronously; | 125 m_options.synchronousPolicy = RequestSynchronously; |
120 } | 126 } |
121 | 127 |
| 128 void FetchRequest::setAllowImagePlaceholder() { |
| 129 DCHECK_EQ(DisallowPlaceholder, m_placeholderImageRequestType); |
| 130 if (!m_resourceRequest.url().protocolIsInHTTPFamily() || |
| 131 m_resourceRequest.httpMethod() != "GET" || |
| 132 !m_resourceRequest.httpHeaderField("range").isNull()) { |
| 133 return; |
| 134 } |
| 135 |
| 136 m_placeholderImageRequestType = AllowPlaceholder; |
| 137 |
| 138 // Fetch the first few bytes of the image. This number is tuned to both (a) |
| 139 // likely capture the entire image for small images and (b) likely contain |
| 140 // the dimensions for larger images. |
| 141 // TODO(sclittle): Calculate the optimal value for this number. |
| 142 m_resourceRequest.setHTTPHeaderField("range", "bytes=0-2047"); |
| 143 |
| 144 // TODO(sclittle): Indicate somehow (e.g. through a new request bit) to the |
| 145 // embedder that it should return the full resource if the entire resource is |
| 146 // fresh in the cache. |
| 147 } |
| 148 |
122 } // namespace blink | 149 } // namespace blink |
OLD | NEW |