| 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 Delegate* delegate_; | 182 Delegate* delegate_; |
| 183 views::Button* buttons_[CONTROL_COUNT]; | 183 views::Button* buttons_[CONTROL_COUNT]; |
| 184 | 184 |
| 185 DISALLOW_COPY_AND_ASSIGN(ControlPanel); | 185 DISALLOW_COPY_AND_ASSIGN(ControlPanel); |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { | 188 class NavigatorImpl : public InterfaceImpl<Navigator> { |
| 189 public: | 189 public: |
| 190 explicit NavigatorImpl(MediaViewer* viewer) : viewer_(viewer) {} | 190 explicit NavigatorImpl(MediaViewer* viewer) : viewer_(viewer) {} |
| 191 virtual ~NavigatorImpl() {} | 191 virtual ~NavigatorImpl() {} |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 // Overridden from navigation::Navigate: | 194 // Overridden from Navigator: |
| 195 virtual void Navigate( | 195 virtual void Navigate( |
| 196 uint32_t node_id, | 196 uint32_t node_id, |
| 197 navigation::NavigationDetailsPtr navigation_details, | 197 NavigationDetailsPtr navigation_details, |
| 198 navigation::ResponseDetailsPtr response_details) OVERRIDE; | 198 ResponseDetailsPtr response_details) OVERRIDE; |
| 199 | 199 |
| 200 MediaViewer* viewer_; | 200 MediaViewer* viewer_; |
| 201 | 201 |
| 202 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); | 202 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 class MediaViewer | 205 class MediaViewer |
| 206 : public ApplicationDelegate, | 206 : public ApplicationDelegate, |
| 207 public view_manager::ViewManagerDelegate, | 207 public view_manager::ViewManagerDelegate, |
| 208 public ControlPanel::Delegate, | 208 public ControlPanel::Delegate, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 221 handler_map_["image/png"] = "mojo:mojo_png_viewer"; | 221 handler_map_["image/png"] = "mojo:mojo_png_viewer"; |
| 222 } | 222 } |
| 223 | 223 |
| 224 virtual ~MediaViewer() { | 224 virtual ~MediaViewer() { |
| 225 if (root_node_) | 225 if (root_node_) |
| 226 root_node_->RemoveObserver(this); | 226 root_node_->RemoveObserver(this); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void Navigate( | 229 void Navigate( |
| 230 uint32_t node_id, | 230 uint32_t node_id, |
| 231 navigation::NavigationDetailsPtr navigation_details, | 231 NavigationDetailsPtr navigation_details, |
| 232 navigation::ResponseDetailsPtr response_details) { | 232 ResponseDetailsPtr response_details) { |
| 233 // TODO(yzshen): This shouldn't be needed once FIFO is ready. | 233 // TODO(yzshen): This shouldn't be needed once FIFO is ready. |
| 234 if (!view_manager_) { | 234 if (!view_manager_) { |
| 235 pending_navigate_request_.reset(new PendingNavigateRequest); | 235 pending_navigate_request_.reset(new PendingNavigateRequest); |
| 236 pending_navigate_request_->node_id = node_id; | 236 pending_navigate_request_->node_id = node_id; |
| 237 pending_navigate_request_->navigation_details = navigation_details.Pass(); | 237 pending_navigate_request_->navigation_details = navigation_details.Pass(); |
| 238 pending_navigate_request_->response_details = response_details.Pass(); | 238 pending_navigate_request_->response_details = response_details.Pass(); |
| 239 | 239 |
| 240 return; | 240 return; |
| 241 } | 241 } |
| 242 | 242 |
| 243 std::string handler = GetHandlerForContentType( | 243 std::string handler = GetHandlerForContentType( |
| 244 response_details->response->mime_type); | 244 response_details->response->mime_type); |
| 245 if (handler.empty()) | 245 if (handler.empty()) |
| 246 return; | 246 return; |
| 247 | 247 |
| 248 content_node_->Embed(handler); | 248 content_node_->Embed(handler); |
| 249 | 249 |
| 250 if (navigation_details) { | 250 if (navigation_details) { |
| 251 navigation::NavigatorPtr navigator; | 251 NavigatorPtr navigator; |
| 252 app_->ConnectToService(handler, &navigator); | 252 app_->ConnectToService(handler, &navigator); |
| 253 navigator->Navigate(content_node_->id(), navigation_details.Pass(), | 253 navigator->Navigate(content_node_->id(), navigation_details.Pass(), |
| 254 response_details.Pass()); | 254 response_details.Pass()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 // TODO(yzshen): determine the set of controls to show based on what | 257 // TODO(yzshen): determine the set of controls to show based on what |
| 258 // interfaces the embedded app provides. | 258 // interfaces the embedded app provides. |
| 259 app_->ConnectToService(handler, &zoomable_media_); | 259 app_->ConnectToService(handler, &zoomable_media_); |
| 260 } | 260 } |
| 261 | 261 |
| 262 private: | 262 private: |
| 263 typedef std::map<std::string, std::string> HandlerMap; | 263 typedef std::map<std::string, std::string> HandlerMap; |
| 264 | 264 |
| 265 struct PendingNavigateRequest { | 265 struct PendingNavigateRequest { |
| 266 uint32_t node_id; | 266 uint32_t node_id; |
| 267 navigation::NavigationDetailsPtr navigation_details; | 267 NavigationDetailsPtr navigation_details; |
| 268 navigation::ResponseDetailsPtr response_details; | 268 ResponseDetailsPtr response_details; |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 | 271 |
| 272 // Overridden from ApplicationDelegate: | 272 // Overridden from ApplicationDelegate: |
| 273 virtual void Initialize(ApplicationImpl* app) OVERRIDE { | 273 virtual void Initialize(ApplicationImpl* app) OVERRIDE { |
| 274 app_ = app; | 274 app_ = app; |
| 275 views_init_.reset(new ViewsInit); | 275 views_init_.reset(new ViewsInit); |
| 276 } | 276 } |
| 277 | 277 |
| 278 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 278 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 ControlPanel control_panel_; | 368 ControlPanel control_panel_; |
| 369 ZoomableMediaPtr zoomable_media_; | 369 ZoomableMediaPtr zoomable_media_; |
| 370 HandlerMap handler_map_; | 370 HandlerMap handler_map_; |
| 371 scoped_ptr<PendingNavigateRequest> pending_navigate_request_; | 371 scoped_ptr<PendingNavigateRequest> pending_navigate_request_; |
| 372 | 372 |
| 373 DISALLOW_COPY_AND_ASSIGN(MediaViewer); | 373 DISALLOW_COPY_AND_ASSIGN(MediaViewer); |
| 374 }; | 374 }; |
| 375 | 375 |
| 376 void NavigatorImpl::Navigate( | 376 void NavigatorImpl::Navigate( |
| 377 uint32_t node_id, | 377 uint32_t node_id, |
| 378 navigation::NavigationDetailsPtr navigation_details, | 378 NavigationDetailsPtr navigation_details, |
| 379 navigation::ResponseDetailsPtr response_details) { | 379 ResponseDetailsPtr response_details) { |
| 380 viewer_->Navigate(node_id, navigation_details.Pass(), | 380 viewer_->Navigate(node_id, navigation_details.Pass(), |
| 381 response_details.Pass()); | 381 response_details.Pass()); |
| 382 } | 382 } |
| 383 | 383 |
| 384 } // namespace examples | 384 } // namespace examples |
| 385 | 385 |
| 386 // static | 386 // static |
| 387 ApplicationDelegate* ApplicationDelegate::Create() { | 387 ApplicationDelegate* ApplicationDelegate::Create() { |
| 388 return new examples::MediaViewer; | 388 return new examples::MediaViewer; |
| 389 } | 389 } |
| 390 | 390 |
| 391 } // namespace mojo | 391 } // namespace mojo |
| OLD | NEW |