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

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

Issue 2049363003: Adds support for headless chrome embedder mojo services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Abandon (for now) the concice bindings. Add BINDINGS_POLICY_HEADLESS and headless-mojo:// Created 4 years, 6 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_context_impl.cc
diff --git a/headless/lib/browser/headless_browser_context_impl.cc b/headless/lib/browser/headless_browser_context_impl.cc
index ed0188050ec88de09923d17faeab4fc65db6f886..9de33e55f1f82a39c02963b7d2feaeff445349de 100644
--- a/headless/lib/browser/headless_browser_context_impl.cc
+++ b/headless/lib/browser/headless_browser_context_impl.cc
@@ -13,10 +13,15 @@
#include "content/public/browser/storage_partition.h"
#include "headless/lib/browser/headless_browser_impl.h"
#include "headless/lib/browser/headless_url_request_context_getter.h"
+#include "headless/public/util/kv_map_protocol_handler.h"
#include "net/url_request/url_request_context.h"
namespace headless {
+namespace {
+const char kHeadlessMojomProtocol[] = "headless-mojom";
+}
+
// Contains net::URLRequestContextGetter required for resource loading.
// Must be destructed on the IO thread as per content::ResourceContext
// requirements.
@@ -202,10 +207,40 @@ HeadlessBrowserContext::Builder::SetProtocolHandlers(
return *this;
}
+HeadlessBrowserContext::Builder&
+HeadlessBrowserContext::Builder::AddJsMojoBindings(
+ const std::string& mojom_name,
+ const std::string& js_bindings) {
+ mojo_bindings_.emplace_back(mojom_name, js_bindings);
+ return *this;
+}
+
std::unique_ptr<HeadlessBrowserContext>
HeadlessBrowserContext::Builder::Build() {
+ if (!mojo_bindings_.empty()) {
+ std::unique_ptr<KVMapProtocolHandler> headless_mojom_protocol_handler(
+ new KVMapProtocolHandler());
+ for (const MojoBindings& binding : mojo_bindings_) {
+ headless_mojom_protocol_handler->InsertResponse(
+ binding.mojom_name,
+ KVMapProtocolHandler::Response(binding.js_bindings,
+ "application/javascript"));
+ }
+ protocol_handlers_[kHeadlessMojomProtocol] =
Sami 2016/06/27 11:10:42 Maybe DCHECK that we're not clobbering the users's
alex clarke (OOO till 29th) 2016/06/27 11:35:52 Done.
+ std::move(headless_mojom_protocol_handler);
+ }
+
return base::WrapUnique(new HeadlessBrowserContextImpl(
std::move(protocol_handlers_), browser_->options()));
}
+HeadlessBrowserContext::Builder::MojoBindings::MojoBindings() {}
+
+HeadlessBrowserContext::Builder::MojoBindings::MojoBindings(
+ const std::string& mojom_name,
+ const std::string& js_bindings)
+ : mojom_name(mojom_name), js_bindings(js_bindings) {}
+
+HeadlessBrowserContext::Builder::MojoBindings::~MojoBindings() {}
+
} // namespace headless

Powered by Google App Engine
This is Rietveld 408576698