Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/browser/dom_ui/dom_ui.h" | 5 #include "chrome/browser/dom_ui/dom_ui.h" |
| 6 | 6 |
| 7 #include "base/json_reader.h" | 7 #include "base/json_reader.h" |
| 8 #include "base/json_writer.h" | 8 #include "base/json_writer.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/common/l10n_util.h" | 10 #include "chrome/common/l10n_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 // This probably indicates a programming error. | 40 // This probably indicates a programming error. |
| 41 NOTREACHED(); | 41 NOTREACHED(); |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Forward this message and content on. | 46 // Forward this message and content on. |
| 47 callback->second->Run(value.get()); | 47 callback->second->Run(value.get()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void DOMUI::CallJavascriptFunction(const std::wstring& function_name) { | |
| 51 std::wstring javascript = function_name + L"();"; | |
| 52 ExecuteJavascript(javascript); | |
| 53 } | |
| 54 | |
| 50 void DOMUI::CallJavascriptFunction(const std::wstring& function_name, | 55 void DOMUI::CallJavascriptFunction(const std::wstring& function_name, |
| 51 const Value& arg) { | 56 const Value& arg) { |
| 52 std::string json; | 57 std::string json; |
| 53 JSONWriter::Write(&arg, false, &json); | 58 JSONWriter::Write(&arg, false, &json); |
| 54 std::wstring javascript = function_name + L"(" + UTF8ToWide(json) + L");"; | 59 std::wstring javascript = function_name + L"(" + UTF8ToWide(json) + L");"; |
| 55 | 60 |
| 56 ExecuteJavascript(javascript); | 61 ExecuteJavascript(javascript); |
| 57 } | 62 } |
| 58 | 63 |
| 59 void DOMUI::CallJavascriptFunction( | 64 void DOMUI::CallJavascriptFunction( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { | 120 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { |
| 116 if (using_url_as_the_title) { | 121 if (using_url_as_the_title) { |
| 117 l10n_util::WrapStringWithLTRFormatting(&title_to_set); | 122 l10n_util::WrapStringWithLTRFormatting(&title_to_set); |
| 118 } else { | 123 } else { |
| 119 bool success = | 124 bool success = |
| 120 l10n_util::AdjustStringForLocaleDirection(title, &title_to_set); | 125 l10n_util::AdjustStringForLocaleDirection(title, &title_to_set); |
| 121 DCHECK(success ? (title != title_to_set) : (title == title_to_set)); | 126 DCHECK(success ? (title != title_to_set) : (title == title_to_set)); |
| 122 } | 127 } |
| 123 } | 128 } |
| 124 dictionary->SetString(L"title", title_to_set); | 129 dictionary->SetString(L"title", title_to_set); |
| 125 } | 130 } |
| 131 | |
| 132 int DOMMessageHandler::ExtractIntegerValue(const Value* value) { | |
| 133 if (value && value->GetType() == Value::TYPE_LIST) { | |
| 134 const ListValue* list_value = static_cast<const ListValue*>(value); | |
| 135 Value* list_member; | |
| 136 | |
| 137 // Get id. | |
| 138 if (list_value->Get(0, &list_member) && | |
| 139 list_member->GetType() == Value::TYPE_STRING) { | |
| 140 const StringValue* string_value = | |
| 141 static_cast<const StringValue*>(list_member); | |
| 142 std::wstring wstring_value; | |
| 143 string_value->GetAsString(&wstring_value); | |
| 144 return StringToInt(wstring_value); | |
| 145 } | |
| 146 } | |
| 147 return NULL; | |
|
Paul Godavari
2009/02/17 22:23:19
Nit: I think this should return some default value
| |
| 148 } | |
| 149 | |
| 150 std::wstring DOMMessageHandler::ExtractStringValue(const Value* value) { | |
| 151 if (value && value->GetType() == Value::TYPE_LIST) { | |
| 152 const ListValue* list_value = static_cast<const ListValue*>(value); | |
| 153 Value* list_member; | |
| 154 | |
| 155 // Get id. | |
| 156 if (list_value->Get(0, &list_member) && | |
| 157 list_member->GetType() == Value::TYPE_STRING) { | |
| 158 const StringValue* string_value = | |
| 159 static_cast<const StringValue*>(list_member); | |
| 160 std::wstring wstring_value; | |
| 161 string_value->GetAsString(&wstring_value); | |
| 162 return wstring_value; | |
| 163 } | |
| 164 } | |
| 165 return std::wstring(); | |
| 166 } | |
| 167 | |
| OLD | NEW |