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

Unified Diff: headless/app/headless_shell.cc

Issue 1805983002: headless: Implement client API generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Documentation Created 4 years, 8 months 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 side-by-side diff with in-line comments
Download patch
Index: headless/app/headless_shell.cc
diff --git a/headless/app/headless_shell.cc b/headless/app/headless_shell.cc
index 1031dbd5446b78a4fa95d7981971fc1a9faca677..f0905799d8a9556df34d6b95bb17d919b48f2ca6 100644
--- a/headless/app/headless_shell.cc
+++ b/headless/app/headless_shell.cc
@@ -13,13 +13,18 @@
#include "base/strings/string_number_conversions.h"
#include "content/public/common/content_switches.h"
#include "headless/app/headless_shell_switches.h"
+#include "headless/public/domains/page.h"
#include "headless/public/headless_browser.h"
+#include "headless/public/headless_devtools_client.h"
+#include "headless/public/headless_devtools_target.h"
#include "headless/public/headless_web_contents.h"
#include "net/base/ip_address.h"
#include "ui/gfx/geometry/size.h"
using headless::HeadlessBrowser;
+using headless::HeadlessDevToolsClient;
using headless::HeadlessWebContents;
+namespace page = headless::page;
namespace {
// Address where to listen to incoming DevTools connections.
@@ -29,12 +34,20 @@ const char kDevToolsHttpServerAddress[] = "127.0.0.1";
// A sample application which demonstrates the use of the headless API.
class HeadlessShell : public HeadlessWebContents::Observer {
public:
- HeadlessShell() : browser_(nullptr) {}
+ HeadlessShell()
+ : browser_(nullptr), devtools_client_(HeadlessDevToolsClient::Create()) {}
~HeadlessShell() override {
if (web_contents_)
web_contents_->RemoveObserver(this);
}
+ void DevToolsTargetReady() override {
+ web_contents_->GetDevToolsTarget()->AttachClient(devtools_client_.get());
+ // TODO(skyostil): Implement shorthand overloads for required parameters.
+ devtools_client_->GetPage()->Navigate(
+ page::NavigateParams::Builder().SetUrl("http://hs.fi").Build());
+ }
+
void OnStart(HeadlessBrowser* browser) {
browser_ = browser;
@@ -58,8 +71,14 @@ class HeadlessShell : public HeadlessWebContents::Observer {
}
void ShutdownIfNeeded() {
+ return;
altimin 2016/04/14 12:54:11 Unremoved debugging?
Sami 2016/04/15 14:43:44 Argh, yes. Cleaned up.
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
+ // Detach the devtools client so a remote debugger can connect.
+ if (devtools_client_) {
+ web_contents_->GetDevToolsTarget()->DetachClient(devtools_client_.get());
+ devtools_client_ = nullptr;
+ }
if (!command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
web_contents_ = nullptr;
browser_->Shutdown();
@@ -73,6 +92,7 @@ class HeadlessShell : public HeadlessWebContents::Observer {
private:
HeadlessBrowser* browser_; // Not owned.
+ std::unique_ptr<HeadlessDevToolsClient> devtools_client_;
std::unique_ptr<HeadlessWebContents> web_contents_;
DISALLOW_COPY_AND_ASSIGN(HeadlessShell);

Powered by Google App Engine
This is Rietveld 408576698