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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/pdf/basic_plugin_test.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/out_of_process_instance.cc
diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc
index a7c53401bc4a0332549abde80c7907442212b6ff..4e76e32736a641d938c007ad6cff20aeb2d81332 100644
--- a/pdf/out_of_process_instance.cc
+++ b/pdf/out_of_process_instance.cc
@@ -127,6 +127,11 @@ const char kJSRotateClockwiseType[] = "rotateClockwise";
const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
// Select all text in the document (Page -> Plugin)
const char kJSSelectAllType[] = "selectAll";
+// Get the selected text in the document (Page -> Plugin)
+const char kJSGetSelectedTextType[] = "getSelectedText";
+// Reply with selected text (Plugin -> Page)
+const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply";
+const char kJSSelectedText[] = "selectedText";
const int kFindResultCooldownMs = 100;
@@ -444,6 +449,14 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
PostMessage(reply);
} else if (type == kJSStopScrollingType) {
stop_scrolling_ = true;
+ } else if (type == kJSGetSelectedTextType) {
+ std::string selected_text = engine_->GetSelectedText();
+ // Always return unix newlines to JS.
+ base::ReplaceChars(selected_text, "\r", std::string(), &selected_text);
+ pp::VarDictionary reply;
+ reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType));
+ reply.Set(pp::Var(kJSSelectedText), selected_text);
+ PostMessage(reply);
} else {
NOTREACHED();
}
« 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