| OLD | NEW |
| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 Profile* profile_; | 117 Profile* profile_; |
| 118 scoped_refptr<DevToolsAgentHost> agent_host_; | 118 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 119 std::string extension_id_; | 119 std::string extension_id_; |
| 120 Debuggee debuggee_; | 120 Debuggee debuggee_; |
| 121 content::NotificationRegistrar registrar_; | 121 content::NotificationRegistrar registrar_; |
| 122 int last_request_id_; | 122 int last_request_id_; |
| 123 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > | 123 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > |
| 124 PendingRequests; | 124 PendingRequests; |
| 125 PendingRequests pending_requests_; | 125 PendingRequests pending_requests_; |
| 126 infobars::InfoBar* infobar_; | 126 infobars::InfoBar* infobar_; |
| 127 OnDetach::Reason detach_reason_; | 127 api::debugger::OnDetachReason detach_reason_; |
| 128 | 128 |
| 129 // Listen to extension unloaded notification. | 129 // Listen to extension unloaded notification. |
| 130 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 130 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 131 extension_registry_observer_; | 131 extension_registry_observer_; |
| 132 | 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); | 133 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 // The member function declarations come after the other class declarations, so | 136 // The member function declarations come after the other class declarations, so |
| 137 // they can call members on them. | 137 // they can call members on them. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 DevToolsAgentHost* agent_host, | 304 DevToolsAgentHost* agent_host, |
| 305 const std::string& extension_id, | 305 const std::string& extension_id, |
| 306 const std::string& extension_name, | 306 const std::string& extension_name, |
| 307 const Debuggee& debuggee, | 307 const Debuggee& debuggee, |
| 308 infobars::InfoBar* infobar) | 308 infobars::InfoBar* infobar) |
| 309 : profile_(profile), | 309 : profile_(profile), |
| 310 agent_host_(agent_host), | 310 agent_host_(agent_host), |
| 311 extension_id_(extension_id), | 311 extension_id_(extension_id), |
| 312 last_request_id_(0), | 312 last_request_id_(0), |
| 313 infobar_(infobar), | 313 infobar_(infobar), |
| 314 detach_reason_(OnDetach::REASON_TARGET_CLOSED), | 314 detach_reason_(api::debugger::ON_DETACH_REASON_TARGET_CLOSED), |
| 315 extension_registry_observer_(this) { | 315 extension_registry_observer_(this) { |
| 316 CopyDebuggee(&debuggee_, debuggee); | 316 CopyDebuggee(&debuggee_, debuggee); |
| 317 | 317 |
| 318 AttachedClientHosts::GetInstance()->Add(this); | 318 AttachedClientHosts::GetInstance()->Add(this); |
| 319 | 319 |
| 320 // ExtensionRegistryObserver listen extension unloaded and detach debugger | 320 // ExtensionRegistryObserver listen extension unloaded and detach debugger |
| 321 // from there. | 321 // from there. |
| 322 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 322 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 323 | 323 |
| 324 // RVH-based agents disconnect from their clients when the app is terminating | 324 // RVH-based agents disconnect from their clients when the app is terminating |
| (...skipping 29 matching lines...) Expand all Loading... |
| 354 infobar_service->RemoveInfoBar(infobar_); | 354 infobar_service->RemoveInfoBar(infobar_); |
| 355 } | 355 } |
| 356 AttachedClientHosts::GetInstance()->Remove(this); | 356 AttachedClientHosts::GetInstance()->Remove(this); |
| 357 } | 357 } |
| 358 | 358 |
| 359 // DevToolsAgentHostClient implementation. | 359 // DevToolsAgentHostClient implementation. |
| 360 void ExtensionDevToolsClientHost::AgentHostClosed( | 360 void ExtensionDevToolsClientHost::AgentHostClosed( |
| 361 DevToolsAgentHost* agent_host, bool replaced_with_another_client) { | 361 DevToolsAgentHost* agent_host, bool replaced_with_another_client) { |
| 362 DCHECK(agent_host == agent_host_.get()); | 362 DCHECK(agent_host == agent_host_.get()); |
| 363 if (replaced_with_another_client) | 363 if (replaced_with_another_client) |
| 364 detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS; | 364 detach_reason_ = api::debugger::ON_DETACH_REASON_REPLACED_WITH_DEVTOOLS; |
| 365 SendDetachedEvent(); | 365 SendDetachedEvent(); |
| 366 delete this; | 366 delete this; |
| 367 } | 367 } |
| 368 | 368 |
| 369 void ExtensionDevToolsClientHost::Close() { | 369 void ExtensionDevToolsClientHost::Close() { |
| 370 agent_host_->DetachClient(); | 370 agent_host_->DetachClient(); |
| 371 delete this; | 371 delete this; |
| 372 } | 372 } |
| 373 | 373 |
| 374 void ExtensionDevToolsClientHost::SendMessageToBackend( | 374 void ExtensionDevToolsClientHost::SendMessageToBackend( |
| 375 DebuggerSendCommandFunction* function, | 375 DebuggerSendCommandFunction* function, |
| 376 const std::string& method, | 376 const std::string& method, |
| 377 SendCommand::Params::CommandParams* command_params) { | 377 SendCommand::Params::CommandParams* command_params) { |
| 378 base::DictionaryValue protocol_request; | 378 base::DictionaryValue protocol_request; |
| 379 int request_id = ++last_request_id_; | 379 int request_id = ++last_request_id_; |
| 380 pending_requests_[request_id] = function; | 380 pending_requests_[request_id] = function; |
| 381 protocol_request.SetInteger("id", request_id); | 381 protocol_request.SetInteger("id", request_id); |
| 382 protocol_request.SetString("method", method); | 382 protocol_request.SetString("method", method); |
| 383 if (command_params) { | 383 if (command_params) { |
| 384 protocol_request.Set("params", | 384 protocol_request.Set("params", |
| 385 command_params->additional_properties.DeepCopy()); | 385 command_params->additional_properties.DeepCopy()); |
| 386 } | 386 } |
| 387 | 387 |
| 388 std::string json_args; | 388 std::string json_args; |
| 389 base::JSONWriter::Write(&protocol_request, &json_args); | 389 base::JSONWriter::Write(&protocol_request, &json_args); |
| 390 agent_host_->DispatchProtocolMessage(json_args); | 390 agent_host_->DispatchProtocolMessage(json_args); |
| 391 } | 391 } |
| 392 | 392 |
| 393 void ExtensionDevToolsClientHost::MarkAsDismissed() { | 393 void ExtensionDevToolsClientHost::MarkAsDismissed() { |
| 394 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; | 394 detach_reason_ = api::debugger::ON_DETACH_REASON_CANCELED_BY_USER; |
| 395 } | 395 } |
| 396 | 396 |
| 397 void ExtensionDevToolsClientHost::SendDetachedEvent() { | 397 void ExtensionDevToolsClientHost::SendDetachedEvent() { |
| 398 if (!EventRouter::Get(profile_)) | 398 if (!EventRouter::Get(profile_)) |
| 399 return; | 399 return; |
| 400 | 400 |
| 401 scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee_, | 401 scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee_, |
| 402 detach_reason_)); | 402 detach_reason_)); |
| 403 scoped_ptr<Event> event(new Event(OnDetach::kEventName, args.Pass())); | 403 scoped_ptr<Event> event(new Event(OnDetach::kEventName, args.Pass())); |
| 404 event->restrict_to_browser_context = profile_; | 404 event->restrict_to_browser_context = profile_; |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 const std::vector<DevToolsTargetImpl*>& target_list) { | 743 const std::vector<DevToolsTargetImpl*>& target_list) { |
| 744 scoped_ptr<base::ListValue> result(new base::ListValue()); | 744 scoped_ptr<base::ListValue> result(new base::ListValue()); |
| 745 for (size_t i = 0; i < target_list.size(); ++i) | 745 for (size_t i = 0; i < target_list.size(); ++i) |
| 746 result->Append(SerializeTarget(*target_list[i])); | 746 result->Append(SerializeTarget(*target_list[i])); |
| 747 STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 747 STLDeleteContainerPointers(target_list.begin(), target_list.end()); |
| 748 SetResult(result.release()); | 748 SetResult(result.release()); |
| 749 SendResponse(true); | 749 SendResponse(true); |
| 750 } | 750 } |
| 751 | 751 |
| 752 } // namespace extensions | 752 } // namespace extensions |
| OLD | NEW |