Remove Client relationship between mojo.Shell/mojo.Application

Instead of mojo.Shell and mojo.Application being clients of each other
they are now separate interfaces. An implementation of mojo.Application
receives a handle to the shell in its Initialize call, as described in
this doc:

https://docs.google.com/document/d/1xjt_TPjTu0elix8fNdBgWmnjJdJAtqSr1XDS_C-Ct8E/edit?usp=sharing

An analogous change is made to the content handler definition.

In C++, this is handled by the mojo::ApplicationImpl class which stores
shell handle in its implementation of Initialize. Thus the only change
for most C++ applications is the meaning of the handle in MojoMain is
different, although mains that use the ApplicationRunners do the same
thing with it.  Connecting to other apps is largely the same although
instead of grabbing the ApplicationImpl's client() to talk to the shell
code must now use the ApplicationImpl::shell() getter.

In JavaScript, the initialization sequence is a bit different although
this is hidden mostly in the Application class which calls initialize()
on its subclass with the same set of parameters. Connecting to another
application looks different, especially for sky code using the shell
proxy handle exposed via internals. Hans has some ideas about how to
make this a bit nicer.

Python apps similarly need to change their startup sequence a bit. I
didn't find a common library to take care of this dance, although it's
possible I just missed it.

Other languages probably a bit of reworking - I fixed everything here
that is covered by mojob.py test but some might be missing.

This patch also uses typed handles (i.e. InterfacePtr<> or
InterfaceRequest<> or their type aliases) wherever possible instead of
ScopedMessagePipeHandle for clarity.

R=davemoore@chromium.org

Review URL: https://codereview.chromium.org/868463008
This commit is contained in:
James Robinson 2015-01-26 17:53:08 -08:00
parent df4b5c5e55
commit 2ff9d2d006

View File

@ -5,14 +5,19 @@
<import src="/mojo/public/sky/connection.sky" as="connection" />
<import src="/mojo/services/network/public/interfaces/network_service.mojom.sky" as="net" />
<import src="/mojo/services/network/public/interfaces/url_loader.mojom.sky" as="loader" />
<import src="/mojo/services/public/sky/application.sky" as="application" />
<import src="/mojo/services/public/sky/shell.sky" as="shell" />
<import src="/mojo/public/interfaces/application/shell.mojom.sky" as="shellMojom" />
<script>
const Shell = shell.Shell;
describe('Mojo network_service', function() {
this.enableTimeouts(false);
it('should be able to fetch text files', function(done) {
var app = new application.Application(internals.passShellProxyHandle());
var netService = app.shell.connectToService(
var shellHandle = internals.passShellProxyHandle();
var shellProxy = connection.bindHandleToProxy(shellHandle, shellMojom.Shell);
var shell = new Shell(shellProxy);
var netService = shell.connectToService(
"mojo:network_service", net.NetworkService);
var urlLoader;
@ -24,11 +29,21 @@ describe('Mojo network_service', function() {
urlRequest.url = "http://127.0.0.1:8000/sky/tests/services/resources/pass.txt";
urlRequest.method = "GET";
urlRequest.auto_follow_redirects = true;
var urlRequestPromise = urlLoader.start(urlRequest);
urlRequestPromise.then(function(result) {
if (result.response.error) {
assert.ok(false, "network request failed " + result.response.error.code + " "
+ result.response.error.description);
done();
}
console.log("url => " + result.response["url"]);
console.log("status_line => " + result.response["status_line"]);
console.log("mime_type => " + result.response["mime_type"]);
var start = Date.now();
while (Date.now() - start < 3) {}
var drainDataPromise = core.drainData(result.response.body);
drainDataPromise.then(function(result) {
console.log("read " + result.buffer.byteLength + " bytes");