2
* Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3
* Copyright (C) 2011 Google Inc. All rights reserved.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
#include "DocumentLoader.h"
33
#include "ApplicationCacheHost.h"
34
#include "ArchiveResourceCollection.h"
35
#include "CachedPage.h"
36
#include "CachedResourceLoader.h"
37
#include "DOMWindow.h"
39
#include "DocumentParser.h"
40
#include "DocumentWriter.h"
43
#include "FrameLoader.h"
44
#include "FrameLoaderClient.h"
45
#include "FrameTree.h"
46
#include "HistoryItem.h"
47
#include "InspectorInstrumentation.h"
49
#include "MainResourceLoader.h"
51
#include "ResourceBuffer.h"
52
#include "SchemeRegistry.h"
54
#include "TextResourceDecoder.h"
55
#include "WebCoreMemoryInstrumentation.h"
56
#include <wtf/Assertions.h>
57
#include <wtf/MemoryInstrumentationHashMap.h>
58
#include <wtf/MemoryInstrumentationHashSet.h>
59
#include <wtf/MemoryInstrumentationVector.h>
60
#include <wtf/text/CString.h>
61
#include <wtf/text/WTFString.h>
62
#include <wtf/unicode/Unicode.h>
64
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
65
#include "ArchiveFactory.h"
70
static void cancelAll(const ResourceLoaderSet& loaders)
72
Vector<RefPtr<ResourceLoader> > loadersCopy;
73
copyToVector(loaders, loadersCopy);
74
size_t size = loadersCopy.size();
75
for (size_t i = 0; i < size; ++i)
76
loadersCopy[i]->cancel();
79
static void setAllDefersLoading(const ResourceLoaderSet& loaders, bool defers)
81
Vector<RefPtr<ResourceLoader> > loadersCopy;
82
copyToVector(loaders, loadersCopy);
83
size_t size = loadersCopy.size();
84
for (size_t i = 0; i < size; ++i)
85
loadersCopy[i]->setDefersLoading(defers);
88
DocumentLoader::DocumentLoader(const ResourceRequest& req, const SubstituteData& substituteData)
89
: m_deferMainResourceDataLoad(true)
91
, m_cachedResourceLoader(CachedResourceLoader::create(this))
93
, m_originalRequest(req)
94
, m_substituteData(substituteData)
95
, m_originalRequestCopy(req)
99
, m_gotFirstByte(false)
100
, m_isClientRedirect(false)
101
, m_loadingEmptyDocument(false)
102
, m_wasOnloadHandled(false)
103
, m_stopRecordingResponses(false)
104
, m_substituteResourceDeliveryTimer(this, &DocumentLoader::substituteResourceDeliveryTimerFired)
105
, m_didCreateGlobalHistoryEntry(false)
106
, m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this)))
110
FrameLoader* DocumentLoader::frameLoader() const
114
return m_frame->loader();
117
DocumentLoader::~DocumentLoader()
119
ASSERT(!m_frame || frameLoader()->activeDocumentLoader() != this || !isLoading());
120
if (m_iconLoadDecisionCallback)
121
m_iconLoadDecisionCallback->invalidate();
122
if (m_iconDataCallback)
123
m_iconDataCallback->invalidate();
124
m_cachedResourceLoader->clearDocumentLoader();
127
PassRefPtr<ResourceBuffer> DocumentLoader::mainResourceData() const
129
if (m_mainResourceData)
130
return m_mainResourceData;
131
if (m_mainResourceLoader)
132
return m_mainResourceLoader->resourceData();
136
const ResourceRequest& DocumentLoader::originalRequest() const
138
return m_originalRequest;
141
const ResourceRequest& DocumentLoader::originalRequestCopy() const
143
return m_originalRequestCopy;
146
const ResourceRequest& DocumentLoader::request() const
151
ResourceRequest& DocumentLoader::request()
156
const KURL& DocumentLoader::url() const
158
return request().url();
161
void DocumentLoader::replaceRequestURLForSameDocumentNavigation(const KURL& url)
163
m_originalRequestCopy.setURL(url);
164
m_request.setURL(url);
167
void DocumentLoader::setRequest(const ResourceRequest& req)
169
// Replacing an unreachable URL with alternate content looks like a server-side
170
// redirect at this point, but we can replace a committed dataSource.
171
bool handlingUnreachableURL = false;
173
handlingUnreachableURL = m_substituteData.isValid() && !m_substituteData.failingURL().isEmpty();
175
if (handlingUnreachableURL)
178
// We should never be getting a redirect callback after the data
179
// source is committed, except in the unreachable URL case. It
180
// would be a WebFoundation bug if it sent a redirect callback after commit.
181
ASSERT(!m_committed);
183
KURL oldURL = m_request.url();
186
// Only dispatchDidReceiveServerRedirectForProvisionalLoad() if URL changed (and is non-null).
187
// Also, don't send it when replacing unreachable URLs with alternate content.
188
if (!handlingUnreachableURL && !req.url().isNull() && oldURL != req.url())
189
frameLoader()->client()->dispatchDidReceiveServerRedirectForProvisionalLoad();
192
void DocumentLoader::setMainDocumentError(const ResourceError& error)
194
m_mainDocumentError = error;
195
frameLoader()->client()->setMainDocumentError(this, error);
198
void DocumentLoader::mainReceivedError(const ResourceError& error)
200
ASSERT(!error.isNull());
202
m_applicationCacheHost->failedLoadingMainResource();
206
setMainDocumentError(error);
207
clearMainResourceLoader();
208
frameLoader()->receivedMainResourceError(error);
211
// Cancels the data source's pending loads. Conceptually, a data source only loads
212
// one document at a time, but one document may have many related resources.
213
// stopLoading will stop all loads initiated by the data source,
214
// but not loads initiated by child frames' data sources -- that's the WebFrame's job.
215
void DocumentLoader::stopLoading()
217
RefPtr<Frame> protectFrame(m_frame);
218
RefPtr<DocumentLoader> protectLoader(this);
220
// In some rare cases, calling FrameLoader::stopLoading could cause isLoading() to return false.
221
// (This can happen when there's a single XMLHttpRequest currently loading and stopLoading causes it
222
// to stop loading. Because of this, we need to save it so we don't return early.
223
bool loading = isLoading();
226
// Attempt to stop the frame if the document loader is loading, or if it is done loading but
227
// still parsing. Failure to do so can cause a world leak.
228
Document* doc = m_frame->document();
230
if (loading || doc->parsing())
231
m_frame->loader()->stopLoading(UnloadEventPolicyNone);
234
// Always cancel multipart loaders
235
cancelAll(m_multipartSubresourceLoaders);
237
// Appcache uses ResourceHandle directly, DocumentLoader doesn't count these loads.
238
m_applicationCacheHost->stopLoadingInFrame(m_frame);
240
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
241
clearArchiveResources();
245
// If something above restarted loading we might run into mysterious crashes like
246
// https://bugs.webkit.org/show_bug.cgi?id=62764 and <rdar://problem/9328684>
247
ASSERT(!isLoading());
251
// We might run in to infinite recursion if we're stopping loading as the result of
252
// detaching from the frame, so break out of that recursion here.
253
// See <rdar://problem/9673866> for more details.
259
FrameLoader* frameLoader = DocumentLoader::frameLoader();
261
if (m_mainResourceLoader)
262
// Stop the main resource loader and let it send the cancelled message.
263
m_mainResourceLoader->cancel();
264
else if (!m_subresourceLoaders.isEmpty())
265
// The main resource loader already finished loading. Set the cancelled error on the
266
// document and let the subresourceLoaders send individual cancelled messages below.
267
setMainDocumentError(frameLoader->cancelledError(m_request));
269
// If there are no resource loaders, we need to manufacture a cancelled message.
270
// (A back/forward navigation has no resource loaders because its resources are cached.)
271
mainReceivedError(frameLoader->cancelledError(m_request));
273
stopLoadingSubresources();
274
stopLoadingPlugIns();
276
m_isStopping = false;
279
void DocumentLoader::commitIfReady()
283
frameLoader()->commitProvisionalLoad();
287
void DocumentLoader::finishedLoading()
293
if (!maybeCreateArchive()) {
294
// If this is an empty document, it will not have actually been created yet. Commit dummy data so that
295
// DocumentWriter::begin() gets called and creates the Document.
298
frameLoader()->client()->finishedLoading(this);
302
if (!m_mainDocumentError.isNull())
304
clearMainResourceLoader();
305
if (!frameLoader()->stateMachine()->creatingInitialEmptyDocument())
306
frameLoader()->checkLoadComplete();
309
void DocumentLoader::commitLoad(const char* data, int length)
311
// Both unloading the old page and parsing the new page may execute JavaScript which destroys the datasource
312
// by starting a new load, so retain temporarily.
313
RefPtr<Frame> protectFrame(m_frame);
314
RefPtr<DocumentLoader> protectLoader(this);
317
FrameLoader* frameLoader = DocumentLoader::frameLoader();
320
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
321
if (ArchiveFactory::isArchiveMimeType(response().mimeType()))
324
frameLoader->client()->committedLoad(this, data, length);
327
void DocumentLoader::commitData(const char* bytes, size_t length)
329
if (!m_gotFirstByte) {
330
m_gotFirstByte = true;
331
m_writer.begin(documentURL(), false);
332
m_writer.setDocumentWasLoadedAsPartOfNavigation();
334
if (frameLoader()->stateMachine()->creatingInitialEmptyDocument())
338
// The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so
339
// relative URLs are resolved properly.
340
if (m_archive && m_archive->type() == Archive::MHTML)
341
m_frame->document()->setBaseURLOverride(m_archive->mainResource()->url());
344
// Call receivedFirstData() exactly once per load. We should only reach this point multiple times
345
// for multipart loads, and FrameLoader::isReplacing() will be true after the first time.
346
if (!isMultipartReplacingLoad())
347
frameLoader()->receivedFirstData();
349
bool userChosen = true;
350
String encoding = overrideEncoding();
351
if (encoding.isNull()) {
353
encoding = response().textEncodingName();
354
#if ENABLE(WEB_ARCHIVE)
355
if (m_archive && m_archive->type() == Archive::WebArchive)
356
encoding = m_archive->mainResource()->textEncoding();
359
m_writer.setEncoding(encoding, userChosen);
361
ASSERT(m_frame->document()->parsing());
362
m_writer.addData(bytes, length);
365
void DocumentLoader::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
367
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Loader);
368
info.addMember(m_frame);
369
info.addMember(m_mainResourceLoader);
370
info.addMember(m_subresourceLoaders);
371
info.addMember(m_multipartSubresourceLoaders);
372
info.addMember(m_plugInStreamLoaders);
373
info.addMember(m_substituteData);
374
info.addMember(m_pageTitle.string());
375
info.addMember(m_overrideEncoding);
376
info.addMember(m_responses);
377
info.addMember(m_originalRequest);
378
info.addMember(m_originalRequestCopy);
379
info.addMember(m_request);
380
info.addMember(m_response);
381
info.addMember(m_lastCheckedRequest);
382
info.addMember(m_responses);
383
info.addMember(m_pendingSubstituteResources);
384
info.addMember(m_resourcesClientKnowsAbout);
385
info.addMember(m_resourcesLoadedFromMemoryCacheForClientNotification);
386
info.addMember(m_clientRedirectSourceForHistory);
387
info.addMember(m_mainResourceData);
390
void DocumentLoader::receivedData(const char* data, int length)
392
if (!isMultipartReplacingLoad())
393
commitLoad(data, length);
396
void DocumentLoader::setupForReplace()
398
if (!mainResourceData())
401
maybeFinishLoadingMultipartContent();
402
maybeCreateArchive();
404
frameLoader()->setReplacing();
405
m_gotFirstByte = false;
407
stopLoadingSubresources();
408
stopLoadingPlugIns();
409
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
410
clearArchiveResources();
414
void DocumentLoader::checkLoadComplete()
416
if (!m_frame || isLoading())
418
ASSERT(this == frameLoader()->activeDocumentLoader());
419
m_frame->document()->domWindow()->finishedLoading();
422
void DocumentLoader::setFrame(Frame* frame)
424
if (m_frame == frame)
426
ASSERT(frame && !m_frame);
428
m_writer.setFrame(frame);
432
void DocumentLoader::attachToFrame()
437
void DocumentLoader::detachFromFrame()
440
RefPtr<Frame> protectFrame(m_frame);
441
RefPtr<DocumentLoader> protectLoader(this);
443
// It never makes sense to have a document loader that is detached from its
444
// frame have any loads active, so go ahead and kill all the loads.
447
m_applicationCacheHost->setDOMApplicationCache(0);
448
InspectorInstrumentation::loaderDetachedFromFrame(m_frame, this);
452
void DocumentLoader::clearMainResourceLoader()
454
if (m_mainResourceLoader) {
455
m_mainResourceData = m_mainResourceLoader->resourceData();
456
m_mainResourceLoader = 0;
458
m_loadingEmptyDocument = false;
460
if (this == frameLoader()->activeDocumentLoader())
464
bool DocumentLoader::isLoadingInAPISense() const
466
// Once a frame has loaded, we no longer need to consider subresources,
467
// but we still need to consider subframes.
468
if (frameLoader()->state() != FrameStateComplete) {
469
if (m_frame->settings()->needsIsLoadingInAPISenseQuirk() && !m_subresourceLoaders.isEmpty())
472
Document* doc = m_frame->document();
473
if ((isLoadingMainResource() || !m_frame->document()->loadEventFinished()) && isLoading())
475
if (m_cachedResourceLoader->requestCount())
477
if (DocumentParser* parser = doc->parser())
478
if (parser->processingData())
481
return frameLoader()->subframeIsLoading();
484
bool DocumentLoader::maybeCreateArchive()
486
#if !ENABLE(WEB_ARCHIVE) && !ENABLE(MHTML)
490
// Give the archive machinery a crack at this document. If the MIME type is not an archive type, it will return 0.
491
RefPtr<ResourceBuffer> mainResourceBuffer = mainResourceData();
492
m_archive = ArchiveFactory::create(m_response.url(), mainResourceBuffer ? mainResourceBuffer->sharedBuffer() : 0, m_response.mimeType());
496
addAllArchiveResources(m_archive.get());
497
ArchiveResource* mainResource = m_archive->mainResource();
498
m_parsedArchiveData = mainResource->data();
499
m_writer.setMIMEType(mainResource->mimeType());
501
ASSERT(m_frame->document());
502
commitData(mainResource->data()->data(), mainResource->data()->size());
504
#endif // !ENABLE(WEB_ARCHIVE) && !ENABLE(MHTML)
507
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
508
void DocumentLoader::setArchive(PassRefPtr<Archive> archive)
511
addAllArchiveResources(m_archive.get());
514
void DocumentLoader::addAllArchiveResources(Archive* archive)
516
if (!m_archiveResourceCollection)
517
m_archiveResourceCollection = adoptPtr(new ArchiveResourceCollection);
523
m_archiveResourceCollection->addAllResources(archive);
526
// FIXME: Adding a resource directly to a DocumentLoader/ArchiveResourceCollection seems like bad design, but is API some apps rely on.
527
// Can we change the design in a manner that will let us deprecate that API without reducing functionality of those apps?
528
void DocumentLoader::addArchiveResource(PassRefPtr<ArchiveResource> resource)
530
if (!m_archiveResourceCollection)
531
m_archiveResourceCollection = adoptPtr(new ArchiveResourceCollection);
537
m_archiveResourceCollection->addResource(resource);
540
PassRefPtr<Archive> DocumentLoader::popArchiveForSubframe(const String& frameName, const KURL& url)
542
return m_archiveResourceCollection ? m_archiveResourceCollection->popSubframeArchive(frameName, url) : PassRefPtr<Archive>(0);
545
void DocumentLoader::clearArchiveResources()
547
m_archiveResourceCollection.clear();
548
m_substituteResourceDeliveryTimer.stop();
551
SharedBuffer* DocumentLoader::parsedArchiveData() const
553
return m_parsedArchiveData.get();
555
#endif // ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
557
ArchiveResource* DocumentLoader::archiveResourceForURL(const KURL& url) const
559
if (!m_archiveResourceCollection)
562
ArchiveResource* resource = m_archiveResourceCollection->archiveResourceForURL(url);
564
return resource && !resource->shouldIgnoreWhenUnarchiving() ? resource : 0;
567
PassRefPtr<ArchiveResource> DocumentLoader::mainResource() const
569
const ResourceResponse& r = response();
571
RefPtr<ResourceBuffer> mainResourceBuffer = mainResourceData();
572
RefPtr<SharedBuffer> data = mainResourceBuffer ? mainResourceBuffer->sharedBuffer() : 0;
574
data = SharedBuffer::create();
576
return ArchiveResource::create(data, r.url(), r.mimeType(), r.textEncodingName(), frame()->tree()->uniqueName());
579
PassRefPtr<ArchiveResource> DocumentLoader::subresource(const KURL& url) const
584
CachedResource* resource = m_cachedResourceLoader->cachedResource(url);
585
if (!resource || !resource->isLoaded())
586
return archiveResourceForURL(url);
588
// FIXME: This has the side effect of making the resource non-purgeable.
589
// It would be better if it didn't have this permanent effect.
590
if (!resource->makePurgeable(false))
593
ResourceBuffer* data = resource->resourceBuffer();
597
return ArchiveResource::create(data->sharedBuffer(), url, resource->response());
600
void DocumentLoader::getSubresources(Vector<PassRefPtr<ArchiveResource> >& subresources) const
605
const CachedResourceLoader::DocumentResourceMap& allResources = m_cachedResourceLoader->allCachedResources();
606
CachedResourceLoader::DocumentResourceMap::const_iterator end = allResources.end();
607
for (CachedResourceLoader::DocumentResourceMap::const_iterator it = allResources.begin(); it != end; ++it) {
608
RefPtr<ArchiveResource> subresource = this->subresource(KURL(ParsedURLString, it->value->url()));
610
subresources.append(subresource.release());
616
void DocumentLoader::deliverSubstituteResourcesAfterDelay()
618
if (m_pendingSubstituteResources.isEmpty())
620
ASSERT(m_frame && m_frame->page());
621
if (m_frame->page()->defersLoading())
623
if (!m_substituteResourceDeliveryTimer.isActive())
624
m_substituteResourceDeliveryTimer.startOneShot(0);
627
void DocumentLoader::substituteResourceDeliveryTimerFired(Timer<DocumentLoader>*)
629
if (m_pendingSubstituteResources.isEmpty())
631
ASSERT(m_frame && m_frame->page());
632
if (m_frame->page()->defersLoading())
635
SubstituteResourceMap copy;
636
copy.swap(m_pendingSubstituteResources);
638
SubstituteResourceMap::const_iterator end = copy.end();
639
for (SubstituteResourceMap::const_iterator it = copy.begin(); it != end; ++it) {
640
RefPtr<ResourceLoader> loader = it->key;
641
SubstituteResource* resource = it->value.get();
644
SharedBuffer* data = resource->data();
646
loader->didReceiveResponse(resource->response());
648
// Calling ResourceLoader::didReceiveResponse can end up cancelling the load,
649
// so we need to check if the loader has reached its terminal state.
650
if (loader->reachedTerminalState())
653
loader->didReceiveData(data->data(), data->size(), data->size(), true);
655
// Calling ResourceLoader::didReceiveData can end up cancelling the load,
656
// so we need to check if the loader has reached its terminal state.
657
if (loader->reachedTerminalState())
660
loader->didFinishLoading(0);
662
// A null resource means that we should fail the load.
663
// FIXME: Maybe we should use another error here - something like "not in cache".
664
loader->didFail(loader->cannotShowURLError());
670
bool DocumentLoader::isSubstituteLoadPending(ResourceLoader* loader) const
672
return m_pendingSubstituteResources.contains(loader);
676
void DocumentLoader::cancelPendingSubstituteLoad(ResourceLoader* loader)
678
if (m_pendingSubstituteResources.isEmpty())
680
m_pendingSubstituteResources.remove(loader);
681
if (m_pendingSubstituteResources.isEmpty())
682
m_substituteResourceDeliveryTimer.stop();
685
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
686
bool DocumentLoader::scheduleArchiveLoad(ResourceLoader* loader, const ResourceRequest& request, const KURL& originalURL)
688
if (request.url() == originalURL) {
689
if (ArchiveResource* resource = archiveResourceForURL(originalURL)) {
690
m_pendingSubstituteResources.set(loader, resource);
691
deliverSubstituteResourcesAfterDelay();
699
switch (m_archive->type()) {
700
#if ENABLE(WEB_ARCHIVE)
701
case Archive::WebArchive:
702
// WebArchiveDebugMode means we fail loads instead of trying to fetch them from the network if they're not in the archive.
703
return m_frame->settings() && m_frame->settings()->webArchiveDebugModeEnabled() && ArchiveFactory::isArchiveMimeType(responseMIMEType());
707
return true; // Always fail the load for resources not included in the MHTML.
713
#endif // ENABLE(WEB_ARCHIVE)
715
void DocumentLoader::addResponse(const ResourceResponse& r)
717
if (!m_stopRecordingResponses)
718
m_responses.append(r);
721
void DocumentLoader::stopRecordingResponses()
723
m_stopRecordingResponses = true;
724
m_responses.shrinkToFit();
727
void DocumentLoader::setTitle(const StringWithDirection& title)
729
if (m_pageTitle == title)
732
frameLoader()->willChangeTitle(this);
734
frameLoader()->didChangeTitle(this);
737
KURL DocumentLoader::urlForHistory() const
739
// Return the URL to be used for history and B/F list.
740
// Returns nil for WebDataProtocol URLs that aren't alternates
741
// for unreachable URLs, because these can't be stored in history.
742
if (m_substituteData.isValid())
743
return unreachableURL();
745
return m_originalRequestCopy.url();
748
bool DocumentLoader::urlForHistoryReflectsFailure() const
750
return m_substituteData.isValid() || m_response.httpStatusCode() >= 400;
753
const KURL& DocumentLoader::originalURL() const
755
return m_originalRequestCopy.url();
758
const KURL& DocumentLoader::requestURL() const
760
return request().url();
763
const KURL& DocumentLoader::responseURL() const
765
return m_response.url();
768
KURL DocumentLoader::documentURL() const
770
KURL url = substituteData().responseURL();
771
#if ENABLE(WEB_ARCHIVE)
772
if (url.isEmpty() && m_archive && m_archive->type() == Archive::WebArchive)
773
url = m_archive->mainResource()->url();
782
const String& DocumentLoader::responseMIMEType() const
784
return m_response.mimeType();
787
const KURL& DocumentLoader::unreachableURL() const
789
return m_substituteData.failingURL();
792
void DocumentLoader::setDefersLoading(bool defers)
794
if (m_mainResourceLoader)
795
m_mainResourceLoader->setDefersLoading(defers);
796
setAllDefersLoading(m_subresourceLoaders, defers);
797
setAllDefersLoading(m_plugInStreamLoaders, defers);
799
deliverSubstituteResourcesAfterDelay();
802
void DocumentLoader::stopLoadingPlugIns()
804
cancelAll(m_plugInStreamLoaders);
807
void DocumentLoader::stopLoadingSubresources()
809
cancelAll(m_subresourceLoaders);
812
void DocumentLoader::addSubresourceLoader(ResourceLoader* loader)
814
m_subresourceLoaders.add(loader);
817
void DocumentLoader::removeSubresourceLoader(ResourceLoader* loader)
819
m_subresourceLoaders.remove(loader);
821
if (Frame* frame = m_frame)
822
frame->loader()->checkLoadComplete();
825
void DocumentLoader::addPlugInStreamLoader(ResourceLoader* loader)
827
m_plugInStreamLoaders.add(loader);
830
void DocumentLoader::removePlugInStreamLoader(ResourceLoader* loader)
832
m_plugInStreamLoaders.remove(loader);
836
bool DocumentLoader::isLoadingMainResource() const
838
return !!m_mainResourceLoader || m_loadingEmptyDocument;
841
bool DocumentLoader::isLoadingMultipartContent() const
843
return m_mainResourceLoader && m_mainResourceLoader->isLoadingMultipartContent();
846
bool DocumentLoader::isMultipartReplacingLoad() const
848
return isLoadingMultipartContent() && frameLoader()->isReplacing();
851
bool DocumentLoader::maybeLoadEmpty()
853
bool shouldLoadEmpty = !m_substituteData.isValid() && (m_request.url().isEmpty() || SchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(m_request.url().protocol()));
854
if (!shouldLoadEmpty && !frameLoader()->client()->representationExistsForURLScheme(m_request.url().protocol()))
857
m_loadingEmptyDocument = true;
858
if (m_request.url().isEmpty() && !frameLoader()->stateMachine()->creatingInitialEmptyDocument())
859
m_request.setURL(blankURL());
860
String mimeType = shouldLoadEmpty ? "text/html" : frameLoader()->client()->generatedMIMETypeForURLScheme(m_request.url().protocol());
861
setResponse(ResourceResponse(m_request.url(), mimeType, 0, String(), String()));
866
void DocumentLoader::startLoadingMainResource()
868
m_mainDocumentError = ResourceError();
869
timing()->markNavigationStart();
870
ASSERT(!m_mainResourceLoader);
872
if (maybeLoadEmpty())
875
m_mainResourceLoader = MainResourceLoader::create(m_frame);
877
// FIXME: Is there any way the extra fields could have not been added by now?
878
// If not, it would be great to remove this line of code.
879
frameLoader()->addExtraFieldsToMainResourceRequest(m_request);
880
m_mainResourceLoader->load(m_request, m_substituteData);
882
if (m_request.isNull()) {
883
m_mainResourceLoader = 0;
888
void DocumentLoader::cancelMainResourceLoad(const ResourceError& error)
890
m_mainResourceLoader->cancel(error);
893
void DocumentLoader::subresourceLoaderFinishedLoadingOnePart(ResourceLoader* loader)
895
m_multipartSubresourceLoaders.add(loader);
896
m_subresourceLoaders.remove(loader);
898
if (Frame* frame = m_frame)
899
frame->loader()->checkLoadComplete();
902
void DocumentLoader::maybeFinishLoadingMultipartContent()
904
if (!frameLoader()->isReplacing())
907
frameLoader()->setupForReplace();
909
RefPtr<ResourceBuffer> resourceData = mainResourceData();
910
commitLoad(resourceData->data(), resourceData->size());
913
void DocumentLoader::iconLoadDecisionAvailable()
916
m_frame->loader()->icon()->loadDecisionReceived(iconDatabase().synchronousLoadDecisionForIconURL(frameLoader()->icon()->url(), this));
919
static void iconLoadDecisionCallback(IconLoadDecision decision, void* context)
921
static_cast<DocumentLoader*>(context)->continueIconLoadWithDecision(decision);
924
void DocumentLoader::getIconLoadDecisionForIconURL(const String& urlString)
926
if (m_iconLoadDecisionCallback)
927
m_iconLoadDecisionCallback->invalidate();
928
m_iconLoadDecisionCallback = IconLoadDecisionCallback::create(this, iconLoadDecisionCallback);
929
iconDatabase().loadDecisionForIconURL(urlString, m_iconLoadDecisionCallback);
932
void DocumentLoader::continueIconLoadWithDecision(IconLoadDecision decision)
934
ASSERT(m_iconLoadDecisionCallback);
935
m_iconLoadDecisionCallback = 0;
937
m_frame->loader()->icon()->continueLoadWithDecision(decision);
940
static void iconDataCallback(SharedBuffer*, void*)
942
// FIXME: Implement this once we know what parts of WebCore actually need the icon data returned.
945
void DocumentLoader::getIconDataForIconURL(const String& urlString)
947
if (m_iconDataCallback)
948
m_iconDataCallback->invalidate();
949
m_iconDataCallback = IconDataCallback::create(this, iconDataCallback);
950
iconDatabase().iconDataForIconURL(urlString, m_iconDataCallback);
953
void DocumentLoader::handledOnloadEvents()
955
m_wasOnloadHandled = true;
956
applicationCacheHost()->stopDeferringEvents();
959
} // namespace WebCore