Changeset 70914 in webkit


Ignore:
Timestamp:
Oct 29, 2010 12:13:22 PM (13 years ago)
Author:
Patrick Gansterer
Message:

2010-10-29 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::createGlobalURLContent): (WebCore::createGlobalUrlFileDescriptor): (WebCore::ClipboardWin::writeURL):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r70912 r70914  
     12010-10-29  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::createGlobalURLContent):
     10        (WebCore::createGlobalUrlFileDescriptor):
     11        (WebCore::ClipboardWin::writeURL):
     12
    1132010-10-29  Dmitry Titov  <dimich@chromium.org>
    214
  • trunk/WebCore/platform/win/ClipboardWin.cpp

    r68854 r70914  
    5757#include <wtf/RefPtr.h>
    5858#include <wtf/text/CString.h>
     59#include <wtf/text/StringConcatenate.h>
    5960#include <wtf/text/StringHash.h>
    6061
     
    6465
    6566using namespace HTMLNames;
    66 
    67 // format string for
    68 static const char szShellDotUrlTemplate[] = "[InternetShortcut]\r\nURL=%s\r\n";
    6967
    7068// We provide the IE clipboard types (URL and Text), and the clipboard types specified in the WHATWG Web Applications 1.0 draft
     
    164162}
    165163
    166 static HGLOBAL createGlobalURLContent(const String& url, int estimatedFileSize)
     164static HGLOBAL createGlobalURLContent(const CString& content)
    167165{
    168166    HRESULT hr = S_OK;
     
    170168
    171169    char* fileContents;
    172     char ansiUrl[INTERNET_MAX_URL_LENGTH + 1];
    173     // Used to generate the buffer. This is null terminated whereas the fileContents won't be.
    174     char contentGenerationBuffer[INTERNET_MAX_URL_LENGTH + ARRAYSIZE(szShellDotUrlTemplate) + 1];
    175    
    176     if (estimatedFileSize > 0 && estimatedFileSize > ARRAYSIZE(contentGenerationBuffer))
    177         return 0;
    178 
    179     int ansiUrlSize = ::WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)url.characters(), url.length(), ansiUrl, ARRAYSIZE(ansiUrl) - 1, 0, 0);
    180     if (!ansiUrlSize)
    181         return 0;
    182 
    183     ansiUrl[ansiUrlSize] = 0;
    184    
    185     int fileSize = (int) (ansiUrlSize+strlen(szShellDotUrlTemplate)-2); // -2 to remove the %s
    186     ASSERT(estimatedFileSize < 0 || fileSize == estimatedFileSize);
    187 
    188     memObj = GlobalAlloc(GPTR, fileSize);
     170
     171    memObj = GlobalAlloc(GPTR, content.length());
    189172    if (!memObj)
    190173        return 0;
    191174
    192175    fileContents = (PSTR)GlobalLock(memObj);
    193 
    194     sprintf_s(contentGenerationBuffer, ARRAYSIZE(contentGenerationBuffer), szShellDotUrlTemplate, ansiUrl);
    195     CopyMemory(fileContents, contentGenerationBuffer, fileSize);
     176    CopyMemory(fileContents, content.data(), content.length());
    196177   
    197178    GlobalUnlock(memObj);
     
    278259}
    279260
    280 static HGLOBAL createGlobalUrlFileDescriptor(const String& url, const String& title, int& /*out*/ estimatedSize)
     261static HGLOBAL createGlobalUrlFileDescriptor(const String& url, const String& title, const CString& content)
    281262{
    282263    HRESULT hr = S_OK;
     
    291272    fgd->cItems = 1;
    292273    fgd->fgd[0].dwFlags = FD_FILESIZE;
    293     int fileSize = ::WideCharToMultiByte(CP_ACP, 0, url.characters(), url.length(), 0, 0, 0, 0);
    294     fileSize += strlen(szShellDotUrlTemplate) - 2; // -2 is for getting rid of %s in the template string
    295     fgd->fgd[0].nFileSizeLow = fileSize;
    296     estimatedSize = fileSize;
     274    fgd->fgd[0].nFileSizeLow = content.length();
    297275    fsPath = filesystemPathFromUrlOrTitle(url, title, L".URL", true);
    298276
     
    745723    WebCore::writeURL(m_writableDataObject.get(), kurl, titleStr, true, true);
    746724
    747     int estimatedSize = 0;
    748725    String url = kurl.string();
    749 
    750     HGLOBAL urlFileDescriptor = createGlobalUrlFileDescriptor(url, titleStr, estimatedSize);
     726    ASSERT(url.containsOnlyASCII()); // KURL::string() is URL encoded.
     727
     728    CString content = makeString("[InternetShortcut]\r\nURL=", url, "\r\n").ascii();
     729
     730    HGLOBAL urlFileDescriptor = createGlobalUrlFileDescriptor(url, titleStr, content);
    751731    if (!urlFileDescriptor)
    752732        return;
    753     HGLOBAL urlFileContent = createGlobalURLContent(url, estimatedSize);
     733    HGLOBAL urlFileContent = createGlobalURLContent(content);
    754734    if (!urlFileContent) {
    755735        GlobalFree(urlFileDescriptor);
Note: See TracChangeset for help on using the changeset viewer.