diff --git a/engine/src/flutter/tools/debugger/BUILD.gn b/engine/src/flutter/tools/debugger/BUILD.gn index 1efddf46f9..199269cc46 100644 --- a/engine/src/flutter/tools/debugger/BUILD.gn +++ b/engine/src/flutter/tools/debugger/BUILD.gn @@ -16,8 +16,12 @@ group("debugger") { shared_library("sky_debugger") { sources = [ "debugger.cc", + "debugger.h", "focus_rules.cc", "focus_rules.h", + "main.cc", + "navigator_host_impl.cc", + "navigator_host_impl.h", ] deps = [ @@ -30,6 +34,7 @@ shared_library("sky_debugger") { "//mojo/public/cpp/utility", "//mojo/services/public/cpp/view_manager", "//mojo/services/public/interfaces/input_events:input_events", + "//mojo/services/public/interfaces/navigation", "//mojo/services/window_manager:lib", "//sky/viewer:bindings", "//ui/aura:aura", diff --git a/engine/src/flutter/tools/debugger/DEPS b/engine/src/flutter/tools/debugger/DEPS new file mode 100644 index 0000000000..f97d96c0d2 --- /dev/null +++ b/engine/src/flutter/tools/debugger/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + "+mojo/public", + "+mojo/application", + "+mojo/services", +] diff --git a/engine/src/flutter/tools/debugger/debugger.cc b/engine/src/flutter/tools/debugger/debugger.cc index 82b0ea154f..a764ae5957 100644 --- a/engine/src/flutter/tools/debugger/debugger.cc +++ b/engine/src/flutter/tools/debugger/debugger.cc @@ -2,141 +2,110 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "mojo/application/application_runner_chromium.h" -#include "mojo/public/c/system/main.h" -#include "mojo/public/cpp/application/application_delegate.h" -#include "mojo/public/cpp/application/application_impl.h" -#include "mojo/public/cpp/application/connect.h" -#include "mojo/public/cpp/application/service_provider_impl.h" -#include "mojo/services/public/cpp/view_manager/view_manager.h" -#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" -#include "mojo/services/public/cpp/view_manager/view_observer.h" -#include "mojo/services/public/interfaces/input_events/input_events.mojom.h" -#include "mojo/services/window_manager/window_manager_app.h" -#include "mojo/services/window_manager/window_manager_delegate.h" -#include "sky/tools/debugger/focus_rules.h" -#include "sky/tools/debugger/debugger.mojom.h" -#include "sky/viewer/services/inspector.mojom.h" +#include "sky/tools/debugger/debugger.h" namespace sky { +namespace debugger { -class SkyDebugger : public mojo::ApplicationDelegate, - public mojo::ViewManagerDelegate, - public mojo::ViewObserver, - public mojo::InterfaceFactory, - public mojo::InterfaceImpl { - public: - SkyDebugger() - : window_manager_app_(new mojo::WindowManagerApp(this, nullptr)), - view_manager_(nullptr), - root_(nullptr), - content_(nullptr) {} - virtual ~SkyDebugger() {} - - private: - // Overridden from mojo::ApplicationDelegate: - virtual void Initialize(mojo::ApplicationImpl* app) override { - window_manager_app_->Initialize(app); - app->ConnectToApplication("mojo:sky_debugger_prompt"); - } - - virtual bool ConfigureIncomingConnection( - mojo::ApplicationConnection* connection) override { - window_manager_app_->ConfigureIncomingConnection(connection); - connection->AddService(this); - return true; - } - - virtual bool ConfigureOutgoingConnection( - mojo::ApplicationConnection* connection) override { - window_manager_app_->ConfigureOutgoingConnection(connection); - connection->AddService(this); - return true; - } - - // Overridden from mojo::ViewManagerDelegate: - virtual void OnEmbed( - mojo::ViewManager* view_manager, - mojo::View* root, - mojo::ServiceProviderImpl* exported_services, - scoped_ptr imported_services) override { - view_manager_ = view_manager; - - root_ = root; - root_->AddObserver(this); - - window_manager_app_->SetViewportSize(gfx::Size(320, 640)); - - content_ = mojo::View::Create(view_manager_); - content_->SetBounds(root_->bounds()); - root_->AddChild(content_); - - window_manager_app_->InitFocus( - new FocusRules(window_manager_app_.get(), content_)); - - if (!pending_url_.empty()) - NavigateToURL(pending_url_); - } - - virtual void OnViewManagerDisconnected( - mojo::ViewManager* view_manager) override { - CHECK(false); // FIXME: This is dead code, why? - view_manager_ = nullptr; - root_ = nullptr; - } - - virtual void OnViewDestroyed(mojo::View* view) override { - CHECK(false); // FIXME: This is dead code, why? - view->RemoveObserver(this); - } - - virtual void OnViewBoundsChanged(mojo::View* view, - const mojo::Rect& old_bounds, - const mojo::Rect& new_bounds) override { - content_->SetBounds(new_bounds); - } - - // Overridden from InterfaceFactory - virtual void Create(mojo::ApplicationConnection* connection, - mojo::InterfaceRequest request) override { - mojo::WeakBindToRequest(this, &request); - } - - // Overridden from Debugger - virtual void NavigateToURL(const mojo::String& url) override { - // We can get Navigate commands before we've actually been - // embedded into the view and content_ created. - // Just save the last one. - if (content_) { - scoped_ptr exported_services( - new mojo::ServiceProviderImpl()); - viewer_services_ = content_->Embed(url, exported_services.Pass()); - } else { - pending_url_ = url; - } - } - - virtual void InjectInspector() override { - InspectorServicePtr inspector_service; - mojo::ConnectToService(viewer_services_.get(), &inspector_service); - inspector_service->Inject(); - } - - scoped_ptr window_manager_app_; - - mojo::ViewManager* view_manager_; - mojo::View* root_; - mojo::View* content_; - std::string pending_url_; - - scoped_ptr viewer_services_; - - DISALLOW_COPY_AND_ASSIGN(SkyDebugger); -}; - -} // namespace sky - -MojoResult MojoMain(MojoHandle shell_handle) { - mojo::ApplicationRunnerChromium runner(new sky::SkyDebugger); - return runner.Run(shell_handle); +SkyDebugger::SkyDebugger() + : window_manager_app_(new mojo::WindowManagerApp(this, nullptr)), + view_manager_(nullptr), + root_(nullptr), + content_(nullptr), + navigator_host_factory_(this), + weak_factory_(this) { } + +SkyDebugger::~SkyDebugger() { +} + +base::WeakPtr SkyDebugger::GetWeakPtr() { + return weak_factory_.GetWeakPtr(); +} + +void SkyDebugger::Initialize(mojo::ApplicationImpl* app) { + window_manager_app_->Initialize(app); + app->ConnectToApplication("mojo:sky_debugger_prompt"); +} + +bool SkyDebugger::ConfigureIncomingConnection( + mojo::ApplicationConnection* connection) { + window_manager_app_->ConfigureIncomingConnection(connection); + connection->AddService(this); + return true; +} + +bool SkyDebugger::ConfigureOutgoingConnection( + mojo::ApplicationConnection* connection) { + window_manager_app_->ConfigureOutgoingConnection(connection); + connection->AddService(this); + return true; +} + +void SkyDebugger::OnEmbed( + mojo::ViewManager* view_manager, + mojo::View* root, + mojo::ServiceProviderImpl* exported_services, + scoped_ptr imported_services) { + view_manager_ = view_manager; + + root_ = root; + root_->AddObserver(this); + + window_manager_app_->SetViewportSize(gfx::Size(320, 640)); + + content_ = mojo::View::Create(view_manager_); + content_->SetBounds(root_->bounds()); + root_->AddChild(content_); + + window_manager_app_->InitFocus( + new FocusRules(window_manager_app_.get(), content_)); + + if (!pending_url_.empty()) + NavigateToURL(pending_url_); +} + +void SkyDebugger::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { + CHECK(false); // FIXME: This is dead code, why? + view_manager_ = nullptr; + root_ = nullptr; +} + +void SkyDebugger::OnViewDestroyed(mojo::View* view) { + CHECK(false); // FIXME: This is dead code, why? + view->RemoveObserver(this); +} + +void SkyDebugger::OnViewBoundsChanged(mojo::View* view, + const mojo::Rect& old_bounds, + const mojo::Rect& new_bounds) { + content_->SetBounds(new_bounds); +} + +void SkyDebugger::Create(mojo::ApplicationConnection* connection, + mojo::InterfaceRequest request) { + mojo::WeakBindToRequest(this, &request); +} + +void SkyDebugger::NavigateToURL(const mojo::String& url) { + // We can get Navigate commands before we've actually been + // embedded into the view and content_ created. + // Just save the last one. + if (content_) { + scoped_ptr exported_services( + new mojo::ServiceProviderImpl()); + exported_services->AddService(&navigator_host_factory_); + viewer_services_ = content_->Embed(url, exported_services.Pass()); + } else { + pending_url_ = url; + } +} + +void SkyDebugger::InjectInspector() { + InspectorServicePtr inspector_service; + mojo::ConnectToService(viewer_services_.get(), &inspector_service); + inspector_service->Inject(); +} + +} // namespace debugger +} // namespace sky diff --git a/engine/src/flutter/tools/debugger/debugger.h b/engine/src/flutter/tools/debugger/debugger.h new file mode 100644 index 0000000000..4bd60db068 --- /dev/null +++ b/engine/src/flutter/tools/debugger/debugger.h @@ -0,0 +1,80 @@ +// Copyright 2014 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 "base/memory/weak_ptr.h" +#include "mojo/public/cpp/application/application_delegate.h" +#include "mojo/public/cpp/application/application_impl.h" +#include "mojo/public/cpp/application/connect.h" +#include "mojo/public/cpp/application/service_provider_impl.h" +#include "mojo/services/public/cpp/view_manager/view_manager.h" +#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" +#include "mojo/services/public/cpp/view_manager/view_observer.h" +#include "mojo/services/public/interfaces/input_events/input_events.mojom.h" +#include "mojo/services/public/interfaces/navigation/navigation.mojom.h" +#include "mojo/services/window_manager/window_manager_app.h" +#include "mojo/services/window_manager/window_manager_delegate.h" +#include "sky/tools/debugger/debugger.mojom.h" +#include "sky/tools/debugger/focus_rules.h" +#include "sky/tools/debugger/navigator_host_impl.h" +#include "sky/viewer/services/inspector.mojom.h" + +namespace sky { +namespace debugger { + +class SkyDebugger : public mojo::ApplicationDelegate, + public mojo::ViewManagerDelegate, + public mojo::ViewObserver, + public mojo::InterfaceFactory, + public mojo::InterfaceImpl { + public: + SkyDebugger(); + virtual ~SkyDebugger(); + + base::WeakPtr GetWeakPtr(); + + // Overridden from Debugger + void NavigateToURL(const mojo::String& url) override; + void InjectInspector() override; + + private: + // Overridden from mojo::ApplicationDelegate: + void Initialize(mojo::ApplicationImpl* app) override; + bool ConfigureIncomingConnection( + mojo::ApplicationConnection* connection) override; + bool ConfigureOutgoingConnection( + mojo::ApplicationConnection* connection) override; + + // Overridden from mojo::ViewManagerDelegate: + void OnEmbed(mojo::ViewManager* view_manager, + mojo::View* root, + mojo::ServiceProviderImpl* exported_services, + scoped_ptr imported_services) override; + void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override; + void OnViewDestroyed(mojo::View* view) override; + void OnViewBoundsChanged(mojo::View* view, + const mojo::Rect& old_bounds, + const mojo::Rect& new_bounds) override; + + // Overridden from InterfaceFactory + void Create(mojo::ApplicationConnection* connection, + mojo::InterfaceRequest request) override; + + scoped_ptr window_manager_app_; + + mojo::ViewManager* view_manager_; + mojo::View* root_; + mojo::View* content_; + std::string pending_url_; + + scoped_ptr viewer_services_; + + NavigatorHostFactory navigator_host_factory_; + + base::WeakPtrFactory weak_factory_; + + DISALLOW_COPY_AND_ASSIGN(SkyDebugger); +}; + +} // namespace debugger +} // namespace sky diff --git a/engine/src/flutter/tools/debugger/focus_rules.cc b/engine/src/flutter/tools/debugger/focus_rules.cc index fb193d8b4f..68eca6223c 100644 --- a/engine/src/flutter/tools/debugger/focus_rules.cc +++ b/engine/src/flutter/tools/debugger/focus_rules.cc @@ -5,6 +5,7 @@ #include "sky/tools/debugger/focus_rules.h" namespace sky { +namespace debugger { FocusRules::FocusRules(mojo::WindowManagerApp* window_manager_app, mojo::View* content) @@ -56,4 +57,5 @@ aura::Window* FocusRules::GetNextActivatableWindow(aura::Window* ignore) const { return NULL; } +} // namespace debugger } // namespace sky diff --git a/engine/src/flutter/tools/debugger/focus_rules.h b/engine/src/flutter/tools/debugger/focus_rules.h index ee13cafed8..fa5a91974f 100644 --- a/engine/src/flutter/tools/debugger/focus_rules.h +++ b/engine/src/flutter/tools/debugger/focus_rules.h @@ -10,6 +10,7 @@ #include "ui/wm/core/focus_rules.h" namespace sky { +namespace debugger { class FocusRules : public wm::FocusRules { public: @@ -32,6 +33,7 @@ class FocusRules : public wm::FocusRules { DISALLOW_COPY_AND_ASSIGN(FocusRules); }; +} // namespace debugger } // namespace sky #endif // SKY_TOOLS_DEBUGGER_FOCUS_RULES_H_ diff --git a/engine/src/flutter/tools/debugger/main.cc b/engine/src/flutter/tools/debugger/main.cc new file mode 100644 index 0000000000..9c6ed847e7 --- /dev/null +++ b/engine/src/flutter/tools/debugger/main.cc @@ -0,0 +1,13 @@ +// Copyright 2014 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 "mojo/application/application_runner_chromium.h" +#include "mojo/public/c/system/main.h" + +#include "sky/tools/debugger/debugger.h" + +MojoResult MojoMain(MojoHandle shell_handle) { + mojo::ApplicationRunnerChromium runner(new sky::debugger::SkyDebugger); + return runner.Run(shell_handle); +} diff --git a/engine/src/flutter/tools/debugger/navigator_host_impl.cc b/engine/src/flutter/tools/debugger/navigator_host_impl.cc new file mode 100644 index 0000000000..5422b6400b --- /dev/null +++ b/engine/src/flutter/tools/debugger/navigator_host_impl.cc @@ -0,0 +1,31 @@ +// Copyright 2014 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 "sky/tools/debugger/navigator_host_impl.h" + +#include "sky/tools/debugger/debugger.h" + +namespace sky { +namespace debugger { + +NavigatorHostImpl::NavigatorHostImpl(SkyDebugger* debugger) + : debugger_(debugger->GetWeakPtr()) { +} + +NavigatorHostImpl::~NavigatorHostImpl() { +} + +void NavigatorHostImpl::DidNavigateLocally(const mojo::String& url) { + // TODO(abarth): Do something interesting. +} + +void NavigatorHostImpl::RequestNavigate(mojo::Target target, + mojo::URLRequestPtr request) { + if (!debugger_) + return; + debugger_->NavigateToURL(request->url); +} + +} // namespace debugger +} // namespace sky diff --git a/engine/src/flutter/tools/debugger/navigator_host_impl.h b/engine/src/flutter/tools/debugger/navigator_host_impl.h new file mode 100644 index 0000000000..0d7c7e68b5 --- /dev/null +++ b/engine/src/flutter/tools/debugger/navigator_host_impl.h @@ -0,0 +1,37 @@ +// Copyright 2014 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. + +#ifndef SKY_TOOLS_DEBUGGER_NAVIGATOR_HOST_IMPL_H_ +#define SKY_TOOLS_DEBUGGER_NAVIGATOR_HOST_IMPL_H_ + +#include "base/memory/weak_ptr.h" +#include "mojo/public/cpp/application/interface_factory_impl.h" +#include "mojo/services/public/interfaces/navigation/navigation.mojom.h" +#include "sky/tools/debugger/debugger.mojom.h" + +namespace sky { +namespace debugger { +class SkyDebugger; + +class NavigatorHostImpl : public mojo::InterfaceImpl { + public: + explicit NavigatorHostImpl(SkyDebugger*); + ~NavigatorHostImpl(); + + private: + void DidNavigateLocally(const mojo::String& url) override; + void RequestNavigate(mojo::Target target, mojo::URLRequestPtr request) override; + + base::WeakPtr debugger_; + + DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl); +}; + +typedef mojo::InterfaceFactoryImplWithContext< + NavigatorHostImpl, SkyDebugger> NavigatorHostFactory; + +} // namespace debugger +} // namespace sky + +#endif // SKY_TOOLS_DEBUGGER_NAVIGATOR_HOST_IMPL_H_