Reviewed by Eric.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 4 Mar 2006 10:26:22 +0000 (10:26 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 4 Mar 2006 10:26:22 +0000 (10:26 +0000)
        - make TransferJobWin handle file: URLs, and fix other bugs
        as needed to make local file image loads work
        http://bugzilla.opendarwin.org/show_bug.cgi?id=7587

        * WebCore.vcproj/WebCore/WebCore.vcproj: add TransferJobWin
        to build.
        * bridge/win/FrameWin.cpp:
        (WebCore::FrameWin::FrameWin): Set autoLoadImages to true.
        * platform/TransferJob.cpp:
        (WebCore::TransferJob::TransferJob): Pass this to internal
        constructor, so windows version can initialize timer
        * platform/TransferJob.h:
        * platform/TransferJobInternal.h:
        (WebCore::TransferJobInternal::TransferJobInternal): On windows,
        prepare a timer for file loads.
        * platform/cairo/GraphicsContextCairo.cpp:
        (WebCore::GraphicsContext::drawFloatImage): If passed-in context
        is null, use our built-in context (this is probably not the best,
        but should work for now).
        * platform/win/TemporaryLinkStubs.cpp:
        (FrameWin::issueRedoCommand): Don't break.
        (WebCore::TransferJob::assembleResponseHeaders): ditto
        (FrameWin::saveDocumentState): ditto
        (FrameWin::clearUndoRedoOperations): ditto
        * platform/win/TransferJobWin.cpp:
        (WebCore::TransferJobInternal::~TransferJobInternal): Close file
        handle if we have one.
        (WebCore::TransferJob::~TransferJob): Empty.
        (WebCore::TransferJob::start): Open a windows file handle.
        (WebCore::TransferJob::fileLoadTimer): Load from windows file
        handle.
        (WebCore::TransferJob::cancel): Stop timer and close windows file
        handle if present.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13124 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.vcproj/WebCore/WebCore.vcproj
WebCore/bridge/win/FrameWin.cpp
WebCore/platform/TransferJob.cpp
WebCore/platform/TransferJob.h
WebCore/platform/TransferJobInternal.h
WebCore/platform/cairo/GraphicsContextCairo.cpp
WebCore/platform/mac/TransferJobMac.mm
WebCore/platform/win/TemporaryLinkStubs.cpp
WebCore/platform/win/TransferJobWin.cpp

index 32c9896..fe05799 100644 (file)
@@ -1,3 +1,41 @@
+2006-03-04  Maciej Stachowiak  <mjs@apple.com
+
+        Reviewed by Eric.
+
+        - make TransferJobWin handle file: URLs, and fix other bugs
+        as needed to make local file image loads work
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=7587
+
+        * WebCore.vcproj/WebCore/WebCore.vcproj: add TransferJobWin
+        to build.
+        * bridge/win/FrameWin.cpp:
+        (WebCore::FrameWin::FrameWin): Set autoLoadImages to true.
+        * platform/TransferJob.cpp:
+        (WebCore::TransferJob::TransferJob): Pass this to internal
+        constructor, so windows version can initialize timer
+        * platform/TransferJob.h:
+        * platform/TransferJobInternal.h:
+        (WebCore::TransferJobInternal::TransferJobInternal): On windows,
+        prepare a timer for file loads.
+        * platform/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::drawFloatImage): If passed-in context
+        is null, use our built-in context (this is probably not the best,
+        but should work for now).
+        * platform/win/TemporaryLinkStubs.cpp:
+        (FrameWin::issueRedoCommand): Don't break.
+        (WebCore::TransferJob::assembleResponseHeaders): ditto
+        (FrameWin::saveDocumentState): ditto
+        (FrameWin::clearUndoRedoOperations): ditto
+        * platform/win/TransferJobWin.cpp:
+        (WebCore::TransferJobInternal::~TransferJobInternal): Close file
+        handle if we have one.
+        (WebCore::TransferJob::~TransferJob): Empty.
+        (WebCore::TransferJob::start): Open a windows file handle.
+        (WebCore::TransferJob::fileLoadTimer): Load from windows file
+        handle.
+        (WebCore::TransferJob::cancel): Stop timer and close windows file 
+        handle if present.
+
 2006-03-03  Eric Seidel  <eseidel@apple.com>
 
         Reviewed by hyatt.
index 626aabf..4c11eef 100644 (file)
                                        >\r
                                </File>\r
                                <File\r
+                                       RelativePath="..\..\platform\win\TransferJobWin.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
                                        RelativePath="..\..\platform\win\WidgetWin.cpp"\r
                                        >\r
                                </File>\r
