Changeset 56750 in webkit


Ignore:
Timestamp:
Mar 29, 2010 4:58:03 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-03-29 Dawit Alemayehu <adawit@kde.org>

Reviewed by Simon Hausmann.

Added a function, WebCore::shouldTreatAsAttachment, to HTTPParsers.*

https://bugs.webkit.org/show_bug.cgi?id=36395

This function, which was moved from WebKit/chromium/src/FrameClientImpl.cpp,
is used to check whether or not a request is supposed to be rendered or
simply downloaded based on the "Content-Disposition" header sent by the
web server. The intent of code refactoring is to avoid code duplication
so that this piece of code can be used by other implementations such as
QtWebKit.

  • platform/network/HTTPParsers.cpp: (WebCore::shouldTreatAsAttachment):
  • platform/network/HTTPParsers.h:

2010-03-29 Dawit Alemayehu <adawit@kde.org>

Reviewed by Simon Hausmann.

Factored out the 'ShouldTreatAsAttachment' function to HTTPParsers.*
and replacted local version with the factored out version.

The code was factored out to make possible its use in other implementations
such as QtWebKit.

  • src/FrameLoaderClientImpl.cpp: (WebKit::FrameLoaderClientImpl::dispatchDecidePolicyForMIMEType):

2010-03-29 Dawit Alemayehu <adawit@kde.org>

Reviewed by Simon Hausmann.

[Qt] Added support for handling the HTTP "Content-Disposition" header.

https://bugs.webkit.org/show_bug.cgi?id=36395

