提交 119b1a99 编写于 作者: A Adam Barth 提交者: GitHub

Finish routing platform messages on iOS (#3119)

上级 2ff316e7
......@@ -7,11 +7,12 @@
#include <unordered_map>
#include "lib/ftl/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/services/platform/app_messages.mojom.h"
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterAsyncMessageListener.h"
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterMessageListener.h"
#include "lib/ftl/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/binding_set.h"
namespace shell {
......@@ -24,6 +25,8 @@ class ApplicationMessagesImpl : public flutter::platform::ApplicationMessages {
void AddBinding(
mojo::InterfaceRequest<flutter::platform::ApplicationMessages> request);
void HandlePlatformMessage(ftl::RefPtr<blink::PlatformMessage> message);
void SetMessageListener(const std::string& message_name,
NSObject<FlutterMessageListener>* listener);
......
......@@ -4,9 +4,21 @@
#include "flutter/shell/platform/darwin/ios/framework/Source/application_messages_impl.h"
#include <vector>
#include "base/strings/sys_string_conversions.h"
namespace shell {
namespace {
std::vector<char> SysNSStringToVector(NSString* string) {
if (!string.length)
return std::vector<char>();
const char* utf8 = string.UTF8String;
return std::vector<char>(utf8, utf8 + strlen(utf8));
}
} // namespace
ApplicationMessagesImpl::ApplicationMessagesImpl() : weak_factory_(this) {}
......@@ -21,6 +33,31 @@ void ApplicationMessagesImpl::AddBinding(
binding_.AddBinding(this, request.Pass());
}
void ApplicationMessagesImpl::HandlePlatformMessage(
ftl::RefPtr<blink::PlatformMessage> message) {
NSString* string = [NSString stringWithUTF8String:message->data().data()];
{
auto it = listeners_.find(message->name());
if (it != listeners_.end()) {
NSString* response = [it->second didReceiveString:string];
message->InvokeCallback(SysNSStringToVector(response));
return;
}
}
{
auto it = async_listeners_.find(message->name());
if (it != async_listeners_.end()) {
[it->second
didReceiveString:string
callback:^(NSString* response) {
message->InvokeCallback(SysNSStringToVector(response));
}];
}
}
}
void ApplicationMessagesImpl::SetMessageListener(
const std::string& message_name,
NSObject<FlutterMessageListener>* listener) {
......
......@@ -49,12 +49,15 @@ class PlatformViewIOS : public PlatformView, public GPUSurfaceGLDelegate {
intptr_t GLContextFBO() const override;
void HandlePlatformMessage(
ftl::RefPtr<blink::PlatformMessage> message) override;
void UpdateSemantics(std::vector<blink::SemanticsNode> update) override;
void RunFromSource(const std::string& main,
const std::string& packages,
const std::string& assets_directory) override;
void UpdateSemantics(std::vector<blink::SemanticsNode> update) override;
private:
std::unique_ptr<IOSGLContext> context_;
sky::SkyEnginePtr engine_;
......
......@@ -8,6 +8,9 @@
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import <QuartzCore/CAEAGLLayer.h>
#include <utility>
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/trace_event/trace_event.h"
#include "flutter/shell/gpu/gpu_rasterizer.h"
......@@ -369,6 +372,17 @@ bool PlatformViewIOS::GLContextPresent() {
return context_ != nullptr ? context_->PresentRenderBuffer() : false;
}
void PlatformViewIOS::UpdateSemantics(
std::vector<blink::SemanticsNode> update) {
if (accessibility_bridge_)
accessibility_bridge_->UpdateSemantics(std::move(update));
}
void PlatformViewIOS::HandlePlatformMessage(
ftl::RefPtr<blink::PlatformMessage> message) {
app_message_receiver_.HandlePlatformMessage(std::move(message));
}
void PlatformViewIOS::RunFromSource(const std::string& main,
const std::string& packages,
const std::string& assets_directory) {
......@@ -383,10 +397,4 @@ void PlatformViewIOS::RunFromSource(const std::string& main,
delete latch;
}
void PlatformViewIOS::UpdateSemantics(
std::vector<blink::SemanticsNode> update) {
if (accessibility_bridge_)
accessibility_bridge_->UpdateSemantics(std::move(update));
}
} // namespace shell
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册