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

Side by Side Diff: chrome/browser/extensions/api/debugger/debugger_api.cc

Issue 11826048: Revert 176015 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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
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 // Implements the Chrome Extensions Debugger API. 5 // Implements the Chrome Extensions Debugger API.
6 6
7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" 7 #include "chrome/browser/extensions/api/debugger/debugger_api.h"
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 ExtensionDevToolsClientHost(WebContents* web_contents, 97 ExtensionDevToolsClientHost(WebContents* web_contents,
98 const std::string& extension_id, 98 const std::string& extension_id,
99 const std::string& extension_name, 99 const std::string& extension_name,
100 int tab_id); 100 int tab_id);
101 101
102 ~ExtensionDevToolsClientHost(); 102 ~ExtensionDevToolsClientHost();
103 103
104 bool MatchesContentsAndExtensionId(WebContents* web_contents, 104 bool MatchesContentsAndExtensionId(WebContents* web_contents,
105 const std::string& extension_id); 105 const std::string& extension_id);
106 void Close(); 106 void Close();
107 void SendMessageToBackend(DebuggerSendCommandFunction* function, 107 void SendMessageToBackend(SendCommandDebuggerFunction* function,
108 const std::string& method, 108 const std::string& method,
109 SendCommand::Params::CommandParams* command_params); 109 SendCommand::Params::CommandParams* command_params);
110 110
111 // Marks connection as to-be-terminated by the user. 111 // Marks connection as to-be-terminated by the user.
112 void MarkAsDismissed(); 112 void MarkAsDismissed();
113 113
114 // DevToolsClientHost interface 114 // DevToolsClientHost interface
115 virtual void InspectedContentsClosing() OVERRIDE; 115 virtual void InspectedContentsClosing() OVERRIDE;
116 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; 116 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE;
117 virtual void ReplacedWithAnotherClient() OVERRIDE; 117 virtual void ReplacedWithAnotherClient() OVERRIDE;
118 118
119 private: 119 private:
120 void SendDetachedEvent(); 120 void SendDetachedEvent();
121 121
122 // content::NotificationObserver implementation. 122 // content::NotificationObserver implementation.
123 virtual void Observe(int type, 123 virtual void Observe(int type,
124 const content::NotificationSource& source, 124 const content::NotificationSource& source,
125 const content::NotificationDetails& details); 125 const content::NotificationDetails& details);
126 126
127 WebContents* web_contents_; 127 WebContents* web_contents_;
128 std::string extension_id_; 128 std::string extension_id_;
129 int tab_id_; 129 int tab_id_;
130 content::NotificationRegistrar registrar_; 130 content::NotificationRegistrar registrar_;
131 int last_request_id_; 131 int last_request_id_;
132 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > 132 typedef std::map<int, scoped_refptr<SendCommandDebuggerFunction> >
133 PendingRequests; 133 PendingRequests;
134 PendingRequests pending_requests_; 134 PendingRequests pending_requests_;
135 ExtensionDevToolsInfoBarDelegate* infobar_delegate_; 135 ExtensionDevToolsInfoBarDelegate* infobar_delegate_;
136 OnDetach::Reason detach_reason_; 136 OnDetach::Reason detach_reason_;
137 137
138 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); 138 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost);
139 }; 139 };
140 140
141 namespace { 141 namespace {
142 142
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 void ExtensionDevToolsClientHost::ReplacedWithAnotherClient() { 242 void ExtensionDevToolsClientHost::ReplacedWithAnotherClient() {
243 detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS; 243 detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS;
244 } 244 }
245 245
246 void ExtensionDevToolsClientHost::Close() { 246 void ExtensionDevToolsClientHost::Close() {
247 DevToolsManager::GetInstance()->ClientHostClosing(this); 247 DevToolsManager::GetInstance()->ClientHostClosing(this);
248 delete this; 248 delete this;
249 } 249 }
250 250
251 void ExtensionDevToolsClientHost::SendMessageToBackend( 251 void ExtensionDevToolsClientHost::SendMessageToBackend(
252 DebuggerSendCommandFunction* function, 252 SendCommandDebuggerFunction* function,
253 const std::string& method, 253 const std::string& method,
254 SendCommand::Params::CommandParams* command_params) { 254 SendCommand::Params::CommandParams* command_params) {
255 DictionaryValue protocol_request; 255 DictionaryValue protocol_request;
256 int request_id = ++last_request_id_; 256 int request_id = ++last_request_id_;
257 pending_requests_[request_id] = function; 257 pending_requests_[request_id] = function;
258 protocol_request.SetInteger("id", request_id); 258 protocol_request.SetInteger("id", request_id);
259 protocol_request.SetString("method", method); 259 protocol_request.SetString("method", method);
260 if (command_params) { 260 if (command_params) {
261 protocol_request.Set("params", 261 protocol_request.Set("params",
262 command_params->additional_properties.DeepCopy()); 262 command_params->additional_properties.DeepCopy());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 if (dictionary->GetDictionary("params", &params_value)) 336 if (dictionary->GetDictionary("params", &params_value))
337 params.additional_properties.Swap(params_value); 337 params.additional_properties.Swap(params_value);
338 338
339 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params)); 339 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params));
340 scoped_ptr<extensions::Event> event(new extensions::Event( 340 scoped_ptr<extensions::Event> event(new extensions::Event(
341 keys::kOnEvent, args.Pass())); 341 keys::kOnEvent, args.Pass()));
342 event->restrict_to_profile = profile; 342 event->restrict_to_profile = profile;
343 extensions::ExtensionSystem::Get(profile)->event_router()-> 343 extensions::ExtensionSystem::Get(profile)->event_router()->
344 DispatchEventToExtension(extension_id_, event.Pass()); 344 DispatchEventToExtension(extension_id_, event.Pass());
345 } else { 345 } else {
346 DebuggerSendCommandFunction* function = pending_requests_[id]; 346 SendCommandDebuggerFunction* function = pending_requests_[id];
347 if (!function) 347 if (!function)
348 return; 348 return;
349 349
350 function->SendResponseBody(dictionary); 350 function->SendResponseBody(dictionary);
351 pending_requests_.erase(id); 351 pending_requests_.erase(id);
352 } 352 }
353 } 353 }
354 354
355 // static 355 // static
356 ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create( 356 ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 !client_host_->MatchesContentsAndExtensionId(contents_, 450 !client_host_->MatchesContentsAndExtensionId(contents_,
451 GetExtension()->id())) { 451 GetExtension()->id())) {
452 error_ = ErrorUtils::FormatErrorMessage( 452 error_ = ErrorUtils::FormatErrorMessage(
453 keys::kNotAttachedError, 453 keys::kNotAttachedError,
454 base::IntToString(tab_id_)); 454 base::IntToString(tab_id_));
455 return false; 455 return false;
456 } 456 }
457 return true; 457 return true;
458 } 458 }
459 459
460 DebuggerAttachFunction::DebuggerAttachFunction() {} 460 AttachDebuggerFunction::AttachDebuggerFunction() {}
461 461
462 DebuggerAttachFunction::~DebuggerAttachFunction() {} 462 AttachDebuggerFunction::~AttachDebuggerFunction() {}
463 463
464 bool DebuggerAttachFunction::RunImpl() { 464 bool AttachDebuggerFunction::RunImpl() {
465 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); 465 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_));
466 EXTENSION_FUNCTION_VALIDATE(params.get()); 466 EXTENSION_FUNCTION_VALIDATE(params.get());
467 467
468 tab_id_ = params->target.tab_id; 468 tab_id_ = params->target.tab_id;
469 if (!InitWebContents()) 469 if (!InitWebContents())
470 return false; 470 return false;
471 471
472 if (!webkit_glue::IsInspectorProtocolVersionSupported( 472 if (!webkit_glue::IsInspectorProtocolVersionSupported(
473 params->required_version)) { 473 params->required_version)) {
474 error_ = ErrorUtils::FormatErrorMessage( 474 error_ = ErrorUtils::FormatErrorMessage(
(...skipping 15 matching lines...) Expand all
490 } 490 }
491 491
492 new ExtensionDevToolsClientHost(contents_, 492 new ExtensionDevToolsClientHost(contents_,
493 GetExtension()->id(), 493 GetExtension()->id(),
494 GetExtension()->name(), 494 GetExtension()->name(),
495 tab_id_); 495 tab_id_);
496 SendResponse(true); 496 SendResponse(true);
497 return true; 497 return true;
498 } 498 }
499 499
500 DebuggerDetachFunction::DebuggerDetachFunction() {} 500 DetachDebuggerFunction::DetachDebuggerFunction() {}
501 501
502 DebuggerDetachFunction::~DebuggerDetachFunction() {} 502 DetachDebuggerFunction::~DetachDebuggerFunction() {}
503 503
504 bool DebuggerDetachFunction::RunImpl() { 504 bool DetachDebuggerFunction::RunImpl() {
505 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); 505 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_));
506 EXTENSION_FUNCTION_VALIDATE(params.get()); 506 EXTENSION_FUNCTION_VALIDATE(params.get());
507 507
508 tab_id_ = params->target.tab_id; 508 tab_id_ = params->target.tab_id;
509 if (!InitClientHost()) 509 if (!InitClientHost())
510 return false; 510 return false;
511 511
512 client_host_->Close(); 512 client_host_->Close();
513 SendResponse(true); 513 SendResponse(true);
514 return true; 514 return true;
515 } 515 }
516 516
517 DebuggerSendCommandFunction::DebuggerSendCommandFunction() {} 517 SendCommandDebuggerFunction::SendCommandDebuggerFunction() {}
518 518
519 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() {} 519 SendCommandDebuggerFunction::~SendCommandDebuggerFunction() {}
520 520
521 bool DebuggerSendCommandFunction::RunImpl() { 521 bool SendCommandDebuggerFunction::RunImpl() {
522 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_)); 522 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_));
523 EXTENSION_FUNCTION_VALIDATE(params.get()); 523 EXTENSION_FUNCTION_VALIDATE(params.get());
524 524
525 tab_id_ = params->target.tab_id; 525 tab_id_ = params->target.tab_id;
526 if (!InitClientHost()) 526 if (!InitClientHost())
527 return false; 527 return false;
528 528
529 client_host_->SendMessageToBackend(this, params->method, 529 client_host_->SendMessageToBackend(this, params->method,
530 params->command_params.get()); 530 params->command_params.get());
531 return true; 531 return true;
532 } 532 }
533 533
534 void DebuggerSendCommandFunction::SendResponseBody( 534 void SendCommandDebuggerFunction::SendResponseBody(
535 DictionaryValue* response) { 535 DictionaryValue* response) {
536 Value* error_body; 536 Value* error_body;
537 if (response->Get("error", &error_body)) { 537 if (response->Get("error", &error_body)) {
538 base::JSONWriter::Write(error_body, &error_); 538 base::JSONWriter::Write(error_body, &error_);
539 SendResponse(false); 539 SendResponse(false);
540 return; 540 return;
541 } 541 }
542 542
543 DictionaryValue* result_body; 543 DictionaryValue* result_body;
544 SendCommand::Results::Result result; 544 SendCommand::Results::Result result;
545 if (response->GetDictionary("result", &result_body)) 545 if (response->GetDictionary("result", &result_body))
546 result.additional_properties.Swap(result_body); 546 result.additional_properties.Swap(result_body);
547 547
548 results_ = SendCommand::Results::Create(result); 548 results_ = SendCommand::Results::Create(result);
549 SendResponse(true); 549 SendResponse(true);
550 } 550 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/debugger/debugger_api.h ('k') | chrome/browser/extensions/api/declarative/declarative_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698