1 /* 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/) 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 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. 18 * 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. 29 */ 30 31 #include "config.h" 32 #include "core/loader/ResourceLoadNotifier.h" 33 34 #include "core/inspector/InspectorInstrumentation.h" 35 #include "core/loader/DocumentLoader.h" 36 #include "core/loader/FrameLoader.h" 37 #include "core/loader/FrameLoaderClient.h" 38 #include "core/loader/ProgressTracker.h" 39 #include "core/page/Frame.h" 40 #include "core/page/Page.h" 41 42 namespace WebCore { 43 44 ResourceLoadNotifier::ResourceLoadNotifier(Frame* frame) 45 : m_frame(frame) 46 { 47 } 48 49 void ResourceLoadNotifier::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& initiatorInfo) 50 { 51 m_frame->loader()->applyUserAgent(request); 52 m_frame->loader()->client()->dispatchWillSendRequest(loader, identifier, request, redirectResponse); 53 InspectorInstrumentation::willSendRequest(m_frame, identifier, loader, request, redirectResponse, initiatorInfo); 54 } 55 56 void ResourceLoadNotifier::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r, ResourceLoader* resourceLoader) 57 { 58 if (Page* page = m_frame->page()) 59 page->progress()->incrementProgress(identifier, r); 60 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(m_frame, identifier, r); 61 m_frame->loader()->client()->dispatchDidReceiveResponse(loader, identifier, r); 62 InspectorInstrumentation::didReceiveResourceResponse(cookie, identifier, loader, r, resourceLoader); 63 } 64 65 void ResourceLoadNotifier::dispatchDidReceiveData(DocumentLoader*, unsigned long identifier, const char* data, int dataLength, int encodedDataLength) 66 { 67 if (Page* page = m_frame->page()) 68 page->progress()->incrementProgress(identifier, data, dataLength); 69 InspectorInstrumentation::didReceiveData(m_frame, identifier, data, dataLength, encodedDataLength); 70 } 71 72 void ResourceLoadNotifier::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier, double finishTime) 73 { 74 if (Page* page = m_frame->page()) 75 page->progress()->completeProgress(identifier); 76 m_frame->loader()->client()->dispatchDidFinishLoading(loader, identifier); 77 78 InspectorInstrumentation::didFinishLoading(m_frame, identifier, loader, finishTime); 79 } 80 81 void ResourceLoadNotifier::dispatchDidFail(DocumentLoader* loader, unsigned long identifier, const ResourceError& error) 82 { 83 if (Page* page = m_frame->page()) 84 page->progress()->completeProgress(identifier); 85 InspectorInstrumentation::didFailLoading(m_frame, identifier, loader, error); 86 } 87 88 void ResourceLoadNotifier::sendRemainingDelegateMessages(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response, const char* data, int dataLength, int encodedDataLength, const ResourceError& error) 89 { 90 if (!response.isNull()) 91 dispatchDidReceiveResponse(loader, identifier, response); 92 93 if (dataLength > 0) 94 dispatchDidReceiveData(loader, identifier, data, dataLength, encodedDataLength); 95 96 if (error.isNull()) 97 dispatchDidFinishLoading(loader, identifier, 0); 98 else 99 dispatchDidFail(loader, identifier, error); 100 } 101 102 } // namespace WebCore 103