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

Side by Side Diff: third_party/WebKit/Source/core/fetch/Resource.cpp

Issue 1738553002: [ABANDONED] Move multipart/x-mixed-replace related code to ImageResource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@multipart-cleanup-2
Patch Set: Created 4 years, 9 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) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 { 198 {
199 InspectorInstrumentation::removedResourceFromMemoryCache(this); 199 InspectorInstrumentation::removedResourceFromMemoryCache(this);
200 } 200 }
201 201
202 DEFINE_TRACE(Resource) 202 DEFINE_TRACE(Resource)
203 { 203 {
204 visitor->trace(m_loader); 204 visitor->trace(m_loader);
205 #if ENABLE(OILPAN) 205 #if ENABLE(OILPAN)
206 visitor->trace(m_cacheHandler); 206 visitor->trace(m_cacheHandler);
207 #endif 207 #endif
208 visitor->trace(m_multipartParser);
209 MultipartImageResourceParser::Client::trace(visitor);
210 } 208 }
211 209
212 void Resource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& optio ns) 210 void Resource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& optio ns)
213 { 211 {
214 m_options = options; 212 m_options = options;
215 m_loading = true; 213 m_loading = true;
216 214
217 ResourceRequest request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest); 215 ResourceRequest request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest);
218 if (!accept().isEmpty()) 216 if (!accept().isEmpty())
219 request.setHTTPAccept(accept()); 217 request.setHTTPAccept(accept());
(...skipping 23 matching lines...) Expand all
243 return; 241 return;
244 242
245 ResourceClientWalker<ResourceClient> w(m_clients); 243 ResourceClientWalker<ResourceClient> w(m_clients);
246 while (ResourceClient* c = w.next()) 244 while (ResourceClient* c = w.next())
247 c->notifyFinished(this); 245 c->notifyFinished(this);
248 } 246 }
249 247
250 void Resource::appendData(const char* data, size_t length) 248 void Resource::appendData(const char* data, size_t length)
251 { 249 {
252 TRACE_EVENT0("blink", "Resource::appendData"); 250 TRACE_EVENT0("blink", "Resource::appendData");
253 if (isMultipartImage()) {
254 m_multipartParser->appendData(data, length);
255 return;
256 }
257 appendDataInternal(data, length);
258 }
259
260 void Resource::appendDataInternal(const char* data, size_t length)
261 {
262 ASSERT(m_revalidatingRequest.isNull()); 251 ASSERT(m_revalidatingRequest.isNull());
263 ASSERT(!errorOccurred()); 252 ASSERT(!errorOccurred());
264 if (m_options.dataBufferingPolicy == DoNotBufferData) 253 if (m_options.dataBufferingPolicy == DoNotBufferData)
265 return; 254 return;
266 if (m_data) 255 if (m_data)
267 m_data->append(data, length); 256 m_data->append(data, length);
268 else 257 else
269 m_data = SharedBuffer::createPurgeable(data, length); 258 m_data = SharedBuffer::createPurgeable(data, length);
270 setEncodedSize(m_data->size()); 259 setEncodedSize(m_data->size());
271 } 260 }
(...skipping 20 matching lines...) Expand all
292 HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); 281 HashCountedSet<ResourceClient*>::iterator it = m_clients.begin();
293 for (int i = it->value; i; i--) { 282 for (int i = it->value; i; i--) {
294 m_finishedClients.add(it->key); 283 m_finishedClients.add(it->key);
295 m_clients.remove(it); 284 m_clients.remove(it);
296 } 285 }
297 } 286 }
298 } 287 }
299 288
300 void Resource::error(Resource::Status status) 289 void Resource::error(Resource::Status status)
301 { 290 {
302 if (m_multipartParser)
303 m_multipartParser->cancel();
304
305 if (!m_revalidatingRequest.isNull()) 291 if (!m_revalidatingRequest.isNull())
306 m_revalidatingRequest = ResourceRequest(); 292 m_revalidatingRequest = ResourceRequest();
307 293
308 if (!m_error.isNull() && (m_error.isCancellation() || !isPreloaded())) 294 if (!m_error.isNull() && (m_error.isCancellation() || !isPreloaded()))
309 memoryCache()->remove(this); 295 memoryCache()->remove(this);
310 296
311 setStatus(status); 297 setStatus(status);
312 ASSERT(errorOccurred()); 298 ASSERT(errorOccurred());
313 m_data.clear(); 299 m_data.clear();
314 300
315 setLoading(false); 301 setLoading(false);
316 checkNotify(); 302 checkNotify();
317 markClientsFinished(); 303 markClientsFinished();
318 } 304 }
319 305
320 void Resource::finishOnePart()
321 {
322 setLoading(false);
323 checkNotify();
324 }
325
326 void Resource::finish() 306 void Resource::finish()
327 { 307 {
328 ASSERT(m_revalidatingRequest.isNull()); 308 ASSERT(m_revalidatingRequest.isNull());
329 ASSERT(!errorOccurred()); 309 setLoading(false);
330 if (m_multipartParser) 310 checkNotify();
331 m_multipartParser->finish();
332
333 finishOnePart();
334 markClientsFinished(); 311 markClientsFinished();
335 if (!errorOccurred()) 312 if (!errorOccurred())
336 m_status = Cached; 313 m_status = Cached;
337 } 314 }
338 315
339 AtomicString Resource::httpContentType() const 316 AtomicString Resource::httpContentType() const
340 { 317 {
341 return extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPNames::Co ntent_Type).lower()); 318 return extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPNames::Co ntent_Type).lower());
342 } 319 }
343 320
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 { 449 {
473 m_responseTimestamp = currentTime(); 450 m_responseTimestamp = currentTime();
474 451
475 if (!m_revalidatingRequest.isNull()) { 452 if (!m_revalidatingRequest.isNull()) {
476 if (response.httpStatusCode() == 304) { 453 if (response.httpStatusCode() == 304) {
477 revalidationSucceeded(response); 454 revalidationSucceeded(response);
478 return; 455 return;
479 } 456 }
480 revalidationFailed(); 457 revalidationFailed();
481 } 458 }
482 // If there's no boundary, just handle the request normally.
483 if (response.isMultipart() && !response.multipartBoundary().isEmpty() && (m_ type == Resource::Image || m_type == Resource::MainResource) && !m_multipartPars er)
484 m_multipartParser = new MultipartImageResourceParser(response, response. multipartBoundary(), this);
485 setResponse(response); 459 setResponse(response);
486 String encoding = response.textEncodingName(); 460 String encoding = response.textEncodingName();
487 if (!encoding.isNull()) 461 if (!encoding.isNull())
488 setEncoding(encoding); 462 setEncoding(encoding);
489 } 463 }
490 464
491 void Resource::setSerializedCachedMetadata(const char* data, size_t size) 465 void Resource::setSerializedCachedMetadata(const char* data, size_t size)
492 { 466 {
493 // We only expect to receive cached metadata from the platform once. 467 // We only expect to receive cached metadata from the platform once.
494 // If this triggers, it indicates an efficiency problem which is most 468 // If this triggers, it indicates an efficiency problem which is most
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 508
535 WeakPtrWillBeRawPtr<Resource> Resource::asWeakPtr() 509 WeakPtrWillBeRawPtr<Resource> Resource::asWeakPtr()
536 { 510 {
537 #if ENABLE(OILPAN) 511 #if ENABLE(OILPAN)
538 return this; 512 return this;
539 #else 513 #else
540 return m_weakPtrFactory.createWeakPtr(); 514 return m_weakPtrFactory.createWeakPtr();
541 #endif 515 #endif
542 } 516 }
543 517
544 bool Resource::isMultipartImage() const
545 {
546 return m_multipartParser;
547 }
548
549 void Resource::onePartInMultipartReceived(const ResourceResponse& response)
550 {
551 ASSERT(isMultipartImage());
552 responseReceived(response, nullptr);
553 if (response.isMultipartPayload() && m_loader)
554 m_loader->didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncoded DataLength);
555 }
556
557 void Resource::multipartDataReceived(const char* bytes, size_t size)
558 {
559 ASSERT(isMultipartImage());
560 appendDataInternal(bytes, size);
561 }
562
563 String Resource::reasonNotDeletable() const 518 String Resource::reasonNotDeletable() const
564 { 519 {
565 StringBuilder builder; 520 StringBuilder builder;
566 if (hasClients()) { 521 if (hasClients()) {
567 builder.append("hasClients("); 522 builder.append("hasClients(");
568 builder.appendNumber(m_clients.size()); 523 builder.appendNumber(m_clients.size());
569 if (!m_clientsAwaitingCallback.isEmpty()) { 524 if (!m_clientsAwaitingCallback.isEmpty()) {
570 builder.append(", AwaitingCallback="); 525 builder.append(", AwaitingCallback=");
571 builder.appendNumber(m_clientsAwaitingCallback.size()); 526 builder.appendNumber(m_clientsAwaitingCallback.size());
572 } 527 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 661
707 void Resource::allClientsRemoved() 662 void Resource::allClientsRemoved()
708 { 663 {
709 if (!m_loader) 664 if (!m_loader)
710 return; 665 return;
711 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this )) 666 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this ))
712 cancelTimerFired(&m_cancelTimer); 667 cancelTimerFired(&m_cancelTimer);
713 else if (!m_cancelTimer.isActive()) 668 else if (!m_cancelTimer.isActive())
714 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); 669 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE);
715 670
716 if (m_multipartParser)
717 m_multipartParser->cancel();
718 unlock(); 671 unlock();
719 } 672 }
720 673
721 void Resource::cancelTimerFired(Timer<Resource>* timer) 674 void Resource::cancelTimerFired(Timer<Resource>* timer)
722 { 675 {
723 ASSERT_UNUSED(timer, timer == &m_cancelTimer); 676 ASSERT_UNUSED(timer, timer == &m_cancelTimer);
724 if (hasClients() || !m_loader) 677 if (hasClients() || !m_loader)
725 return; 678 return;
726 RefPtrWillBeRawPtr<Resource> protect(this); 679 RefPtrWillBeRawPtr<Resource> protect(this);
727 m_loader->cancelIfNotFinishing(); 680 m_loader->cancelIfNotFinishing();
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 case Resource::Media: 1110 case Resource::Media:
1158 return "Media"; 1111 return "Media";
1159 case Resource::Manifest: 1112 case Resource::Manifest:
1160 return "Manifest"; 1113 return "Manifest";
1161 } 1114 }
1162 ASSERT_NOT_REACHED(); 1115 ASSERT_NOT_REACHED();
1163 return "Unknown"; 1116 return "Unknown";
1164 } 1117 }
1165 1118
1166 } // namespace blink 1119 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.h ('k') | third_party/WebKit/Source/core/fetch/ResourceLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698