OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "mojo/examples/window_manager/window_manager.mojom.h" | 9 #include "mojo/examples/window_manager/window_manager.mojom.h" |
10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace mojo { | 24 namespace mojo { |
25 namespace examples { | 25 namespace examples { |
26 | 26 |
27 namespace { | 27 namespace { |
28 const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app"; | 28 const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app"; |
29 } | 29 } |
30 | 30 |
31 class NestingApp; | 31 class NestingApp; |
32 | 32 |
33 class Navigator : public InterfaceImpl<navigation::Navigator> { | 33 class NavigatorImpl : public InterfaceImpl<Navigator> { |
34 public: | 34 public: |
35 explicit Navigator(NestingApp* app) : app_(app) {} | 35 explicit NavigatorImpl(NestingApp* app) : app_(app) {} |
36 | 36 |
37 private: | 37 private: |
38 virtual void Navigate( | 38 virtual void Navigate( |
39 uint32 node_id, | 39 uint32 node_id, |
40 navigation::NavigationDetailsPtr navigation_details, | 40 NavigationDetailsPtr navigation_details, |
41 navigation::ResponseDetailsPtr response_details) OVERRIDE; | 41 ResponseDetailsPtr response_details) OVERRIDE; |
42 | 42 |
43 NestingApp* app_; | 43 NestingApp* app_; |
44 DISALLOW_COPY_AND_ASSIGN(Navigator); | 44 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); |
45 }; | 45 }; |
46 | 46 |
47 // An app that embeds another app. | 47 // An app that embeds another app. |
48 // TODO(davemoore): Is this the right name? | 48 // TODO(davemoore): Is this the right name? |
49 class NestingApp : public ApplicationDelegate, | 49 class NestingApp |
50 public ViewManagerDelegate, | 50 : public ApplicationDelegate, |
51 public ViewObserver, | 51 public ViewManagerDelegate, |
52 public NodeObserver, | 52 public ViewObserver, |
53 public InterfaceFactoryWithContext<Navigator, NestingApp> { | 53 public NodeObserver, |
| 54 public InterfaceFactoryWithContext<NavigatorImpl, NestingApp> { |
54 public: | 55 public: |
55 NestingApp() | 56 NestingApp() |
56 : InterfaceFactoryWithContext(this), | 57 : InterfaceFactoryWithContext(this), |
57 nested_(NULL), | 58 nested_(NULL), |
58 view_manager_client_factory_(this) {} | 59 view_manager_client_factory_(this) {} |
59 virtual ~NestingApp() {} | 60 virtual ~NestingApp() {} |
60 | 61 |
61 void set_color(const std::string& color) { color_ = color; } | 62 void set_color(const std::string& color) { color_ = color; } |
62 | 63 |
63 void NavigateChild() { | 64 void NavigateChild() { |
64 if (!color_.empty() && nested_) { | 65 if (!color_.empty() && nested_) { |
65 navigation::NavigationDetailsPtr details( | 66 NavigationDetailsPtr details(NavigationDetails::New()); |
66 navigation::NavigationDetails::New()); | |
67 details->url = | 67 details->url = |
68 base::StringPrintf("%s/%s", kEmbeddedAppURL, color_.c_str()); | 68 base::StringPrintf("%s/%s", kEmbeddedAppURL, color_.c_str()); |
69 navigation::ResponseDetailsPtr response_details( | 69 ResponseDetailsPtr response_details(ResponseDetails::New()); |
70 navigation::ResponseDetails::New()); | |
71 navigator_->Navigate( | 70 navigator_->Navigate( |
72 nested_->id(), details.Pass(), response_details.Pass()); | 71 nested_->id(), details.Pass(), response_details.Pass()); |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 private: | 75 private: |
77 // Overridden from ApplicationImpl: | 76 // Overridden from ApplicationImpl: |
78 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 77 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
79 MOJO_OVERRIDE { | 78 MOJO_OVERRIDE { |
80 connection->ConnectToService(&window_manager_); | 79 connection->ConnectToService(&window_manager_); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 114 } |
116 | 115 |
117 // Overridden from NodeObserver: | 116 // Overridden from NodeObserver: |
118 virtual void OnNodeDestroyed(Node* node) OVERRIDE { | 117 virtual void OnNodeDestroyed(Node* node) OVERRIDE { |
119 // TODO(beng): reap views & child nodes. | 118 // TODO(beng): reap views & child nodes. |
120 nested_ = NULL; | 119 nested_ = NULL; |
121 } | 120 } |
122 | 121 |
123 std::string color_; | 122 std::string color_; |
124 Node* nested_; | 123 Node* nested_; |
125 navigation::NavigatorPtr navigator_; | 124 NavigatorPtr navigator_; |
126 IWindowManagerPtr window_manager_; | 125 IWindowManagerPtr window_manager_; |
127 ViewManagerClientFactory view_manager_client_factory_; | 126 ViewManagerClientFactory view_manager_client_factory_; |
128 | 127 |
129 DISALLOW_COPY_AND_ASSIGN(NestingApp); | 128 DISALLOW_COPY_AND_ASSIGN(NestingApp); |
130 }; | 129 }; |
131 | 130 |
132 void Navigator::Navigate(uint32 node_id, | 131 void NavigatorImpl::Navigate(uint32 node_id, |
133 navigation::NavigationDetailsPtr navigation_details, | 132 NavigationDetailsPtr navigation_details, |
134 navigation::ResponseDetailsPtr response_details) { | 133 ResponseDetailsPtr response_details) { |
135 GURL url(navigation_details->url.To<std::string>()); | 134 GURL url(navigation_details->url.To<std::string>()); |
136 if (!url.is_valid()) { | 135 if (!url.is_valid()) { |
137 LOG(ERROR) << "URL is invalid."; | 136 LOG(ERROR) << "URL is invalid."; |
138 return; | 137 return; |
139 } | 138 } |
140 app_->set_color(url.path().substr(1)); | 139 app_->set_color(url.path().substr(1)); |
141 app_->NavigateChild(); | 140 app_->NavigateChild(); |
142 } | 141 } |
143 | 142 |
144 } // namespace examples | 143 } // namespace examples |
145 | 144 |
146 // static | 145 // static |
147 ApplicationDelegate* ApplicationDelegate::Create() { | 146 ApplicationDelegate* ApplicationDelegate::Create() { |
148 return new examples::NestingApp; | 147 return new examples::NestingApp; |
149 } | 148 } |
150 | 149 |
151 } // namespace mojo | 150 } // namespace mojo |
OLD | NEW |