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

Side by Side Diff: chrome/browser/devtools/devtools_ui_bindings.cc

Issue 887023002: [DevTools] DevToolsUIBindings::CallClientFunction - reduce number of string copyings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 | « no previous file | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/devtools/devtools_ui_bindings.h" 5 #include "chrome/browser/devtools/devtools_ui_bindings.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 } 861 }
862 862
863 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) { 863 bool DevToolsUIBindings::IsAttachedTo(content::DevToolsAgentHost* agent_host) {
864 return agent_host_.get() == agent_host; 864 return agent_host_.get() == agent_host;
865 } 865 }
866 866
867 void DevToolsUIBindings::CallClientFunction(const std::string& function_name, 867 void DevToolsUIBindings::CallClientFunction(const std::string& function_name,
868 const base::Value* arg1, 868 const base::Value* arg1,
869 const base::Value* arg2, 869 const base::Value* arg2,
870 const base::Value* arg3) { 870 const base::Value* arg3) {
871 std::string params; 871 std::string javascript = function_name + "(";
872 if (arg1) { 872 if (arg1) {
873 std::string json; 873 std::string json;
874 base::JSONWriter::Write(arg1, &json); 874 base::JSONWriter::Write(arg1, &json);
875 params.append(json); 875 javascript.append(json);
876 if (arg2) { 876 if (arg2) {
877 base::JSONWriter::Write(arg2, &json); 877 base::JSONWriter::Write(arg2, &json);
878 params.append(", " + json); 878 javascript.append(", ").append(json);
879 if (arg3) { 879 if (arg3) {
880 base::JSONWriter::Write(arg3, &json); 880 base::JSONWriter::Write(arg3, &json);
881 params.append(", " + json); 881 javascript.append(", ").append(json);
882 } 882 }
883 } 883 }
884 } 884 }
885 885 javascript.append(");");
886 base::string16 javascript = base::UTF8ToUTF16( 886 web_contents_->GetMainFrame()->ExecuteJavaScript(
887 function_name + "(" + params + ");"); 887 base::UTF8ToUTF16(javascript));
888 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript);
889 } 888 }
890 889
891 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { 890 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() {
892 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event 891 // In the DEBUG_DEVTOOLS mode, the DocumentOnLoadCompletedInMainFrame event
893 // arrives before the LoadCompleted event, thus it should not trigger the 892 // arrives before the LoadCompleted event, thus it should not trigger the
894 // frontend load handling. 893 // frontend load handling.
895 #if !defined(DEBUG_DEVTOOLS) 894 #if !defined(DEBUG_DEVTOOLS)
896 FrontendLoaded(); 895 FrontendLoaded();
897 #endif 896 #endif
898 } 897 }
899 898
900 void DevToolsUIBindings::DidNavigateMainFrame() { 899 void DevToolsUIBindings::DidNavigateMainFrame() {
901 frontend_loaded_ = false; 900 frontend_loaded_ = false;
902 } 901 }
903 902
904 void DevToolsUIBindings::FrontendLoaded() { 903 void DevToolsUIBindings::FrontendLoaded() {
905 if (frontend_loaded_) 904 if (frontend_loaded_)
906 return; 905 return;
907 frontend_loaded_ = true; 906 frontend_loaded_ = true;
908 907
909 // Call delegate first - it seeds importants bit of information. 908 // Call delegate first - it seeds importants bit of information.
910 delegate_->OnLoadCompleted(); 909 delegate_->OnLoadCompleted();
911 910
912 UpdateTheme(); 911 UpdateTheme();
913 AddDevToolsExtensionsToClient(); 912 AddDevToolsExtensionsToClient();
914 } 913 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698