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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/common/extensions/extension_messages.h" | 8 #include "chrome/common/extensions/extension_messages.h" |
9 #include "chrome/common/extensions/message_bundle.h" | 9 #include "chrome/common/extensions/message_bundle.h" |
10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 *GetExtensionToL10nMessagesMap(); | 54 *GetExtensionToL10nMessagesMap(); |
55 l10n_messages_map[extension_id] = messages; | 55 l10n_messages_map[extension_id] = messages; |
56 | 56 |
57 l10n_messages = GetL10nMessagesMap(extension_id); | 57 l10n_messages = GetL10nMessagesMap(extension_id); |
58 } | 58 } |
59 | 59 |
60 std::string message_name = *v8::String::Utf8Value(args[0]); | 60 std::string message_name = *v8::String::Utf8Value(args[0]); |
61 std::string message = | 61 std::string message = |
62 MessageBundle::GetL10nMessage(message_name, *l10n_messages); | 62 MessageBundle::GetL10nMessage(message_name, *l10n_messages); |
63 | 63 |
| 64 v8::Isolate* isolate = args.GetIsolate(); |
64 std::vector<std::string> substitutions; | 65 std::vector<std::string> substitutions; |
65 if (args[1]->IsArray()) { | 66 if (args[1]->IsArray()) { |
66 // chrome.i18n.getMessage("message_name", ["more", "params"]); | 67 // chrome.i18n.getMessage("message_name", ["more", "params"]); |
67 v8::Local<v8::Array> placeholders = v8::Local<v8::Array>::Cast(args[1]); | 68 v8::Local<v8::Array> placeholders = v8::Local<v8::Array>::Cast(args[1]); |
68 uint32_t count = placeholders->Length(); | 69 uint32_t count = placeholders->Length(); |
69 if (count > 9) | 70 if (count > 9) |
70 return; | 71 return; |
71 for (uint32_t i = 0; i < count; ++i) { | 72 for (uint32_t i = 0; i < count; ++i) { |
72 substitutions.push_back( | 73 substitutions.push_back( |
73 *v8::String::Utf8Value( | 74 *v8::String::Utf8Value( |
74 placeholders->Get(v8::Integer::New(i))->ToString())); | 75 placeholders->Get(v8::Integer::New(isolate, i))->ToString())); |
75 } | 76 } |
76 } else if (args[1]->IsString()) { | 77 } else if (args[1]->IsString()) { |
77 // chrome.i18n.getMessage("message_name", "one param"); | 78 // chrome.i18n.getMessage("message_name", "one param"); |
78 substitutions.push_back(*v8::String::Utf8Value(args[1]->ToString())); | 79 substitutions.push_back(*v8::String::Utf8Value(args[1]->ToString())); |
79 } | 80 } |
80 | 81 |
81 args.GetReturnValue().Set( | 82 args.GetReturnValue().Set( |
82 v8::String::NewFromUtf8(args.GetIsolate(), ReplaceStringPlaceholders( | 83 v8::String::NewFromUtf8(isolate, ReplaceStringPlaceholders( |
83 message, substitutions, NULL).c_str())); | 84 message, substitutions, NULL).c_str())); |
84 } | 85 } |
85 | 86 |
86 } // namespace extensions | 87 } // namespace extensions |
OLD | NEW |