Whenever a server response contains a "Content-Disposition: attachment..." header,
treat the request as a download and emit the unsupportedContent signal.

  • Api/qwebpage.cpp:
  • WebCoreSupport/FrameLoaderClientQt.cpp: (WebCore::FrameLoaderClientQt::download): (WebCore::FrameLoaderClientQt::dispatchDecidePolicyForMIMEType):
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56749 r56750  
     12010-03-29  Dawit Alemayehu  <adawit@kde.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        Added a function, WebCore::shouldTreatAsAttachment, to HTTPParsers.*
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=36395
     8
     9        This function, which was moved from WebKit/chromium/src/FrameClientImpl.cpp,
     10        is used to check whether or not a request is supposed to be rendered or
     11        simply downloaded based on the "Content-Disposition" header sent by the
     12        web server. The intent of code refactoring is to avoid code duplication
     13        so that this piece of code can be used by other implementations such as
     14        QtWebKit.
     15
     16        * platform/network/HTTPParsers.cpp:
     17        (WebCore::shouldTreatAsAttachment):
     18        * platform/network/HTTPParsers.h:
     19
    1202010-03-29  Chris Fleizach  <cfleizach@apple.com>
    221
  • trunk/WebCore/platform/network/HTTPParsers.cpp

    r56295 r56750  
    33 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
    44 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
     5 * Copyright (C) 2009 Google Inc. All rights reserved.
    56 *
    67 * Redistribution and use in source and binary forms, with or without
     
    3132#include "config.h"
    3233#include "HTTPParsers.h"
     34#include "ResourceResponseBase.h"
    3335
    3436#include "CString.h"
     
    6971
    7072    return true;
     73}
     74
     75bool shouldTreatAsAttachment(const ResourceResponseBase& response)
     76{
     77    const String& contentDisposition = response.httpHeaderField("Content-Disposition");
     78   
     79    if (contentDisposition.isEmpty())
     80        return false;
     81
     82    // Some broken sites just send
     83    // Content-Disposition: ; filename="file"
     84    // screen those out here.
     85    if (contentDisposition.startsWith(";"))
     86        return false;
     87
     88    if (contentDisposition.startsWith("inline", false))
     89        return false;
     90
     91    // Some broken sites just send
     92    // Content-Disposition: filename="file"
     93    // without a disposition token... screen those out.
     94    if (contentDisposition.startsWith("filename", false))
     95        return false;
     96
     97    // Also in use is Content-Disposition: name="file"
     98    if (contentDisposition.startsWith("name", false))
     99        return false;
     100
     101    // We have a content-disposition of "attachment" or unknown.
     102    // RFC 2183, section 2.8 says that an unknown disposition
     103    // value should be treated as "attachment"
     104    return true; 
    71105}
    72106
  • trunk/WebCore/platform/network/HTTPParsers.h

    r56295 r56750  
    11/*
    22 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334
    3435class String;
     36class ResourceResponseBase;
    3537
    3638enum XSSProtectionDisposition {
     
    4042};
    4143
     44
     45bool shouldTreatAsAttachment(const ResourceResponseBase& response);
    4246bool parseHTTPRefresh(const String& refresh, bool fromHttpEquivMeta, double& delay, String& url);
    4347double parseDate(const String&);
  • trunk/WebKit/chromium/ChangeLog

    r56728 r56750  
     12010-03-29  Dawit Alemayehu  <adawit@kde.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        Factored out the 'ShouldTreatAsAttachment' function to HTTPParsers.*
     6        and replacted local version with the factored out version.
     7
     8        The code was factored out to make possible its use in other implementations
     9        such as QtWebKit.
     10
     11        * src/FrameLoaderClientImpl.cpp:
     12        (WebKit::FrameLoaderClientImpl::dispatchDecidePolicyForMIMEType):
     13
    1142010-03-29  Jochen Eisinger  <jochen@chromium.org>
    215
  • trunk/WebKit/chromium/src/FrameLoaderClientImpl.cpp

    r56346 r56750  
    3939#include "FrameLoader.h"
    4040#include "FrameLoadRequest.h"
     41#include "HTTPParsers.h"
    4142#include "HistoryItem.h"
    4243#include "HitTestResult.h"
     
    829830}
    830831
    831 static bool shouldTreatAsAttachment(const ResourceResponse& response)
    832 {
    833     const String& contentDisposition =
    834         response.httpHeaderField("Content-Disposition");
    835     if (contentDisposition.isEmpty())
    836         return false;
    837 
    838     // Some broken sites just send
    839     // Content-Disposition: ; filename="file"
    840     // screen those out here.
    841     if (contentDisposition.startsWith(";"))
    842         return false;
    843 
    844     if (contentDisposition.startsWith("inline", false))
    845         return false;
    846 
    847     // Some broken sites just send
    848     // Content-Disposition: filename="file"
    849     // without a disposition token... screen those out.
    850     if (contentDisposition.startsWith("filename", false))
    851         return false;
    852 
    853     // Also in use is Content-Disposition: name="file"
    854     if (contentDisposition.startsWith("name", false))
    855         return false;
    856 
    857     // We have a content-disposition of "attachment" or unknown.
    858     // RFC 2183, section 2.8 says that an unknown disposition
    859     // value should be treated as "attachment"
    860     return true;
    861 }
    862 
    863832void FrameLoaderClientImpl::dispatchDecidePolicyForMIMEType(
    864833     FramePolicyFunction function,
     
    875844        // The server does not want us to replace the page contents.
    876845        action = PolicyIgnore;
    877     } else if (shouldTreatAsAttachment(response)) {
     846    } else if (WebCore::shouldTreatAsAttachment(response)) {
    878847        // The server wants us to download instead of replacing the page contents.
    879848        // Downloading is handled by the embedder, but we still get the initial
  • trunk/WebKit/qt/Api/qwebpage.cpp

    r56740 r56750  
    35593559    \fn void QWebPage::unsupportedContent(QNetworkReply *reply)
    35603560
    3561     This signal is emitted when WebKit cannot handle a link the user navigated to.
     3561    This signal is emitted when WebKit cannot handle a link the user navigated to or a
     3562    web server's response includes a "Content-Disposition" header with the 'attachment'
     3563    directive. If "Content-Disposition" is present in \a reply, the web server is indicating
     3564    that the client should prompt the user to save the content regardless of content-type.
     3565    See RFC 2616 sections 19.5.1 for details about Content-Disposition.
    35623566
    35633567    At signal emission time the meta-data of the QNetworkReply \a reply is available.
  • trunk/WebKit/qt/ChangeLog

    r56740 r56750  
     12010-03-29  Dawit Alemayehu  <adawit@kde.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] Added support for handling the HTTP "Content-Disposition" header.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=36395
     8
     9        Whenever a server response contains a "Content-Disposition: attachment..." header,
     10        treat the request as a download and emit the unsupportedContent signal.
     11
     12        * Api/qwebpage.cpp:
     13        * WebCoreSupport/FrameLoaderClientQt.cpp:
     14        (WebCore::FrameLoaderClientQt::download):
     15        (WebCore::FrameLoaderClientQt::dispatchDecidePolicyForMIMEType):
     16
    1172010-03-22  Kenneth Rohde Christiansen  <kenneth@webkit.org>
    218
  • trunk/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp

    r54938 r56750  
    5151#include "HTMLFormElement.h"
    5252#include "HTMLPlugInElement.h"
     53#include "HTTPParsers.h"
    5354#include "NotImplemented.h"
    5455#include "QNetworkReplyHandler.h"
     
    820821        QWebPage *page = m_webFrame->page();
    821822        if (page->forwardUnsupportedContent())
    822             emit m_webFrame->page()->unsupportedContent(reply);
     823            emit page->unsupportedContent(reply);
    823824        else
    824825            reply->abort();
     
    967968{
    968969    // we need to call directly here
    969     if (canShowMIMEType(MIMEType))
     970    if (WebCore::shouldTreatAsAttachment(m_frame->loader()->activeDocumentLoader()->response()))
     971        callPolicyFunction(function, PolicyDownload);   
     972    else if (canShowMIMEType(MIMEType))
    970973        callPolicyFunction(function, PolicyUse);
    971974    else
Note: See TracChangeset for help on using the changeset viewer.