Make clicking links work in SkyDB

Now the SkyDebugger implements NavigatorHost and actually navigates the
mojo::View. This CL pulled a big refactor of sky/tools/debugger to separate out
MojoMain from debugger.cc.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/690363002
This commit is contained in:
Adam Barth
2014-10-31 13:17:15 -07:00
parent 60314d529b
commit d11c879659
9 changed files with 278 additions and 134 deletions

View File

@@ -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",

View File

@@ -0,0 +1,5 @@
include_rules = [
"+mojo/public",
"+mojo/application",
"+mojo/services",
]

View File

@@ -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<Debugger>,
public mojo::InterfaceImpl<Debugger> {
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<mojo::ServiceProvider> 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<Debugger>
virtual void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<Debugger> 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<mojo::ServiceProviderImpl> 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<mojo::WindowManagerApp> window_manager_app_;
mojo::ViewManager* view_manager_;
mojo::View* root_;
mojo::View* content_;
std::string pending_url_;
scoped_ptr<mojo::ServiceProvider> 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> 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<mojo::ServiceProvider> 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<Debugger> 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<mojo::ServiceProviderImpl> 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

View File

@@ -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<Debugger>,
public mojo::InterfaceImpl<Debugger> {
public:
SkyDebugger();
virtual ~SkyDebugger();
base::WeakPtr<SkyDebugger> 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<mojo::ServiceProvider> 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<Debugger>
void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<Debugger> request) override;
scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
mojo::ViewManager* view_manager_;
mojo::View* root_;
mojo::View* content_;
std::string pending_url_;
scoped_ptr<mojo::ServiceProvider> viewer_services_;
NavigatorHostFactory navigator_host_factory_;
base::WeakPtrFactory<SkyDebugger> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(SkyDebugger);
};
} // namespace debugger
} // namespace sky

View File

@@ -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

View File

@@ -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_

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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<mojo::NavigatorHost> {
public:
explicit NavigatorHostImpl(SkyDebugger*);
~NavigatorHostImpl();
private:
void DidNavigateLocally(const mojo::String& url) override;
void RequestNavigate(mojo::Target target, mojo::URLRequestPtr request) override;
base::WeakPtr<SkyDebugger> debugger_;
DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl);
};
typedef mojo::InterfaceFactoryImplWithContext<
NavigatorHostImpl, SkyDebugger> NavigatorHostFactory;
} // namespace debugger
} // namespace sky
#endif // SKY_TOOLS_DEBUGGER_NAVIGATOR_HOST_IMPL_H_