Skip to content

Commit

Permalink
Allow mojo_runner to connect to arbitrary executables.
Browse files Browse the repository at this point in the history
- Introduces a new scheme "exe" which loads an executable alongside mojo_runner. TODO is some more security checking around this to prevent arbitrary apps from launching executables but since this is implemented in mojo_runner it's not in any production code right now.
- Includes an apptest of a .mojo app that connects to an executable and binds a service provided by it.
- Creates a new child library that makes it easy to bring up a runner controller thread in an arbitrary executable.

R=jam@chromium.org
http://crbug.com/548694

Review URL: https://codereview.chromium.org/1419293003

Cr-Commit-Position: refs/heads/master@{#357034}
  • Loading branch information
ben authored and Commit bot committed Oct 30, 2015
1 parent 1c31871 commit 48799d7
Show file tree
Hide file tree
Showing 20 changed files with 625 additions and 47 deletions.
3 changes: 0 additions & 3 deletions mojo/application/public/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,4 @@ source_set("test_support") {
if (is_android) {
data_deps += [ "//mojo/android" ]
}
if (!is_component_build) {
data_deps += [ "//mojo/runner" ]
}
}
24 changes: 17 additions & 7 deletions mojo/fetcher/url_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,32 @@ URLResolver::URLResolver(const GURL& mojo_base_url)
DCHECK(mojo_base_url_.is_valid());
// Needed to treat first component of mojo URLs as host, not path.
url::AddStandardScheme("mojo", url::SCHEME_WITHOUT_AUTHORITY);
url::AddStandardScheme("exe", url::SCHEME_WITHOUT_AUTHORITY);
}

URLResolver::~URLResolver() {
}

GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const {
if (mojo_url.scheme() != "mojo") {
if (mojo_url.SchemeIs("mojo")) {
// It's still a mojo: URL, use the default mapping scheme.
std::string query;
GURL base_url = shell::GetBaseURLAndQuery(mojo_url, &query);
const std::string host = base_url.host();
return mojo_base_url_.Resolve(host + "/" + host + ".mojo" + query);
} else if (mojo_url.SchemeIs("exe")) {
#if defined OS_WIN
std::string extension = ".exe";
#else
std::string extension;
#endif
std::string query;
GURL base_url = shell::GetBaseURLAndQuery(mojo_url, &query);
return mojo_base_url_.Resolve(base_url.host() + extension);
} else {
// The mapping has produced some sort of non-mojo: URL - file:, http:, etc.
return mojo_url;
}

// It's still a mojo: URL, use the default mapping scheme.
std::string query;
GURL base_url = shell::GetBaseURLAndQuery(mojo_url, &query);
const std::string host = base_url.host();
return mojo_base_url_.Resolve(host + "/" + host + ".mojo" + query);
}

} // namespace fetcher
Expand Down
35 changes: 10 additions & 25 deletions mojo/runner/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ group("runner") {

deps = [
":mojo_runner",
"//mojo/runner/child",
]
}

Expand Down Expand Up @@ -94,18 +95,14 @@ executable("mojo_runner") {
}
}

