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 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 } | 1383 } |
1384 | 1384 |
1385 void Instance::OnPrint(int32_t) { | 1385 void Instance::OnPrint(int32_t) { |
1386 pp::PDF::Print(this); | 1386 pp::PDF::Print(this); |
1387 } | 1387 } |
1388 | 1388 |
1389 void Instance::SaveAs() { | 1389 void Instance::SaveAs() { |
1390 pp::PDF::SaveAs(this); | 1390 pp::PDF::SaveAs(this); |
1391 } | 1391 } |
1392 | 1392 |
| 1393 void Instance::SetPrintPresetOptionsFromDocument() { |
| 1394 PP_PrintPresetOptions_Dev print_options; |
| 1395 print_options.is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
| 1396 print_options.copies = engine_->GetCopiesToPrint(); |
| 1397 |
| 1398 pp::Printing_Dev::SetPrintPresetOptionsFromDocument(print_options); |
| 1399 } |
| 1400 |
1393 void Instance::SubmitForm(const std::string& url, | 1401 void Instance::SubmitForm(const std::string& url, |
1394 const void* data, | 1402 const void* data, |
1395 int length) { | 1403 int length) { |
1396 pp::URLRequestInfo request(this); | 1404 pp::URLRequestInfo request(this); |
1397 request.SetURL(url); | 1405 request.SetURL(url); |
1398 request.SetMethod("POST"); | 1406 request.SetMethod("POST"); |
1399 request.AppendDataToBody(reinterpret_cast<const char*>(data), length); | 1407 request.AppendDataToBody(reinterpret_cast<const char*>(data), length); |
1400 | 1408 |
1401 pp::CompletionCallback callback = | 1409 pp::CompletionCallback callback = |
1402 form_factory_.NewCallback(&Instance::FormDidOpen); | 1410 form_factory_.NewCallback(&Instance::FormDidOpen); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 | 1519 |
1512 if (on_load_callback_.is_string()) | 1520 if (on_load_callback_.is_string()) |
1513 ExecuteScript(on_load_callback_); | 1521 ExecuteScript(on_load_callback_); |
1514 // Note: If we are in print preview mode on_load_callback_ might call | 1522 // Note: If we are in print preview mode on_load_callback_ might call |
1515 // ScrollTo{X|Y}() and we don't want to scroll again and override it. | 1523 // ScrollTo{X|Y}() and we don't want to scroll again and override it. |
1516 // #page=N is not supported in Print Preview. | 1524 // #page=N is not supported in Print Preview. |
1517 if (!IsPrintPreview()) { | 1525 if (!IsPrintPreview()) { |
1518 int initial_page = GetInitialPage(url_); | 1526 int initial_page = GetInitialPage(url_); |
1519 if (initial_page >= 0) | 1527 if (initial_page >= 0) |
1520 ScrollToPage(initial_page); | 1528 ScrollToPage(initial_page); |
| 1529 } else { |
| 1530 // Set print preset options from pdf document. |
| 1531 SetPrintPresetOptionsFromDocument(); |
1521 } | 1532 } |
1522 | 1533 |
1523 if (!full_) | 1534 if (!full_) |
1524 return; | 1535 return; |
1525 if (!pp::PDF::IsAvailable()) | 1536 if (!pp::PDF::IsAvailable()) |
1526 return; | 1537 return; |
1527 | 1538 |
1528 int content_restrictions = | 1539 int content_restrictions = |
1529 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; | 1540 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; |
1530 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | 1541 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2739 return instance_->HasScriptableMethod(name, exception); | 2750 return instance_->HasScriptableMethod(name, exception); |
2740 } | 2751 } |
2741 | 2752 |
2742 pp::Var PDFScriptableObject::Call(const pp::Var& method, | 2753 pp::Var PDFScriptableObject::Call(const pp::Var& method, |
2743 const std::vector<pp::Var>& args, | 2754 const std::vector<pp::Var>& args, |
2744 pp::Var* exception) { | 2755 pp::Var* exception) { |
2745 return instance_->CallScriptableMethod(method, args, exception); | 2756 return instance_->CallScriptableMethod(method, args, exception); |
2746 } | 2757 } |
2747 | 2758 |
2748 } // namespace chrome_pdf | 2759 } // namespace chrome_pdf |
OLD | NEW |