forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow embedders to add callbacks for responses to platform messages f…
…rom the framework. (flutter#9655) Fixes flutter#18852
- Loading branch information
1 parent
8dac2e9
commit b84f89b
Showing
12 changed files
with
294 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
shell/platform/embedder/embedder_platform_message_response.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2013 The Flutter 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 "flutter/shell/platform/embedder/embedder_platform_message_response.h" | ||
|
||
#include "flutter/fml/make_copyable.h" | ||
|
||
namespace flutter { | ||
|
||
EmbedderPlatformMessageResponse::EmbedderPlatformMessageResponse( | ||
fml::RefPtr<fml::TaskRunner> runner, | ||
Callback callback) | ||
: runner_(std::move(runner)), callback_(callback) {} | ||
|
||
EmbedderPlatformMessageResponse::~EmbedderPlatformMessageResponse() = default; | ||
|
||
// |PlatformMessageResponse| | ||
void EmbedderPlatformMessageResponse::Complete( | ||
std::unique_ptr<fml::Mapping> data) { | ||
if (!data) { | ||
CompleteEmpty(); | ||
return; | ||
} | ||
|
||
runner_->PostTask( | ||
fml::MakeCopyable([data = std::move(data), callback = callback_]() { | ||
callback(data->GetMapping(), data->GetSize()); | ||
})); | ||
} | ||
|
||
// |PlatformMessageResponse| | ||
void EmbedderPlatformMessageResponse::CompleteEmpty() { | ||
Complete(std::make_unique<fml::NonOwnedMapping>(nullptr, 0u)); | ||
} | ||
|
||
} // namespace flutter |
53 changes: 53 additions & 0 deletions
53
shell/platform/embedder/embedder_platform_message_response.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2013 The Flutter 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 FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_PLATFORM_MESSAGE_RESPONSE_H_ | ||
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_PLATFORM_MESSAGE_RESPONSE_H_ | ||
|
||
#include "flutter/fml/macros.h" | ||
#include "flutter/fml/task_runner.h" | ||
#include "flutter/lib/ui/window/platform_message_response.h" | ||
|
||
namespace flutter { | ||
|
||
//------------------------------------------------------------------------------ | ||
/// @brief The platform message response subclass for responses to messages | ||
/// from the embedder to the framework. Message responses are | ||
/// fulfilled by the framework. | ||
class EmbedderPlatformMessageResponse : public PlatformMessageResponse { | ||
public: | ||
using Callback = std::function<void(const uint8_t* data, size_t size)>; | ||
|
||
//---------------------------------------------------------------------------- | ||
/// @param[in] runner The task runner on which to execute the callback. | ||
/// The response will be initiated by the framework on | ||
/// the UI thread. | ||
/// @param[in] callback The callback that communicates to the embedder the | ||
/// contents of the response sent by the framework back | ||
/// to the emebder. | ||
EmbedderPlatformMessageResponse(fml::RefPtr<fml::TaskRunner> runner, | ||
Callback callback); | ||
|
||
//---------------------------------------------------------------------------- | ||
/// @brief Destroys the message response. Can be called on any thread. | ||
/// Does not execute unfulfilled callbacks. | ||
/// | ||
~EmbedderPlatformMessageResponse() override; | ||
|
||
private: | ||
fml::RefPtr<fml::TaskRunner> runner_; | ||
Callback callback_; | ||
|
||
// |PlatformMessageResponse| | ||
void Complete(std::unique_ptr<fml::Mapping> data) override; | ||
|
||
// |PlatformMessageResponse| | ||
void CompleteEmpty() override; | ||
|
||
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderPlatformMessageResponse); | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_PLATFORM_MESSAGE_RESPONSE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.