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

Side by Side Diff: content/browser/background_fetch/background_fetch_data_manager.cc

Issue 2818703003: Consider the Access-Control-Allow-Origin header for Background Fetch (Closed)
Patch Set: Consider the Access-Control-Allow-Origin header for Background Fetch Created 3 years, 8 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 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/background_fetch/background_fetch_data_manager.h" 5 #include "content/browser/background_fetch/background_fetch_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "content/browser/background_fetch/background_fetch_constants.h" 11 #include "content/browser/background_fetch/background_fetch_constants.h"
12 #include "content/browser/background_fetch/background_fetch_context.h" 12 #include "content/browser/background_fetch/background_fetch_context.h"
13 #include "content/browser/background_fetch/background_fetch_cross_origin_filter. h"
13 #include "content/browser/background_fetch/background_fetch_request_info.h" 14 #include "content/browser/background_fetch/background_fetch_request_info.h"
14 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 15 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
15 #include "content/public/browser/blob_handle.h" 16 #include "content/public/browser/blob_handle.h"
16 #include "content/public/browser/browser_context.h" 17 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/download_interrupt_reasons.h" 18 #include "content/public/browser/download_interrupt_reasons.h"
18 #include "content/public/browser/download_item.h" 19 #include "content/public/browser/download_item.h"
19 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponseType.h" 20 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponseType.h"
20 21
21 namespace content { 22 namespace content {
22 23
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 200
200 std::vector<BackgroundFetchSettledFetch> settled_fetches; 201 std::vector<BackgroundFetchSettledFetch> settled_fetches;
201 settled_fetches.reserve(requests.size()); 202 settled_fetches.reserve(requests.size());
202 203
203 std::vector<std::unique_ptr<BlobHandle>> blob_handles; 204 std::vector<std::unique_ptr<BlobHandle>> blob_handles;
204 205
205 for (const auto& request : requests) { 206 for (const auto& request : requests) {
206 BackgroundFetchSettledFetch settled_fetch; 207 BackgroundFetchSettledFetch settled_fetch;
207 settled_fetch.request = request->fetch_request(); 208 settled_fetch.request = request->fetch_request();
208 209
209 // TODO(peter): Find the appropriate way to generalize CORS security checks. 210 // The |filter| decides which values can be passed on to the Service Worker.
210 const bool opaque = !registration_id.origin().IsSameOriginWith( 211 BackgroundFetchCrossOriginFilter filter(registration_id.origin(), *request);
211 url::Origin(request->GetURLChain().back().GetOrigin()));
212 212
213 settled_fetch.response.url_list = request->GetURLChain(); 213 settled_fetch.response.url_list = request->GetURLChain();
214 settled_fetch.response.response_type = 214 settled_fetch.response.response_type =
215 blink::kWebServiceWorkerResponseTypeDefault; 215 blink::kWebServiceWorkerResponseTypeDefault;
216 216
217 if (!opaque) { 217 // Include the status code, status text and the response's body as a blob
218 // when this is allowed by the CORS protocol.
219 if (filter.CanPopulateBody()) {
218 settled_fetch.response.status_code = request->GetResponseCode(); 220 settled_fetch.response.status_code = request->GetResponseCode();
219 settled_fetch.response.status_text = request->GetResponseText(); 221 settled_fetch.response.status_text = request->GetResponseText();
220 settled_fetch.response.headers.insert( 222 settled_fetch.response.headers.insert(
221 request->GetResponseHeaders().begin(), 223 request->GetResponseHeaders().begin(),
222 request->GetResponseHeaders().end()); 224 request->GetResponseHeaders().end());
223 225
224 // Include the response data as a blob backed by the downloaded file.
225 if (request->GetFileSize() > 0) { 226 if (request->GetFileSize() > 0) {
226 DCHECK(!request->GetFilePath().empty()); 227 DCHECK(!request->GetFilePath().empty());
227 std::unique_ptr<BlobHandle> blob_handle = 228 std::unique_ptr<BlobHandle> blob_handle =
228 blob_storage_context_->CreateFileBackedBlob( 229 blob_storage_context_->CreateFileBackedBlob(
229 request->GetFilePath(), 0 /* offset */, request->GetFileSize(), 230 request->GetFilePath(), 0 /* offset */, request->GetFileSize(),
230 base::Time() /* expected_modification_time */); 231 base::Time() /* expected_modification_time */);
231 232
232 // TODO(peter): Appropriately handle !blob_handle 233 // TODO(peter): Appropriately handle !blob_handle
233 if (blob_handle) { 234 if (blob_handle) {
234 settled_fetch.response.blob_uuid = blob_handle->GetUUID(); 235 settled_fetch.response.blob_uuid = blob_handle->GetUUID();
(...skipping 23 matching lines...) Expand all
258 std::move(callback).Run(blink::mojom::BackgroundFetchError::INVALID_TAG); 259 std::move(callback).Run(blink::mojom::BackgroundFetchError::INVALID_TAG);
259 return; 260 return;
260 } 261 }
261 262
262 registrations_.erase(iter); 263 registrations_.erase(iter);
263 264
264 std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE); 265 std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE);
265 } 266 }
266 267
267 } // namespace content 268 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698