Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
e8a21f5d
Commit
e8a21f5d
authored
Jan 29, 2016
by
Hixie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Turn MojoShell into an actual binding
parent
9e784f0c
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
108 additions
and
89 deletions
+108
-89
services.dart
packages/flutter/lib/services.dart
+1
-1
mojo_client.dart
packages/flutter/lib/src/http/mojo_client.dart
+1
-1
binding.dart
packages/flutter/lib/src/rendering/binding.dart
+2
-2
activity.dart
packages/flutter/lib/src/services/activity.dart
+1
-1
asset_bundle.dart
packages/flutter/lib/src/services/asset_bundle.dart
+1
-1
binding.dart
packages/flutter/lib/src/services/binding.dart
+90
-0
keyboard.dart
packages/flutter/lib/src/services/keyboard.dart
+1
-1
shell.dart
packages/flutter/lib/src/services/shell.dart
+0
-74
binding.dart
packages/flutter/lib/src/widgets/binding.dart
+1
-1
mock_services.dart
packages/flutter/test/services/mock_services.dart
+9
-7
input_test.dart
packages/flutter/test/widget/input_test.dart
+1
-0
No files found.
packages/flutter/lib/services.dart
View file @
e8a21f5d
...
...
@@ -21,4 +21,4 @@ export 'src/services/image_resource.dart';
export
'src/services/keyboard.dart'
;
export
'src/services/print.dart'
;
export
'src/services/service_registry.dart'
;
export
'src/services/shell.dart'
;
packages/flutter/lib/src/http/mojo_client.dart
View file @
e8a21f5d
...
...
@@ -6,7 +6,7 @@ import 'dart:async';
import
'dart:convert'
;
import
'dart:typed_data'
;
import
'package:flutter/s
rc/services/shell
.dart'
;
import
'package:flutter/s
ervices
.dart'
;
import
'package:mojo_services/mojo/network_service.mojom.dart'
as
mojo
;
import
'package:mojo_services/mojo/url_loader.mojom.dart'
as
mojo
;
import
'package:mojo/core.dart'
as
mojo
;
...
...
packages/flutter/lib/src/rendering/binding.dart
View file @
e8a21f5d
...
...
@@ -18,7 +18,7 @@ import 'semantics.dart';
export
'package:flutter/gestures.dart'
show
HitTestResult
;
/// The glue between the render tree and the Flutter engine.
abstract
class
Renderer
extends
Scheduler
abstract
class
Renderer
extends
Object
with
Scheduler
,
MojoShell
implements
HitTestable
{
void
initInstances
()
{
...
...
@@ -116,7 +116,7 @@ void debugDumpSemanticsTree() {
/// A concrete binding for applications that use the Rendering framework
/// directly. This is the glue that binds the framework to the Flutter engine.
class
RenderingFlutterBinding
extends
BindingBase
with
Scheduler
,
Gesturer
,
Renderer
{
class
RenderingFlutterBinding
extends
BindingBase
with
Scheduler
,
Gesturer
,
MojoShell
,
Renderer
{
RenderingFlutterBinding
({
RenderBox
root
})
{
assert
(
renderView
!=
null
);
renderView
.
child
=
root
;
...
...
packages/flutter/lib/src/services/activity.dart
View file @
e8a21f5d
...
...
@@ -7,7 +7,7 @@ import 'dart:async';
import
'package:sky_services/activity/activity.mojom.dart'
;
import
'
shell
.dart'
;
import
'
binding
.dart'
;
export
'package:sky_services/activity/activity.mojom.dart'
;
...
...
packages/flutter/lib/src/services/asset_bundle.dart
View file @
e8a21f5d
...
...
@@ -16,7 +16,7 @@ import 'fetch.dart';
import
'image_cache.dart'
;
import
'image_decoder.dart'
;
import
'image_resource.dart'
;
import
'
shell
.dart'
;
import
'
binding
.dart'
;
abstract
class
AssetBundle
{
ImageResource
loadImage
(
String
key
);
...
...
packages/flutter/lib/src/services/binding.dart
View file @
e8a21f5d
...
...
@@ -2,6 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:ui_internals'
as
internals
;
import
'package:mojo/application.dart'
;
import
'package:mojo/bindings.dart'
as
bindings
;
import
'package:mojo/core.dart'
as
core
;
import
'package:mojo/mojo/service_provider.mojom.dart'
as
mojom
;
import
'package:mojo/mojo/shell.mojom.dart'
as
mojom
;
/// Base class for mixins that provide singleton services (also known as
/// "bindings").
///
...
...
@@ -30,3 +38,85 @@ abstract class BindingBase {
assert
(()
{
_debugInitialized
=
true
;
return
true
;
});
}
}
// A replacement for shell.connectToService. Implementations should return true
// if they handled the request, or false if the request should fall through
// to the default requestService.
typedef
bool
OverrideConnectToService
(
String
url
,
Object
proxy
);
abstract
class
MojoShell
extends
BindingBase
{
void
initInstances
()
{
super
.
initInstances
();
_instance
=
this
;
}
static
MojoShell
_instance
;
static
MojoShell
get
instance
=>
_instance
;
static
mojom
.
ShellProxy
_initShellProxy
()
{
core
.
MojoHandle
shellHandle
=
new
core
.
MojoHandle
(
internals
.
takeShellProxyHandle
());
if
(!
shellHandle
.
isValid
)
return
null
;
return
new
mojom
.
ShellProxy
.
fromHandle
(
shellHandle
);
}
final
mojom
.
Shell
_shell
=
_initShellProxy
()?.
ptr
;
static
ApplicationConnection
_initEmbedderConnection
()
{
core
.
MojoHandle
servicesHandle
=
new
core
.
MojoHandle
(
internals
.
takeServicesProvidedByEmbedder
());
core
.
MojoHandle
exposedServicesHandle
=
new
core
.
MojoHandle
(
internals
.
takeServicesProvidedToEmbedder
());
if
(!
servicesHandle
.
isValid
||
!
exposedServicesHandle
.
isValid
)
return
null
;
mojom
.
ServiceProviderProxy
services
=
new
mojom
.
ServiceProviderProxy
.
fromHandle
(
servicesHandle
);
mojom
.
ServiceProviderStub
exposedServices
=
new
mojom
.
ServiceProviderStub
.
fromHandle
(
exposedServicesHandle
);
return
new
ApplicationConnection
(
exposedServices
,
services
);
}
final
ApplicationConnection
_embedderConnection
=
_initEmbedderConnection
();
/// Attempts to connect to an application via the Mojo shell.
ApplicationConnection
connectToApplication
(
String
url
)
{
if
(
_shell
==
null
)
return
null
;
mojom
.
ServiceProviderProxy
services
=
new
mojom
.
ServiceProviderProxy
.
unbound
();
mojom
.
ServiceProviderStub
exposedServices
=
new
mojom
.
ServiceProviderStub
.
unbound
();
_shell
.
connectToApplication
(
url
,
services
,
exposedServices
);
return
new
ApplicationConnection
(
exposedServices
,
services
);
}
/// Set this to intercept calls to [connectToService()] and supply an
/// alternative implementation of a service (for example, a mock for testing).
OverrideConnectToService
overrideConnectToService
;
/// Attempts to connect to a service implementing the interface for the given proxy.
/// If an application URL is specified, the service will be requested from that application.
/// Otherwise, it will be requested from the embedder (the Flutter engine).
void
connectToService
(
String
url
,
bindings
.
ProxyBase
proxy
)
{
if
(
overrideConnectToService
!=
null
&&
overrideConnectToService
(
url
,
proxy
))
return
;
if
(
url
==
null
||
_shell
==
null
)
{
// If the application URL is null, it means the service to connect
// to is one provided by the embedder.
// If the applircation URL isn't null but there's no shell, then
// ask the embedder in case it provides it. (For example, if you're
// running on Android without the Mojo shell, then you can obtain
// the media service from the embedder directly, instead of having
// to ask the media application for it.)
// This makes it easier to write an application that works both
// with and without a Mojo environment.
_embedderConnection
?.
requestService
(
proxy
);
return
;
}
mojom
.
ServiceProviderProxy
services
=
new
mojom
.
ServiceProviderProxy
.
unbound
();
_shell
.
connectToApplication
(
url
,
services
,
null
);
core
.
MojoMessagePipe
pipe
=
new
core
.
MojoMessagePipe
();
proxy
.
impl
.
bind
(
pipe
.
endpoints
[
0
]);
services
.
ptr
.
connectToService
(
proxy
.
serviceName
,
pipe
.
endpoints
[
1
]);
services
.
close
();
}
/// Registers a service to expose to the embedder.
void
provideService
(
String
interfaceName
,
ServiceFactory
factory
)
{
_embedderConnection
?.
provideService
(
interfaceName
,
factory
);
}
}
MojoShell
get
shell
=>
MojoShell
.
instance
;
packages/flutter/lib/src/services/keyboard.dart
View file @
e8a21f5d
...
...
@@ -6,7 +6,7 @@ import 'dart:async';
import
'package:mojo_services/keyboard/keyboard.mojom.dart'
;
import
'
shell
.dart'
;
import
'
binding
.dart'
;
export
'package:mojo_services/keyboard/keyboard.mojom.dart'
;
...
...
packages/flutter/lib/src/services/shell.dart
deleted
100644 → 0
View file @
9e784f0c
// 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
'dart:ui_internals'
as
internals
;
import
'package:mojo/application.dart'
;
import
'package:mojo/bindings.dart'
as
bindings
;
import
'package:mojo/core.dart'
as
core
;
import
'package:mojo/mojo/service_provider.mojom.dart'
as
mojom
;
import
'package:mojo/mojo/shell.mojom.dart'
as
mojom
;
// A replacement for shell.connectToService. Implementations should return true
// if they handled the request, or false if the request should fall through
// to the default requestService.
typedef
bool
OverrideConnectToService
(
String
url
,
Object
proxy
);
class
MojoShell
{
MojoShell
.
_
();
static
mojom
.
ShellProxy
_initShellProxy
()
{
core
.
MojoHandle
shellHandle
=
new
core
.
MojoHandle
(
internals
.
takeShellProxyHandle
());
if
(!
shellHandle
.
isValid
)
return
null
;
return
new
mojom
.
ShellProxy
.
fromHandle
(
shellHandle
);
}
static
final
mojom
.
Shell
_shell
=
_initShellProxy
()?.
ptr
;
static
ApplicationConnection
_initEmbedderConnection
()
{
core
.
MojoHandle
servicesHandle
=
new
core
.
MojoHandle
(
internals
.
takeServicesProvidedByEmbedder
());
core
.
MojoHandle
exposedServicesHandle
=
new
core
.
MojoHandle
(
internals
.
takeServicesProvidedToEmbedder
());
if
(!
servicesHandle
.
isValid
||
!
exposedServicesHandle
.
isValid
)
return
null
;
mojom
.
ServiceProviderProxy
services
=
new
mojom
.
ServiceProviderProxy
.
fromHandle
(
servicesHandle
);
mojom
.
ServiceProviderStub
exposedServices
=
new
mojom
.
ServiceProviderStub
.
fromHandle
(
exposedServicesHandle
);
return
new
ApplicationConnection
(
exposedServices
,
services
);
}
static
final
ApplicationConnection
_embedderConnection
=
_initEmbedderConnection
();
ApplicationConnection
connectToApplication
(
String
url
)
{
if
(
_shell
==
null
)
return
null
;
mojom
.
ServiceProviderProxy
services
=
new
mojom
.
ServiceProviderProxy
.
unbound
();
mojom
.
ServiceProviderStub
exposedServices
=
new
mojom
.
ServiceProviderStub
.
unbound
();
_shell
.
connectToApplication
(
url
,
services
,
exposedServices
);
return
new
ApplicationConnection
(
exposedServices
,
services
);
}
// Set this to intercept calls to shell.connectToService and supply an
// alternative implementation of a service (for example, a mock for testing).
OverrideConnectToService
overrideConnectToService
;
void
connectToService
(
String
url
,
bindings
.
ProxyBase
proxy
)
{
if
(
overrideConnectToService
!=
null
&&
overrideConnectToService
(
url
,
proxy
))
return
;
_connectToService
(
url
,
proxy
);
}
void
_connectToService
(
String
url
,
bindings
.
ProxyBase
proxy
)
{
if
(
_shell
==
null
||
url
==
null
)
{
// If we don't have a shell or a url, we try to get the services from the
// embedder directly instead of using the shell to connect.
_embedderConnection
?.
requestService
(
proxy
);
return
;
}
mojom
.
ServiceProviderProxy
services
=
new
mojom
.
ServiceProviderProxy
.
unbound
();
_shell
.
connectToApplication
(
url
,
services
,
null
);
core
.
MojoMessagePipe
pipe
=
new
core
.
MojoMessagePipe
();
proxy
.
impl
.
bind
(
pipe
.
endpoints
[
0
]);
services
.
ptr
.
connectToService
(
proxy
.
serviceName
,
pipe
.
endpoints
[
1
]);
services
.
close
();
}
}
final
MojoShell
shell
=
new
MojoShell
.
_
();
packages/flutter/lib/src/widgets/binding.dart
View file @
e8a21f5d
...
...
@@ -21,7 +21,7 @@ class BindingObserver {
/// A concrete binding for applications based on the Widgets framework.
/// This is the glue that binds the framework to the Flutter engine.
class
WidgetFlutterBinding
extends
BindingBase
with
Scheduler
,
Gesturer
,
Renderer
{
class
WidgetFlutterBinding
extends
BindingBase
with
Scheduler
,
Gesturer
,
MojoShell
,
Renderer
{
WidgetFlutterBinding
.
_
();
...
...
packages/flutter/test/services/mock_services.dart
View file @
e8a21f5d
import
'package:flutter/s
rc/services/shell
.dart'
;
import
'package:flutter/s
ervices
.dart'
;
import
'package:mojo/bindings.dart'
as
bindings
;
// Tests can use ServiceMocker to register replacement implementations
// of Mojo services.
class
_
ServiceMocker
{
_ServiceMocker
()
{
class
ServiceMocker
{
ServiceMocker
.
_
()
{
shell
.
overrideConnectToService
=
_connectToService
;
}
// Map of interface names to mock implementations.
Map
<
String
,
Object
>
_interfaceMock
=
new
Map
<
String
,
Object
>()
;
Map
<
String
,
Object
>
_interfaceMock
s
=
<
String
,
Object
>{}
;
bool
_connectToService
(
String
url
,
bindings
.
ProxyBase
proxy
)
{
Object
mock
=
_interfaceMock
[
proxy
.
serviceName
];
Object
mock
=
_interfaceMock
s
[
proxy
.
serviceName
];
if
(
mock
!=
null
)
{
// Replace the proxy's implementation of the service interface with the
// mock. The mojom bindings put the "ptr" field on all proxies.
...
...
@@ -24,9 +24,11 @@ class _ServiceMocker {
}
// Provide a mock implementation for a Mojo interface.
// Make sure you initialise the binding before calling this.
// For example, by calling `WidgetFlutterBinding.ensureInitialized();`
void
registerMockService
(
String
interfaceName
,
Object
mock
)
{
_interfaceMock
[
interfaceName
]
=
mock
;
_interfaceMock
s
[
interfaceName
]
=
mock
;
}
}
final
_ServiceMocker
serviceMocker
=
new
_ServiceMocker
();
final
ServiceMocker
serviceMocker
=
new
ServiceMocker
.
_
();
packages/flutter/test/widget/input_test.dart
View file @
e8a21f5d
...
...
@@ -28,6 +28,7 @@ class MockKeyboard implements KeyboardService {
}
void
main
(
)
{
WidgetFlutterBinding
.
ensureInitialized
();
// for serviceMocker
MockKeyboard
mockKeyboard
=
new
MockKeyboard
();
serviceMocker
.
registerMockService
(
KeyboardService
.
serviceName
,
mockKeyboard
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment