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
074564ee
Commit
074564ee
authored
Mar 17, 2016
by
Jason Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide APIs for exchanging messages with the host application
parent
79a098e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
services.dart
packages/flutter/lib/services.dart
+1
-0
app_messages.dart
packages/flutter/lib/src/services/app_messages.dart
+59
-0
No files found.
packages/flutter/lib/services.dart
View file @
074564ee
...
...
@@ -12,6 +12,7 @@
library
services
;
export
'src/services/activity.dart'
;
export
'src/services/app_messages.dart'
;
export
'src/services/assertions.dart'
;
export
'src/services/asset_bundle.dart'
;
export
'src/services/binding.dart'
;
...
...
packages/flutter/lib/src/services/app_messages.dart
0 → 100644
View file @
074564ee
// Copyright 2016 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:async'
;
import
'package:flutter/shell.dart'
;
import
'package:mojo/core.dart'
as
core
;
import
'package:sky_services/flutter/platform/app_messages.mojom.dart'
;
// APIs for exchanging messages with the host application.
ApplicationMessagesProxy
_initHostAppMessagesProxy
(
)
{
ApplicationMessagesProxy
proxy
=
new
ApplicationMessagesProxy
.
unbound
();
shell
.
connectToViewAssociatedService
(
proxy
);
return
proxy
;
}
final
ApplicationMessagesProxy
_hostAppMessagesProxy
=
_initHostAppMessagesProxy
();
typedef
Future
<
String
>
HostMessageCallback
(
String
message
);
typedef
Object
_SendStringResponseFactory
(
String
response
);
class
_ApplicationMessagesImpl
extends
ApplicationMessages
{
final
Map
<
String
,
HostMessageCallback
>
handlers
=
<
String
,
HostMessageCallback
>{};
_ApplicationMessagesImpl
()
{
shell
.
provideService
(
ApplicationMessages
.
serviceName
,
(
core
.
MojoMessagePipeEndpoint
endpoint
)
{
ApplicationMessagesStub
stub
=
new
ApplicationMessagesStub
.
fromEndpoint
(
endpoint
);
stub
.
impl
=
this
;
}
);
}
@override
dynamic
sendString
(
String
messageName
,
String
message
,
[
_SendStringResponseFactory
responseFactory
])
{
HostMessageCallback
callback
=
handlers
[
messageName
];
if
(
callback
==
null
)
return
responseFactory
(
null
);
return
callback
(
message
).
then
((
String
s
)
=>
responseFactory
(
s
));
}
}
final
_ApplicationMessagesImpl
_appMessages
=
new
_ApplicationMessagesImpl
();
class
HostMessages
{
/// Send a message to the host application.
static
Future
<
String
>
sendToHost
(
String
messageName
,
String
message
)
async
{
return
(
await
_hostAppMessagesProxy
.
ptr
.
sendString
(
messageName
,
message
)).
reply
;
}
/// Register a callback for messages received from the host application.
/// The callback function must return a String, Future<String>, or null.
static
void
addMessageHandler
(
String
messageName
,
HostMessageCallback
callback
)
{
_appMessages
.
handlers
[
messageName
]
=
callback
;
}
}
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