Changeset 63704 in webkit


Ignore:
Timestamp:
Jul 19, 2010 6:19:55 PM (14 years ago)
Author:
andersca@apple.com
Message:

Handle NP_ASFILE and NP_ASFILEONLY transfer modes
https://bugs.webkit.org/show_bug.cgi?id=42587

Reviewed by Darin Adler, Adam Roben, Dan Bernstein and Sam Weinig.

WebCore:

  • WebCore.exp.in:

Export functions from FileSystem.h

  • platform/mac/FileSystemMac.mm:

(WebCore::openTemporaryFile):
Try to create a temporary file using mkstemp.

WebKit2:

  • WebProcess/Plugins/Netscape/NetscapePlugin.cpp:

(WebKit::NetscapePlugin::NPP_StreamAsFile):

  • WebProcess/Plugins/Netscape/NetscapePlugin.h:

Add NPP_ wrapper.

  • WebProcess/Plugins/Netscape/NetscapePluginStream.cpp:

(WebKit::NetscapePluginStream::NetscapePluginStream):
Initialize m_fileHandle.

(WebKit::isSupportedTransferMode):
NP_ASFILE and NP_ASFILEONLY is now supported.

(WebKit::NetscapePluginStream::deliverData):
Call deliverDataToFile if necessary.

(WebKit::NetscapePluginStream::deliverDataToFile):
Create a temporary file and write the data into it.

(WebKit::NetscapePluginStream::stop):
If the transfer mode is either NP_ASFILE or NP_ASFILEONLY, make sure to
call NPP_StreamAsFile and close the file and delete it.

  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::cancelStreamLoad):
