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

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

Issue 11308012: Remove some TabContentses from extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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>
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/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" 19 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
20 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" 20 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h"
21 #include "chrome/browser/extensions/event_router.h" 21 #include "chrome/browser/extensions/event_router.h"
22 #include "chrome/browser/extensions/extension_tab_util.h" 22 #include "chrome/browser/extensions/extension_tab_util.h"
23 #include "chrome/browser/infobars/infobar.h" 23 #include "chrome/browser/infobars/infobar.h"
24 #include "chrome/browser/infobars/infobar_tab_helper.h" 24 #include "chrome/browser/infobars/infobar_tab_helper.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/tab_contents/tab_contents.h"
27 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 26 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
28 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/extensions/api/debugger.h" 28 #include "chrome/common/extensions/api/debugger.h"
30 #include "chrome/common/extensions/extension.h" 29 #include "chrome/common/extensions/extension.h"
31 #include "chrome/common/extensions/extension_error_utils.h" 30 #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"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 client_host_->MarkAsDismissed(); 399 client_host_->MarkAsDismissed();
401 return true; 400 return true;
402 } 401 }
403 402
404 DebuggerFunction::DebuggerFunction() 403 DebuggerFunction::DebuggerFunction()
405 : contents_(0), 404 : contents_(0),
406 tab_id_(0), 405 tab_id_(0),
407 client_host_(0) { 406 client_host_(0) {
408 } 407 }
409 408
410 bool DebuggerFunction::InitTabContents() { 409 bool DebuggerFunction::InitWebContents() {
411 // Find the TabContents that contains this tab id. 410 // Find the WebContents that contains this tab id.
412 contents_ = NULL; 411 contents_ = NULL;
413 TabContents* tab_contents = NULL; 412 WebContents* web_contents = NULL;
414 bool result = ExtensionTabUtil::GetTabById( 413 bool result = ExtensionTabUtil::GetTabById(
415 tab_id_, profile(), include_incognito(), NULL, NULL, &tab_contents, NULL); 414 tab_id_, profile(), include_incognito(), NULL, NULL, &web_contents, NULL);
416 if (!result || !tab_contents) { 415 if (!result || !web_contents) {
417 error_ = ExtensionErrorUtils::FormatErrorMessage( 416 error_ = ExtensionErrorUtils::FormatErrorMessage(
418 keys::kNoTabError, 417 keys::kNoTabError,
419 base::IntToString(tab_id_)); 418 base::IntToString(tab_id_));
420 return false; 419 return false;
421 } 420 }
422 contents_ = tab_contents->web_contents(); 421 contents_ = web_contents;
423 422
424 if (content::GetContentClient()->HasWebUIScheme( 423 if (content::GetContentClient()->HasWebUIScheme(
425 contents_->GetURL())) { 424 contents_->GetURL())) {
426 error_ = ExtensionErrorUtils::FormatErrorMessage( 425 error_ = ExtensionErrorUtils::FormatErrorMessage(
427 keys::kAttachToWebUIError, 426 keys::kAttachToWebUIError,
428 contents_->GetURL().scheme()); 427 contents_->GetURL().scheme());
429 return false; 428 return false;
430 } 429 }
431 430
432 return true; 431 return true;
433 } 432 }
434 433
435 bool DebuggerFunction::InitClientHost() { 434 bool DebuggerFunction::InitClientHost() {
436 if (!InitTabContents()) 435 if (!InitWebContents())
437 return false; 436 return false;
438 437
439 // Don't fetch rvh from the contents since it'll be wrong upon navigation. 438 // Don't fetch rvh from the contents since it'll be wrong upon navigation.
440 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); 439 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_);
441 440
442 if (!client_host_ || 441 if (!client_host_ ||
443 !client_host_->MatchesContentsAndExtensionId(contents_, 442 !client_host_->MatchesContentsAndExtensionId(contents_,
444 GetExtension()->id())) { 443 GetExtension()->id())) {
445 error_ = ExtensionErrorUtils::FormatErrorMessage( 444 error_ = ExtensionErrorUtils::FormatErrorMessage(
446 keys::kNotAttachedError, 445 keys::kNotAttachedError,
447 base::IntToString(tab_id_)); 446 base::IntToString(tab_id_));
448 return false; 447 return false;
449 } 448 }
450 return true; 449 return true;
451 } 450 }
452 451
453 AttachDebuggerFunction::AttachDebuggerFunction() {} 452 AttachDebuggerFunction::AttachDebuggerFunction() {}
454 453
455 AttachDebuggerFunction::~AttachDebuggerFunction() {} 454 AttachDebuggerFunction::~AttachDebuggerFunction() {}
456 455
457 bool AttachDebuggerFunction::RunImpl() { 456 bool AttachDebuggerFunction::RunImpl() {
458 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); 457 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_));
459 EXTENSION_FUNCTION_VALIDATE(params.get()); 458 EXTENSION_FUNCTION_VALIDATE(params.get());
460 459
461 tab_id_ = params->target.tab_id; 460 tab_id_ = params->target.tab_id;
462 if (!InitTabContents()) 461 if (!InitWebContents())
463 return false; 462 return false;
464 463
465 if (!webkit_glue::IsInspectorProtocolVersionSupported( 464 if (!webkit_glue::IsInspectorProtocolVersionSupported(
466 params->required_version)) { 465 params->required_version)) {
467 error_ = ExtensionErrorUtils::FormatErrorMessage( 466 error_ = ExtensionErrorUtils::FormatErrorMessage(
468 keys::kProtocolVersionNotSupportedError, 467 keys::kProtocolVersionNotSupportedError,
469 params->required_version); 468 params->required_version);
470 return false; 469 return false;
471 } 470 }
472 471
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 542 }
544 543
545 // static 544 // static
546 void DebuggerApi::MarkDevToolsClientHostAsReplaced( 545 void DebuggerApi::MarkDevToolsClientHostAsReplaced(
547 DevToolsClientHost* client_host) { 546 DevToolsClientHost* client_host) {
548 ExtensionDevToolsClientHost* host = AttachedClientHosts::GetInstance()-> 547 ExtensionDevToolsClientHost* host = AttachedClientHosts::GetInstance()->
549 AsExtensionDevToolsClientHost(client_host); 548 AsExtensionDevToolsClientHost(client_host);
550 if (host) 549 if (host)
551 host->MarkAsReplaced(); 550 host->MarkAsReplaced();
552 } 551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698