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

Side by Side Diff: content/shell/browser/shell_devtools_frontend.cc

Issue 870883008: Test runner: make inspector tests reuse a single inspector process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for landing 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/shell/browser/shell_devtools_frontend.h" 5 #include "content/shell/browser/shell_devtools_frontend.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/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 void ShellDevToolsFrontend::Activate() { 54 void ShellDevToolsFrontend::Activate() {
55 frontend_shell_->ActivateContents(web_contents()); 55 frontend_shell_->ActivateContents(web_contents());
56 } 56 }
57 57
58 void ShellDevToolsFrontend::Focus() { 58 void ShellDevToolsFrontend::Focus() {
59 web_contents()->Focus(); 59 web_contents()->Focus();
60 } 60 }
61 61
62 void ShellDevToolsFrontend::InspectElementAt(int x, int y) { 62 void ShellDevToolsFrontend::InspectElementAt(int x, int y) {
63 agent_host_->InspectElement(x, y); 63 if (agent_host_)
64 agent_host_->InspectElement(x, y);
64 } 65 }
65 66
66 void ShellDevToolsFrontend::Close() { 67 void ShellDevToolsFrontend::Close() {
67 frontend_shell_->Close(); 68 frontend_shell_->Close();
68 } 69 }
69 70
71 void ShellDevToolsFrontend::DisconnectFromTarget() {
72 if (!agent_host_)
73 return;
74 agent_host_->DetachClient();
75 agent_host_ = NULL;
76 }
77
70 ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell, 78 ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell,
71 DevToolsAgentHost* agent_host) 79 DevToolsAgentHost* agent_host)
72 : WebContentsObserver(frontend_shell->web_contents()), 80 : WebContentsObserver(frontend_shell->web_contents()),
73 frontend_shell_(frontend_shell), 81 frontend_shell_(frontend_shell),
74 agent_host_(agent_host) { 82 agent_host_(agent_host) {
75 } 83 }
76 84
77 ShellDevToolsFrontend::~ShellDevToolsFrontend() { 85 ShellDevToolsFrontend::~ShellDevToolsFrontend() {
78 } 86 }
79 87
80 void ShellDevToolsFrontend::RenderViewCreated( 88 void ShellDevToolsFrontend::RenderViewCreated(
81 RenderViewHost* render_view_host) { 89 RenderViewHost* render_view_host) {
82 if (!frontend_host_) { 90 if (!frontend_host_) {
83 frontend_host_.reset( 91 frontend_host_.reset(
84 DevToolsFrontendHost::Create(web_contents()->GetMainFrame(), this)); 92 DevToolsFrontendHost::Create(web_contents()->GetMainFrame(), this));
85 agent_host_->AttachClient(this);
86 } 93 }
87 } 94 }
88 95
96 void ShellDevToolsFrontend::DidNavigateMainFrame(
97 const LoadCommittedDetails& details,
98 const FrameNavigateParams& params) {
99 if (agent_host_)
100 agent_host_->AttachClient(this);
101 }
102
89 void ShellDevToolsFrontend::WebContentsDestroyed() { 103 void ShellDevToolsFrontend::WebContentsDestroyed() {
90 agent_host_->DetachClient(); 104 if (agent_host_)
105 agent_host_->DetachClient();
91 delete this; 106 delete this;
92 } 107 }
93 108
94 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend( 109 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
95 const std::string& message) { 110 const std::string& message) {
111 if (!agent_host_)
112 return;
96 std::string method; 113 std::string method;
97 int id = 0; 114 int id = 0;
98 base::ListValue* params = NULL; 115 base::ListValue* params = NULL;
99 base::DictionaryValue* dict = NULL; 116 base::DictionaryValue* dict = NULL;
100 scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message)); 117 scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
101 if (!parsed_message || 118 if (!parsed_message ||
102 !parsed_message->GetAsDictionary(&dict) || 119 !parsed_message->GetAsDictionary(&dict) ||
103 !dict->GetString("method", &method)) { 120 !dict->GetString("method", &method)) {
104 return; 121 return;
105 } 122 }
(...skipping 14 matching lines...) Expand all
120 if (id) { 137 if (id) {
121 std::string code = "DevToolsAPI.embedderMessageAck(" + 138 std::string code = "DevToolsAPI.embedderMessageAck(" +
122 base::IntToString(id) + ",\"\");"; 139 base::IntToString(id) + ",\"\");";
123 base::string16 javascript = base::UTF8ToUTF16(code); 140 base::string16 javascript = base::UTF8ToUTF16(code);
124 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); 141 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
125 } 142 }
126 } 143 }
127 144
128 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend( 145 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend(
129 const std::string& message) { 146 const std::string& message) {
130 agent_host_->DispatchProtocolMessage(message); 147 if (agent_host_)
148 agent_host_->DispatchProtocolMessage(message);
131 } 149 }
132 150
133 void ShellDevToolsFrontend::DispatchProtocolMessage( 151 void ShellDevToolsFrontend::DispatchProtocolMessage(
134 DevToolsAgentHost* agent_host, const std::string& message) { 152 DevToolsAgentHost* agent_host, const std::string& message) {
135 153
136 if (message.length() < kMaxMessageChunkSize) { 154 if (message.length() < kMaxMessageChunkSize) {
137 base::string16 javascript = base::UTF8ToUTF16( 155 base::string16 javascript = base::UTF8ToUTF16(
138 "DevToolsAPI.dispatchMessage(" + message + ");"); 156 "DevToolsAPI.dispatchMessage(" + message + ");");
139 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); 157 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
140 return; 158 return;
141 } 159 }
142 160
143 base::FundamentalValue total_size(static_cast<int>(message.length())); 161 base::FundamentalValue total_size(static_cast<int>(message.length()));
144 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { 162 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
145 base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); 163 base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize));
146 std::string param; 164 std::string param;
147 base::JSONWriter::Write(&message_value, &param); 165 base::JSONWriter::Write(&message_value, &param);
148 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");"; 166 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");";
149 base::string16 javascript = base::UTF8ToUTF16(code); 167 base::string16 javascript = base::UTF8ToUTF16(code);
150 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); 168 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
151 } 169 }
152 } 170 }
153 171
172 void ShellDevToolsFrontend::AttachTo(WebContents* inspected_contents) {
173 DisconnectFromTarget();
174 agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents);
175 }
176
154 void ShellDevToolsFrontend::AgentHostClosed( 177 void ShellDevToolsFrontend::AgentHostClosed(
155 DevToolsAgentHost* agent_host, bool replaced) { 178 DevToolsAgentHost* agent_host, bool replaced) {
156 frontend_shell_->Close(); 179 frontend_shell_->Close();
157 } 180 }
158 181
159 } // namespace content 182 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/browser/shell_devtools_frontend.h ('k') | content/shell/browser/webkit_test_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698