| Index: mojo/examples/nesting_app/nesting_app.cc
|
| diff --git a/mojo/examples/nesting_app/nesting_app.cc b/mojo/examples/nesting_app/nesting_app.cc
|
| index 249cc374873b8d9186126eff129ec7c6338e5f51..b882f4a7d2cab4b1649e3d8fbf3814fa86b16abc 100644
|
| --- a/mojo/examples/nesting_app/nesting_app.cc
|
| +++ b/mojo/examples/nesting_app/nesting_app.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"
|
| @@ -13,6 +15,7 @@
|
| #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
|
| #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h"
|
| #include "ui/events/event_constants.h"
|
| +#include "url/gurl.h"
|
|
|
| using mojo::view_manager::View;
|
| using mojo::view_manager::ViewManager;
|
| @@ -24,19 +27,42 @@ using mojo::view_manager::ViewTreeNodeObserver;
|
| namespace mojo {
|
| namespace examples {
|
|
|
| +namespace {
|
| +const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app";
|
| +}
|
| +
|
| // An app that embeds another app.
|
| class NestingApp : public Application,
|
| public ViewManagerDelegate,
|
| public ViewObserver {
|
| public:
|
| - NestingApp() {}
|
| + NestingApp() : nested_(NULL) {}
|
| virtual ~NestingApp() {}
|
|
|
| private:
|
| + class Navigator : public InterfaceImpl<navigation::Navigator> {
|
| + public:
|
| + explicit Navigator(NestingApp* app) : app_(app) {}
|
| + private:
|
| + virtual void Navigate(uint32 node_id,
|
| + navigation::NavigationDetailsPtr details) OVERRIDE {
|
| + GURL url(details->url.To<std::string>());
|
| + if (!url.is_valid()) {
|
| + LOG(ERROR) << "URL is invalid.";
|
| + return;
|
| + }
|
| + app_->color_ = url.path().substr(1);
|
| + app_->NavigateChild();
|
| + }
|
| + NestingApp* app_;
|
| + DISALLOW_COPY_AND_ASSIGN(Navigator);
|
| + };
|
| +
|
| // Overridden from Application:
|
| virtual void Initialize() MOJO_OVERRIDE {
|
| ViewManager::Create(this, this);
|
| ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_);
|
| + AddService<Navigator>(this);
|
| }
|
|
|
| // Overridden from ViewManagerDelegate:
|
| @@ -47,14 +73,21 @@ class NestingApp : public Application,
|
| view->SetColor(SK_ColorCYAN);
|
| view->AddObserver(this);
|
|
|
| - ViewTreeNode* nested = ViewTreeNode::Create(view_manager);
|
| - root->AddChild(nested);
|
| - nested->SetBounds(gfx::Rect(20, 20, 50, 50));
|
| - nested->Embed("mojo:mojo_embedded_app");
|
| + nested_ = ViewTreeNode::Create(view_manager);
|
| + root->AddChild(nested_);
|
| + nested_->SetBounds(gfx::Rect(20, 20, 50, 50));
|
| + nested_->Embed(kEmbeddedAppURL);
|
| +
|
| + if (!navigator_.get())
|
| + ConnectTo(kEmbeddedAppURL, &navigator_);
|
| +
|
| + NavigateChild();
|
| }
|
| +
|
| virtual void OnRootRemoved(ViewManager* view_manager,
|
| ViewTreeNode* root) OVERRIDE {
|
| // TODO(beng): reap views & child nodes.
|
| + nested_ = NULL;
|
| }
|
|
|
| // Overridden from ViewObserver:
|
| @@ -63,6 +96,19 @@ class NestingApp : public Application,
|
| window_manager_->CloseWindow(view->node()->id());
|
| }
|
|
|
| + void NavigateChild() {
|
| + if (!color_.empty() && nested_) {
|
| + navigation::NavigationDetailsPtr details(
|
| + navigation::NavigationDetails::New());
|
| + details->url =
|
| + base::StringPrintf("%s/%s", kEmbeddedAppURL, color_.c_str());
|
| + navigator_->Navigate(nested_->id(), details.Pass());
|
| + }
|
| + }
|
| +
|
| + std::string color_;
|
| + ViewTreeNode* nested_;
|
| + navigation::NavigatorPtr navigator_;
|
| IWindowManagerPtr window_manager_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(NestingApp);
|
|
|