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

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

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

Powered by Google App Engine
This is Rietveld 408576698