Commit 6fbb4139 authored by ben's avatar ben Committed by Commit bot

Pass CapabilityFilter via CreateInstanceForHandle

http://crbug.com/555392

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

Cr-Commit-Position: refs/heads/master@{#361255}
parent 53588a7c
...@@ -4,14 +4,15 @@ ...@@ -4,14 +4,15 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/thread_task_runner_handle.h" #include "base/thread_task_runner_handle.h"
#include "components/mus/public/interfaces/gpu.mojom.h"
#include "content/browser/mojo/mojo_shell_client_host.h" #include "content/browser/mojo/mojo_shell_client_host.h"
#include "content/common/mojo/mojo_messages.h" #include "content/common/mojo/mojo_messages.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/common/mojo_shell_connection.h" #include "content/public/common/mojo_shell_connection.h"
#include "ipc/ipc_sender.h" #include "ipc/ipc_sender.h"
#include "mojo/application/public/cpp/application_impl.h" #include "mojo/application/public/cpp/application_impl.h"
#include "mojo/application/public/interfaces/application_manager.mojom.h"
#include "mojo/converters/network/network_type_converters.h" #include "mojo/converters/network/network_type_converters.h"
#include "mojo/shell/application_manager.mojom.h"
#include "third_party/mojo/src/mojo/edk/embedder/embedder.h" #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
#include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h" #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h"
...@@ -82,8 +83,15 @@ void RegisterChildWithExternalShell(int child_process_id, ...@@ -82,8 +83,15 @@ void RegisterChildWithExternalShell(int child_process_id,
// http://crbug.com/555393 // http://crbug.com/555393
std::string url = std::string url =
base::StringPrintf("exe:chrome_renderer%d", child_process_id); base::StringPrintf("exe:chrome_renderer%d", child_process_id);
mojo::CapabilityFilterPtr filter(mojo::CapabilityFilter::New());
mojo::Array<mojo::String> window_manager_interfaces;
window_manager_interfaces.push_back(mus::mojom::Gpu::Name_);
filter->filter.insert("mojo:mus", window_manager_interfaces.Pass());
application_manager->CreateInstanceForHandle( application_manager->CreateInstanceForHandle(
mojo::ScopedHandle(mojo::Handle(handle.release().value())), url); mojo::ScopedHandle(mojo::Handle(handle.release().value())),
url,
filter.Pass());
// Send the other end to the child via Chrome IPC. // Send the other end to the child via Chrome IPC.
base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle( base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle(
......
...@@ -8,6 +8,7 @@ import("//mojo/public/tools/bindings/mojom.gni") ...@@ -8,6 +8,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") { mojom("interfaces") {
sources = [ sources = [
"application.mojom", "application.mojom",
"application_manager.mojom",
"content_handler.mojom", "content_handler.mojom",
"service_provider.mojom", "service_provider.mojom",
"shell.mojom", "shell.mojom",
......
...@@ -4,17 +4,15 @@ ...@@ -4,17 +4,15 @@
module mojo.shell.mojom; module mojo.shell.mojom;
import "mojo/application/public/interfaces/shell.mojom";
interface ApplicationManager { interface ApplicationManager {
// Instructs the ApplicationManager to create an instance for an existing // Instructs the ApplicationManager to create an instance for an existing
// process at the other end of |channel|, and perform applicable // process at the other end of |channel|, and perform applicable
// initialization. This assumes the target process will bind the other end of // initialization. This assumes the target process will bind the other end of
// channel to an implementation of ChildController and bind an Application // channel to an implementation of ChildController and bind an Application
// request there. // request there.
// TODO(beng): we should probably have an Identity mojom struct. CreateInstanceForHandle(handle channel,
// TODO(beng): for this to be used in production, it's going to have to take string url,
// a fully qualified Identity complete with CapabilityFilter, mojo.CapabilityFilter filter);
// otherwise child processes registered with the shell will be
// able to request any application/service.
// http://crbug.com/555392
CreateInstanceForHandle(handle channel, string url);
}; };
...@@ -205,6 +205,7 @@ ...@@ -205,6 +205,7 @@
'variables': { 'variables': {
'mojom_files': [ 'mojom_files': [
'application/public/interfaces/application.mojom', 'application/public/interfaces/application.mojom',
'application/public/interfaces/application_manager.mojom',
'application/public/interfaces/content_handler.mojom', 'application/public/interfaces/content_handler.mojom',
'application/public/interfaces/service_provider.mojom', 'application/public/interfaces/service_provider.mojom',
'application/public/interfaces/shell.mojom', 'application/public/interfaces/shell.mojom',
......
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
'<(DEPTH)/mojo/mojo_base.gyp:mojo_common_lib', '<(DEPTH)/mojo/mojo_base.gyp:mojo_common_lib',
'<(DEPTH)/mojo/mojo_base.gyp:mojo_environment_chromium', '<(DEPTH)/mojo/mojo_base.gyp:mojo_environment_chromium',
'<(DEPTH)/mojo/mojo_base.gyp:mojo_url_type_converters', '<(DEPTH)/mojo/mojo_base.gyp:mojo_url_type_converters',
'<(DEPTH)/mojo/mojo_shell.gyp:mojo_shell_interfaces',
'<(DEPTH)/url/url.gyp:url_lib', '<(DEPTH)/url/url.gyp:url_lib',
], ],
}, { }, {
...@@ -123,16 +122,5 @@ ...@@ -123,16 +122,5 @@
'includes': [ 'includes': [
'../third_party/mojo/mojom_bindings_generator_explicit.gypi', '../third_party/mojo/mojom_bindings_generator_explicit.gypi',
], ],
}, {
'target_name': 'mojo_shell_interfaces',
'type': 'none',
'variables': {
'mojom_files': [
'shell/application_manager.mojom',
],
},
'includes': [
'../third_party/mojo/mojom_bindings_generator_explicit.gypi',
],
}], }],
} }
...@@ -50,7 +50,6 @@ source_set("shell") { ...@@ -50,7 +50,6 @@ source_set("shell") {
"//url", "//url",
] ]
deps = [ deps = [
":interfaces",
"//base/third_party/dynamic_annotations", "//base/third_party/dynamic_annotations",
"//crypto:crypto", "//crypto:crypto",
"//mojo/application/public/cpp:sources", "//mojo/application/public/cpp:sources",
...@@ -115,12 +114,6 @@ mojom("test_bindings") { ...@@ -115,12 +114,6 @@ mojom("test_bindings") {
] ]
} }
mojom("interfaces") {
sources = [
"application_manager.mojom",
]
}
mojo_native_application("apptests") { mojo_native_application("apptests") {
output_name = "mojo_shell_apptests" output_name = "mojo_shell_apptests"
testonly = true testonly = true
...@@ -157,11 +150,11 @@ executable("application_manager_apptest_driver") { ...@@ -157,11 +150,11 @@ executable("application_manager_apptest_driver") {
"//base", "//base",
"//base:base_static", "//base:base_static",
"//mojo/application/public/cpp", "//mojo/application/public/cpp",
"//mojo/application/public/interfaces",
"//mojo/common:common_base", "//mojo/common:common_base",
"//mojo/converters/network", "//mojo/converters/network",
"//mojo/runner:init", "//mojo/runner:init",
"//mojo/runner/child:test_native_main", "//mojo/runner/child:test_native_main",
"//mojo/shell:interfaces",
"//third_party/mojo/src/mojo/edk/system", "//third_party/mojo/src/mojo/edk/system",
] ]
} }
......
...@@ -117,14 +117,16 @@ ApplicationInstance* ApplicationManager::GetApplicationInstance( ...@@ -117,14 +117,16 @@ ApplicationInstance* ApplicationManager::GetApplicationInstance(
} }
void ApplicationManager::CreateInstanceForHandle(ScopedHandle channel, void ApplicationManager::CreateInstanceForHandle(ScopedHandle channel,
const GURL& url) { const GURL& url,
CapabilityFilterPtr filter) {
// Instances created by others are considered unique, and thus have no // Instances created by others are considered unique, and thus have no
// identity. As such they cannot be connected to by anyone else, and so we // identity. As such they cannot be connected to by anyone else, and so we
// never call ConnectToClient(). // never call ConnectToClient().
// TODO(beng): GetPermissiveCapabilityFilter() here obviously cannot make it // TODO(beng): GetPermissiveCapabilityFilter() here obviously cannot make it
// to production. See note in application_manager.mojom. // to production. See note in application_manager.mojom.
// http://crbug.com/555392 // http://crbug.com/555392
Identity target_id(url, std::string(), GetPermissiveCapabilityFilter()); CapabilityFilter local_filter = filter->filter.To<CapabilityFilter>();
Identity target_id(url, std::string(), local_filter);
InterfaceRequest<Application> application_request = InterfaceRequest<Application> application_request =
CreateInstance(target_id, base::Closure(), nullptr); CreateInstance(target_id, base::Closure(), nullptr);
NativeRunner* runner = NativeRunner* runner =
......
...@@ -92,7 +92,9 @@ class ApplicationManager { ...@@ -92,7 +92,9 @@ class ApplicationManager {
ApplicationInstance* GetApplicationInstance(const Identity& identity) const; ApplicationInstance* GetApplicationInstance(const Identity& identity) const;
void CreateInstanceForHandle(ScopedHandle channel, const GURL& url); void CreateInstanceForHandle(ScopedHandle channel,
const GURL& url,
CapabilityFilterPtr filter);
private: private:
using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>; using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>;
......
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
#include "mojo/application/public/cpp/application_delegate.h" #include "mojo/application/public/cpp/application_delegate.h"
#include "mojo/application/public/cpp/application_impl.h" #include "mojo/application/public/cpp/application_impl.h"
#include "mojo/application/public/cpp/interface_factory.h" #include "mojo/application/public/cpp/interface_factory.h"
#include "mojo/application/public/interfaces/application_manager.mojom.h"
#include "mojo/common/weak_binding_set.h" #include "mojo/common/weak_binding_set.h"
#include "mojo/converters/network/network_type_converters.h" #include "mojo/converters/network/network_type_converters.h"
#include "mojo/runner/child/test_native_main.h" #include "mojo/runner/child/test_native_main.h"
#include "mojo/runner/init.h" #include "mojo/runner/init.h"
#include "mojo/shell/application_manager.mojom.h"
#include "mojo/shell/application_manager_apptests.mojom.h" #include "mojo/shell/application_manager_apptests.mojom.h"
#include "third_party/mojo/src/mojo/edk/embedder/embedder.h" #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
...@@ -79,9 +79,15 @@ class TargetApplicationDelegate : public mojo::ApplicationDelegate, ...@@ -79,9 +79,15 @@ class TargetApplicationDelegate : public mojo::ApplicationDelegate,
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
base::ThreadTaskRunnerHandle::Get())); base::ThreadTaskRunnerHandle::Get()));
mojo::CapabilityFilterPtr filter(mojo::CapabilityFilter::New());
mojo::Array<mojo::String> test_interfaces;
test_interfaces.push_back(
mojo::shell::test::mojom::CreateInstanceForHandleTest::Name_);
filter->filter.insert("mojo:mojo_shell_apptests", test_interfaces.Pass());
application_manager->CreateInstanceForHandle( application_manager->CreateInstanceForHandle(
mojo::ScopedHandle(mojo::Handle(handle.release().value())), mojo::ScopedHandle(mojo::Handle(handle.release().value())),
"exe:application_manager_apptest_target"); "exe:application_manager_apptest_target",
filter.Pass());
// Put the other end on the command line used to launch the target. // Put the other end on the command line used to launch the target.
platform_channel_pair.PrepareToPassClientHandleToChildProcess( platform_channel_pair.PrepareToPassClientHandleToChildProcess(
&child_command_line, &handle_passing_info); &child_command_line, &handle_passing_info);
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "mojo/application/public/cpp/application_connection.h" #include "mojo/application/public/cpp/application_connection.h"
#include "mojo/application/public/cpp/application_delegate.h" #include "mojo/application/public/cpp/application_delegate.h"
#include "mojo/application/public/cpp/application_impl.h" #include "mojo/application/public/cpp/application_impl.h"
#include "mojo/converters/network/network_type_converters.h"
#include "mojo/runner/child/test_native_main.h" #include "mojo/runner/child/test_native_main.h"
#include "mojo/runner/init.h" #include "mojo/runner/init.h"
#include "mojo/shell/application_manager_apptests.mojom.h" #include "mojo/shell/application_manager_apptests.mojom.h"
...@@ -25,9 +24,7 @@ class TargetApplicationDelegate : public mojo::ApplicationDelegate { ...@@ -25,9 +24,7 @@ class TargetApplicationDelegate : public mojo::ApplicationDelegate {
// mojo::ApplicationDelegate: // mojo::ApplicationDelegate:
void Initialize(mojo::ApplicationImpl* app) override { void Initialize(mojo::ApplicationImpl* app) override {
CreateInstanceForHandleTestPtr service; CreateInstanceForHandleTestPtr service;
mojo::ApplicationImpl::ConnectParams params( app->ConnectToService("mojo:mojo_shell_apptests", &service);
std::string("mojo:mojo_shell_apptests"));
app->ConnectToService(&params, &service);
service->Ping("From Target"); service->Ping("From Target");
} }
bool ConfigureIncomingConnection( bool ConfigureIncomingConnection(
......
...@@ -28,9 +28,11 @@ void ShellApplicationDelegate::Create( ...@@ -28,9 +28,11 @@ void ShellApplicationDelegate::Create(
bindings_.AddBinding(this, request.Pass()); bindings_.AddBinding(this, request.Pass());
} }
void ShellApplicationDelegate::CreateInstanceForHandle(ScopedHandle channel, void ShellApplicationDelegate::CreateInstanceForHandle(
const String& url) { ScopedHandle channel,
manager_->CreateInstanceForHandle(channel.Pass(), GURL(url)); const String& url,
CapabilityFilterPtr filter) {
manager_->CreateInstanceForHandle(channel.Pass(), GURL(url), filter.Pass());
} }
} // namespace shell } // namespace shell
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "mojo/application/public/cpp/interface_factory.h" #include "mojo/application/public/cpp/interface_factory.h"
#include "mojo/application/public/interfaces/application_manager.mojom.h"
#include "mojo/common/weak_binding_set.h" #include "mojo/common/weak_binding_set.h"
#include "mojo/shell/application_manager.mojom.h"
namespace mojo { namespace mojo {
namespace shell { namespace shell {
...@@ -36,7 +36,8 @@ class ShellApplicationDelegate ...@@ -36,7 +36,8 @@ class ShellApplicationDelegate
// Overridden from mojom::ApplicationManager: // Overridden from mojom::ApplicationManager:
void CreateInstanceForHandle(ScopedHandle channel, void CreateInstanceForHandle(ScopedHandle channel,
const String& url) override; const String& url,
CapabilityFilterPtr filter) override;
mojo::shell::ApplicationManager* manager_; mojo::shell::ApplicationManager* manager_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment