summaryrefslogtreecommitdiff
path: root/chromium/fuchsia/runners/common
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/fuchsia/runners/common')
-rw-r--r--chromium/fuchsia/runners/common/web_component.cc68
-rw-r--r--chromium/fuchsia/runners/common/web_component.h39
-rw-r--r--chromium/fuchsia/runners/common/web_content_runner.cc4
3 files changed, 84 insertions, 27 deletions
diff --git a/chromium/fuchsia/runners/common/web_component.cc b/chromium/fuchsia/runners/common/web_component.cc
index 53ef3d1e641..edaf54562da 100644
--- a/chromium/fuchsia/runners/common/web_component.cc
+++ b/chromium/fuchsia/runners/common/web_component.cc
@@ -9,10 +9,10 @@
#include <lib/fidl/cpp/binding_set.h>
#include <lib/fit/function.h>
#include <lib/sys/cpp/component_context.h>
+#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <utility>
#include "base/bind.h"
-#include "base/fuchsia/default_context.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "base/logging.h"
#include "fuchsia/runners/common/web_content_runner.h"
@@ -25,9 +25,9 @@ WebComponent::WebComponent(
: runner_(runner),
startup_context_(std::move(context)),
controller_binding_(this),
- module_context_(startup_context()
- ->svc()
- ->Connect<fuchsia::modular::ModuleContext>()) {
+ module_context_(
+ startup_context()->svc()->Connect<fuchsia::modular::ModuleContext>()),
+ navigation_listener_binding_(this) {
DCHECK(runner);
// If the ComponentController request is valid then bind it, and configure it
@@ -67,13 +67,19 @@ void WebComponent::StartComponent() {
create_params.set_enable_remote_debugging(enable_remote_debugging_);
frame_ = runner_->CreateFrame(std::move(create_params));
- // If the Frame unexpectedly disconnect us then tear-down this Component.
+ // If the Frame unexpectedly disconnects then tear-down this Component.
+ // ZX_OK indicates intentional termination (e.g. via window.close()).
+ // ZX_ERR_PEER_CLOSED will usually indicate a crash, reported elsewhere.
+ // Therefore only log other, more unusual, |status| codes.
frame_.set_error_handler([this](zx_status_t status) {
- ZX_LOG_IF(ERROR, status != ZX_ERR_PEER_CLOSED, status)
- << " Frame disconnected";
- DestroyComponent(0, fuchsia::sys::TerminationReason::EXITED);
+ if (status != ZX_OK && status != ZX_ERR_PEER_CLOSED)
+ ZX_LOG(ERROR, status) << " Frame disconnected";
+ DestroyComponent(status, fuchsia::sys::TerminationReason::EXITED);
});
+ // Observe the Frame for failures, via navigation state change events.
+ frame_->SetNavigationEventListener(navigation_listener_binding_.NewBinding());
+
if (startup_context()->has_outgoing_directory_request()) {
// Publish outgoing services and start serving component's outgoing
// directory.
@@ -110,8 +116,8 @@ void WebComponent::LoadUrl(
}
void WebComponent::Kill() {
- // Signal abnormal process termination.
- DestroyComponent(1, fuchsia::sys::TerminationReason::RUNNER_TERMINATED);
+ // Signal normal termination, since the caller requested it.
+ DestroyComponent(ZX_OK, fuchsia::sys::TerminationReason::EXITED);
}
void WebComponent::Detach() {
@@ -122,19 +128,53 @@ void WebComponent::CreateView(
zx::eventpair view_token_value,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> incoming_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> outgoing_services) {
+ scenic::ViewRefPair view_ref_pair = scenic::ViewRefPair::New();
+ CreateViewWithViewRef(std::move(view_token_value),
+ std::move(view_ref_pair.control_ref),
+ std::move(view_ref_pair.view_ref));
+}
+
+void WebComponent::CreateViewWithViewRef(
+ zx::eventpair view_token_value,
+ fuchsia::ui::views::ViewRefControl control_ref,
+ fuchsia::ui::views::ViewRef view_ref) {
DCHECK(frame_);
- DCHECK(!view_is_bound_);
+ if (view_is_bound_) {
+ LOG(ERROR) << "CreateView() called more than once.";
+ DestroyComponent(ZX_ERR_BAD_STATE, fuchsia::sys::TerminationReason::EXITED);
+ return;
+ }
fuchsia::ui::views::ViewToken view_token;
view_token.value = std::move(view_token_value);
- frame_->CreateView(std::move(view_token));
+ frame_->CreateViewWithViewRef(std::move(view_token), std::move(control_ref),
+ std::move(view_ref));
view_is_bound_ = true;
}
-void WebComponent::DestroyComponent(int termination_exit_code,
+void WebComponent::OnNavigationStateChanged(
+ fuchsia::web::NavigationState change,
+ OnNavigationStateChangedCallback callback) {
+ if (change.has_page_type()) {
+ switch (change.page_type()) {
+ case fuchsia::web::PageType::ERROR:
+ DestroyComponent(ZX_ERR_INTERNAL,
+ fuchsia::sys::TerminationReason::EXITED);
+ break;
+ case fuchsia::web::PageType::NORMAL:
+ break;
+ }
+ }
+ // Do not touch |this|, which may have been deleted by DestroyComponent().
+
+ // |callback| is safe to run, since it is on the stack.
+ callback();
+}
+
+void WebComponent::DestroyComponent(int64_t exit_code,
fuchsia::sys::TerminationReason reason) {
termination_reason_ = reason;
- termination_exit_code_ = termination_exit_code;
+ termination_exit_code_ = exit_code;
runner_->DestroyComponent(this);
}
diff --git a/chromium/fuchsia/runners/common/web_component.h b/chromium/fuchsia/runners/common/web_component.h
index 4653f465058..0ed8cebbc42 100644
--- a/chromium/fuchsia/runners/common/web_component.h
+++ b/chromium/fuchsia/runners/common/web_component.h
@@ -18,7 +18,6 @@
#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/startup_context.h"
-#include "base/logging.h"
#include "fuchsia/base/lifecycle_impl.h"
#include "url/gurl.h"
@@ -30,7 +29,8 @@ class WebContentRunner;
// (e.g. Cast applications) can extend this class to configure the Frame to
// their needs, publish additional APIs, etc.
class WebComponent : public fuchsia::sys::ComponentController,
- public fuchsia::ui::app::ViewProvider {
+ public fuchsia::ui::app::ViewProvider,
+ public fuchsia::web::NavigationEventListener {
public:
// Creates a WebComponent encapsulating a web.Frame. A ViewProvider service
// will be published to the service-directory specified by |startup_context|,
@@ -60,6 +60,12 @@ class WebComponent : public fuchsia::sys::ComponentController,
WebContentRunner* runner() const { return runner_; }
+ // Returns the component's startup context (e.g. incoming services, public
+ // service directory, etc).
+ base::fuchsia::StartupContext* startup_context() const {
+ return startup_context_.get();
+ }
+
protected:
// fuchsia::sys::ComponentController implementation.
void Kill() override;
@@ -71,18 +77,24 @@ class WebComponent : public fuchsia::sys::ComponentController,
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> incoming_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> outgoing_services)
override;
+ void CreateViewWithViewRef(zx::eventpair view_token,
+ fuchsia::ui::views::ViewRefControl control_ref,
+ fuchsia::ui::views::ViewRef view_ref) override;
+
+ // fuchsia::web::NavigationEventListener implementation.
+ // Used to detect when the Frame enters an error state (e.g. the top-level
+ // content's Renderer process crashes).
+ void OnNavigationStateChanged(
+ fuchsia::web::NavigationState change,
+ OnNavigationStateChangedCallback callback) override;
// Reports the supplied exit-code and reason to the |controller_binding_| and
- // requests that the |runner_| delete this component.
- virtual void DestroyComponent(int termination_exit_code,
+ // requests that the |runner_| delete this component. The EXITED |reason| is
+ // used to indicate Frame disconnection, in which case the |exit_code| is set
+ // to the status reported by the FramePtr's error handler.
+ virtual void DestroyComponent(int64_t exit_code,
fuchsia::sys::TerminationReason reason);
- // Returns the component's startup context (e.g. incoming services, public
- // service directory, etc).
- base::fuchsia::StartupContext* startup_context() const {
- return startup_context_.get();
- }
-
private:
WebContentRunner* const runner_ = nullptr;
const std::unique_ptr<base::fuchsia::StartupContext> startup_context_;
@@ -105,13 +117,18 @@ class WebComponent : public fuchsia::sys::ComponentController,
// sys::ComponentController::OnTerminated event.
fuchsia::sys::TerminationReason termination_reason_ =
fuchsia::sys::TerminationReason::UNKNOWN;
- int termination_exit_code_ = 0;
+ int64_t termination_exit_code_ = 0;
bool view_is_bound_ = false;
bool component_started_ = false;
bool enable_remote_debugging_ = false;
+ // Used to watch for failures of the Frame's web content, including Renderer
+ // process crashes.
+ fidl::Binding<fuchsia::web::NavigationEventListener>
+ navigation_listener_binding_;
+
DISALLOW_COPY_AND_ASSIGN(WebComponent);
};
diff --git a/chromium/fuchsia/runners/common/web_content_runner.cc b/chromium/fuchsia/runners/common/web_content_runner.cc
index 22ea1651c35..34140e73d25 100644
--- a/chromium/fuchsia/runners/common/web_content_runner.cc
+++ b/chromium/fuchsia/runners/common/web_content_runner.cc
@@ -12,9 +12,9 @@
#include "base/bind.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
-#include "base/fuchsia/default_context.h"
#include "base/fuchsia/file_utils.h"
#include "base/fuchsia/fuchsia_logging.h"
+#include "base/fuchsia/process_context.h"
#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/startup_context.h"
#include "base/logging.h"
@@ -26,7 +26,7 @@ namespace {
fuchsia::web::ContextPtr CreateWebContext(
fuchsia::web::CreateContextParams context_params) {
- auto context_provider = base::fuchsia::ComponentContextForCurrentProcess()
+ auto context_provider = base::ComponentContextForProcess()
->svc()
->Connect<fuchsia::web::ContextProvider>();
fuchsia::web::ContextPtr web_context;