Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: chrome/renderer/extensions/i18n_custom_bindings.cc

Issue 10544066: Double dollar ($$) parsing in messages.json broken (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/extension_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"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ExtensionMessageBundle::GetL10nMessage(message_name, *l10n_messages);
61 61
62 std::vector<std::string> substitutions; 62 std::vector<std::string> substitutions;
63 if (args[1]->IsNull() || args[1]->IsUndefined()) { 63 if (args[1]->IsArray()) {
64 // chrome.i18n.getMessage("message_name");
65 // chrome.i18n.getMessage("message_name", null);
66 return v8::String::New(message.c_str());
67 } else if (args[1]->IsArray()) {
68 // chrome.i18n.getMessage("message_name", ["more", "params"]); 64 // chrome.i18n.getMessage("message_name", ["more", "params"]);
69 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]);
70 uint32_t count = placeholders->Length(); 66 uint32_t count = placeholders->Length();
71 if (count > 9) 67 if (count > 9)
72 return v8::Undefined(); 68 return v8::Undefined();
73 for (uint32_t i = 0; i < count; ++i) { 69 for (uint32_t i = 0; i < count; ++i) {
74 substitutions.push_back( 70 substitutions.push_back(
75 *v8::String::Utf8Value( 71 *v8::String::Utf8Value(
76 placeholders->Get(v8::Integer::New(i))->ToString())); 72 placeholders->Get(v8::Integer::New(i))->ToString()));
77 } 73 }
78 } else { 74 } else if (args[1]->IsString()) {
79 // chrome.i18n.getMessage("message_name", "one param"); 75 // chrome.i18n.getMessage("message_name", "one param");
80 substitutions.push_back(*v8::String::Utf8Value(args[1]->ToString())); 76 substitutions.push_back(*v8::String::Utf8Value(args[1]->ToString()));
81 } 77 }
82 78
83 return v8::String::New(ReplaceStringPlaceholders( 79 return v8::String::New(ReplaceStringPlaceholders(
84 message, substitutions, NULL).c_str()); 80 message, substitutions, NULL).c_str());
85 } 81 }
86 82
87 } // namespace extension 83 } // namespace extension
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698