| 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_impl.h" | 9 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 10 #include "mojo/services/html_viewer/blink_platform_impl.h" | 10 #include "mojo/services/html_viewer/blink_platform_impl.h" |
| 11 #include "mojo/services/html_viewer/html_document_view.h" | 11 #include "mojo/services/html_viewer/html_document_view.h" |
| 12 #include "mojo/services/public/cpp/view_manager/types.h" | 12 #include "mojo/services/public/cpp/view_manager/types.h" |
| 13 #include "mojo/services/public/cpp/view_manager/view.h" | 13 #include "mojo/services/public/cpp/view_manager/view.h" |
| 14 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 14 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 15 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 15 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
| 16 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 17 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 17 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.
h" |
| 18 #include "third_party/WebKit/public/web/WebKit.h" | 18 #include "third_party/WebKit/public/web/WebKit.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 | 21 |
| 22 class HTMLViewer; | 22 class HTMLViewer; |
| 23 | 23 |
| 24 class NavigatorImpl : public InterfaceImpl<Navigator> { | 24 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { |
| 25 public: | 25 public: |
| 26 explicit NavigatorImpl(HTMLViewer* viewer) : viewer_(viewer) {} | 26 explicit ContentHandlerImpl(HTMLViewer* viewer) : viewer_(viewer) {} |
| 27 virtual ~NavigatorImpl() {} | 27 virtual ~ContentHandlerImpl() {} |
| 28 | 28 |
| 29 private: | 29 private: |
| 30 // Overridden from Navigator: | 30 // Overridden from ContentHandler: |
| 31 virtual void Navigate( | 31 virtual void OnConnect(mojo::String url, |
| 32 uint32_t view_id, | 32 ResponseDetailsPtr response_details, |
| 33 NavigationDetailsPtr navigation_details, | 33 ServiceProviderPtr service_provider) OVERRIDE; |
| 34 ResponseDetailsPtr response_details) OVERRIDE; | |
| 35 | 34 |
| 36 HTMLViewer* viewer_; | 35 HTMLViewer* viewer_; |
| 37 | 36 |
| 38 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); | 37 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 class HTMLViewer : public ApplicationDelegate, public ViewManagerDelegate { | 40 class HTMLViewer : public ApplicationDelegate, public ViewManagerDelegate { |
| 42 public: | 41 public: |
| 43 HTMLViewer() | 42 HTMLViewer() |
| 44 : application_impl_(NULL), | 43 : application_impl_(NULL), |
| 45 document_view_(NULL), | 44 document_view_(NULL), |
| 46 navigator_factory_(this), | 45 content_handler_factory_(this), |
| 47 view_manager_client_factory_(this) {} | 46 view_manager_client_factory_(this) {} |
| 48 virtual ~HTMLViewer() { | 47 virtual ~HTMLViewer() { |
| 49 blink::shutdown(); | 48 blink::shutdown(); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void Load(ResponseDetailsPtr response_details) { | 51 void Load(ResponseDetailsPtr response_details) { |
| 53 // Need to wait for OnEmbed. | 52 // Need to wait for OnEmbed. |
| 54 response_details_ = response_details.Pass(); | 53 response_details_ = response_details.Pass(); |
| 55 MaybeLoad(); | 54 MaybeLoad(); |
| 56 } | 55 } |
| 57 | 56 |
| 58 private: | 57 private: |
| 59 // Overridden from ApplicationDelegate: | 58 // Overridden from ApplicationDelegate: |
| 60 virtual void Initialize(ApplicationImpl* app) OVERRIDE { | 59 virtual void Initialize(ApplicationImpl* app) OVERRIDE { |
| 61 application_impl_ = app; | 60 application_impl_ = app; |
| 62 blink_platform_impl_.reset(new BlinkPlatformImpl(app)); | 61 blink_platform_impl_.reset(new BlinkPlatformImpl(app)); |
| 63 blink::initialize(blink_platform_impl_.get()); | 62 blink::initialize(blink_platform_impl_.get()); |
| 64 } | 63 } |
| 65 | 64 |
| 66 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 65 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 67 OVERRIDE { | 66 OVERRIDE { |
| 68 connection->AddService(&navigator_factory_); | 67 connection->AddService(&content_handler_factory_); |
| 69 connection->AddService(&view_manager_client_factory_); | 68 connection->AddService(&view_manager_client_factory_); |
| 70 return true; | 69 return true; |
| 71 } | 70 } |
| 72 | 71 |
| 73 // Overridden from ViewManagerDelegate: | 72 // Overridden from ViewManagerDelegate: |
| 74 virtual void OnEmbed(ViewManager* view_manager, | 73 virtual void OnEmbed(ViewManager* view_manager, |
| 75 View* root, | 74 View* root, |
| 76 ServiceProviderImpl* exported_services, | 75 ServiceProviderImpl* exported_services, |
| 77 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 76 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
| 78 document_view_ = new HTMLDocumentView( | 77 document_view_ = new HTMLDocumentView( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 if (document_view_ && response_details_) | 89 if (document_view_ && response_details_) |
| 91 document_view_->Load(response_details_->response.Pass()); | 90 document_view_->Load(response_details_->response.Pass()); |
| 92 } | 91 } |
| 93 | 92 |
| 94 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; | 93 scoped_ptr<BlinkPlatformImpl> blink_platform_impl_; |
| 95 ApplicationImpl* application_impl_; | 94 ApplicationImpl* application_impl_; |
| 96 | 95 |
| 97 // TODO(darin): Figure out proper ownership of this instance. | 96 // TODO(darin): Figure out proper ownership of this instance. |
| 98 HTMLDocumentView* document_view_; | 97 HTMLDocumentView* document_view_; |
| 99 ResponseDetailsPtr response_details_; | 98 ResponseDetailsPtr response_details_; |
| 100 InterfaceFactoryImplWithContext<NavigatorImpl, HTMLViewer> navigator_factory_; | 99 InterfaceFactoryImplWithContext<ContentHandlerImpl, HTMLViewer> |
| 100 content_handler_factory_; |
| 101 ViewManagerClientFactory view_manager_client_factory_; | 101 ViewManagerClientFactory view_manager_client_factory_; |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | 103 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 void NavigatorImpl::Navigate( | 106 void ContentHandlerImpl::OnConnect(const mojo::String& url, |
| 107 uint32_t view_id, | 107 URLResponsePtr url_response, |
| 108 NavigationDetailsPtr navigation_details, | 108 ServiceProviderPtr service_provider) { |
| 109 ResponseDetailsPtr response_details) { | 109 viewer_->Load(url_response.Pass()); |
| 110 viewer_->Load(response_details.Pass()); | |
| 111 } | 110 } |
| 112 | 111 |
| 113 // static | 112 // static |
| 114 ApplicationDelegate* ApplicationDelegate::Create() { | 113 ApplicationDelegate* ApplicationDelegate::Create() { |
| 115 return new HTMLViewer; | 114 return new HTMLViewer; |
| 116 } | 115 } |
| 117 | 116 |
| 118 } | 117 } |
| OLD | NEW |