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

Side by Side Diff: content/browser/webui/web_ui_impl.cc

Issue 2695873002: Prevent some string copies when sending Values to WebUI. (Closed)
Patch Set: Removed another copy Created 3 years, 10 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
« no previous file with comments | « base/json/json_writer.h ('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) 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 "content/browser/webui/web_ui_impl.h" 5 #include "content/browser/webui/web_ui_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/debug/dump_without_crashing.h" 9 #include "base/debug/dump_without_crashing.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 WebUIImpl* web_ui_; 49 WebUIImpl* web_ui_;
50 }; 50 };
51 51
52 const WebUI::TypeID WebUI::kNoWebUI = NULL; 52 const WebUI::TypeID WebUI::kNoWebUI = NULL;
53 53
54 // static 54 // static
55 base::string16 WebUI::GetJavascriptCall( 55 base::string16 WebUI::GetJavascriptCall(
56 const std::string& function_name, 56 const std::string& function_name,
57 const std::vector<const base::Value*>& arg_list) { 57 const std::vector<const base::Value*>& arg_list) {
58 base::string16 parameters; 58 base::string16 result(base::ASCIIToUTF16(function_name));
59 result.push_back('(');
60
59 std::string json; 61 std::string json;
60 for (size_t i = 0; i < arg_list.size(); ++i) { 62 for (size_t i = 0; i < arg_list.size(); ++i) {
61 if (i > 0) 63 if (i > 0)
62 parameters += base::char16(','); 64 result.push_back(',');
63 65
64 base::JSONWriter::Write(*arg_list[i], &json); 66 base::JSONWriter::Write(*arg_list[i], &json);
65 parameters += base::UTF8ToUTF16(json); 67 result.append(base::UTF8ToUTF16(json));
66 } 68 }
67 return base::ASCIIToUTF16(function_name) + 69
68 base::char16('(') + parameters + base::char16(')') + base::char16(';'); 70 result.push_back(')');
71 result.push_back(';');
72 return result;
69 } 73 }
70 74
71 WebUIImpl::WebUIImpl(WebContents* contents, const std::string& frame_name) 75 WebUIImpl::WebUIImpl(WebContents* contents, const std::string& frame_name)
72 : bindings_(BINDINGS_POLICY_WEB_UI), 76 : bindings_(BINDINGS_POLICY_WEB_UI),
73 web_contents_(contents), 77 web_contents_(contents),
74 web_contents_observer_(new MainFrameNavigationObserver(this, contents)), 78 web_contents_observer_(new MainFrameNavigationObserver(this, contents)),
75 frame_name_(frame_name) { 79 frame_name_(frame_name) {
76 DCHECK(contents); 80 DCHECK(contents);
77 } 81 }
78 82
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 if (host->GetFrameName() == frame_name_) 298 if (host->GetFrameName() == frame_name_)
295 frame_set->insert(host); 299 frame_set->insert(host);
296 } 300 }
297 301
298 void WebUIImpl::DisallowJavascriptOnAllHandlers() { 302 void WebUIImpl::DisallowJavascriptOnAllHandlers() {
299 for (const std::unique_ptr<WebUIMessageHandler>& handler : handlers_) 303 for (const std::unique_ptr<WebUIMessageHandler>& handler : handlers_)
300 handler->DisallowJavascript(); 304 handler->DisallowJavascript();
301 } 305 }
302 306
303 } // namespace content 307 } // namespace content
OLDNEW
« no previous file with comments | « base/json/json_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698