Keep a reference to the Stream since cancelling it will remove it from the map.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63701 r63704  
     12010-07-19  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Darin Adler, Adam Roben, Dan Bernstein and Sam Weinig.
     4
     5        Handle NP_ASFILE and NP_ASFILEONLY transfer modes
     6        https://bugs.webkit.org/show_bug.cgi?id=42587
     7
     8        * WebCore.exp.in:
     9        Export functions from FileSystem.h
     10       
     11        * platform/mac/FileSystemMac.mm:
     12        (WebCore::openTemporaryFile):
     13        Try to create a temporary file using mkstemp.
     14
    1152010-07-19  Anders Carlsson  <andersca@apple.com>
    216
  • trunk/WebCore/WebCore.exp.in

    r63701 r63704  
    140140__ZN7WebCore10StringImplcvP8NSStringEv
    141141__ZN7WebCore20SpaceSplitStringData12createVectorEv
     142__ZN7WebCore10deleteFileERKNS_6StringE
    142143__ZN7WebCore10handCursorEv
    143144__ZN7WebCore10setCookiesEPNS_8DocumentERKNS_4KURLERKNS_6StringE
     
    203204__ZN7WebCore11IconFetcher6createEPNS_5FrameEPNS_17IconFetcherClientE
    204205__ZN7WebCore11RenderLayer19scrollRectToVisibleERKNS_7IntRectEbRKNS_15ScrollAlignmentES6_
    205 __ZNK7WebCore11RenderLayer19absoluteBoundingBoxEv
    206206__ZN7WebCore11globalPointERK8_NSPointP8NSWindow
    207207__ZN7WebCore11toUserSpaceERK7_NSRectP8NSWindow
     208__ZN7WebCore11writeToFileEiPKci
    208209__ZN7WebCore12ChromeClient20paintCustomScrollbarEPNS_15GraphicsContextERKNS_9FloatRectENS_20ScrollbarControlSizeEjNS_13ScrollbarPartEbffj
    209210__ZN7WebCore12ChromeClient23paintCustomScrollCornerEPNS_15GraphicsContextERKNS_9FloatRectE
     
    402403__ZN7WebCore17HistoryController26saveDocumentAndScrollStateEv
    403404__ZN7WebCore17nameForCursorTypeENS_6Cursor4TypeE
     405__ZN7WebCore17openTemporaryFileEPKcRi
    404406__ZN7WebCore18deprecatedParseURLERKNS_6StringE
    405407__ZN7WebCore18isStartOfParagraphERKNS_15VisiblePositionE
     
    786788__ZN7WebCore9TimerBaseC2Ev
    787789__ZN7WebCore9TimerBaseD2Ev
    788 __ZN7WebCore9toElementEN3JSC7JSValueE
     790__ZN7WebCore9closeFileERi
    789791__ZN7WebCore9fontCacheEv
    790792__ZN7WebCore9makeRangeERKNS_15VisiblePositionES2_
    791793__ZN7WebCore9pageCacheEv
     794__ZN7WebCore9toElementEN3JSC7JSValueE
    792795__ZN7WebCoreeqERKNS_19ResourceRequestBaseES2_
    793796__ZNK3JSC8Bindings10RootObject12globalObjectEv
     
    826829__ZNK7WebCore11HistoryItem9urlStringEv
    827830__ZNK7WebCore11HistoryItem9viewStateEv
     831__ZNK7WebCore11RenderLayer19absoluteBoundingBoxEv
    828832__ZNK7WebCore11RenderStyle21visitedDependentColorEi
    829833__ZNK7WebCore11ScriptValue9getStringEPN3JSC9ExecStateERNS_6StringE
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r63696 r63704  
    10711071                514185EE0CD65F0400763C99 /* ChangeVersionWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 514185EC0CD65F0400763C99 /* ChangeVersionWrapper.h */; };
    10721072                514185EF0CD65F0400763C99 /* ChangeVersionWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 514185ED0CD65F0400763C99 /* ChangeVersionWrapper.cpp */; };
    1073                 514B3F730C722047000530DF /* FileSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 514B3F720C722047000530DF /* FileSystem.h */; };
     1073                514B3F730C722047000530DF /* FileSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 514B3F720C722047000530DF /* FileSystem.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10741074                514B3F760C722055000530DF /* FileSystemMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 514B3F750C722055000530DF /* FileSystemMac.mm */; };
    10751075                514C76370CE9225E007EF3CD /* JSSQLError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 514C76350CE9225E007EF3CD /* JSSQLError.cpp */; };
  • trunk/WebCore/platform/mac/FileSystemMac.mm

    r35002 r63704  
    3030
    3131#import "PlatformString.h"
     32#import <wtf/text/CString.h>
    3233
    3334namespace WebCore {
     
    3839}
    3940
     41CString openTemporaryFile(const char* prefix, PlatformFileHandle& platformFileHandle)
     42{
     43    platformFileHandle = invalidPlatformFileHandle;
     44   
     45    Vector<char> temporaryFilePath(PATH_MAX);
     46    if (!confstr(_CS_DARWIN_USER_TEMP_DIR, temporaryFilePath.data(), temporaryFilePath.size()))
     47        return CString();
     48
     49    // Shrink the vector.   
     50    temporaryFilePath.shrink(strlen(temporaryFilePath.data()));
     51    ASSERT(temporaryFilePath.last() == '/');
     52
     53    // Append the file name.   
     54    temporaryFilePath.append(prefix, strlen(prefix));
     55    temporaryFilePath.append("XXXXXX", 6);
     56    temporaryFilePath.append('\0');
     57
     58    platformFileHandle = mkstemp(temporaryFilePath.data());
     59    if (platformFileHandle == invalidPlatformFileHandle)
     60        return CString();
     61
     62    return CString(temporaryFilePath.data());
     63}
     64
    4065} // namespace WebCore
  • trunk/WebKit2/ChangeLog

    r63701 r63704  
     12010-07-19  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Darin Adler, Adam Roben, Dan Bernstein and Sam Weinig.
     4
     5        Handle NP_ASFILE and NP_ASFILEONLY transfer modes
     6        https://bugs.webkit.org/show_bug.cgi?id=42587
     7
     8        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
     9        (WebKit::NetscapePlugin::NPP_StreamAsFile):
     10        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
     11        Add NPP_ wrapper.
     12
     13        * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp:
     14        (WebKit::NetscapePluginStream::NetscapePluginStream):
     15        Initialize m_fileHandle.
     16
     17        (WebKit::isSupportedTransferMode):
     18        NP_ASFILE and NP_ASFILEONLY is now supported.
     19
     20        (WebKit::NetscapePluginStream::deliverData):
     21        Call deliverDataToFile if necessary.
     22
     23        (WebKit::NetscapePluginStream::deliverDataToFile):
     24        Create a temporary file and write the data into it.
     25
     26        (WebKit::NetscapePluginStream::stop):
     27        If the transfer mode is either NP_ASFILE or NP_ASFILEONLY, make sure to
     28        call NPP_StreamAsFile and close the file and delete it.
     29
     30        * WebProcess/Plugins/PluginView.cpp:
     31        (WebKit::PluginView::cancelStreamLoad):
     32        Keep a reference to the Stream since cancelling it will remove it from the map.
     33
    1342010-07-19  Anders Carlsson  <andersca@apple.com>
    235
  • trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp

    r63701 r63704  
    191191}
    192192
     193void NetscapePlugin::NPP_StreamAsFile(NPStream* stream, const char* filename)
     194{
     195    return m_pluginModule->pluginFuncs().asfile(&m_npp, stream, filename);
     196}
     197
    193198int32_t NetscapePlugin::NPP_WriteReady(NPStream* stream)
    194199{
  • trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h

    r63701 r63704  
    7474    NPError NPP_NewStream(NPMIMEType, NPStream*, NPBool seekable, uint16_t* stype);
    7575    NPError NPP_DestroyStream(NPStream*, NPReason);
     76    void NPP_StreamAsFile(NPStream*, const char* filename);
     77
    7678    int32_t NPP_WriteReady(NPStream*);
    7779    int32_t NPP_Write(NPStream*, int32_t offset, int32_t len, void* buffer);
  • trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp

    r63500 r63704  
    4242    , m_transferMode(NP_NORMAL)
    4343    , m_offset(0)
     44    , m_fileHandle(invalidPlatformFileHandle)
    4445    , m_isStarted(false)
    4546#if !ASSERT_DISABLED
     
    5556    ASSERT(!m_isStarted);
    5657    ASSERT(!m_sendNotification || m_urlNotifyHasBeenCalled);
     58    ASSERT(m_fileHandle == invalidPlatformFileHandle);
    5759}
    5860
     
    128130{
    129131    switch (transferMode) {
     132    case NP_ASFILEONLY:
     133    case NP_ASFILE:
    130134    case NP_NORMAL:
    131135        return true;
    132     // FIXME: We don't support streaming to files.
    133     case NP_ASFILEONLY:
    134     case NP_ASFILE:
    135         return false;
    136136    // FIXME: We don't support seekable streams.
    137137    case NP_SEEK:
     
    191191    }
    192192
    193     // FIXME: Deliver the data to a file as well if needed.
     193    if (m_transferMode == NP_ASFILE || m_transferMode == NP_ASFILEONLY)
     194        deliverDataToFile(bytes, length);
    194195}
    195196
     
    245246        if (m_stopStreamWhenDoneDelivering)
    246247            stop(NPRES_DONE);
     248    }
     249}
     250
     251void NetscapePluginStream::deliverDataToFile(const char* bytes, int length)
     252{
     253    if (m_fileHandle == invalidPlatformFileHandle && m_filePath.isNull()) {
     254        // Create a temporary file.
     255        m_filePath = openTemporaryFile("WebKitPluginStream", m_fileHandle);
     256
     257        // We failed to open the file, stop the stream.
     258        if (m_fileHandle == invalidPlatformFileHandle) {
     259            stop(NPRES_NETWORK_ERR);
     260            return;
     261        }
     262    }
     263
     264    if (!length)
     265        return;
     266
     267    int byteCount = writeToFile(m_fileHandle, bytes, length);
     268    if (byteCount != length) {
     269        // This happens only rarely, when we are out of disk space or have a disk I/O error.
     270        closeFile(m_fileHandle);
     271
     272        stop(NPRES_NETWORK_ERR);
    247273    }
    248274}
     
    265291    m_deliveryData = 0;
    266292    m_deliveryDataTimer.stop();
     293
     294    if (m_transferMode == NP_ASFILE || m_transferMode == NP_ASFILEONLY) {
     295        if (reason == NPRES_DONE) {
     296            // Ensure that the file is created.
     297            deliverDataToFile(0, 0);
     298            if (m_fileHandle != invalidPlatformFileHandle)
     299                closeFile(m_fileHandle);
     300           
     301            ASSERT(!m_filePath.isNull());
     302           
     303            m_plugin->NPP_StreamAsFile(&m_npStream, m_filePath.data());
     304        } else {
     305            // Just close the file.
     306            if (m_fileHandle != invalidPlatformFileHandle)
     307                closeFile(m_fileHandle);
     308        }
     309
     310        // Delete the file after calling NPP_StreamAsFile(), instead of in the destructor.  It should be OK
     311        // to delete the file here -- NPP_StreamAsFile() is always called immediately before NPP_DestroyStream()
     312        // (the stream destruction function), so there can be no expectation that a plugin will read the stream
     313        // file asynchronously after NPP_StreamAsFile() is called.
     314        deleteFile(String::fromUTF8(m_filePath.data()));
     315        m_filePath = CString();
     316
     317        // NPP_StreamAsFile could call NPN_DestroyStream and destroy the stream.
     318        if (!m_isStarted)
     319            return;
     320    }
    267321
    268322    // Set m_isStarted to false before calling NPP_DestroyStream in case NPP_DestroyStream calls NPN_DestroyStream.
  • trunk/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h

    r63612 r63704  
    2828
    2929#include "RunLoop.h"
     30#include <WebCore/FileSystem.h>
    3031#include <WebCore/npapi.h>
    3132#include <wtf/PassRefPtr.h>
     
    7677    void deliverData(const char* bytes, int length);
    7778    void deliverDataToPlugin();
     79    void deliverDataToFile(const char* bytes, int length);
    7880
    7981    RefPtr<NetscapePlugin> m_plugin;
     
    8789    int32_t m_offset;
    8890
     91    CString m_filePath;
     92    WebCore::PlatformFileHandle m_fileHandle;
     93   
    8994    // Whether NPP_NewStream has successfully been called.
    9095    bool m_isStarted;
  • trunk/WebKit2/WebProcess/Plugins/PluginView.cpp

    r63701 r63704  
    372372
    373373    // This request is to load a URL and create a stream.
    374     RefPtr<PluginView::Stream> stream = PluginView::Stream::create(this, request->requestID(), request->request());
     374    RefPtr<Stream> stream = PluginView::Stream::create(this, request->requestID(), request->request());
    375375    addStream(stream.get());
    376376    stream->start();
     
    537537void PluginView::cancelStreamLoad(uint64_t streamID)
    538538{
    539     PluginView::Stream* stream = m_streams.get(streamID).get();
     539    // Keep a reference to the stream. Stream::cancel might remove the stream from the map, and thus
     540    // releasing its last reference.
     541    RefPtr<Stream> stream = m_streams.get(streamID).get();
    540542    if (!stream)
    541543        return;
    542544
     545    // Cancelling the stream here will remove it from the map.
    543546    stream->cancel();
    544     removeStream(stream);
     547    ASSERT(!m_streams.contains(streamID));
    545548}
    546549
Note: See TracChangeset for help on using the changeset viewer.