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

Side by Side Diff: mojo/examples/embedded_app/embedded_app.cc

Issue 413353002: Remove extraneous namespaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review nits and merge Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/examples/browser/browser.cc ('k') | mojo/examples/media_viewer/media_viewer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_impl.h" 12 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/interface_factory_with_context.h" 13 #include "mojo/public/cpp/application/interface_factory_with_context.h"
14 #include "mojo/services/public/cpp/view_manager/node.h" 14 #include "mojo/services/public/cpp/view_manager/node.h"
15 #include "mojo/services/public/cpp/view_manager/node_observer.h" 15 #include "mojo/services/public/cpp/view_manager/node_observer.h"
16 #include "mojo/services/public/cpp/view_manager/view.h" 16 #include "mojo/services/public/cpp/view_manager/view.h"
17 #include "mojo/services/public/cpp/view_manager/view_manager.h" 17 #include "mojo/services/public/cpp/view_manager/view_manager.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" 18 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
20 #include "mojo/services/public/cpp/view_manager/view_observer.h" 20 #include "mojo/services/public/cpp/view_manager/view_observer.h"
21 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" 21 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
22 #include "ui/events/event_constants.h" 22 #include "ui/events/event_constants.h"
23 #include "url/gurl.h" 23 #include "url/gurl.h"
24 #include "url/url_util.h" 24 #include "url/url_util.h"
25 25
26 namespace mojo { 26 namespace mojo {
27 namespace examples { 27 namespace examples {
28 class EmbeddedApp; 28 class EmbeddedApp;
29 29
30 class Navigator : public InterfaceImpl<navigation::Navigator> { 30 class NavigatorImpl : public InterfaceImpl<Navigator> {
31 public: 31 public:
32 explicit Navigator(EmbeddedApp* app) : app_(app) {} 32 explicit NavigatorImpl(EmbeddedApp* app) : app_(app) {}
33 33
34 private: 34 private:
35 virtual void Navigate( 35 virtual void Navigate(
36 uint32 node_id, 36 uint32 node_id,
37 navigation::NavigationDetailsPtr navigation_details, 37 NavigationDetailsPtr navigation_details,
38 navigation::ResponseDetailsPtr response_details) OVERRIDE; 38 ResponseDetailsPtr response_details) OVERRIDE;
39 39
40 EmbeddedApp* app_; 40 EmbeddedApp* app_;
41 DISALLOW_COPY_AND_ASSIGN(Navigator); 41 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
42 }; 42 };
43 43
44 class EmbeddedApp : public ApplicationDelegate, 44 class EmbeddedApp
45 public ViewManagerDelegate, 45 : public ApplicationDelegate,
46 public ViewObserver, 46 public ViewManagerDelegate,
47 public NodeObserver, 47 public ViewObserver,
48 public InterfaceFactoryWithContext<Navigator, EmbeddedApp> { 48 public NodeObserver,
49 public InterfaceFactoryWithContext<NavigatorImpl, EmbeddedApp> {
49 public: 50 public:
50 EmbeddedApp() 51 EmbeddedApp()
51 : InterfaceFactoryWithContext(this), 52 : InterfaceFactoryWithContext(this),
52 view_manager_(NULL), 53 view_manager_(NULL),
53 view_manager_client_factory_(this) { 54 view_manager_client_factory_(this) {
54 url::AddStandardScheme("mojo"); 55 url::AddStandardScheme("mojo");
55 } 56 }
56 virtual ~EmbeddedApp() {} 57 virtual ~EmbeddedApp() {}
57 58
58 void SetNodeColor(uint32 node_id, SkColor color) { 59 void SetNodeColor(uint32 node_id, SkColor color) {
(...skipping 29 matching lines...) Expand all
88 ProcessPendingNodeColor(root->id()); 89 ProcessPendingNodeColor(root->id());
89 } 90 }
90 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { 91 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {
91 base::MessageLoop::current()->Quit(); 92 base::MessageLoop::current()->Quit();
92 } 93 }
93 94
94 // Overridden from ViewObserver: 95 // Overridden from ViewObserver:
95 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { 96 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE {
96 if (event->action == EVENT_TYPE_MOUSE_RELEASED) { 97 if (event->action == EVENT_TYPE_MOUSE_RELEASED) {
97 if (event->flags & EVENT_FLAGS_LEFT_MOUSE_BUTTON) { 98 if (event->flags & EVENT_FLAGS_LEFT_MOUSE_BUTTON) {
98 navigation::NavigationDetailsPtr nav_details( 99 NavigationDetailsPtr nav_details(NavigationDetails::New());
99 navigation::NavigationDetails::New());
100 nav_details->url = "http://www.aaronboodman.com/z_dropbox/test.html"; 100 nav_details->url = "http://www.aaronboodman.com/z_dropbox/test.html";
101 navigator_host_->RequestNavigate(view->node()->id(), 101 navigator_host_->RequestNavigate(view->node()->id(),
102 navigation::TARGET_SOURCE_NODE, 102 TARGET_SOURCE_NODE,
103 nav_details.Pass()); 103 nav_details.Pass());
104 } 104 }
105 } 105 }
106 } 106 }
107 107
108 // Overridden from NodeObserver: 108 // Overridden from NodeObserver:
109 virtual void OnNodeActiveViewChanged(Node* node, 109 virtual void OnNodeActiveViewChanged(Node* node,
110 View* old_view, 110 View* old_view,
111 View* new_view) OVERRIDE { 111 View* new_view) OVERRIDE {
112 if (new_view == 0) 112 if (new_view == 0)
(...skipping 14 matching lines...) Expand all
127 127
128 PendingNodeColors::iterator color = pending_node_colors_.find(node_id); 128 PendingNodeColors::iterator color = pending_node_colors_.find(node_id);
129 if (color == pending_node_colors_.end()) 129 if (color == pending_node_colors_.end())
130 return; 130 return;
131 131
132 root->second->active_view()->SetColor(color->second); 132 root->second->active_view()->SetColor(color->second);
133 pending_node_colors_.erase(color); 133 pending_node_colors_.erase(color);
134 } 134 }
135 135
136 ViewManager* view_manager_; 136 ViewManager* view_manager_;
137 navigation::NavigatorHostPtr navigator_host_; 137 NavigatorHostPtr navigator_host_;
138 std::map<Node*, View*> views_to_reap_; 138 std::map<Node*, View*> views_to_reap_;
139 ViewManagerClientFactory view_manager_client_factory_; 139 ViewManagerClientFactory view_manager_client_factory_;
140 140
141 typedef std::map<Id, Node*> RootMap; 141 typedef std::map<Id, Node*> RootMap;
142 RootMap roots_; 142 RootMap roots_;
143 143
144 // We can receive navigations for nodes we don't have yet. 144 // We can receive navigations for nodes we don't have yet.
145 typedef std::map<uint32, SkColor> PendingNodeColors; 145 typedef std::map<uint32, SkColor> PendingNodeColors;
146 PendingNodeColors pending_node_colors_; 146 PendingNodeColors pending_node_colors_;
147 147
148 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp); 148 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp);
149 }; 149 };
150 150
151 void Navigator::Navigate(uint32 node_id, 151 void NavigatorImpl::Navigate(uint32 node_id,
152 navigation::NavigationDetailsPtr navigation_details, 152 NavigationDetailsPtr navigation_details,
153 navigation::ResponseDetailsPtr response_details) { 153 ResponseDetailsPtr response_details) {
154 GURL url(navigation_details->url.To<std::string>()); 154 GURL url(navigation_details->url.To<std::string>());
155 if (!url.is_valid()) { 155 if (!url.is_valid()) {
156 LOG(ERROR) << "URL is invalid."; 156 LOG(ERROR) << "URL is invalid.";
157 return; 157 return;
158 } 158 }
159 // TODO(aa): Verify new URL is same origin as current origin. 159 // TODO(aa): Verify new URL is same origin as current origin.
160 SkColor color = 0x00; 160 SkColor color = 0x00;
161 if (!base::HexStringToUInt(url.path().substr(1), &color)) { 161 if (!base::HexStringToUInt(url.path().substr(1), &color)) {
162 LOG(ERROR) << "Invalid URL, path not convertible to integer"; 162 LOG(ERROR) << "Invalid URL, path not convertible to integer";
163 return; 163 return;
164 } 164 }
165 app_->SetNodeColor(node_id, color); 165 app_->SetNodeColor(node_id, color);
166 } 166 }
167 167
168 } // namespace examples 168 } // namespace examples
169 169
170 // static 170 // static
171 ApplicationDelegate* ApplicationDelegate::Create() { 171 ApplicationDelegate* ApplicationDelegate::Create() {
172 return new examples::EmbeddedApp; 172 return new examples::EmbeddedApp;
173 } 173 }
174 174
175 } // namespace mojo 175 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/browser/browser.cc ('k') | mojo/examples/media_viewer/media_viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698