[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 5 | #include "content/shell/browser/shell_devtools_frontend.h" |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 6 | |
[email protected] | ee54606 | 2014-08-04 18:06:48 | [diff] [blame] | 7 | #include "base/strings/string_number_conversions.h" |
[email protected] | fee9eca0 | 2014-02-14 19:24:40 | [diff] [blame] | 8 | #include "base/strings/stringprintf.h" |
[email protected] | e9cd74c | 2013-12-04 13:09:32 | [diff] [blame] | 9 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 10 | #include "content/public/browser/web_contents.h" |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 11 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 12 | #include "content/shell/browser/shell.h" |
| 13 | #include "content/shell/browser/shell_browser_context.h" |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 14 | #include "content/shell/browser/shell_devtools_bindings.h" |
vkuzkokov | cbabd58 | 2014-11-06 13:53:54 | [diff] [blame] | 15 | #include "content/shell/browser/shell_devtools_manager_delegate.h" |
chenwilliam | e88d836 | 2017-03-21 02:34:30 | [diff] [blame] | 16 | |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 17 | namespace content { |
| 18 | |
pfeldman | 175b3339 | 2015-02-28 15:52:48 | [diff] [blame] | 19 | namespace { |
pfeldman | f1a1694 | 2016-09-02 21:28:00 | [diff] [blame] | 20 | static GURL GetFrontendURL() { |
pfeldman | f7c18d024 | 2016-09-08 19:54:26 | [diff] [blame] | 21 | int port = ShellDevToolsManagerDelegate::GetHttpHandlerPort(); |
Pavel Feldman | 9018df6a | 2018-03-12 23:35:42 | [diff] [blame^] | 22 | return GURL(base::StringPrintf( |
| 23 | "http://127.0.0.1:%d/devtools/devtools_app.html", port)); |
pfeldman | f1a1694 | 2016-09-02 21:28:00 | [diff] [blame] | 24 | } |
pfeldman | 175b3339 | 2015-02-28 15:52:48 | [diff] [blame] | 25 | } // namespace |
| 26 | |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 27 | // static |
| 28 | ShellDevToolsFrontend* ShellDevToolsFrontend::Show( |
| 29 | WebContents* inspected_contents) { |
| 30 | Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 31 | GURL(), nullptr, gfx::Size()); |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 32 | ShellDevToolsFrontend* devtools_frontend = |
| 33 | new ShellDevToolsFrontend(shell, inspected_contents); |
pfeldman | f1a1694 | 2016-09-02 21:28:00 | [diff] [blame] | 34 | shell->LoadURL(GetFrontendURL()); |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 35 | return devtools_frontend; |
| 36 | } |
| 37 | |
[email protected] | 546618b | 2013-10-20 21:17:32 | [diff] [blame] | 38 | void ShellDevToolsFrontend::Activate() { |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 39 | frontend_shell_->ActivateContents(frontend_shell_->web_contents()); |
[email protected] | 546618b | 2013-10-20 21:17:32 | [diff] [blame] | 40 | } |
| 41 | |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 42 | void ShellDevToolsFrontend::Focus() { |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 43 | frontend_shell_->web_contents()->Focus(); |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 44 | } |
| 45 | |
[email protected] | 2317fcd | 2014-02-10 14:36:48 | [diff] [blame] | 46 | void ShellDevToolsFrontend::InspectElementAt(int x, int y) { |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 47 | devtools_bindings_->InspectElementAt(x, y); |
[email protected] | 2317fcd | 2014-02-10 14:36:48 | [diff] [blame] | 48 | } |
| 49 | |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 50 | void ShellDevToolsFrontend::Close() { |
| 51 | frontend_shell_->Close(); |
| 52 | } |
| 53 | |
Will Chen | 8bbdf20f | 2017-12-12 21:09:54 | [diff] [blame] | 54 | void ShellDevToolsFrontend::DocumentAvailableInMainFrame() { |
| 55 | devtools_bindings_->Attach(); |
| 56 | } |
| 57 | |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 58 | void ShellDevToolsFrontend::WebContentsDestroyed() { |
| 59 | delete this; |
pfeldman | 55275645 | 2015-02-03 17:33:06 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 62 | ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell, |
pfeldman | 11f5b14 | 2015-03-18 11:11:51 | [diff] [blame] | 63 | WebContents* inspected_contents) |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 64 | : WebContentsObserver(frontend_shell->web_contents()), |
| 65 | frontend_shell_(frontend_shell), |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 66 | devtools_bindings_( |
| 67 | new ShellDevToolsBindings(frontend_shell->web_contents(), |
| 68 | inspected_contents, |
| 69 | this)) {} |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 70 | |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 71 | ShellDevToolsFrontend::~ShellDevToolsFrontend() {} |
[email protected] | 0773e0c | 2013-01-25 15:57:57 | [diff] [blame] | 72 | |
| 73 | } // namespace content |