forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication_controller_impl.cc
98 lines (79 loc) · 3.01 KB
/
application_controller_impl.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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.
#include "flutter/content_handler/application_controller_impl.h"
#include <utility>
#include "application/lib/app/connect.h"
#include "flutter/content_handler/app.h"
#include "flutter/content_handler/runtime_holder.h"
#include "lib/ftl/logging.h"
#include "lib/mtl/vmo/vector.h"
namespace flutter_runner {
ApplicationControllerImpl::ApplicationControllerImpl(
App* app,
app::ApplicationPackagePtr application,
app::ApplicationStartupInfoPtr startup_info,
fidl::InterfaceRequest<app::ApplicationController> controller)
: app_(app), binding_(this) {
if (controller.is_pending()) {
binding_.Bind(std::move(controller));
binding_.set_connection_error_handler([this] {
app_->Destroy(this);
// |this| has been deleted at this point.
});
}
std::vector<char> bundle;
if (!mtl::VectorFromVmo(std::move(application->data), &bundle)) {
FTL_LOG(ERROR) << "Failed to receive bundle.";
return;
}
// TODO(jeffbrown): Decide what to do with command-line arguments and
// startup handles.
if (startup_info->launch_info->services) {
service_provider_bridge_.AddBinding(
std::move(startup_info->launch_info->services));
}
if (startup_info->launch_info->service_request.is_valid()) {
service_provider_bridge_.ServeDirectory(
std::move(startup_info->launch_info->service_request));
}
service_provider_bridge_.AddService<mozart::ViewProvider>(
[this](fidl::InterfaceRequest<mozart::ViewProvider> request) {
view_provider_bindings_.AddBinding(this, std::move(request));
});
app::ServiceProviderPtr service_provider;
auto request = service_provider.NewRequest();
service_provider_bridge_.set_backend(std::move(service_provider));
url_ = startup_info->launch_info->url;
runtime_holder_.reset(new RuntimeHolder());
runtime_holder_->Init(
app::ApplicationContext::CreateFrom(std::move(startup_info)),
std::move(request), std::move(bundle));
}
ApplicationControllerImpl::~ApplicationControllerImpl() = default;
void ApplicationControllerImpl::Kill() {
runtime_holder_.reset();
app_->Destroy(this);
// |this| has been deleted at this point.
}
void ApplicationControllerImpl::Detach() {
binding_.set_connection_error_handler(ftl::Closure());
}
void ApplicationControllerImpl::CreateView(
fidl::InterfaceRequest<mozart::ViewOwner> view_owner_request,
fidl::InterfaceRequest<app::ServiceProvider> services) {
runtime_holder_->CreateView(url_, std::move(view_owner_request),
std::move(services));
}
Dart_Port ApplicationControllerImpl::GetUIIsolateMainPort() {
if (!runtime_holder_)
return ILLEGAL_PORT;
return runtime_holder_->GetUIIsolateMainPort();
}
std::string ApplicationControllerImpl::GetUIIsolateName() {
if (!runtime_holder_) {
return "";
}
return runtime_holder_->GetUIIsolateName();
}
} // namespace flutter_runner