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

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

Issue 11747025: Run the JSON Schema Compiler's bundle compilation on JSON files. Previously it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: restore missing registrations 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 ExtensionDevToolsClientHost(WebContents* web_contents, 90 ExtensionDevToolsClientHost(WebContents* web_contents,
91 const std::string& extension_id, 91 const std::string& extension_id,
92 const std::string& extension_name, 92 const std::string& extension_name,
93 int tab_id); 93 int tab_id);
94 94
95 ~ExtensionDevToolsClientHost(); 95 ~ExtensionDevToolsClientHost();
96 96
97 bool MatchesContentsAndExtensionId(WebContents* web_contents, 97 bool MatchesContentsAndExtensionId(WebContents* web_contents,
98 const std::string& extension_id); 98 const std::string& extension_id);
99 void Close(); 99 void Close();
100 void SendMessageToBackend(SendCommandDebuggerFunction* function, 100 void SendMessageToBackend(DebuggerSendCommandFunction* function,
101 const std::string& method, 101 const std::string& method,
102 SendCommand::Params::CommandParams* command_params); 102 SendCommand::Params::CommandParams* command_params);
103 103
104 // Marks connection as to-be-terminated by the user. 104 // Marks connection as to-be-terminated by the user.
105 void MarkAsDismissed(); 105 void MarkAsDismissed();
106 106
107 // DevToolsClientHost interface 107 // DevToolsClientHost interface
108 virtual void InspectedContentsClosing() OVERRIDE; 108 virtual void InspectedContentsClosing() OVERRIDE;
109 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; 109 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE;
110 virtual void ReplacedWithAnotherClient() OVERRIDE; 110 virtual void ReplacedWithAnotherClient() OVERRIDE;
111 111
112 private: 112 private:
113 void SendDetachedEvent(); 113 void SendDetachedEvent();
114 114
115 // content::NotificationObserver implementation. 115 // content::NotificationObserver implementation.
116 virtual void Observe(int type, 116 virtual void Observe(int type,
117 const content::NotificationSource& source, 117 const content::NotificationSource& source,
118 const content::NotificationDetails& details); 118 const content::NotificationDetails& details);
119 119
120 WebContents* web_contents_; 120 WebContents* web_contents_;
121 std::string extension_id_; 121 std::string extension_id_;
122 int tab_id_; 122 int tab_id_;
123 content::NotificationRegistrar registrar_; 123 content::NotificationRegistrar registrar_;
124 int last_request_id_; 124 int last_request_id_;
125 typedef std::map<int, scoped_refptr<SendCommandDebuggerFunction> > 125 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> >
126 PendingRequests; 126 PendingRequests;
127 PendingRequests pending_requests_; 127 PendingRequests pending_requests_;
128 ExtensionDevToolsInfoBarDelegate* infobar_delegate_; 128 ExtensionDevToolsInfoBarDelegate* infobar_delegate_;
129 OnDetach::Reason detach_reason_; 129 OnDetach::Reason detach_reason_;
130 130
131 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); 131 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost);
132 }; 132 };
133 133
134 namespace { 134 namespace {
135 135
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 void ExtensionDevToolsClientHost::ReplacedWithAnotherClient() { 237 void ExtensionDevToolsClientHost::ReplacedWithAnotherClient() {
238 detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS; 238 detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS;
239 } 239 }
240 240
241 void ExtensionDevToolsClientHost::Close() { 241 void ExtensionDevToolsClientHost::Close() {
242 DevToolsManager::GetInstance()->ClientHostClosing(this); 242 DevToolsManager::GetInstance()->ClientHostClosing(this);
243 delete this; 243 delete this;
244 } 244 }
245 245
246 void ExtensionDevToolsClientHost::SendMessageToBackend( 246 void ExtensionDevToolsClientHost::SendMessageToBackend(
247 SendCommandDebuggerFunction* function, 247 DebuggerSendCommandFunction* function,
248 const std::string& method, 248 const std::string& method,
249 SendCommand::Params::CommandParams* command_params) { 249 SendCommand::Params::CommandParams* command_params) {
250 DictionaryValue protocol_request; 250 DictionaryValue protocol_request;
251 int request_id = ++last_request_id_; 251 int request_id = ++last_request_id_;
252 pending_requests_[request_id] = function; 252 pending_requests_[request_id] = function;
253 protocol_request.SetInteger("id", request_id); 253 protocol_request.SetInteger("id", request_id);
254 protocol_request.SetString("method", method); 254 protocol_request.SetString("method", method);
255 if (command_params) { 255 if (command_params) {
256 protocol_request.Set("params", 256 protocol_request.Set("params",
257 command_params->additional_properties.DeepCopy()); 257 command_params->additional_properties.DeepCopy());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 if (dictionary->GetDictionary("params", &params_value)) 331 if (dictionary->GetDictionary("params", &params_value))
332 params.additional_properties.Swap(params_value); 332 params.additional_properties.Swap(params_value);
333 333
334 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params)); 334 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params));
335 scoped_ptr<extensions::Event> event(new extensions::Event( 335 scoped_ptr<extensions::Event> event(new extensions::Event(
336 keys::kOnEvent, args.Pass())); 336 keys::kOnEvent, args.Pass()));
337 event->restrict_to_profile = profile; 337 event->restrict_to_profile = profile;
338 extensions::ExtensionSystem::Get(profile)->event_router()-> 338 extensions::ExtensionSystem::Get(profile)->event_router()->
339 DispatchEventToExtension(extension_id_, event.Pass()); 339 DispatchEventToExtension(extension_id_, event.Pass());
340 } else { 340 } else {
341 SendCommandDebuggerFunction* function = pending_requests_[id]; 341 DebuggerSendCommandFunction* function = pending_requests_[id];
342 if (!function) 342 if (!function)
343 return; 343 return;
344 344
345 function->SendResponseBody(dictionary); 345 function->SendResponseBody(dictionary);
346 pending_requests_.erase(id); 346 pending_requests_.erase(id);
347 } 347 }
348 } 348 }
349 349
350 ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate( 350 ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate(
351 InfoBarService* infobar_service, 351 InfoBarService* infobar_service,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 !client_host_->MatchesContentsAndExtensionId(contents_, 434 !client_host_->MatchesContentsAndExtensionId(contents_,
435 GetExtension()->id())) { 435 GetExtension()->id())) {
436 error_ = ErrorUtils::FormatErrorMessage( 436 error_ = ErrorUtils::FormatErrorMessage(
437 keys::kNotAttachedError, 437 keys::kNotAttachedError,
438 base::IntToString(tab_id_)); 438 base::IntToString(tab_id_));
439 return false; 439 return false;
440 } 440 }
441 return true; 441 return true;
442 } 442 }
443 443
444 AttachDebuggerFunction::AttachDebuggerFunction() {} 444 DebuggerAttachFunction::DebuggerAttachFunction() {}
445 445
446 AttachDebuggerFunction::~AttachDebuggerFunction() {} 446 DebuggerAttachFunction::~DebuggerAttachFunction() {}
447 447
448 bool AttachDebuggerFunction::RunImpl() { 448 bool DebuggerAttachFunction::RunImpl() {
449 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); 449 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_));
450 EXTENSION_FUNCTION_VALIDATE(params.get()); 450 EXTENSION_FUNCTION_VALIDATE(params.get());
451 451
452 tab_id_ = params->target.tab_id; 452 tab_id_ = params->target.tab_id;
453 if (!InitWebContents()) 453 if (!InitWebContents())
454 return false; 454 return false;
455 455
456 if (!webkit_glue::IsInspectorProtocolVersionSupported( 456 if (!webkit_glue::IsInspectorProtocolVersionSupported(
457 params->required_version)) { 457 params->required_version)) {
458 error_ = ErrorUtils::FormatErrorMessage( 458 error_ = ErrorUtils::FormatErrorMessage(
(...skipping 15 matching lines...) Expand all
474 } 474 }
475 475
476 new ExtensionDevToolsClientHost(contents_, 476 new ExtensionDevToolsClientHost(contents_,
477 GetExtension()->id(), 477 GetExtension()->id(),
478 GetExtension()->name(), 478 GetExtension()->name(),
479 tab_id_); 479 tab_id_);
480 SendResponse(true); 480 SendResponse(true);
481 return true; 481 return true;
482 } 482 }
483 483
484 DetachDebuggerFunction::DetachDebuggerFunction() {} 484 DebuggerDetachFunction::DebuggerDetachFunction() {}
485 485
486 DetachDebuggerFunction::~DetachDebuggerFunction() {} 486 DebuggerDetachFunction::~DebuggerDetachFunction() {}
487 487
488 bool DetachDebuggerFunction::RunImpl() { 488 bool DebuggerDetachFunction::RunImpl() {
489 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); 489 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_));
490 EXTENSION_FUNCTION_VALIDATE(params.get()); 490 EXTENSION_FUNCTION_VALIDATE(params.get());
491 491
492 tab_id_ = params->target.tab_id; 492 tab_id_ = params->target.tab_id;
493 if (!InitClientHost()) 493 if (!InitClientHost())
494 return false; 494 return false;
495 495
496 client_host_->Close(); 496 client_host_->Close();
497 SendResponse(true); 497 SendResponse(true);
498 return true; 498 return true;
499 } 499 }
500 500
501 SendCommandDebuggerFunction::SendCommandDebuggerFunction() {} 501 DebuggerSendCommandFunction::DebuggerSendCommandFunction() {}
502 502
503 SendCommandDebuggerFunction::~SendCommandDebuggerFunction() {} 503 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() {}
504 504
505 bool SendCommandDebuggerFunction::RunImpl() { 505 bool DebuggerSendCommandFunction::RunImpl() {
506 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_)); 506 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_));
507 EXTENSION_FUNCTION_VALIDATE(params.get()); 507 EXTENSION_FUNCTION_VALIDATE(params.get());
508 508
509 tab_id_ = params->target.tab_id; 509 tab_id_ = params->target.tab_id;
510 if (!InitClientHost()) 510 if (!InitClientHost())
511 return false; 511 return false;
512 512
513 client_host_->SendMessageToBackend(this, params->method, 513 client_host_->SendMessageToBackend(this, params->method,
514 params->command_params.get()); 514 params->command_params.get());
515 return true; 515 return true;
516 } 516 }
517 517
518 void SendCommandDebuggerFunction::SendResponseBody( 518 void DebuggerSendCommandFunction::SendResponseBody(
519 DictionaryValue* response) { 519 DictionaryValue* response) {
520 Value* error_body; 520 Value* error_body;
521 if (response->Get("error", &error_body)) { 521 if (response->Get("error", &error_body)) {
522 base::JSONWriter::Write(error_body, &error_); 522 base::JSONWriter::Write(error_body, &error_);
523 SendResponse(false); 523 SendResponse(false);
524 return; 524 return;
525 } 525 }
526 526
527 DictionaryValue* result_body; 527 DictionaryValue* result_body;
528 SendCommand::Results::Result result; 528 SendCommand::Results::Result result;
529 if (response->GetDictionary("result", &result_body)) 529 if (response->GetDictionary("result", &result_body))
530 result.additional_properties.Swap(result_body); 530 result.additional_properties.Swap(result_body);
531 531
532 results_ = SendCommand::Results::Create(result); 532 results_ = SendCommand::Results::Create(result);
533 SendResponse(true); 533 SendResponse(true);
534 } 534 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698