| 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 | 8 |
| 8 #include "base/bind.h" | 9 #include "base/bind.h" |
| 9 #include "base/callback.h" | 10 #include "base/callback.h" |
| 10 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "components/bitmap_uploader/bitmap_uploader.h" | 14 #include "components/bitmap_uploader/bitmap_uploader.h" |
| 14 #include "components/mus/common/types.h" | 15 #include "components/mus/common/types.h" |
| 15 #include "components/mus/public/cpp/input_event_handler.h" | 16 #include "components/mus/public/cpp/input_event_handler.h" |
| 16 #include "components/mus/public/cpp/scoped_window_ptr.h" | 17 #include "components/mus/public/cpp/scoped_window_ptr.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 bitmap->resize(width * height * 4); | 96 bitmap->resize(width * height * 4); |
| 96 | 97 |
| 97 FPDF_BITMAP f_bitmap = FPDFBitmap_CreateEx(width, height, FPDFBitmap_BGRA, | 98 FPDF_BITMAP f_bitmap = FPDFBitmap_CreateEx(width, height, FPDFBitmap_BGRA, |
| 98 &(*bitmap)[0], width * 4); | 99 &(*bitmap)[0], width * 4); |
| 99 FPDFBitmap_FillRect(f_bitmap, 0, 0, width, height, 0xFFFFFFFF); | 100 FPDFBitmap_FillRect(f_bitmap, 0, 0, width, height, 0xFFFFFFFF); |
| 100 FPDF_RenderPageBitmap(f_bitmap, page, 0, 0, width, height, 0, 0); | 101 FPDF_RenderPageBitmap(f_bitmap, page, 0, 0, width, height, 0, 0); |
| 101 FPDFBitmap_Destroy(f_bitmap); | 102 FPDFBitmap_Destroy(f_bitmap); |
| 102 | 103 |
| 103 FPDF_ClosePage(page); | 104 FPDF_ClosePage(page); |
| 104 | 105 |
| 105 bitmap_uploader_->SetBitmap(width, height, bitmap.Pass(), | 106 bitmap_uploader_->SetBitmap(width, height, std::move(bitmap), |
| 106 bitmap_uploader::BitmapUploader::BGRA); | 107 bitmap_uploader::BitmapUploader::BGRA); |
| 107 } | 108 } |
| 108 | 109 |
| 109 // WindowTreeDelegate: | 110 // WindowTreeDelegate: |
| 110 void OnEmbed(mus::Window* root) override { | 111 void OnEmbed(mus::Window* root) override { |
| 111 DCHECK(!root_); | 112 DCHECK(!root_); |
| 112 root_ = root; | 113 root_ = root; |
| 113 root_->AddObserver(this); | 114 root_->AddObserver(this); |
| 114 root_->set_input_event_handler(this); | 115 root_->set_input_event_handler(this); |
| 115 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(root_)); | 116 bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(root_)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // web_view::mojom::FrameClient: | 172 // web_view::mojom::FrameClient: |
| 172 void OnConnect(web_view::mojom::FramePtr frame, | 173 void OnConnect(web_view::mojom::FramePtr frame, |
| 173 uint32_t change_id, | 174 uint32_t change_id, |
| 174 uint32_t view_id, | 175 uint32_t view_id, |
| 175 web_view::mojom::WindowConnectType view_connect_type, | 176 web_view::mojom::WindowConnectType view_connect_type, |
| 176 mojo::Array<web_view::mojom::FrameDataPtr> frame_data, | 177 mojo::Array<web_view::mojom::FrameDataPtr> frame_data, |
| 177 int64_t navigation_start_time_ticks, | 178 int64_t navigation_start_time_ticks, |
| 178 const OnConnectCallback& callback) override { | 179 const OnConnectCallback& callback) override { |
| 179 callback.Run(); | 180 callback.Run(); |
| 180 | 181 |
| 181 frame_ = frame.Pass(); | 182 frame_ = std::move(frame); |
| 182 frame_->DidCommitProvisionalLoad(); | 183 frame_->DidCommitProvisionalLoad(); |
| 183 } | 184 } |
| 184 void OnFrameAdded(uint32_t change_id, | 185 void OnFrameAdded(uint32_t change_id, |
| 185 web_view::mojom::FrameDataPtr frame_data) override {} | 186 web_view::mojom::FrameDataPtr frame_data) override {} |
| 186 void OnFrameRemoved(uint32_t change_id, uint32_t frame_id) override {} | 187 void OnFrameRemoved(uint32_t change_id, uint32_t frame_id) override {} |
| 187 void OnFrameClientPropertyChanged(uint32_t frame_id, | 188 void OnFrameClientPropertyChanged(uint32_t frame_id, |
| 188 const mojo::String& name, | 189 const mojo::String& name, |
| 189 mojo::Array<uint8_t> new_value) override {} | 190 mojo::Array<uint8_t> new_value) override {} |
| 190 void OnPostMessageEvent(uint32_t source_frame_id, | 191 void OnPostMessageEvent(uint32_t source_frame_id, |
| 191 uint32_t target_frame_id, | 192 uint32_t target_frame_id, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 210 web_view::mojom::FindOptionsPtr options, | 211 web_view::mojom::FindOptionsPtr options, |
| 211 bool reset) override { | 212 bool reset) override { |
| 212 NOTIMPLEMENTED(); | 213 NOTIMPLEMENTED(); |
| 213 } | 214 } |
| 214 void StopHighlightingFindResults() override {} | 215 void StopHighlightingFindResults() override {} |
| 215 | 216 |
| 216 // mojo::InterfaceFactory<web_view::mojom::FrameClient>: | 217 // mojo::InterfaceFactory<web_view::mojom::FrameClient>: |
| 217 void Create( | 218 void Create( |
| 218 mojo::ApplicationConnection* connection, | 219 mojo::ApplicationConnection* connection, |
| 219 mojo::InterfaceRequest<web_view::mojom::FrameClient> request) override { | 220 mojo::InterfaceRequest<web_view::mojom::FrameClient> request) override { |
| 220 frame_client_binding_.Bind(request.Pass()); | 221 frame_client_binding_.Bind(std::move(request)); |
| 221 } | 222 } |
| 222 | 223 |
| 223 scoped_ptr<mojo::AppRefCount> app_ref_; | 224 scoped_ptr<mojo::AppRefCount> app_ref_; |
| 224 FPDF_DOCUMENT doc_; | 225 FPDF_DOCUMENT doc_; |
| 225 int current_page_; | 226 int current_page_; |
| 226 int page_count_; | 227 int page_count_; |
| 227 | 228 |
| 228 scoped_ptr<bitmap_uploader::BitmapUploader> bitmap_uploader_; | 229 scoped_ptr<bitmap_uploader::BitmapUploader> bitmap_uploader_; |
| 229 | 230 |
| 230 mojo::Shell* shell_; | 231 mojo::Shell* shell_; |
| 231 mus::Window* root_; | 232 mus::Window* root_; |
| 232 | 233 |
| 233 web_view::mojom::FramePtr frame_; | 234 web_view::mojom::FramePtr frame_; |
| 234 mojo::Binding<web_view::mojom::FrameClient> frame_client_binding_; | 235 mojo::Binding<web_view::mojom::FrameClient> frame_client_binding_; |
| 235 DeleteCallback delete_callback_; | 236 DeleteCallback delete_callback_; |
| 236 | 237 |
| 237 DISALLOW_COPY_AND_ASSIGN(PDFView); | 238 DISALLOW_COPY_AND_ASSIGN(PDFView); |
| 238 }; | 239 }; |
| 239 | 240 |
| 240 // Responsible for managing all the views for displaying a PDF document. | 241 // Responsible for managing all the views for displaying a PDF document. |
| 241 class PDFViewerApplicationDelegate | 242 class PDFViewerApplicationDelegate |
| 242 : public mojo::ApplicationDelegate, | 243 : public mojo::ApplicationDelegate, |
| 243 public mojo::InterfaceFactory<mus::mojom::WindowTreeClient> { | 244 public mojo::InterfaceFactory<mus::mojom::WindowTreeClient> { |
| 244 public: | 245 public: |
| 245 PDFViewerApplicationDelegate( | 246 PDFViewerApplicationDelegate( |
| 246 mojo::InterfaceRequest<mojo::Application> request, | 247 mojo::InterfaceRequest<mojo::Application> request, |
| 247 mojo::URLResponsePtr response, | 248 mojo::URLResponsePtr response, |
| 248 const mojo::Callback<void()>& destruct_callback) | 249 const mojo::Callback<void()>& destruct_callback) |
| 249 : app_(this, | 250 : app_(this, |
| 250 request.Pass(), | 251 std::move(request), |
| 251 base::Bind(&PDFViewerApplicationDelegate::OnTerminate, | 252 base::Bind(&PDFViewerApplicationDelegate::OnTerminate, |
| 252 base::Unretained(this))), | 253 base::Unretained(this))), |
| 253 doc_(nullptr), | 254 doc_(nullptr), |
| 254 is_destroying_(false), | 255 is_destroying_(false), |
| 255 destruct_callback_(destruct_callback) { | 256 destruct_callback_(destruct_callback) { |
| 256 FetchPDF(response.Pass()); | 257 FetchPDF(std::move(response)); |
| 257 } | 258 } |
| 258 | 259 |
| 259 ~PDFViewerApplicationDelegate() override { | 260 ~PDFViewerApplicationDelegate() override { |
| 260 is_destroying_ = true; | 261 is_destroying_ = true; |
| 261 if (doc_) | 262 if (doc_) |
| 262 FPDF_CloseDocument(doc_); | 263 FPDF_CloseDocument(doc_); |
| 263 while (!pdf_views_.empty()) | 264 while (!pdf_views_.empty()) |
| 264 pdf_views_.front()->Close(); | 265 pdf_views_.front()->Close(); |
| 265 destruct_callback_.Run(); | 266 destruct_callback_.Run(); |
| 266 } | 267 } |
| 267 | 268 |
| 268 private: | 269 private: |
| 269 void FetchPDF(mojo::URLResponsePtr response) { | 270 void FetchPDF(mojo::URLResponsePtr response) { |
| 270 data_.clear(); | 271 data_.clear(); |
| 271 mojo::common::BlockingCopyToString(response->body.Pass(), &data_); | 272 mojo::common::BlockingCopyToString(std::move(response->body), &data_); |
| 272 if (data_.length() >= static_cast<size_t>(std::numeric_limits<int>::max())) | 273 if (data_.length() >= static_cast<size_t>(std::numeric_limits<int>::max())) |
| 273 return; | 274 return; |
| 274 doc_ = FPDF_LoadMemDocument(data_.data(), static_cast<int>(data_.length()), | 275 doc_ = FPDF_LoadMemDocument(data_.data(), static_cast<int>(data_.length()), |
| 275 nullptr); | 276 nullptr); |
| 276 } | 277 } |
| 277 | 278 |
| 278 // Callback from the quit closure. We key off this rather than | 279 // Callback from the quit closure. We key off this rather than |
| 279 // ApplicationDelegate::Quit() as we don't want to shut down the messageloop | 280 // ApplicationDelegate::Quit() as we don't want to shut down the messageloop |
| 280 // when we quit (the messageloop is shared among multiple PDFViews). | 281 // when we quit (the messageloop is shared among multiple PDFViews). |
| 281 void OnTerminate() { delete this; } | 282 void OnTerminate() { delete this; } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 296 // mojo::InterfaceFactory<mus::mojom::WindowTreeClient>: | 297 // mojo::InterfaceFactory<mus::mojom::WindowTreeClient>: |
| 297 void Create( | 298 void Create( |
| 298 mojo::ApplicationConnection* connection, | 299 mojo::ApplicationConnection* connection, |
| 299 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) override { | 300 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) override { |
| 300 PDFView* pdf_view = new PDFView( | 301 PDFView* pdf_view = new PDFView( |
| 301 &app_, connection, doc_, | 302 &app_, connection, doc_, |
| 302 base::Bind(&PDFViewerApplicationDelegate::OnPDFViewDestroyed, | 303 base::Bind(&PDFViewerApplicationDelegate::OnPDFViewDestroyed, |
| 303 base::Unretained(this))); | 304 base::Unretained(this))); |
| 304 pdf_views_.push_back(pdf_view); | 305 pdf_views_.push_back(pdf_view); |
| 305 mus::WindowTreeConnection::Create( | 306 mus::WindowTreeConnection::Create( |
| 306 pdf_view, request.Pass(), | 307 pdf_view, std::move(request), |
| 307 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | 308 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); |
| 308 } | 309 } |
| 309 | 310 |
| 310 mojo::ApplicationImpl app_; | 311 mojo::ApplicationImpl app_; |
| 311 std::string data_; | 312 std::string data_; |
| 312 std::vector<PDFView*> pdf_views_; | 313 std::vector<PDFView*> pdf_views_; |
| 313 FPDF_DOCUMENT doc_; | 314 FPDF_DOCUMENT doc_; |
| 314 bool is_destroying_; | 315 bool is_destroying_; |
| 315 mojo::Callback<void()> destruct_callback_; | 316 mojo::Callback<void()> destruct_callback_; |
| 316 | 317 |
| 317 DISALLOW_COPY_AND_ASSIGN(PDFViewerApplicationDelegate); | 318 DISALLOW_COPY_AND_ASSIGN(PDFViewerApplicationDelegate); |
| 318 }; | 319 }; |
| 319 | 320 |
| 320 class ContentHandlerImpl : public mojo::ContentHandler { | 321 class ContentHandlerImpl : public mojo::ContentHandler { |
| 321 public: | 322 public: |
| 322 ContentHandlerImpl(mojo::InterfaceRequest<ContentHandler> request) | 323 ContentHandlerImpl(mojo::InterfaceRequest<ContentHandler> request) |
| 323 : binding_(this, request.Pass()) {} | 324 : binding_(this, std::move(request)) {} |
| 324 ~ContentHandlerImpl() override {} | 325 ~ContentHandlerImpl() override {} |
| 325 | 326 |
| 326 private: | 327 private: |
| 327 // ContentHandler: | 328 // ContentHandler: |
| 328 void StartApplication( | 329 void StartApplication( |
| 329 mojo::InterfaceRequest<mojo::Application> request, | 330 mojo::InterfaceRequest<mojo::Application> request, |
| 330 mojo::URLResponsePtr response, | 331 mojo::URLResponsePtr response, |
| 331 const mojo::Callback<void()>& destruct_callback) override { | 332 const mojo::Callback<void()>& destruct_callback) override { |
| 332 new PDFViewerApplicationDelegate( | 333 new PDFViewerApplicationDelegate(std::move(request), std::move(response), |
| 333 request.Pass(), response.Pass(), destruct_callback); | 334 destruct_callback); |
| 334 } | 335 } |
| 335 | 336 |
| 336 mojo::StrongBinding<mojo::ContentHandler> binding_; | 337 mojo::StrongBinding<mojo::ContentHandler> binding_; |
| 337 | 338 |
| 338 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); | 339 DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); |
| 339 }; | 340 }; |
| 340 | 341 |
| 341 class PDFViewer : public mojo::ApplicationDelegate, | 342 class PDFViewer : public mojo::ApplicationDelegate, |
| 342 public mojo::InterfaceFactory<mojo::ContentHandler> { | 343 public mojo::InterfaceFactory<mojo::ContentHandler> { |
| 343 public: | 344 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 356 | 357 |
| 357 bool ConfigureIncomingConnection( | 358 bool ConfigureIncomingConnection( |
| 358 mojo::ApplicationConnection* connection) override { | 359 mojo::ApplicationConnection* connection) override { |
| 359 connection->AddService(this); | 360 connection->AddService(this); |
| 360 return true; | 361 return true; |
| 361 } | 362 } |
| 362 | 363 |
| 363 // InterfaceFactory<ContentHandler>: | 364 // InterfaceFactory<ContentHandler>: |
| 364 void Create(mojo::ApplicationConnection* connection, | 365 void Create(mojo::ApplicationConnection* connection, |
| 365 mojo::InterfaceRequest<mojo::ContentHandler> request) override { | 366 mojo::InterfaceRequest<mojo::ContentHandler> request) override { |
| 366 new ContentHandlerImpl(request.Pass()); | 367 new ContentHandlerImpl(std::move(request)); |
| 367 } | 368 } |
| 368 | 369 |
| 369 mojo::TracingImpl tracing_; | 370 mojo::TracingImpl tracing_; |
| 370 | 371 |
| 371 DISALLOW_COPY_AND_ASSIGN(PDFViewer); | 372 DISALLOW_COPY_AND_ASSIGN(PDFViewer); |
| 372 }; | 373 }; |
| 373 } // namespace | 374 } // namespace |
| 374 } // namespace pdf_viewer | 375 } // namespace pdf_viewer |
| 375 | 376 |
| 376 MojoResult MojoMain(MojoHandle application_request) { | 377 MojoResult MojoMain(MojoHandle application_request) { |
| 377 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); | 378 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); |
| 378 return runner.Run(application_request); | 379 return runner.Run(application_request); |
| 379 } | 380 } |
| OLD | NEW |