Changeset 79827 in webkit


Ignore:
Timestamp:
Feb 27, 2011 1:16:50 PM (13 years ago)
Author:
Adam Roben
Message:

Make ResourceLoadDelegate print URLs relative to the main resource on Windows

This matches Mac. (In fact, the code was ported from Mac!)

Fixes <http://webkit.org/b/55328> URLs printed by ResourceLoadDelegate on Windows don't
match Mac

Reviewed by Anders Carlsson.

  • DumpRenderTree/win/DumpRenderTree.cpp:

(substringFromIndex): Added. Emulates -[NSString substringFromIndex:].
(urlSuitableForTestResult): Ported code from -[NSURL(DRTExtras)
_drt_descriptionSuitableForTestResult].
(cfStringRefToWString): Moved here from LayoutTestControllerWin.cpp.

  • DumpRenderTree/win/DumpRenderTreeWin.h: Added declaration of cfStringRefToWString.
  • DumpRenderTree/win/LayoutTestControllerWin.cpp: Moved cfStringRefToWString to

DumpRenderTree.cpp.

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r79823 r79827  
     12011-02-27  Adam Roben  <aroben@apple.com>
     2
     3        Make ResourceLoadDelegate print URLs relative to the main resource on Windows
     4
     5        This matches Mac. (In fact, the code was ported from Mac!)
     6
     7        Fixes <http://webkit.org/b/55328> URLs printed by ResourceLoadDelegate on Windows don't
     8        match Mac
     9
     10        Reviewed by Anders Carlsson.
     11
     12        * DumpRenderTree/win/DumpRenderTree.cpp:
     13        (substringFromIndex): Added. Emulates -[NSString substringFromIndex:].
     14        (urlSuitableForTestResult): Ported code from -[NSURL(DRTExtras)
     15        _drt_descriptionSuitableForTestResult].
     16        (cfStringRefToWString): Moved here from LayoutTestControllerWin.cpp.
     17
     18        * DumpRenderTree/win/DumpRenderTreeWin.h: Added declaration of cfStringRefToWString.
     19
     20        * DumpRenderTree/win/LayoutTestControllerWin.cpp: Moved cfStringRefToWString to
     21        DumpRenderTree.cpp.
     22
    1232011-02-27  Adam Roben  <aroben@apple.com>
    224
  • trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp

    r79793 r79827  
    4141#include "WorkQueue.h"
    4242
     43#include <comutil.h>
    4344#include <fcntl.h>
    4445#include <io.h>
     
    132133}
    133134
    134 wstring urlSuitableForTestResult(const wstring& url)
    135 {
    136     if (url.find(L"file://") == wstring::npos)
    137         return url;
    138 
    139     return lastPathComponent(url);
     135static RetainPtr<CFStringRef> substringFromIndex(CFStringRef string, CFIndex index)
     136{
     137    return RetainPtr<CFStringRef>(AdoptCF, CFStringCreateWithSubstring(kCFAllocatorDefault, string, CFRangeMake(index, CFStringGetLength(string) - index)));
     138}
     139
     140wstring urlSuitableForTestResult(const wstring& urlString)
     141{
     142    RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateWithBytes(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(urlString.c_str()), urlString.length() * sizeof(wstring::value_type), kCFStringEncodingUTF16, 0));
     143
     144    RetainPtr<CFStringRef> scheme(AdoptCF, CFURLCopyScheme(url.get()));
     145    if (scheme && CFStringCompare(scheme.get(), CFSTR("file"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)
     146        return urlString;
     147
     148    COMPtr<IWebDataSource> dataSource;
     149    if (FAILED(frame->dataSource(&dataSource))) {
     150        if (FAILED(frame->provisionalDataSource(&dataSource)))
     151            return urlString;
     152    }
     153
     154    COMPtr<IWebMutableURLRequest> request;
     155    if (FAILED(dataSource->request(&request)))
     156        return urlString;
     157
     158    _bstr_t requestURLString;
     159    if (FAILED(request->URL(requestURLString.GetAddress())))
     160        return urlString;
     161
     162    RetainPtr<CFURLRef> requestURL(AdoptCF, CFURLCreateWithBytes(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(requestURLString.GetBSTR()), requestURLString.length() * sizeof(OLECHAR), kCFStringEncodingUTF16, 0));
     163    RetainPtr<CFURLRef> baseURL(AdoptCF, CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, requestURL.get()));
     164
     165    RetainPtr<CFStringRef> basePath(AdoptCF, CFURLCopyPath(baseURL.get()));
     166    RetainPtr<CFStringRef> path(AdoptCF, CFURLCopyPath(url.get()));
     167
     168    return cfStringRefToWString(substringFromIndex(path.get(), CFStringGetLength(basePath.get())).get());
    140169}
    141170
     
    167196{
    168197    return toUTF8(wideString.c_str(), wideString.length());
     198}
     199
     200wstring cfStringRefToWString(CFStringRef cfStr)
     201{
     202    Vector<wchar_t> v(CFStringGetLength(cfStr));
     203    CFStringGetCharacters(cfStr, CFRangeMake(0, CFStringGetLength(cfStr)), (UniChar *)v.data());
     204
     205    return wstring(v.data(), v.size());
    169206}
    170207
  • trunk/Tools/DumpRenderTree/win/DumpRenderTreeWin.h

    r70540 r79827  
    5353std::string toUTF8(BSTR);
    5454std::string toUTF8(const std::wstring&);
     55std::wstring cfStringRefToWString(CFStringRef);
     56
    5557IWebView* createWebViewAndOffscreenWindow(HWND* webViewWindow = 0);
    5658Vector<HWND>& openWindows();
  • trunk/Tools/DumpRenderTree/win/LayoutTestControllerWin.cpp

    r79783 r79827  
    712712}
    713713
    714 static wstring cfStringRefToWString(CFStringRef cfStr)
    715 {
    716     Vector<wchar_t> v(CFStringGetLength(cfStr));
    717     CFStringGetCharacters(cfStr, CFRangeMake(0, CFStringGetLength(cfStr)), (UniChar *)v.data());
    718 
    719     return wstring(v.data(), v.size());
    720 }
    721 
    722714void LayoutTestController::setUserStyleSheetLocation(JSStringRef jsURL)
    723715{
Note: See TracChangeset for help on using the changeset viewer.