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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 2103043003: Remove legacy PDF JSON interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo after merge Created 4 years, 5 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 | « chrome/test/data/pdf/basic_plugin_test.js ('k') | pdf/pdf_engine.h » ('j') | 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 <cmath> // for log() and pow() 12 #include <cmath> // for log() and pow()
13 #include <math.h> 13 #include <math.h>
14 #include <list> 14 #include <list>
15 15
16 #include "base/json/json_reader.h"
17 #include "base/json/json_writer.h"
18 #include "base/logging.h" 16 #include "base/logging.h"
19 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
21 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
23 #include "base/values.h" 21 #include "base/values.h"
24 #include "chrome/common/content_restriction.h" 22 #include "chrome/common/content_restriction.h"
25 #include "net/base/escape.h" 23 #include "net/base/escape.h"
26 #include "pdf/pdf.h" 24 #include "pdf/pdf.h"
27 #include "ppapi/c/dev/ppb_cursor_control_dev.h" 25 #include "ppapi/c/dev/ppb_cursor_control_dev.h"
(...skipping 16 matching lines...) Expand all
44 #include "ppapi/cpp/var_array.h" 42 #include "ppapi/cpp/var_array.h"
45 #include "ppapi/cpp/var_dictionary.h" 43 #include "ppapi/cpp/var_dictionary.h"
46 #include "ui/events/keycodes/keyboard_codes.h" 44 #include "ui/events/keycodes/keyboard_codes.h"
47 45
48 namespace chrome_pdf { 46 namespace chrome_pdf {
49 47
50 const char kChromePrint[] = "chrome://print/"; 48 const char kChromePrint[] = "chrome://print/";
51 const char kChromeExtension[] = 49 const char kChromeExtension[] =
52 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai"; 50 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai";
53 51
54 // Dictionary Value key names for the document accessibility info
55 const char kAccessibleNumberOfPages[] = "numberOfPages";
56 const char kAccessibleLoaded[] = "loaded";
57 const char kAccessibleCopyable[] = "copyable";
58
59 // Constants used in handling postMessage() messages. 52 // Constants used in handling postMessage() messages.
60 const char kType[] = "type"; 53 const char kType[] = "type";
61 // Viewport message arguments. (Page -> Plugin). 54 // Viewport message arguments. (Page -> Plugin).
62 const char kJSViewportType[] = "viewport"; 55 const char kJSViewportType[] = "viewport";
63 const char kJSXOffset[] = "xOffset"; 56 const char kJSXOffset[] = "xOffset";
64 const char kJSYOffset[] = "yOffset"; 57 const char kJSYOffset[] = "yOffset";
65 const char kJSZoom[] = "zoom"; 58 const char kJSZoom[] = "zoom";
66 // Stop scrolling message (Page -> Plugin) 59 // Stop scrolling message (Page -> Plugin)
67 const char kJSStopScrollingType[] = "stopScrolling"; 60 const char kJSStopScrollingType[] = "stopScrolling";
68 // Document dimension arguments (Plugin -> Page). 61 // Document dimension arguments (Plugin -> Page).
(...skipping 30 matching lines...) Expand all
99 const char kJSPrintPreviewGrayscale[] = "grayscale"; 92 const char kJSPrintPreviewGrayscale[] = "grayscale";
100 const char kJSPrintPreviewPageCount[] = "pageCount"; 93 const char kJSPrintPreviewPageCount[] = "pageCount";
101 // Load preview page (Page -> Plugin) 94 // Load preview page (Page -> Plugin)
102 const char kJSLoadPreviewPageType[] = "loadPreviewPage"; 95 const char kJSLoadPreviewPageType[] = "loadPreviewPage";
103 const char kJSPreviewPageUrl[] = "url"; 96 const char kJSPreviewPageUrl[] = "url";
104 const char kJSPreviewPageIndex[] = "index"; 97 const char kJSPreviewPageIndex[] = "index";
105 // Set scroll position (Plugin -> Page) 98 // Set scroll position (Plugin -> Page)
106 const char kJSSetScrollPositionType[] = "setScrollPosition"; 99 const char kJSSetScrollPositionType[] = "setScrollPosition";
107 const char kJSPositionX[] = "x"; 100 const char kJSPositionX[] = "x";
108 const char kJSPositionY[] = "y"; 101 const char kJSPositionY[] = "y";
109 // Request accessibility JSON data (Page -> Plugin)
110 const char kJSGetAccessibilityJSONType[] = "getAccessibilityJSON";
111 const char kJSAccessibilityPageNumber[] = "page";
112 // Reply with accessibility JSON data (Plugin -> Page)
113 const char kJSGetAccessibilityJSONReplyType[] = "getAccessibilityJSONReply";
114 const char kJSAccessibilityJSON[] = "json";
115 // Cancel the stream URL request (Plugin -> Page) 102 // Cancel the stream URL request (Plugin -> Page)
116 const char kJSCancelStreamUrlType[] = "cancelStreamUrl"; 103 const char kJSCancelStreamUrlType[] = "cancelStreamUrl";
117 // Navigate to the given URL (Plugin -> Page) 104 // Navigate to the given URL (Plugin -> Page)
118 const char kJSNavigateType[] = "navigate"; 105 const char kJSNavigateType[] = "navigate";
119 const char kJSNavigateUrl[] = "url"; 106 const char kJSNavigateUrl[] = "url";
120 const char kJSNavigateNewTab[] = "newTab"; 107 const char kJSNavigateNewTab[] = "newTab";
121 // Open the email editor with the given parameters (Plugin -> Page) 108 // Open the email editor with the given parameters (Plugin -> Page)
122 const char kJSEmailType[] = "email"; 109 const char kJSEmailType[] = "email";
123 const char kJSEmailTo[] = "to"; 110 const char kJSEmailTo[] = "to";
124 const char kJSEmailCc[] = "cc"; 111 const char kJSEmailCc[] = "cc";
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 441
455 print_preview_page_count_ = 442 print_preview_page_count_ =
456 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0); 443 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0);
457 444
458 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); 445 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
459 } else if (type == kJSLoadPreviewPageType && 446 } else if (type == kJSLoadPreviewPageType &&
460 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() && 447 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() &&
461 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) { 448 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) {
462 ProcessPreviewPageInfo(dict.Get(pp::Var(kJSPreviewPageUrl)).AsString(), 449 ProcessPreviewPageInfo(dict.Get(pp::Var(kJSPreviewPageUrl)).AsString(),
463 dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt()); 450 dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt());
464 } else if (type == kJSGetAccessibilityJSONType) {
465 pp::VarDictionary reply;
466 reply.Set(pp::Var(kType), pp::Var(kJSGetAccessibilityJSONReplyType));
467 if (dict.Get(pp::Var(kJSAccessibilityPageNumber)).is_int()) {
468 int page = dict.Get(pp::Var(kJSAccessibilityPageNumber)).AsInt();
469 reply.Set(pp::Var(kJSAccessibilityJSON),
470 pp::Var(engine_->GetPageAsJSON(page)));
471 } else {
472 base::DictionaryValue node;
473 node.SetInteger(kAccessibleNumberOfPages, engine_->GetNumberOfPages());
474 node.SetBoolean(kAccessibleLoaded,
475 document_load_state_ != LOAD_STATE_LOADING);
476 bool has_permissions =
477 engine_->HasPermission(PDFEngine::PERMISSION_COPY) ||
478 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE);
479 node.SetBoolean(kAccessibleCopyable, has_permissions);
480 std::string json;
481 base::JSONWriter::Write(node, &json);
482 reply.Set(pp::Var(kJSAccessibilityJSON), pp::Var(json));
483 }
484 PostMessage(reply);
485 } else if (type == kJSStopScrollingType) { 451 } else if (type == kJSStopScrollingType) {
486 stop_scrolling_ = true; 452 stop_scrolling_ = true;
487 } else if (type == kJSGetSelectedTextType) { 453 } else if (type == kJSGetSelectedTextType) {
488 std::string selected_text = engine_->GetSelectedText(); 454 std::string selected_text = engine_->GetSelectedText();
489 // Always return unix newlines to JS. 455 // Always return unix newlines to JS.
490 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text); 456 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text);
491 pp::VarDictionary reply; 457 pp::VarDictionary reply;
492 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType)); 458 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType));
493 reply.Set(pp::Var(kJSSelectedText), selected_text); 459 reply.Set(pp::Var(kJSSelectedText), selected_text);
494 PostMessage(reply); 460 PostMessage(reply);
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 const pp::FloatPoint& scroll_offset) { 1523 const pp::FloatPoint& scroll_offset) {
1558 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1524 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1559 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1525 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1560 float min_y = -top_toolbar_height_; 1526 float min_y = -top_toolbar_height_;
1561 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1527 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1562 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); 1528 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1563 return pp::FloatPoint(x, y); 1529 return pp::FloatPoint(x, y);
1564 } 1530 }
1565 1531
1566 } // namespace chrome_pdf 1532 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « chrome/test/data/pdf/basic_plugin_test.js ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698