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

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

Issue 347019: Convert ReplaceStringPlaceholders(std::string...) to take a (Closed)
Patch Set: a Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_theme_source.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extension_process_bindings.h" 5 #include "chrome/renderer/extensions/extension_process_bindings.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 318
319 L10nMessagesMap* l10n_messages = 319 L10nMessagesMap* l10n_messages =
320 GetL10nMessagesMap(ExtensionIdForCurrentContext()); 320 GetL10nMessagesMap(ExtensionIdForCurrentContext());
321 if (!l10n_messages) 321 if (!l10n_messages)
322 return v8::Undefined(); 322 return v8::Undefined();
323 323
324 std::string message_name = *v8::String::AsciiValue(args[0]); 324 std::string message_name = *v8::String::AsciiValue(args[0]);
325 std::string message = 325 std::string message =
326 ExtensionMessageBundle::GetL10nMessage(message_name, *l10n_messages); 326 ExtensionMessageBundle::GetL10nMessage(message_name, *l10n_messages);
327 327
328 std::vector<string16> substitutions; 328 std::vector<std::string> substitutions;
329 if (args[1]->IsNull() || args[1]->IsUndefined()) { 329 if (args[1]->IsNull() || args[1]->IsUndefined()) {
330 // chrome.i18n.getMessage("message_name"); 330 // chrome.i18n.getMessage("message_name");
331 // chrome.i18n.getMessage("message_name", null); 331 // chrome.i18n.getMessage("message_name", null);
332 return v8::String::New(message.c_str()); 332 return v8::String::New(message.c_str());
333 } else if (args[1]->IsString()) { 333 } else if (args[1]->IsString()) {
334 // chrome.i18n.getMessage("message_name", "one param"); 334 // chrome.i18n.getMessage("message_name", "one param");
335 std::string substitute = *v8::String::Utf8Value(args[1]->ToString()); 335 std::string substitute = *v8::String::Utf8Value(args[1]->ToString());
336 substitutions.push_back(UTF8ToUTF16(substitute)); 336 substitutions.push_back(substitute);
337 } else if (args[1]->IsArray()) { 337 } else if (args[1]->IsArray()) {
338 // chrome.i18n.getMessage("message_name", ["more", "params"]); 338 // chrome.i18n.getMessage("message_name", ["more", "params"]);
339 v8::Array* placeholders = static_cast<v8::Array*>(*args[1]); 339 v8::Array* placeholders = static_cast<v8::Array*>(*args[1]);
340 uint32_t count = placeholders->Length(); 340 uint32_t count = placeholders->Length();
341 DCHECK(count > 0 && count <= 9); 341 DCHECK(count > 0 && count <= 9);
342 for (uint32_t i = 0; i < count; ++i) { 342 for (uint32_t i = 0; i < count; ++i) {
343 std::string substitute = 343 std::string substitute =
344 *v8::String::Utf8Value( 344 *v8::String::Utf8Value(
345 placeholders->Get(v8::Integer::New(i))->ToString()); 345 placeholders->Get(v8::Integer::New(i))->ToString());
346 substitutions.push_back(UTF8ToUTF16(substitute)); 346 substitutions.push_back(substitute);
347 } 347 }
348 } else { 348 } else {
349 NOTREACHED() << "Couldn't parse second parameter."; 349 NOTREACHED() << "Couldn't parse second parameter.";
350 return v8::Undefined(); 350 return v8::Undefined();
351 } 351 }
352 352
353 return v8::String::New(UTF16ToUTF8(ReplaceStringPlaceholders( 353 return v8::String::New(ReplaceStringPlaceholders(
354 UTF8ToUTF16(message), substitutions, NULL)).c_str()); 354 message, substitutions, NULL).c_str());
355 } 355 }
356 356
357 // Common code for starting an API request to the browser. |value_args| 357 // Common code for starting an API request to the browser. |value_args|
358 // contains the request's arguments. 358 // contains the request's arguments.
359 static v8::Handle<v8::Value> StartRequestCommon( 359 static v8::Handle<v8::Value> StartRequestCommon(
360 const v8::Arguments& args, Value* value_args) { 360 const v8::Arguments& args, Value* value_args) {
361 // Get the current RenderView so that we can send a routed IPC message from 361 // Get the current RenderView so that we can send a routed IPC message from
362 // the correct source. 362 // the correct source.
363 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); 363 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext();
364 if (!renderview) 364 if (!renderview)
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 return; 610 return;
611 611
612 v8::HandleScope handle_scope; 612 v8::HandleScope handle_scope;
613 WebFrame* frame = view->mainFrame(); 613 WebFrame* frame = view->mainFrame();
614 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); 614 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
615 v8::Handle<v8::Value> argv[1]; 615 v8::Handle<v8::Value> argv[1];
616 argv[0] = v8::String::New(type_str); 616 argv[0] = v8::String::New(type_str);
617 bindings_utils::CallFunctionInContext(context, "setViewType", 617 bindings_utils::CallFunctionInContext(context, "setViewType",
618 arraysize(argv), argv); 618 arraysize(argv), argv);
619 } 619 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_theme_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698