| 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "mojo/public/cpp/application/application_connection.h" | 6 #include "mojo/public/cpp/application/application_connection.h" |
| 7 #include "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_delegate.h" |
| 8 #include "mojo/public/cpp/application/application_impl.h" | 8 #include "mojo/public/cpp/application/application_impl.h" |
| 9 #include "mojo/public/cpp/application/interface_factory_with_context.h" | 9 #include "mojo/public/cpp/application/interface_factory_with_context.h" |
| 10 #include "mojo/services/html_viewer/blink_platform_impl.h" | 10 #include "mojo/services/html_viewer/blink_platform_impl.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 navigation::NavigationDetailsPtr navigation_details, | 34 navigation::NavigationDetailsPtr navigation_details, |
| 35 navigation::ResponseDetailsPtr response_details) OVERRIDE; | 35 navigation::ResponseDetailsPtr response_details) OVERRIDE; |
| 36 | 36 |
| 37 HTMLViewer* viewer_; | 37 HTMLViewer* viewer_; |
| 38 | 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); | 39 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class HTMLViewer | 42 class HTMLViewer |
| 43 : public ApplicationDelegate, | 43 : public ApplicationDelegate, |
| 44 public view_manager::ViewManagerDelegate, | 44 public ViewManagerDelegate, |
| 45 public InterfaceFactoryWithContext<NavigatorImpl, HTMLViewer> { | 45 public InterfaceFactoryWithContext<NavigatorImpl, HTMLViewer> { |
| 46 public: | 46 public: |
| 47 HTMLViewer() | 47 HTMLViewer() |
| 48 : InterfaceFactoryWithContext(this), | 48 : InterfaceFactoryWithContext(this), |
| 49 application_impl_(NULL), | 49 application_impl_(NULL), |
| 50 document_view_(NULL), | 50 document_view_(NULL), |
| 51 view_manager_client_factory_(this) {} | 51 view_manager_client_factory_(this) {} |
| 52 virtual ~HTMLViewer() { | 52 virtual ~HTMLViewer() { |
| 53 blink::shutdown(); | 53 blink::shutdown(); |
| 54 } | 54 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 67 blink::initialize(blink_platform_impl_.get()); | 67 blink::initialize(blink_platform_impl_.get()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 70 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 71 OVERRIDE { | 71 OVERRIDE { |
| 72 connection->AddService(this); | 72 connection->AddService(this); |
| 73 connection->AddService(&view_manager_client_factory_); | 73 connection->AddService(&view_manager_client_factory_); |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Overridden from view_manager::ViewManagerDelegate: | 77 // Overridden from ViewManagerDelegate: |
| 78 virtual void OnRootAdded(view_manager::ViewManager* view_manager, | 78 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
| 79 view_manager::Node* root) OVERRIDE { | |
| 80 document_view_ = new HTMLDocumentView( | 79 document_view_ = new HTMLDocumentView( |
| 81 application_impl_->ConnectToApplication("mojo://mojo_window_manager/")-> | 80 application_impl_->ConnectToApplication("mojo://mojo_window_manager/")-> |
| 82 GetServiceProvider(), | 81 GetServiceProvider(), |
| 83 view_manager); | 82 view_manager); |
| 84 document_view_->AttachToNode(root); | 83 document_view_->AttachToNode(root); |
| 85 MaybeLoad(); | 84 MaybeLoad(); |
| 86 } | 85 } |
| 87 virtual void OnViewManagerDisconnected( | 86 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { |
| 88 view_manager::ViewManager* view_manager) OVERRIDE { | |
| 89 base::MessageLoop::current()->Quit(); | 87 base::MessageLoop::current()->Quit(); |
| 90 } | 88 } |
| 91 | 89 |
| 92 void MaybeLoad() { | 90 void MaybeLoad() { |
| 93 if (document_view_ && response_) | 91 if (document_view_ && response_) |
| 94 document_view_->Load(response_.Pass()); | 92 document_view_->Load(response_.Pass()); |
| 95 } | 93 } |
| 96 | 94 |
| 97 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; | 95 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; |
| 98 ApplicationImpl* application_impl_; | 96 ApplicationImpl* application_impl_; |
| 99 | 97 |
| 100 // TODO(darin): Figure out proper ownership of this instance. | 98 // TODO(darin): Figure out proper ownership of this instance. |
| 101 HTMLDocumentView* document_view_; | 99 HTMLDocumentView* document_view_; |
| 102 URLResponsePtr response_; | 100 URLResponsePtr response_; |
| 103 view_manager::ViewManagerClientFactory view_manager_client_factory_; | 101 ViewManagerClientFactory view_manager_client_factory_; |
| 104 | 102 |
| 105 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | 103 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); |
| 106 }; | 104 }; |
| 107 | 105 |
| 108 void NavigatorImpl::Navigate( | 106 void NavigatorImpl::Navigate( |
| 109 uint32_t node_id, | 107 uint32_t node_id, |
| 110 navigation::NavigationDetailsPtr navigation_details, | 108 navigation::NavigationDetailsPtr navigation_details, |
| 111 navigation::ResponseDetailsPtr response_details) { | 109 navigation::ResponseDetailsPtr response_details) { |
| 112 viewer_->Load(response_details->response.Pass()); | 110 viewer_->Load(response_details->response.Pass()); |
| 113 } | 111 } |
| 114 | 112 |
| 115 // static | 113 // static |
| 116 ApplicationDelegate* ApplicationDelegate::Create() { | 114 ApplicationDelegate* ApplicationDelegate::Create() { |
| 117 return new HTMLViewer; | 115 return new HTMLViewer; |
| 118 } | 116 } |
| 119 | 117 |
| 120 } | 118 } |
| OLD | NEW |