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

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: goto fail 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
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 3f463072b62e098f08e683d8316bb56e46657066..b411ba56e96ba69adb95e0d027cbc00f97a0115d 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,39 +28,74 @@ 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 ViewNavigator : public InterfaceImpl<navigation::ViewNavigator> {
+ public:
+ explicit ViewNavigator(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_;
+ };
+
// 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<ViewNavigator>(this);
}
// Overridden from ViewManagerDelegate:
virtual void OnRootAdded(ViewManager* view_manager,
ViewTreeNode* root) OVERRIDE {
+ if (!view_manager_)
+ view_manager_ = view_manager;
+ DCHECK_EQ(view_manager_, view_manager);
+
View* view = View::Create(view_manager);
view->AddObserver(this);
root->SetActiveView(view);
root->AddObserver(this);
- size_t index = view_manager->roots().size() - 1;
- view->SetColor(kColors[index % arraysize(kColors)]);
+ ProcessPendingNodeColor(root->id());
}
virtual void OnRootRemoved(ViewManager* view_manager,
ViewTreeNode* root) OVERRIDE {
@@ -81,9 +121,31 @@ class EmbeddedApp : public Application,
views_to_reap_[node] = old_view;
}
+ void ProcessPendingNodeColor(uint32 node_id) {
+ if (!view_manager_)
+ return;
+
+ ViewTreeNode* node = view_manager_->GetNodeById(node_id);
+ if (!node)
+ return;
+
+ PendingNodeColors::iterator iter = pending_node_colors_.find(node_id);
+ if (iter == pending_node_colors_.end())
+ return;
+
+ node->active_view()->SetColor(iter->second);
+ pending_node_colors_.erase(iter);
+ }
+
+
+ view_manager::ViewManager* view_manager_;
IWindowManagerPtr window_manager_;
std::map<ViewTreeNode*, View*> views_to_reap_;
+ // 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);
};
@@ -94,4 +156,4 @@ Application* Application::Create() {
return new examples::EmbeddedApp;
}
-} // namespace mojo
+} // namespace mojo
« no previous file with comments | « no previous file | mojo/examples/window_manager/window_manager.cc » ('j') | mojo/examples/window_manager/window_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698