 Chromium Code Reviews
 Chromium Code Reviews Issue 5631002:
  wstrings: convert CppVariant and CppBoundClass to not use wstring  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 5631002:
  wstrings: convert CppVariant and CppBoundClass to not use wstring  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "chrome/renderer/dom_ui_bindings.h" | 5 #include "chrome/renderer/dom_ui_bindings.h" | 
| 6 | 6 | 
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" | 
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" | 
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "base/values.h" | 9 #include "base/values.h" | 
| 11 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" | 
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 
| 14 | 13 | 
| 15 DOMBoundBrowserObject::DOMBoundBrowserObject() | 14 DOMBoundBrowserObject::DOMBoundBrowserObject() | 
| 16 : sender_(NULL), | 15 : sender_(NULL), | 
| 17 routing_id_(0) { | 16 routing_id_(0) { | 
| 18 } | 17 } | 
| 19 | 18 | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 36 // Require the first parameter to be the message name. | 35 // Require the first parameter to be the message name. | 
| 37 if (!args[0].isString()) | 36 if (!args[0].isString()) | 
| 38 return; | 37 return; | 
| 39 const std::string message = args[0].ToString(); | 38 const std::string message = args[0].ToString(); | 
| 40 | 39 | 
| 41 // If they've provided an optional message parameter, convert that into JSON. | 40 // If they've provided an optional message parameter, convert that into JSON. | 
| 42 std::string content; | 41 std::string content; | 
| 43 if (args.size() == 2) { | 42 if (args.size() == 2) { | 
| 44 if (!args[1].isObject()) | 43 if (!args[1].isObject()) | 
| 45 return; | 44 return; | 
| 46 // TODO(evanm): we ought to support more than just sending arrays of | 45 std::vector<std::string> strings = args[1].ToStringVector(); | 
| 47 // strings, but it's not yet necessary for the current code. | |
| 48 std::vector<std::wstring> strings = args[1].ToStringVector(); | |
| 49 ListValue value; | 46 ListValue value; | 
| 50 for (size_t i = 0; i < strings.size(); ++i) { | 47 for (size_t i = 0; i < strings.size(); ++i) { | 
| 51 // TODO(viettrungluu): remove conversion and utf_string_conversions.h | 48 value.Append(Value::CreateStringValue(strings[i])); | 
| 52 value.Append(Value::CreateStringValue(WideToUTF16Hack(strings[i]))); | |
| 53 } | 49 } | 
| 
viettrungluu
2010/12/03 02:00:16
You can probably omit the braces as well. (I don't
 | |
| 54 base::JSONWriter::Write(&value, /* pretty_print= */ false, &content); | 50 base::JSONWriter::Write(&value, /* pretty_print= */ false, &content); | 
| 55 } | 51 } | 
| 56 | 52 | 
| 57 // Retrieve the source frame's url | 53 // Retrieve the source frame's url | 
| 58 GURL source_url; | 54 GURL source_url; | 
| 59 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | 55 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | 
| 60 if (webframe) | 56 if (webframe) | 
| 61 source_url = webframe->url(); | 57 source_url = webframe->url(); | 
| 62 | 58 | 
| 63 // Send the message up to the browser. | 59 // Send the message up to the browser. | 
| 64 sender()->Send( | 60 sender()->Send( | 
| 65 new ViewHostMsg_DOMUISend(routing_id(), source_url, message, content)); | 61 new ViewHostMsg_DOMUISend(routing_id(), source_url, message, content)); | 
| 66 } | 62 } | 
| 67 | 63 | 
| 68 void DOMBoundBrowserObject::SetProperty(const std::string& name, | 64 void DOMBoundBrowserObject::SetProperty(const std::string& name, | 
| 69 const std::string& value) { | 65 const std::string& value) { | 
| 70 CppVariant* cpp_value = new CppVariant; | 66 CppVariant* cpp_value = new CppVariant; | 
| 71 cpp_value->Set(value); | 67 cpp_value->Set(value); | 
| 72 BindProperty(name, cpp_value); | 68 BindProperty(name, cpp_value); | 
| 73 properties_.push_back(cpp_value); | 69 properties_.push_back(cpp_value); | 
| 74 } | 70 } | 
| OLD | NEW |