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

Unified Diff: headless/lib/browser/headless_browser_impl.cc

Issue 1674263002: headless: Initial headless embedder API implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add pak file generation. Created 4 years, 10 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/lib/browser/headless_browser_impl.cc
diff --git a/headless/lib/browser/headless_browser_impl.cc b/headless/lib/browser/headless_browser_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e8bbcb06fe87815bb1b92a0afc3a8724ae89312f
--- /dev/null
+++ b/headless/lib/browser/headless_browser_impl.cc
@@ -0,0 +1,92 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "headless/lib/browser/headless_browser_impl.h"
+
+#include "base/thread_task_runner_handle.h"
+#include "content/public/app/content_main.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/web_contents.h"
+#include "headless/lib/browser/headless_browser_context.h"
+#include "headless/lib/browser/headless_browser_main_parts.h"
+#include "headless/lib/browser/headless_web_contents_impl.h"
+#include "headless/lib/headless_content_main_delegate.h"
+#include "ui/aura/env.h"
+#include "ui/aura/window_tree_host.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace headless {
+
+HeadlessBrowserImpl::HeadlessBrowserImpl(
+ const StartCallback& on_start_callback,
+ const HeadlessBrowser::Options& options)
Ryan Sleevi 2016/02/22 22:01:21 STYLE: Your .cc order should match your .h order -
Sami 2016/02/23 20:19:07 Done.
+ : on_start_callback_(on_start_callback),
+ options_(options),
+ browser_main_parts_(nullptr) {}
+
+HeadlessBrowserImpl::~HeadlessBrowserImpl() {}
+
+scoped_ptr<HeadlessWebContents> HeadlessBrowserImpl::CreateWebContents(
+ const gfx::Size& size) {
+ DCHECK(BrowserMainThread()->BelongsToCurrentThread());
+ return make_scoped_ptr(new HeadlessWebContentsImpl(
+ browser_context(), window_tree_host_->window(), size));
+}
+
+scoped_refptr<base::SingleThreadTaskRunner>
+HeadlessBrowserImpl::BrowserMainThread() const {
+ return content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::UI);
+}
+
+void HeadlessBrowserImpl::Stop() {
+ DCHECK(BrowserMainThread()->BelongsToCurrentThread());
+ BrowserMainThread()->PostTask(FROM_HERE,
+ base::MessageLoop::QuitWhenIdleClosure());
Ryan Sleevi 2016/02/22 22:01:21 Are you sure this is the right place to put this?
Sami 2016/02/23 20:19:08 The RunLoop is actually still owned by content::Br
+}
+
+HeadlessBrowserContext* HeadlessBrowserImpl::browser_context() const {
+ DCHECK(BrowserMainThread()->BelongsToCurrentThread());
+ DCHECK(browser_main_parts());
+ return browser_main_parts()->browser_context();
+}
+
+HeadlessBrowserMainParts* HeadlessBrowserImpl::browser_main_parts() const {
+ DCHECK(BrowserMainThread()->BelongsToCurrentThread());
+ return browser_main_parts_;
+}
+
+void HeadlessBrowserImpl::set_browser_main_parts(
+ HeadlessBrowserMainParts* browser_main_parts) {
+ DCHECK(!browser_main_parts_);
+ browser_main_parts_ = browser_main_parts;
+}
+
+void HeadlessBrowserImpl::RunOnStartCallback() {
+ DCHECK(aura::Env::GetInstance());
+ window_tree_host_.reset(aura::WindowTreeHost::Create(gfx::Rect()));
+ window_tree_host_->InitHost();
+
+ if (!on_start_callback_.is_null()) {
+ on_start_callback_.Run(this);
+ on_start_callback_ = StartCallback();
+ }
Ryan Sleevi 2016/02/22 22:01:21 DESIGN: This is a confusing API contract that you
Sami 2016/02/23 20:19:07 Good point. This was here only for testing -- I've
+}
+
+int HeadlessBrowser::Run(const Options& options,
+ const StartCallback& on_browser_start_callback) {
+ scoped_ptr<HeadlessBrowserImpl> browser(
+ new HeadlessBrowserImpl(on_browser_start_callback, options));
+
+ // TODO(skyostil): Implement custom message pumps.
+ DCHECK(!options.message_pump);
+
+ headless::HeadlessContentMainDelegate delegate(std::move(browser));
+ content::ContentMainParams params(&delegate);
+ params.argc = options.argc;
+ params.argv = options.argv;
+ return content::ContentMain(params);
+}
+
+} // namespace headless

Powered by Google App Engine
This is Rietveld 408576698