index 8dc381d..ac29cf1 100644 (file)
@@ -39,7 +39,9 @@ FrameWin::FrameWin(Page* page, RenderPart* renderPart)
     : Frame(page, renderPart)
 {
     d->m_extension = new BrowserExtensionWin(this);
-    setSettings(new KHTMLSettings());
+    KHTMLSettings* settings = new KHTMLSettings();
+    settings->setAutoLoadImages(true);
+    setSettings(settings);
 }
 
 FrameWin::~FrameWin()
index d8086b4..1e92de8 100644 (file)
 namespace WebCore {
 
 TransferJob::TransferJob(TransferJobClient* client, const String& method, const KURL& url)
-    : d(new TransferJobInternal(client, method, url))
+    : d(new TransferJobInternal(this, client, method, url))
 {
 }
 
 TransferJob::TransferJob(TransferJobClient* client, const String& method, const KURL& url, const FormData& postData)
-    : d(new TransferJobInternal(client, method, url, postData))
+    : d(new TransferJobInternal(this, client, method, url, postData))
 {
 }
 
@@ -70,8 +70,8 @@ QString TransferJob::errorText() const
 QString TransferJob::queryMetaData(const QString &key) const
 {
     if (key == "HTTP-Headers") {
-       assembleResponseHeaders();
-       return d->responseHeaders;
+        assembleResponseHeaders();
+        return d->responseHeaders;
     } 
 
     if (key == "charset")
index 92851f6..17904a2 100644 (file)
@@ -29,6 +29,7 @@
 #include "PlatformString.h"
 #include "TransferJobClient.h" // for PlatformResponse
 #include <kxmlcore/HashMap.h>
+#include "Timer.h"
 
 #if __APPLE__
 #ifdef __OBJC__
@@ -70,6 +71,9 @@ public:
 #if __APPLE__
     void setLoader(KWQResourceLoader*);
 #endif
+#if WIN32
+    void TransferJob::fileLoadTimer(Timer<TransferJob>* timer);
+#endif
 
     void cancel();
     
index 627930b..64da8d4 100644 (file)
@@ -29,6 +29,9 @@
 
 #include "KURL.h"
 #include "formdata.h"
+#if WIN32
+#include "windows.h"
+#endif
 
 // The allocations and releases in TransferJobInternal are
 // definitely Cocoa-exception-free (either simple Foundation
@@ -40,21 +43,25 @@ namespace WebCore {
     class TransferJobInternal
     {
     public:
-        TransferJobInternal(TransferJobClient* c, const String& method, const KURL& u)
+        TransferJobInternal(TransferJob* job, TransferJobClient* c, const String& method, const KURL& u)
             : client(c)
-              , status(0)
-              , URL(u)
-              , method(method)
-              , assembledResponseHeaders(true)
-              , retrievedCharset(true)
+            , status(0)
+            , URL(u)
+            , method(method)
+            , assembledResponseHeaders(true)
+            , retrievedCharset(true)
 #if __APPLE__
-              , loader(nil)
-              , response(nil)
+            , loader(nil)
+            , response(nil)
+#endif
+#if WIN32
+            , m_fileHandle(0)
+            , m_fileLoadTimer(job, &TransferJob::fileLoadTimer)
 #endif
         {
         }
         
-        TransferJobInternal(TransferJobClient* c, const String& method, const KURL& u, const FormData& p)
+        TransferJobInternal(TransferJob* job, TransferJobClient* c, const String& method, const KURL& u, const FormData& p)
             : client(c)
             , status(0)
             , URL(u)
@@ -66,6 +73,10 @@ namespace WebCore {
             , loader(nil)
             , response(nil)
 #endif
+#if WIN32
+            , m_fileHandle(0)
+            , m_fileLoadTimer(job, &TransferJob::fileLoadTimer)
+#endif
         {
         }
 
@@ -87,7 +98,11 @@ namespace WebCore {
         KWQResourceLoader* loader;
         NSURLResponse* response;
 #endif
-    };
+#if WIN32
+                HANDLE m_fileHandle;
+                Timer<TransferJob> m_fileLoadTimer;
+#endif
+        };
 
 } // namespace WebCore
 
index 0458974..0bc6ce6 100644 (file)
@@ -413,6 +413,9 @@ void GraphicsContext::drawConvexPolygon(const IntPointArray& points)
 void GraphicsContext::drawFloatImage(Image* image, float x, float y, float w, float h, 
                               float sx, float sy, float sw, float sh, Image::CompositeOperator compositeOperator, void* context)
 {
+    if (!context)
+        context = m_data->context;
+
     if (m_data->state.paintingDisabled)
         return;
 
index 7ac6247..b8ea154 100644 (file)
@@ -104,7 +104,7 @@ void TransferJob::assembleResponseHeaders() const
             NSDictionary *headers = [httpResponse allHeaderFields];
             d->responseHeaders = QString::fromNSString(KWQHeaderStringFromDictionary(headers, [httpResponse statusCode]));
         }
-       d->assembledResponseHeaders = true;
+        d->assembledResponseHeaders = true;
     }
 }
 
index 4303618..552447c 100644 (file)
@@ -211,8 +211,7 @@ void FrameWin::respondToChangedContents() { notImplemented(); }
 void FrameWin::unfocusWindow() { notImplemented(); }
 bool FrameWin::locationbarVisible() { notImplemented(); return 0; }
 void FrameWin::respondToChangedSelection(WebCore::SelectionController const&,bool) { notImplemented(); }
-void FrameWin::clearUndoRedoOperations() { notImplemented(); }
-void FrameWin::issueRedoCommand() { notImplemented(); }
+void FrameWin::issueRedoCommand(void) { notImplemented(); }
 KJS::Bindings::Instance * FrameWin::getObjectInstanceForWidget(Widget *) { notImplemented(); return 0; }
 KJS::Bindings::Instance * FrameWin::getEmbedInstanceForWidget(Widget *) { notImplemented(); return 0; }
 bool FrameWin::canRedo() const { notImplemented(); return 0; }
@@ -224,7 +223,6 @@ void FrameWin::runJavaScriptAlert(String const&) { notImplemented(); }
 bool FrameWin::runJavaScriptConfirm(String const&) { notImplemented(); return 0; }
 bool FrameWin::openURL(KURL const&) { notImplemented(); return 0; }
 void FrameWin::urlSelected(KURL const&,struct WebCore::URLArgs const&) { notImplemented(); }
-void FrameWin::saveDocumentState() { notImplemented(); }
 void FrameWin::print() { notImplemented(); }
 KJS::Bindings::Instance * FrameWin::getAppletInstanceForWidget(Widget *) { notImplemented(); return 0; }
 bool FrameWin::passMouseDownEventToWidget(Widget *) { notImplemented(); return 0; }
@@ -273,7 +271,6 @@ void QTextEdit::setWritingDirection(enum WebCore::TextDirection) { notImplemente
 GraphicsContext::GraphicsContext() { notImplemented(); }
 void WebCore::TransferJob::retrieveCharset() const { notImplemented(); }
 void WebCore::TransferJob::assembleResponseHeaders() const { notImplemented(); }
-WebCore::TransferJob::~TransferJob() { notImplemented(); }
 
 // Completely empty stubs (mostly to allow DRT to run):
 bool WebCore::historyContains(QString const&) { return false; }
@@ -312,7 +309,8 @@ bool FrameWin::shouldChangeSelection(SelectionController const&,SelectionControl
 static int frameNumber = 0;
 String FrameWin::generateFrameName() { return QString::number(frameNumber++); }
 Frame* FrameWin::createFrame(KURL const&,QString const&,RenderPart*,String const&) { return 0; }
-
+void FrameWin::saveDocumentState(void) { }
+void FrameWin::clearUndoRedoOperations(void) {}
 
 BrowserExtensionWin::BrowserExtensionWin(WebCore::Frame*) { }
 
@@ -336,8 +334,6 @@ int ScrollView::contentsWidth() const { return 1000; }
 void ScrollView::viewportToContents(int x1, int y1, int& x2, int& y2) { x2 = x1; y2 = y1; }
 void ScrollView::setStaticBackground(bool) { }
 
-bool TransferJob::start(class WebCore::DocLoader *){ return false; }
-
 Font const& GraphicsContext::font() const { return localFont; }
 void GraphicsContext::setFont(Font const&) { }
 void GraphicsContext::drawText(int,int,int,int,int,int,int,QString const&) { }
index 7ac6247..15209d1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2004, 2006 Apple Computer, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#import "config.h"
-#import "TransferJob.h"
+#include "config.h"
+#include "TransferJob.h"
 
-#import "TransferJobInternal.h"
-
-#import "FoundationExtras.h"
-#import "KURL.h"
-#import "KWQExceptions.h"
-#import "KWQLoader.h"
-#import "Logging.h"
-#import "KWQResourceLoader.h"
-#import "formdata.h"
-#import "MacFrame.h"
-#import "WebCoreFrameBridge.h"
-#import "DocLoader.h"
-#import "KWQFormData.h"
-#import "KWQLoader.h"
+#include "TransferJobInternal.h"
+#include "KURL.h"
+#include "formdata.h"
 
 namespace WebCore {
     
 TransferJobInternal::~TransferJobInternal()
 {
-    KWQRelease(response);
-    KWQRelease(loader);
+       if (m_fileHandle)
+               CloseHandle(m_fileHandle);
 }
 
 TransferJob::~TransferJob()
 {
-    // This will cancel the handle, and who knows what that could do
-    KWQ_BLOCK_EXCEPTIONS;
-    [d->loader jobWillBeDeallocated];
-    KWQ_UNBLOCK_EXCEPTIONS;
-    delete d;
 }
 
 bool TransferJob::start(DocLoader* docLoader)
 {
-    MacFrame *frame = Mac(docLoader->frame());
-    
-    if (!frame) {
-        delete this;
-        return false;
+    if (d->URL.isLocalFile()) {
+        QString path = d->URL.path();
+        // windows does not enjoy a leading slash on paths
+        if (path[0] == '/')
+               path = path.mid(1);
+           d->m_fileHandle = CreateFileA(path.ascii(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
     }
-    
-    WebCoreFrameBridge* bridge = frame->bridge();
-
-    frame->didTellBridgeAboutLoad(url().url());
-
-    KWQ_BLOCK_EXCEPTIONS;
-    KWQResourceLoader* resourceLoader = [[KWQResourceLoader alloc] initWithJob:this];
 
-    id <WebCoreResourceHandle> handle;
-
-    NSDictionary* headerDict = nil;
-    QString headerString = queryMetaData("customHTTPHeader");
-
-    if (!headerString.isEmpty())
-        headerDict = [NSDictionary _webcore_dictionaryWithHeaderString:headerString.getNSString()];
-
-    if (postData().count() > 0) {
-        handle = [bridge startLoadingResource:resourceLoader withMethod:method() URL:url().getNSURL() customHeaders:headerDict
-            postData:arrayFromFormData(postData())];
-    } else {
-        handle = [bridge startLoadingResource:resourceLoader withMethod:method() URL:url().getNSURL() customHeaders:headerDict];
+    if (d->m_fileHandle == INVALID_HANDLE_VALUE) {
+        delete this;
+           return false;
     }
-    [resourceLoader setHandle:handle];
-    [resourceLoader release];
-    return handle != nil;
-    KWQ_UNBLOCK_EXCEPTIONS;
 
+    d->m_fileLoadTimer.startOneShot(0.0);
     return true;
 }
 
-void TransferJob::assembleResponseHeaders() const
-{
-    if (!d->assembledResponseHeaders) {
-        if ([d->response isKindOfClass:[NSHTTPURLResponse class]]) {
-            NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)d->response;
-            NSDictionary *headers = [httpResponse allHeaderFields];
-            d->responseHeaders = QString::fromNSString(KWQHeaderStringFromDictionary(headers, [httpResponse statusCode]));
-        }
-       d->assembledResponseHeaders = true;
-    }
-}
-
-void TransferJob::retrieveCharset() const
-{
-    if (!d->retrievedCharset) {
-        NSString *charset = [d->response textEncodingName];
-        if (charset)
-            d->metaData.set("charset", charset);
-        d->retrievedCharset = true;
-    }
-}
-
-void TransferJob::setLoader(KWQResourceLoader *loader)
-{
-    KWQRetain(loader);
-    KWQRelease(d->loader);
-    d->loader = loader;
-}
-
-void TransferJob::receivedResponse(NSURLResponse* response)
+void TransferJob::fileLoadTimer(Timer<TransferJob>* timer)
 {
-    d->assembledResponseHeaders = false;
-    d->retrievedCharset = false;
-    d->response = response;
-    KWQRetain(d->response);
-    if (d->client)
-        d->client->receivedResponse(this, response);
+    bool result = false;
+    DWORD bytesRead = 0;
+
+    do {
+        const int bufferSize = 8192;
+       char buffer[bufferSize];
+       result = ReadFile(d->m_fileHandle, &buffer, bufferSize, &bytesRead, NULL); 
+       d->client->receivedData(this, buffer, bytesRead);
+       // Check for end of file. 
+    } while (!result || bytesRead);
+
+    CloseHandle(d->m_fileHandle);
+    d->m_fileHandle = 0;
 }
 
 void TransferJob::cancel()
 {
-    [d->loader jobCanceledLoad];
+    d->m_fileLoadTimer.stop();
 }
 
 } // namespace WebCore