diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 03:37:55 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 03:37:55 +0000 |
commit | 9c5645b5f8af3c04528caef61c59e2754f79288b (patch) | |
tree | 76b465be9c92307ff53d3e793d727084c807c681 /webkit | |
parent | e3ecc42b385ab2e6dc6e37c11cc52e15fb755185 (diff) | |
download | chromium_src-9c5645b5f8af3c04528caef61c59e2754f79288b.zip chromium_src-9c5645b5f8af3c04528caef61c59e2754f79288b.tar.gz chromium_src-9c5645b5f8af3c04528caef61c59e2754f79288b.tar.bz2 |
Add some helper methods for constructing a WebCString from UTF16 input,
assuming a UTF16 to UTF8 conversion. Also, includes a .utf16() method on
WebCString to get a UTF16 string out. These methods mirror the similar
methods for UTF8 on WebString.
Make use of these conversion methods in a few more places.
R=dglazkov
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/164274
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23010 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/api/public/WebCString.h | 19 | ||||
-rw-r--r-- | webkit/api/public/WebString.h | 1 | ||||
-rw-r--r-- | webkit/api/src/WebCString.cpp | 28 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.cc | 2 | ||||
-rw-r--r-- | webkit/glue/webplugin_impl.cc | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/mock_webclipboard_impl.cc | 6 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 2 |
8 files changed, 50 insertions, 15 deletions
diff --git a/webkit/api/public/WebCString.h b/webkit/api/public/WebCString.h index 7b4cc4e..3e12ff0 100644 --- a/webkit/api/public/WebCString.h +++ b/webkit/api/public/WebCString.h @@ -1,10 +1,10 @@ /* * Copyright (C) 2009 Google Inc. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -40,8 +40,8 @@ namespace WebCore { class CString; } #endif namespace WebKit { - class WebCStringPrivate; + class WebString; // A single-byte string container with unspecified encoding. It is // inexpensive to copy a WebCString object. @@ -77,6 +77,11 @@ namespace WebKit { bool isEmpty() const { return length() == 0; } bool isNull() const { return m_private == 0; } + WEBKIT_API WebString utf16() const; + + WEBKIT_API static WebCString fromUTF16(const WebUChar* data, size_t length); + WEBKIT_API static WebCString fromUTF16(const WebUChar* data); + #if WEBKIT_IMPLEMENTATION WebCString(const WebCore::CString&); WebCString& operator=(const WebCore::CString&); @@ -98,6 +103,12 @@ namespace WebKit { size_t len = length(); return len ? std::string(data(), len) : std::string(); } + + template <class UTF16String> + static WebCString fromUTF16(const UTF16String& s) + { + return fromUTF16(s.data(), s.length()); + } #endif private: diff --git a/webkit/api/public/WebString.h b/webkit/api/public/WebString.h index bf59854..5107de4 100644 --- a/webkit/api/public/WebString.h +++ b/webkit/api/public/WebString.h @@ -86,6 +86,7 @@ namespace WebKit { WebString(const WebCore::String&); WebString& operator=(const WebCore::String&); operator WebCore::String() const; + WebString(const WebCore::AtomicString&); WebString& operator=(const WebCore::AtomicString&); operator WebCore::AtomicString() const; diff --git a/webkit/api/src/WebCString.cpp b/webkit/api/src/WebCString.cpp index a387a72..8e10659 100644 --- a/webkit/api/src/WebCString.cpp +++ b/webkit/api/src/WebCString.cpp @@ -1,10 +1,10 @@ /* * Copyright (C) 2009 Google Inc. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -31,7 +31,10 @@ #include "config.h" #include "WebCString.h" +#include "WebString.h" + #include "CString.h" +#include "TextEncoding.h" namespace WebKit { @@ -75,6 +78,25 @@ const char* WebCString::data() const return const_cast<WebCStringPrivate*>(m_private)->data(); } +WebString WebCString::utf16() const +{ + return WebCore::UTF8Encoding().decode(data(), length()); +} + +WebCString WebCString::fromUTF16(const WebUChar* data, size_t length) +{ + return WebCore::UTF8Encoding().encode( + data, length, WebCore::QuestionMarksForUnencodables); +} + +WebCString WebCString::fromUTF16(const WebUChar* data) +{ + size_t len = 0; + while (data[len] != WebUChar(0)) + len++; + return fromUTF16(data, len); +} + WebCString::WebCString(const WebCore::CString& s) : m_private(static_cast<WebCStringPrivate*>(s.buffer())) { diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index 7233a1f..5b1669b 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -116,7 +116,7 @@ void WebKitClientImpl::getPluginList(bool refresh, const WebPluginMimeType& mime_type = plugin.mime_types[j]; builder->addMediaTypeToLastPlugin( - UTF8ToUTF16(mime_type.mime_type), + WebString::fromUTF8(mime_type.mime_type), WideToUTF16Hack(mime_type.description)); for (size_t k = 0; k < mime_type.file_extensions.size(); ++k) { diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index b4e78d0..7bb8b94 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -629,7 +629,8 @@ NPObject* WebPluginImpl::GetPluginElement() { void WebPluginImpl::SetCookie(const GURL& url, const GURL& policy_url, const std::string& cookie) { - WebKit::webKitClient()->setCookies(url, policy_url, UTF8ToUTF16(cookie)); + WebKit::webKitClient()->setCookies( + url, policy_url, WebString::fromUTF8(cookie)); } std::string WebPluginImpl::GetCookies(const GURL& url, const GURL& policy_url) { diff --git a/webkit/tools/test_shell/mock_webclipboard_impl.cc b/webkit/tools/test_shell/mock_webclipboard_impl.cc index bca4aad..32f3f01 100644 --- a/webkit/tools/test_shell/mock_webclipboard_impl.cc +++ b/webkit/tools/test_shell/mock_webclipboard_impl.cc @@ -50,16 +50,16 @@ void MockWebClipboardImpl::writeHTML( void MockWebClipboardImpl::writeURL( const WebKit::WebURL& url, const WebKit::WebString& title) { - m_htmlText = UTF8ToUTF16( + m_htmlText = WebString::fromUTF8( webkit_glue::WebClipboardImpl::URLToMarkup(url, title)); - m_plainText = UTF8ToUTF16(url.spec()); + m_plainText = url.spec().utf16(); m_writeSmartPaste = false; } void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, const WebKit::WebURL& url, const WebKit::WebString& title) { if (!image.isNull()) { - m_htmlText = UTF8ToUTF16( + m_htmlText = WebString::fromUTF8( webkit_glue::WebClipboardImpl::URLToImageMarkup(url, title)); m_plainText = m_htmlText; m_writeSmartPaste = false; diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index 6db295c..8b4fb66 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -101,13 +101,13 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { const WebKit::WebURL& first_party_for_cookies, const WebKit::WebString& value) { SimpleResourceLoaderBridge::SetCookie( - url, first_party_for_cookies, UTF16ToUTF8(value)); + url, first_party_for_cookies, value.utf8()); } virtual WebKit::WebString cookies( const WebKit::WebURL& url, const WebKit::WebURL& first_party_for_cookies) { - return UTF8ToUTF16(SimpleResourceLoaderBridge::GetCookies( + return WebKit::WebString::fromUTF8(SimpleResourceLoaderBridge::GetCookies( url, first_party_for_cookies)); } diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index e665c84..f3ae7e8 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -285,7 +285,7 @@ void TestWebViewDelegate::WillSendRequest( GetResourceDescription(identifier).c_str(), request_url.c_str(), GetURLDescription(main_document_url).c_str(), - UTF16ToUTF8(request->httpMethod()).c_str(), + request->httpMethod().utf8().data(), GetResponseDescription(redirect_response).c_str()); } |