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/instance.h" | 5 #include "pdf/instance.h" |
6 | 6 |
7 #include <algorithm> // for min() | 7 #include <algorithm> // for min() |
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 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 } | 1379 } |
1380 | 1380 |
1381 void Instance::OnPrint(int32_t) { | 1381 void Instance::OnPrint(int32_t) { |
1382 pp::PDF::Print(this); | 1382 pp::PDF::Print(this); |
1383 } | 1383 } |
1384 | 1384 |
1385 void Instance::SaveAs() { | 1385 void Instance::SaveAs() { |
1386 pp::PDF::SaveAs(this); | 1386 pp::PDF::SaveAs(this); |
1387 } | 1387 } |
1388 | 1388 |
| 1389 void Instance::SetPrintPresetOptionsFromDocument() { |
| 1390 PP_PrintPresetOptions_Dev print_options; |
| 1391 print_options.is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
| 1392 print_options.copies = engine_->GetCopiesToPrint(); |
| 1393 |
| 1394 pp::Printing_Dev::SetPrintPresetOptionsFromDocument(print_options); |
| 1395 } |
| 1396 |
1389 void Instance::SubmitForm(const std::string& url, | 1397 void Instance::SubmitForm(const std::string& url, |
1390 const void* data, | 1398 const void* data, |
1391 int length) { | 1399 int length) { |
1392 pp::URLRequestInfo request(this); | 1400 pp::URLRequestInfo request(this); |
1393 request.SetURL(url); | 1401 request.SetURL(url); |
1394 request.SetMethod("POST"); | 1402 request.SetMethod("POST"); |
1395 request.AppendDataToBody(reinterpret_cast<const char*>(data), length); | 1403 request.AppendDataToBody(reinterpret_cast<const char*>(data), length); |
1396 | 1404 |
1397 pp::CompletionCallback callback = | 1405 pp::CompletionCallback callback = |
1398 form_factory_.NewCallback(&Instance::FormDidOpen); | 1406 form_factory_.NewCallback(&Instance::FormDidOpen); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 | 1515 |
1508 if (on_load_callback_.is_string()) | 1516 if (on_load_callback_.is_string()) |
1509 ExecuteScript(on_load_callback_); | 1517 ExecuteScript(on_load_callback_); |
1510 // Note: If we are in print preview mode on_load_callback_ might call | 1518 // Note: If we are in print preview mode on_load_callback_ might call |
1511 // ScrollTo{X|Y}() and we don't want to scroll again and override it. | 1519 // ScrollTo{X|Y}() and we don't want to scroll again and override it. |
1512 // #page=N is not supported in Print Preview. | 1520 // #page=N is not supported in Print Preview. |
1513 if (!IsPrintPreview()) { | 1521 if (!IsPrintPreview()) { |
1514 int initial_page = GetInitialPage(url_); | 1522 int initial_page = GetInitialPage(url_); |
1515 if (initial_page >= 0) | 1523 if (initial_page >= 0) |
1516 ScrollToPage(initial_page); | 1524 ScrollToPage(initial_page); |
| 1525 } else { |
| 1526 // Set print preset options from pdf document. |
| 1527 SetPrintPresetOptionsFromDocument(); |
1517 } | 1528 } |
1518 | 1529 |
1519 if (!full_) | 1530 if (!full_) |
1520 return; | 1531 return; |
1521 if (!pp::PDF::IsAvailable()) | 1532 if (!pp::PDF::IsAvailable()) |
1522 return; | 1533 return; |
1523 | 1534 |
1524 int content_restrictions = | 1535 int content_restrictions = |
1525 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; | 1536 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; |
1526 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | 1537 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2726 return instance_->HasScriptableMethod(name, exception); | 2737 return instance_->HasScriptableMethod(name, exception); |
2727 } | 2738 } |
2728 | 2739 |
2729 pp::Var PDFScriptableObject::Call(const pp::Var& method, | 2740 pp::Var PDFScriptableObject::Call(const pp::Var& method, |
2730 const std::vector<pp::Var>& args, | 2741 const std::vector<pp::Var>& args, |
2731 pp::Var* exception) { | 2742 pp::Var* exception) { |
2732 return instance_->CallScriptableMethod(method, args, exception); | 2743 return instance_->CallScriptableMethod(method, args, exception); |
2733 } | 2744 } |
2734 | 2745 |
2735 } // namespace chrome_pdf | 2746 } // namespace chrome_pdf |
OLD | NEW |