Index: mojo/examples/window_manager/window_manager.cc |
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc |
index cbdde1abb38e2864020256660b5a57a9009edf20..f949e724501e1b6de066d0271ef2abd5b134cf74 100644 |
--- a/mojo/examples/window_manager/window_manager.cc |
+++ b/mojo/examples/window_manager/window_manager.cc |
@@ -4,8 +4,10 @@ |
#include "base/basictypes.h" |
#include "base/bind.h" |
+#include "base/strings/stringprintf.h" |
#include "mojo/examples/window_manager/window_manager.mojom.h" |
#include "mojo/public/cpp/application/application.h" |
+#include "mojo/services/navigation/navigation.mojom.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_delegate.h" |
@@ -30,6 +32,17 @@ namespace examples { |
class WindowManager; |
+namespace { |
+ |
+const SkColor kColors[] = { SK_ColorYELLOW, |
+ SK_ColorRED, |
+ SK_ColorGREEN, |
+ SK_ColorMAGENTA }; |
+ |
+const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app"; |
+ |
+} // namespace |
+ |
class WindowManagerConnection : public InterfaceImpl<IWindowManager> { |
public: |
explicit WindowManagerConnection(WindowManager* window_manager) |
@@ -69,7 +82,7 @@ class WindowManager : public Application, |
virtual void OnViewInputEvent(View* view, EventPtr event) OVERRIDE { |
if (event->action == ui::ET_MOUSE_RELEASED) { |
if (event->flags & ui::EF_LEFT_MOUSE_BUTTON) |
- CreateWindow("mojo:mojo_embedded_app"); |
+ CreateWindow(kEmbeddedAppURL); |
else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON) |
CreateWindow("mojo:mojo_nesting_app"); |
} |
@@ -92,7 +105,7 @@ class WindowManager : public Application, |
view->AddObserver(this); |
} |
- void CreateWindow(const String& url) { |
+ void CreateWindow(const std::string& url) { |
ViewTreeNode* node = view_manager_->GetNodeById(parent_node_id_); |
gfx::Rect bounds(50, 50, 200, 200); |
@@ -106,6 +119,19 @@ class WindowManager : public Application, |
node->AddChild(embedded); |
embedded->SetBounds(bounds); |
embedded->Embed(url); |
+ |
+ // TODO(aa): This means that there can only ever be one instance of every |
+ // app, which seems wrong. Instead, perhaps embedder should get back a |
+ // service provider that allows it to talk to embeddee. |
+ navigation::ViewNavigatorPtr view_navigator; |
+ ConnectTo(url, &view_navigator); |
+ |
+ navigation::NavigationDetailsPtr details( |
+ navigation::NavigationDetails::New()); |
+ size_t index = node->children().size() - 1; |
+ details->url = base::StringPrintf( |
+ "%s/%x", kEmbeddedAppURL, kColors[index % arraysize(kColors)]); |
+ view_navigator->Navigate(embedded->id(), details.Pass()); |
} |
ViewManager* view_manager_; |
@@ -125,4 +151,4 @@ Application* Application::Create() { |
return new examples::WindowManager; |
} |
-} // namespace mojo |
+} // namespace mojo |