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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 843463002: Add print and getSelectedText functions to the OOP PDF scripting API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@postMessage-api
Patch Set: Created 5 years, 11 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') | 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 <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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 const char kJSEmailTo[] = "to"; 120 const char kJSEmailTo[] = "to";
121 const char kJSEmailCc[] = "cc"; 121 const char kJSEmailCc[] = "cc";
122 const char kJSEmailBcc[] = "bcc"; 122 const char kJSEmailBcc[] = "bcc";
123 const char kJSEmailSubject[] = "subject"; 123 const char kJSEmailSubject[] = "subject";
124 const char kJSEmailBody[] = "body"; 124 const char kJSEmailBody[] = "body";
125 // Rotation (Page -> Plugin) 125 // Rotation (Page -> Plugin)
126 const char kJSRotateClockwiseType[] = "rotateClockwise"; 126 const char kJSRotateClockwiseType[] = "rotateClockwise";
127 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; 127 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
128 // Select all text in the document (Page -> Plugin) 128 // Select all text in the document (Page -> Plugin)
129 const char kJSSelectAllType[] = "selectAll"; 129 const char kJSSelectAllType[] = "selectAll";
130 // Get the selected text in the document (Page -> Plugin)
131 const char kJSGetSelectedTextType[] = "getSelectedText";
132 // Reply with selected text (Plugin -> Page)
133 const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply";
134 const char kJSSelectedText[] = "selectedText";
130 135
131 const int kFindResultCooldownMs = 100; 136 const int kFindResultCooldownMs = 100;
132 137
133 const double kMinZoom = 0.01; 138 const double kMinZoom = 0.01;
134 139
135 namespace { 140 namespace {
136 141
137 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; 142 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;
138 143
139 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { 144 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 engine_->HasPermission(PDFEngine::PERMISSION_COPY) || 442 engine_->HasPermission(PDFEngine::PERMISSION_COPY) ||
438 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE); 443 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE);
439 node.SetBoolean(kAccessibleCopyable, has_permissions); 444 node.SetBoolean(kAccessibleCopyable, has_permissions);
440 std::string json; 445 std::string json;
441 base::JSONWriter::Write(&node, &json); 446 base::JSONWriter::Write(&node, &json);
442 reply.Set(pp::Var(kJSAccessibilityJSON), pp::Var(json)); 447 reply.Set(pp::Var(kJSAccessibilityJSON), pp::Var(json));
443 } 448 }
444 PostMessage(reply); 449 PostMessage(reply);
445 } else if (type == kJSStopScrollingType) { 450 } else if (type == kJSStopScrollingType) {
446 stop_scrolling_ = true; 451 stop_scrolling_ = true;
452 } else if (type == kJSGetSelectedTextType) {
453 std::string selected_text = engine_->GetSelectedText();
454 // Always return unix newlines to JS.
455 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text);
456 pp::VarDictionary reply;
457 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType));
458 reply.Set(pp::Var(kJSSelectedText), selected_text);
459 PostMessage(reply);
447 } else { 460 } else {
448 NOTREACHED(); 461 NOTREACHED();
449 } 462 }
450 } 463 }
451 464
452 bool OutOfProcessInstance::HandleInputEvent( 465 bool OutOfProcessInstance::HandleInputEvent(
453 const pp::InputEvent& event) { 466 const pp::InputEvent& event) {
454 // To simplify things, convert the event into device coordinates if it is 467 // To simplify things, convert the event into device coordinates if it is
455 // a mouse event. 468 // a mouse event.
456 pp::InputEvent event_device_res(event); 469 pp::InputEvent event_device_res(event);
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( 1395 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
1383 const pp::FloatPoint& scroll_offset) { 1396 const pp::FloatPoint& scroll_offset) {
1384 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1397 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1385 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1398 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1386 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1399 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1387 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); 1400 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f);
1388 return pp::FloatPoint(x, y); 1401 return pp::FloatPoint(x, y);
1389 } 1402 }
1390 1403
1391 } // namespace chrome_pdf 1404 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « chrome/test/data/pdf/basic_plugin_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698