| 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/extension_debugger_api.h" | 7 #include "chrome/browser/extensions/extension_debugger_api.h" |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/extensions/extension_debugger_api_constants.h" | 18 #include "chrome/browser/extensions/extension_debugger_api_constants.h" |
| 19 #include "chrome/browser/extensions/extension_event_router.h" | 19 #include "chrome/browser/extensions/extension_event_router.h" |
| 20 #include "chrome/browser/extensions/extension_tab_util.h" | 20 #include "chrome/browser/extensions/extension_tab_util.h" |
| 21 #include "chrome/browser/infobars/infobar.h" | 21 #include "chrome/browser/infobars/infobar.h" |
| 22 #include "chrome/browser/infobars/infobar_tab_helper.h" | 22 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 24 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 26 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 26 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/extensions/extension.h" | 28 #include "chrome/common/extensions/extension.h" |
| 29 #include "chrome/common/extensions/extension_error_utils.h" | 29 #include "chrome/common/extensions/extension_error_utils.h" |
| 30 #include "content/public/browser/devtools_agent_host_registry.h" | 30 #include "content/public/browser/devtools_agent_host_registry.h" |
| 31 #include "content/public/browser/devtools_client_host.h" | 31 #include "content/public/browser/devtools_client_host.h" |
| 32 #include "content/public/browser/devtools_manager.h" | 32 #include "content/public/browser/devtools_manager.h" |
| 33 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
| 35 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 174 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 175 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 175 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 176 content::Source<Profile>(profile)); | 176 content::Source<Profile>(profile)); |
| 177 | 177 |
| 178 // Attach to debugger and tell it we are ready. | 178 // Attach to debugger and tell it we are ready. |
| 179 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 179 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 180 web_contents_->GetRenderViewHost()); | 180 web_contents_->GetRenderViewHost()); |
| 181 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); | 181 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); |
| 182 | 182 |
| 183 InfoBarTabHelper* infobar_helper = | 183 InfoBarTabHelper* infobar_helper = |
| 184 TabContentsWrapper::GetCurrentWrapperForContents(web_contents_)-> | 184 TabContents::FromWebContents(web_contents_)->infobar_tab_helper(); |
| 185 infobar_tab_helper(); | |
| 186 infobar_delegate_ = | 185 infobar_delegate_ = |
| 187 new ExtensionDevToolsInfoBarDelegate(infobar_helper, extension_name); | 186 new ExtensionDevToolsInfoBarDelegate(infobar_helper, extension_name); |
| 188 if (infobar_helper->AddInfoBar(infobar_delegate_)) { | 187 if (infobar_helper->AddInfoBar(infobar_delegate_)) { |
| 189 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 188 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 190 content::Source<InfoBarTabHelper>(infobar_helper)); | 189 content::Source<InfoBarTabHelper>(infobar_helper)); |
| 191 } else { | 190 } else { |
| 192 infobar_delegate_ = NULL; | 191 infobar_delegate_ = NULL; |
| 193 } | 192 } |
| 194 } | 193 } |
| 195 | 194 |
| 196 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { | 195 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { |
| 197 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to | 196 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to |
| 198 // Close() us. | 197 // Close() us. |
| 199 registrar_.RemoveAll(); | 198 registrar_.RemoveAll(); |
| 200 | 199 |
| 201 if (infobar_delegate_) { | 200 if (infobar_delegate_) { |
| 202 TabContentsWrapper* wrapper = | 201 TabContents* tab_contents = TabContents::FromWebContents(web_contents_); |
| 203 TabContentsWrapper::GetCurrentWrapperForContents(web_contents_); | 202 InfoBarTabHelper* helper = tab_contents->infobar_tab_helper(); |
| 204 InfoBarTabHelper* helper = wrapper->infobar_tab_helper(); | |
| 205 if (helper) | 203 if (helper) |
| 206 helper->RemoveInfoBar(infobar_delegate_); | 204 helper->RemoveInfoBar(infobar_delegate_); |
| 207 } | 205 } |
| 208 AttachedClientHosts::GetInstance()->Remove(this); | 206 AttachedClientHosts::GetInstance()->Remove(this); |
| 209 } | 207 } |
| 210 | 208 |
| 211 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId( | 209 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId( |
| 212 WebContents* web_contents, | 210 WebContents* web_contents, |
| 213 const std::string& extension_id) { | 211 const std::string& extension_id) { |
| 214 return web_contents == web_contents_ && extension_id_ == extension_id; | 212 return web_contents == web_contents_ && extension_id_ == extension_id; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 client_host_(0) { | 354 client_host_(0) { |
| 357 } | 355 } |
| 358 | 356 |
| 359 bool DebuggerFunction::InitTabContents() { | 357 bool DebuggerFunction::InitTabContents() { |
| 360 Value* debuggee; | 358 Value* debuggee; |
| 361 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &debuggee)); | 359 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &debuggee)); |
| 362 | 360 |
| 363 DictionaryValue* dict = static_cast<DictionaryValue*>(debuggee); | 361 DictionaryValue* dict = static_cast<DictionaryValue*>(debuggee); |
| 364 EXTENSION_FUNCTION_VALIDATE(dict->GetInteger(keys::kTabIdKey, &tab_id_)); | 362 EXTENSION_FUNCTION_VALIDATE(dict->GetInteger(keys::kTabIdKey, &tab_id_)); |
| 365 | 363 |
| 366 // Find the TabContentsWrapper that contains this tab id. | 364 // Find the TabContents that contains this tab id. |
| 367 contents_ = NULL; | 365 contents_ = NULL; |
| 368 TabContentsWrapper* wrapper = NULL; | 366 TabContents* tab_contents = NULL; |
| 369 bool result = ExtensionTabUtil::GetTabById( | 367 bool result = ExtensionTabUtil::GetTabById( |
| 370 tab_id_, profile(), include_incognito(), NULL, NULL, &wrapper, NULL); | 368 tab_id_, profile(), include_incognito(), NULL, NULL, &tab_contents, NULL); |
| 371 if (!result || !wrapper) { | 369 if (!result || !tab_contents) { |
| 372 error_ = ExtensionErrorUtils::FormatErrorMessage( | 370 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 373 keys::kNoTabError, | 371 keys::kNoTabError, |
| 374 base::IntToString(tab_id_)); | 372 base::IntToString(tab_id_)); |
| 375 return false; | 373 return false; |
| 376 } | 374 } |
| 377 contents_ = wrapper->web_contents(); | 375 contents_ = tab_contents->web_contents(); |
| 378 | 376 |
| 379 if (content::GetContentClient()->HasWebUIScheme( | 377 if (content::GetContentClient()->HasWebUIScheme( |
| 380 contents_->GetURL())) { | 378 contents_->GetURL())) { |
| 381 error_ = ExtensionErrorUtils::FormatErrorMessage( | 379 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 382 keys::kAttachToWebUIError, | 380 keys::kAttachToWebUIError, |
| 383 contents_->GetURL().scheme()); | 381 contents_->GetURL().scheme()); |
| 384 return false; | 382 return false; |
| 385 } | 383 } |
| 386 | 384 |
| 387 return true; | 385 return true; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 return; | 483 return; |
| 486 } | 484 } |
| 487 | 485 |
| 488 Value* result_body; | 486 Value* result_body; |
| 489 if (dictionary->Get("result", &result_body)) | 487 if (dictionary->Get("result", &result_body)) |
| 490 result_.reset(result_body->DeepCopy()); | 488 result_.reset(result_body->DeepCopy()); |
| 491 else | 489 else |
| 492 result_.reset(new DictionaryValue()); | 490 result_.reset(new DictionaryValue()); |
| 493 SendResponse(true); | 491 SendResponse(true); |
| 494 } | 492 } |
| OLD | NEW |