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

Side by Side Diff: chrome/browser/debugger/debugger_shell.cc

Issue 27365: Add a command line flag --v8-proxy-resolver, to select the new PAC implementa... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address wtc's comments Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/net/chrome_url_request_context.cc » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/debugger/debugger_shell.h" 5 #include "chrome/browser/debugger/debugger_shell.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 17 matching lines...) Expand all
28 #endif 28 #endif
29 29
30 DebuggerShell::DebuggerShell(DebuggerInputOutput* io) : io_(io), 30 DebuggerShell::DebuggerShell(DebuggerInputOutput* io) : io_(io),
31 debugger_ready_(true) { 31 debugger_ready_(true) {
32 } 32 }
33 33
34 DebuggerShell::~DebuggerShell() { 34 DebuggerShell::~DebuggerShell() {
35 io_->Stop(); 35 io_->Stop();
36 io_ = NULL; 36 io_ = NULL;
37 37
38 v8::Locker locked;
38 v8::HandleScope scope; 39 v8::HandleScope scope;
39 SubshellFunction("exit", 0, NULL); 40 SubshellFunction("exit", 0, NULL);
40 v8::V8::RemoveMessageListeners(&DelegateMessageListener); 41 v8::V8::RemoveMessageListeners(&DelegateMessageListener);
41 v8_this_.Dispose(); 42 v8_this_.Dispose();
42 v8_context_.Dispose(); 43 v8_context_.Dispose();
43 shell_.Dispose(); 44 shell_.Dispose();
44 } 45 }
45 46
46 void DebuggerShell::Start() { 47 void DebuggerShell::Start() {
47 io_->Start(this); 48 io_->Start(this);
48 49
50 v8::Locker locked;
49 v8::HandleScope scope; 51 v8::HandleScope scope;
50 52
51 v8_this_ = v8::Persistent<v8::External>::New(v8::External::New(this)); 53 v8_this_ = v8::Persistent<v8::External>::New(v8::External::New(this));
52 54
53 v8::V8::AddMessageListener(&DelegateMessageListener, v8_this_); 55 v8::V8::AddMessageListener(&DelegateMessageListener, v8_this_);
54 56
55 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 57 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
56 58
57 // shell function 59 // shell function
58 v8::Local<v8::FunctionTemplate> shell_template = 60 v8::Local<v8::FunctionTemplate> shell_template =
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 188 }
187 189
188 void DebuggerShell::DelegateMessageListener(v8::Handle<v8::Message> message, 190 void DebuggerShell::DelegateMessageListener(v8::Handle<v8::Message> message,
189 v8::Handle<v8::Value> data) { 191 v8::Handle<v8::Value> data) {
190 DCHECK(!data.IsEmpty()); 192 DCHECK(!data.IsEmpty());
191 DebuggerShell* debugger = 193 DebuggerShell* debugger =
192 static_cast<DebuggerShell*>(v8::External::Cast(*data)->Value()); 194 static_cast<DebuggerShell*>(v8::External::Cast(*data)->Value());
193 debugger->MessageListener(message); 195 debugger->MessageListener(message);
194 } 196 }
195 197
196 void DebuggerShell::MessageListener(v8::Handle<v8::Message> message) { 198 void DebuggerShell::MessageListener(v8::Handle<v8::Message> message) {
Erik does not do reviews 2009/03/03 17:20:09 Since there can only be one message listener, I as
197 v8::HandleScope scope; 199 v8::HandleScope scope;
198 v8::Local<v8::String> msg_str = message->Get(); 200 v8::Local<v8::String> msg_str = message->Get();
199 PrintObject(msg_str); 201 PrintObject(msg_str);
200 202
201 v8::Handle<v8::Value> data = message->GetScriptResourceName(); 203 v8::Handle<v8::Value> data = message->GetScriptResourceName();
202 if (!data.IsEmpty() && !data->IsUndefined()) { 204 if (!data.IsEmpty() && !data->IsUndefined()) {
203 std::wstring out; 205 std::wstring out;
204 ObjectToString(data, &out); 206 ObjectToString(data, &out);
205 int line_number = message->GetLineNumber(); 207 int line_number = message->GetLineNumber();
206 if (line_number >= 0) 208 if (line_number >= 0)
207 out += StringPrintf(L":%d", line_number); 209 out += StringPrintf(L":%d", line_number);
208 PrintLine(out); 210 PrintLine(out);
209 data = message->GetSourceLine(); 211 data = message->GetSourceLine();
210 if (!data->IsUndefined()) { 212 if (!data->IsUndefined()) {
211 ObjectToString(data, &out); 213 ObjectToString(data, &out);
212 PrintLine(out); 214 PrintLine(out);
213 } 215 }
214 } 216 }
215 } 217 }
216 218
217 void DebuggerShell::Debug(TabContents* tab) { 219 void DebuggerShell::Debug(TabContents* tab) {
220 v8::Locker locked;
218 v8::HandleScope outer; 221 v8::HandleScope outer;
219 v8::Context::Scope scope(v8_context_); 222 v8::Context::Scope scope(v8_context_);
220 223
221 v8::Local<v8::Object> global = v8_context_->Global(); 224 v8::Local<v8::Object> global = v8_context_->Global();
222 v8::Local<v8::Value> function = global->Get(v8::String::New("debug")); 225 v8::Local<v8::Value> function = global->Get(v8::String::New("debug"));
223 if (function->IsFunction()) { 226 if (function->IsFunction()) {
224 TabNode* node = new TabNode(tab); 227 TabNode* node = new TabNode(tab);
225 v8::Handle<v8::Value> argv[] = {node->NewInstance()}; 228 v8::Handle<v8::Value> argv[] = {node->NewInstance()};
226 PrintObject(v8::Function::Cast(*function)->Call(global, 1, argv)); 229 PrintObject(v8::Function::Cast(*function)->Call(global, 1, argv));
227 } 230 }
228 } 231 }
229 232
230 void DebuggerShell::DebugMessage(const std::wstring& msg) { 233 void DebuggerShell::DebugMessage(const std::wstring& msg) {
234 v8::Locker locked;
231 v8::HandleScope scope; 235 v8::HandleScope scope;
232 236
233 if (msg.length()) { 237 if (msg.length()) {
234 if ((msg[0] == L'{' || msg[0] == L'[' || msg[0] == L'(') && (!shell_.IsEmpty ())) { 238 if ((msg[0] == L'{' || msg[0] == L'[' || msg[0] == L'(') && (!shell_.IsEmpty ())) {
235 // v8's wide String constructor requires uint16 rather than wchar 239 // v8's wide String constructor requires uint16 rather than wchar
236 const uint16* data = reinterpret_cast<const uint16* >(msg.c_str()); 240 const uint16* data = reinterpret_cast<const uint16* >(msg.c_str());
237 v8::Handle<v8::Value> argv[] = {v8::String::New(data)}; 241 v8::Handle<v8::Value> argv[] = {v8::String::New(data)};
238 PrintObject(SubshellFunction("response", 1, argv)); 242 PrintObject(SubshellFunction("response", 1, argv));
239 PrintPrompt(); 243 PrintPrompt();
240 } else { 244 } else {
241 if (msg[msg.length() - 1] == L'\n') 245 if (msg[msg.length() - 1] == L'\n')
242 PrintString(msg); 246 PrintString(msg);
243 else 247 else
244 PrintLine(msg); 248 PrintLine(msg);
245 } 249 }
246 } 250 }
247 } 251 }
248 252
249 void DebuggerShell::OnDebugAttach() { 253 void DebuggerShell::OnDebugAttach() {
254 v8::Locker locked;
250 v8::HandleScope scope; 255 v8::HandleScope scope;
251 SubshellFunction("on_attach", 0, NULL); 256 SubshellFunction("on_attach", 0, NULL);
252 } 257 }
253 258
254 void DebuggerShell::OnDebugDisconnect() { 259 void DebuggerShell::OnDebugDisconnect() {
260 v8::Locker locked;
255 v8::HandleScope scope; 261 v8::HandleScope scope;
256 SubshellFunction("on_disconnect", 0, NULL); 262 SubshellFunction("on_disconnect", 0, NULL);
257 } 263 }
258 264
259 void DebuggerShell::ObjectToString(v8::Handle<v8::Value> result, std::wstring* s tr) { 265 void DebuggerShell::ObjectToString(v8::Handle<v8::Value> result, std::wstring* s tr) {
260 v8::HandleScope scope; 266 v8::HandleScope scope;
261 if (!result.IsEmpty() && !result->IsUndefined()) { 267 if (!result.IsEmpty() && !result->IsUndefined()) {
262 v8::Local<v8::String> str_obj = result->ToString(); 268 v8::Local<v8::String> str_obj = result->ToString();
263 if (!str_obj.IsEmpty()) { 269 if (!str_obj.IsEmpty()) {
264 int length = str_obj->Length(); 270 int length = str_obj->Length();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 void DebuggerShell::PrintLine(const std::string& out) { 322 void DebuggerShell::PrintLine(const std::string& out) {
317 if (io_) 323 if (io_)
318 io_->OutputLine(out); 324 io_->OutputLine(out);
319 } 325 }
320 326
321 void DebuggerShell::PrintPrompt() { 327 void DebuggerShell::PrintPrompt() {
322 std::wstring out = L"Chrome> "; 328 std::wstring out = L"Chrome> ";
323 if (!shell_.IsEmpty()) { 329 if (!shell_.IsEmpty()) {
324 if (!debugger_ready_) 330 if (!debugger_ready_)
325 return; 331 return;
332 v8::Locker locked;
326 v8::HandleScope outer; 333 v8::HandleScope outer;
327 v8::Handle<v8::Value> result = CompileAndRun("shell_.prompt()"); 334 v8::Handle<v8::Value> result = CompileAndRun("shell_.prompt()");
328 if (!result.IsEmpty() && !result->IsUndefined()) { 335 if (!result.IsEmpty() && !result->IsUndefined()) {
329 ObjectToString(result, &out); 336 ObjectToString(result, &out);
330 } 337 }
331 } 338 }
332 if (io_) 339 if (io_)
333 io_->OutputPrompt(out); 340 io_->OutputPrompt(out);
334 } 341 }
335 342
336 void DebuggerShell::ProcessCommand(const std::wstring& data) { 343 void DebuggerShell::ProcessCommand(const std::wstring& data) {
344 v8::Locker locked;
337 v8::HandleScope outer; 345 v8::HandleScope outer;
338 v8::Context::Scope scope(v8_context_); 346 v8::Context::Scope scope(v8_context_);
339 if (!shell_.IsEmpty() && data.substr(0, 7) != L"source(") { 347 if (!shell_.IsEmpty() && data.substr(0, 7) != L"source(") {
340 if (data == L"exit") { 348 if (data == L"exit") {
341 PrintObject(SubshellFunction("exit", 0, NULL)); 349 PrintObject(SubshellFunction("exit", 0, NULL));
342 v8_context_->Global()->Delete(v8::String::New("shell_")); 350 v8_context_->Global()->Delete(v8::String::New("shell_"));
343 shell_.Dispose(); 351 shell_.Dispose();
344 shell_.Clear(); 352 shell_.Clear();
345 } else { 353 } else {
346 const uint16* utf16 = reinterpret_cast<const uint16*>(data.c_str()); 354 const uint16* utf16 = reinterpret_cast<const uint16*>(data.c_str());
(...skipping 21 matching lines...) Expand all
368 } 376 }
369 377
370 void DebuggerShell::LoadUserConfig() { 378 void DebuggerShell::LoadUserConfig() {
371 std::wstring path; 379 std::wstring path;
372 PathService::Get(chrome::DIR_USER_DATA, &path); 380 PathService::Get(chrome::DIR_USER_DATA, &path);
373 file_util::AppendToPath(&path, L"debugger_custom.js"); 381 file_util::AppendToPath(&path, L"debugger_custom.js");
374 LoadFile(path); 382 LoadFile(path);
375 } 383 }
376 384
377 void DebuggerShell::DidConnect() { 385 void DebuggerShell::DidConnect() {
386 v8::Locker locked;
378 v8::HandleScope outer; 387 v8::HandleScope outer;
379 v8::Context::Scope scope(v8_context_); 388 v8::Context::Scope scope(v8_context_);
380 389
381 LoadUserConfig(); 390 LoadUserConfig();
382 391
383 PrintPrompt(); 392 PrintPrompt();
384 } 393 }
385 394
386 void DebuggerShell::DidDisconnect() { 395 void DebuggerShell::DidDisconnect() {
396 v8::Locker locked;
387 v8::HandleScope outer; 397 v8::HandleScope outer;
388 SubshellFunction("exit", 0, NULL); 398 SubshellFunction("exit", 0, NULL);
389 } 399 }
390 400
391 v8::Handle<v8::Value> DebuggerShell::CompileAndRun( 401 v8::Handle<v8::Value> DebuggerShell::CompileAndRun(
392 const std::string& str, 402 const std::string& str,
393 const std::string& filename) { 403 const std::string& filename) {
394 const std::wstring wstr = UTF8ToWide(str); 404 const std::wstring wstr = UTF8ToWide(str);
395 return CompileAndRun(wstr, filename); 405 return CompileAndRun(wstr, filename);
396 } 406 }
397 407
398 v8::Handle<v8::Value> DebuggerShell::CompileAndRun( 408 v8::Handle<v8::Value> DebuggerShell::CompileAndRun(
399 const std::wstring& wstr, 409 const std::wstring& wstr,
400 const std::string& filename) { 410 const std::string& filename) {
411 v8::Locker locked;
401 v8::Context::Scope scope(v8_context_); 412 v8::Context::Scope scope(v8_context_);
402 v8::Handle<v8::String> scriptname; 413 v8::Handle<v8::String> scriptname;
403 if (filename.length() > 0) { 414 if (filename.length() > 0) {
404 scriptname = v8::String::New(filename.c_str()); 415 scriptname = v8::String::New(filename.c_str());
405 } else { 416 } else {
406 scriptname = v8::String::New(""); 417 scriptname = v8::String::New("");
407 } 418 }
408 const uint16* utf16 = reinterpret_cast<const uint16*>(wstr.c_str()); 419 const uint16* utf16 = reinterpret_cast<const uint16*>(wstr.c_str());
409 v8::ScriptOrigin origin = v8::ScriptOrigin(scriptname); 420 v8::ScriptOrigin origin = v8::ScriptOrigin(scriptname);
410 v8::Local<v8::Script> code = 421 v8::Local<v8::Script> code =
411 v8::Script::Compile(v8::String::New(utf16), &origin); 422 v8::Script::Compile(v8::String::New(utf16), &origin);
412 if (!code.IsEmpty()) { 423 if (!code.IsEmpty()) {
413 v8::Local<v8::Value> result = code->Run(); 424 v8::Local<v8::Value> result = code->Run();
414 if (!result.IsEmpty()) { 425 if (!result.IsEmpty()) {
415 return result; 426 return result;
416 } 427 }
417 } 428 }
418 return v8::Undefined(); 429 return v8::Undefined();
419 } 430 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/chrome_url_request_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698