OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/i18n_custom_bindings.h" | 5 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
6 | 6 |
7 #include "chrome/common/extensions/extension_messages.h" | 7 #include "chrome/common/extensions/extension_messages.h" |
8 #include "chrome/common/extensions/extension_message_bundle.h" | 8 #include "chrome/common/extensions/message_bundle.h" |
9 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
10 #include "grit/renderer_resources.h" | 10 #include "grit/renderer_resources.h" |
11 #include "v8/include/v8.h" | 11 #include "v8/include/v8.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 I18NCustomBindings::I18NCustomBindings() | 15 I18NCustomBindings::I18NCustomBindings() |
16 : ChromeV8Extension(NULL) { | 16 : ChromeV8Extension(NULL) { |
17 RouteStaticFunction("GetL10nMessage", &GetL10nMessage); | 17 RouteStaticFunction("GetL10nMessage", &GetL10nMessage); |
18 } | 18 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // Save messages we got. | 50 // Save messages we got. |
51 ExtensionToL10nMessagesMap& l10n_messages_map = | 51 ExtensionToL10nMessagesMap& l10n_messages_map = |
52 *GetExtensionToL10nMessagesMap(); | 52 *GetExtensionToL10nMessagesMap(); |
53 l10n_messages_map[extension_id] = messages; | 53 l10n_messages_map[extension_id] = messages; |
54 | 54 |
55 l10n_messages = GetL10nMessagesMap(extension_id); | 55 l10n_messages = GetL10nMessagesMap(extension_id); |
56 } | 56 } |
57 | 57 |
58 std::string message_name = *v8::String::AsciiValue(args[0]); | 58 std::string message_name = *v8::String::AsciiValue(args[0]); |
59 std::string message = | 59 std::string message = |
60 ExtensionMessageBundle::GetL10nMessage(message_name, *l10n_messages); | 60 MessageBundle::GetL10nMessage(message_name, *l10n_messages); |
61 | 61 |
62 std::vector<std::string> substitutions; | 62 std::vector<std::string> substitutions; |
63 if (args[1]->IsArray()) { | 63 if (args[1]->IsArray()) { |
64 // chrome.i18n.getMessage("message_name", ["more", "params"]); | 64 // chrome.i18n.getMessage("message_name", ["more", "params"]); |
65 v8::Local<v8::Array> placeholders = v8::Local<v8::Array>::Cast(args[1]); | 65 v8::Local<v8::Array> placeholders = v8::Local<v8::Array>::Cast(args[1]); |
66 uint32_t count = placeholders->Length(); | 66 uint32_t count = placeholders->Length(); |
67 if (count > 9) | 67 if (count > 9) |
68 return v8::Undefined(); | 68 return v8::Undefined(); |
69 for (uint32_t i = 0; i < count; ++i) { | 69 for (uint32_t i = 0; i < count; ++i) { |
70 substitutions.push_back( | 70 substitutions.push_back( |
71 *v8::String::Utf8Value( | 71 *v8::String::Utf8Value( |
72 placeholders->Get(v8::Integer::New(i))->ToString())); | 72 placeholders->Get(v8::Integer::New(i))->ToString())); |
73 } | 73 } |
74 } else if (args[1]->IsString()) { | 74 } else if (args[1]->IsString()) { |
75 // chrome.i18n.getMessage("message_name", "one param"); | 75 // chrome.i18n.getMessage("message_name", "one param"); |
76 substitutions.push_back(*v8::String::Utf8Value(args[1]->ToString())); | 76 substitutions.push_back(*v8::String::Utf8Value(args[1]->ToString())); |
77 } | 77 } |
78 | 78 |
79 return v8::String::New(ReplaceStringPlaceholders( | 79 return v8::String::New(ReplaceStringPlaceholders( |
80 message, substitutions, NULL).c_str()); | 80 message, substitutions, NULL).c_str()); |
81 } | 81 } |
82 | 82 |
83 } // namespace extension | 83 } // namespace extension |
OLD | NEW |