Changeset 65835 in webkit


Ignore:
Timestamp:
Aug 23, 2010 3:12:03 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-08-23 Patrick Gansterer <paroga@paroga.com>

Reviewed by Adam Roben.

Move filehandling into fileLoadTimer callback
https://bugs.webkit.org/show_bug.cgi?id=43714

Also add mimetype detection for local files.

  • platform/network/ResourceHandleInternal.h: (WebCore::ResourceHandleInternal::ResourceHandleInternal):
  • platform/network/win/ResourceHandleWin.cpp: (WebCore::ResourceHandle::start): (WebCore::ResourceHandle::fileLoadTimer):
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r65833 r65835  
     12010-08-23  Patrick Gansterer  <paroga@paroga.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        Move filehandling into fileLoadTimer callback
     6        https://bugs.webkit.org/show_bug.cgi?id=43714
     7
     8        Also add mimetype detection for local files.
     9
     10        * platform/network/ResourceHandleInternal.h:
     11        (WebCore::ResourceHandleInternal::ResourceHandleInternal):
     12        * platform/network/win/ResourceHandleWin.cpp:
     13        (WebCore::ResourceHandle::start):
     14        (WebCore::ResourceHandle::fileLoadTimer):
     15
    1162010-08-23  Iain Merrick  <husky@google.com>
    217
  • trunk/WebCore/platform/network/ResourceHandleInternal.h

    r63332 r65835  
    9393#endif
    9494#if USE(WININET)
    95             , m_fileHandle(INVALID_HANDLE_VALUE)
    9695            , m_fileLoadTimer(loader, &ResourceHandle::fileLoadTimer)
    9796            , m_resourceHandle(0)
     
    171170#endif
    172171#if USE(WININET)
    173         HANDLE m_fileHandle;
    174172        Timer<ResourceHandle> m_fileLoadTimer;
    175173        HINTERNET m_resourceHandle;
  • trunk/WebCore/platform/network/win/ResourceHandleWin.cpp

    r61183 r65835  
    11/*
    22 * Copyright (C) 2004, 2006 Apple Computer, Inc.  All rights reserved.
     3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    334335    ref();
    335336    if (request().url().isLocalFile()) {
    336         String path = request().url().path();
    337         // windows does not enjoy a leading slash on paths
    338         if (path[0] == '/')
    339             path = path.substring(1);
    340         // FIXME: This is wrong. Need to use wide version of this call.
    341         d->m_fileHandle = CreateFileA(path.utf8().data(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    342 
    343         // FIXME: perhaps this error should be reported asynchronously for
    344         // consistency.
    345         if (d->m_fileHandle == INVALID_HANDLE_VALUE) {
    346             delete this;
    347             return false;
    348         }
    349 
    350337        d->m_fileLoadTimer.startOneShot(0.0);
    351338        return true;
     
    410397}
    411398
    412 void ResourceHandle::fileLoadTimer(Timer<ResourceHandle>* timer)
    413 {
     399void ResourceHandle::fileLoadTimer(Timer<ResourceHandle>*)
     400{
     401    RefPtr<ResourceHandle> protector(this);
     402    deref(); // balances ref in start
     403
     404    String fileName = firstRequest().url().fileSystemPath();
     405    HANDLE fileHandle = CreateFileW(fileName.charactersWithNullTermination(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
     406
     407    if (fileHandle == INVALID_HANDLE_VALUE) {
     408        client()->didFail(this, ResourceError());
     409        return;
     410    }
     411
    414412    ResourceResponse response;
     413
     414    int dotPos = fileName.reverseFind('.');
     415    int slashPos = fileName.reverseFind('/');
     416
     417    if (slashPos < dotPos && dotPos != -1) {
     418        String ext = fileName.substring(dotPos + 1);
     419        response.setMimeType(MIMETypeRegistry::getMIMETypeForExtension(ext));
     420    }
     421
    415422    client()->didReceiveResponse(this, response);
    416423
     
    421428        const int bufferSize = 8192;
    422429        char buffer[bufferSize];
    423         result = ReadFile(d->m_fileHandle, &buffer, bufferSize, &bytesRead, NULL);
     430        result = ReadFile(fileHandle, &buffer, bufferSize, &bytesRead, 0);
    424431        if (result && bytesRead)
    425432            client()->didReceiveData(this, buffer, bytesRead, 0);
    426         // Check for end of file. 
     433        // Check for end of file.
    427434    } while (result && bytesRead);
    428435
    429     // FIXME: handle errors better
    430 
    431     CloseHandle(d->m_fileHandle);
    432     d->m_fileHandle = INVALID_HANDLE_VALUE;
     436    CloseHandle(fileHandle);
    433437
    434438    client()->didFinishLoading(this);
Note: See TracChangeset for help on using the changeset viewer.