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

Side by Side Diff: Source/core/loader/DocumentLoader.cpp

Issue 1194003004: Oilpan: enable appcache + move DocumentLoader to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add outer loader protection Created 5 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) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
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 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 , m_navigationType(NavigationTypeOther) 93 , m_navigationType(NavigationTypeOther)
94 , m_loadingMainResource(false) 94 , m_loadingMainResource(false)
95 , m_timeOfLastDataReceived(0.0) 95 , m_timeOfLastDataReceived(0.0)
96 , m_applicationCacheHost(ApplicationCacheHost::create(this)) 96 , m_applicationCacheHost(ApplicationCacheHost::create(this))
97 { 97 {
98 } 98 }
99 99
100 FrameLoader* DocumentLoader::frameLoader() const 100 FrameLoader* DocumentLoader::frameLoader() const
101 { 101 {
102 if (!m_frame) 102 if (!m_frame)
103 return 0; 103 return nullptr;
104 return &m_frame->loader(); 104 return &m_frame->loader();
105 } 105 }
106 106
107 ResourceLoader* DocumentLoader::mainResourceLoader() const 107 ResourceLoader* DocumentLoader::mainResourceLoader() const
108 { 108 {
109 return m_mainResource ? m_mainResource->loader() : 0; 109 return m_mainResource ? m_mainResource->loader() : nullptr;
110 } 110 }
111 111
112 DocumentLoader::~DocumentLoader() 112 DocumentLoader::~DocumentLoader()
113 { 113 {
114 ASSERT(!m_frame || !isLoading()); 114 ASSERT(!m_frame || !isLoading());
115 clearMainResourceHandle(); 115 ASSERT(!m_mainResource);
116 #if !ENABLE(OILPAN)
116 m_applicationCacheHost->dispose(); 117 m_applicationCacheHost->dispose();
haraken 2015/06/22 01:57:58 I'm wondering if we could move this to detachFromF
118 #endif
119 }
120
121 DEFINE_TRACE(DocumentLoader)
122 {
123 visitor->trace(m_fetcher);
124 // TODO(sof): start tracing ResourcePtr<>s (and m_mainResource.)
haraken 2015/06/22 01:57:58 I don't quite remember the current status of Resou
sof 2015/06/22 06:49:18 We definitely ought to when present on Oilpan heap
125 visitor->trace(m_writer);
126 visitor->trace(m_archive);
127 visitor->trace(m_applicationCacheHost);
117 } 128 }
118 129
119 unsigned long DocumentLoader::mainResourceIdentifier() const 130 unsigned long DocumentLoader::mainResourceIdentifier() const
120 { 131 {
121 return m_mainResource ? m_mainResource->identifier() : 0; 132 return m_mainResource ? m_mainResource->identifier() : 0;
122 } 133 }
123 134
124 Document* DocumentLoader::document() const 135 Document* DocumentLoader::document() const
125 { 136 {
126 if (m_frame && m_frame->loader().documentLoader() == this) 137 if (m_frame && m_frame->loader().documentLoader() == this)
127 return m_frame->document(); 138 return m_frame->document();
128 return 0; 139 return nullptr;
129 } 140 }
130 141
131 const ResourceRequest& DocumentLoader::originalRequest() const 142 const ResourceRequest& DocumentLoader::originalRequest() const
132 { 143 {
133 return m_originalRequest; 144 return m_originalRequest;
134 } 145 }
135 146
136 const ResourceRequest& DocumentLoader::request() const 147 const ResourceRequest& DocumentLoader::request() const
137 { 148 {
138 return m_request; 149 return m_request;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 clearMainResourceHandle(); 210 clearMainResourceHandle();
200 } 211 }
201 212
202 // Cancels the data source's pending loads. Conceptually, a data source only lo ads 213 // Cancels the data source's pending loads. Conceptually, a data source only lo ads
203 // one document at a time, but one document may have many related resources. 214 // one document at a time, but one document may have many related resources.
204 // stopLoading will stop all loads initiated by the data source, 215 // stopLoading will stop all loads initiated by the data source,
205 // but not loads initiated by child frames' data sources -- that's the WebFrame' s job. 216 // but not loads initiated by child frames' data sources -- that's the WebFrame' s job.
206 void DocumentLoader::stopLoading() 217 void DocumentLoader::stopLoading()
207 { 218 {
208 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame); 219 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame);
209 RefPtr<DocumentLoader> protectLoader(this); 220 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this);
210 221
211 m_fetcher->stopFetching(); 222 m_fetcher->stopFetching();
212 if (isLoading()) 223 if (isLoading())
213 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); 224 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url()));
214 } 225 }
215 226
216 void DocumentLoader::commitIfReady() 227 void DocumentLoader::commitIfReady()
217 { 228 {
218 if (!m_committed) { 229 if (!m_committed) {
219 m_committed = true; 230 m_committed = true;
220 frameLoader()->commitProvisionalLoad(); 231 frameLoader()->commitProvisionalLoad();
221 } 232 }
222 } 233 }
223 234
224 bool DocumentLoader::isLoading() const 235 bool DocumentLoader::isLoading() const
225 { 236 {
226 if (document() && document()->hasActiveParser()) 237 if (document() && document()->hasActiveParser())
227 return true; 238 return true;
228 239
229 return m_loadingMainResource || m_fetcher->isFetching(); 240 return m_loadingMainResource || m_fetcher->isFetching();
230 } 241 }
231 242
232 void DocumentLoader::notifyFinished(Resource* resource) 243 void DocumentLoader::notifyFinished(Resource* resource)
233 { 244 {
234 ASSERT_UNUSED(resource, m_mainResource == resource); 245 ASSERT_UNUSED(resource, m_mainResource == resource);
235 ASSERT(m_mainResource); 246 ASSERT(m_mainResource);
236 247
237 RefPtr<DocumentLoader> protect(this); 248 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
238 249
239 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) { 250 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) {
240 finishedLoading(m_mainResource->loadFinishTime()); 251 finishedLoading(m_mainResource->loadFinishTime());
241 return; 252 return;
242 } 253 }
243 254
244 mainReceivedError(m_mainResource->resourceError()); 255 mainReceivedError(m_mainResource->resourceError());
245 } 256 }
246 257
247 void DocumentLoader::finishedLoading(double finishTime) 258 void DocumentLoader::finishedLoading(double finishTime)
248 { 259 {
249 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading() || In spectorInstrumentation::isDebuggerPaused(m_frame)); 260 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading() || In spectorInstrumentation::isDebuggerPaused(m_frame));
250 261
251 RefPtr<DocumentLoader> protect(this); 262 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
252 263
253 double responseEndTime = finishTime; 264 double responseEndTime = finishTime;
254 if (!responseEndTime) 265 if (!responseEndTime)
255 responseEndTime = m_timeOfLastDataReceived; 266 responseEndTime = m_timeOfLastDataReceived;
256 if (!responseEndTime) 267 if (!responseEndTime)
257 responseEndTime = monotonicallyIncreasingTime(); 268 responseEndTime = monotonicallyIncreasingTime();
258 timing().setResponseEnd(responseEndTime); 269 timing().setResponseEnd(responseEndTime);
259 270
260 commitIfReady(); 271 commitIfReady();
261 if (!frameLoader()) 272 if (!frameLoader())
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // The load event might have detached this frame. In that case, the load wil l already have been cancelled during detach. 440 // The load event might have detached this frame. In that case, the load wil l already have been cancelled during detach.
430 if (frameLoader()) 441 if (frameLoader())
431 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); 442 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url()));
432 return; 443 return;
433 } 444 }
434 445
435 void DocumentLoader::responseReceived(Resource* resource, const ResourceResponse & response, PassOwnPtr<WebDataConsumerHandle> handle) 446 void DocumentLoader::responseReceived(Resource* resource, const ResourceResponse & response, PassOwnPtr<WebDataConsumerHandle> handle)
436 { 447 {
437 ASSERT_UNUSED(resource, m_mainResource == resource); 448 ASSERT_UNUSED(resource, m_mainResource == resource);
438 ASSERT_UNUSED(handle, !handle); 449 ASSERT_UNUSED(handle, !handle);
439 RefPtr<DocumentLoader> protect(this); 450 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
440 ASSERT(frame()); 451 ASSERT(frame());
441 452
442 m_applicationCacheHost->didReceiveResponseForMainResource(response); 453 m_applicationCacheHost->didReceiveResponseForMainResource(response);
443 454
444 // The memory cache doesn't understand the application cache or its caching rules. So if a main resource is served 455 // The memory cache doesn't understand the application cache or its caching rules. So if a main resource is served
445 // from the application cache, ensure we don't save the result for future us e. All responses loaded 456 // from the application cache, ensure we don't save the result for future us e. All responses loaded
446 // from appcache will have a non-zero appCacheID(). 457 // from appcache will have a non-zero appCacheID().
447 if (response.appCacheID()) 458 if (response.appCacheID())
448 memoryCache()->remove(m_mainResource.get()); 459 memoryCache()->remove(m_mainResource.get());
449 460
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 { 546 {
536 ASSERT(data); 547 ASSERT(data);
537 ASSERT(length); 548 ASSERT(length);
538 ASSERT_UNUSED(resource, resource == m_mainResource); 549 ASSERT_UNUSED(resource, resource == m_mainResource);
539 ASSERT(!m_response.isNull()); 550 ASSERT(!m_response.isNull());
540 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); 551 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading());
541 552
542 // Both unloading the old page and parsing the new page may execute JavaScri pt which destroys the datasource 553 // Both unloading the old page and parsing the new page may execute JavaScri pt which destroys the datasource
543 // by starting a new load, so retain temporarily. 554 // by starting a new load, so retain temporarily.
544 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame); 555 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame);
545 RefPtr<DocumentLoader> protectLoader(this); 556 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this);
546 557
547 m_applicationCacheHost->mainResourceDataReceived(data, length); 558 m_applicationCacheHost->mainResourceDataReceived(data, length);
548 m_timeOfLastDataReceived = monotonicallyIncreasingTime(); 559 m_timeOfLastDataReceived = monotonicallyIncreasingTime();
549 560
550 if (isArchiveMIMEType(response().mimeType())) 561 if (isArchiveMIMEType(response().mimeType()))
551 return; 562 return;
552 commitIfReady(); 563 commitIfReady();
553 if (!frameLoader()) 564 if (!frameLoader())
554 return; 565 return;
555 commitData(data, length); 566 commitData(data, length);
(...skipping 16 matching lines...) Expand all
572 583
573 bool DocumentLoader::loadingMultipartContent() const 584 bool DocumentLoader::loadingMultipartContent() const
574 { 585 {
575 return mainResourceLoader() ? mainResourceLoader()->loadingMultipartContent( ) : false; 586 return mainResourceLoader() ? mainResourceLoader()->loadingMultipartContent( ) : false;
576 } 587 }
577 588
578 void DocumentLoader::detachFromFrame() 589 void DocumentLoader::detachFromFrame()
579 { 590 {
580 ASSERT(m_frame); 591 ASSERT(m_frame);
581 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame); 592 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame);
582 RefPtr<DocumentLoader> protectLoader(this); 593 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this);
583 594
584 // It never makes sense to have a document loader that is detached from its 595 // It never makes sense to have a document loader that is detached from its
585 // frame have any loads active, so go ahead and kill all the loads. 596 // frame have any loads active, so go ahead and kill all the loads.
586 stopLoading(); 597 stopLoading();
587 598
588 m_fetcher->clearContext(); 599 m_fetcher->clearContext();
589 m_applicationCacheHost->setApplicationCache(0); 600 m_applicationCacheHost->setApplicationCache(0);
590 WeakIdentifierMap<DocumentLoader>::notifyObjectDestroyed(this); 601 WeakIdentifierMap<DocumentLoader>::notifyObjectDestroyed(this);
591 m_frame = 0; 602 m_frame = nullptr;
603 clearMainResourceHandle();
592 } 604 }
593 605
594 void DocumentLoader::clearMainResourceLoader() 606 void DocumentLoader::clearMainResourceLoader()
595 { 607 {
596 m_loadingMainResource = false; 608 m_loadingMainResource = false;
597 } 609 }
598 610
599 void DocumentLoader::clearMainResourceHandle() 611 void DocumentLoader::clearMainResourceHandle()
600 { 612 {
601 if (!m_mainResource) 613 if (!m_mainResource)
602 return; 614 return;
603 m_mainResource->removeClient(this); 615 m_mainResource->removeClient(this);
604 m_mainResource = 0; 616 m_mainResource = nullptr;
605 } 617 }
606 618
607 bool DocumentLoader::maybeCreateArchive() 619 bool DocumentLoader::maybeCreateArchive()
608 { 620 {
609 // Only the top-frame can load MHTML. 621 // Only the top-frame can load MHTML.
610 if (m_frame->tree().parent()) 622 if (m_frame->tree().parent())
611 return false; 623 return false;
612 624
613 // Give the archive machinery a crack at this document. If the MIME type is not an archive type, it will return 0. 625 // Give the archive machinery a crack at this document. If the MIME type is not an archive type, it will return 0.
614 if (!isArchiveMIMEType(m_response.mimeType())) 626 if (!isArchiveMIMEType(m_response.mimeType()))
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 696
685 if (m_request.url().isEmpty() && !frameLoader()->stateMachine()->creatingIni tialEmptyDocument()) 697 if (m_request.url().isEmpty() && !frameLoader()->stateMachine()->creatingIni tialEmptyDocument())
686 m_request.setURL(blankURL()); 698 m_request.setURL(blankURL());
687 m_response = ResourceResponse(m_request.url(), "text/html", 0, nullAtom, Str ing()); 699 m_response = ResourceResponse(m_request.url(), "text/html", 0, nullAtom, Str ing());
688 finishedLoading(monotonicallyIncreasingTime()); 700 finishedLoading(monotonicallyIncreasingTime());
689 return true; 701 return true;
690 } 702 }
691 703
692 void DocumentLoader::startLoadingMainResource() 704 void DocumentLoader::startLoadingMainResource()
693 { 705 {
694 RefPtr<DocumentLoader> protect(this); 706 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
695 m_mainDocumentError = ResourceError(); 707 m_mainDocumentError = ResourceError();
696 timing().markNavigationStart(); 708 timing().markNavigationStart();
697 ASSERT(!m_mainResource); 709 ASSERT(!m_mainResource);
698 ASSERT(!m_loadingMainResource); 710 ASSERT(!m_loadingMainResource);
699 m_loadingMainResource = true; 711 m_loadingMainResource = true;
700 712
701 if (maybeLoadEmpty()) 713 if (maybeLoadEmpty())
702 return; 714 return;
703 715
704 ASSERT(timing().navigationStart()); 716 ASSERT(timing().navigationStart());
(...skipping 29 matching lines...) Expand all
734 request = mainResourceLoader()->originalRequest(); 746 request = mainResourceLoader()->originalRequest();
735 // If there was a fragment identifier on m_request, the cache will have stri pped it. m_request should include 747 // If there was a fragment identifier on m_request, the cache will have stri pped it. m_request should include
736 // the fragment identifier, so add that back in. 748 // the fragment identifier, so add that back in.
737 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url())) 749 if (equalIgnoringFragmentIdentifier(m_request.url(), request.url()))
738 request.setURL(m_request.url()); 750 request.setURL(m_request.url());
739 m_request = request; 751 m_request = request;
740 } 752 }
741 753
742 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError) 754 void DocumentLoader::cancelMainResourceLoad(const ResourceError& resourceError)
743 { 755 {
744 RefPtr<DocumentLoader> protect(this); 756 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
745 ResourceError error = resourceError.isNull() ? ResourceError::cancelledError (m_request.url()) : resourceError; 757 ResourceError error = resourceError.isNull() ? ResourceError::cancelledError (m_request.url()) : resourceError;
746 758
747 if (mainResourceLoader()) 759 if (mainResourceLoader())
748 mainResourceLoader()->cancel(error); 760 mainResourceLoader()->cancel(error);
749 761
750 mainReceivedError(error); 762 mainReceivedError(error);
751 } 763 }
752 764
753 void DocumentLoader::attachThreadedDataReceiver(PassRefPtrWillBeRawPtr<ThreadedD ataReceiver> threadedDataReceiver) 765 void DocumentLoader::attachThreadedDataReceiver(PassRefPtrWillBeRawPtr<ThreadedD ataReceiver> threadedDataReceiver)
754 { 766 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR L() 811 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR L()
800 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(const DocumentIn it& init, const String& source, Document* ownerDocument) 812 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(const DocumentIn it& init, const String& source, Document* ownerDocument)
801 { 813 {
802 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing); 814 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing);
803 if (!source.isNull()) 815 if (!source.isNull())
804 m_writer->appendReplacingData(source); 816 m_writer->appendReplacingData(source);
805 endWriting(m_writer.get()); 817 endWriting(m_writer.get());
806 } 818 }
807 819
808 } // namespace blink 820 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698