Commit 1f191872 authored by aroben@apple.com's avatar aroben@apple.com
Browse files

Convert status bar text to UTF-8 before logging it on Windows

We were previously logging the text using printf("%S", bstr). This
converts the UTF-16 BSTR to a multibyte string using wctomb, which
uses the codepage for the current locale to perform the conversion.
The conversion was failing, causing printf to bail and truncate the
string. By converting to UTF-8 manually before logging, we avoid this
issue (and also end up with UTF-8 output, which is what the expected
results contain). We may have to do this in other places in DRT,
eventually.

Fixes <http://webkit.org/b/38849> REGRESSION (r59016):
plugins/set-status.html fails on Windows

Reviewed by Alexey Proskuryakov.

* DumpRenderTree/win/DumpRenderTree.cpp:
(toUTF8): Moved this here from FrameLoadDelegate. Renamed from
BSTRtoString.

* DumpRenderTree/win/DumpRenderTreeWin.h: Added declaration of toUTF8.

* DumpRenderTree/win/FrameLoadDelegate.cpp: Removed BSTRtoString.
(descriptionSuitableForTestResult): Updated for rename.

* DumpRenderTree/win/UIDelegate.cpp:
(UIDelegate::setStatusText): Convert the status bar text to UTF-8
before logging it so that Windows won't try (and fail) to convert it
to the current locale's codepage.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@59371 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 882bfcfa
2010-05-10 Adam Roben <aroben@apple.com>
Convert status bar text to UTF-8 before logging it on Windows
We were previously logging the text using printf("%S", bstr). This
converts the UTF-16 BSTR to a multibyte string using wctomb, which
uses the codepage for the current locale to perform the conversion.
The conversion was failing, causing printf to bail and truncate the
string. By converting to UTF-8 manually before logging, we avoid this
issue (and also end up with UTF-8 output, which is what the expected
results contain). We may have to do this in other places in DRT,
eventually.
Fixes <http://webkit.org/b/38849> REGRESSION (r59016):
plugins/set-status.html fails on Windows
Reviewed by Alexey Proskuryakov.
* DumpRenderTree/win/DumpRenderTree.cpp:
(toUTF8): Moved this here from FrameLoadDelegate. Renamed from
BSTRtoString.
* DumpRenderTree/win/DumpRenderTreeWin.h: Added declaration of toUTF8.
* DumpRenderTree/win/FrameLoadDelegate.cpp: Removed BSTRtoString.
(descriptionSuitableForTestResult): Updated for rename.
* DumpRenderTree/win/UIDelegate.cpp:
(UIDelegate::setStatusText): Convert the status bar text to UTF-8
before logging it so that Windows won't try (and fail) to convert it
to the current locale's codepage.
2010-05-13 Eric Seidel <eric@webkit.org>
 
Unreviewed hack, attempting to get the commit-queue running again.
......@@ -140,6 +140,17 @@ wstring urlSuitableForTestResult(const wstring& url)
return PathFindFileNameW(url.c_str());
}
string toUTF8(BSTR bstr)
{
int result = WideCharToMultiByte(CP_UTF8, 0, bstr, SysStringLen(bstr) + 1, 0, 0, 0, 0);
Vector<char> utf8Vector(result);
result = WideCharToMultiByte(CP_UTF8, 0, bstr, SysStringLen(bstr) + 1, utf8Vector.data(), result, 0, 0);
if (!result)
return string();
return string(utf8Vector.data(), utf8Vector.size() - 1);
}
static LRESULT CALLBACK DumpRenderTreeWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
......
......@@ -49,6 +49,7 @@ extern HWND webViewWindow;
#include <wtf/Vector.h>
std::wstring urlSuitableForTestResult(const std::wstring& url);
std::string toUTF8(BSTR);
IWebView* createWebViewAndOffscreenWindow(HWND* webViewWindow = 0);
Vector<HWND>& openWindows();
typedef HashMap<HWND, COMPtr<IWebView> > WindowToWebViewMap;
......
......@@ -48,17 +48,6 @@ using std::string;
static FrameLoadDelegate* g_delegateWaitingOnTimer;
string BSTRtoString(BSTR bstr)
{
int result = WideCharToMultiByte(CP_UTF8, 0, bstr, SysStringLen(bstr) + 1, 0, 0, 0, 0);
Vector<char> utf8Vector(result);
result = WideCharToMultiByte(CP_UTF8, 0, bstr, SysStringLen(bstr) + 1, utf8Vector.data(), result, 0, 0);
if (!result)
return string();
return string(utf8Vector.data(), utf8Vector.size() - 1);
}
string descriptionSuitableForTestResult(IWebFrame* webFrame)
{
COMPtr<IWebView> webView;
......@@ -70,11 +59,11 @@ string descriptionSuitableForTestResult(IWebFrame* webFrame)
return string();
BSTR frameNameBSTR;
if (FAILED(webFrame->name(&frameNameBSTR)) || BSTRtoString(frameNameBSTR).empty() )
if (FAILED(webFrame->name(&frameNameBSTR)) || toUTF8(frameNameBSTR).empty())
return (webFrame == mainFrame) ? "main frame" : string();
string frameName = (webFrame == mainFrame) ? "main frame" : "frame";
frameName += " \"" + BSTRtoString(frameNameBSTR) + "\"";
frameName += " \"" + toUTF8(frameNameBSTR) + "\"";
SysFreeString(frameNameBSTR);
return frameName;
......
......@@ -625,7 +625,7 @@ HRESULT STDMETHODCALLTYPE UIDelegate::webViewDidInvalidate(
HRESULT STDMETHODCALLTYPE UIDelegate::setStatusText(IWebView*, BSTR text)
{
if (gLayoutTestController->dumpStatusCallbacks())
printf("UI DELEGATE STATUS CALLBACK: setStatusText:%S\n", text ? text : L"");
printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", text ? toUTF8(text).c_str() : "");
return S_OK;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment