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

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: introduce detachFromDocumentLoader() 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 m_applicationCacheHost->dispose(); 116 ASSERT(!m_applicationCacheHost);
117 }
118
119 DEFINE_TRACE(DocumentLoader)
120 {
121 visitor->trace(m_frame);
122 visitor->trace(m_fetcher);
123 // TODO(sof): start tracing ResourcePtr<>s (and m_mainResource.)
124 visitor->trace(m_writer);
125 visitor->trace(m_archive);
126 visitor->trace(m_applicationCacheHost);
117 } 127 }
118 128
119 unsigned long DocumentLoader::mainResourceIdentifier() const 129 unsigned long DocumentLoader::mainResourceIdentifier() const
120 { 130 {
121 return m_mainResource ? m_mainResource->identifier() : 0; 131 return m_mainResource ? m_mainResource->identifier() : 0;
122 } 132 }
123 133
124 Document* DocumentLoader::document() const 134 Document* DocumentLoader::document() const
125 { 135 {
126 if (m_frame && m_frame->loader().documentLoader() == this) 136 if (m_frame && m_frame->loader().documentLoader() == this)
127 return m_frame->document(); 137 return m_frame->document();
128 return 0; 138 return nullptr;
129 } 139 }
130 140
131 const ResourceRequest& DocumentLoader::originalRequest() const 141 const ResourceRequest& DocumentLoader::originalRequest() const
132 { 142 {
133 return m_originalRequest; 143 return m_originalRequest;
134 } 144 }
135 145
136 const ResourceRequest& DocumentLoader::request() const 146 const ResourceRequest& DocumentLoader::request() const
137 { 147 {
138 return m_request; 148 return m_request;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 frameLoader()->receivedMainResourceError(this, error); 208 frameLoader()->receivedMainResourceError(this, error);
199 clearMainResourceHandle(); 209 clearMainResourceHandle();
200 } 210 }
201 211
202 // Cancels the data source's pending loads. Conceptually, a data source only lo ads 212 // 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. 213 // one document at a time, but one document may have many related resources.
204 // stopLoading will stop all loads initiated by the data source, 214 // 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. 215 // but not loads initiated by child frames' data sources -- that's the WebFrame' s job.
206 void DocumentLoader::stopLoading() 216 void DocumentLoader::stopLoading()
207 { 217 {
208 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame); 218 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame.get());
209 RefPtr<DocumentLoader> protectLoader(this); 219 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this);
210 220
211 m_fetcher->stopFetching(); 221 m_fetcher->stopFetching();
212 if (isLoading()) 222 if (isLoading())
213 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); 223 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url()));
214 } 224 }
215 225
216 void DocumentLoader::commitIfReady() 226 void DocumentLoader::commitIfReady()
217 { 227 {
218 if (!m_committed) { 228 if (!m_committed) {
219 m_committed = true; 229 m_committed = true;
220 frameLoader()->commitProvisionalLoad(); 230 frameLoader()->commitProvisionalLoad();
221 } 231 }
222 } 232 }
223 233
224 bool DocumentLoader::isLoading() const 234 bool DocumentLoader::isLoading() const
225 { 235 {
226 if (document() && document()->hasActiveParser()) 236 if (document() && document()->hasActiveParser())
227 return true; 237 return true;
228 238
229 return m_loadingMainResource || m_fetcher->isFetching(); 239 return m_loadingMainResource || m_fetcher->isFetching();
230 } 240 }
231 241
232 void DocumentLoader::notifyFinished(Resource* resource) 242 void DocumentLoader::notifyFinished(Resource* resource)
233 { 243 {
234 ASSERT_UNUSED(resource, m_mainResource == resource); 244 ASSERT_UNUSED(resource, m_mainResource == resource);
235 ASSERT(m_mainResource); 245 ASSERT(m_mainResource);
236 246
237 RefPtr<DocumentLoader> protect(this); 247 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
238 248
239 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) { 249 if (!m_mainResource->errorOccurred() && !m_mainResource->wasCanceled()) {
240 finishedLoading(m_mainResource->loadFinishTime()); 250 finishedLoading(m_mainResource->loadFinishTime());
241 return; 251 return;
242 } 252 }
243 253
244 mainReceivedError(m_mainResource->resourceError()); 254 mainReceivedError(m_mainResource->resourceError());
245 } 255 }
246 256
247 void DocumentLoader::finishedLoading(double finishTime) 257 void DocumentLoader::finishedLoading(double finishTime)
248 { 258 {
249 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading() || In spectorInstrumentation::isDebuggerPaused(m_frame)); 259 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading() || In spectorInstrumentation::isDebuggerPaused(m_frame));
250 260
251 RefPtr<DocumentLoader> protect(this); 261 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
252 262
253 double responseEndTime = finishTime; 263 double responseEndTime = finishTime;
254 if (!responseEndTime) 264 if (!responseEndTime)
255 responseEndTime = m_timeOfLastDataReceived; 265 responseEndTime = m_timeOfLastDataReceived;
256 if (!responseEndTime) 266 if (!responseEndTime)
257 responseEndTime = monotonicallyIncreasingTime(); 267 responseEndTime = monotonicallyIncreasingTime();
258 timing().setResponseEnd(responseEndTime); 268 timing().setResponseEnd(responseEndTime);
259 269
260 commitIfReady(); 270 commitIfReady();
261 if (!frameLoader()) 271 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. 439 // The load event might have detached this frame. In that case, the load wil l already have been cancelled during detach.
430 if (frameLoader()) 440 if (frameLoader())
431 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); 441 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url()));
432 return; 442 return;
433 } 443 }
434 444
435 void DocumentLoader::responseReceived(Resource* resource, const ResourceResponse & response, PassOwnPtr<WebDataConsumerHandle> handle) 445 void DocumentLoader::responseReceived(Resource* resource, const ResourceResponse & response, PassOwnPtr<WebDataConsumerHandle> handle)
436 { 446 {
437 ASSERT_UNUSED(resource, m_mainResource == resource); 447 ASSERT_UNUSED(resource, m_mainResource == resource);
438 ASSERT_UNUSED(handle, !handle); 448 ASSERT_UNUSED(handle, !handle);
439 RefPtr<DocumentLoader> protect(this); 449 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
440 ASSERT(frame()); 450 ASSERT(frame());
441 451
442 m_applicationCacheHost->didReceiveResponseForMainResource(response); 452 m_applicationCacheHost->didReceiveResponseForMainResource(response);
443 453
444 // The memory cache doesn't understand the application cache or its caching rules. So if a main resource is served 454 // 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 455 // 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(). 456 // from appcache will have a non-zero appCacheID().
447 if (response.appCacheID()) 457 if (response.appCacheID())
448 memoryCache()->remove(m_mainResource.get()); 458 memoryCache()->remove(m_mainResource.get());
449 459
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 void DocumentLoader::dataReceived(Resource* resource, const char* data, unsigned length) 544 void DocumentLoader::dataReceived(Resource* resource, const char* data, unsigned length)
535 { 545 {
536 ASSERT(data); 546 ASSERT(data);
537 ASSERT(length); 547 ASSERT(length);
538 ASSERT_UNUSED(resource, resource == m_mainResource); 548 ASSERT_UNUSED(resource, resource == m_mainResource);
539 ASSERT(!m_response.isNull()); 549 ASSERT(!m_response.isNull());
540 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); 550 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading());
541 551
542 // Both unloading the old page and parsing the new page may execute JavaScri pt which destroys the datasource 552 // 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. 553 // by starting a new load, so retain temporarily.
544 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame); 554 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame.get());
545 RefPtr<DocumentLoader> protectLoader(this); 555 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this);
546 556
547 m_applicationCacheHost->mainResourceDataReceived(data, length); 557 m_applicationCacheHost->mainResourceDataReceived(data, length);
548 m_timeOfLastDataReceived = monotonicallyIncreasingTime(); 558 m_timeOfLastDataReceived = monotonicallyIncreasingTime();
549 559
550 if (isArchiveMIMEType(response().mimeType())) 560 if (isArchiveMIMEType(response().mimeType()))
551 return; 561 return;
552 commitIfReady(); 562 commitIfReady();
553 if (!frameLoader()) 563 if (!frameLoader())
554 return; 564 return;
555 commitData(data, length); 565 commitData(data, length);
(...skipping 15 matching lines...) Expand all
571 } 581 }
572 582
573 bool DocumentLoader::loadingMultipartContent() const 583 bool DocumentLoader::loadingMultipartContent() const
574 { 584 {
575 return mainResourceLoader() ? mainResourceLoader()->loadingMultipartContent( ) : false; 585 return mainResourceLoader() ? mainResourceLoader()->loadingMultipartContent( ) : false;
576 } 586 }
577 587
578 void DocumentLoader::detachFromFrame() 588 void DocumentLoader::detachFromFrame()
579 { 589 {
580 ASSERT(m_frame); 590 ASSERT(m_frame);
581 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame); 591 RefPtrWillBeRawPtr<LocalFrame> protectFrame(m_frame.get());
582 RefPtr<DocumentLoader> protectLoader(this); 592 RefPtrWillBeRawPtr<DocumentLoader> protectLoader(this);
583 593
584 // It never makes sense to have a document loader that is detached from its 594 // 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. 595 // frame have any loads active, so go ahead and kill all the loads.
586 stopLoading(); 596 stopLoading();
587 597
588 m_fetcher->clearContext(); 598 m_fetcher->clearContext();
589 m_applicationCacheHost->setApplicationCache(0); 599 m_applicationCacheHost->detachFromDocumentLoader();
600 m_applicationCacheHost.clear();
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