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

Side by Side Diff: third_party/WebKit/Source/core/loader/DocumentThreadableLoader.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013, Intel Corporation 3 * Copyright (C) 2013, Intel Corporation
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "core/loader/ThreadableLoaderClient.h" 48 #include "core/loader/ThreadableLoaderClient.h"
49 #include "core/page/ChromeClient.h" 49 #include "core/page/ChromeClient.h"
50 #include "core/page/Page.h" 50 #include "core/page/Page.h"
51 #include "platform/SharedBuffer.h" 51 #include "platform/SharedBuffer.h"
52 #include "platform/network/ResourceRequest.h" 52 #include "platform/network/ResourceRequest.h"
53 #include "platform/weborigin/SchemeRegistry.h" 53 #include "platform/weborigin/SchemeRegistry.h"
54 #include "platform/weborigin/SecurityOrigin.h" 54 #include "platform/weborigin/SecurityOrigin.h"
55 #include "public/platform/Platform.h" 55 #include "public/platform/Platform.h"
56 #include "public/platform/WebURLRequest.h" 56 #include "public/platform/WebURLRequest.h"
57 #include "wtf/Assertions.h" 57 #include "wtf/Assertions.h"
58 #include "wtf/PtrUtil.h"
59 #include <memory>
60 58
61 namespace blink { 59 namespace blink {
62 60
63 namespace { 61 namespace {
64 62
65 class EmptyDataHandle final : public WebDataConsumerHandle { 63 class EmptyDataHandle final : public WebDataConsumerHandle {
66 private: 64 private:
67 class EmptyDataReader final : public WebDataConsumerHandle::Reader { 65 class EmptyDataReader final : public WebDataConsumerHandle::Reader {
68 public: 66 public:
69 explicit EmptyDataReader(WebDataConsumerHandle::Client* client) : m_fact ory(this) 67 explicit EmptyDataReader(WebDataConsumerHandle::Client* client) : m_fact ory(this)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // Max number of CORS redirects handled in DocumentThreadableLoader. 117 // Max number of CORS redirects handled in DocumentThreadableLoader.
120 // Same number as net/url_request/url_request.cc, and 118 // Same number as net/url_request/url_request.cc, and
121 // same number as https://fetch.spec.whatwg.org/#concept-http-fetch, Step 4. 119 // same number as https://fetch.spec.whatwg.org/#concept-http-fetch, Step 4.
122 // FIXME: currently the number of redirects is counted and limited here and in 120 // FIXME: currently the number of redirects is counted and limited here and in
123 // net/url_request/url_request.cc separately. 121 // net/url_request/url_request.cc separately.
124 static const int kMaxCORSRedirects = 20; 122 static const int kMaxCORSRedirects = 20;
125 123
126 void DocumentThreadableLoader::loadResourceSynchronously(Document& document, con st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa derOptions& options, const ResourceLoaderOptions& resourceLoaderOptions) 124 void DocumentThreadableLoader::loadResourceSynchronously(Document& document, con st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa derOptions& options, const ResourceLoaderOptions& resourceLoaderOptions)
127 { 125 {
128 // The loader will be deleted as soon as this function exits. 126 // The loader will be deleted as soon as this function exits.
129 std::unique_ptr<DocumentThreadableLoader> loader = wrapUnique(new DocumentTh readableLoader(document, &client, LoadSynchronously, options, resourceLoaderOpti ons)); 127 OwnPtr<DocumentThreadableLoader> loader = adoptPtr(new DocumentThreadableLoa der(document, &client, LoadSynchronously, options, resourceLoaderOptions));
130 loader->start(request); 128 loader->start(request);
131 } 129 }
132 130
133 std::unique_ptr<DocumentThreadableLoader> DocumentThreadableLoader::create(Docum ent& document, ThreadableLoaderClient* client, const ThreadableLoaderOptions& op tions, const ResourceLoaderOptions& resourceLoaderOptions) 131 PassOwnPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document& document, ThreadableLoaderClient* client, const ThreadableLoaderOptions& options , const ResourceLoaderOptions& resourceLoaderOptions)
134 { 132 {
135 return wrapUnique(new DocumentThreadableLoader(document, client, LoadAsynchr onously, options, resourceLoaderOptions)); 133 return adoptPtr(new DocumentThreadableLoader(document, client, LoadAsynchron ously, options, resourceLoaderOptions));
136 } 134 }
137 135
138 DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ThreadableLoader Options& options, const ResourceLoaderOptions& resourceLoaderOptions) 136 DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ThreadableLoader Options& options, const ResourceLoaderOptions& resourceLoaderOptions)
139 : m_client(client) 137 : m_client(client)
140 , m_document(&document) 138 , m_document(&document)
141 , m_options(options) 139 , m_options(options)
142 , m_resourceLoaderOptions(resourceLoaderOptions) 140 , m_resourceLoaderOptions(resourceLoaderOptions)
143 , m_forceDoNotAllowStoredCredentials(false) 141 , m_forceDoNotAllowStoredCredentials(false)
144 , m_securityOrigin(m_resourceLoaderOptions.securityOrigin) 142 , m_securityOrigin(m_resourceLoaderOptions.securityOrigin)
145 , m_sameOriginRequest(false) 143 , m_sameOriginRequest(false)
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // We use |m_redirectMode| to check the original redirect mode. 444 // We use |m_redirectMode| to check the original redirect mode.
447 // |request| is a new request for redirect. So we don't set the redirect 445 // |request| is a new request for redirect. So we don't set the redirect
448 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect(). 446 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect().
449 ASSERT(request.useStreamOnResponse()); 447 ASSERT(request.useStreamOnResponse());
450 // There is no need to read the body of redirect response because there 448 // There is no need to read the body of redirect response because there
451 // is no way to read the body of opaque-redirect filtered response's 449 // is no way to read the body of opaque-redirect filtered response's
452 // internal response. 450 // internal response.
453 // TODO(horo): If we support any API which expose the internal body, we 451 // TODO(horo): If we support any API which expose the internal body, we
454 // will have to read the body. And also HTTPCache changes will be needed 452 // will have to read the body. And also HTTPCache changes will be needed
455 // because it doesn't store the body of redirect responses. 453 // because it doesn't store the body of redirect responses.
456 responseReceived(resource, redirectResponse, wrapUnique(new EmptyDataHan dle())); 454 responseReceived(resource, redirectResponse, adoptPtr(new EmptyDataHandl e()));
457 455
458 if (!self) { 456 if (!self) {
459 request = ResourceRequest(); 457 request = ResourceRequest();
460 return; 458 return;
461 } 459 }
462 460
463 if (m_client) { 461 if (m_client) {
464 ASSERT(m_actualRequest.isNull()); 462 ASSERT(m_actualRequest.isNull());
465 notifyFinished(resource); 463 notifyFinished(resource);
466 } 464 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 void DocumentThreadableLoader::didReceiveResourceTiming(Resource* resource, cons t ResourceTimingInfo& info) 589 void DocumentThreadableLoader::didReceiveResourceTiming(Resource* resource, cons t ResourceTimingInfo& info)
592 { 590 {
593 ASSERT(m_client); 591 ASSERT(m_client);
594 ASSERT_UNUSED(resource, resource == this->resource()); 592 ASSERT_UNUSED(resource, resource == this->resource());
595 ASSERT(m_async); 593 ASSERT(m_async);
596 594
597 m_client->didReceiveResourceTiming(info); 595 m_client->didReceiveResourceTiming(info);
598 // |this| may be dead here. 596 // |this| may be dead here.
599 } 597 }
600 598
601 void DocumentThreadableLoader::responseReceived(Resource* resource, const Resour ceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) 599 void DocumentThreadableLoader::responseReceived(Resource* resource, const Resour ceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle)
602 { 600 {
603 ASSERT_UNUSED(resource, resource == this->resource()); 601 ASSERT_UNUSED(resource, resource == this->resource());
604 ASSERT(m_async); 602 ASSERT(m_async);
605 603
606 if (handle) 604 if (handle)
607 m_isUsingDataConsumerHandle = true; 605 m_isUsingDataConsumerHandle = true;
608 606
609 handleResponse(resource->identifier(), response, std::move(handle)); 607 handleResponse(resource->identifier(), response, std::move(handle));
610 // |this| may be dead here. 608 // |this| may be dead here.
611 } 609 }
(...skipping 13 matching lines...) Expand all
625 // |this| may be dead here in async mode. 623 // |this| may be dead here in async mode.
626 return; 624 return;
627 } 625 }
628 626
629 if (m_actualRequest.isExternalRequest() && !passesExternalPreflightCheck(res ponse, accessControlErrorDescription)) { 627 if (m_actualRequest.isExternalRequest() && !passesExternalPreflightCheck(res ponse, accessControlErrorDescription)) {
630 handlePreflightFailure(response.url().getString(), accessControlErrorDes cription); 628 handlePreflightFailure(response.url().getString(), accessControlErrorDes cription);
631 // |this| may be dead here in async mode. 629 // |this| may be dead here in async mode.
632 return; 630 return;
633 } 631 }
634 632
635 std::unique_ptr<CrossOriginPreflightResultCacheItem> preflightResult = wrapU nique(new CrossOriginPreflightResultCacheItem(effectiveAllowCredentials())); 633 OwnPtr<CrossOriginPreflightResultCacheItem> preflightResult = adoptPtr(new C rossOriginPreflightResultCacheItem(effectiveAllowCredentials()));
636 if (!preflightResult->parse(response, accessControlErrorDescription) 634 if (!preflightResult->parse(response, accessControlErrorDescription)
637 || !preflightResult->allowsCrossOriginMethod(m_actualRequest.httpMethod( ), accessControlErrorDescription) 635 || !preflightResult->allowsCrossOriginMethod(m_actualRequest.httpMethod( ), accessControlErrorDescription)
638 || !preflightResult->allowsCrossOriginHeaders(m_actualRequest.httpHeader Fields(), accessControlErrorDescription)) { 636 || !preflightResult->allowsCrossOriginHeaders(m_actualRequest.httpHeader Fields(), accessControlErrorDescription)) {
639 handlePreflightFailure(response.url().getString(), accessControlErrorDes cription); 637 handlePreflightFailure(response.url().getString(), accessControlErrorDes cription);
640 // |this| may be dead here in async mode. 638 // |this| may be dead here in async mode.
641 return; 639 return;
642 } 640 }
643 641
644 CrossOriginPreflightResultCache::shared().appendEntry(getSecurityOrigin()->t oString(), m_actualRequest.url(), std::move(preflightResult)); 642 CrossOriginPreflightResultCache::shared().appendEntry(getSecurityOrigin()->t oString(), m_actualRequest.url(), std::move(preflightResult));
645 } 643 }
646 644
647 void DocumentThreadableLoader::reportResponseReceived(unsigned long identifier, const ResourceResponse& response) 645 void DocumentThreadableLoader::reportResponseReceived(unsigned long identifier, const ResourceResponse& response)
648 { 646 {
649 LocalFrame* frame = document().frame(); 647 LocalFrame* frame = document().frame();
650 // We are seeing crashes caused by nullptr (crbug.com/578849). But the frame 648 // We are seeing crashes caused by nullptr (crbug.com/578849). But the frame
651 // must be set here. TODO(horo): Find the root cause of the unset frame. 649 // must be set here. TODO(horo): Find the root cause of the unset frame.
652 ASSERT(frame); 650 ASSERT(frame);
653 if (!frame) 651 if (!frame)
654 return; 652 return;
655 DocumentLoader* loader = frame->loader().documentLoader(); 653 DocumentLoader* loader = frame->loader().documentLoader();
656 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceiveResponse", TRACE_E VENT_SCOPE_THREAD, "data", InspectorReceiveResponseEvent::data(identifier, frame , response)); 654 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceiveResponse", TRACE_E VENT_SCOPE_THREAD, "data", InspectorReceiveResponseEvent::data(identifier, frame , response));
657 InspectorInstrumentation::didReceiveResourceResponse(frame, identifier, load er, response, resource()); 655 InspectorInstrumentation::didReceiveResourceResponse(frame, identifier, load er, response, resource());
658 frame->console().reportResourceResponseReceived(loader, identifier, response ); 656 frame->console().reportResourceResponseReceived(loader, identifier, response );
659 } 657 }
660 658
661 void DocumentThreadableLoader::handleResponse(unsigned long identifier, const Re sourceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) 659 void DocumentThreadableLoader::handleResponse(unsigned long identifier, const Re sourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle)
662 { 660 {
663 ASSERT(m_client); 661 ASSERT(m_client);
664 662
665 if (!m_actualRequest.isNull()) { 663 if (!m_actualRequest.isNull()) {
666 reportResponseReceived(identifier, response); 664 reportResponseReceived(identifier, response);
667 handlePreflightResponse(response); 665 handlePreflightResponse(response);
668 // |this| may be dead here in async mode. 666 // |this| may be dead here in async mode.
669 return; 667 return;
670 } 668 }
671 669
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri gin(); 991 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri gin();
994 } 992 }
995 993
996 Document& DocumentThreadableLoader::document() const 994 Document& DocumentThreadableLoader::document() const
997 { 995 {
998 ASSERT(m_document); 996 ASSERT(m_document);
999 return *m_document; 997 return *m_document;
1000 } 998 }
1001 999
1002 } // namespace blink 1000 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698