Changeset 71145 in webkit


Ignore:
Timestamp:
Nov 2, 2010 12:07:32 PM (13 years ago)
Author:
Patrick Gansterer
Message:

2010-11-02 Patrick Gansterer <Patrick Gansterer>

Reviewed by Adam Roben.

Cleanup createGlobalImageFileDescriptor in ClipboardWin
https://bugs.webkit.org/show_bug.cgi?id=48189

  • platform/win/ClipboardWin.cpp: (WebCore::ClipboardWin::writeURL):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r71144 r71145  
     12010-11-02  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Reviewed by Adam Roben.
     4
     5        Cleanup createGlobalImageFileDescriptor in ClipboardWin
     6        https://bugs.webkit.org/show_bug.cgi?id=48189
     7
     8        * platform/win/ClipboardWin.cpp:
     9        (WebCore::ClipboardWin::writeURL):
     10
    1112010-11-02  Pavel Feldman  <pfeldman@chromium.org>
    212
  • trunk/WebCore/platform/win/ClipboardWin.cpp

    r70914 r71145  
    5757#include <wtf/RefPtr.h>
    5858#include <wtf/text/CString.h>
    59 #include <wtf/text/StringConcatenate.h> 
     59#include <wtf/text/StringConcatenate.h>
    6060#include <wtf/text/StringHash.h>
    6161
     
    160160    result += String(static_cast<UChar*>(extension));
    161161    return result;
    162 }
    163 
    164 static HGLOBAL createGlobalURLContent(const CString& content)
    165 {
    166     HRESULT hr = S_OK;
    167     HGLOBAL memObj = 0;
    168 
    169     char* fileContents;
    170 
    171     memObj = GlobalAlloc(GPTR, content.length());
    172     if (!memObj)
    173         return 0;
    174 
    175     fileContents = (PSTR)GlobalLock(memObj);
    176     CopyMemory(fileContents, content.data(), content.length());
    177    
    178     GlobalUnlock(memObj);
    179    
    180     return memObj;
    181162}
    182163
     
    259240}
    260241
    261 static HGLOBAL createGlobalUrlFileDescriptor(const String& url, const String& title, const CString& content)
    262 {
    263     HRESULT hr = S_OK;
    264     HGLOBAL memObj = 0;
    265     String fsPath;
    266     memObj = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR));
    267     if (!memObj)
    268         return 0;
    269 
    270     FILEGROUPDESCRIPTOR* fgd = (FILEGROUPDESCRIPTOR*)GlobalLock(memObj);
    271     memset(fgd, 0, sizeof(FILEGROUPDESCRIPTOR));
    272     fgd->cItems = 1;
    273     fgd->fgd[0].dwFlags = FD_FILESIZE;
    274     fgd->fgd[0].nFileSizeLow = content.length();
    275     fsPath = filesystemPathFromUrlOrTitle(url, title, L".URL", true);
    276 
    277     if (fsPath.length() <= 0) {
    278         GlobalUnlock(memObj);
    279         GlobalFree(memObj);
    280         return 0;
    281     }
    282 
    283     int maxSize = min(fsPath.length(), ARRAYSIZE(fgd->fgd[0].cFileName));
    284     CopyMemory(fgd->fgd[0].cFileName, (LPCWSTR)fsPath.characters(), maxSize * sizeof(UChar));
    285     GlobalUnlock(memObj);
    286    
    287     return memObj;
    288 }
    289 
    290 
    291242static HGLOBAL createGlobalImageFileDescriptor(const String& url, const String& title, CachedImage* image)
    292243{
     
    726677    ASSERT(url.containsOnlyASCII()); // KURL::string() is URL encoded.
    727678
     679    String fsPath = filesystemPathFromUrlOrTitle(url, titleStr, L".URL", true);
    728680    CString content = makeString("[InternetShortcut]\r\nURL=", url, "\r\n").ascii();
    729681
    730     HGLOBAL urlFileDescriptor = createGlobalUrlFileDescriptor(url, titleStr, content);
     682    if (fsPath.length() <= 0)
     683        return;
     684
     685    HGLOBAL urlFileDescriptor = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR));
    731686    if (!urlFileDescriptor)
    732687        return;
    733     HGLOBAL urlFileContent = createGlobalURLContent(content);
     688
     689    HGLOBAL urlFileContent = GlobalAlloc(GPTR, content.length());
    734690    if (!urlFileContent) {
    735691        GlobalFree(urlFileDescriptor);
    736692        return;
    737693    }
     694
     695    FILEGROUPDESCRIPTOR* fgd = static_cast<FILEGROUPDESCRIPTOR*>(GlobalLock(urlFileDescriptor));
     696    ZeroMemory(fgd, sizeof(FILEGROUPDESCRIPTOR));
     697    fgd->cItems = 1;
     698    fgd->fgd[0].dwFlags = FD_FILESIZE;
     699    fgd->fgd[0].nFileSizeLow = content.length();
     700
     701    unsigned maxSize = min(fsPath.length(), ARRAYSIZE(fgd->fgd[0].cFileName));
     702    CopyMemory(fgd->fgd[0].cFileName, fsPath.characters(), maxSize * sizeof(UChar));
     703    GlobalUnlock(urlFileDescriptor);
     704
     705    char* fileContents = static_cast<char*>(GlobalLock(urlFileContent));
     706    CopyMemory(fileContents, content.data(), content.length());
     707    GlobalUnlock(urlFileContent);
     708
    738709    writeFileToDataObject(m_writableDataObject.get(), urlFileDescriptor, urlFileContent, 0);
    739710}
Note: See TracChangeset for help on using the changeset viewer.