diff options
author | skyostil <skyostil@chromium.org> | 2016-03-02 08:13:05 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-02 16:14:26 +0000 |
commit | 85c6b560c583cf265e4af5d68c9f07afb1fe74ca (patch) | |
tree | 04de8d126f30cc6884d254cc55f3a388d6db9833 | |
parent | de3cd13d57602a4d17223145a996e69394486bee (diff) | |
download | chromium_src-85c6b560c583cf265e4af5d68c9f07afb1fe74ca.zip chromium_src-85c6b560c583cf265e4af5d68c9f07afb1fe74ca.tar.gz chromium_src-85c6b560c583cf265e4af5d68c9f07afb1fe74ca.tar.bz2 |
headless: Add devtools discovery page
This page adds a generated discovery page which can be used to pick a
tab to inspect using devtools. This is based on the similar page
generated by Content Shell.
BUG=546953
TEST=headless_shell --remote-debugging-port=9222 # Navigate to localhost:9222 to see the google.com tab.
Review URL: https://codereview.chromium.org/1698403004
Cr-Commit-Position: refs/heads/master@{#378759}
-rw-r--r-- | headless/BUILD.gn | 11 | ||||
-rw-r--r-- | headless/lib/browser/headless_devtools.cc | 4 | ||||
-rw-r--r-- | headless/lib/resources/devtools_discovery_page.html | 54 | ||||
-rw-r--r-- | headless/lib/resources/headless_lib_resources.grd | 16 | ||||
-rw-r--r-- | tools/gritsettings/resource_ids | 3 |
5 files changed, 87 insertions, 1 deletions
diff --git a/headless/BUILD.gn b/headless/BUILD.gn index f31584f..a388908 100644 --- a/headless/BUILD.gn +++ b/headless/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. import("//testing/test.gni") +import("//tools/grit/grit_rule.gni") import("//tools/grit/repack.gni") group("headless") { @@ -20,6 +21,7 @@ repack("pak") { "$root_gen_dir/content/app/strings/content_strings_en-US.pak", "$root_gen_dir/content/browser/tracing/tracing_resources.pak", "$root_gen_dir/content/content_resources.pak", + "$root_gen_dir/headless/headless_lib_resources.pak", "$root_gen_dir/net/net_resources.pak", "$root_gen_dir/ui/resources/ui_resources_100_percent.pak", "$root_gen_dir/ui/resources/webui_resources.pak", @@ -28,6 +30,7 @@ repack("pak") { ] deps = [ + ":headless_lib_resources_grit", "//content:resources", "//content/app/resources", "//content/app/strings", @@ -43,6 +46,14 @@ repack("pak") { output = "$root_out_dir/headless_lib.pak" } +grit("headless_lib_resources_grit") { + source = "lib/resources/headless_lib_resources.grd" + outputs = [ + "grit/headless_lib_resources.h", + "$root_gen_dir/headless/headless_lib_resources.pak", + ] +} + static_library("headless_lib") { sources = [ "lib/browser/headless_browser_context.cc", diff --git a/headless/lib/browser/headless_devtools.cc b/headless/lib/browser/headless_devtools.cc index 8fe4b7d..258e9de 100644 --- a/headless/lib/browser/headless_devtools.cc +++ b/headless/lib/browser/headless_devtools.cc @@ -10,6 +10,7 @@ #include "content/public/browser/browser_context.h" #include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/navigation_entry.h" +#include "headless/grit/headless_lib_resources.h" #include "headless/lib/browser/headless_browser_context.h" #include "net/base/net_errors.h" #include "net/socket/tcp_server_socket.h" @@ -68,7 +69,8 @@ HeadlessDevToolsDelegate::HeadlessDevToolsDelegate() {} HeadlessDevToolsDelegate::~HeadlessDevToolsDelegate() {} std::string HeadlessDevToolsDelegate::GetDiscoveryPageHTML() { - return std::string(); + return ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_HEADLESS_LIB_DEVTOOLS_DISCOVERY_PAGE).as_string(); } std::string HeadlessDevToolsDelegate::GetFrontendResource( diff --git a/headless/lib/resources/devtools_discovery_page.html b/headless/lib/resources/devtools_discovery_page.html new file mode 100644 index 0000000..47534f7 --- /dev/null +++ b/headless/lib/resources/devtools_discovery_page.html @@ -0,0 +1,54 @@ +<html> +<head> +<title>Headless remote debugging</title> +<style> +</style> + +<script> +function onLoad() { + var tabs_list_request = new XMLHttpRequest(); + tabs_list_request.open("GET", "/json/list?t=" + new Date().getTime(), true); + tabs_list_request.onreadystatechange = onReady; + tabs_list_request.send(); +} + +function onReady() { + if(this.readyState == 4 && this.status == 200) { + if(this.response != null) + var responseJSON = JSON.parse(this.response); + for (var i = 0; i < responseJSON.length; ++i) + appendItem(responseJSON[i]); + } +} + +function appendItem(item_object) { + var frontend_ref; + if (item_object.devtoolsFrontendUrl) { + frontend_ref = document.createElement("a"); + frontend_ref.href = item_object.devtoolsFrontendUrl; + frontend_ref.title = item_object.title; + } else { + frontend_ref = document.createElement("div"); + frontend_ref.title = "The tab already has active debugging session"; + } + + var text = document.createElement("div"); + if (item_object.title) + text.innerText = item_object.title; + else + text.innerText = "(untitled tab)"; + text.style.cssText = "background-image:url(" + item_object.faviconUrl + ")"; + frontend_ref.appendChild(text); + + var item = document.createElement("p"); + item.appendChild(frontend_ref); + + document.getElementById("items").appendChild(item); +} +</script> +</head> +<body onload='onLoad()'> + <div id='caption'>Inspectable WebContents</div> + <div id='items'></div> +</body> +</html> diff --git a/headless/lib/resources/headless_lib_resources.grd b/headless/lib/resources/headless_lib_resources.grd new file mode 100644 index 0000000..060ab47 --- /dev/null +++ b/headless/lib/resources/headless_lib_resources.grd @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<grit latest_public_release="0" current_release="1"> + <outputs> + <output filename="grit/headless_lib_resources.h" type="rc_header"> + <emit emit_type='prepend'></emit> + </output> + <output filename="headless_lib_resources.pak" type="data_package" /> + </outputs> + <translations /> + <release seq="1"> + <includes> + <include name="IDR_HEADLESS_LIB_DEVTOOLS_DISCOVERY_PAGE" file="devtools_discovery_page.html" type="BINDATA" /> + </includes> + </release> +</grit> diff --git a/tools/gritsettings/resource_ids b/tools/gritsettings/resource_ids index aa93852..fe95f0d 100644 --- a/tools/gritsettings/resource_ids +++ b/tools/gritsettings/resource_ids @@ -302,6 +302,9 @@ "chrome/browser/resources/settings/settings_resources.grd": { "structures": [30920], }, + "headless/lib/resources/headless_lib_resources.grd": { + "includes": [30940], + }, # Resource ids starting at 31000 are reserved for projects built on Chromium. } |