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

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: Changes for Sami 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..87407e87e2e123dfaed525be1dffbf9a3e25a7b7 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/in_memory_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,42 @@ 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<InMemoryProtocolHandler> headless_mojom_protocol_handler(
+ new InMemoryProtocolHandler());
+ for (const MojoBindings& binding : mojo_bindings_) {
+ headless_mojom_protocol_handler->InsertResponse(
+ binding.mojom_name,
+ InMemoryProtocolHandler::Response(binding.js_bindings,
+ "application/javascript"));
+ }
+ DCHECK(protocol_handlers_.find(kHeadlessMojomProtocol) ==
+ protocol_handlers_.end());
+ protocol_handlers_[kHeadlessMojomProtocol] =
+ 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