Changeset 116591 in webkit


Ignore:
Timestamp:
May 9, 2012 6:13:35 PM (12 years ago)
Author:
charles.wei@torchmobile.com.cn
Message:

[BlackBerry] Refactor data scheme support
https://bugs.webkit.org/show_bug.cgi?id=85938

Reviewed by Rob Buis.

We will create a DataStream in our platform repository,
so that can be wrapped up by NetworkJob for webkit rendering,
and by DownloadStream for downloading.

Refactor, no new tests.

  • platform/network/blackberry/NetworkJob.cpp:

(WebCore::NetworkJob::NetworkJob):
(WebCore::NetworkJob::initialize):
(WebCore::NetworkJob::cancelJob):
(WebCore::NetworkJob::sendResponseIfNeeded):

  • platform/network/blackberry/NetworkJob.h:

(NetworkJob):

  • platform/network/blackberry/NetworkManager.cpp:

(WebCore::NetworkManager::startJob):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r116587 r116591  
     12012-05-09  Charles Wei  <charles.wei@torchmobile.com.cn>
     2
     3        [BlackBerry]  Refactor data scheme support
     4        https://bugs.webkit.org/show_bug.cgi?id=85938
     5
     6        Reviewed by Rob Buis.
     7
     8        We will create a DataStream in our platform repository,
     9        so that can be wrapped up by NetworkJob for webkit rendering,
     10        and by DownloadStream for downloading.
     11
     12        Refactor, no new tests.
     13
     14        * platform/network/blackberry/NetworkJob.cpp:
     15        (WebCore::NetworkJob::NetworkJob):
     16        (WebCore::NetworkJob::initialize):
     17        (WebCore::NetworkJob::cancelJob):
     18        (WebCore::NetworkJob::sendResponseIfNeeded):
     19        * platform/network/blackberry/NetworkJob.h:
     20        (NetworkJob):
     21        * platform/network/blackberry/NetworkManager.cpp:
     22        (WebCore::NetworkManager::startJob):
     23
    1242012-05-09  Dana Jansens  <danakj@chromium.org>
    225
  • trunk/Source/WebCore/platform/network/blackberry/NetworkJob.cpp

    r116308 r116591  
    2121
    2222#include "AboutData.h"
    23 #include "Base64.h"
    2423#include "Chrome.h"
    2524#include "ChromeClient.h"
     
    4241#include <BlackBerryPlatformWebKitCredits.h>
    4342#include <BuildInformation.h>
     43#include <LocalizeResource.h>
    4444#include <network/MultipartStream.h>
    45 #include <network/NetworkRequest.h>
    4645#include <network/NetworkStreamFactory.h>
    47 #include <wtf/ASCIICType.h>
    4846
    4947namespace WebCore {
     
    6462{
    6563    return statusCode == 401;
    66 }
    67 
    68 static void escapeDecode(const char* src, int length, Vector<char>& out)
    69 {
    70     out.resize(length);
    71     const char* const srcEnd = src + length;
    72     char* dst = out.data();
    73     for (; src < srcEnd; ) {
    74         char inputChar = *src++;
    75         if (inputChar == '%' && src + 2 <= srcEnd) {
    76             int digit1 = 0;
    77             char character = *src++;
    78             if (isASCIIHexDigit(character))
    79                 digit1 = toASCIIHexValue(character);
    80 
    81             int digit2 = 0;
    82             character = *src++;
    83             if (isASCIIHexDigit(character))
    84                 digit2 = toASCIIHexValue(character);
    85 
    86             *dst++ = (digit1 << 4) | digit2;
    87         } else
    88             *dst++ = inputChar;
    89     }
    90     out.resize(dst - out.data());
    9164}
    9265
    9366NetworkJob::NetworkJob()
    9467    : m_playerId(0)
    95     , m_loadDataTimer(this, &NetworkJob::fireLoadDataTimer)
    9668    , m_loadAboutTimer(this, &NetworkJob::fireLoadAboutTimer)
    9769    , m_deleteJobTimer(this, &NetworkJob::fireDeleteJobTimer)
    9870    , m_streamFactory(0)
    9971    , m_isFile(false)
    100     , m_isData(false)
    10172    , m_isAbout(false)
    10273    , m_isFTP(false)
     
    135106    m_response.setURL(url);
    136107    m_isFile = url.protocolIs("file") || url.protocolIs("local");
    137     m_isData = url.protocolIs("data");
    138108    m_isAbout = url.protocolIs("about");
    139109    m_isFTP = url.protocolIs("ftp");
     
    161131    }
    162132
    163     // No need to create the streams for data and about.
    164     if (m_isData || m_isAbout)
     133    // No need to create the streams for about.
     134    if (m_isAbout)
    165135        return true;
    166136
     
    189159    // Cancel jobs loading local data by killing the timer, and jobs
    190160    // getting data from the network by calling the inherited URLStream::cancel.
    191     if (m_loadDataTimer.isActive()) {
    192         m_loadDataTimer.stop();
    193         notifyClose(BlackBerry::Platform::FilterStream::StatusCancelled);
    194         return 0;
    195     }
    196161
    197162    if (m_loadAboutTimer.isActive()) {
     
    613578        return;
    614579
    615     String urlFilename = m_response.url().lastPathComponent();
     580    String urlFilename;
     581    if (!m_response.url().protocolIsData() && !m_response.url().protocolIs("about"))
     582        urlFilename = m_response.url().lastPathComponent();
    616583
    617584    // Get the MIME type that was set by the content sniffer
     
    636603
    637604    // Set suggested filename for downloads from the Content-Disposition header; if this fails,
    638     // fill it in from the url and sniffed mime type;Skip this for data and about URLs,
     605    // fill it in from the url and sniffed mime type;Skip this for about URLs,
    639606    // because they have no Content-Disposition header and the format is wrong to be a filename.
    640     if (!m_isData && !m_isAbout) {
     607    if (!m_isAbout) {
    641608        String suggestedFilename = filenameFromHTTPContentDisposition(m_contentDisposition);
    642609        if (suggestedFilename.isEmpty()) {
     
    645612            if (urlFilename.isEmpty()) {
    646613                if (mimeExtension.isEmpty()) // No extension found for the mimeType.
    647                     suggestedFilename = String("Untitled");
     614                    suggestedFilename = String(BlackBerry::Platform::LocalizeResource::getString(BlackBerry::Platform::FILENAME_UNTITLED));
    648615                else
    649                     suggestedFilename = String("Untitled") + "." + mimeExtension;
     616                    suggestedFilename = String(BlackBerry::Platform::LocalizeResource::getString(BlackBerry::Platform::FILENAME_UNTITLED)) + "." + mimeExtension;
    650617            } else {
    651618                if (urlFilename.reverseFind('.') == notFound && !mimeExtension.isEmpty())
     
    674641        m_multipartResponse = nullptr;
    675642    }
    676 }
    677 
    678 void NetworkJob::parseData()
    679 {
    680     Vector<char> result;
    681 
    682     String contentType("text/plain;charset=US-ASCII");
    683 
    684     String data(m_response.url().string().substring(5));
    685     Vector<String> hparts;
    686     bool isBase64 = false;
    687 
    688     size_t index = data.find(',');
    689     if (index != notFound && index > 0) {
    690         contentType = data.left(index).lower();
    691         data = data.substring(index + 1);
    692 
    693         contentType.split(';', hparts);
    694         Vector<String>::iterator i;
    695         for (i = hparts.begin(); i != hparts.end(); ++i) {
    696             if (i->stripWhiteSpace().lower() == "base64") {
    697                 isBase64 = true;
    698                 String value = *i;
    699                 do {
    700                     if (*i == value) {
    701                         int position = i - hparts.begin();
    702                         hparts.remove(position);
    703                         i = hparts.begin() + position;
    704                     } else
    705                         ++i;
    706                 } while (i != hparts.end());
    707                 break;
    708             }
    709         }
    710         contentType = String();
    711         for (i = hparts.begin(); i != hparts.end(); ++i) {
    712             if (i > hparts.begin())
    713                 contentType += ",";
    714 
    715             contentType += *i;
    716         }
    717     } else if (!index)
    718         data = data.substring(1); // Broken header.
    719 
    720     {
    721         CString latin = data.latin1();
    722         escapeDecode(latin.data(), latin.length(), result);
    723     }
    724 
    725     if (isBase64) {
    726         String s(result.data(), result.size());
    727         CString latin = s.removeCharacters(isSpaceOrNewline).latin1();
    728         result.clear();
    729         result.append(latin.data(), latin.length());
    730         Vector<char> bytesOut;
    731         if (base64Decode(result, bytesOut))
    732             result.swap(bytesOut);
    733         else
    734             result.clear();
    735     }
    736 
    737     notifyStatusReceived(result.isEmpty() ? 404 : 200, 0);
    738     notifyStringHeaderReceived("Content-Type", contentType);
    739     notifyStringHeaderReceived("Content-Length", String::number(result.size()));
    740     notifyDataReceivedPlain(result.data(), result.size());
    741     notifyClose(BlackBerry::Platform::FilterStream::StatusSuccess);
    742643}
    743644
  • trunk/Source/WebCore/platform/network/blackberry/NetworkJob.h

    r112092 r116591  
    6161#endif
    6262    bool isCancelled() const { return m_cancelled; }
    63     void loadDataURL() { m_loadDataTimer.startOneShot(0); }
    6463    void loadAboutURL();
    6564    int cancelJob();
     
    114113    void sendMultipartResponseIfNeeded();
    115114
    116     void fireLoadDataTimer(Timer<NetworkJob>*)
    117     {
    118         parseData();
    119     }
    120 
    121115    void fireLoadAboutTimer(Timer<NetworkJob>*)
    122116    {
     
    125119
    126120    void fireDeleteJobTimer(Timer<NetworkJob>*);
    127 
    128     void parseData();
    129121
    130122    void handleAbout();
     
    152144    RefPtr<ResourceHandle> m_handle;
    153145    ResourceResponse m_response;
    154     Timer<NetworkJob> m_loadDataTimer;
    155146    Timer<NetworkJob> m_loadAboutTimer;
    156147    OwnPtr<ResourceResponse> m_multipartResponse;
     
    161152    BlackBerry::Platform::NetworkStreamFactory* m_streamFactory;
    162153    bool m_isFile;
    163     bool m_isData;
    164154    bool m_isAbout;
    165155    bool m_isFTP;
  • trunk/Source/WebCore/platform/network/blackberry/NetworkManager.cpp

    r112766 r116591  
    137137    m_jobs.append(networkJob);
    138138
    139     if (url.protocolIs("data")) {
    140         networkJob->loadDataURL();
    141         return true;
    142     }
    143 
    144139    if (url.protocolIs("about")) {
    145140        // If the protocol matches "about", loadAboutURL should recognize and handle it.
Note: See TracChangeset for help on using the changeset viewer.