Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Unified Diff: mojo/examples/embedded_app/embedded_app.cc

Issue 327523004: Introduce very beginning of navigation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add url dependency to two smaple apps Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/examples/nesting_app/nesting_app.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/examples/embedded_app/embedded_app.cc
diff --git a/mojo/examples/embedded_app/embedded_app.cc b/mojo/examples/embedded_app/embedded_app.cc
index adcef0264bff9231bc917eb596293548b2638457..003cb82d0f5f192d0ab160cda373895c8188aa16 100644
--- a/mojo/examples/embedded_app/embedded_app.cc
+++ b/mojo/examples/embedded_app/embedded_app.cc
@@ -4,8 +4,11 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.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 +16,8 @@
#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"
+#include "url/url_util.h"
using mojo::view_manager::View;
using mojo::view_manager::ViewManager;
@@ -23,28 +28,54 @@ using mojo::view_manager::ViewTreeNodeObserver;
namespace mojo {
namespace examples {
-namespace {
-
-const SkColor kColors[] = { SK_ColorYELLOW,
- SK_ColorRED,
- SK_ColorGREEN,
- SK_ColorMAGENTA };
-
-} // namespace
class EmbeddedApp : public Application,
public ViewManagerDelegate,
public ViewObserver,
public ViewTreeNodeObserver {
public:
- EmbeddedApp() {}
+ EmbeddedApp() : view_manager_(NULL) {
+ url::AddStandardScheme("mojo");
+ }
virtual ~EmbeddedApp() {}
+ void SetNodeColor(uint32 node_id, SkColor color) {
+ pending_node_colors_[node_id] = color;
+ ProcessPendingNodeColor(node_id);
+ }
+
private:
+ class Navigator : public InterfaceImpl<navigation::Navigator> {
+ public:
+ explicit Navigator(EmbeddedApp* 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;
+ }
+ // TODO(aa): Verify new URL is same origin as current origin.
+ SkColor color = 0x00;
+ if (!base::HexStringToUInt(url.path().substr(1), &color)) {
+ LOG(ERROR) << "Invalid URL, path not convertible to integer";
+ return;
+ }
+ app_->SetNodeColor(node_id, color);
+ }
+ EmbeddedApp* app_;
+ DISALLOW_COPY_AND_ASSIGN(Navigator);
+ };
+
// Overridden from Application:
virtual void Initialize() MOJO_OVERRIDE {
ViewManager::Create(this, 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.
ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_);
+ AddService<Navigator>(this);
}
// Overridden from ViewManagerDelegate:
@@ -54,11 +85,14 @@ class EmbeddedApp : public Application,
view->AddObserver(this);
root->SetActiveView(view);
root->AddObserver(this);
- size_t index = view_manager->GetRoots().size() - 1;
- view->SetColor(kColors[index % arraysize(kColors)]);
+
+ roots_[root->id()] = root;
+ ProcessPendingNodeColor(root->id());
}
virtual void OnRootRemoved(ViewManager* view_manager,
ViewTreeNode* root) OVERRIDE {
+ roots_.erase(root->id());
+
std::map<ViewTreeNode*, View*>::const_iterator it =
views_to_reap_.find(root);
if (it != views_to_reap_.end())
@@ -81,9 +115,31 @@ class EmbeddedApp : public Application,
views_to_reap_[node] = old_view;
}
+ void ProcessPendingNodeColor(uint32 node_id) {
+ RootMap::iterator root = roots_.find(node_id);
+ if (root == roots_.end())
+ return;
+
+ PendingNodeColors::iterator color = pending_node_colors_.find(node_id);
+ if (color == pending_node_colors_.end())
+ return;
+
+ root->second->active_view()->SetColor(color->second);
+ pending_node_colors_.erase(color);
+ }
+
+
+ view_manager::ViewManager* view_manager_;
IWindowManagerPtr window_manager_;
std::map<ViewTreeNode*, View*> views_to_reap_;
+ typedef std::map<uint32, ViewTreeNode*> RootMap;
+ RootMap roots_;
+
+ // We can receive navigations for nodes we don't have yet.
+ typedef std::map<uint32, SkColor> PendingNodeColors;
+ PendingNodeColors pending_node_colors_;
+
DISALLOW_COPY_AND_ASSIGN(EmbeddedApp);
};
« no previous file with comments | « no previous file | mojo/examples/nesting_app/nesting_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698