| 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> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/devtools/devtools_target_impl.h" | 22 #include "chrome/browser/devtools/devtools_target_impl.h" |
| 23 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" | 23 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" |
| 24 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
| 25 #include "chrome/browser/extensions/extension_tab_util.h" | 25 #include "chrome/browser/extensions/extension_tab_util.h" |
| 26 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 26 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 27 #include "chrome/browser/infobars/infobar.h" | |
| 28 #include "chrome/browser/infobars/infobar_service.h" | 27 #include "chrome/browser/infobars/infobar_service.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 29 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 31 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "components/infobars/core/infobar.h" |
| 32 #include "content/public/browser/devtools_agent_host.h" | 32 #include "content/public/browser/devtools_agent_host.h" |
| 33 #include "content/public/browser/devtools_client_host.h" | 33 #include "content/public/browser/devtools_client_host.h" |
| 34 #include "content/public/browser/devtools_http_handler.h" | 34 #include "content/public/browser/devtools_http_handler.h" |
| 35 #include "content/public/browser/devtools_manager.h" | 35 #include "content/public/browser/devtools_manager.h" |
| 36 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
| 38 #include "content/public/browser/render_process_host.h" | 38 #include "content/public/browser/render_process_host.h" |
| 39 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/render_widget_host.h" | 40 #include "content/public/browser/render_widget_host.h" |
| 41 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 65 namespace OnDetach = extensions::api::debugger::OnDetach; | 65 namespace OnDetach = extensions::api::debugger::OnDetach; |
| 66 namespace OnEvent = extensions::api::debugger::OnEvent; | 66 namespace OnEvent = extensions::api::debugger::OnEvent; |
| 67 namespace SendCommand = extensions::api::debugger::SendCommand; | 67 namespace SendCommand = extensions::api::debugger::SendCommand; |
| 68 | 68 |
| 69 | 69 |
| 70 // ExtensionDevToolsClientHost ------------------------------------------------ | 70 // ExtensionDevToolsClientHost ------------------------------------------------ |
| 71 | 71 |
| 72 class ExtensionDevToolsClientHost : public DevToolsClientHost, | 72 class ExtensionDevToolsClientHost : public DevToolsClientHost, |
| 73 public content::NotificationObserver { | 73 public content::NotificationObserver { |
| 74 public: | 74 public: |
| 75 ExtensionDevToolsClientHost( | 75 ExtensionDevToolsClientHost(Profile* profile, |
| 76 Profile* profile, | 76 DevToolsAgentHost* agent_host, |
| 77 DevToolsAgentHost* agent_host, | 77 const std::string& extension_id, |
| 78 const std::string& extension_id, | 78 const std::string& extension_name, |
| 79 const std::string& extension_name, | 79 const Debuggee& debuggee, |
| 80 const Debuggee& debuggee, | 80 infobars::InfoBar* infobar); |
| 81 InfoBar* infobar); | |
| 82 | 81 |
| 83 virtual ~ExtensionDevToolsClientHost(); | 82 virtual ~ExtensionDevToolsClientHost(); |
| 84 | 83 |
| 85 const std::string& extension_id() { return extension_id_; } | 84 const std::string& extension_id() { return extension_id_; } |
| 86 void Close(); | 85 void Close(); |
| 87 void SendMessageToBackend(DebuggerSendCommandFunction* function, | 86 void SendMessageToBackend(DebuggerSendCommandFunction* function, |
| 88 const std::string& method, | 87 const std::string& method, |
| 89 SendCommand::Params::CommandParams* command_params); | 88 SendCommand::Params::CommandParams* command_params); |
| 90 | 89 |
| 91 // Marks connection as to-be-terminated by the user. | 90 // Marks connection as to-be-terminated by the user. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 106 | 105 |
| 107 Profile* profile_; | 106 Profile* profile_; |
| 108 scoped_refptr<DevToolsAgentHost> agent_host_; | 107 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 109 std::string extension_id_; | 108 std::string extension_id_; |
| 110 Debuggee debuggee_; | 109 Debuggee debuggee_; |
| 111 content::NotificationRegistrar registrar_; | 110 content::NotificationRegistrar registrar_; |
| 112 int last_request_id_; | 111 int last_request_id_; |
| 113 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > | 112 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > |
| 114 PendingRequests; | 113 PendingRequests; |
| 115 PendingRequests pending_requests_; | 114 PendingRequests pending_requests_; |
| 116 InfoBar* infobar_; | 115 infobars::InfoBar* infobar_; |
| 117 OnDetach::Reason detach_reason_; | 116 OnDetach::Reason detach_reason_; |
| 118 | 117 |
| 119 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); | 118 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); |
| 120 }; | 119 }; |
| 121 | 120 |
| 122 // The member function declarations come after the other class declarations, so | 121 // The member function declarations come after the other class declarations, so |
| 123 // they can call members on them. | 122 // they can call members on them. |
| 124 | 123 |
| 125 | 124 |
| 126 namespace { | 125 namespace { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 137 } | 136 } |
| 138 | 137 |
| 139 | 138 |
| 140 // ExtensionDevToolsInfoBarDelegate ------------------------------------------- | 139 // ExtensionDevToolsInfoBarDelegate ------------------------------------------- |
| 141 | 140 |
| 142 class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { | 141 class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 143 public: | 142 public: |
| 144 // Creates an extension dev tools infobar and delegate and adds the infobar to | 143 // Creates an extension dev tools infobar and delegate and adds the infobar to |
| 145 // the InfoBarService associated with |rvh|. Returns the infobar if it was | 144 // the InfoBarService associated with |rvh|. Returns the infobar if it was |
| 146 // successfully added. | 145 // successfully added. |
| 147 static InfoBar* Create(RenderViewHost* rvh, const std::string& client_name); | 146 static infobars::InfoBar* Create(RenderViewHost* rvh, |
| 147 const std::string& client_name); |
| 148 | 148 |
| 149 void set_client_host(ExtensionDevToolsClientHost* client_host) { | 149 void set_client_host(ExtensionDevToolsClientHost* client_host) { |
| 150 client_host_ = client_host; | 150 client_host_ = client_host; |
| 151 } | 151 } |
| 152 | 152 |
| 153 private: | 153 private: |
| 154 explicit ExtensionDevToolsInfoBarDelegate(const std::string& client_name); | 154 explicit ExtensionDevToolsInfoBarDelegate(const std::string& client_name); |
| 155 virtual ~ExtensionDevToolsInfoBarDelegate(); | 155 virtual ~ExtensionDevToolsInfoBarDelegate(); |
| 156 | 156 |
| 157 // ConfirmInfoBarDelegate: | 157 // ConfirmInfoBarDelegate: |
| 158 virtual void InfoBarDismissed() OVERRIDE; | 158 virtual void InfoBarDismissed() OVERRIDE; |
| 159 virtual Type GetInfoBarType() const OVERRIDE; | 159 virtual Type GetInfoBarType() const OVERRIDE; |
| 160 virtual bool ShouldExpireInternal( | 160 virtual bool ShouldExpireInternal( |
| 161 const NavigationDetails& details) const OVERRIDE; | 161 const NavigationDetails& details) const OVERRIDE; |
| 162 virtual base::string16 GetMessageText() const OVERRIDE; | 162 virtual base::string16 GetMessageText() const OVERRIDE; |
| 163 virtual int GetButtons() const OVERRIDE; | 163 virtual int GetButtons() const OVERRIDE; |
| 164 virtual bool Cancel() OVERRIDE; | 164 virtual bool Cancel() OVERRIDE; |
| 165 | 165 |
| 166 std::string client_name_; | 166 std::string client_name_; |
| 167 ExtensionDevToolsClientHost* client_host_; | 167 ExtensionDevToolsClientHost* client_host_; |
| 168 | 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); | 169 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 // static | 172 // static |
| 173 InfoBar* ExtensionDevToolsInfoBarDelegate::Create( | 173 infobars::InfoBar* ExtensionDevToolsInfoBarDelegate::Create( |
| 174 RenderViewHost* rvh, | 174 RenderViewHost* rvh, |
| 175 const std::string& client_name) { | 175 const std::string& client_name) { |
| 176 if (!rvh) | 176 if (!rvh) |
| 177 return NULL; | 177 return NULL; |
| 178 | 178 |
| 179 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | 179 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| 180 if (!web_contents) | 180 if (!web_contents) |
| 181 return NULL; | 181 return NULL; |
| 182 | 182 |
| 183 InfoBarService* infobar_service = | 183 InfoBarService* infobar_service = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 198 } | 198 } |
| 199 | 199 |
| 200 ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() { | 200 ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() { |
| 201 } | 201 } |
| 202 | 202 |
| 203 void ExtensionDevToolsInfoBarDelegate::InfoBarDismissed() { | 203 void ExtensionDevToolsInfoBarDelegate::InfoBarDismissed() { |
| 204 if (client_host_) | 204 if (client_host_) |
| 205 client_host_->MarkAsDismissed(); | 205 client_host_->MarkAsDismissed(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 InfoBarDelegate::Type ExtensionDevToolsInfoBarDelegate::GetInfoBarType() const { | 208 infobars::InfoBarDelegate::Type |
| 209 ExtensionDevToolsInfoBarDelegate::GetInfoBarType() const { |
| 209 return WARNING_TYPE; | 210 return WARNING_TYPE; |
| 210 } | 211 } |
| 211 | 212 |
| 212 bool ExtensionDevToolsInfoBarDelegate::ShouldExpireInternal( | 213 bool ExtensionDevToolsInfoBarDelegate::ShouldExpireInternal( |
| 213 const NavigationDetails& details) const { | 214 const NavigationDetails& details) const { |
| 214 return false; | 215 return false; |
| 215 } | 216 } |
| 216 | 217 |
| 217 base::string16 ExtensionDevToolsInfoBarDelegate::GetMessageText() const { | 218 base::string16 ExtensionDevToolsInfoBarDelegate::GetMessageText() const { |
| 218 return l10n_util::GetStringFUTF16(IDS_DEV_TOOLS_INFOBAR_LABEL, | 219 return l10n_util::GetStringFUTF16(IDS_DEV_TOOLS_INFOBAR_LABEL, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 | 289 |
| 289 | 290 |
| 290 // ExtensionDevToolsClientHost ------------------------------------------------ | 291 // ExtensionDevToolsClientHost ------------------------------------------------ |
| 291 | 292 |
| 292 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( | 293 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( |
| 293 Profile* profile, | 294 Profile* profile, |
| 294 DevToolsAgentHost* agent_host, | 295 DevToolsAgentHost* agent_host, |
| 295 const std::string& extension_id, | 296 const std::string& extension_id, |
| 296 const std::string& extension_name, | 297 const std::string& extension_name, |
| 297 const Debuggee& debuggee, | 298 const Debuggee& debuggee, |
| 298 InfoBar* infobar) | 299 infobars::InfoBar* infobar) |
| 299 : profile_(profile), | 300 : profile_(profile), |
| 300 agent_host_(agent_host), | 301 agent_host_(agent_host), |
| 301 extension_id_(extension_id), | 302 extension_id_(extension_id), |
| 302 last_request_id_(0), | 303 last_request_id_(0), |
| 303 infobar_(infobar), | 304 infobar_(infobar), |
| 304 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { | 305 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { |
| 305 CopyDebuggee(&debuggee_, debuggee); | 306 CopyDebuggee(&debuggee_, debuggee); |
| 306 | 307 |
| 307 AttachedClientHosts::GetInstance()->Add(this); | 308 AttachedClientHosts::GetInstance()->Add(this); |
| 308 | 309 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 const content::NotificationSource& source, | 403 const content::NotificationSource& source, |
| 403 const content::NotificationDetails& details) { | 404 const content::NotificationDetails& details) { |
| 404 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { | 405 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { |
| 405 if (content::Details<extensions::UnloadedExtensionInfo>(details)-> | 406 if (content::Details<extensions::UnloadedExtensionInfo>(details)-> |
| 406 extension->id() == extension_id_) | 407 extension->id() == extension_id_) |
| 407 Close(); | 408 Close(); |
| 408 } else if (type == chrome::NOTIFICATION_APP_TERMINATING) { | 409 } else if (type == chrome::NOTIFICATION_APP_TERMINATING) { |
| 409 Close(); | 410 Close(); |
| 410 } else { | 411 } else { |
| 411 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 412 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
| 412 if (content::Details<InfoBar::RemovedDetails>(details)->first == infobar_) { | 413 if (content::Details<infobars::InfoBar::RemovedDetails>(details)->first == |
| 414 infobar_) { |
| 413 infobar_ = NULL; | 415 infobar_ = NULL; |
| 414 SendDetachedEvent(); | 416 SendDetachedEvent(); |
| 415 Close(); | 417 Close(); |
| 416 } | 418 } |
| 417 } | 419 } |
| 418 } | 420 } |
| 419 | 421 |
| 420 void ExtensionDevToolsClientHost::DispatchOnInspectorFrontend( | 422 void ExtensionDevToolsClientHost::DispatchOnInspectorFrontend( |
| 421 const std::string& message) { | 423 const std::string& message) { |
| 422 if (!extensions::ExtensionSystem::Get(profile_)->event_router()) | 424 if (!extensions::ExtensionSystem::Get(profile_)->event_router()) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 keys::kProtocolVersionNotSupportedError, | 559 keys::kProtocolVersionNotSupportedError, |
| 558 params->required_version); | 560 params->required_version); |
| 559 return false; | 561 return false; |
| 560 } | 562 } |
| 561 | 563 |
| 562 if (agent_host_->IsAttached()) { | 564 if (agent_host_->IsAttached()) { |
| 563 FormatErrorMessage(keys::kAlreadyAttachedError); | 565 FormatErrorMessage(keys::kAlreadyAttachedError); |
| 564 return false; | 566 return false; |
| 565 } | 567 } |
| 566 | 568 |
| 567 InfoBar* infobar = NULL; | 569 infobars::InfoBar* infobar = NULL; |
| 568 if (!CommandLine::ForCurrentProcess()-> | 570 if (!CommandLine::ForCurrentProcess()-> |
| 569 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { | 571 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { |
| 570 // Do not attach to the target if for any reason the infobar cannot be shown | 572 // Do not attach to the target if for any reason the infobar cannot be shown |
| 571 // for this WebContents instance. | 573 // for this WebContents instance. |
| 572 infobar = ExtensionDevToolsInfoBarDelegate::Create( | 574 infobar = ExtensionDevToolsInfoBarDelegate::Create( |
| 573 agent_host_->GetRenderViewHost(), GetExtension()->name()); | 575 agent_host_->GetRenderViewHost(), GetExtension()->name()); |
| 574 if (!infobar) { | 576 if (!infobar) { |
| 575 error_ = ErrorUtils::FormatErrorMessage( | 577 error_ = ErrorUtils::FormatErrorMessage( |
| 576 keys::kSilentDebuggingRequired, | 578 keys::kSilentDebuggingRequired, |
| 577 switches::kSilentDebuggerExtensionAPI); | 579 switches::kSilentDebuggerExtensionAPI); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 | 713 |
| 712 void DebuggerGetTargetsFunction::SendTargetList( | 714 void DebuggerGetTargetsFunction::SendTargetList( |
| 713 const std::vector<DevToolsTargetImpl*>& target_list) { | 715 const std::vector<DevToolsTargetImpl*>& target_list) { |
| 714 scoped_ptr<base::ListValue> result(new base::ListValue()); | 716 scoped_ptr<base::ListValue> result(new base::ListValue()); |
| 715 for (size_t i = 0; i < target_list.size(); ++i) | 717 for (size_t i = 0; i < target_list.size(); ++i) |
| 716 result->Append(SerializeTarget(*target_list[i])); | 718 result->Append(SerializeTarget(*target_list[i])); |
| 717 STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 719 STLDeleteContainerPointers(target_list.begin(), target_list.end()); |
| 718 SetResult(result.release()); | 720 SetResult(result.release()); |
| 719 SendResponse(true); | 721 SendResponse(true); |
| 720 } | 722 } |
| OLD | NEW |