OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "pdf/pdfium/pdfium_page.h" | 5 #include "pdf/pdfium/pdfium_page.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 namespace chrome_pdf { | 78 namespace chrome_pdf { |
79 | 79 |
80 PDFiumPage::PDFiumPage(PDFiumEngine* engine, | 80 PDFiumPage::PDFiumPage(PDFiumEngine* engine, |
81 int i, | 81 int i, |
82 const pp::Rect& r, | 82 const pp::Rect& r, |
83 bool available) | 83 bool available) |
84 : engine_(engine), | 84 : engine_(engine), |
85 page_(NULL), | 85 page_(nullptr), |
86 text_page_(NULL), | 86 text_page_(nullptr), |
87 index_(i), | 87 index_(i), |
88 loading_count_(0), | 88 loading_count_(0), |
89 rect_(r), | 89 rect_(r), |
90 calculated_links_(false), | 90 calculated_links_(false), |
91 available_(available) { | 91 available_(available) {} |
92 } | 92 |
| 93 PDFiumPage::PDFiumPage(const PDFiumPage& that) = default; |
93 | 94 |
94 PDFiumPage::~PDFiumPage() { | 95 PDFiumPage::~PDFiumPage() { |
95 DCHECK_EQ(0, loading_count_); | 96 DCHECK_EQ(0, loading_count_); |
96 } | 97 } |
97 | 98 |
98 void PDFiumPage::Unload() { | 99 void PDFiumPage::Unload() { |
99 // Do not unload while in the middle of a load. | 100 // Do not unload while in the middle of a load. |
100 if (loading_count_) | 101 if (loading_count_) |
101 return; | 102 return; |
102 | 103 |
103 if (text_page_) { | 104 if (text_page_) { |
104 FPDFText_ClosePage(text_page_); | 105 FPDFText_ClosePage(text_page_); |
105 text_page_ = NULL; | 106 text_page_ = nullptr; |
106 } | 107 } |
107 | 108 |
108 if (page_) { | 109 if (page_) { |
109 if (engine_->form()) { | 110 if (engine_->form()) { |
110 FORM_OnBeforeClosePage(page_, engine_->form()); | 111 FORM_OnBeforeClosePage(page_, engine_->form()); |
111 } | 112 } |
112 FPDF_ClosePage(page_); | 113 FPDF_ClosePage(page_); |
113 page_ = NULL; | 114 page_ = nullptr; |
114 } | 115 } |
115 } | 116 } |
116 | 117 |
117 FPDF_PAGE PDFiumPage::GetPage() { | 118 FPDF_PAGE PDFiumPage::GetPage() { |
118 ScopedUnsupportedFeature scoped_unsupported_feature(engine_); | 119 ScopedUnsupportedFeature scoped_unsupported_feature(engine_); |
119 if (!available_) | 120 if (!available_) |
120 return NULL; | 121 return nullptr; |
121 if (!page_) { | 122 if (!page_) { |
122 ScopedLoadCounter scoped_load(this); | 123 ScopedLoadCounter scoped_load(this); |
123 page_ = FPDF_LoadPage(engine_->doc(), index_); | 124 page_ = FPDF_LoadPage(engine_->doc(), index_); |
124 if (page_ && engine_->form()) { | 125 if (page_ && engine_->form()) { |
125 FORM_OnAfterLoadPage(page_, engine_->form()); | 126 FORM_OnAfterLoadPage(page_, engine_->form()); |
126 } | 127 } |
127 } | 128 } |
128 return page_; | 129 return page_; |
129 } | 130 } |
130 | 131 |
131 FPDF_PAGE PDFiumPage::GetPrintPage() { | 132 FPDF_PAGE PDFiumPage::GetPrintPage() { |
132 ScopedUnsupportedFeature scoped_unsupported_feature(engine_); | 133 ScopedUnsupportedFeature scoped_unsupported_feature(engine_); |
133 if (!available_) | 134 if (!available_) |
134 return NULL; | 135 return nullptr; |
135 if (!page_) { | 136 if (!page_) { |
136 ScopedLoadCounter scoped_load(this); | 137 ScopedLoadCounter scoped_load(this); |
137 page_ = FPDF_LoadPage(engine_->doc(), index_); | 138 page_ = FPDF_LoadPage(engine_->doc(), index_); |
138 } | 139 } |
139 return page_; | 140 return page_; |
140 } | 141 } |
141 | 142 |
142 void PDFiumPage::ClosePrintPage() { | 143 void PDFiumPage::ClosePrintPage() { |
143 // Do not close |page_| while in the middle of a load. | 144 // Do not close |page_| while in the middle of a load. |
144 if (loading_count_) | 145 if (loading_count_) |
145 return; | 146 return; |
146 | 147 |
147 if (page_) { | 148 if (page_) { |
148 FPDF_ClosePage(page_); | 149 FPDF_ClosePage(page_); |
149 page_ = NULL; | 150 page_ = nullptr; |
150 } | 151 } |
151 } | 152 } |
152 | 153 |
153 FPDF_TEXTPAGE PDFiumPage::GetTextPage() { | 154 FPDF_TEXTPAGE PDFiumPage::GetTextPage() { |
154 if (!available_) | 155 if (!available_) |
155 return NULL; | 156 return nullptr; |
156 if (!text_page_) { | 157 if (!text_page_) { |
157 ScopedLoadCounter scoped_load(this); | 158 ScopedLoadCounter scoped_load(this); |
158 text_page_ = FPDFText_LoadPage(GetPage()); | 159 text_page_ = FPDFText_LoadPage(GetPage()); |
159 } | 160 } |
160 return text_page_; | 161 return text_page_; |
161 } | 162 } |
162 | 163 |
163 void PDFiumPage::GetTextRunInfo(int start_char_index, | 164 void PDFiumPage::GetTextRunInfo(int start_char_index, |
164 uint32_t* out_len, | 165 uint32_t* out_len, |
165 double* out_font_size, | 166 double* out_font_size, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 FPDF_DEST dest = FPDFAction_GetDest(engine_->doc(), action); | 313 FPDF_DEST dest = FPDFAction_GetDest(engine_->doc(), action); |
313 if (dest) | 314 if (dest) |
314 return GetDestinationTarget(dest, target); | 315 return GetDestinationTarget(dest, target); |
315 // TODO(gene): We don't fully support all types of the in-document | 316 // TODO(gene): We don't fully support all types of the in-document |
316 // links. Need to implement that. There is a bug to track that: | 317 // links. Need to implement that. There is a bug to track that: |
317 // http://code.google.com/p/chromium/issues/detail?id=55776 | 318 // http://code.google.com/p/chromium/issues/detail?id=55776 |
318 } break; | 319 } break; |
319 case PDFACTION_URI: { | 320 case PDFACTION_URI: { |
320 if (target) { | 321 if (target) { |
321 size_t buffer_size = | 322 size_t buffer_size = |
322 FPDFAction_GetURIPath(engine_->doc(), action, NULL, 0); | 323 FPDFAction_GetURIPath(engine_->doc(), action, nullptr, 0); |
323 if (buffer_size > 0) { | 324 if (buffer_size > 0) { |
324 PDFiumAPIStringBufferAdapter<std::string> api_string_adapter( | 325 PDFiumAPIStringBufferAdapter<std::string> api_string_adapter( |
325 &target->url, buffer_size, true); | 326 &target->url, buffer_size, true); |
326 void* data = api_string_adapter.GetData(); | 327 void* data = api_string_adapter.GetData(); |
327 size_t bytes_written = FPDFAction_GetURIPath( | 328 size_t bytes_written = FPDFAction_GetURIPath( |
328 engine_->doc(), action, data, buffer_size); | 329 engine_->doc(), action, data, buffer_size); |
329 api_string_adapter.Close(bytes_written); | 330 api_string_adapter.Close(bytes_written); |
330 } | 331 } |
331 } | 332 } |
332 return WEBLINK_AREA; | 333 return WEBLINK_AREA; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 397 |
397 void PDFiumPage::CalculateLinks() { | 398 void PDFiumPage::CalculateLinks() { |
398 if (calculated_links_) | 399 if (calculated_links_) |
399 return; | 400 return; |
400 | 401 |
401 calculated_links_ = true; | 402 calculated_links_ = true; |
402 FPDF_PAGELINK links = FPDFLink_LoadWebLinks(GetTextPage()); | 403 FPDF_PAGELINK links = FPDFLink_LoadWebLinks(GetTextPage()); |
403 int count = FPDFLink_CountWebLinks(links); | 404 int count = FPDFLink_CountWebLinks(links); |
404 for (int i = 0; i < count; ++i) { | 405 for (int i = 0; i < count; ++i) { |
405 base::string16 url; | 406 base::string16 url; |
406 int url_length = FPDFLink_GetURL(links, i, NULL, 0); | 407 int url_length = FPDFLink_GetURL(links, i, nullptr, 0); |
407 if (url_length > 0) { | 408 if (url_length > 0) { |
408 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter( | 409 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter( |
409 &url, url_length, true); | 410 &url, url_length, true); |
410 unsigned short* data = | 411 unsigned short* data = |
411 reinterpret_cast<unsigned short*>(api_string_adapter.GetData()); | 412 reinterpret_cast<unsigned short*>(api_string_adapter.GetData()); |
412 int actual_length = FPDFLink_GetURL(links, i, data, url_length); | 413 int actual_length = FPDFLink_GetURL(links, i, data, url_length); |
413 api_string_adapter.Close(actual_length); | 414 api_string_adapter.Close(actual_length); |
414 } | 415 } |
415 Link link; | 416 Link link; |
416 link.url = base::UTF16ToUTF8(url); | 417 link.url = base::UTF16ToUTF8(url); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 491 |
491 PDFiumPage::ScopedLoadCounter::ScopedLoadCounter(PDFiumPage* page) | 492 PDFiumPage::ScopedLoadCounter::ScopedLoadCounter(PDFiumPage* page) |
492 : page_(page) { | 493 : page_(page) { |
493 page_->loading_count_++; | 494 page_->loading_count_++; |
494 } | 495 } |
495 | 496 |
496 PDFiumPage::ScopedLoadCounter::~ScopedLoadCounter() { | 497 PDFiumPage::ScopedLoadCounter::~ScopedLoadCounter() { |
497 page_->loading_count_--; | 498 page_->loading_count_--; |
498 } | 499 } |
499 | 500 |
500 PDFiumPage::Link::Link() { | 501 PDFiumPage::Link::Link() = default; |
501 } | |
502 | 502 |
503 PDFiumPage::Link::~Link() { | 503 PDFiumPage::Link::Link(const Link& that) = default; |
504 } | 504 |
| 505 PDFiumPage::Link::~Link() = default; |
505 | 506 |
506 } // namespace chrome_pdf | 507 } // namespace chrome_pdf |
OLD | NEW |