| 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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/extensions/event_router.h" | 21 #include "chrome/browser/extensions/event_router.h" |
| 22 #include "chrome/browser/extensions/extension_system.h" | 22 #include "chrome/browser/extensions/extension_system.h" |
| 23 #include "chrome/browser/extensions/extension_tab_util.h" | 23 #include "chrome/browser/extensions/extension_tab_util.h" |
| 24 #include "chrome/browser/infobars/infobar.h" | 24 #include "chrome/browser/infobars/infobar.h" |
| 25 #include "chrome/browser/infobars/infobar_tab_helper.h" | 25 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 27 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/extensions/api/debugger.h" | 29 #include "chrome/common/extensions/api/debugger.h" |
| 30 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
| 31 #include "chrome/common/extensions/extension_error_utils.h" | |
| 32 #include "content/public/browser/devtools_agent_host_registry.h" | 31 #include "content/public/browser/devtools_agent_host_registry.h" |
| 33 #include "content/public/browser/devtools_client_host.h" | 32 #include "content/public/browser/devtools_client_host.h" |
| 34 #include "content/public/browser/devtools_manager.h" | 33 #include "content/public/browser/devtools_manager.h" |
| 35 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
| 37 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
| 38 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 39 #include "content/public/common/content_client.h" | 38 #include "content/public/common/content_client.h" |
| 39 #include "extensions/common/extension_error_utils.h" |
| 40 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 42 #include "webkit/glue/webkit_glue.h" | 42 #include "webkit/glue/webkit_glue.h" |
| 43 | 43 |
| 44 using content::DevToolsAgentHost; | 44 using content::DevToolsAgentHost; |
| 45 using content::DevToolsAgentHostRegistry; | 45 using content::DevToolsAgentHostRegistry; |
| 46 using content::DevToolsClientHost; | 46 using content::DevToolsClientHost; |
| 47 using content::DevToolsManager; | 47 using content::DevToolsManager; |
| 48 using content::WebContents; | 48 using content::WebContents; |
| 49 using extensions::api::debugger::Debuggee; | 49 using extensions::api::debugger::Debuggee; |
| 50 using extensions::ErrorUtils; |
| 50 | 51 |
| 51 namespace keys = debugger_api_constants; | 52 namespace keys = debugger_api_constants; |
| 52 namespace Attach = extensions::api::debugger::Attach; | 53 namespace Attach = extensions::api::debugger::Attach; |
| 53 namespace Detach = extensions::api::debugger::Detach; | 54 namespace Detach = extensions::api::debugger::Detach; |
| 54 namespace OnDetach = extensions::api::debugger::OnDetach; | 55 namespace OnDetach = extensions::api::debugger::OnDetach; |
| 55 namespace OnEvent = extensions::api::debugger::OnEvent; | 56 namespace OnEvent = extensions::api::debugger::OnEvent; |
| 56 namespace SendCommand = extensions::api::debugger::SendCommand; | 57 namespace SendCommand = extensions::api::debugger::SendCommand; |
| 57 | 58 |
| 58 class ExtensionDevToolsClientHost; | 59 class ExtensionDevToolsClientHost; |
| 59 | 60 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 client_host_(0) { | 402 client_host_(0) { |
| 402 } | 403 } |
| 403 | 404 |
| 404 bool DebuggerFunction::InitWebContents() { | 405 bool DebuggerFunction::InitWebContents() { |
| 405 // Find the WebContents that contains this tab id. | 406 // Find the WebContents that contains this tab id. |
| 406 contents_ = NULL; | 407 contents_ = NULL; |
| 407 WebContents* web_contents = NULL; | 408 WebContents* web_contents = NULL; |
| 408 bool result = ExtensionTabUtil::GetTabById( | 409 bool result = ExtensionTabUtil::GetTabById( |
| 409 tab_id_, profile(), include_incognito(), NULL, NULL, &web_contents, NULL); | 410 tab_id_, profile(), include_incognito(), NULL, NULL, &web_contents, NULL); |
| 410 if (!result || !web_contents) { | 411 if (!result || !web_contents) { |
| 411 error_ = ExtensionErrorUtils::FormatErrorMessage( | 412 error_ = ErrorUtils::FormatErrorMessage( |
| 412 keys::kNoTabError, | 413 keys::kNoTabError, |
| 413 base::IntToString(tab_id_)); | 414 base::IntToString(tab_id_)); |
| 414 return false; | 415 return false; |
| 415 } | 416 } |
| 416 contents_ = web_contents; | 417 contents_ = web_contents; |
| 417 | 418 |
| 418 if (content::GetContentClient()->HasWebUIScheme( | 419 if (content::GetContentClient()->HasWebUIScheme( |
| 419 contents_->GetURL())) { | 420 contents_->GetURL())) { |
| 420 error_ = ExtensionErrorUtils::FormatErrorMessage( | 421 error_ = ErrorUtils::FormatErrorMessage( |
| 421 keys::kAttachToWebUIError, | 422 keys::kAttachToWebUIError, |
| 422 contents_->GetURL().scheme()); | 423 contents_->GetURL().scheme()); |
| 423 return false; | 424 return false; |
| 424 } | 425 } |
| 425 | 426 |
| 426 return true; | 427 return true; |
| 427 } | 428 } |
| 428 | 429 |
| 429 bool DebuggerFunction::InitClientHost() { | 430 bool DebuggerFunction::InitClientHost() { |
| 430 if (!InitWebContents()) | 431 if (!InitWebContents()) |
| 431 return false; | 432 return false; |
| 432 | 433 |
| 433 // Don't fetch rvh from the contents since it'll be wrong upon navigation. | 434 // Don't fetch rvh from the contents since it'll be wrong upon navigation. |
| 434 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); | 435 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); |
| 435 | 436 |
| 436 if (!client_host_ || | 437 if (!client_host_ || |
| 437 !client_host_->MatchesContentsAndExtensionId(contents_, | 438 !client_host_->MatchesContentsAndExtensionId(contents_, |
| 438 GetExtension()->id())) { | 439 GetExtension()->id())) { |
| 439 error_ = ExtensionErrorUtils::FormatErrorMessage( | 440 error_ = ErrorUtils::FormatErrorMessage( |
| 440 keys::kNotAttachedError, | 441 keys::kNotAttachedError, |
| 441 base::IntToString(tab_id_)); | 442 base::IntToString(tab_id_)); |
| 442 return false; | 443 return false; |
| 443 } | 444 } |
| 444 return true; | 445 return true; |
| 445 } | 446 } |
| 446 | 447 |
| 447 AttachDebuggerFunction::AttachDebuggerFunction() {} | 448 AttachDebuggerFunction::AttachDebuggerFunction() {} |
| 448 | 449 |
| 449 AttachDebuggerFunction::~AttachDebuggerFunction() {} | 450 AttachDebuggerFunction::~AttachDebuggerFunction() {} |
| 450 | 451 |
| 451 bool AttachDebuggerFunction::RunImpl() { | 452 bool AttachDebuggerFunction::RunImpl() { |
| 452 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); | 453 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); |
| 453 EXTENSION_FUNCTION_VALIDATE(params.get()); | 454 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 454 | 455 |
| 455 tab_id_ = params->target.tab_id; | 456 tab_id_ = params->target.tab_id; |
| 456 if (!InitWebContents()) | 457 if (!InitWebContents()) |
| 457 return false; | 458 return false; |
| 458 | 459 |
| 459 if (!webkit_glue::IsInspectorProtocolVersionSupported( | 460 if (!webkit_glue::IsInspectorProtocolVersionSupported( |
| 460 params->required_version)) { | 461 params->required_version)) { |
| 461 error_ = ExtensionErrorUtils::FormatErrorMessage( | 462 error_ = ErrorUtils::FormatErrorMessage( |
| 462 keys::kProtocolVersionNotSupportedError, | 463 keys::kProtocolVersionNotSupportedError, |
| 463 params->required_version); | 464 params->required_version); |
| 464 return false; | 465 return false; |
| 465 } | 466 } |
| 466 | 467 |
| 467 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 468 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 468 contents_->GetRenderViewHost()); | 469 contents_->GetRenderViewHost()); |
| 469 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> | 470 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> |
| 470 GetDevToolsClientHostFor(agent); | 471 GetDevToolsClientHostFor(agent); |
| 471 | 472 |
| 472 if (client_host != NULL) { | 473 if (client_host != NULL) { |
| 473 error_ = ExtensionErrorUtils::FormatErrorMessage( | 474 error_ = ErrorUtils::FormatErrorMessage( |
| 474 keys::kAlreadyAttachedError, | 475 keys::kAlreadyAttachedError, |
| 475 base::IntToString(tab_id_)); | 476 base::IntToString(tab_id_)); |
| 476 return false; | 477 return false; |
| 477 } | 478 } |
| 478 | 479 |
| 479 new ExtensionDevToolsClientHost(contents_, | 480 new ExtensionDevToolsClientHost(contents_, |
| 480 GetExtension()->id(), | 481 GetExtension()->id(), |
| 481 GetExtension()->name(), | 482 GetExtension()->name(), |
| 482 tab_id_); | 483 tab_id_); |
| 483 SendResponse(true); | 484 SendResponse(true); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 529 } |
| 529 | 530 |
| 530 DictionaryValue* result_body; | 531 DictionaryValue* result_body; |
| 531 SendCommand::Results::Result result; | 532 SendCommand::Results::Result result; |
| 532 if (response->GetDictionary("result", &result_body)) | 533 if (response->GetDictionary("result", &result_body)) |
| 533 result.additional_properties.Swap(result_body); | 534 result.additional_properties.Swap(result_body); |
| 534 | 535 |
| 535 results_ = SendCommand::Results::Create(result); | 536 results_ = SendCommand::Results::Create(result); |
| 536 SendResponse(true); | 537 SendResponse(true); |
| 537 } | 538 } |
| OLD | NEW |