Eric Seidel 9f0f8f500c Make it possible to pass a default url to sky_debugger
sky_debugger will load the default url in every view that it's
asked to embed.  Think of the default_url as being like the
home-page in a conventional browser.

I also fixed prompt.cc to not terminate the entire mojo
environment when it can't start itself, but rather just
quit its own application.

With this patch I'm able to hack up mojo_shell to be able
to have a sensible default behavior when clicked from
the Android homescreen, but I'll land those hacks in a
separate change.

TBR=abarth@chromium.org
BUG=451620

Review URL: https://codereview.chromium.org/875183002
2015-01-26 13:19:06 -08:00

134 lines
4.1 KiB
C++

// 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/debugger.h"
#include "services/window_manager/basic_focus_rules.h"
namespace sky {
namespace debugger {
SkyDebugger::SkyDebugger()
: window_manager_app_(new window_manager::WindowManagerApp(this, this)),
root_(nullptr),
content_(nullptr),
navigator_host_factory_(this),
weak_factory_(this) {
exposed_services_impl_.AddService(&navigator_host_factory_);
}
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");
// Format: --args-for="app_url default_url"
if (app->args().size() > 1)
default_url_ = app->args()[1];
}
bool SkyDebugger::ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) {
window_manager_app_->ConfigureIncomingConnection(connection);
connection->AddService(this);
if (!default_url_.empty())
NavigateToURL(default_url_); // Schedule a navigation in the new embedding.
return true;
}
bool SkyDebugger::ConfigureOutgoingConnection(
mojo::ApplicationConnection* connection) {
window_manager_app_->ConfigureOutgoingConnection(connection);
connection->AddService(this);
return true;
}
void SkyDebugger::OnEmbed(
mojo::View* root,
mojo::InterfaceRequest<mojo::ServiceProvider> services,
mojo::ServiceProviderPtr exposed_services) {
root_ = root;
root_->AddObserver(this);
window_manager_app_->SetViewportSize(gfx::Size(320, 640));
content_ = root->view_manager()->CreateView();
content_->SetBounds(root_->bounds());
root_->AddChild(content_);
content_->SetVisible(true);
window_manager_app_->InitFocus(
make_scoped_ptr(new window_manager::BasicFocusRules(root_)));
if (!pending_url_.empty())
NavigateToURL(pending_url_);
}
void SkyDebugger::Embed(const mojo::String& url,
mojo::InterfaceRequest<mojo::ServiceProvider> services,
mojo::ServiceProviderPtr exposed_services) {
content_->Embed(url, nullptr, nullptr);
}
void SkyDebugger::OnViewManagerDisconnected(mojo::ViewManager* view_manager) {
root_ = nullptr;
}
void SkyDebugger::OnViewDestroyed(mojo::View* view) {
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_) {
mojo::ServiceProviderPtr exposed_services;
exposed_services_impl_.Bind(GetProxy(&exposed_services));
content_->Embed(url, GetProxy(&viewer_services_), exposed_services.Pass());
} else {
pending_url_ = url;
}
}
void SkyDebugger::Shutdown() {
// Make sure we shut down mojo before quitting the message loop or things
// like blink::shutdown() may try to talk to the message loop and crash.
window_manager_app_.reset();
// TODO(eseidel): This still hits an X11 error which I don't understand
// "X Error of failed request: GLXBadDrawable", crbug.com/430581
mojo::ApplicationImpl::Terminate();
// TODO(eseidel): REMOVE THIS, temporarily fast-exit now to stop confusing
// folks with exit-time crashes due to GLXBadDrawable above.
exit(0);
}
void SkyDebugger::InjectInspector() {
InspectorServicePtr inspector_service;
mojo::ConnectToService(viewer_services_.get(), &inspector_service);
inspector_service->Inject();
}
} // namespace debugger
} // namespace sky