Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: mojo/services/html_viewer/html_viewer.cc

Issue 1049013004: Add some simple HTMLViewer apptests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Continue cleanup. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "gin/public/isolate_holder.h" 11 #include "gin/public/isolate_holder.h"
12 #include "mojo/application/application_runner_chromium.h" 12 #include "mojo/application/application_runner_chromium.h"
13 #include "mojo/services/html_viewer/discardable_memory_allocator.h" 13 #include "mojo/services/html_viewer/discardable_memory_allocator.h"
14 #include "mojo/services/html_viewer/html_document.h" 14 #include "mojo/services/html_viewer/html_document.h"
15 #include "mojo/services/html_viewer/mojo_blink_platform_impl.h" 15 #include "mojo/services/html_viewer/mojo_blink_platform_impl.h"
16 #include "mojo/services/html_viewer/public/interfaces/html_viewer.mojom.h"
16 #include "mojo/services/html_viewer/webmediaplayer_factory.h" 17 #include "mojo/services/html_viewer/webmediaplayer_factory.h"
17 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 18 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
18 #include "third_party/WebKit/public/web/WebKit.h" 19 #include "third_party/WebKit/public/web/WebKit.h"
19 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 20 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
20 #include "third_party/mojo/src/mojo/public/c/system/main.h" 21 #include "third_party/mojo/src/mojo/public/c/system/main.h"
21 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h" 22 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h"
22 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate. h" 23 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate. h"
23 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" 24 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
24 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h" 25 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h"
25 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory_imp l.h" 26 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory_imp l.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // Disables support for (unprefixed) Encrypted Media Extensions. 58 // Disables support for (unprefixed) Encrypted Media Extensions.
58 const char kDisableEncryptedMedia[] = "disable-encrypted-media"; 59 const char kDisableEncryptedMedia[] = "disable-encrypted-media";
59 60
60 // Prevents creation of any output surface. 61 // Prevents creation of any output surface.
61 const char kIsHeadless[] = "is-headless"; 62 const char kIsHeadless[] = "is-headless";
62 63
63 size_t kDesiredMaxMemory = 20 * 1024 * 1024; 64 size_t kDesiredMaxMemory = 20 * 1024 * 1024;
64 65
65 class HTMLViewer; 66 class HTMLViewer;
66 67
67 class HTMLViewerApplication : public mojo::Application { 68 class HTMLViewerApplication
69 : public mojo::Application,
70 public mojo::InterfaceImpl<mojo::HTMLViewerTestAPI>,
71 public mojo::InterfaceFactory<mojo::HTMLViewerTestAPI> {
68 public: 72 public:
69 HTMLViewerApplication(InterfaceRequest<Application> request, 73 HTMLViewerApplication(InterfaceRequest<Application> request,
70 URLResponsePtr response, 74 URLResponsePtr response,
71 scoped_refptr<base::MessageLoopProxy> compositor_thread, 75 scoped_refptr<base::MessageLoopProxy> compositor_thread,
72 WebMediaPlayerFactory* web_media_player_factory, 76 WebMediaPlayerFactory* web_media_player_factory,
73 bool is_headless) 77 bool is_headless)
74 : url_(response->url), 78 : url_(response->url),
75 binding_(this, request.Pass()), 79 binding_(this, request.Pass()),
76 initial_response_(response.Pass()), 80 initial_response_(response.Pass()),
77 compositor_thread_(compositor_thread), 81 compositor_thread_(compositor_thread),
78 web_media_player_factory_(web_media_player_factory), 82 web_media_player_factory_(web_media_player_factory),
79 is_headless_(is_headless) {} 83 is_headless_(is_headless) {}
80 84
81 void Initialize(ShellPtr shell, 85 void Initialize(ShellPtr shell,
82 Array<String> args, 86 Array<String> args,
83 const String& url) override { 87 const String& url) override {
88 printf("MSW HTMLViewerApplication::Initialize\n");
84 ServiceProviderPtr service_provider; 89 ServiceProviderPtr service_provider;
85 shell_ = shell.Pass(); 90 shell_ = shell.Pass();
86 shell_->ConnectToApplication("mojo:network_service", 91 shell_->ConnectToApplication("mojo:network_service",
87 GetProxy(&service_provider), nullptr); 92 GetProxy(&service_provider), nullptr);
88 ConnectToService(service_provider.get(), &network_service_); 93 ConnectToService(service_provider.get(), &network_service_);
89 } 94 }
90 95
91 void AcceptConnection(const String& requestor_url, 96 void AcceptConnection(const String& requestor_url,
92 InterfaceRequest<ServiceProvider> services, 97 InterfaceRequest<ServiceProvider> services,
93 ServiceProviderPtr exposed_services, 98 ServiceProviderPtr exposed_services,
94 const String& url) override { 99 const String& url) override {
100 service_provider_.AddService<mojo::HTMLViewerTestAPI>(this);
sky 2015/04/02 16:56:17 We should only do this if a command line switch is
101 service_provider_.Bind(services.Pass());
102
103 printf("MSW HTMLViewerApplication::AcceptConnection "
104 "requestor=[%s] url=[%s] (url_=[%s], initial_response_=[%d])\n",
105 requestor_url.data(), url.data(), url_.data(),
106 !initial_response_.is_null());
107
95 if (initial_response_) { 108 if (initial_response_) {
96 OnResponseReceived(URLLoaderPtr(), services.Pass(), 109 OnResponseReceived(URLLoaderPtr(), initial_response_.Pass());
97 initial_response_.Pass());
98 } else { 110 } else {
111 // TODO(msw): Is this dead code? When is this called?
99 URLLoaderPtr loader; 112 URLLoaderPtr loader;
100 network_service_->CreateURLLoader(GetProxy(&loader)); 113 network_service_->CreateURLLoader(GetProxy(&loader));
101 mojo::URLRequestPtr request(mojo::URLRequest::New()); 114 mojo::URLRequestPtr request(mojo::URLRequest::New());
102 request->url = url_; 115 request->url = url_;
103 request->auto_follow_redirects = true; 116 request->auto_follow_redirects = true;
104 117
105 // |loader| will be pass to the OnResponseReceived method through a 118 // |loader| will be pass to the OnResponseReceived method through a
106 // callback. Because order of evaluation is undefined, a reference to the 119 // callback. Because order of evaluation is undefined, a reference to the
107 // raw pointer is needed. 120 // raw pointer is needed.
108 mojo::URLLoader* raw_loader = loader.get(); 121 mojo::URLLoader* raw_loader = loader.get();
109 raw_loader->Start( 122 raw_loader->Start(
110 request.Pass(), 123 request.Pass(),
111 base::Bind(&HTMLViewerApplication::OnResponseReceived, 124 base::Bind(&HTMLViewerApplication::OnResponseReceived,
112 base::Unretained(this), base::Passed(&loader), 125 base::Unretained(this), base::Passed(&loader)));
113 base::Passed(&services)));
114 } 126 }
115 } 127 }
116 128
117 void RequestQuit() override {} 129 void RequestQuit() override {}
118 130
131 // mojo::InterfaceImpl<mojo::HTMLViewerTestAPI>:
132 void WaitForLoad(const WaitForLoadCallback& callback) override {
133 printf("MSW HTMLViewerApplication::WaitForLoad loaded:%d\n", loaded_);
134 if (loaded_)
135 callback.Run();
136 else
137 wait_for_load_callback_ = callback;
sky 2015/04/02 16:56:17 Log or DCHECK if already waiting?
138 }
139
140 // mojo::InterfaceFactory<mojo::HTMLViewerTestAPI>:
141 void Create(
142 ApplicationConnection* connection,
143 mojo::InterfaceRequest<mojo::HTMLViewerTestAPI> request) override {
144 printf("MSW HTMLViewerApplication::Create (HTMLViewerTestAPI)\n");
145 // TODO(msw): Do not offer this service without --html-viewer-test-flag...
146 // TODO(msw): Is this safe/correct? Can we avoid InterfaceFactory?
147 // (getting flaky shutdown crashes w/base::MessageLoop dtor...)
148 BindToRequest(this, &request);
149 }
150
119 private: 151 private:
120 void OnResponseReceived(URLLoaderPtr loader, 152 void OnResponseReceived(URLLoaderPtr loader, URLResponsePtr response) {
121 InterfaceRequest<ServiceProvider> services, 153 loaded_ = true;
sky 2015/04/02 16:56:17 Is this really loaded, or just created document?
122 URLResponsePtr response) { 154 printf("MSW HTMLViewerApplication::OnResponseReceived\n");
123 new HTMLDocument(services.Pass(), response.Pass(), shell_.get(), 155 new HTMLDocument(&service_provider_, response.Pass(), shell_.get(),
124 compositor_thread_, web_media_player_factory_, 156 compositor_thread_, web_media_player_factory_,
125 is_headless_); 157 is_headless_);
158 if (!wait_for_load_callback_.is_null())
159 wait_for_load_callback_.Run();
126 } 160 }
127 161
128 String url_; 162 String url_;
129 mojo::StrongBinding<mojo::Application> binding_; 163 mojo::StrongBinding<mojo::Application> binding_;
164 mojo::ServiceProviderImpl service_provider_;
130 ShellPtr shell_; 165 ShellPtr shell_;
131 mojo::NetworkServicePtr network_service_; 166 mojo::NetworkServicePtr network_service_;
132 URLResponsePtr initial_response_; 167 URLResponsePtr initial_response_;
133 scoped_refptr<base::MessageLoopProxy> compositor_thread_; 168 scoped_refptr<base::MessageLoopProxy> compositor_thread_;
134 WebMediaPlayerFactory* web_media_player_factory_; 169 WebMediaPlayerFactory* web_media_player_factory_;
135 bool is_headless_; 170 bool is_headless_;
171 bool loaded_ = false;
172 WaitForLoadCallback wait_for_load_callback_;
136 }; 173 };
137 174
138 class ContentHandlerImpl : public mojo::InterfaceImpl<ContentHandler> { 175 class ContentHandlerImpl : public mojo::InterfaceImpl<ContentHandler> {
139 public: 176 public:
140 ContentHandlerImpl(scoped_refptr<base::MessageLoopProxy> compositor_thread, 177 ContentHandlerImpl(scoped_refptr<base::MessageLoopProxy> compositor_thread,
141 WebMediaPlayerFactory* web_media_player_factory, 178 WebMediaPlayerFactory* web_media_player_factory,
142 bool is_headless) 179 bool is_headless)
143 : compositor_thread_(compositor_thread), 180 : compositor_thread_(compositor_thread),
144 web_media_player_factory_(web_media_player_factory), 181 web_media_player_factory_(web_media_player_factory),
145 is_headless_(is_headless) {} 182 is_headless_(is_headless) {
183 printf("MSW ContentHandlerImpl::ContentHandlerImpl\n");
184 }
146 ~ContentHandlerImpl() override {} 185 ~ContentHandlerImpl() override {}
147 186
148 private: 187 private:
149 // Overridden from ContentHandler: 188 // Overridden from ContentHandler:
150 void StartApplication(InterfaceRequest<mojo::Application> request, 189 void StartApplication(InterfaceRequest<mojo::Application> request,
151 URLResponsePtr response) override { 190 URLResponsePtr response) override {
191 printf("MSW ContentHandlerImpl::StartApplication\n");
152 new HTMLViewerApplication(request.Pass(), response.Pass(), 192 new HTMLViewerApplication(request.Pass(), response.Pass(),
153 compositor_thread_, web_media_player_factory_, 193 compositor_thread_, web_media_player_factory_,
154 is_headless_); 194 is_headless_);
155 } 195 }
156 196
157 scoped_refptr<base::MessageLoopProxy> compositor_thread_; 197 scoped_refptr<base::MessageLoopProxy> compositor_thread_;
158 WebMediaPlayerFactory* web_media_player_factory_; 198 WebMediaPlayerFactory* web_media_player_factory_;
159 bool is_headless_; 199 bool is_headless_;
160 200
161 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); 201 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 269 }
230 270
231 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 271 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
232 connection->AddService(this); 272 connection->AddService(this);
233 return true; 273 return true;
234 } 274 }
235 275
236 // Overridden from InterfaceFactory<ContentHandler> 276 // Overridden from InterfaceFactory<ContentHandler>
237 void Create(ApplicationConnection* connection, 277 void Create(ApplicationConnection* connection,
238 mojo::InterfaceRequest<ContentHandler> request) override { 278 mojo::InterfaceRequest<ContentHandler> request) override {
279 printf("MSW HTMLViewer::Create (ContentHandler)\n");
239 BindToRequest( 280 BindToRequest(
240 new ContentHandlerImpl(compositor_thread_.message_loop_proxy(), 281 new ContentHandlerImpl(compositor_thread_.message_loop_proxy(),
241 web_media_player_factory_.get(), is_headless_), 282 web_media_player_factory_.get(), is_headless_),
242 &request); 283 &request);
243 } 284 }
244 285
245 // Skia requires that we have one of these. Unlike the one used in chrome, 286 // Skia requires that we have one of these. Unlike the one used in chrome,
246 // this doesn't use purgable shared memory. Instead, it tries to free the 287 // this doesn't use purgable shared memory. Instead, it tries to free the
247 // oldest unlocked chunks on allocation. 288 // oldest unlocked chunks on allocation.
248 // 289 //
249 // TODO(erg): In the long run, delete this allocator and get the real shared 290 // TODO(erg): In the long run, delete this allocator and get the real shared
250 // memory based purging allocator working here. 291 // memory based purging allocator working here.
251 DiscardableMemoryAllocator discardable_memory_allocator_; 292 DiscardableMemoryAllocator discardable_memory_allocator_;
252 293
253 scoped_ptr<MojoBlinkPlatformImpl> blink_platform_; 294 scoped_ptr<MojoBlinkPlatformImpl> blink_platform_;
254 base::Thread compositor_thread_; 295 base::Thread compositor_thread_;
255 scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_; 296 scoped_ptr<WebMediaPlayerFactory> web_media_player_factory_;
256 // Set if the content will never be displayed. 297 // Set if the content will never be displayed.
257 bool is_headless_; 298 bool is_headless_;
258 299
259 DISALLOW_COPY_AND_ASSIGN(HTMLViewer); 300 DISALLOW_COPY_AND_ASSIGN(HTMLViewer);
260 }; 301 };
261 302
262 } // namespace html_viewer 303 } // namespace html_viewer
263 304
264 MojoResult MojoMain(MojoHandle shell_handle) { 305 MojoResult MojoMain(MojoHandle shell_handle) {
306 printf("MSW MojoMain\n");
265 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer); 307 mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer);
266 return runner.Run(shell_handle); 308 return runner.Run(shell_handle);
267 } 309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698