| OLD | NEW |
| 1 // Copyright (c) 2009 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/browser/dom_ui/dom_ui.h" | 5 #include "chrome/browser/dom_ui/dom_ui.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 dom_ui_ = dom_ui; | 110 dom_ui_ = dom_ui; |
| 111 RegisterMessages(); | 111 RegisterMessages(); |
| 112 return this; | 112 return this; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // DOMMessageHandler, protected: ---------------------------------------------- | 115 // DOMMessageHandler, protected: ---------------------------------------------- |
| 116 | 116 |
| 117 void DOMMessageHandler::SetURLAndTitle(DictionaryValue* dictionary, | 117 void DOMMessageHandler::SetURLAndTitle(DictionaryValue* dictionary, |
| 118 string16 title, | 118 string16 title, |
| 119 const GURL& gurl) { | 119 const GURL& gurl) { |
| 120 string16 url16 = UTF8ToUTF16(gurl.spec()); | 120 dictionary->SetString("url", gurl.spec()); |
| 121 dictionary->SetStringFromUTF16(L"url", url16); | |
| 122 | 121 |
| 123 bool using_url_as_the_title = false; | 122 bool using_url_as_the_title = false; |
| 124 if (title.empty()) { | 123 if (title.empty()) { |
| 125 using_url_as_the_title = true; | 124 using_url_as_the_title = true; |
| 126 title = url16; | 125 title = UTF8ToUTF16(gurl.spec()); |
| 127 } | 126 } |
| 128 | 127 |
| 129 // Since the title can contain BiDi text, we need to mark the text as either | 128 // Since the title can contain BiDi text, we need to mark the text as either |
| 130 // RTL or LTR, depending on the characters in the string. If we use the URL | 129 // RTL or LTR, depending on the characters in the string. If we use the URL |
| 131 // as the title, we mark the title as LTR since URLs are always treated as | 130 // as the title, we mark the title as LTR since URLs are always treated as |
| 132 // left to right strings. | 131 // left to right strings. |
| 133 string16 title_to_set(title); | 132 string16 title_to_set(title); |
| 134 if (base::i18n::IsRTL()) { | 133 if (base::i18n::IsRTL()) { |
| 135 if (using_url_as_the_title) { | 134 if (using_url_as_the_title) { |
| 136 base::i18n::WrapStringWithLTRFormatting(&title_to_set); | 135 base::i18n::WrapStringWithLTRFormatting(&title_to_set); |
| 137 } else { | 136 } else { |
| 138 bool success = | 137 bool success = |
| 139 base::i18n::AdjustStringForLocaleDirection(title, &title_to_set); | 138 base::i18n::AdjustStringForLocaleDirection(title, &title_to_set); |
| 140 DCHECK(success ? (title != title_to_set) : (title == title_to_set)); | 139 DCHECK(success ? (title != title_to_set) : (title == title_to_set)); |
| 141 } | 140 } |
| 142 } | 141 } |
| 143 dictionary->SetStringFromUTF16(L"title", title_to_set); | 142 dictionary->SetString("title", title_to_set); |
| 144 } | 143 } |
| 145 | 144 |
| 146 bool DOMMessageHandler::ExtractIntegerValue(const Value* value, int* out_int) { | 145 bool DOMMessageHandler::ExtractIntegerValue(const Value* value, int* out_int) { |
| 147 if (value && value->GetType() == Value::TYPE_LIST) { | 146 if (value && value->GetType() == Value::TYPE_LIST) { |
| 148 const ListValue* list_value = static_cast<const ListValue*>(value); | 147 const ListValue* list_value = static_cast<const ListValue*>(value); |
| 149 std::string string_value; | 148 std::string string_value; |
| 150 if (list_value->GetString(0, &string_value)) { | 149 if (list_value->GetString(0, &string_value)) { |
| 151 base::StringToInt(string_value, out_int); | 150 base::StringToInt(string_value, out_int); |
| 152 return true; | 151 return true; |
| 153 } | 152 } |
| 154 } | 153 } |
| 155 return false; | 154 return false; |
| 156 } | 155 } |
| 157 | 156 |
| 158 std::wstring DOMMessageHandler::ExtractStringValue(const Value* value) { | 157 std::wstring DOMMessageHandler::ExtractStringValue(const Value* value) { |
| 159 if (value && value->GetType() == Value::TYPE_LIST) { | 158 if (value && value->GetType() == Value::TYPE_LIST) { |
| 160 const ListValue* list_value = static_cast<const ListValue*>(value); | 159 const ListValue* list_value = static_cast<const ListValue*>(value); |
| 161 std::wstring wstring_value; | 160 std::wstring wstring_value; |
| 162 if (list_value->GetString(0, &wstring_value)) | 161 if (list_value->GetString(0, &wstring_value)) |
| 163 return wstring_value; | 162 return wstring_value; |
| 164 } | 163 } |
| 165 return std::wstring(); | 164 return std::wstring(); |
| 166 } | 165 } |
| OLD | NEW |