Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 2857743005: Partial revert of r469453. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pdf/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> // for min/max() 10 #include <algorithm> // for min/max()
11 #define _USE_MATH_DEFINES // for M_PI 11 #define _USE_MATH_DEFINES // for M_PI
12 #include <math.h> 12 #include <math.h>
13 #include <cmath> // for log() and pow() 13 #include <cmath> // for log() and pow()
14 #include <list> 14 #include <list>
15 15
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "chrome/common/content_restriction.h" 23 #include "chrome/common/content_restriction.h"
24 #include "chrome/common/url_constants.h"
25 #include "net/base/escape.h" 24 #include "net/base/escape.h"
26 #include "pdf/pdf.h" 25 #include "pdf/pdf.h"
27 #include "ppapi/c/dev/ppb_cursor_control_dev.h" 26 #include "ppapi/c/dev/ppb_cursor_control_dev.h"
28 #include "ppapi/c/pp_errors.h" 27 #include "ppapi/c/pp_errors.h"
29 #include "ppapi/c/pp_rect.h" 28 #include "ppapi/c/pp_rect.h"
30 #include "ppapi/c/private/ppb_instance_private.h" 29 #include "ppapi/c/private/ppb_instance_private.h"
31 #include "ppapi/c/private/ppp_pdf.h" 30 #include "ppapi/c/private/ppp_pdf.h"
32 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" 31 #include "ppapi/c/trusted/ppb_url_loader_trusted.h"
33 #include "ppapi/cpp/core.h" 32 #include "ppapi/cpp/core.h"
34 #include "ppapi/cpp/dev/memory_dev.h" 33 #include "ppapi/cpp/dev/memory_dev.h"
35 #include "ppapi/cpp/dev/text_input_dev.h" 34 #include "ppapi/cpp/dev/text_input_dev.h"
36 #include "ppapi/cpp/dev/url_util_dev.h" 35 #include "ppapi/cpp/dev/url_util_dev.h"
37 #include "ppapi/cpp/module.h" 36 #include "ppapi/cpp/module.h"
38 #include "ppapi/cpp/point.h" 37 #include "ppapi/cpp/point.h"
39 #include "ppapi/cpp/private/pdf.h" 38 #include "ppapi/cpp/private/pdf.h"
40 #include "ppapi/cpp/private/var_private.h" 39 #include "ppapi/cpp/private/var_private.h"
41 #include "ppapi/cpp/rect.h" 40 #include "ppapi/cpp/rect.h"
42 #include "ppapi/cpp/resource.h" 41 #include "ppapi/cpp/resource.h"
43 #include "ppapi/cpp/url_request_info.h" 42 #include "ppapi/cpp/url_request_info.h"
44 #include "ppapi/cpp/var_array.h" 43 #include "ppapi/cpp/var_array.h"
45 #include "ppapi/cpp/var_dictionary.h" 44 #include "ppapi/cpp/var_dictionary.h"
46 #include "ui/events/keycodes/keyboard_codes.h" 45 #include "ui/events/keycodes/keyboard_codes.h"
47 46
48 namespace chrome_pdf { 47 namespace chrome_pdf {
49 48
50 namespace { 49 namespace {
51 50
51 const char kChromePrint[] = "chrome://print/";
52 const char kChromeExtension[] = 52 const char kChromeExtension[] =
53 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai"; 53 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai";
54 54
55 // Constants used in handling postMessage() messages. 55 // Constants used in handling postMessage() messages.
56 const char kType[] = "type"; 56 const char kType[] = "type";
57 // Viewport message arguments. (Page -> Plugin). 57 // Viewport message arguments. (Page -> Plugin).
58 const char kJSViewportType[] = "viewport"; 58 const char kJSViewportType[] = "viewport";
59 const char kJSXOffset[] = "xOffset"; 59 const char kJSXOffset[] = "xOffset";
60 const char kJSYOffset[] = "yOffset"; 60 const char kJSYOffset[] = "yOffset";
61 const char kJSZoom[] = "zoom"; 61 const char kJSZoom[] = "zoom";
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 214 }
215 215
216 const PPP_Pdf ppp_private = { 216 const PPP_Pdf ppp_private = {
217 &GetLinkAtPosition, &Transform, &GetPrintPresetOptionsFromDocument, 217 &GetLinkAtPosition, &Transform, &GetPrintPresetOptionsFromDocument,
218 &EnableAccessibility, 218 &EnableAccessibility,
219 }; 219 };
220 220
221 int ExtractPrintPreviewPageIndex(base::StringPiece src_url) { 221 int ExtractPrintPreviewPageIndex(base::StringPiece src_url) {
222 // Sample |src_url| format: chrome://print/id/page_index/print.pdf 222 // Sample |src_url| format: chrome://print/id/page_index/print.pdf
223 std::vector<base::StringPiece> url_substr = 223 std::vector<base::StringPiece> url_substr =
224 base::SplitStringPiece(src_url.substr(strlen(chrome::kChromeUIPrintURL)), 224 base::SplitStringPiece(src_url.substr(strlen(kChromePrint)), "/",
225 "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 225 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
226 if (url_substr.size() != 3) 226 if (url_substr.size() != 3)
227 return -1; 227 return -1;
228 228
229 if (url_substr[2] != "print.pdf") 229 if (url_substr[2] != "print.pdf")
230 return -1; 230 return -1;
231 231
232 int page_index = 0; 232 int page_index = 0;
233 if (!base::StringToInt(url_substr[1], &page_index)) 233 if (!base::StringToInt(url_substr[1], &page_index))
234 return -1; 234 return -1;
235 return page_index; 235 return page_index;
236 } 236 }
237 237
238 bool IsPrintPreviewUrl(base::StringPiece url) { 238 bool IsPrintPreviewUrl(base::StringPiece url) {
239 return url.starts_with(chrome::kChromeUIPrintURL); 239 return url.starts_with(kChromePrint);
240 } 240 }
241 241
242 void ScalePoint(float scale, pp::Point* point) { 242 void ScalePoint(float scale, pp::Point* point) {
243 point->set_x(static_cast<int>(point->x() * scale)); 243 point->set_x(static_cast<int>(point->x() * scale));
244 point->set_y(static_cast<int>(point->y() * scale)); 244 point->set_y(static_cast<int>(point->y() * scale));
245 } 245 }
246 246
247 void ScaleRect(float scale, pp::Rect* rect) { 247 void ScaleRect(float scale, pp::Rect* rect) {
248 int left = static_cast<int>(floorf(rect->x() * scale)); 248 int left = static_cast<int>(floorf(rect->x() * scale));
249 int top = static_cast<int>(floorf(rect->y() * scale)); 249 int top = static_cast<int>(floorf(rect->y() * scale));
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 const pp::FloatPoint& scroll_offset) { 1610 const pp::FloatPoint& scroll_offset) {
1611 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1611 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1612 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1612 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1613 float min_y = -top_toolbar_height_; 1613 float min_y = -top_toolbar_height_;
1614 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1614 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1615 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); 1615 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1616 return pp::FloatPoint(x, y); 1616 return pp::FloatPoint(x, y);
1617 } 1617 }
1618 1618
1619 } // namespace chrome_pdf 1619 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698