WebCore/loader/ResourceLoadNotifier.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 "ResourceLoadNotifier.h"
       
    33 
       
    34 #include "DocumentLoader.h"
       
    35 #include "Frame.h"
       
    36 #include "FrameLoader.h"
       
    37 #include "FrameLoaderClient.h"
       
    38 #include "InspectorController.h"
       
    39 #include "Page.h"
       
    40 #include "ProgressTracker.h"
       
    41 #include "ResourceLoader.h"
       
    42 
       
    43 namespace WebCore {
       
    44 
       
    45 ResourceLoadNotifier::ResourceLoadNotifier(Frame* frame)
       
    46     : m_frame(frame)
       
    47 {
       
    48 }
       
    49 
       
    50 void ResourceLoadNotifier::didReceiveAuthenticationChallenge(ResourceLoader* loader, const AuthenticationChallenge& currentWebChallenge)
       
    51 {
       
    52     m_frame->loader()->client()->dispatchDidReceiveAuthenticationChallenge(loader->documentLoader(), loader->identifier(), currentWebChallenge);
       
    53 }
       
    54 
       
    55 void ResourceLoadNotifier::didCancelAuthenticationChallenge(ResourceLoader* loader, const AuthenticationChallenge& currentWebChallenge)
       
    56 {
       
    57     m_frame->loader()->client()->dispatchDidCancelAuthenticationChallenge(loader->documentLoader(), loader->identifier(), currentWebChallenge);
       
    58 }
       
    59 
       
    60 void ResourceLoadNotifier::willSendRequest(ResourceLoader* loader, ResourceRequest& clientRequest, const ResourceResponse& redirectResponse)
       
    61 {
       
    62     m_frame->loader()->applyUserAgent(clientRequest);
       
    63 
       
    64     dispatchWillSendRequest(loader->documentLoader(), loader->identifier(), clientRequest, redirectResponse);
       
    65 }
       
    66 
       
    67 void ResourceLoadNotifier::didReceiveResponse(ResourceLoader* loader, const ResourceResponse& r)
       
    68 {
       
    69     loader->documentLoader()->addResponse(r);
       
    70 
       
    71     if (Page* page = m_frame->page())
       
    72         page->progress()->incrementProgress(loader->identifier(), r);
       
    73 
       
    74     dispatchDidReceiveResponse(loader->documentLoader(), loader->identifier(), r);
       
    75 }
       
    76 
       
    77 void ResourceLoadNotifier::didReceiveData(ResourceLoader* loader, const char* data, int length, int lengthReceived)
       
    78 {
       
    79     if (Page* page = m_frame->page())
       
    80         page->progress()->incrementProgress(loader->identifier(), data, length);
       
    81 
       
    82     dispatchDidReceiveContentLength(loader->documentLoader(), loader->identifier(), lengthReceived);
       
    83 }
       
    84 
       
    85 void ResourceLoadNotifier::didFinishLoad(ResourceLoader* loader)
       
    86 {    
       
    87     if (Page* page = m_frame->page())
       
    88         page->progress()->completeProgress(loader->identifier());
       
    89     dispatchDidFinishLoading(loader->documentLoader(), loader->identifier());
       
    90 }
       
    91 
       
    92 void ResourceLoadNotifier::didFailToLoad(ResourceLoader* loader, const ResourceError& error)
       
    93 {
       
    94     if (Page* page = m_frame->page())
       
    95         page->progress()->completeProgress(loader->identifier());
       
    96 
       
    97     if (!error.isNull())
       
    98         m_frame->loader()->client()->dispatchDidFailLoading(loader->documentLoader(), loader->identifier(), error);
       
    99 
       
   100 #if ENABLE(INSPECTOR)
       
   101     if (Page* page = m_frame->page())
       
   102         page->inspectorController()->didFailLoading(loader->identifier(), error);
       
   103 #endif
       
   104 }
       
   105 
       
   106 void ResourceLoadNotifier::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request)
       
   107 {
       
   108     m_frame->loader()->client()->assignIdentifierToInitialRequest(identifier, loader, request);
       
   109 
       
   110 #if ENABLE(INSPECTOR)
       
   111     if (Page* page = m_frame->page())
       
   112         page->inspectorController()->identifierForInitialRequest(identifier, loader, request);
       
   113 #endif
       
   114 }
       
   115 
       
   116 void ResourceLoadNotifier::dispatchWillSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
       
   117 {
       
   118     StringImpl* oldRequestURL = request.url().string().impl();
       
   119     m_frame->loader()->documentLoader()->didTellClientAboutLoad(request.url());
       
   120 
       
   121     m_frame->loader()->client()->dispatchWillSendRequest(loader, identifier, request, redirectResponse);
       
   122 
       
   123     // If the URL changed, then we want to put that new URL in the "did tell client" set too.
       
   124     if (!request.isNull() && oldRequestURL != request.url().string().impl())
       
   125         m_frame->loader()->documentLoader()->didTellClientAboutLoad(request.url());
       
   126 
       
   127 #if ENABLE(INSPECTOR)
       
   128     if (Page* page = m_frame->page())
       
   129         page->inspectorController()->willSendRequest(identifier, request, redirectResponse);
       
   130 #endif
       
   131 }
       
   132 
       
   133 void ResourceLoadNotifier::dispatchDidReceiveResponse(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
       
   134 {
       
   135     m_frame->loader()->client()->dispatchDidReceiveResponse(loader, identifier, r);
       
   136 
       
   137 #if ENABLE(INSPECTOR)
       
   138     if (Page* page = m_frame->page())
       
   139         page->inspectorController()->didReceiveResponse(identifier, r);
       
   140 #endif
       
   141 }
       
   142 
       
   143 void ResourceLoadNotifier::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long identifier, int length)
       
   144 {
       
   145     m_frame->loader()->client()->dispatchDidReceiveContentLength(loader, identifier, length);
       
   146 
       
   147 #if ENABLE(INSPECTOR)
       
   148     if (Page* page = m_frame->page())
       
   149         page->inspectorController()->didReceiveContentLength(identifier, length);
       
   150 #endif
       
   151 }
       
   152 
       
   153 void ResourceLoadNotifier::dispatchDidFinishLoading(DocumentLoader* loader, unsigned long identifier)
       
   154 {
       
   155     m_frame->loader()->client()->dispatchDidFinishLoading(loader, identifier);
       
   156 
       
   157 #if ENABLE(INSPECTOR)
       
   158     if (Page* page = m_frame->page())
       
   159         page->inspectorController()->didFinishLoading(identifier);
       
   160 #endif
       
   161 }
       
   162 
       
   163 void ResourceLoadNotifier::sendRemainingDelegateMessages(DocumentLoader* loader, unsigned long identifier, const ResourceResponse& response, int length, const ResourceError& error)
       
   164 {
       
   165     if (!response.isNull())
       
   166         dispatchDidReceiveResponse(loader, identifier, response);
       
   167 
       
   168     if (length > 0)
       
   169         dispatchDidReceiveContentLength(loader, identifier, length);
       
   170 
       
   171     if (error.isNull())
       
   172         dispatchDidFinishLoading(loader, identifier);
       
   173     else
       
   174         m_frame->loader()->client()->dispatchDidFailLoading(loader, identifier, error);
       
   175 }
       
   176 
       
   177 } // namespace WebCore