blob: 2804a0d565ad8f08404b7f7fbab234d540acd355 [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001 /*
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
Ben Murdoch02772c62013-07-26 10:21:05 +010011 * notice, this list of conditions and the following disclaimer.
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010012 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
Ben Murdoch02772c62013-07-26 10:21:05 +010014 * documentation and/or other materials provided with the distribution.
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010015 * 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
Ben Murdoch02772c62013-07-26 10:21:05 +010017 * from this software without specific prior written permission.
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010018 *
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"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010039#include "core/page/Frame.h"
40#include "core/page/Page.h"
41
42namespace WebCore {
43
44ResourceLoadNotifier::ResourceLoadNotifier(Frame* frame)
45 : m_frame(frame)
46{
47}
48
Ben Murdochfff88842013-07-30 15:20:09 +010049void ResourceLoadNotifier::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& initiatorInfo)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010050{
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010051 m_frame->loader()->applyUserAgent(request);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010052 m_frame->loader()->client()->dispatchWillSendRequest(loader, identifier, request, redirectResponse);
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010053 InspectorInstrumentation::willSendRequest(m_frame, identifier, loader, request, redirectResponse, initiatorInfo);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010054}
55
56void ResourceLoadNotifier::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r, ResourceLoader* resourceLoader)
57{
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010058 if (Page* page = m_frame->page())
59 page->progress()->incrementProgress(identifier, r);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010060 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
65void ResourceLoadNotifier::dispatchDidReceiveData(DocumentLoader*, unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
66{
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010067 if (Page* page = m_frame->page())
68 page->progress()->incrementProgress(identifier, data, dataLength);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010069 InspectorInstrumentation::didReceiveData(m_frame, identifier, data, dataLength, encodedDataLength);
70}
71
72void ResourceLoadNotifier::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier, double finishTime)
73{
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010074 if (Page* page = m_frame->page())
75 page->progress()->completeProgress(identifier);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010076 m_frame->loader()->client()->dispatchDidFinishLoading(loader, identifier);
77
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +010078 InspectorInstrumentation::didFinishLoading(m_frame, identifier, loader, finishTime);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010079}
80
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010081void ResourceLoadNotifier::dispatchDidFail(DocumentLoader* loader, unsigned long identifier, const ResourceError& error)
82{
83 if (Page* page = m_frame->page())
84 page->progress()->completeProgress(identifier);
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010085 InspectorInstrumentation::didFailLoading(m_frame, identifier, loader, error);
86}
87
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010088void 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
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010099 dispatchDidFail(loader, identifier, error);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100100}
101
102} // namespace WebCore