Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
370db6cd
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
370db6cd
编写于
3月 16, 2016
作者:
J
Jason Simmons
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Provide Mojo services for passing application-specific messages between the host and Flutter
上级
dcbd64e4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
138 addition
and
1 deletion
+138
-1
sky/services/platform/BUILD.gn
sky/services/platform/BUILD.gn
+1
-0
sky/services/platform/app_messages.mojom
sky/services/platform/app_messages.mojom
+13
-0
sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java
...rm/android/org/domokit/sky/shell/PlatformViewAndroid.java
+124
-1
未找到文件。
sky/services/platform/BUILD.gn
浏览文件 @
370db6cd
...
...
@@ -6,6 +6,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
"app_messages.mojom",
"haptic_feedback.mojom",
"path_provider.mojom",
"system_chrome.mojom",
...
...
sky/services/platform/app_messages.mojom
0 → 100644
浏览文件 @
370db6cd
// 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.
[DartPackage="sky_services"]
module flutter.platform;
/// A service that can be implemented by the host application and the
/// Flutter framework to exchange application-specific messages.
[ServiceName="flutter::platform::ApplicationMessages"]
interface ApplicationMessages {
SendString(string messageName, string message) => (string? reply);
};
sky/shell/platform/android/org/domokit/sky/shell/PlatformViewAndroid.java
浏览文件 @
370db6cd
...
...
@@ -31,8 +31,8 @@ import org.chromium.mojo.system.MessagePipeHandle;
import
org.chromium.mojo.system.MojoException
;
import
org.chromium.mojo.system.Pair
;
import
org.chromium.mojo.system.impl.CoreImpl
;
import
org.chromium.mojo.system.impl.CoreImpl
;
import
org.chromium.mojom.editing.Keyboard
;
import
org.chromium.mojom.flutter.platform.ApplicationMessages
;
import
org.chromium.mojom.mojo.ServiceProvider
;
import
org.chromium.mojom.pointer.Pointer
;
import
org.chromium.mojom.pointer.PointerKind
;
...
...
@@ -72,6 +72,9 @@ public class PlatformViewAndroid extends SurfaceView
private
ServiceProviderImpl
mPlatformServiceProvider
;
private
ServiceProviderImpl
mViewServiceProvider
;
private
ServiceProvider
.
Proxy
mDartServiceProvider
;
private
ApplicationMessages
.
Proxy
mFlutterAppMessages
;
private
HashMap
<
String
,
OnMessageListener
>
mOnMessageListeners
;
private
HashMap
<
String
,
OnMessageListenerAsync
>
mAsyncOnMessageListeners
;
private
final
SurfaceHolder
.
Callback
mSurfaceCallback
;
private
final
ViewportMetrics
mMetrics
;
private
final
KeyboardViewState
mKeyboardState
;
...
...
@@ -125,6 +128,9 @@ public class PlatformViewAndroid extends SurfaceView
mAccessibilityManager
=
(
AccessibilityManager
)
getContext
().
getSystemService
(
Context
.
ACCESSIBILITY_SERVICE
);
mOnMessageListeners
=
new
HashMap
<
String
,
OnMessageListener
>();
mAsyncOnMessageListeners
=
new
HashMap
<
String
,
OnMessageListenerAsync
>();
setLocale
(
getResources
().
getConfiguration
().
locale
);
}
...
...
@@ -335,6 +341,13 @@ public class PlatformViewAndroid extends SurfaceView
RawKeyboardService
.
MANAGER
.
bind
(
new
RawKeyboardServiceImpl
(
mRawKeyboardState
),
pipe
);
}
});
registry
.
register
(
ApplicationMessages
.
MANAGER
.
getName
(),
new
ServiceFactory
()
{
@Override
public
void
connectToService
(
Context
context
,
Core
core
,
MessagePipeHandle
pipe
)
{
ApplicationMessages
.
MANAGER
.
bind
(
new
ApplicationMessagesImpl
(),
pipe
);
}
});
}
private
void
attach
()
{
...
...
@@ -380,6 +393,13 @@ public class PlatformViewAndroid extends SurfaceView
}
else
{
mSkyEngine
.
runFromBundle
(
scriptUri
,
bundlePath
);
}
// Connect to the ApplicationMessages service exported by the Flutter framework
Pair
<
ApplicationMessages
.
Proxy
,
InterfaceRequest
<
ApplicationMessages
>>
appMessages
=
ApplicationMessages
.
MANAGER
.
getInterfaceRequest
(
core
);
mDartServiceProvider
.
connectToService
(
ApplicationMessages
.
MANAGER
.
getName
(),
appMessages
.
second
.
passHandle
());
mFlutterAppMessages
=
appMessages
.
first
;
}
private
static
native
long
nativeAttach
(
int
inputObserverHandle
);
...
...
@@ -488,4 +508,107 @@ public class PlatformViewAndroid extends SurfaceView
return
true
;
}
/**
* Send a message to the Flutter application. The Flutter Dart code can register a
* host message handler that will receive these messages.
*/
public
void
sendToFlutter
(
String
messageName
,
String
message
,
final
MessageReplyCallback
callback
)
{
mFlutterAppMessages
.
sendString
(
messageName
,
message
,
new
ApplicationMessages
.
SendStringResponse
()
{
@Override
public
void
call
(
String
reply
)
{
if
(
callback
!=
null
)
{
callback
.
onReply
(
reply
);
}
}
});
}
public
void
sendToFlutter
(
String
messageName
,
String
message
)
{
sendToFlutter
(
messageName
,
message
,
null
);
}
/** Callback invoked when the app replies to a message sent with sendToFlutter. */
public
interface
MessageReplyCallback
{
void
onReply
(
String
reply
);
}
/**
* Register a callback to be invoked when the Flutter application sends a message
* to its host.
*/
public
void
addOnMessageListener
(
String
messageName
,
OnMessageListener
listener
)
{
mOnMessageListeners
.
put
(
messageName
,
listener
);
}
/**
* Register a callback to be invoked when the Flutter application sends a message
* to its host. The reply to the message can be provided asynchronously.
*/
public
void
addOnMessageListenerAsync
(
String
messageName
,
OnMessageListenerAsync
listener
)
{
mAsyncOnMessageListeners
.
put
(
messageName
,
listener
);
}
public
interface
OnMessageListener
{
/**
* Called when a message is received from the Flutter app.
* @return the reply to the message (can be null)
*/
String
onMessage
(
String
message
);
};
public
interface
OnMessageListenerAsync
{
/**
* Called when a message is received from the Flutter app.
* @param response Used to send a reply back to the app.
*/
void
onMessage
(
String
message
,
MessageResponse
response
);
}
public
interface
MessageResponse
{
void
send
(
String
reply
);
}
private
class
ApplicationMessagesImpl
implements
ApplicationMessages
{
@Override
public
void
close
()
{}
@Override
public
void
onConnectionError
(
MojoException
e
)
{}
@Override
public
void
sendString
(
String
messageName
,
String
message
,
SendStringResponse
callback
)
{
OnMessageListener
listener
=
mOnMessageListeners
.
get
(
messageName
);
if
(
listener
!=
null
)
{
callback
.
call
(
listener
.
onMessage
(
message
));
return
;
}
OnMessageListenerAsync
asyncListener
=
mAsyncOnMessageListeners
.
get
(
messageName
);
if
(
asyncListener
!=
null
)
{
asyncListener
.
onMessage
(
message
,
new
MessageResponseAdapter
(
callback
));
return
;
}
callback
.
call
(
null
);
}
}
/**
* This class wraps the raw Mojo callback object in an interface that is owned
* by Flutter and can be safely given to host apps.
*/
private
static
class
MessageResponseAdapter
implements
MessageResponse
{
private
ApplicationMessages
.
SendStringResponse
callback
;
MessageResponseAdapter
(
ApplicationMessages
.
SendStringResponse
callback
)
{
this
.
callback
=
callback
;
}
@Override
public
void
send
(
String
reply
)
{
callback
.
call
(
reply
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录