diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-03 18:11:25 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-03 18:11:25 +0000 |
commit | 906690b746ff0bbc3eedc839fc7ae03936f3dc67 (patch) | |
tree | 6baea2966a1f5008bb06bf70f13e391ce8550ed7 /webkit | |
parent | f889b65a91ed110ba84a75b3d6c6c87f77367c5e (diff) | |
download | chromium_src-906690b746ff0bbc3eedc839fc7ae03936f3dc67.zip chromium_src-906690b746ff0bbc3eedc839fc7ae03936f3dc67.tar.gz chromium_src-906690b746ff0bbc3eedc839fc7ae03936f3dc67.tar.bz2 |
wstrings: convert CppVariant and CppBoundClass to not use wstring
Confusingly, we had a ToString() that returned a UTF-8 string and
a ToStringVector() that returned wstrings. Since CppVariant is
a small wrapper around NPVariant I made them both use UTF-8; it
simplified most of the users anyway (which only dealt with ASCII
anyway).
BUG=23581
TEST=compiles
Review URL: http://codereview.chromium.org/5631002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68187 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/cpp_bound_class.cc | 4 | ||||
-rw-r--r-- | webkit/glue/cpp_bound_class.h | 3 | ||||
-rw-r--r-- | webkit/glue/cpp_bound_class_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/glue/cpp_variant.cc | 9 | ||||
-rw-r--r-- | webkit/glue/cpp_variant.h | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/accessibility_controller.cc | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/accessibility_controller.h | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/event_sending_controller.cc | 28 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.cc | 10 |
9 files changed, 29 insertions, 34 deletions
diff --git a/webkit/glue/cpp_bound_class.cc b/webkit/glue/cpp_bound_class.cc index d58fc4e..c5d15b6 100644 --- a/webkit/glue/cpp_bound_class.cc +++ b/webkit/glue/cpp_bound_class.cc @@ -319,7 +319,7 @@ CppVariant* CppBoundClass::GetAsCppVariant() { } void CppBoundClass::BindToJavascript(WebFrame* frame, - const std::wstring& classname) { + const std::string& classname) { #if WEBKIT_USING_JSC #error "This is not going to work anymore...but it's not clear what the solution is...or if it's still necessary." JSC::JSLock lock(false); @@ -328,7 +328,7 @@ void CppBoundClass::BindToJavascript(WebFrame* frame, // BindToWindowObject will take its own reference to the NPObject, and clean // up after itself. It will also (indirectly) register the object with V8, // so we must remember this so we can unregister it when we're destroyed. - frame->bindToWindowObject(WideToUTF16Hack(classname), + frame->bindToWindowObject(ASCIIToUTF16(classname), NPVARIANT_TO_OBJECT(*GetAsCppVariant())); bound_to_frame_ = true; } diff --git a/webkit/glue/cpp_bound_class.h b/webkit/glue/cpp_bound_class.h index a446386..06662ce 100644 --- a/webkit/glue/cpp_bound_class.h +++ b/webkit/glue/cpp_bound_class.h @@ -65,8 +65,7 @@ class CppBoundClass { // as window.<classname>. The owner of the CppBoundObject is responsible for // keeping the object around while the frame is alive, and for destroying it // afterwards. - void BindToJavascript( - WebKit::WebFrame* frame, const std::wstring& classname); + void BindToJavascript(WebKit::WebFrame* frame, const std::string& classname); // The type of callbacks. typedef Callback2<const CppArgumentList&, CppVariant*>::Type Callback; diff --git a/webkit/glue/cpp_bound_class_unittest.cc b/webkit/glue/cpp_bound_class_unittest.cc index 283b807..2f53c47 100644 --- a/webkit/glue/cpp_bound_class_unittest.cc +++ b/webkit/glue/cpp_bound_class_unittest.cc @@ -63,7 +63,7 @@ class ExampleTestShell : public TestShell { // When called by WebViewDelegate::WindowObjectCleared method, this binds a // CppExampleObject to window.example. virtual void BindJSObjectsToWindow(WebFrame* frame) { - example_bound_class_.BindToJavascript(frame, L"example"); + example_bound_class_.BindToJavascript(frame, "example"); // We use the layoutTestController binding for notifyDone. TestShell::BindJSObjectsToWindow(frame); } diff --git a/webkit/glue/cpp_variant.cc b/webkit/glue/cpp_variant.cc index 8545bc1..0d16cdd 100644 --- a/webkit/glue/cpp_variant.cc +++ b/webkit/glue/cpp_variant.cc @@ -211,10 +211,9 @@ bool CppVariant::ToBoolean() const { return value.boolValue; } -std::vector<std::wstring> CppVariant::ToStringVector() const { - +std::vector<std::string> CppVariant::ToStringVector() const { DCHECK(isObject()); - std::vector<std::wstring> wstring_vector; + std::vector<std::string> string_vector; NPObject* np_value = value.objectValue; NPIdentifier length_id = WebBindings::getStringIdentifier("length"); @@ -242,7 +241,7 @@ std::vector<std::wstring> CppVariant::ToStringVector() const { std::string string( NPVARIANT_TO_STRING(index_value).UTF8Characters, NPVARIANT_TO_STRING(index_value).UTF8Length); - wstring_vector.push_back(UTF8ToWide(string)); + string_vector.push_back(string); } WebBindings::releaseVariantValue(&index_value); } @@ -250,7 +249,7 @@ std::vector<std::wstring> CppVariant::ToStringVector() const { } } } - return wstring_vector; + return string_vector; } bool CppVariant::Invoke(const std::string& method, const CppVariant* args, diff --git a/webkit/glue/cpp_variant.h b/webkit/glue/cpp_variant.h index 71b3166..34f843a 100644 --- a/webkit/glue/cpp_variant.h +++ b/webkit/glue/cpp_variant.h @@ -96,7 +96,7 @@ class CppVariant : public NPVariant { bool ToBoolean() const; // Returns a vector of strings for the specified argument. This is useful // for converting a JavaScript array of strings into a vector of strings. - std::vector<std::wstring> ToStringVector() const; + std::vector<std::string> ToStringVector() const; // Invoke method of the given name on an object with the supplied arguments. // The first argument should be the object on which the method is to be diff --git a/webkit/tools/test_shell/accessibility_controller.cc b/webkit/tools/test_shell/accessibility_controller.cc index 7778499..4f0276f 100644 --- a/webkit/tools/test_shell/accessibility_controller.cc +++ b/webkit/tools/test_shell/accessibility_controller.cc @@ -34,7 +34,7 @@ AccessibilityController::AccessibilityController(TestShell* shell) } void AccessibilityController::BindToJavascript( - WebFrame* frame, const std::wstring& classname) { + WebFrame* frame, const std::string& classname) { WebAccessibilityCache::enableAccessibility(); CppBoundClass::BindToJavascript(frame, classname); } diff --git a/webkit/tools/test_shell/accessibility_controller.h b/webkit/tools/test_shell/accessibility_controller.h index 018c2f1..6948c2d 100644 --- a/webkit/tools/test_shell/accessibility_controller.h +++ b/webkit/tools/test_shell/accessibility_controller.h @@ -22,8 +22,7 @@ class AccessibilityController : public CppBoundClass { explicit AccessibilityController(TestShell* shell); // shadow to include accessibility initialization. - void BindToJavascript( - WebKit::WebFrame* frame, const std::wstring& classname); + void BindToJavascript(WebKit::WebFrame* frame, const std::string& classname); void Reset(); void SetFocusedElement(const WebKit::WebAccessibilityObject& focused_element); diff --git a/webkit/tools/test_shell/event_sending_controller.cc b/webkit/tools/test_shell/event_sending_controller.cc index bf02835..9f6fe4b 100644 --- a/webkit/tools/test_shell/event_sending_controller.cc +++ b/webkit/tools/test_shell/event_sending_controller.cc @@ -149,19 +149,17 @@ void InitMouseEvent(WebInputEvent::Type t, WebMouseEvent::Button b, } // Returns true if the specified key is the system key. -bool ApplyKeyModifier(const std::wstring& arg, WebInputEvent* event) { +bool ApplyKeyModifier(const std::string& key, WebInputEvent* event) { bool system_key = false; - const wchar_t* arg_string = arg.c_str(); - if (!wcscmp(arg_string, L"ctrlKey") + if (key == "ctrlKey" #if !defined(OS_MACOSX) - || !wcscmp(arg_string, L"addSelectionKey") + || key == "addSelectionKey" #endif ) { event->modifiers |= WebInputEvent::ControlKey; - } else if (!wcscmp(arg_string, L"shiftKey") - || !wcscmp(arg_string, L"rangeSelectionKey")) { + } else if (key == "shiftKey" || key == "rangeSelectionKey") { event->modifiers |= WebInputEvent::ShiftKey; - } else if (!wcscmp(arg_string, L"altKey")) { + } else if (key == "altKey") { event->modifiers |= WebInputEvent::AltKey; #if !defined(OS_MACOSX) // On Windows all keys with Alt modifier will be marked as system key. @@ -172,8 +170,7 @@ bool ApplyKeyModifier(const std::wstring& arg, WebInputEvent* event) { system_key = true; #endif #if defined(OS_MACOSX) - } else if (!wcscmp(arg_string, L"metaKey") - || !wcscmp(arg_string, L"addSelectionKey")) { + } else if (key == "metaKey" || key == "addSelectionKey") { event->modifiers |= WebInputEvent::MetaKey; // On Mac only command key presses are marked as system key. // See the related code in: @@ -181,7 +178,7 @@ bool ApplyKeyModifier(const std::wstring& arg, WebInputEvent* event) { // It must be kept in sync with the related code in above file. system_key = true; #else - } else if (!wcscmp(arg_string, L"metaKey")) { + } else if (key == "metaKey") { event->modifiers |= WebInputEvent::MetaKey; #endif } @@ -191,13 +188,13 @@ bool ApplyKeyModifier(const std::wstring& arg, WebInputEvent* event) { bool ApplyKeyModifiers(const CppVariant* arg, WebInputEvent* event) { bool system_key = false; if (arg->isObject()) { - std::vector<std::wstring> args = arg->ToStringVector(); - for (std::vector<std::wstring>::const_iterator i = args.begin(); + std::vector<std::string> args = arg->ToStringVector(); + for (std::vector<std::string>::const_iterator i = args.begin(); i != args.end(); ++i) { system_key |= ApplyKeyModifier(*i, event); } } else if (arg->isString()) { - system_key = ApplyKeyModifier(UTF8ToWide(arg->ToString()), event); + system_key = ApplyKeyModifier(arg->ToString(), event); } return system_key; } @@ -863,9 +860,10 @@ void EventSendingController::scheduleAsynchronousClick( void EventSendingController::beginDragWithFiles( const CppArgumentList& args, CppVariant* result) { current_drag_data.initialize(); - std::vector<std::wstring> files = args[0].ToStringVector(); + std::vector<std::string> files = args[0].ToStringVector(); for (size_t i = 0; i < files.size(); ++i) { - FilePath file_path = FilePath::FromWStringHack(files[i]); + std::wstring file = UTF8ToWide(files[i]); + FilePath file_path = FilePath::FromWStringHack(file); file_util::AbsolutePath(&file_path); current_drag_data.appendToFilenames( webkit_glue::FilePathStringToWebString(file_path.value())); diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index e5d4461..ffaba74 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -555,11 +555,11 @@ void TestShell::BindJSObjectsToWindow(WebFrame* frame) { // Only bind the test classes if we're running tests. if (layout_test_mode_) { accessibility_controller_->BindToJavascript( - frame, L"accessibilityController"); - layout_test_controller_->BindToJavascript(frame, L"layoutTestController"); - event_sending_controller_->BindToJavascript(frame, L"eventSender"); - plain_text_controller_->BindToJavascript(frame, L"plainText"); - text_input_controller_->BindToJavascript(frame, L"textInputController"); + frame, "accessibilityController"); + layout_test_controller_->BindToJavascript(frame, "layoutTestController"); + event_sending_controller_->BindToJavascript(frame, "eventSender"); + plain_text_controller_->BindToJavascript(frame, "plainText"); + text_input_controller_->BindToJavascript(frame, "textInputController"); } } |