2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "ResourceLoadNotifier.h"
34 #include "DocumentLoader.h"
36 #include "FrameLoader.h"
37 #include "FrameLoaderClient.h"
38 #include "InspectorInstrumentation.h"
40 #include "ProgressTracker.h"
41 #include "ResourceLoader.h"
45 ResourceLoadNotifier::ResourceLoadNotifier(Frame* frame)
50 void ResourceLoadNotifier::didReceiveAuthenticationChallenge(ResourceLoader* loader, const AuthenticationChallenge& currentWebChallenge)
52 m_frame->loader()->client()->dispatchDidReceiveAuthenticationChallenge(loader->documentLoader(), loader->identifier(), currentWebChallenge);
55 void ResourceLoadNotifier::didCancelAuthenticationChallenge(ResourceLoader* loader, const AuthenticationChallenge& currentWebChallenge)
57 m_frame->loader()->client()->dispatchDidCancelAuthenticationChallenge(loader->documentLoader(), loader->identifier(), currentWebChallenge);
60 void ResourceLoadNotifier::willSendRequest(ResourceLoader* loader, ResourceRequest& clientRequest, const ResourceResponse& redirectResponse)
62 m_frame->loader()->applyUserAgent(clientRequest);
64 dispatchWillSendRequest(loader->documentLoader(), loader->identifier(), clientRequest, redirectResponse);
67 void ResourceLoadNotifier::didReceiveResponse(ResourceLoader* loader, const ResourceResponse& r)
69 loader->documentLoader()->addResponse(r);
71 if (Page* page = m_frame->page())
72 page->progress()->incrementProgress(loader->identifier(), r);
74 dispatchDidReceiveResponse(loader->documentLoader(), loader->identifier(), r);
77 void ResourceLoadNotifier::didReceiveData(ResourceLoader* loader, const char* data, int dataLength, int encodedDataLength)
79 if (Page* page = m_frame->page())
80 page->progress()->incrementProgress(loader->identifier(), data, dataLength);
82 dispatchDidReceiveData(loader->documentLoader(), loader->identifier(), data, dataLength, encodedDataLength);
85 void ResourceLoadNotifier::didFinishLoad(ResourceLoader* loader, double finishTime)
87 if (Page* page = m_frame->page())
88 page->progress()->completeProgress(loader->identifier());
89 dispatchDidFinishLoading(loader->documentLoader(), loader->identifier(), finishTime);
92 void ResourceLoadNotifier::didFailToLoad(ResourceLoader* loader, const ResourceError& error)
94 if (Page* page = m_frame->page())
95 page->progress()->completeProgress(loader->identifier());
98 m_frame->loader()->client()->dispatchDidFailLoading(loader->documentLoader(), loader->identifier(), error);
100 InspectorInstrumentation::didFailLoading(m_frame, loader->documentLoader(), loader->identifier(), error);
103 void ResourceLoadNotifier::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request)
105 m_frame->loader()->client()->assignIdentifierToInitialRequest(identifier, loader, request);
108 void ResourceLoadNotifier::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
110 String oldRequestURL = request.url().string();
111 m_frame->loader()->documentLoader()->didTellClientAboutLoad(request.url());
113 m_frame->loader()->client()->dispatchWillSendRequest(loader, identifier, request, redirectResponse);
115 // If the URL changed, then we want to put that new URL in the "did tell client" set too.
116 if (!request.isNull() && oldRequestURL != request.url().string())
117 m_frame->loader()->documentLoader()->didTellClientAboutLoad(request.url());
119 InspectorInstrumentation::willSendRequest(m_frame, identifier, loader, request, redirectResponse);
121 // Report WebTiming for all frames.
122 if (loader && !request.isNull() && request.url() == loader->requestURL())
123 request.setReportLoadTiming(true);
126 void ResourceLoadNotifier::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
128 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(m_frame, identifier, r);
129 m_frame->loader()->client()->dispatchDidReceiveResponse(loader, identifier, r);
130 InspectorInstrumentation::didReceiveResourceResponse(cookie, identifier, loader, r);
133 void ResourceLoadNotifier::dispatchDidReceiveData(DocumentLoader* loader, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
135 m_frame->loader()->client()->dispatchDidReceiveContentLength(loader, identifier, dataLength);
137 InspectorInstrumentation::didReceiveData(m_frame, identifier, data, dataLength, encodedDataLength);
140 void ResourceLoadNotifier::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier, double finishTime)
142 m_frame->loader()->client()->dispatchDidFinishLoading(loader, identifier);
144 InspectorInstrumentation::didFinishLoading(m_frame, loader, identifier, finishTime);
147 void ResourceLoadNotifier::dispatchTransferLoadingResourceFromPage(ResourceLoader* loader, const ResourceRequest& request, Page* oldPage)
149 ASSERT(oldPage != m_frame->page());
150 m_frame->loader()->client()->transferLoadingResourceFromPage(loader, request, oldPage);
152 oldPage->progress()->completeProgress(loader->identifier());
155 void ResourceLoadNotifier::sendRemainingDelegateMessages(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response, const char* data, int dataLength, int encodedDataLength, const ResourceError& error)
157 if (!response.isNull())
158 dispatchDidReceiveResponse(loader, identifier, response);
161 dispatchDidReceiveData(loader, identifier, data, dataLength, encodedDataLength);
164 dispatchDidFinishLoading(loader, identifier, 0);
166 m_frame->loader()->client()->dispatchDidFailLoading(loader, identifier, error);
169 } // namespace WebCore