Skip to content

Commit

Permalink
Fixup Fuchsia content handler post shell refactor. (flutter#5072)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored Apr 24, 2018
1 parent ec61147 commit 79b9ffb
Show file tree
Hide file tree
Showing 28 changed files with 350 additions and 363 deletions.
3 changes: 1 addition & 2 deletions content_handler/accessibility_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
#include <unordered_set>

#include "lib/app/cpp/application_context.h"
#include "lib/context/fidl/context_writer.fidl.h"
#include "third_party/rapidjson/rapidjson/document.h"
#include "third_party/rapidjson/rapidjson/stringbuffer.h"
#include "third_party/rapidjson/rapidjson/writer.h"

namespace flutter {

AccessibilityBridge::AccessibilityBridge(maxwell::ContextWriterPtr writer)
AccessibilityBridge::AccessibilityBridge(modular::ContextWriterPtr writer)
: writer_(std::move(writer)) {}

AccessibilityBridge::~AccessibilityBridge() = default;
Expand Down
7 changes: 4 additions & 3 deletions content_handler/accessibility_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

#include <map>

#include <fuchsia/cpp/modular.h>

#include "flutter/lib/ui/semantics/semantics_node.h"
#include "lib/context/fidl/context_writer.fidl.h"
#include "lib/fxl/macros.h"

namespace flutter {
Expand All @@ -16,7 +17,7 @@ namespace flutter {
// with the Context Service.
class AccessibilityBridge final {
public:
AccessibilityBridge(maxwell::ContextWriterPtr writer);
AccessibilityBridge(modular::ContextWriterPtr writer);

~AccessibilityBridge();

Expand All @@ -25,7 +26,7 @@ class AccessibilityBridge final {
void UpdateSemantics(const blink::SemanticsNodeUpdates& update);

private:
maxwell::ContextWriterPtr writer_;
modular::ContextWriterPtr writer_;
std::map<int, blink::SemanticsNode> semantics_nodes_;

// Walk the semantics node tree starting at |id|, and store the id of each
Expand Down
76 changes: 34 additions & 42 deletions content_handler/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ namespace flutter {
std::pair<std::unique_ptr<fsl::Thread>, std::unique_ptr<Application>>
Application::Create(
Application::Delegate& delegate,
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller) {
component::ApplicationPackage package,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller) {
auto thread = std::make_unique<fsl::Thread>();
std::unique_ptr<Application> application;

Expand Down Expand Up @@ -52,52 +52,48 @@ static std::string DebugLabelForURL(const std::string url) {

Application::Application(
Application::Delegate& delegate,
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController>
component::ApplicationPackage,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController>
application_controller_request)
: delegate_(delegate),
debug_label_(DebugLabelForURL(startup_info->launch_info->url)),
debug_label_(DebugLabelForURL(startup_info.launch_info.url)),
application_controller_(this) {
application_controller_.set_error_handler([this]() { Kill(); });

FXL_DCHECK(fdio_ns_.is_valid());
// ApplicationLaunchInfo::url non-optional.
auto& launch_info = startup_info->launch_info;
auto& launch_info = startup_info.launch_info;

// ApplicationLaunchInfo::arguments optional.
if (auto& arguments = launch_info->arguments) {
if (auto& arguments = launch_info.arguments) {
settings_ = shell::SettingsFromCommandLine(
fxl::CommandLineFromIterators(arguments->begin(), arguments->end()));
}

// TODO: ApplicationLaunchInfo::out optional.
// TODO: ApplicationLaunchInfo::out.

// TODO: ApplicationLaunchInfo::err optional.
// TODO: ApplicationLaunchInfo::err.

// ApplicationLaunchInfo::service_request optional.
if (launch_info->directory_request) {
if (launch_info.directory_request) {
service_provider_bridge_.ServeDirectory(
std::move(launch_info->directory_request));
std::move(launch_info.directory_request));
}

// ApplicationLaunchInfo::flat_namespace optional.
if (auto& flat_namespace = startup_info->flat_namespace) {
for (size_t i = 0; i < flat_namespace->paths->size(); ++i) {
const auto& path = flat_namespace->paths->at(i);
if (path == "/svc") {
continue;
}

zx::channel dir = std::move(flat_namespace->directories->at(i));
zx_handle_t dir_handle = dir.release();
if (fdio_ns_bind(fdio_ns_.get(), path->data(), dir_handle) != ZX_OK) {
FXL_DLOG(ERROR) << "Could not bind path to namespace: " << path;
zx_handle_close(dir_handle);
}
for (size_t i = 0; i < startup_info.flat_namespace.paths->size(); ++i) {
const auto& path = startup_info.flat_namespace.paths->at(i);
if (path == "/svc") {
continue;
}

zx::channel dir = std::move(startup_info.flat_namespace.directories->at(i));
zx_handle_t dir_handle = dir.release();
if (fdio_ns_bind(fdio_ns_.get(), path->data(), dir_handle) != ZX_OK) {
FXL_DLOG(ERROR) << "Could not bind path to namespace: " << path;
zx_handle_close(dir_handle);
}
} else {
FXL_DLOG(ERROR) << "There was no flat namespace.";
}

application_directory_.reset(fdio_ns_opendir(fdio_ns_.get()));
Expand All @@ -108,15 +104,11 @@ Application::Application(

// TODO: ApplicationLaunchInfo::additional_services optional.

// ApplicationPackage::data: This is legacy FLX data. Ensure that we dont have
// any.
FXL_DCHECK(!package->data) << "Legacy FLX data must not be supplied.";

// All launch arguments have been read. Perform service binding and
// final settings configuration. The next call will be to create a view
// for this application.

service_provider_bridge_.AddService<mozart::ViewProvider>(
service_provider_bridge_.AddService<views_v1::ViewProvider>(
std::bind(&Application::CreateShellForView, this, std::placeholders::_1));

component::ServiceProviderPtr outgoing_services;
Expand Down Expand Up @@ -193,10 +185,10 @@ void Application::AttemptVMLaunchWithCurrentSettings(
return;
}

auto lib = fxl::MakeRefCounted<fml::NativeLibrary>(
library_handle, // library handle
true // close the handle when done
);
auto lib =
fml::NativeLibrary::CreateWithHandle(library_handle, // library handle
true // close the handle when done
);

auto symbol = [](const char* str) {
return std::string{"_"} + std::string{str};
Expand Down Expand Up @@ -248,7 +240,7 @@ void Application::Detach() {
}

// |component::ApplicationController|
void Application::Wait(const WaitCallback& callback) {
void Application::Wait(WaitCallback callback) {
wait_callbacks_.emplace_back(std::move(callback));
}

Expand Down Expand Up @@ -281,14 +273,14 @@ void Application::OnEngineTerminate(const Engine* shell_holder) {
}

void Application::CreateShellForView(
f1dl::InterfaceRequest<mozart::ViewProvider> view_provider_request) {
fidl::InterfaceRequest<views_v1::ViewProvider> view_provider_request) {
shells_bindings_.AddBinding(this, std::move(view_provider_request));
}

// |mozart::ViewProvider|
// |views_v1::ViewProvider|
void Application::CreateView(
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner,
f1dl::InterfaceRequest<component::ServiceProvider>) {
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner,
fidl::InterfaceRequest<component::ServiceProvider>) {
if (!application_context_) {
FXL_DLOG(ERROR) << "Application context was invalid when attempting to "
"create a shell for a view provider request.";
Expand Down
39 changes: 21 additions & 18 deletions content_handler/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
#include <memory>
#include <set>

#include <fuchsia/cpp/component.h>
#include <fuchsia/cpp/views_v1.h>
#include <fuchsia/cpp/views_v1_token.h>

#include "engine.h"
#include "flutter/common/settings.h"
#include "lib/app/cpp/application_context.h"
#include "lib/app/fidl/application_controller.fidl.h"
#include "lib/fidl/cpp/bindings/binding_set.h"
#include "lib/fidl/cpp/binding_set.h"
#include "lib/fidl/cpp/interface_request.h"
#include "lib/fsl/threading/thread.h"
#include "lib/fxl/files/unique_fd.h"
#include "lib/fxl/macros.h"
#include "lib/svc/cpp/service_provider_bridge.h"
#include "lib/ui/views/fidl/view_provider.fidl.h"
#include "unique_fdio_ns.h"

namespace flutter {
Expand All @@ -26,7 +29,7 @@ namespace flutter {
// Flutter engine instances.
class Application final : public Engine::Delegate,
public component::ApplicationController,
public mozart::ViewProvider {
public views_v1::ViewProvider {
public:
class Delegate {
public:
Expand All @@ -38,9 +41,9 @@ class Application final : public Engine::Delegate,
// This is a synchronous operation.
static std::pair<std::unique_ptr<fsl::Thread>, std::unique_ptr<Application>>
Create(Application::Delegate& delegate,
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller);
component::ApplicationPackage package,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller);

// Must be called on the same thread returned from the create call. The thread
// may be collected after.
Expand All @@ -53,20 +56,20 @@ class Application final : public Engine::Delegate,
UniqueFDIONS fdio_ns_ = UniqueFDIONSCreate();
fxl::UniqueFD application_directory_;
fxl::UniqueFD application_assets_directory_;
f1dl::Binding<component::ApplicationController> application_controller_;
f1dl::InterfaceRequest<component::ServiceProvider> outgoing_services_request_;
fidl::Binding<component::ApplicationController> application_controller_;
fidl::InterfaceRequest<component::ServiceProvider> outgoing_services_request_;
component::ServiceProviderBridge service_provider_bridge_;
std::unique_ptr<component::ApplicationContext> application_context_;
f1dl::BindingSet<mozart::ViewProvider> shells_bindings_;
fidl::BindingSet<views_v1::ViewProvider> shells_bindings_;
std::set<std::unique_ptr<Engine>> shell_holders_;
std::vector<WaitCallback> wait_callbacks_;
std::pair<bool, uint32_t> last_return_code_;

Application(
Application::Delegate& delegate,
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller);
component::ApplicationPackage package,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller);

// |component::ApplicationController|
void Kill() override;
Expand All @@ -75,18 +78,18 @@ class Application final : public Engine::Delegate,
void Detach() override;

// |component::ApplicationController|
void Wait(const WaitCallback& callback) override;
void Wait(WaitCallback callback) override;

// |mozart::ViewProvider|
// |views_v1::ViewProvider|
void CreateView(
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner,
f1dl::InterfaceRequest<component::ServiceProvider> services) override;
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner,
fidl::InterfaceRequest<component::ServiceProvider> services) override;

// |flutter::Engine::Delegate|
void OnEngineTerminate(const Engine* holder) override;

void CreateShellForView(
f1dl::InterfaceRequest<mozart::ViewProvider> view_provider_request);
fidl::InterfaceRequest<views_v1::ViewProvider> view_provider_request);

void AttemptVMLaunchWithCurrentSettings(
const blink::Settings& settings) const;
Expand Down
9 changes: 4 additions & 5 deletions content_handler/application_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "flutter/lib/ui/text/font_collection.h"
#include "fuchsia_font_manager.h"
#include "lib/fonts/fidl/font_provider.fidl.h"
#include "lib/icu_data/cpp/icu_data.h"

namespace flutter {
Expand Down Expand Up @@ -38,14 +37,14 @@ ApplicationRunner::~ApplicationRunner() {
}

void ApplicationRunner::RegisterApplication(
f1dl::InterfaceRequest<component::ApplicationRunner> request) {
fidl::InterfaceRequest<component::ApplicationRunner> request) {
active_applications_bindings_.AddBinding(this, std::move(request));
}

void ApplicationRunner::StartApplication(
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller) {
component::ApplicationPackage package,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller) {
auto thread_application_pair =
Application::Create(*this, // delegate
std::move(package), // application pacakge
Expand Down
15 changes: 8 additions & 7 deletions content_handler/application_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include <memory>
#include <unordered_map>

#include <fuchsia/cpp/component.h>

#include "application.h"
#include "lib/app/cpp/application_context.h"
#include "lib/app/fidl/application_runner.fidl.h"
#include "lib/fidl/cpp/bindings/binding_set.h"
#include "lib/fidl/cpp/binding_set.h"
#include "lib/fsl/tasks/message_loop.h"
#include "lib/fxl/functional/make_copyable.h"
#include "lib/fxl/macros.h"
Expand Down Expand Up @@ -49,18 +50,18 @@ class ApplicationRunner final : public Application::Delegate,

fxl::Closure on_termination_callback_;
std::unique_ptr<component::ApplicationContext> host_context_;
f1dl::BindingSet<component::ApplicationRunner> active_applications_bindings_;
fidl::BindingSet<component::ApplicationRunner> active_applications_bindings_;
std::unordered_map<const Application*, ActiveApplication>
active_applications_;

// |component::ApplicationRunner|
void StartApplication(component::ApplicationPackagePtr application,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController>
void StartApplication(component::ApplicationPackage application,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController>
controller) override;

void RegisterApplication(
f1dl::InterfaceRequest<component::ApplicationRunner> request);
fidl::InterfaceRequest<component::ApplicationRunner> request);

void UnregisterApplication(const Application* application);

Expand Down
3 changes: 2 additions & 1 deletion content_handler/compositor_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

#pragma once

#include <fuchsia/cpp/ui.h>

#include "flutter/flow/compositor_context.h"
#include "garnet/public/lib/ui/scenic/fidl/scenic.fidl-common.h"
#include "lib/fxl/macros.h"
#include "session_connection.h"

Expand Down
Loading

0 comments on commit 79b9ffb

Please sign in to comment.