| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "components/view_manager/public/cpp/lib/view_manager_client_impl.h" | |
| 10 #include "components/view_manager/public/cpp/types.h" | 9 #include "components/view_manager/public/cpp/types.h" |
| 11 #include "components/view_manager/public/cpp/view.h" | 10 #include "components/view_manager/public/cpp/view.h" |
| 12 #include "components/view_manager/public/cpp/view_manager.h" | 11 #include "components/view_manager/public/cpp/view_manager.h" |
| 13 #include "components/view_manager/public/cpp/view_manager_delegate.h" | 12 #include "components/view_manager/public/cpp/view_manager_delegate.h" |
| 14 #include "components/view_manager/public/cpp/view_observer.h" | 13 #include "components/view_manager/public/cpp/view_observer.h" |
| 15 #include "components/view_manager/public/interfaces/gpu.mojom.h" | 14 #include "components/view_manager/public/interfaces/gpu.mojom.h" |
| 16 #include "components/view_manager/public/interfaces/surface_id.mojom.h" | 15 #include "components/view_manager/public/interfaces/surface_id.mojom.h" |
| 17 #include "components/view_manager/public/interfaces/surfaces.mojom.h" | 16 #include "components/view_manager/public/interfaces/surfaces.mojom.h" |
| 18 #include "gpu/GLES2/gl2chromium.h" | 17 #include "gpu/GLES2/gl2chromium.h" |
| 19 #include "gpu/GLES2/gl2extchromium.h" | 18 #include "gpu/GLES2/gl2extchromium.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 343 |
| 345 private: | 344 private: |
| 346 BitmapUploader bitmap_uploader_; | 345 BitmapUploader bitmap_uploader_; |
| 347 | 346 |
| 348 DISALLOW_COPY_AND_ASSIGN(EmbedderData); | 347 DISALLOW_COPY_AND_ASSIGN(EmbedderData); |
| 349 }; | 348 }; |
| 350 | 349 |
| 351 class PDFView : public mojo::ApplicationDelegate, | 350 class PDFView : public mojo::ApplicationDelegate, |
| 352 public mojo::ViewManagerDelegate, | 351 public mojo::ViewManagerDelegate, |
| 353 public mojo::ViewObserver, | 352 public mojo::ViewObserver, |
| 354 public mojo::InterfaceFactory<mojo::ViewManagerClient> { | 353 public mojo::InterfaceFactory<mojo::ViewTreeClient> { |
| 355 public: | 354 public: |
| 356 PDFView(mojo::InterfaceRequest<mojo::Application> request, | 355 PDFView(mojo::InterfaceRequest<mojo::Application> request, |
| 357 mojo::URLResponsePtr response) | 356 mojo::URLResponsePtr response) |
| 358 : app_(this, request.Pass(), base::Bind(&PDFView::OnTerminate, | 357 : app_(this, request.Pass(), base::Bind(&PDFView::OnTerminate, |
| 359 base::Unretained(this))), | 358 base::Unretained(this))), |
| 360 current_page_(0), page_count_(0), doc_(nullptr) { | 359 current_page_(0), page_count_(0), doc_(nullptr) { |
| 361 FetchPDF(response.Pass()); | 360 FetchPDF(response.Pass()); |
| 362 } | 361 } |
| 363 | 362 |
| 364 ~PDFView() override { | 363 ~PDFView() override { |
| 365 if (doc_) | 364 if (doc_) |
| 366 FPDF_CloseDocument(doc_); | 365 FPDF_CloseDocument(doc_); |
| 367 for (auto& roots : embedder_for_roots_) { | 366 for (auto& roots : embedder_for_roots_) { |
| 368 roots.first->RemoveObserver(this); | 367 roots.first->RemoveObserver(this); |
| 369 delete roots.second; | 368 delete roots.second; |
| 370 } | 369 } |
| 371 } | 370 } |
| 372 | 371 |
| 373 private: | 372 private: |
| 374 // Overridden from ApplicationDelegate: | 373 // Overridden from ApplicationDelegate: |
| 375 bool ConfigureIncomingConnection( | 374 bool ConfigureIncomingConnection( |
| 376 mojo::ApplicationConnection* connection) override { | 375 mojo::ApplicationConnection* connection) override { |
| 377 connection->AddService<mojo::ViewManagerClient>(this); | 376 connection->AddService<mojo::ViewTreeClient>(this); |
| 378 return true; | 377 return true; |
| 379 } | 378 } |
| 380 | 379 |
| 381 // Overridden from ViewManagerDelegate: | 380 // Overridden from ViewManagerDelegate: |
| 382 void OnEmbed(mojo::View* root) override { | 381 void OnEmbed(mojo::View* root) override { |
| 383 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end()); | 382 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end()); |
| 384 root->AddObserver(this); | 383 root->AddObserver(this); |
| 385 EmbedderData* embedder_data = new EmbedderData(app_.shell(), root); | 384 EmbedderData* embedder_data = new EmbedderData(app_.shell(), root); |
| 386 embedder_for_roots_[root] = embedder_data; | 385 embedder_for_roots_[root] = embedder_data; |
| 387 DrawBitmap(embedder_data); | 386 DrawBitmap(embedder_data); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 void OnViewDestroyed(mojo::View* view) override { | 426 void OnViewDestroyed(mojo::View* view) override { |
| 428 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); | 427 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); |
| 429 const auto& it = embedder_for_roots_.find(view); | 428 const auto& it = embedder_for_roots_.find(view); |
| 430 DCHECK(it != embedder_for_roots_.end()); | 429 DCHECK(it != embedder_for_roots_.end()); |
| 431 delete it->second; | 430 delete it->second; |
| 432 embedder_for_roots_.erase(it); | 431 embedder_for_roots_.erase(it); |
| 433 if (embedder_for_roots_.size() == 0) | 432 if (embedder_for_roots_.size() == 0) |
| 434 app_.Quit(); | 433 app_.Quit(); |
| 435 } | 434 } |
| 436 | 435 |
| 437 // Overridden from mojo::InterfaceFactory<mojo::ViewManagerClient>: | 436 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>: |
| 438 void Create( | 437 void Create( |
| 439 mojo::ApplicationConnection* connection, | 438 mojo::ApplicationConnection* connection, |
| 440 mojo::InterfaceRequest<mojo::ViewManagerClient> request) override { | 439 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override { |
| 441 mojo::ViewManager::Create(this, request.Pass()); | 440 mojo::ViewManager::Create(this, request.Pass()); |
| 442 } | 441 } |
| 443 | 442 |
| 444 void DrawBitmap(EmbedderData* embedder_data) { | 443 void DrawBitmap(EmbedderData* embedder_data) { |
| 445 if (!doc_) | 444 if (!doc_) |
| 446 return; | 445 return; |
| 447 | 446 |
| 448 FPDF_PAGE page = FPDF_LoadPage(doc_, current_page_); | 447 FPDF_PAGE page = FPDF_LoadPage(doc_, current_page_); |
| 449 int width = static_cast<int>(FPDF_GetPageWidth(page)); | 448 int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 450 int height = static_cast<int>(FPDF_GetPageHeight(page)); | 449 int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 DISALLOW_COPY_AND_ASSIGN(PDFViewer); | 538 DISALLOW_COPY_AND_ASSIGN(PDFViewer); |
| 540 }; | 539 }; |
| 541 | 540 |
| 542 } // namespace | 541 } // namespace |
| 543 } // namespace pdf_viewer | 542 } // namespace pdf_viewer |
| 544 | 543 |
| 545 MojoResult MojoMain(MojoHandle application_request) { | 544 MojoResult MojoMain(MojoHandle application_request) { |
| 546 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); | 545 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); |
| 547 return runner.Run(application_request); | 546 return runner.Run(application_request); |
| 548 } | 547 } |
| OLD | NEW |