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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 } | 179 } |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 Delegate* delegate_; | 183 Delegate* delegate_; |
184 views::Button* buttons_[CONTROL_COUNT]; | 184 views::Button* buttons_[CONTROL_COUNT]; |
185 | 185 |
186 DISALLOW_COPY_AND_ASSIGN(ControlPanel); | 186 DISALLOW_COPY_AND_ASSIGN(ControlPanel); |
187 }; | 187 }; |
188 | 188 |
189 class NavigatorImpl : public InterfaceImpl<Navigator> { | |
Aaron Boodman
2014/09/04 08:02:59
MediaViewer was already broken from previous chang
| |
190 public: | |
191 explicit NavigatorImpl(MediaViewer* viewer) : viewer_(viewer) {} | |
192 virtual ~NavigatorImpl() {} | |
193 | |
194 private: | |
195 // Overridden from Navigator: | |
196 virtual void Navigate( | |
197 uint32_t view_id, | |
198 NavigationDetailsPtr navigation_details, | |
199 ResponseDetailsPtr response_details) OVERRIDE; | |
200 | |
201 MediaViewer* viewer_; | |
202 | |
203 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); | |
204 }; | |
205 | |
206 class MediaViewer | 189 class MediaViewer |
207 : public ApplicationDelegate, | 190 : public ApplicationDelegate, |
208 public ViewManagerDelegate, | 191 public ViewManagerDelegate, |
209 public ControlPanel::Delegate, | 192 public ControlPanel::Delegate, |
210 public ViewObserver { | 193 public ViewObserver { |
211 public: | 194 public: |
212 MediaViewer() | 195 MediaViewer() |
213 : navigator_factory_(this), | 196 : app_(NULL), |
214 app_(NULL), | |
215 view_manager_(NULL), | 197 view_manager_(NULL), |
216 root_view_(NULL), | 198 root_view_(NULL), |
217 control_view_(NULL), | 199 control_view_(NULL), |
218 content_view_(NULL), | 200 content_view_(NULL), |
219 control_panel_(this) { | 201 control_panel_(this) { |
220 handler_map_["image/png"] = "mojo:mojo_png_viewer"; | 202 handler_map_["image/png"] = "mojo:mojo_png_viewer"; |
221 } | 203 } |
222 | 204 |
223 virtual ~MediaViewer() { | 205 virtual ~MediaViewer() { |
224 if (root_view_) | 206 if (root_view_) |
225 root_view_->RemoveObserver(this); | 207 root_view_->RemoveObserver(this); |
226 } | 208 } |
227 | 209 |
228 void Navigate( | |
229 uint32_t view_id, | |
230 NavigationDetailsPtr navigation_details, | |
231 ResponseDetailsPtr response_details) { | |
232 // TODO(yzshen): This shouldn't be needed once FIFO is ready. | |
233 if (!view_manager_) { | |
234 pending_navigate_request_.reset(new PendingNavigateRequest); | |
235 pending_navigate_request_->view_id = view_id; | |
236 pending_navigate_request_->navigation_details = navigation_details.Pass(); | |
237 pending_navigate_request_->response_details = response_details.Pass(); | |
238 | |
239 return; | |
240 } | |
241 | |
242 std::string handler = GetHandlerForContentType( | |
243 response_details->response->mime_type); | |
244 if (handler.empty()) | |
245 return; | |
246 | |
247 content_view_->Embed(handler); | |
248 | |
249 if (navigation_details) { | |
250 NavigatorPtr navigator; | |
251 app_->ConnectToService(handler, &navigator); | |
252 navigator->Navigate(content_view_->id(), navigation_details.Pass(), | |
253 response_details.Pass()); | |
254 } | |
255 | |
256 // TODO(yzshen): determine the set of controls to show based on what | |
257 // interfaces the embedded app provides. | |
258 app_->ConnectToService(handler, &zoomable_media_); | |
259 } | |
260 | |
261 private: | 210 private: |
262 typedef std::map<std::string, std::string> HandlerMap; | 211 typedef std::map<std::string, std::string> HandlerMap; |
263 | 212 |
264 struct PendingNavigateRequest { | 213 struct PendingNavigateRequest { |
265 uint32_t view_id; | 214 uint32_t view_id; |
266 NavigationDetailsPtr navigation_details; | 215 NavigationDetailsPtr navigation_details; |
267 ResponseDetailsPtr response_details; | 216 ResponseDetailsPtr response_details; |
268 }; | 217 }; |
269 | 218 |
270 | 219 |
271 // Overridden from ApplicationDelegate: | 220 // Overridden from ApplicationDelegate: |
272 virtual void Initialize(ApplicationImpl* app) OVERRIDE { | 221 virtual void Initialize(ApplicationImpl* app) OVERRIDE { |
273 view_manager_client_factory_.reset( | 222 view_manager_client_factory_.reset( |
274 new ViewManagerClientFactory(app->shell(), this)); | 223 new ViewManagerClientFactory(app->shell(), this)); |
275 app_ = app; | 224 app_ = app; |
276 views_init_.reset(new ViewsInit); | 225 views_init_.reset(new ViewsInit); |
277 } | 226 } |
278 | 227 |
279 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 228 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
280 OVERRIDE { | 229 OVERRIDE { |
281 connection->AddService(&navigator_factory_); | |
282 connection->AddService(view_manager_client_factory_.get()); | 230 connection->AddService(view_manager_client_factory_.get()); |
283 return true; | 231 return true; |
284 } | 232 } |
285 | 233 |
286 void LayoutViews() { | 234 void LayoutViews() { |
287 View* root = content_view_->parent(); | 235 View* root = content_view_->parent(); |
288 gfx::Rect control_bounds(root->bounds().width(), 28); | 236 gfx::Rect control_bounds(root->bounds().width(), 28); |
289 control_view_->SetBounds(control_bounds); | 237 control_view_->SetBounds(control_bounds); |
290 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), | 238 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), |
291 root->bounds().height() - control_bounds.height()); | 239 root->bounds().height() - control_bounds.height()); |
(...skipping 12 matching lines...) Expand all Loading... | |
304 root_view_->AddChild(control_view_); | 252 root_view_->AddChild(control_view_); |
305 | 253 |
306 content_view_ = View::Create(view_manager_); | 254 content_view_ = View::Create(view_manager_); |
307 root_view_->AddChild(content_view_); | 255 root_view_->AddChild(content_view_); |
308 | 256 |
309 control_panel_.Initialize(control_view_); | 257 control_panel_.Initialize(control_view_); |
310 | 258 |
311 LayoutViews(); | 259 LayoutViews(); |
312 root_view_->AddObserver(this); | 260 root_view_->AddObserver(this); |
313 | 261 |
314 if (pending_navigate_request_) { | 262 content_view_->Embed("TODO"); |
315 scoped_ptr<PendingNavigateRequest> request( | 263 } |
316 pending_navigate_request_.release()); | |
317 | 264 |
318 Navigate(request->view_id, request->navigation_details.Pass(), | |
319 request->response_details.Pass()); | |
320 } | |
321 } | |
322 virtual void OnViewManagerDisconnected( | 265 virtual void OnViewManagerDisconnected( |
323 ViewManager* view_manager) OVERRIDE { | 266 ViewManager* view_manager) OVERRIDE { |
324 DCHECK_EQ(view_manager_, view_manager); | 267 DCHECK_EQ(view_manager_, view_manager); |
325 view_manager_ = NULL; | 268 view_manager_ = NULL; |
326 base::MessageLoop::current()->Quit(); | 269 base::MessageLoop::current()->Quit(); |
327 } | 270 } |
328 | 271 |
329 // Overridden from ControlPanel::Delegate: | 272 // Overridden from ControlPanel::Delegate: |
330 virtual void ButtonPressed(ControlPanel::ControlType type) OVERRIDE { | 273 virtual void ButtonPressed(ControlPanel::ControlType type) OVERRIDE { |
331 switch (type) { | 274 switch (type) { |
(...skipping 21 matching lines...) Expand all Loading... | |
353 DCHECK_EQ(view, root_view_); | 296 DCHECK_EQ(view, root_view_); |
354 view->RemoveObserver(this); | 297 view->RemoveObserver(this); |
355 root_view_ = NULL; | 298 root_view_ = NULL; |
356 } | 299 } |
357 | 300 |
358 std::string GetHandlerForContentType(const std::string& content_type) { | 301 std::string GetHandlerForContentType(const std::string& content_type) { |
359 HandlerMap::const_iterator it = handler_map_.find(content_type); | 302 HandlerMap::const_iterator it = handler_map_.find(content_type); |
360 return it != handler_map_.end() ? it->second : std::string(); | 303 return it != handler_map_.end() ? it->second : std::string(); |
361 } | 304 } |
362 | 305 |
363 InterfaceFactoryImplWithContext<NavigatorImpl, MediaViewer> | |
364 navigator_factory_; | |
365 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 306 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
366 | 307 |
367 ApplicationImpl* app_; | 308 ApplicationImpl* app_; |
368 scoped_ptr<ViewsInit> views_init_; | 309 scoped_ptr<ViewsInit> views_init_; |
369 ViewManager* view_manager_; | 310 ViewManager* view_manager_; |
370 View* root_view_; | 311 View* root_view_; |
371 View* control_view_; | 312 View* control_view_; |
372 View* content_view_; | 313 View* content_view_; |
373 ControlPanel control_panel_; | 314 ControlPanel control_panel_; |
374 ZoomableMediaPtr zoomable_media_; | 315 ZoomableMediaPtr zoomable_media_; |
375 HandlerMap handler_map_; | 316 HandlerMap handler_map_; |
376 scoped_ptr<PendingNavigateRequest> pending_navigate_request_; | |
377 | 317 |
378 DISALLOW_COPY_AND_ASSIGN(MediaViewer); | 318 DISALLOW_COPY_AND_ASSIGN(MediaViewer); |
379 }; | 319 }; |
380 | 320 |
381 void NavigatorImpl::Navigate( | |
382 uint32_t view_id, | |
383 NavigationDetailsPtr navigation_details, | |
384 ResponseDetailsPtr response_details) { | |
385 viewer_->Navigate(view_id, navigation_details.Pass(), | |
386 response_details.Pass()); | |
387 } | |
388 | |
389 } // namespace examples | 321 } // namespace examples |
390 } // namespace mojo | 322 } // namespace mojo |
391 | 323 |
392 MojoResult MojoMain(MojoHandle shell_handle) { | 324 MojoResult MojoMain(MojoHandle shell_handle) { |
393 mojo::ApplicationRunnerChromium runner(new mojo::examples::MediaViewer); | 325 mojo::ApplicationRunnerChromium runner(new mojo::examples::MediaViewer); |
394 return runner.Run(shell_handle); | 326 return runner.Run(shell_handle); |
395 } | 327 } |
OLD | NEW |