blob: 6447347797c56f4009fdd9ea02e5f288d9954f0a [file] [log] [blame]
[email protected]de7d61ff2013-08-20 11:30:411// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]0773e0c2013-01-25 15:57:572// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]de7d61ff2013-08-20 11:30:415#include "content/shell/browser/shell_devtools_frontend.h"
[email protected]0773e0c2013-01-25 15:57:576
[email protected]ee546062014-08-04 18:06:487#include "base/strings/string_number_conversions.h"
[email protected]fee9eca02014-02-14 19:24:408#include "base/strings/stringprintf.h"
[email protected]e9cd74c2013-12-04 13:09:329#include "base/strings/utf_string_conversions.h"
[email protected]0773e0c2013-01-25 15:57:5710#include "content/public/browser/web_contents.h"
chenwilliamfed5bda2017-03-24 02:01:0611#include "content/public/browser/web_contents_observer.h"
[email protected]de7d61ff2013-08-20 11:30:4112#include "content/shell/browser/shell.h"
13#include "content/shell/browser/shell_browser_context.h"
chenwilliamfed5bda2017-03-24 02:01:0614#include "content/shell/browser/shell_devtools_bindings.h"
vkuzkokovcbabd582014-11-06 13:53:5415#include "content/shell/browser/shell_devtools_manager_delegate.h"
chenwilliame88d8362017-03-21 02:34:3016
[email protected]0773e0c2013-01-25 15:57:5717namespace content {
18
pfeldman175b33392015-02-28 15:52:4819namespace {
pfeldmanf1a16942016-09-02 21:28:0020static GURL GetFrontendURL() {
pfeldmanf7c18d0242016-09-08 19:54:2621 int port = ShellDevToolsManagerDelegate::GetHttpHandlerPort();
Pavel Feldman9018df6a2018-03-12 23:35:4222 return GURL(base::StringPrintf(
23 "http://127.0.0.1:%d/devtools/devtools_app.html", port));
pfeldmanf1a16942016-09-02 21:28:0024}
pfeldman175b33392015-02-28 15:52:4825} // namespace
26
[email protected]0773e0c2013-01-25 15:57:5727// static
28ShellDevToolsFrontend* ShellDevToolsFrontend::Show(
29 WebContents* inspected_contents) {
30 Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2831 GURL(), nullptr, gfx::Size());
chenwilliamfed5bda2017-03-24 02:01:0632 ShellDevToolsFrontend* devtools_frontend =
33 new ShellDevToolsFrontend(shell, inspected_contents);
pfeldmanf1a16942016-09-02 21:28:0034 shell->LoadURL(GetFrontendURL());
[email protected]0773e0c2013-01-25 15:57:5735 return devtools_frontend;
36}
37
[email protected]546618b2013-10-20 21:17:3238void ShellDevToolsFrontend::Activate() {
chenwilliamfed5bda2017-03-24 02:01:0639 frontend_shell_->ActivateContents(frontend_shell_->web_contents());
[email protected]546618b2013-10-20 21:17:3240}
41
[email protected]0773e0c2013-01-25 15:57:5742void ShellDevToolsFrontend::Focus() {
chenwilliamfed5bda2017-03-24 02:01:0643 frontend_shell_->web_contents()->Focus();
[email protected]0773e0c2013-01-25 15:57:5744}
45
[email protected]2317fcd2014-02-10 14:36:4846void ShellDevToolsFrontend::InspectElementAt(int x, int y) {
chenwilliamfed5bda2017-03-24 02:01:0647 devtools_bindings_->InspectElementAt(x, y);
[email protected]2317fcd2014-02-10 14:36:4848}
49
[email protected]0773e0c2013-01-25 15:57:5750void ShellDevToolsFrontend::Close() {
51 frontend_shell_->Close();
52}
53
Will Chen8bbdf20f2017-12-12 21:09:5454void ShellDevToolsFrontend::DocumentAvailableInMainFrame() {
55 devtools_bindings_->Attach();
56}
57
chenwilliamfed5bda2017-03-24 02:01:0658void ShellDevToolsFrontend::WebContentsDestroyed() {
59 delete this;
pfeldman552756452015-02-03 17:33:0660}
61
[email protected]0773e0c2013-01-25 15:57:5762ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell,
pfeldman11f5b142015-03-18 11:11:5163 WebContents* inspected_contents)
[email protected]0773e0c2013-01-25 15:57:5764 : WebContentsObserver(frontend_shell->web_contents()),
65 frontend_shell_(frontend_shell),
chenwilliamfed5bda2017-03-24 02:01:0666 devtools_bindings_(
67 new ShellDevToolsBindings(frontend_shell->web_contents(),
68 inspected_contents,
69 this)) {}
[email protected]0773e0c2013-01-25 15:57:5770
chenwilliamfed5bda2017-03-24 02:01:0671ShellDevToolsFrontend::~ShellDevToolsFrontend() {}
[email protected]0773e0c2013-01-25 15:57:5772
73} // namespace content