| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "components/html_viewer/html_document.h" | 12 #include "components/html_viewer/html_document.h" |
| 13 #include "components/html_viewer/setup.h" | 13 #include "components/html_viewer/setup.h" |
| 14 #include "mojo/application/public/cpp/application_connection.h" | 14 #include "mojo/application/public/cpp/application_connection.h" |
| 15 #include "mojo/application/public/cpp/application_delegate.h" | 15 #include "mojo/application/public/cpp/application_delegate.h" |
| 16 #include "mojo/application/public/cpp/application_impl.h" | 16 #include "mojo/application/public/cpp/application_impl.h" |
| 17 #include "mojo/application/public/cpp/application_runner.h" | 17 #include "mojo/application/public/cpp/application_runner.h" |
| 18 #include "mojo/application/public/cpp/connect.h" | 18 #include "mojo/application/public/cpp/connect.h" |
| 19 #include "mojo/application/public/cpp/interface_factory_impl.h" | 19 #include "mojo/application/public/cpp/interface_factory_impl.h" |
| 20 #include "mojo/application/public/interfaces/content_handler.mojom.h" | 20 #include "mojo/application/public/interfaces/content_handler.mojom.h" |
| 21 #include "mojo/common/common_type_converters.h" | 21 #include "mojo/common/common_type_converters.h" |
| 22 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 22 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 23 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h" |
| 23 #include "third_party/WebKit/public/web/WebKit.h" | 24 #include "third_party/WebKit/public/web/WebKit.h" |
| 24 #include "third_party/mojo/src/mojo/public/c/system/main.h" | 25 #include "third_party/mojo/src/mojo/public/c/system/main.h" |
| 25 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | 26 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" |
| 26 | 27 |
| 27 using mojo::ApplicationConnection; | 28 using mojo::ApplicationConnection; |
| 28 using mojo::Array; | 29 using mojo::Array; |
| 29 using mojo::BindToRequest; | 30 using mojo::BindToRequest; |
| 30 using mojo::ContentHandler; | 31 using mojo::ContentHandler; |
| 31 using mojo::InterfaceRequest; | 32 using mojo::InterfaceRequest; |
| 32 using mojo::ServiceProvider; | 33 using mojo::ServiceProvider; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // when we quit (the messageloop is shared among multiple | 66 // when we quit (the messageloop is shared among multiple |
| 66 // HTMLDocumentApplicationDelegates). | 67 // HTMLDocumentApplicationDelegates). |
| 67 void OnTerminate() { | 68 void OnTerminate() { |
| 68 delete this; | 69 delete this; |
| 69 } | 70 } |
| 70 | 71 |
| 71 // ApplicationDelegate; | 72 // ApplicationDelegate; |
| 72 void Initialize(mojo::ApplicationImpl* app) override { | 73 void Initialize(mojo::ApplicationImpl* app) override { |
| 73 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 74 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 74 request->url = mojo::String::From("mojo:network_service"); | 75 request->url = mojo::String::From("mojo:network_service"); |
| 75 app_.ConnectToService(request.Pass(), (&network_service_)); | 76 mojo::ApplicationConnection* connection = |
| 77 app_.ConnectToApplication(request.Pass()); |
| 78 connection->ConnectToService(&network_service_); |
| 79 connection->ConnectToService(&url_loader_factory_); |
| 76 } | 80 } |
| 77 bool ConfigureIncomingConnection( | 81 bool ConfigureIncomingConnection( |
| 78 mojo::ApplicationConnection* connection) override { | 82 mojo::ApplicationConnection* connection) override { |
| 79 if (initial_response_) { | 83 if (initial_response_) { |
| 80 OnResponseReceived(URLLoaderPtr(), connection, initial_response_.Pass()); | 84 OnResponseReceived(URLLoaderPtr(), connection, initial_response_.Pass()); |
| 81 } else { | 85 } else { |
| 82 URLLoaderPtr loader; | 86 URLLoaderPtr loader; |
| 83 network_service_->CreateURLLoader(GetProxy(&loader)); | 87 url_loader_factory_->CreateURLLoader(GetProxy(&loader)); |
| 84 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 88 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 85 request->url = url_; | 89 request->url = url_; |
| 86 request->auto_follow_redirects = true; | 90 request->auto_follow_redirects = true; |
| 87 | 91 |
| 88 // |loader| will be passed to the OnResponseReceived method through a | 92 // |loader| will be passed to the OnResponseReceived method through a |
| 89 // callback. Because order of evaluation is undefined, a reference to the | 93 // callback. Because order of evaluation is undefined, a reference to the |
| 90 // raw pointer is needed. | 94 // raw pointer is needed. |
| 91 mojo::URLLoader* raw_loader = loader.get(); | 95 mojo::URLLoader* raw_loader = loader.get(); |
| 92 raw_loader->Start( | 96 raw_loader->Start( |
| 93 request.Pass(), | 97 request.Pass(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 105 // TODO(sky): when headless, this leaks. | 109 // TODO(sky): when headless, this leaks. |
| 106 // TODO(sky): this needs to delete if serviceprovider goes away too. | 110 // TODO(sky): this needs to delete if serviceprovider goes away too. |
| 107 new HTMLDocument(&app_, connection, response.Pass(), setup_); | 111 new HTMLDocument(&app_, connection, response.Pass(), setup_); |
| 108 } | 112 } |
| 109 | 113 |
| 110 mojo::ApplicationImpl app_; | 114 mojo::ApplicationImpl app_; |
| 111 // AppRefCount of the parent (HTMLViewer). | 115 // AppRefCount of the parent (HTMLViewer). |
| 112 scoped_ptr<mojo::AppRefCount> parent_app_refcount_; | 116 scoped_ptr<mojo::AppRefCount> parent_app_refcount_; |
| 113 const String url_; | 117 const String url_; |
| 114 mojo::NetworkServicePtr network_service_; | 118 mojo::NetworkServicePtr network_service_; |
| 119 mojo::URLLoaderFactoryPtr url_loader_factory_; |
| 115 URLResponsePtr initial_response_; | 120 URLResponsePtr initial_response_; |
| 116 Setup* setup_; | 121 Setup* setup_; |
| 117 | 122 |
| 118 DISALLOW_COPY_AND_ASSIGN(HTMLDocumentApplicationDelegate); | 123 DISALLOW_COPY_AND_ASSIGN(HTMLDocumentApplicationDelegate); |
| 119 }; | 124 }; |
| 120 | 125 |
| 121 class ContentHandlerImpl : public mojo::ContentHandler { | 126 class ContentHandlerImpl : public mojo::ContentHandler { |
| 122 public: | 127 public: |
| 123 ContentHandlerImpl(Setup* setup, | 128 ContentHandlerImpl(Setup* setup, |
| 124 mojo::ApplicationImpl* app, | 129 mojo::ApplicationImpl* app, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 184 |
| 180 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); | 185 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); |
| 181 }; | 186 }; |
| 182 | 187 |
| 183 } // namespace html_viewer | 188 } // namespace html_viewer |
| 184 | 189 |
| 185 MojoResult MojoMain(MojoHandle shell_handle) { | 190 MojoResult MojoMain(MojoHandle shell_handle) { |
| 186 mojo::ApplicationRunner runner(new html_viewer::HTMLViewer); | 191 mojo::ApplicationRunner runner(new html_viewer::HTMLViewer); |
| 187 return runner.Run(shell_handle); | 192 return runner.Run(shell_handle); |
| 188 } | 193 } |
| OLD | NEW |