summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 22:41:39 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 22:41:39 +0000
commitadcf849477a46539dcabb92769d9730893054dff (patch)
tree633f09a924b882dcb147bb661f919736dfc26004 /content
parent1f4ea6647f7fecc7c4e913cd47f1df752abcb66e (diff)
downloadchromium_src-adcf849477a46539dcabb92769d9730893054dff.zip
chromium_src-adcf849477a46539dcabb92769d9730893054dff.tar.gz
chromium_src-adcf849477a46539dcabb92769d9730893054dff.tar.bz2
Switch content/browser/webui to string16/std::string, update all callers.
BUG=23581 TEST=zero visible change Review URL: http://codereview.chromium.org/6647021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77535 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/webui/web_ui.cc44
-rw-r--r--content/browser/webui/web_ui.h17
2 files changed, 34 insertions, 27 deletions
diff --git a/content/browser/webui/web_ui.cc b/content/browser/webui/web_ui.cc
index 05bcbc5..e1f5fbd 100644
--- a/content/browser/webui/web_ui.cc
+++ b/content/browser/webui/web_ui.cc
@@ -22,18 +22,19 @@
namespace {
-std::wstring GetJavascript(const std::wstring& function_name,
- const std::vector<const Value*>& arg_list) {
- std::wstring parameters;
+string16 GetJavascript(const std::string& function_name,
+ const std::vector<const Value*>& arg_list) {
+ string16 parameters;
std::string json;
for (size_t i = 0; i < arg_list.size(); ++i) {
if (i > 0)
- parameters += L",";
+ parameters += char16(',');
base::JSONWriter::Write(arg_list[i], false, &json);
- parameters += UTF8ToWide(json);
+ parameters += UTF8ToUTF16(json);
}
- return function_name + L"(" + parameters + L");";
+ return ASCIIToUTF16(function_name) +
+ char16('(') + parameters + char16(')') + char16(';');
}
} // namespace
@@ -70,21 +71,24 @@ void WebUI::ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params) {
callback->second->Run(&params.arguments);
}
-void WebUI::CallJavascriptFunction(const std::wstring& function_name) {
- std::wstring javascript = function_name + L"();";
+void WebUI::CallJavascriptFunction(const std::string& function_name) {
+ DCHECK(IsStringASCII(function_name));
+ string16 javascript = ASCIIToUTF16(function_name + "();");
ExecuteJavascript(javascript);
}
-void WebUI::CallJavascriptFunction(const std::wstring& function_name,
+void WebUI::CallJavascriptFunction(const std::string& function_name,
const Value& arg) {
+ DCHECK(IsStringASCII(function_name));
std::vector<const Value*> args;
args.push_back(&arg);
ExecuteJavascript(GetJavascript(function_name, args));
}
void WebUI::CallJavascriptFunction(
- const std::wstring& function_name,
+ const std::string& function_name,
const Value& arg1, const Value& arg2) {
+ DCHECK(IsStringASCII(function_name));
std::vector<const Value*> args;
args.push_back(&arg1);
args.push_back(&arg2);
@@ -92,8 +96,9 @@ void WebUI::CallJavascriptFunction(
}
void WebUI::CallJavascriptFunction(
- const std::wstring& function_name,
+ const std::string& function_name,
const Value& arg1, const Value& arg2, const Value& arg3) {
+ DCHECK(IsStringASCII(function_name));
std::vector<const Value*> args;
args.push_back(&arg1);
args.push_back(&arg2);
@@ -102,11 +107,12 @@ void WebUI::CallJavascriptFunction(
}
void WebUI::CallJavascriptFunction(
- const std::wstring& function_name,
+ const std::string& function_name,
const Value& arg1,
const Value& arg2,
const Value& arg3,
const Value& arg4) {
+ DCHECK(IsStringASCII(function_name));
std::vector<const Value*> args;
args.push_back(&arg1);
args.push_back(&arg2);
@@ -116,8 +122,9 @@ void WebUI::CallJavascriptFunction(
}
void WebUI::CallJavascriptFunction(
- const std::wstring& function_name,
+ const std::string& function_name,
const std::vector<const Value*>& args) {
+ DCHECK(IsStringASCII(function_name));
ExecuteJavascript(GetJavascript(function_name, args));
}
@@ -151,9 +158,9 @@ void WebUI::AddMessageHandler(WebUIMessageHandler* handler) {
handlers_.push_back(handler);
}
-void WebUI::ExecuteJavascript(const std::wstring& javascript) {
+void WebUI::ExecuteJavascript(const string16& javascript) {
GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(),
- WideToUTF16Hack(javascript));
+ javascript);
}
///////////////////////////////////////////////////////////////////////////////
@@ -207,11 +214,10 @@ bool WebUIMessageHandler::ExtractIntegerValue(const ListValue* value,
return false;
}
-// TODO(viettrungluu): convert to string16 (or UTF-8 std::string?).
-std::wstring WebUIMessageHandler::ExtractStringValue(const ListValue* value) {
+string16 WebUIMessageHandler::ExtractStringValue(const ListValue* value) {
string16 string16_value;
if (value->GetString(0, &string16_value))
- return UTF16ToWideHack(string16_value);
+ return string16_value;
NOTREACHED();
- return std::wstring();
+ return string16();
}
diff --git a/content/browser/webui/web_ui.h b/content/browser/webui/web_ui.h
index 0ff0b15..8dbabe5 100644
--- a/content/browser/webui/web_ui.h
+++ b/content/browser/webui/web_ui.h
@@ -119,23 +119,24 @@ class WebUI {
// the renderer. This is asynchronous; there's no way to get the result
// of the call, and should be thought of more like sending a message to
// the page.
+ // All function names in WebUI must consist of only ASCII characters.
// There are variants for calls with more arguments.
- void CallJavascriptFunction(const std::wstring& function_name);
- void CallJavascriptFunction(const std::wstring& function_name,
+ void CallJavascriptFunction(const std::string& function_name);
+ void CallJavascriptFunction(const std::string& function_name,
const Value& arg);
- void CallJavascriptFunction(const std::wstring& function_name,
+ void CallJavascriptFunction(const std::string& function_name,
const Value& arg1,
const Value& arg2);
- void CallJavascriptFunction(const std::wstring& function_name,
+ void CallJavascriptFunction(const std::string& function_name,
const Value& arg1,
const Value& arg2,
const Value& arg3);
- void CallJavascriptFunction(const std::wstring& function_name,
+ void CallJavascriptFunction(const std::string& function_name,
const Value& arg1,
const Value& arg2,
const Value& arg3,
const Value& arg4);
- void CallJavascriptFunction(const std::wstring& function_name,
+ void CallJavascriptFunction(const std::string& function_name,
const std::vector<const Value*>& args);
ui::ThemeProvider* GetThemeProvider() const;
@@ -153,7 +154,7 @@ class WebUI {
// Execute a string of raw Javascript on the page. Overridable for
// testing purposes.
- virtual void ExecuteJavascript(const std::wstring& javascript);
+ virtual void ExecuteJavascript(const string16& javascript);
// Options that may be overridden by individual Web UI implementations. The
// bool options default to false. See the public getters for more information.
@@ -210,7 +211,7 @@ class WebUIMessageHandler {
bool ExtractIntegerValue(const ListValue* value, int* out_int);
// Extract a string value from a list Value.
- std::wstring ExtractStringValue(const ListValue* value);
+ string16 ExtractStringValue(const ListValue* value);
WebUI* web_ui_;