source_set("in_process_native_runner") {
source_set("init") {
sources = [
"in_process_native_runner.cc",
"in_process_native_runner.h",
]

public_deps = [
":native_application_support",
"//mojo/shell",
"init.cc",
"init.h",
]

deps = [
":switches",
"//base",
]
}
Expand All @@ -118,8 +115,8 @@ source_set("lib") {
"child_process_host.h",
"context.cc",
"context.h",
"init.cc",
"init.h",
"in_process_native_runner.cc",
"in_process_native_runner.h",
"out_of_process_native_runner.cc",
"out_of_process_native_runner.h",
"scoped_user_data_dir.cc",
Expand All @@ -131,8 +128,7 @@ source_set("lib") {
]

deps = [
":child_process_bindings",
":in_process_native_runner",
":init",
":native_application_support",
"//base",
"//base/third_party/dynamic_annotations",
Expand All @@ -142,6 +138,7 @@ source_set("lib") {
"//mojo/application/public/cpp",
"//mojo/message_pump",
"//mojo/package_manager",
"//mojo/runner/child:interfaces",
"//mojo/services/network/public/interfaces",
"//mojo/services/tracing/public/cpp",
"//mojo/services/tracing/public/interfaces",
Expand All @@ -165,6 +162,7 @@ source_set("lib") {
}

public_deps = [
":init",
":switches",
]

Expand Down Expand Up @@ -419,18 +417,6 @@ if (is_android) {
}
}

mojom("child_process_bindings") {
sources = [
"child_process.mojom",
]

deps = [
"//mojo/application/public/interfaces",
]

import_dirs = [ "//mojo/services" ]
}

test("mojo_runner_unittests") {
sources = [
"../fetcher/about_fetcher_unittest.cc",
Expand All @@ -451,7 +437,6 @@ test("mojo_runner_unittests") {
]

deps = [
":in_process_native_runner",
":lib",
"//base",
"//base:i18n",
Expand Down
97 changes: 97 additions & 0 deletions mojo/runner/child/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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.

import("//mojo/public/mojo_application.gni")
import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni")

group("child") {
testonly = true
deps = [
":lib",
":apptests",
]
}

source_set("lib") {
sources = [
"runner_connection.cc",
"runner_connection.h",
]

deps = [
":interfaces",
"//base",
"//mojo/application/public/interfaces",
"//mojo/message_pump",
"//third_party/mojo/src/mojo/edk/system",
]
}

mojom("interfaces") {
sources = [
"child_controller.mojom",
]

deps = [
"//mojo/application/public/interfaces",
]

import_dirs = [ "//mojo/services" ]
}

mojom("apptest_interfaces") {
sources = [
"test_native_service.mojom",
]

deps = [
"//mojo/application/public/interfaces",
]

import_dirs = [ "//mojo/services" ]
}

mojo_native_application("apptests") {
output_name = "mojo_runner_child_apptest"
testonly = true

sources = [
"native_apptest.cc",
]

deps = [
":apptest_interfaces",
"//base",
"//base/test:test_config",
"//mojo/application/public/cpp:sources",
"//mojo/application/public/cpp:test_support",
"//mojo/common:common_base",
"//mojo/converters/network:network",
]

data_deps = [
":native_target",
]
}

executable("native_target") {
output_name = "mojo_runner_child_apptest_native_target"
testonly = true

sources = [
"native_apptest_target.cc",
]

deps = [
":apptest_interfaces",
":lib",
"//base",
"//mojo/application/public/cpp",
"//mojo/application/public/interfaces",
"//mojo/common:common_base",
"//mojo/message_pump",
"//mojo/runner:init",
"//third_party/mojo/src/mojo/edk/embedder:embedder",
]
}
File renamed without changes.
42 changes: 42 additions & 0 deletions mojo/runner/child/native_apptest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 "base/bind.h"
#include "base/macros.h"
#include "mojo/application/public/cpp/application_impl.h"
#include "mojo/application/public/cpp/application_test_base.h"
#include "mojo/converters/network/network_type_converters.h"
#include "mojo/runner/child/test_native_service.mojom.h"

namespace mojo {
namespace runner {
namespace {
void InvertCallback(bool* result, bool from_native) {
*result = from_native;
}
} // namespace

using NativeAppTest = mojo::test::ApplicationTestBase;

TEST_F(NativeAppTest, Connect) {
test::TestNativeServicePtr native_service;
application_impl()->ConnectToService(
mojo::URLRequest::From(
std::string("exe:mojo_runner_child_apptest_native_target")),
&native_service);

bool result = false;
native_service->Invert(
true, base::Bind(&InvertCallback, base::Unretained(&result)));
native_service.WaitForIncomingResponse();
EXPECT_FALSE(result);

native_service->Invert(
false, base::Bind(&InvertCallback, base::Unretained(&result)));
native_service.WaitForIncomingResponse();
EXPECT_TRUE(result);
}

} // namespace runner
} // namespace mojo
Loading

0 comments on commit 48799d7

Please sign in to comment.