| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 const char kJSPrintPreviewGrayscale[] = "grayscale"; | 100 const char kJSPrintPreviewGrayscale[] = "grayscale"; |
| 101 const char kJSPrintPreviewPageCount[] = "pageCount"; | 101 const char kJSPrintPreviewPageCount[] = "pageCount"; |
| 102 // Load preview page (Page -> Plugin) | 102 // Load preview page (Page -> Plugin) |
| 103 const char kJSLoadPreviewPageType[] = "loadPreviewPage"; | 103 const char kJSLoadPreviewPageType[] = "loadPreviewPage"; |
| 104 const char kJSPreviewPageUrl[] = "url"; | 104 const char kJSPreviewPageUrl[] = "url"; |
| 105 const char kJSPreviewPageIndex[] = "index"; | 105 const char kJSPreviewPageIndex[] = "index"; |
| 106 // Set scroll position (Plugin -> Page) | 106 // Set scroll position (Plugin -> Page) |
| 107 const char kJSSetScrollPositionType[] = "setScrollPosition"; | 107 const char kJSSetScrollPositionType[] = "setScrollPosition"; |
| 108 const char kJSPositionX[] = "x"; | 108 const char kJSPositionX[] = "x"; |
| 109 const char kJSPositionY[] = "y"; | 109 const char kJSPositionY[] = "y"; |
| 110 // Set translated strings (Plugin -> Page) | |
| 111 const char kJSSetTranslatedStringsType[] = "setTranslatedStrings"; | |
| 112 const char kJSGetPasswordString[] = "getPasswordString"; | |
| 113 const char kJSLoadingString[] = "loadingString"; | |
| 114 const char kJSLoadFailedString[] = "loadFailedString"; | |
| 115 // Request accessibility JSON data (Page -> Plugin) | 110 // Request accessibility JSON data (Page -> Plugin) |
| 116 const char kJSGetAccessibilityJSONType[] = "getAccessibilityJSON"; | 111 const char kJSGetAccessibilityJSONType[] = "getAccessibilityJSON"; |
| 117 const char kJSAccessibilityPageNumber[] = "page"; | 112 const char kJSAccessibilityPageNumber[] = "page"; |
| 118 // Reply with accessibility JSON data (Plugin -> Page) | 113 // Reply with accessibility JSON data (Plugin -> Page) |
| 119 const char kJSGetAccessibilityJSONReplyType[] = "getAccessibilityJSONReply"; | 114 const char kJSGetAccessibilityJSONReplyType[] = "getAccessibilityJSONReply"; |
| 120 const char kJSAccessibilityJSON[] = "json"; | 115 const char kJSAccessibilityJSON[] = "json"; |
| 121 // Cancel the stream URL request (Plugin -> Page) | 116 // Cancel the stream URL request (Plugin -> Page) |
| 122 const char kJSCancelStreamUrlType[] = "cancelStreamUrl"; | 117 const char kJSCancelStreamUrlType[] = "cancelStreamUrl"; |
| 123 // Navigate to the given URL (Plugin -> Page) | 118 // Navigate to the given URL (Plugin -> Page) |
| 124 const char kJSNavigateType[] = "navigate"; | 119 const char kJSNavigateType[] = "navigate"; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 if (strcmp(argn[i], "full-frame") == 0) { | 320 if (strcmp(argn[i], "full-frame") == 0) { |
| 326 full_ = true; | 321 full_ = true; |
| 327 break; | 322 break; |
| 328 } | 323 } |
| 329 } | 324 } |
| 330 | 325 |
| 331 // Only allow the plugin to handle find requests if it is full frame. | 326 // Only allow the plugin to handle find requests if it is full frame. |
| 332 if (full_) | 327 if (full_) |
| 333 SetPluginToHandleFindRequests(); | 328 SetPluginToHandleFindRequests(); |
| 334 | 329 |
| 335 // Send translated strings to the extension where they will be displayed. | |
| 336 // TODO(raymes): It would be better to get these in the extension directly | |
| 337 // through an API but no such API currently exists. | |
| 338 pp::VarDictionary translated_strings; | |
| 339 translated_strings.Set(kType, kJSSetTranslatedStringsType); | |
| 340 translated_strings.Set(kJSGetPasswordString, | |
| 341 GetLocalizedString(PP_RESOURCESTRING_PDFGETPASSWORD)); | |
| 342 translated_strings.Set(kJSLoadingString, | |
| 343 GetLocalizedString(PP_RESOURCESTRING_PDFLOADING)); | |
| 344 translated_strings.Set(kJSLoadFailedString, | |
| 345 GetLocalizedString(PP_RESOURCESTRING_PDFLOAD_FAILED)); | |
| 346 PostMessage(translated_strings); | |
| 347 | |
| 348 text_input_.reset(new pp::TextInput_Dev(this)); | 330 text_input_.reset(new pp::TextInput_Dev(this)); |
| 349 | 331 |
| 350 const char* stream_url = nullptr; | 332 const char* stream_url = nullptr; |
| 351 const char* original_url = nullptr; | 333 const char* original_url = nullptr; |
| 352 const char* headers = nullptr; | 334 const char* headers = nullptr; |
| 353 bool is_material = false; | 335 bool is_material = false; |
| 354 for (uint32_t i = 0; i < argc; ++i) { | 336 for (uint32_t i = 0; i < argc; ++i) { |
| 355 if (strcmp(argn[i], "src") == 0) | 337 if (strcmp(argn[i], "src") == 0) |
| 356 original_url = argv[i]; | 338 original_url = argv[i]; |
| 357 else if (strcmp(argn[i], "stream-url") == 0) | 339 else if (strcmp(argn[i], "stream-url") == 0) |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 trusted_interface->GrantUniversalAccess(loader.pp_resource()); | 1340 trusted_interface->GrantUniversalAccess(loader.pp_resource()); |
| 1359 return loader; | 1341 return loader; |
| 1360 } | 1342 } |
| 1361 | 1343 |
| 1362 void OutOfProcessInstance::SetZoom(double scale) { | 1344 void OutOfProcessInstance::SetZoom(double scale) { |
| 1363 double old_zoom = zoom_; | 1345 double old_zoom = zoom_; |
| 1364 zoom_ = scale; | 1346 zoom_ = scale; |
| 1365 OnGeometryChanged(old_zoom, device_scale_); | 1347 OnGeometryChanged(old_zoom, device_scale_); |
| 1366 } | 1348 } |
| 1367 | 1349 |
| 1368 std::string OutOfProcessInstance::GetLocalizedString(PP_ResourceString id) { | |
| 1369 pp::Var rv(pp::PDF::GetLocalizedString(this, id)); | |
| 1370 if (!rv.is_string()) | |
| 1371 return std::string(); | |
| 1372 | |
| 1373 return rv.AsString(); | |
| 1374 } | |
| 1375 | |
| 1376 void OutOfProcessInstance::AppendBlankPrintPreviewPages() { | 1350 void OutOfProcessInstance::AppendBlankPrintPreviewPages() { |
| 1377 if (print_preview_page_count_ == 0) | 1351 if (print_preview_page_count_ == 0) |
| 1378 return; | 1352 return; |
| 1379 engine_->AppendBlankPages(print_preview_page_count_); | 1353 engine_->AppendBlankPages(print_preview_page_count_); |
| 1380 if (!preview_pages_info_.empty()) | 1354 if (!preview_pages_info_.empty()) |
| 1381 LoadAvailablePreviewPage(); | 1355 LoadAvailablePreviewPage(); |
| 1382 } | 1356 } |
| 1383 | 1357 |
| 1384 bool OutOfProcessInstance::IsPrintPreview() { | 1358 bool OutOfProcessInstance::IsPrintPreview() { |
| 1385 return IsPrintPreviewUrl(url_); | 1359 return IsPrintPreviewUrl(url_); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 const pp::FloatPoint& scroll_offset) { | 1412 const pp::FloatPoint& scroll_offset) { |
| 1439 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1413 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
| 1440 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1414 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
| 1441 float min_y = -top_toolbar_height_; | 1415 float min_y = -top_toolbar_height_; |
| 1442 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1416 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
| 1443 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); | 1417 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
| 1444 return pp::FloatPoint(x, y); | 1418 return pp::FloatPoint(x, y); |
| 1445 } | 1419 } |
| 1446 | 1420 |
| 1447 } // namespace chrome_pdf | 1421 } // namespace chrome_pdf |
| OLD | NEW |