Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/out_of_process_instance.h" | 5 #include "pdf/out_of_process_instance.h" |
| 6 | 6 |
| 7 #include <algorithm> // for min/max() | 7 #include <algorithm> // for min/max() |
| 8 #define _USE_MATH_DEFINES // for M_PI | 8 #define _USE_MATH_DEFINES // for M_PI |
| 9 #include <cmath> // for log() and pow() | 9 #include <cmath> // for log() and pow() |
| 10 #include <math.h> | 10 #include <math.h> |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 translated_strings.Set(kJSGetPasswordString, | 336 translated_strings.Set(kJSGetPasswordString, |
| 337 GetLocalizedString(PP_RESOURCESTRING_PDFGETPASSWORD)); | 337 GetLocalizedString(PP_RESOURCESTRING_PDFGETPASSWORD)); |
| 338 translated_strings.Set(kJSLoadingString, | 338 translated_strings.Set(kJSLoadingString, |
| 339 GetLocalizedString(PP_RESOURCESTRING_PDFLOADING)); | 339 GetLocalizedString(PP_RESOURCESTRING_PDFLOADING)); |
| 340 translated_strings.Set(kJSLoadFailedString, | 340 translated_strings.Set(kJSLoadFailedString, |
| 341 GetLocalizedString(PP_RESOURCESTRING_PDFLOAD_FAILED)); | 341 GetLocalizedString(PP_RESOURCESTRING_PDFLOAD_FAILED)); |
| 342 PostMessage(translated_strings); | 342 PostMessage(translated_strings); |
| 343 | 343 |
| 344 text_input_.reset(new pp::TextInput_Dev(this)); | 344 text_input_.reset(new pp::TextInput_Dev(this)); |
| 345 | 345 |
| 346 const char* stream_url = NULL; | 346 const char* stream_url = nullptr; |
| 347 const char* original_url = NULL; | 347 const char* original_url = nullptr; |
| 348 const char* headers = NULL; | 348 const char* headers = nullptr; |
| 349 bool is_material = false; | 349 bool is_material = false; |
| 350 for (uint32_t i = 0; i < argc; ++i) { | 350 for (uint32_t i = 0; i < argc; ++i) { |
| 351 if (strcmp(argn[i], "src") == 0) | 351 if (strcmp(argn[i], "src") == 0) |
| 352 original_url = argv[i]; | 352 original_url = argv[i]; |
| 353 else if (strcmp(argn[i], "stream-url") == 0) | 353 else if (strcmp(argn[i], "stream-url") == 0) |
| 354 stream_url = argv[i]; | 354 stream_url = argv[i]; |
| 355 else if (strcmp(argn[i], "headers") == 0) | 355 else if (strcmp(argn[i], "headers") == 0) |
| 356 headers = argv[i]; | 356 headers = argv[i]; |
| 357 else if (strcmp(argn[i], "is-material") == 0) | 357 else if (strcmp(argn[i], "is-material") == 0) |
| 358 is_material = true; | 358 is_material = true; |
| 359 } | 359 } |
| 360 | 360 |
| 361 if (is_material) | 361 if (is_material) |
| 362 background_color_ = kBackgroundColorMaterial; | 362 background_color_ = kBackgroundColorMaterial; |
| 363 else | 363 else |
| 364 background_color_ = kBackgroundColor; | 364 background_color_ = kBackgroundColor; |
| 365 | 365 |
| 366 // TODO(raymes): This is a hack to ensure that if no headers are passed in | |
| 367 // then we get the right MIME type. When the in process plugin is removed we | |
| 368 // can fix the document loader properly and remove this hack. | |
| 369 if (!headers || strcmp(headers, "") == 0) | |
| 370 headers = "content-type: application/pdf"; | |
|
raymes
2015/05/28 02:44:42
Do we need to preserve this in document_loader?
Lei Zhang
2015/05/28 05:56:33
See the code around document_loader.cc line 72.
| |
| 371 | |
| 372 if (!original_url) | 366 if (!original_url) |
| 373 return false; | 367 return false; |
| 374 | 368 |
| 375 if (!stream_url) | 369 if (!stream_url) |
| 376 stream_url = original_url; | 370 stream_url = original_url; |
| 377 | 371 |
| 378 // If we're in print preview mode we don't need to load the document yet. | 372 // If we're in print preview mode we don't need to load the document yet. |
| 379 // A |kJSResetPrintPreviewModeType| message will be sent to the plugin letting | 373 // A |kJSResetPrintPreviewModeType| message will be sent to the plugin letting |
| 380 // it know the url to load. By not loading here we avoid loading the same | 374 // it know the url to load. By not loading here we avoid loading the same |
| 381 // document twice. | 375 // document twice. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() && | 431 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() && |
| 438 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) { | 432 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) { |
| 439 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString(); | 433 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString(); |
| 440 preview_pages_info_ = std::queue<PreviewPageInfo>(); | 434 preview_pages_info_ = std::queue<PreviewPageInfo>(); |
| 441 preview_document_load_state_ = LOAD_STATE_COMPLETE; | 435 preview_document_load_state_ = LOAD_STATE_COMPLETE; |
| 442 document_load_state_ = LOAD_STATE_LOADING; | 436 document_load_state_ = LOAD_STATE_LOADING; |
| 443 LoadUrl(url_); | 437 LoadUrl(url_); |
| 444 preview_engine_.reset(); | 438 preview_engine_.reset(); |
| 445 engine_.reset(PDFEngine::Create(this)); | 439 engine_.reset(PDFEngine::Create(this)); |
| 446 engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool()); | 440 engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool()); |
| 447 engine_->New(url_.c_str()); | 441 engine_->New(url_.c_str(), nullptr /* empty header */); |
| 448 | 442 |
| 449 print_preview_page_count_ = | 443 print_preview_page_count_ = |
| 450 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0); | 444 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0); |
| 451 | 445 |
| 452 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); | 446 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); |
| 453 } else if (type == kJSLoadPreviewPageType && | 447 } else if (type == kJSLoadPreviewPageType && |
| 454 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() && | 448 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() && |
| 455 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) { | 449 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) { |
| 456 ProcessPreviewPageInfo(dict.Get(pp::Var(kJSPreviewPageUrl)).AsString(), | 450 ProcessPreviewPageInfo(dict.Get(pp::Var(kJSPreviewPageUrl)).AsString(), |
| 457 dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt()); | 451 dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt()); |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 | 902 |
| 909 const PPB_CursorControl_Dev* cursor_interface = | 903 const PPB_CursorControl_Dev* cursor_interface = |
| 910 reinterpret_cast<const PPB_CursorControl_Dev*>( | 904 reinterpret_cast<const PPB_CursorControl_Dev*>( |
| 911 pp::Module::Get()->GetBrowserInterface(PPB_CURSOR_CONTROL_DEV_INTERFACE)); | 905 pp::Module::Get()->GetBrowserInterface(PPB_CURSOR_CONTROL_DEV_INTERFACE)); |
| 912 if (!cursor_interface) { | 906 if (!cursor_interface) { |
| 913 NOTREACHED(); | 907 NOTREACHED(); |
| 914 return; | 908 return; |
| 915 } | 909 } |
| 916 | 910 |
| 917 cursor_interface->SetCursor( | 911 cursor_interface->SetCursor( |
| 918 pp_instance(), cursor_, pp::ImageData().pp_resource(), NULL); | 912 pp_instance(), cursor_, pp::ImageData().pp_resource(), nullptr); |
| 919 } | 913 } |
| 920 | 914 |
| 921 void OutOfProcessInstance::UpdateTickMarks( | 915 void OutOfProcessInstance::UpdateTickMarks( |
| 922 const std::vector<pp::Rect>& tickmarks) { | 916 const std::vector<pp::Rect>& tickmarks) { |
| 923 float inverse_scale = 1.0f / device_scale_; | 917 float inverse_scale = 1.0f / device_scale_; |
| 924 std::vector<pp::Rect> scaled_tickmarks = tickmarks; | 918 std::vector<pp::Rect> scaled_tickmarks = tickmarks; |
| 925 for (size_t i = 0; i < scaled_tickmarks.size(); i++) | 919 for (size_t i = 0; i < scaled_tickmarks.size(); i++) |
| 926 ScaleRect(inverse_scale, &scaled_tickmarks[i]); | 920 ScaleRect(inverse_scale, &scaled_tickmarks[i]); |
| 927 tickmarks_ = scaled_tickmarks; | 921 tickmarks_ = scaled_tickmarks; |
| 928 } | 922 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1170 ExtractPrintPreviewPageIndex(preview_pages_info_.front().first); | 1164 ExtractPrintPreviewPageIndex(preview_pages_info_.front().first); |
| 1171 if (src_page_index > 0 && dest_page_index > -1 && preview_engine_.get()) | 1165 if (src_page_index > 0 && dest_page_index > -1 && preview_engine_.get()) |
| 1172 engine_->AppendPage(preview_engine_.get(), dest_page_index); | 1166 engine_->AppendPage(preview_engine_.get(), dest_page_index); |
| 1173 | 1167 |
| 1174 preview_pages_info_.pop(); | 1168 preview_pages_info_.pop(); |
| 1175 // |print_preview_page_count_| is not updated yet. Do not load any | 1169 // |print_preview_page_count_| is not updated yet. Do not load any |
| 1176 // other preview pages till we get this information. | 1170 // other preview pages till we get this information. |
| 1177 if (print_preview_page_count_ == 0) | 1171 if (print_preview_page_count_ == 0) |
| 1178 return; | 1172 return; |
| 1179 | 1173 |
| 1180 if (preview_pages_info_.size()) | 1174 if (!preview_pages_info_.empty()) |
| 1181 LoadAvailablePreviewPage(); | 1175 LoadAvailablePreviewPage(); |
| 1182 } | 1176 } |
| 1183 | 1177 |
| 1184 void OutOfProcessInstance::DocumentLoadFailed() { | 1178 void OutOfProcessInstance::DocumentLoadFailed() { |
| 1185 DCHECK(document_load_state_ == LOAD_STATE_LOADING); | 1179 DCHECK(document_load_state_ == LOAD_STATE_LOADING); |
| 1186 UserMetricsRecordAction("PDF.LoadFailure"); | 1180 UserMetricsRecordAction("PDF.LoadFailure"); |
| 1187 | 1181 |
| 1188 if (did_call_start_loading_) { | 1182 if (did_call_start_loading_) { |
| 1189 pp::PDF::DidStopLoading(this); | 1183 pp::PDF::DidStopLoading(this); |
| 1190 did_call_start_loading_ = false; | 1184 did_call_start_loading_ = false; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1203 void OutOfProcessInstance::PreviewDocumentLoadFailed() { | 1197 void OutOfProcessInstance::PreviewDocumentLoadFailed() { |
| 1204 UserMetricsRecordAction("PDF.PreviewDocumentLoadFailure"); | 1198 UserMetricsRecordAction("PDF.PreviewDocumentLoadFailure"); |
| 1205 if (preview_document_load_state_ != LOAD_STATE_LOADING || | 1199 if (preview_document_load_state_ != LOAD_STATE_LOADING || |
| 1206 preview_pages_info_.empty()) { | 1200 preview_pages_info_.empty()) { |
| 1207 return; | 1201 return; |
| 1208 } | 1202 } |
| 1209 | 1203 |
| 1210 preview_document_load_state_ = LOAD_STATE_FAILED; | 1204 preview_document_load_state_ = LOAD_STATE_FAILED; |
| 1211 preview_pages_info_.pop(); | 1205 preview_pages_info_.pop(); |
| 1212 | 1206 |
| 1213 if (preview_pages_info_.size()) | 1207 if (!preview_pages_info_.empty()) |
| 1214 LoadAvailablePreviewPage(); | 1208 LoadAvailablePreviewPage(); |
| 1215 } | 1209 } |
| 1216 | 1210 |
| 1217 pp::Instance* OutOfProcessInstance::GetPluginInstance() { | 1211 pp::Instance* OutOfProcessInstance::GetPluginInstance() { |
| 1218 return this; | 1212 return this; |
| 1219 } | 1213 } |
| 1220 | 1214 |
| 1221 void OutOfProcessInstance::DocumentHasUnsupportedFeature( | 1215 void OutOfProcessInstance::DocumentHasUnsupportedFeature( |
| 1222 const std::string& feature) { | 1216 const std::string& feature) { |
| 1223 std::string metric("PDF_Unsupported_"); | 1217 std::string metric("PDF_Unsupported_"); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1353 if (!rv.is_string()) | 1347 if (!rv.is_string()) |
| 1354 return std::string(); | 1348 return std::string(); |
| 1355 | 1349 |
| 1356 return rv.AsString(); | 1350 return rv.AsString(); |
| 1357 } | 1351 } |
| 1358 | 1352 |
| 1359 void OutOfProcessInstance::AppendBlankPrintPreviewPages() { | 1353 void OutOfProcessInstance::AppendBlankPrintPreviewPages() { |
| 1360 if (print_preview_page_count_ == 0) | 1354 if (print_preview_page_count_ == 0) |
| 1361 return; | 1355 return; |
| 1362 engine_->AppendBlankPages(print_preview_page_count_); | 1356 engine_->AppendBlankPages(print_preview_page_count_); |
| 1363 if (preview_pages_info_.size() > 0) | 1357 if (!preview_pages_info_.empty()) |
| 1364 LoadAvailablePreviewPage(); | 1358 LoadAvailablePreviewPage(); |
| 1365 } | 1359 } |
| 1366 | 1360 |
| 1367 bool OutOfProcessInstance::IsPrintPreview() { | 1361 bool OutOfProcessInstance::IsPrintPreview() { |
| 1368 return IsPrintPreviewUrl(url_); | 1362 return IsPrintPreviewUrl(url_); |
| 1369 } | 1363 } |
| 1370 | 1364 |
| 1371 uint32 OutOfProcessInstance::GetBackgroundColor() { | 1365 uint32 OutOfProcessInstance::GetBackgroundColor() { |
| 1372 return background_color_; | 1366 return background_color_; |
| 1373 } | 1367 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1386 | 1380 |
| 1387 int src_page_index = ExtractPrintPreviewPageIndex(url); | 1381 int src_page_index = ExtractPrintPreviewPageIndex(url); |
| 1388 if (src_page_index < 1) | 1382 if (src_page_index < 1) |
| 1389 return; | 1383 return; |
| 1390 | 1384 |
| 1391 preview_pages_info_.push(std::make_pair(url, dst_page_index)); | 1385 preview_pages_info_.push(std::make_pair(url, dst_page_index)); |
| 1392 LoadAvailablePreviewPage(); | 1386 LoadAvailablePreviewPage(); |
| 1393 } | 1387 } |
| 1394 | 1388 |
| 1395 void OutOfProcessInstance::LoadAvailablePreviewPage() { | 1389 void OutOfProcessInstance::LoadAvailablePreviewPage() { |
| 1396 if (preview_pages_info_.size() <= 0 || | 1390 if (preview_pages_info_.empty() || |
| 1397 document_load_state_ != LOAD_STATE_COMPLETE) { | 1391 document_load_state_ != LOAD_STATE_COMPLETE) { |
| 1398 return; | 1392 return; |
| 1399 } | 1393 } |
| 1400 | 1394 |
| 1401 std::string url = preview_pages_info_.front().first; | 1395 std::string url = preview_pages_info_.front().first; |
| 1402 int dst_page_index = preview_pages_info_.front().second; | 1396 int dst_page_index = preview_pages_info_.front().second; |
| 1403 int src_page_index = ExtractPrintPreviewPageIndex(url); | 1397 int src_page_index = ExtractPrintPreviewPageIndex(url); |
| 1404 if (src_page_index < 1 || | 1398 if (src_page_index < 1 || |
| 1405 dst_page_index >= print_preview_page_count_ || | 1399 dst_page_index >= print_preview_page_count_ || |
| 1406 preview_document_load_state_ == LOAD_STATE_LOADING) { | 1400 preview_document_load_state_ == LOAD_STATE_LOADING) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1420 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1414 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
| 1421 const pp::FloatPoint& scroll_offset) { | 1415 const pp::FloatPoint& scroll_offset) { |
| 1422 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1416 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
| 1423 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1417 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
| 1424 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1418 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
| 1425 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); | 1419 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
| 1426 return pp::FloatPoint(x, y); | 1420 return pp::FloatPoint(x, y); |
| 1427 } | 1421 } |
| 1428 | 1422 |
| 1429 } // namespace chrome_pdf | 1423 } // namespace chrome_pdf |
| OLD | NEW |