OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "components/bitmap_uploader/bitmap_uploader.h" | 14 #include "components/bitmap_uploader/bitmap_uploader.h" |
15 #include "components/mus/common/types.h" | 15 #include "components/mus/common/types.h" |
16 #include "components/mus/public/cpp/input_event_handler.h" | 16 #include "components/mus/public/cpp/input_event_handler.h" |
17 #include "components/mus/public/cpp/scoped_window_ptr.h" | 17 #include "components/mus/public/cpp/scoped_window_ptr.h" |
18 #include "components/mus/public/cpp/window.h" | 18 #include "components/mus/public/cpp/window.h" |
19 #include "components/mus/public/cpp/window_observer.h" | 19 #include "components/mus/public/cpp/window_observer.h" |
20 #include "components/mus/public/cpp/window_tree_connection.h" | 20 #include "components/mus/public/cpp/window_tree_connection.h" |
21 #include "components/mus/public/cpp/window_tree_delegate.h" | 21 #include "components/mus/public/cpp/window_tree_delegate.h" |
22 #include "components/mus/public/interfaces/input_events.mojom.h" | 22 #include "components/mus/public/interfaces/input_events.mojom.h" |
23 #include "components/mus/public/interfaces/input_key_codes.mojom.h" | 23 #include "components/mus/public/interfaces/input_key_codes.mojom.h" |
24 #include "components/web_view/public/interfaces/frame.mojom.h" | 24 #include "components/web_view/public/interfaces/frame.mojom.h" |
25 #include "mojo/common/data_pipe_utils.h" | 25 #include "mojo/common/data_pipe_utils.h" |
26 #include "mojo/public/c/system/main.h" | 26 #include "mojo/public/c/system/main.h" |
27 #include "mojo/public/cpp/bindings/binding.h" | 27 #include "mojo/public/cpp/bindings/binding.h" |
28 #include "mojo/public/cpp/bindings/strong_binding.h" | 28 #include "mojo/public/cpp/bindings/strong_binding.h" |
29 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 29 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
30 #include "mojo/shell/public/cpp/application_impl.h" | |
31 #include "mojo/shell/public/cpp/application_runner.h" | 30 #include "mojo/shell/public/cpp/application_runner.h" |
32 #include "mojo/shell/public/cpp/interface_factory_impl.h" | 31 #include "mojo/shell/public/cpp/interface_factory_impl.h" |
33 #include "mojo/shell/public/cpp/shell_client.h" | 32 #include "mojo/shell/public/cpp/shell_client.h" |
| 33 #include "mojo/shell/public/cpp/shell_connection.h" |
34 #include "mojo/shell/public/interfaces/content_handler.mojom.h" | 34 #include "mojo/shell/public/interfaces/content_handler.mojom.h" |
35 #include "mojo/shell/public/interfaces/shell.mojom.h" | 35 #include "mojo/shell/public/interfaces/shell.mojom.h" |
36 #include "third_party/pdfium/public/fpdf_ext.h" | 36 #include "third_party/pdfium/public/fpdf_ext.h" |
37 #include "third_party/pdfium/public/fpdfview.h" | 37 #include "third_party/pdfium/public/fpdfview.h" |
38 #include "ui/gfx/geometry/rect.h" | 38 #include "ui/gfx/geometry/rect.h" |
39 #include "v8/include/v8.h" | 39 #include "v8/include/v8.h" |
40 | 40 |
41 const uint32_t g_background_color = 0xFF888888; | 41 const uint32_t g_background_color = 0xFF888888; |
42 | 42 |
43 namespace pdf_viewer { | 43 namespace pdf_viewer { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 235 |
236 DISALLOW_COPY_AND_ASSIGN(PDFView); | 236 DISALLOW_COPY_AND_ASSIGN(PDFView); |
237 }; | 237 }; |
238 | 238 |
239 // Responsible for managing all the views for displaying a PDF document. | 239 // Responsible for managing all the views for displaying a PDF document. |
240 class PDFViewerApplicationDelegate | 240 class PDFViewerApplicationDelegate |
241 : public mojo::ShellClient, | 241 : public mojo::ShellClient, |
242 public mojo::InterfaceFactory<mus::mojom::WindowTreeClient> { | 242 public mojo::InterfaceFactory<mus::mojom::WindowTreeClient> { |
243 public: | 243 public: |
244 PDFViewerApplicationDelegate( | 244 PDFViewerApplicationDelegate( |
245 mojo::ApplicationRequest request, | 245 mojo::ShellClientRequest request, |
246 mojo::URLResponsePtr response, | 246 mojo::URLResponsePtr response, |
247 const mojo::Callback<void()>& destruct_callback) | 247 const mojo::Callback<void()>& destruct_callback) |
248 : app_(this, | 248 : app_(this, |
249 std::move(request), | 249 std::move(request), |
250 base::Bind(&PDFViewerApplicationDelegate::OnTerminate, | 250 base::Bind(&PDFViewerApplicationDelegate::OnTerminate, |
251 base::Unretained(this))), | 251 base::Unretained(this))), |
252 doc_(nullptr), | 252 doc_(nullptr), |
253 is_destroying_(false), | 253 is_destroying_(false), |
254 destruct_callback_(destruct_callback) { | 254 destruct_callback_(destruct_callback) { |
255 FetchPDF(std::move(response)); | 255 FetchPDF(std::move(response)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 PDFView* pdf_view = new PDFView( | 298 PDFView* pdf_view = new PDFView( |
299 &app_, connection, doc_, | 299 &app_, connection, doc_, |
300 base::Bind(&PDFViewerApplicationDelegate::OnPDFViewDestroyed, | 300 base::Bind(&PDFViewerApplicationDelegate::OnPDFViewDestroyed, |
301 base::Unretained(this))); | 301 base::Unretained(this))); |
302 pdf_views_.push_back(pdf_view); | 302 pdf_views_.push_back(pdf_view); |
303 mus::WindowTreeConnection::Create( | 303 mus::WindowTreeConnection::Create( |
304 pdf_view, std::move(request), | 304 pdf_view, std::move(request), |
305 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | 305 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); |
306 } | 306 } |
307 | 307 |
308 mojo::ApplicationImpl app_; | 308 mojo::ShellConnection app_; |
309 std::string data_; | 309 std::string data_; |
310 std::vector<PDFView*> pdf_views_; | 310 std::vector<PDFView*> pdf_views_; |
311 FPDF_DOCUMENT doc_; | 311 FPDF_DOCUMENT doc_; |
312 bool is_destroying_; | 312 bool is_destroying_; |
313 mojo::Callback<void()> destruct_callback_; | 313 mojo::Callback<void()> destruct_callback_; |
314 | 314 |
315 DISALLOW_COPY_AND_ASSIGN(PDFViewerApplicationDelegate); | 315 DISALLOW_COPY_AND_ASSIGN(PDFViewerApplicationDelegate); |
316 }; | 316 }; |
317 | 317 |
318 class ContentHandlerImpl : public mojo::shell::mojom::ContentHandler { | 318 class ContentHandlerImpl : public mojo::shell::mojom::ContentHandler { |
319 public: | 319 public: |
320 ContentHandlerImpl( | 320 ContentHandlerImpl( |
321 mojo::InterfaceRequest<mojo::shell::mojom::ContentHandler> request) | 321 mojo::InterfaceRequest<mojo::shell::mojom::ContentHandler> request) |
322 : binding_(this, std::move(request)) {} | 322 : binding_(this, std::move(request)) {} |
323 ~ContentHandlerImpl() override {} | 323 ~ContentHandlerImpl() override {} |
324 | 324 |
325 private: | 325 private: |
326 // mojo::shell::mojom::ContentHandler: | 326 // mojo::shell::mojom::ContentHandler: |
327 void StartApplication( | 327 void StartApplication( |
328 mojo::ApplicationRequest request, | 328 mojo::ShellClientRequest request, |
329 mojo::URLResponsePtr response, | 329 mojo::URLResponsePtr response, |
330 const mojo::Callback<void()>& destruct_callback) override { | 330 const mojo::Callback<void()>& destruct_callback) override { |
331 new PDFViewerApplicationDelegate(std::move(request), std::move(response), | 331 new PDFViewerApplicationDelegate(std::move(request), std::move(response), |
332 destruct_callback); | 332 destruct_callback); |
333 } | 333 } |
334 | 334 |
335 mojo::StrongBinding<mojo::shell::mojom::ContentHandler> binding_; | 335 mojo::StrongBinding<mojo::shell::mojom::ContentHandler> binding_; |
336 | 336 |
337 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); | 337 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); |
338 }; | 338 }; |
(...skipping 28 matching lines...) Expand all Loading... |
367 new ContentHandlerImpl(std::move(request)); | 367 new ContentHandlerImpl(std::move(request)); |
368 } | 368 } |
369 | 369 |
370 mojo::TracingImpl tracing_; | 370 mojo::TracingImpl tracing_; |
371 | 371 |
372 DISALLOW_COPY_AND_ASSIGN(PDFViewer); | 372 DISALLOW_COPY_AND_ASSIGN(PDFViewer); |
373 }; | 373 }; |
374 } // namespace | 374 } // namespace |
375 } // namespace pdf_viewer | 375 } // namespace pdf_viewer |
376 | 376 |
377 MojoResult MojoMain(MojoHandle application_request) { | 377 MojoResult MojoMain(MojoHandle request) { |
378 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); | 378 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); |
379 return runner.Run(application_request); | 379 return runner.Run(request); |
380 } | 380 } |
OLD | NEW |