Commit 0073e99b authored by aa's avatar aa Committed by Commit bot

Expose NavigatorHost via Embed() rather than globally.

BUG=

Review URL: https://codereview.chromium.org/537843002

Cr-Commit-Position: refs/heads/master@{#293469}
parent ba3e74de
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/application_runner_chromium.h" #include "mojo/public/cpp/application/application_runner_chromium.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/view_manager/view.h" #include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h" #include "mojo/services/public/cpp/view_manager/view_manager.h"
...@@ -169,7 +170,6 @@ class Browser : public ApplicationDelegate, ...@@ -169,7 +170,6 @@ class Browser : public ApplicationDelegate,
view_manager_client_factory_.reset( view_manager_client_factory_.reset(
new ViewManagerClientFactory(app->shell(), this)); new ViewManagerClientFactory(app->shell(), this));
views_init_.reset(new ViewsInit); views_init_.reset(new ViewsInit);
app->ConnectToService("mojo:mojo_window_manager", &navigator_host_);
app->ConnectToService("mojo:mojo_window_manager", &window_manager_); app->ConnectToService("mojo:mojo_window_manager", &window_manager_);
} }
...@@ -209,6 +209,7 @@ class Browser : public ApplicationDelegate, ...@@ -209,6 +209,7 @@ class Browser : public ApplicationDelegate,
ServiceProviderImpl* exported_services, ServiceProviderImpl* exported_services,
scoped_ptr<ServiceProvider> imported_services) OVERRIDE { scoped_ptr<ServiceProvider> imported_services) OVERRIDE {
// TODO: deal with OnEmbed() being invoked multiple times. // TODO: deal with OnEmbed() being invoked multiple times.
ConnectToService(imported_services.get(), &navigator_host_);
view_manager_ = view_manager; view_manager_ = view_manager;
root_ = root; root_ = root;
root_->AddObserver(this); root_->AddObserver(this);
...@@ -230,9 +231,7 @@ class Browser : public ApplicationDelegate, ...@@ -230,9 +231,7 @@ class Browser : public ApplicationDelegate,
printf("User entered this URL: %s\n", url.spec().c_str()); printf("User entered this URL: %s\n", url.spec().c_str());
NavigationDetailsPtr nav_details(NavigationDetails::New()); NavigationDetailsPtr nav_details(NavigationDetails::New());
nav_details->request->url = String::From(url); nav_details->request->url = String::From(url);
navigator_host_->RequestNavigate(view_manager_->GetRoots().front()->id(), navigator_host_->RequestNavigate(TARGET_NEW_NODE, nav_details.Pass());
TARGET_NEW_NODE,
nav_details.Pass());
} }
return false; return false;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/application_runner_chromium.h" #include "mojo/public/cpp/application/application_runner_chromium.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/cpp/application/interface_factory_impl.h" #include "mojo/public/cpp/application/interface_factory_impl.h"
#include "mojo/services/public/cpp/view_manager/view.h" #include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h" #include "mojo/services/public/cpp/view_manager/view_manager.h"
...@@ -29,7 +30,13 @@ namespace examples { ...@@ -29,7 +30,13 @@ namespace examples {
const SkColor kColors[] = {SK_ColorYELLOW, SK_ColorRED, SK_ColorGREEN, const SkColor kColors[] = {SK_ColorYELLOW, SK_ColorRED, SK_ColorGREEN,
SK_ColorMAGENTA}; SK_ColorMAGENTA};
class EmbeddedApp; struct Window {
Window(View* root, scoped_ptr<ServiceProvider> embedder_service_provider)
: root(root),
embedder_service_provider(embedder_service_provider.Pass()) {}
View* root;
scoped_ptr<ServiceProvider> embedder_service_provider;
};
class EmbeddedApp class EmbeddedApp
: public ApplicationDelegate, : public ApplicationDelegate,
...@@ -45,11 +52,6 @@ class EmbeddedApp ...@@ -45,11 +52,6 @@ class EmbeddedApp
virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
view_manager_client_factory_.reset( view_manager_client_factory_.reset(
new ViewManagerClientFactory(app->shell(), this)); new ViewManagerClientFactory(app->shell(), this));
// TODO(aa): Weird for embeddee to talk to embedder by URL. Seems like
// embedder should be able to specify the SP embeddee receives, then
// communication can be anonymous.
app->ConnectToService("mojo:mojo_window_manager", &navigator_host_);
} }
virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
...@@ -64,7 +66,7 @@ class EmbeddedApp ...@@ -64,7 +66,7 @@ class EmbeddedApp
ServiceProviderImpl* exported_services, ServiceProviderImpl* exported_services,
scoped_ptr<ServiceProvider> imported_services) OVERRIDE { scoped_ptr<ServiceProvider> imported_services) OVERRIDE {
root->AddObserver(this); root->AddObserver(this);
roots_[root->id()] = root; windows_[root->id()] = new Window(root, imported_services.Pass());
root->SetColor(kColors[next_color_++ % arraysize(kColors)]); root->SetColor(kColors[next_color_++ % arraysize(kColors)]);
} }
virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {
...@@ -73,8 +75,8 @@ class EmbeddedApp ...@@ -73,8 +75,8 @@ class EmbeddedApp
// Overridden from ViewObserver: // Overridden from ViewObserver:
virtual void OnViewDestroyed(View* view) OVERRIDE { virtual void OnViewDestroyed(View* view) OVERRIDE {
DCHECK(roots_.find(view->id()) != roots_.end()); DCHECK(windows_.find(view->id()) != windows_.end());
roots_.erase(view->id()); windows_.erase(view->id());
} }
virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE {
if (event->action == EVENT_TYPE_MOUSE_RELEASED) { if (event->action == EVENT_TYPE_MOUSE_RELEASED) {
...@@ -82,17 +84,18 @@ class EmbeddedApp ...@@ -82,17 +84,18 @@ class EmbeddedApp
NavigationDetailsPtr nav_details(NavigationDetails::New()); NavigationDetailsPtr nav_details(NavigationDetails::New());
nav_details->request->url = nav_details->request->url =
"http://www.aaronboodman.com/z_dropbox/test.html"; "http://www.aaronboodman.com/z_dropbox/test.html";
navigator_host_->RequestNavigate(view->id(), TARGET_SOURCE_NODE, NavigatorHostPtr navigator_host;
nav_details.Pass()); ConnectToService(windows_[view->id()]->embedder_service_provider.get(),
&navigator_host);
navigator_host->RequestNavigate(TARGET_SOURCE_NODE, nav_details.Pass());
} }
} }
} }
NavigatorHostPtr navigator_host_;
scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
typedef std::map<Id, View*> RootMap; typedef std::map<Id, Window*> WindowMap;
RootMap roots_; WindowMap windows_;
int next_color_; int next_color_;
......
...@@ -186,23 +186,6 @@ class ControlPanel : public views::ButtonListener { ...@@ -186,23 +186,6 @@ class ControlPanel : public views::ButtonListener {
DISALLOW_COPY_AND_ASSIGN(ControlPanel); DISALLOW_COPY_AND_ASSIGN(ControlPanel);
}; };
class NavigatorImpl : public InterfaceImpl<Navigator> {
public:
explicit NavigatorImpl(MediaViewer* viewer) : viewer_(viewer) {}
virtual ~NavigatorImpl() {}
private:
// Overridden from Navigator:
virtual void Navigate(
uint32_t view_id,
NavigationDetailsPtr navigation_details,
ResponseDetailsPtr response_details) OVERRIDE;
MediaViewer* viewer_;
DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
};
class MediaViewer class MediaViewer
: public ApplicationDelegate, : public ApplicationDelegate,
public ViewManagerDelegate, public ViewManagerDelegate,
...@@ -210,8 +193,7 @@ class MediaViewer ...@@ -210,8 +193,7 @@ class MediaViewer
public ViewObserver { public ViewObserver {
public: public:
MediaViewer() MediaViewer()
: navigator_factory_(this), : app_(NULL),
app_(NULL),
view_manager_(NULL), view_manager_(NULL),
root_view_(NULL), root_view_(NULL),
control_view_(NULL), control_view_(NULL),
...@@ -225,39 +207,6 @@ class MediaViewer ...@@ -225,39 +207,6 @@ class MediaViewer
root_view_->RemoveObserver(this); root_view_->RemoveObserver(this);
} }
void Navigate(
uint32_t view_id,
NavigationDetailsPtr navigation_details,
ResponseDetailsPtr response_details) {
// TODO(yzshen): This shouldn't be needed once FIFO is ready.
if (!view_manager_) {
pending_navigate_request_.reset(new PendingNavigateRequest);
pending_navigate_request_->view_id = view_id;
pending_navigate_request_->navigation_details = navigation_details.Pass();
pending_navigate_request_->response_details = response_details.Pass();
return;
}
std::string handler = GetHandlerForContentType(
response_details->response->mime_type);
if (handler.empty())
return;
content_view_->Embed(handler);
if (navigation_details) {
NavigatorPtr navigator;
app_->ConnectToService(handler, &navigator);
navigator->Navigate(content_view_->id(), navigation_details.Pass(),
response_details.Pass());
}
// TODO(yzshen): determine the set of controls to show based on what
// interfaces the embedded app provides.
app_->ConnectToService(handler, &zoomable_media_);
}
private: private:
typedef std::map<std::string, std::string> HandlerMap; typedef std::map<std::string, std::string> HandlerMap;
...@@ -278,7 +227,6 @@ class MediaViewer ...@@ -278,7 +227,6 @@ class MediaViewer
virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
OVERRIDE { OVERRIDE {
connection->AddService(&navigator_factory_);
connection->AddService(view_manager_client_factory_.get()); connection->AddService(view_manager_client_factory_.get());
return true; return true;
} }
...@@ -311,14 +259,9 @@ class MediaViewer ...@@ -311,14 +259,9 @@ class MediaViewer
LayoutViews(); LayoutViews();
root_view_->AddObserver(this); root_view_->AddObserver(this);
if (pending_navigate_request_) { content_view_->Embed("TODO");
scoped_ptr<PendingNavigateRequest> request(
pending_navigate_request_.release());
Navigate(request->view_id, request->navigation_details.Pass(),
request->response_details.Pass());
}
} }
virtual void OnViewManagerDisconnected( virtual void OnViewManagerDisconnected(
ViewManager* view_manager) OVERRIDE { ViewManager* view_manager) OVERRIDE {
DCHECK_EQ(view_manager_, view_manager); DCHECK_EQ(view_manager_, view_manager);
...@@ -360,8 +303,6 @@ class MediaViewer ...@@ -360,8 +303,6 @@ class MediaViewer
return it != handler_map_.end() ? it->second : std::string(); return it != handler_map_.end() ? it->second : std::string();
} }
InterfaceFactoryImplWithContext<NavigatorImpl, MediaViewer>
navigator_factory_;
scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
ApplicationImpl* app_; ApplicationImpl* app_;
...@@ -373,19 +314,10 @@ class MediaViewer ...@@ -373,19 +314,10 @@ class MediaViewer
ControlPanel control_panel_; ControlPanel control_panel_;
ZoomableMediaPtr zoomable_media_; ZoomableMediaPtr zoomable_media_;
HandlerMap handler_map_; HandlerMap handler_map_;
scoped_ptr<PendingNavigateRequest> pending_navigate_request_;
DISALLOW_COPY_AND_ASSIGN(MediaViewer); DISALLOW_COPY_AND_ASSIGN(MediaViewer);
}; };
void NavigatorImpl::Navigate(
uint32_t view_id,
NavigationDetailsPtr navigation_details,
ResponseDetailsPtr response_details) {
viewer_->Navigate(view_id, navigation_details.Pass(),
response_details.Pass());
}
} // namespace examples } // namespace examples
} // namespace mojo } // namespace mojo
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/application_runner_chromium.h" #include "mojo/public/cpp/application/application_runner_chromium.h"
#include "mojo/public/cpp/application/interface_factory_impl.h" #include "mojo/public/cpp/application/interface_factory_impl.h"
#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h" #include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
#include "mojo/services/public/cpp/view_manager/view.h" #include "mojo/services/public/cpp/view_manager/view.h"
...@@ -66,19 +67,19 @@ class WindowManagerConnection : public InterfaceImpl<IWindowManager> { ...@@ -66,19 +67,19 @@ class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> { class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> {
public: public:
explicit NavigatorHostImpl(WindowManager* window_manager) explicit NavigatorHostImpl(WindowManager* window_manager, Id view_id)
: window_manager_(window_manager) {} : window_manager_(window_manager), view_id_(view_id) {}
virtual ~NavigatorHostImpl() { virtual ~NavigatorHostImpl() {
} }
private: private:
virtual void DidNavigateLocally(uint32 source_view_id, virtual void DidNavigateLocally(const mojo::String& url) OVERRIDE;
const mojo::String& url) OVERRIDE;
virtual void RequestNavigate( virtual void RequestNavigate(
uint32 source_view_id,
Target target, Target target,
NavigationDetailsPtr nav_details) OVERRIDE; NavigationDetailsPtr nav_details) OVERRIDE;
WindowManager* window_manager_; WindowManager* window_manager_;
Id view_id_;
DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl); DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl);
}; };
...@@ -249,6 +250,34 @@ class RootLayoutManager : public ViewObserver { ...@@ -249,6 +250,34 @@ class RootLayoutManager : public ViewObserver {
DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); DISALLOW_COPY_AND_ASSIGN(RootLayoutManager);
}; };
class Window : public InterfaceFactory<NavigatorHost> {
public:
Window(WindowManager* window_manager, View* view)
: window_manager_(window_manager), view_(view) {}
virtual ~Window() {}
View* view() const { return view_; }
void Embed(const std::string& url) {
scoped_ptr<ServiceProviderImpl> service_provider_impl(
new ServiceProviderImpl());
service_provider_impl->AddService<NavigatorHost>(this);
view_->Embed(url, service_provider_impl.Pass());
}
private:
// InterfaceFactory<NavigatorHost>
virtual void Create(ApplicationConnection* connection,
InterfaceRequest<NavigatorHost> request) OVERRIDE {
BindToRequest(new NavigatorHostImpl(window_manager_, view_->id()),
&request);
}
WindowManager* window_manager_;
View* view_;
};
class WindowManager class WindowManager
: public ApplicationDelegate, : public ApplicationDelegate,
public DebugPanel::Delegate, public DebugPanel::Delegate,
...@@ -258,7 +287,6 @@ class WindowManager ...@@ -258,7 +287,6 @@ class WindowManager
public: public:
WindowManager() WindowManager()
: window_manager_factory_(this), : window_manager_factory_(this),
navigator_host_factory_(this),
launcher_ui_(NULL), launcher_ui_(NULL),
view_manager_(NULL), view_manager_(NULL),
window_manager_app_(new WindowManagerApp(this, this)), window_manager_app_(new WindowManagerApp(this, this)),
...@@ -272,13 +300,10 @@ class WindowManager ...@@ -272,13 +300,10 @@ class WindowManager
} }
void CloseWindow(Id view_id) { void CloseWindow(Id view_id) {
View* view = view_manager_->GetViewById(view_id); WindowVector::iterator iter = GetWindowByViewId(view_id);
DCHECK(view);
std::vector<View*>::iterator iter =
std::find(windows_.begin(), windows_.end(), view);
DCHECK(iter != windows_.end()); DCHECK(iter != windows_.end());
windows_.erase(iter); windows_.erase(iter);
view->Destroy(); (*iter)->view()->Destroy();
} }
void ShowKeyboard(Id view_id, const gfx::Rect& bounds) { void ShowKeyboard(Id view_id, const gfx::Rect& bounds) {
...@@ -314,7 +339,7 @@ class WindowManager ...@@ -314,7 +339,7 @@ class WindowManager
// Overridden from DebugPanel::Delegate: // Overridden from DebugPanel::Delegate:
virtual void CloseTopWindow() OVERRIDE { virtual void CloseTopWindow() OVERRIDE {
if (!windows_.empty()) if (!windows_.empty())
CloseWindow(windows_.back()->id()); CloseWindow(windows_.back()->view()->id());
} }
virtual void RequestNavigate( virtual void RequestNavigate(
...@@ -325,6 +350,8 @@ class WindowManager ...@@ -325,6 +350,8 @@ class WindowManager
} }
private: private:
typedef std::vector<Window*> WindowVector;
// Overridden from ApplicationDelegate: // Overridden from ApplicationDelegate:
virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
app_ = app; app_ = app;
...@@ -335,7 +362,6 @@ class WindowManager ...@@ -335,7 +362,6 @@ class WindowManager
virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
MOJO_OVERRIDE { MOJO_OVERRIDE {
connection->AddService(&window_manager_factory_); connection->AddService(&window_manager_factory_);
connection->AddService(&navigator_host_factory_);
window_manager_app_->ConfigureIncomingConnection(connection); window_manager_app_->ConfigureIncomingConnection(connection);
return true; return true;
} }
...@@ -377,7 +403,8 @@ class WindowManager ...@@ -377,7 +403,8 @@ class WindowManager
virtual void Embed( virtual void Embed(
const String& url, const String& url,
InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { InterfaceRequest<ServiceProvider> service_provider) OVERRIDE {
CreateWindow(url); const Id kInvalidSourceViewId = 0;
OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url);
} }
virtual void DispatchEvent(EventPtr event) MOJO_OVERRIDE {} virtual void DispatchEvent(EventPtr event) MOJO_OVERRIDE {}
...@@ -405,21 +432,22 @@ class WindowManager ...@@ -405,21 +432,22 @@ class WindowManager
} }
} }
View* dest_view = NULL; Window* dest_view = NULL;
if (target == TARGET_SOURCE_NODE) { if (target == TARGET_SOURCE_NODE) {
View* source_view = view_manager_->GetViewById(source_view_id); WindowVector::iterator source_view = GetWindowByViewId(source_view_id);
bool app_initiated = std::find(windows_.begin(), windows_.end(), bool app_initiated = source_view != windows_.end();
source_view) != windows_.end();
if (app_initiated) if (app_initiated)
dest_view = source_view; dest_view = *source_view;
else if (!windows_.empty()) else if (!windows_.empty())
dest_view = windows_.back(); dest_view = windows_.back();
} }
if (dest_view) if (!dest_view) {
dest_view->Embed(url); dest_view = CreateWindow();
else windows_.push_back(dest_view);
CreateWindow(url); }
dest_view->Embed(url);
} }
// TODO(beng): proper layout manager!! // TODO(beng): proper layout manager!!
...@@ -430,11 +458,12 @@ class WindowManager ...@@ -430,11 +458,12 @@ class WindowManager
gfx::Rect bounds = view->bounds(); gfx::Rect bounds = view->bounds();
bounds.Inset(kBorderInset, kBorderInset); bounds.Inset(kBorderInset, kBorderInset);
bounds.set_height(kTextfieldHeight); bounds.set_height(kTextfieldHeight);
launcher_ui_ = CreateChild(content_view_id_, "mojo:mojo_browser", bounds); launcher_ui_ = CreateWindow(bounds);
return launcher_ui_->id(); launcher_ui_->Embed("mojo:mojo_browser");
return launcher_ui_->view()->id();
} }
void CreateWindow(const std::string& url) { Window* CreateWindow() {
View* view = view_manager_->GetViewById(content_view_id_); View* view = view_manager_->GetViewById(content_view_id_);
gfx::Rect bounds(kBorderInset, gfx::Rect bounds(kBorderInset,
2 * kBorderInset + kTextfieldHeight, 2 * kBorderInset + kTextfieldHeight,
...@@ -443,23 +472,20 @@ class WindowManager ...@@ -443,23 +472,20 @@ class WindowManager
view->bounds().height() - view->bounds().height() -
(3 * kBorderInset + kTextfieldHeight)); (3 * kBorderInset + kTextfieldHeight));
if (!windows_.empty()) { if (!windows_.empty()) {
gfx::Point position = windows_.back()->bounds().origin(); gfx::Point position = windows_.back()->view()->bounds().origin();
position.Offset(35, 35); position.Offset(35, 35);
bounds.set_origin(position); bounds.set_origin(position);
} }
windows_.push_back(CreateChild(content_view_id_, url, bounds)); return CreateWindow(bounds);
} }
View* CreateChild(Id parent_id, Window* CreateWindow(const gfx::Rect& bounds) {
const std::string& url, View* content = view_manager_->GetViewById(content_view_id_);
const gfx::Rect& bounds) { View* view = View::Create(view_manager_);
View* view = view_manager_->GetViewById(parent_id); content->AddChild(view);
View* embedded = View::Create(view_manager_); view->SetBounds(bounds);
view->AddChild(embedded); view->SetFocus();
embedded->SetBounds(bounds); return new Window(this, view);
embedded->Embed(url);
embedded->SetFocus();
return embedded;
} }
bool IsDescendantOfKeyboard(View* target) { bool IsDescendantOfKeyboard(View* target) {
...@@ -483,15 +509,24 @@ class WindowManager ...@@ -483,15 +509,24 @@ class WindowManager
return view->id(); return view->id();
} }
WindowVector::iterator GetWindowByViewId(Id view_id) {
for (std::vector<Window*>::iterator iter = windows_.begin();
iter != windows_.end();
++iter) {
if ((*iter)->view()->id() == view_id) {
return iter;
}
}
return windows_.end();
}
InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager>
window_manager_factory_; window_manager_factory_;
InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager>
navigator_host_factory_;
scoped_ptr<ViewsInit> views_init_; scoped_ptr<ViewsInit> views_init_;
DebugPanel* debug_panel_; DebugPanel* debug_panel_;
View* launcher_ui_; Window* launcher_ui_;
std::vector<View*> windows_; WindowVector windows_;
ViewManager* view_manager_; ViewManager* view_manager_;
scoped_ptr<RootLayoutManager> root_layout_manager_; scoped_ptr<RootLayoutManager> root_layout_manager_;
...@@ -518,16 +553,13 @@ void WindowManagerConnection::HideKeyboard(Id view_id) { ...@@ -518,16 +553,13 @@ void WindowManagerConnection::HideKeyboard(Id view_id) {
window_manager_->HideKeyboard(view_id); window_manager_->HideKeyboard(view_id);
} }
void NavigatorHostImpl::DidNavigateLocally(uint32 source_view_id, void NavigatorHostImpl::DidNavigateLocally(const mojo::String& url) {
const mojo::String& url) { window_manager_->DidNavigateLocally(view_id_, url);
window_manager_->DidNavigateLocally(source_view_id, url);
} }
void NavigatorHostImpl::RequestNavigate( void NavigatorHostImpl::RequestNavigate(Target target,
uint32 source_view_id, NavigationDetailsPtr nav_details) {
Target target, window_manager_->RequestNavigate(view_id_, target, nav_details.Pass());
NavigationDetailsPtr nav_details) {
window_manager_->RequestNavigate(source_view_id, target, nav_details.Pass());
} }
} // namespace examples } // namespace examples
......
...@@ -13,12 +13,21 @@ ...@@ -13,12 +13,21 @@
namespace mojo { namespace mojo {
template<typename Interface> template<typename Interface>
class LazyInterfacePtr : InterfacePtr<Interface> { class LazyInterfacePtr : public InterfacePtr<Interface> {
public: public:
LazyInterfacePtr() : service_provider_(NULL) {}
LazyInterfacePtr(ServiceProvider* service_provider) LazyInterfacePtr(ServiceProvider* service_provider)
: service_provider_(service_provider) { : service_provider_(service_provider) {
} }
void set_service_provider(ServiceProvider* service_provider) {
if (service_provider != service_provider_) {
InterfacePtr<Interface>::reset();
}
service_provider_ = service_provider;
}
Interface* get() const { Interface* get() const {
if (!InterfacePtr<Interface>::get()) { if (!InterfacePtr<Interface>::get()) {
mojo::ConnectToService<Interface>( mojo::ConnectToService<Interface>(
......
...@@ -83,17 +83,17 @@ bool CanNavigateLocally(blink::WebFrame* frame, ...@@ -83,17 +83,17 @@ bool CanNavigateLocally(blink::WebFrame* frame,
HTMLDocumentView::HTMLDocumentView( HTMLDocumentView::HTMLDocumentView(
URLResponsePtr response, URLResponsePtr response,
scoped_ptr<ServiceProvider> imported_services, InterfaceRequest<ServiceProvider> service_provider_request,
ServiceProviderImpl* exported_services,
Shell* shell) Shell* shell)
: imported_services_(imported_services.Pass()), : shell_(shell),
shell_(shell),
web_view_(NULL), web_view_(NULL),
root_(NULL), root_(NULL),
view_manager_client_factory_(shell, this), view_manager_client_factory_(shell, this),
repaint_pending_(false), repaint_pending_(false),
weak_factory_(this) { weak_factory_(this) {
ServiceProviderImpl* exported_services = new ServiceProviderImpl();
exported_services->AddService(&view_manager_client_factory_); exported_services->AddService(&view_manager_client_factory_);
BindToRequest(exported_services, &service_provider_request);
Load(response.Pass()); Load(response.Pass());
} }
...@@ -104,11 +104,15 @@ HTMLDocumentView::~HTMLDocumentView() { ...@@ -104,11 +104,15 @@ HTMLDocumentView::~HTMLDocumentView() {
root_->RemoveObserver(this); root_->RemoveObserver(this);
} }
void HTMLDocumentView::OnEmbed(ViewManager* view_manager, void HTMLDocumentView::OnEmbed(
View* root, ViewManager* view_manager,
ServiceProviderImpl* exported_services, View* root,
scoped_ptr<ServiceProvider> imported_services) { ServiceProviderImpl* embedee_service_provider_impl,
scoped_ptr<ServiceProvider> embedder_service_provider) {
root_ = root; root_ = root;
embedder_service_provider_ = embedder_service_provider.Pass();
navigator_host_.set_service_provider(embedder_service_provider_.get());
root_->SetColor(SK_ColorCYAN); // Dummy background color. root_->SetColor(SK_ColorCYAN); // Dummy background color.
web_view_->resize(root_->bounds().size()); web_view_->resize(root_->bounds().size());
root_->AddObserver(this); root_->AddObserver(this);
...@@ -190,8 +194,7 @@ blink::WebNavigationPolicy HTMLDocumentView::decidePolicyForNavigation( ...@@ -190,8 +194,7 @@ blink::WebNavigationPolicy HTMLDocumentView::decidePolicyForNavigation(
NavigationDetailsPtr nav_details(NavigationDetails::New()); NavigationDetailsPtr nav_details(NavigationDetails::New());
nav_details->request = URLRequest::From(request); nav_details->request = URLRequest::From(request);
GetNavigatorHost()->RequestNavigate( navigator_host_->RequestNavigate(
root_->id(),
WebNavigationPolicyToNavigationTarget(default_policy), WebNavigationPolicyToNavigationTarget(default_policy),
nav_details.Pass()); nav_details.Pass());
...@@ -208,8 +211,7 @@ void HTMLDocumentView::didAddMessageToConsole( ...@@ -208,8 +211,7 @@ void HTMLDocumentView::didAddMessageToConsole(
void HTMLDocumentView::didNavigateWithinPage( void HTMLDocumentView::didNavigateWithinPage(
blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item, blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item,
blink::WebHistoryCommitType commit_type) { blink::WebHistoryCommitType commit_type) {
GetNavigatorHost()->DidNavigateLocally(root_->id(), navigator_host_->DidNavigateLocally(history_item.urlString().utf8());
history_item.urlString().utf8());
} }
void HTMLDocumentView::OnViewBoundsChanged(View* view, void HTMLDocumentView::OnViewBoundsChanged(View* view,
...@@ -252,14 +254,4 @@ void HTMLDocumentView::Repaint() { ...@@ -252,14 +254,4 @@ void HTMLDocumentView::Repaint() {
root_->SetContents(canvas->getDevice()->accessBitmap(false)); root_->SetContents(canvas->getDevice()->accessBitmap(false));
} }
NavigatorHost* HTMLDocumentView::GetNavigatorHost() {
if (!navigator_host_.get()) {
// TODO(aa): This should come via |imported_services| in OnEmbed().
InterfacePtr<ServiceProvider> sp;
shell_->ConnectToApplication("mojo:mojo_window_manager", Get(&sp));
ConnectToService(sp.get(), &navigator_host_);
}
return navigator_host_.get();
}
} // namespace mojo } // namespace mojo
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/application/lazy_interface_ptr.h"
#include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.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/cpp/view_manager/view_observer.h"
...@@ -29,17 +30,14 @@ class HTMLDocumentView : public blink::WebViewClient, ...@@ -29,17 +30,14 @@ class HTMLDocumentView : public blink::WebViewClient,
public: public:
// Load a new HTMLDocument with |response|. // Load a new HTMLDocument with |response|.
// //
// |imported_from_connector| is used to request services of the connecting // |service_provider_request| should be used to implement a
// application (e.g., the application that called // ServiceProvider which exposes services to the connecting application.
// Shell::ConnectToApplication()). // Commonly, the connecting application is the ViewManager and it will
// // request ViewManagerClient.
// |exported_to_connector| is used to export services from this
// HTMLDocumentView to the connecting application.
// //
// |shell| is the Shell connection for this mojo::Application. // |shell| is the Shell connection for this mojo::Application.
HTMLDocumentView(URLResponsePtr response, HTMLDocumentView(URLResponsePtr response,
scoped_ptr<ServiceProvider> imported_from_connector, InterfaceRequest<ServiceProvider> service_provider_request,
ServiceProviderImpl* exported_to_connector,
Shell* shell); Shell* shell);
virtual ~HTMLDocumentView(); virtual ~HTMLDocumentView();
...@@ -74,8 +72,8 @@ class HTMLDocumentView : public blink::WebViewClient, ...@@ -74,8 +72,8 @@ class HTMLDocumentView : public blink::WebViewClient,
virtual void OnEmbed( virtual void OnEmbed(
ViewManager* view_manager, ViewManager* view_manager,
View* root, View* root,
ServiceProviderImpl* exported_to_embedder, ServiceProviderImpl* embedee_service_provider_impl,
scoped_ptr<ServiceProvider> exported_from_embedder) OVERRIDE; scoped_ptr<ServiceProvider> embedder_service_provider) OVERRIDE;
virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE; virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE;
// ViewObserver methods: // ViewObserver methods:
...@@ -87,12 +85,11 @@ class HTMLDocumentView : public blink::WebViewClient, ...@@ -87,12 +85,11 @@ class HTMLDocumentView : public blink::WebViewClient,
void Load(URLResponsePtr response); void Load(URLResponsePtr response);
void Repaint(); void Repaint();
NavigatorHost* GetNavigatorHost();
URLResponsePtr response_; URLResponsePtr response_;
scoped_ptr<ServiceProvider> imported_services_; scoped_ptr<ServiceProvider> embedder_service_provider_;
Shell* shell_; Shell* shell_;
InterfacePtr<NavigatorHost> navigator_host_; LazyInterfacePtr<NavigatorHost> navigator_host_;
blink::WebView* web_view_; blink::WebView* web_view_;
View* root_; View* root_;
ViewManagerClientFactory view_manager_client_factory_; ViewManagerClientFactory view_manager_client_factory_;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/application_runner_chromium.h" #include "mojo/public/cpp/application/application_runner_chromium.h"
#include "mojo/public/cpp/application/interface_factory_impl.h" #include "mojo/public/cpp/application/interface_factory_impl.h"
#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/services/html_viewer/blink_platform_impl.h" #include "mojo/services/html_viewer/blink_platform_impl.h"
#include "mojo/services/html_viewer/html_document_view.h" #include "mojo/services/html_viewer/html_document_view.h"
#include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h" #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
...@@ -29,13 +28,9 @@ class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { ...@@ -29,13 +28,9 @@ class ContentHandlerImpl : public InterfaceImpl<ContentHandler> {
virtual void OnConnect( virtual void OnConnect(
const mojo::String& url, const mojo::String& url,
URLResponsePtr response, URLResponsePtr response,
InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { InterfaceRequest<ServiceProvider> service_provider_request) OVERRIDE {
ServiceProviderImpl* exported_services = new ServiceProviderImpl();
BindToRequest(exported_services, &service_provider);
scoped_ptr<ServiceProvider> remote(
exported_services->CreateRemoteServiceProvider());
new HTMLDocumentView( new HTMLDocumentView(
response.Pass(), remote.Pass(), exported_services, shell_); response.Pass(), service_provider_request.Pass(), shell_);
} }
Shell* shell_; Shell* shell_;
......
...@@ -37,22 +37,11 @@ struct ResponseDetails { ...@@ -37,22 +37,11 @@ struct ResponseDetails {
// Embedders that support navigation of implement this interface. // Embedders that support navigation of implement this interface.
interface NavigatorHost { interface NavigatorHost {
RequestNavigate(uint32 source_node_id, Target target, RequestNavigate(Target target, NavigationDetails? details);
NavigationDetails? details);
// Applications call this to inform hosts of navigations they performed // Applications call this to inform hosts of navigations they performed
// locally. For example, pushState() navigations in an HTML application. // locally. For example, pushState() navigations in an HTML application.
DidNavigateLocally(uint32 source_node_id, string? url); DidNavigateLocally(string? url);
};
// Applications implement this interface to support navigation of their views
// by embedders.
// |response_details| can be NULL when a navigation was not the result of a
// network load.
interface Navigator {
Navigate(uint32 node_id,
NavigationDetails? navigation_details,
ResponseDetails? response_details);
}; };
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment