1cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block/* 2cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 4cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 5cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * 6cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * Redistribution and use in source and binary forms, with or without 7cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * modification, are permitted provided that the following conditions 8cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * are met: 9cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * 10cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * 1. Redistributions of source code must retain the above copyright 11cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * notice, this list of conditions and the following disclaimer. 12cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * 2. Redistributions in binary form must reproduce the above copyright 13cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * notice, this list of conditions and the following disclaimer in the 14cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * documentation and/or other materials provided with the distribution. 15cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 16cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * its contributors may be used to endorse or promote products derived 17cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * from this software without specific prior written permission. 18cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * 19cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block */ 30cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 31cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "config.h" 32cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "ResourceLoadNotifier.h" 33cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 34cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "DocumentLoader.h" 35cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "Frame.h" 36cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "FrameLoader.h" 37cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "FrameLoaderClient.h" 3865f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch#include "InspectorInstrumentation.h" 39cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "Page.h" 40cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "ProgressTracker.h" 41cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "ResourceLoader.h" 42cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 43cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blocknamespace WebCore { 44cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 45cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve BlockResourceLoadNotifier::ResourceLoadNotifier(Frame* frame) 46cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block : m_frame(frame) 47cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 48cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 49cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 50cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid ResourceLoadNotifier::didReceiveAuthenticationChallenge(ResourceLoader* loader, const AuthenticationChallenge& currentWebChallenge) 51cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 52cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->client()->dispatchDidReceiveAuthenticationChallenge(loader->documentLoader(), loader->identifier(), currentWebChallenge); 53cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 54cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 55cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid ResourceLoadNotifier::didCancelAuthenticationChallenge(ResourceLoader* loader, const AuthenticationChallenge& currentWebChallenge) 56cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 57cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->client()->dispatchDidCancelAuthenticationChallenge(loader->documentLoader(), loader->identifier(), currentWebChallenge); 58cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 59cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 60cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid ResourceLoadNotifier::willSendRequest(ResourceLoader* loader, ResourceRequest& clientRequest, const ResourceResponse& redirectResponse) 61cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 62cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->applyUserAgent(clientRequest); 63cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 64cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block dispatchWillSendRequest(loader->documentLoader(), loader->identifier(), clientRequest, redirectResponse); 65cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 66cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 67cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid ResourceLoadNotifier::didReceiveResponse(ResourceLoader* loader, const ResourceResponse& r) 68cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 69cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block loader->documentLoader()->addResponse(r); 70cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 71cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (Page* page = m_frame->page()) 72cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block page->progress()->incrementProgress(loader->identifier(), r); 73cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 74cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block dispatchDidReceiveResponse(loader->documentLoader(), loader->identifier(), r); 75cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 76cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 772daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochvoid ResourceLoadNotifier::didReceiveData(ResourceLoader* loader, const char* data, int dataLength, int encodedDataLength) 78cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 79cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (Page* page = m_frame->page()) 802bde8e466a4451c7319e3a072d118917957d6554Steve Block page->progress()->incrementProgress(loader->identifier(), data, dataLength); 81cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 822daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch dispatchDidReceiveContentLength(loader->documentLoader(), loader->identifier(), dataLength, encodedDataLength); 83cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 84cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 8568513a70bcd92384395513322f1b801e7bf9c729Steve Blockvoid ResourceLoadNotifier::didFinishLoad(ResourceLoader* loader, double finishTime) 86cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 87cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (Page* page = m_frame->page()) 88cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block page->progress()->completeProgress(loader->identifier()); 8968513a70bcd92384395513322f1b801e7bf9c729Steve Block dispatchDidFinishLoading(loader->documentLoader(), loader->identifier(), finishTime); 90cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 91cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 92cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid ResourceLoadNotifier::didFailToLoad(ResourceLoader* loader, const ResourceError& error) 93cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 94cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (Page* page = m_frame->page()) 95cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block page->progress()->completeProgress(loader->identifier()); 96cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 97cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!error.isNull()) 98cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->client()->dispatchDidFailLoading(loader->documentLoader(), loader->identifier(), error); 99643ca7872b450ea4efacab6188849e5aac2ba161Steve Block 10065f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch InspectorInstrumentation::didFailLoading(m_frame, loader->identifier(), error); 101cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 102cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 103cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid ResourceLoadNotifier::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request) 104cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 105cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->client()->assignIdentifierToInitialRequest(identifier, loader, request); 106cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 107cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 108cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid ResourceLoadNotifier::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse) 109cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 110cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block StringImpl* oldRequestURL = request.url().string().impl(); 111cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->documentLoader()->didTellClientAboutLoad(request.url()); 112cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 113cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->client()->dispatchWillSendRequest(loader, identifier, request, redirectResponse); 114cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 115cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block // If the URL changed, then we want to put that new URL in the "did tell client" set too. 116cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!request.isNull() && oldRequestURL != request.url().string().impl()) 117cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->documentLoader()->didTellClientAboutLoad(request.url()); 118cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 1192bde8e466a4451c7319e3a072d118917957d6554Steve Block InspectorInstrumentation::willSendRequest(m_frame, identifier, loader, request, redirectResponse); 12065f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch 12165f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch // Report WebTiming for all frames. 12265f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch if (loader && !request.isNull() && request.url() == loader->requestURL()) 12365f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch request.setReportLoadTiming(true); 124cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 125cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 126cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid ResourceLoadNotifier::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r) 127cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 12865f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(m_frame, identifier, r); 129cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->client()->dispatchDidReceiveResponse(loader, identifier, r); 13065f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch InspectorInstrumentation::didReceiveResourceResponse(cookie, identifier, loader, r); 131cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 132cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 1332daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochvoid ResourceLoadNotifier::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long identifier, int dataLength, int encodedDataLength) 134cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 1352bde8e466a4451c7319e3a072d118917957d6554Steve Block m_frame->loader()->client()->dispatchDidReceiveContentLength(loader, identifier, dataLength); 136cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 1372daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch InspectorInstrumentation::didReceiveContentLength(m_frame, identifier, dataLength, encodedDataLength); 138cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 139cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 14068513a70bcd92384395513322f1b801e7bf9c729Steve Blockvoid ResourceLoadNotifier::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier, double finishTime) 141cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 142cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->client()->dispatchDidFinishLoading(loader, identifier); 143cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 14465f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch InspectorInstrumentation::didFinishLoading(m_frame, identifier, finishTime); 145cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 146cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 1476b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brennervoid ResourceLoadNotifier::dispatchTransferLoadingResourceFromPage(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request, Page* oldPage) 1486b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner{ 1496b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner ASSERT(oldPage != m_frame->page()); 1506b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner m_frame->loader()->client()->transferLoadingResourceFromPage(identifier, loader, request, oldPage); 1516b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner 1526b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner oldPage->progress()->completeProgress(identifier); 1536b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner} 1546b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner 1552daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochvoid ResourceLoadNotifier::sendRemainingDelegateMessages(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response, int dataLength, int encodedDataLength, const ResourceError& error) 156cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 157cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!response.isNull()) 158cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block dispatchDidReceiveResponse(loader, identifier, response); 159cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 1602bde8e466a4451c7319e3a072d118917957d6554Steve Block if (dataLength > 0) 1612daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch dispatchDidReceiveContentLength(loader, identifier, dataLength, encodedDataLength); 162cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 163cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (error.isNull()) 16468513a70bcd92384395513322f1b801e7bf9c729Steve Block dispatchDidFinishLoading(loader, identifier, 0); 165cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block else 166cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_frame->loader()->client()->dispatchDidFailLoading(loader, identifier, error); 167cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 168cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 169cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} // namespace WebCore 170