diff options
Diffstat (limited to 'mojo/services/public')
15 files changed, 336 insertions, 20 deletions
diff --git a/mojo/services/public/cpp/view_manager/BUILD.gn b/mojo/services/public/cpp/view_manager/BUILD.gn index 173abf1..22381a3 100644 --- a/mojo/services/public/cpp/view_manager/BUILD.gn +++ b/mojo/services/public/cpp/view_manager/BUILD.gn @@ -19,6 +19,8 @@ source_set("view_manager") { "view_manager_context.h", "view_manager_delegate.h", "view_observer.h", + "view_tracker.cc", + "view_tracker.h", "window_manager_delegate.h", ] diff --git a/mojo/services/public/cpp/view_manager/lib/view.cc b/mojo/services/public/cpp/view_manager/lib/view.cc index 84a0455..b371000 100644 --- a/mojo/services/public/cpp/view_manager/lib/view.cc +++ b/mojo/services/public/cpp/view_manager/lib/view.cc @@ -311,6 +311,10 @@ void View::Reorder(View* relative, OrderDirection direction) { } bool View::Contains(View* child) const { + if (!child) + return false; + if (child == this) + return true; if (manager_) CHECK_EQ(ViewPrivate(child).view_manager(), manager_); for (View* p = child->parent(); p; p = p->parent()) { diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_factory.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_factory.cc index 91bc265..84fa87d 100644 --- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_factory.cc +++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_factory.cc @@ -27,6 +27,7 @@ ViewManagerClientFactory::WeakBindViewManagerToPipe( scoped_ptr<ViewManagerClientImpl> client( new ViewManagerClientImpl(delegate, shell)); WeakBindToPipe(client.get(), handle.Pass()); + client->OnConnectionEstablished(); return client.Pass(); } @@ -34,7 +35,9 @@ ViewManagerClientFactory::WeakBindViewManagerToPipe( void ViewManagerClientFactory::Create( ApplicationConnection* connection, InterfaceRequest<ViewManagerClient> request) { - BindToRequest(new ViewManagerClientImpl(delegate_, shell_), &request); + ViewManagerClientImpl* impl = + BindToRequest(new ViewManagerClientImpl(delegate_, shell_), &request); + impl->OnConnectionEstablished(); } } // namespace mojo diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc index 860beb5..cc04f04 100644 --- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc +++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc @@ -199,8 +199,9 @@ void ViewManagerClientImpl::Embed( Id view_id, ServiceProviderPtr service_provider) { DCHECK(connected_); - service_->Embed(url, view_id, service_provider.Pass(), - ActionCompletedCallback()); + service_->Embed(url, view_id, + MakeRequest<ServiceProvider>(service_provider.PassMessagePipe()), + ActionCompletedCallback()); } void ViewManagerClientImpl::AddView(View* view) { diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h index f40e3a8..47f08cd 100644 --- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h +++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h @@ -73,6 +73,8 @@ class ViewManagerClientImpl : public ViewManager, void AddView(View* view); void RemoveView(Id view_id); + void OnConnectionEstablished(); + private: friend class RootObserver; @@ -83,9 +85,6 @@ class ViewManagerClientImpl : public ViewManager, const std::vector<View*>& GetRoots() const override; View* GetViewById(Id id) override; - // Overridden from InterfaceImpl: - void OnConnectionEstablished() override; - // Overridden from ViewManagerClient: void OnEmbed(ConnectionSpecificId connection_id, const String& creator_url, diff --git a/mojo/services/public/cpp/view_manager/view_tracker.cc b/mojo/services/public/cpp/view_manager/view_tracker.cc new file mode 100644 index 0000000..453d6f9 --- /dev/null +++ b/mojo/services/public/cpp/view_manager/view_tracker.cc @@ -0,0 +1,41 @@ +// Copyright 2014 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 "mojo/services/public/cpp/view_manager/view_tracker.h" + +namespace mojo { + +ViewTracker::ViewTracker() { +} + +ViewTracker::~ViewTracker() { + for (Views::iterator i = views_.begin(); i != views_.end(); ++i) + (*i)->RemoveObserver(this); +} + +void ViewTracker::Add(View* view) { + if (views_.count(view)) + return; + + view->AddObserver(this); + views_.insert(view); +} + +void ViewTracker::Remove(View* view) { + if (views_.count(view)) { + views_.erase(view); + view->RemoveObserver(this); + } +} + +bool ViewTracker::Contains(View* view) { + return views_.count(view) > 0; +} + +void ViewTracker::OnViewDestroying(View* view) { + DCHECK_GT(views_.count(view), 0u); + Remove(view); +} + +} // namespace mojo diff --git a/mojo/services/public/cpp/view_manager/view_tracker.h b/mojo/services/public/cpp/view_manager/view_tracker.h new file mode 100644 index 0000000..71a218a --- /dev/null +++ b/mojo/services/public/cpp/view_manager/view_tracker.h @@ -0,0 +1,47 @@ +// Copyright 2014 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. + +#ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TRACKER_H_ +#define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TRACKER_H_ + +#include <set> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "mojo/services/public/cpp/view_manager/view_observer.h" + +namespace mojo { + +class ViewTracker : public ViewObserver { + public: + using Views = std::set<View*>; + + ViewTracker(); + ~ViewTracker() override; + + // Returns the set of views being observed. + const std::set<View*>& views() const { return views_; } + + // Adds |view| to the set of Views being tracked. + void Add(View* view); + + // Removes |view| from the set of views being tracked. + void Remove(View* view); + + // Returns true if |view| was previously added and has not been removed or + // deleted. + bool Contains(View* view); + + // ViewObserver overrides: + virtual void OnViewDestroying(View* view) override; + + private: + Views views_; + + DISALLOW_COPY_AND_ASSIGN(ViewTracker); +}; + +} // namespace mojo + +#endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TRACKER_H_ diff --git a/mojo/services/public/interfaces/accessibility/BUILD.gn b/mojo/services/public/interfaces/accessibility/BUILD.gn new file mode 100644 index 0000000..64b570b --- /dev/null +++ b/mojo/services/public/interfaces/accessibility/BUILD.gn @@ -0,0 +1,15 @@ +# Copyright 2014 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/tools/bindings/mojom.gni") + +mojom("accessibility") { + sources = [ + "accessibility.mojom", + ] + + deps = [ + "//mojo/services/public/interfaces/geometry", + ] +} diff --git a/mojo/services/public/interfaces/accessibility/accessibility.mojom b/mojo/services/public/interfaces/accessibility/accessibility.mojom new file mode 100644 index 0000000..abc97c3 --- /dev/null +++ b/mojo/services/public/interfaces/accessibility/accessibility.mojom @@ -0,0 +1,35 @@ +// Copyright 2014 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. + +module mojo; + +import "mojo/services/public/interfaces/geometry/geometry.mojom"; + +interface AxProvider { + GetTree() => (array<AxNode> nodes); +}; + +struct AxNode { + // Must be non-zero. + uint32 id; + + // Can be zero if the node has no parent or next sibling. + uint32 parent_id; + uint32 next_sibling_id; + + mojo.Rect bounds; + + // At most one of the below will be present. + // TODO(aa): These should become a union. + AxLink? link; + AxText? text; +}; + +struct AxLink { + string url; +}; + +struct AxText { + string content; +}; diff --git a/mojo/services/public/interfaces/network/cookie_store.mojom b/mojo/services/public/interfaces/network/cookie_store.mojom index 6f2da5e..92a4241 100644 --- a/mojo/services/public/interfaces/network/cookie_store.mojom +++ b/mojo/services/public/interfaces/network/cookie_store.mojom @@ -5,6 +5,6 @@ module mojo; interface CookieStore { - Get(string? url) => (string? cookies); - Set(string? url, string? cookie) => (bool success); + Get(string url) => (string cookies); + Set(string url, string cookie) => (bool success); }; diff --git a/mojo/services/public/interfaces/network/network_service.mojom b/mojo/services/public/interfaces/network/network_service.mojom index e3e4070..e79dfb5 100644 --- a/mojo/services/public/interfaces/network/network_service.mojom +++ b/mojo/services/public/interfaces/network/network_service.mojom @@ -17,9 +17,9 @@ import "mojo/services/public/interfaces/network/web_socket.mojom"; // high-level origin-build requests like WebSockets and HTTP, and the other for // non-origin-bound low-level stuff like DNS, UDP, and TCP. interface NetworkService { - CreateURLLoader(URLLoader&? loader); + CreateURLLoader(URLLoader& loader); - GetCookieStore(CookieStore&? cookie_store); + GetCookieStore(CookieStore& cookie_store); CreateWebSocket(WebSocket& socket); diff --git a/mojo/services/public/interfaces/network/url_loader.mojom b/mojo/services/public/interfaces/network/url_loader.mojom index b258fc4..c1d2bd3 100644 --- a/mojo/services/public/interfaces/network/url_loader.mojom +++ b/mojo/services/public/interfaces/network/url_loader.mojom @@ -8,17 +8,17 @@ import "mojo/services/public/interfaces/network/network_error.mojom"; struct URLRequest { // The URL to load. - string? url; + string url; // The HTTP method if applicable. - string? method = "GET"; + string method = "GET"; // Additional HTTP request headers. - array<string?>? headers; + array<string>? headers; // The payload for the request body, represented as a concatenation of data // streams. For HTTP requests, the method must be set to "POST" or "PUT". - array<handle<data_pipe_consumer>?>? body; + array<handle<data_pipe_consumer>>? body; // The number of bytes to be read from |body|. A Content-Length header of // this value will be sent. Set to -1 if length is unknown, which will cause @@ -59,7 +59,7 @@ struct URLResponse { string? status_line; // The HTTP response headers. - array<string?>? headers; + array<string>? headers; // The MIME type of the response body. string? mime_type; @@ -92,13 +92,13 @@ interface URLLoader { // Loads the given |request|, asynchronously producing |response|. Consult // |response| to determine if the request resulted in an error, was // redirected, or has a response body to be consumed. - Start(URLRequest? request) => (URLResponse? response); + Start(URLRequest request) => (URLResponse response); // If the request passed to |Start| had |auto_follow_redirects| set to false, // then upon receiving an URLResponse with a non-NULL |redirect_url| field, // |FollowRedirect| may be called to load the URL indicated by the redirect. - FollowRedirect() => (URLResponse? response); + FollowRedirect() => (URLResponse response); // Query status about the URLLoader. - QueryStatus() => (URLLoaderStatus? status); + QueryStatus() => (URLLoaderStatus status); }; diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom index 2a1a178..25e1f06 100644 --- a/mojo/services/public/interfaces/view_manager/view_manager.mojom +++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom @@ -130,7 +130,7 @@ interface ViewManagerService { // any services it provided are not broken and continue to be valid. Embed(string url, uint32 view_id, - ServiceProvider? service_provider) => (bool success); + ServiceProvider&? service_provider) => (bool success); }; // Changes to views are not sent to the connection that originated the diff --git a/mojo/services/public/interfaces/window_manager/window_manager.mojom b/mojo/services/public/interfaces/window_manager/window_manager.mojom index 6d108f9..8fe6f21 100644 --- a/mojo/services/public/interfaces/window_manager/window_manager.mojom +++ b/mojo/services/public/interfaces/window_manager/window_manager.mojom @@ -10,7 +10,7 @@ import "mojo/services/public/interfaces/input_events/input_events.mojom"; [Client=WindowManagerClient] interface WindowManager { // Requests the WindowManager to embed the app for |url| at an appropriate - // View. See ViewManger::Embed() for details on |service_provider|. + // View. See ViewMangerService::Embed() for details on |service_provider|. Embed(string url, ServiceProvider&? service_provider); SetCapture(uint32 view_id) => (bool success); diff --git a/mojo/services/public/js/mojo.js b/mojo/services/public/js/mojo.js new file mode 100644 index 0000000..ad0ed0c --- /dev/null +++ b/mojo/services/public/js/mojo.js @@ -0,0 +1,169 @@ +// Copyright 2014 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. + +define("mojo/services/public/js/mojo", [ + "mojo/public/interfaces/application/service_provider.mojom", + "mojo/public/js/connection", + "mojo/public/js/core", + "services/js/bridge", +], function(service, connection, core, bridge) { + + function Shell() { + this.applications_ = new Map(); + } + + Shell.prototype.connectToApplication = function(url) { + var application = this.applications_.get(url); + if (application) + return application; + application = new ServiceProvider(bridge.connectToApplication(url)); + this.applications_.set(url, application); + return application; + }; + + Shell.prototype.connectToService = function (url, service, client) { + return this.connectToApplication(url).connectToService(service, client); + }; + + Shell.prototype.close = function() { + shell().applications_.forEach(function(application, url) { + application.close(); + }); + shell().applications_.clear(); + }; + + var shellValue = null; + + function shell() { + if (!shellValue) + shellValue = new Shell(); + return shellValue; + } + + var requestorValue = null; + + function requestor() { + if (!requestorValue) { + var handle = bridge.requestorMessagePipeHandle(); + requestorValue = handle && new ServiceProvider(handle); + } + return requestorValue; + } + + function connectToServiceImpl(serviceName, serviceHandle) { + var provider = this.providers_.get(serviceName); + if (!provider) { + this.pendingRequests_.set(serviceName, serviceHandle); + return; + } + + var serviceConnection = new connection.Connection( + serviceHandle, + provider.service.delegatingStubClass, + provider.service.client && provider.service.client.proxyClass); + + serviceConnection.local.connection$ = serviceConnection; + serviceConnection.local.delegate$ = + new provider.factory(serviceConnection.remote); + + provider.connections.push(serviceConnection); + } + + function ServiceProvider(messagePipeHandle) { + // TODO(hansmuller): if messagePipeHandle is null, throw an exception. + this.connections_ = new Map(); + this.providers_ = new Map(); + this.pendingRequests_ = new Map(); + this.connection_ = null; + this.handle_ = messagePipeHandle; + this.connection_ = new connection.Connection( + this.handle_, + service.ServiceProvider.client.delegatingStubClass, + service.ServiceProvider.proxyClass); + this.connection_.local.delegate$ = { + connectToService: connectToServiceImpl.bind(this) + }; + } + + ServiceProvider.prototype.provideService = function(service, factory) { + // TODO(hansmuller): if !factory, remove provider and close its connections. + // TODO(hansmuller): if this.connection_ is null, throw an error. + var provider = { + service: service, + factory: factory, + connections: [], + }; + this.providers_.set(service.name, provider); + + if (this.pendingRequests_.has(service.name)) { + connectToServiceImpl(service.name, pendingRequests_.get(service.name)); + pendingRequests_.delete(service.name); + } + + return this; + }; + + ServiceProvider.prototype.connectToService = function(service, client) { + // TODO(hansmuler): if service.name isn't defined, throw an error. + // TODO(hansmuller): if this.connection_ is null, throw an error. + var serviceConnection = this.connections_.get(service.name); + if (serviceConnection) + return serviceConnection.remote; + + var pipe = core.createMessagePipe(); + this.connection_.remote.connectToService(service.name, pipe.handle1); + var clientClass = client && service.client.delegatingStubClass; + var serviceConnection = + new connection.Connection(pipe.handle0, clientClass, service.proxyClass); + if (serviceConnection.local) + serviceConnection.local.delegate$ = client; + + this.connections_.set(service.name, serviceConnection); + return serviceConnection.remote; + }; + + ServiceProvider.prototype.close = function() { + if (!this.connection_) + return; + + try { + // Outgoing connections + this.connections_.forEach(function(connection, serviceName) { + connection.close(); + }); + // Incoming connections + this.providers_.forEach(function(provider, serviceName) { + provider.connections.forEach(function(connection) { + connection.close(); + }); + }); + this.connection_.close(); + } finally { + this.connections_ = null; + this.providers_ = null; + this.pendingRequests_ = null; + this.connection_ = null; + this.handle_ = null; + + shell().applications_.forEach(function(application, url) { + if (application === this) + shell().applications_.delete(url); + }, this); + } + }; + + function quit() { + if (requestorValue) + requestor().close(); + if (shellValue) + shell().close(); + bridge.quit(); + } + + var exports = {}; + exports.requestor = requestor; + exports.shell = shell; + exports.quit = quit; + return exports; +}); |