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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 286933011: Remove most references to VarPrivate/InstancePrivate from OOP PDF (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « pdf/out_of_process_instance.h ('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>
11 #include <list> 11 #include <list>
12 12
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/common/content_restriction.h" 20 #include "chrome/common/content_restriction.h"
21 #include "net/base/escape.h" 21 #include "net/base/escape.h"
22 #include "pdf/draw_utils.h" 22 #include "pdf/draw_utils.h"
23 #include "pdf/pdf.h" 23 #include "pdf/pdf.h"
24 #include "ppapi/c/dev/ppb_cursor_control_dev.h" 24 #include "ppapi/c/dev/ppb_cursor_control_dev.h"
25 #include "ppapi/c/pp_errors.h" 25 #include "ppapi/c/pp_errors.h"
26 #include "ppapi/c/pp_rect.h" 26 #include "ppapi/c/pp_rect.h"
27 #include "ppapi/c/private/ppb_instance_private.h"
27 #include "ppapi/c/private/ppp_pdf.h" 28 #include "ppapi/c/private/ppp_pdf.h"
28 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" 29 #include "ppapi/c/trusted/ppb_url_loader_trusted.h"
29 #include "ppapi/cpp/core.h" 30 #include "ppapi/cpp/core.h"
30 #include "ppapi/cpp/dev/memory_dev.h" 31 #include "ppapi/cpp/dev/memory_dev.h"
31 #include "ppapi/cpp/dev/text_input_dev.h" 32 #include "ppapi/cpp/dev/text_input_dev.h"
32 #include "ppapi/cpp/dev/url_util_dev.h" 33 #include "ppapi/cpp/dev/url_util_dev.h"
33 #include "ppapi/cpp/module.h" 34 #include "ppapi/cpp/module.h"
34 #include "ppapi/cpp/point.h" 35 #include "ppapi/cpp/point.h"
35 #include "ppapi/cpp/private/pdf.h" 36 #include "ppapi/cpp/private/pdf.h"
36 #include "ppapi/cpp/rect.h" 37 #include "ppapi/cpp/rect.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const char* kJSLoadingString = "loadingString"; 111 const char* kJSLoadingString = "loadingString";
111 const char* kJSLoadFailedString = "loadFailedString"; 112 const char* kJSLoadFailedString = "loadFailedString";
112 // Request accessibility JSON data (Page -> Plugin) 113 // Request accessibility JSON data (Page -> Plugin)
113 const char* kJSGetAccessibilityJSONType = "getAccessibilityJSON"; 114 const char* kJSGetAccessibilityJSONType = "getAccessibilityJSON";
114 const char* kJSAccessibilityPageNumber = "page"; 115 const char* kJSAccessibilityPageNumber = "page";
115 // Reply with accessibility JSON data (Plugin -> Page) 116 // Reply with accessibility JSON data (Plugin -> Page)
116 const char* kJSGetAccessibilityJSONReplyType = "getAccessibilityJSONReply"; 117 const char* kJSGetAccessibilityJSONReplyType = "getAccessibilityJSONReply";
117 const char* kJSAccessibilityJSON = "json"; 118 const char* kJSAccessibilityJSON = "json";
118 // Cancel the stream URL request (Plugin -> Page) 119 // Cancel the stream URL request (Plugin -> Page)
119 const char* kJSCancelStreamUrlType = "cancelStreamUrl"; 120 const char* kJSCancelStreamUrlType = "cancelStreamUrl";
121 // Navigate to the given URL (Plugin -> Page)
122 const char* kJSNavigateType = "navigate";
123 const char* kJSNavigateUrl = "url";
124 const char* kJSNavigateNewTab = "newTab";
125 // Open the email editor with the given parameters (Plugin -> Page)
126 const char* kJSEmailType = "email";
127 const char* kJSEmailTo = "to";
128 const char* kJSEmailCc = "cc";
129 const char* kJSEmailBcc = "bcc";
130 const char* kJSEmailSubject = "subject";
131 const char* kJSEmailBody = "body";
120 132
121 const int kFindResultCooldownMs = 100; 133 const int kFindResultCooldownMs = 100;
122 134
123 const double kMinZoom = 0.01; 135 const double kMinZoom = 0.01;
124 136
125 namespace { 137 namespace {
126 138
127 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; 139 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;
128 140
129 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { 141 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 196 }
185 197
186 void ScaleRect(float scale, pp::Rect* rect) { 198 void ScaleRect(float scale, pp::Rect* rect) {
187 int left = static_cast<int>(floorf(rect->x() * scale)); 199 int left = static_cast<int>(floorf(rect->x() * scale));
188 int top = static_cast<int>(floorf(rect->y() * scale)); 200 int top = static_cast<int>(floorf(rect->y() * scale));
189 int right = static_cast<int>(ceilf((rect->x() + rect->width()) * scale)); 201 int right = static_cast<int>(ceilf((rect->x() + rect->width()) * scale));
190 int bottom = static_cast<int>(ceilf((rect->y() + rect->height()) * scale)); 202 int bottom = static_cast<int>(ceilf((rect->y() + rect->height()) * scale));
191 rect->SetRect(left, top, right - left, bottom - top); 203 rect->SetRect(left, top, right - left, bottom - top);
192 } 204 }
193 205
206 // TODO(raymes): Remove this dependency on VarPrivate/InstancePrivate. It's
207 // needed right now to do a synchronous call to JavaScript, but we could easily
208 // replace this with a custom PPB_PDF function.
209 pp::Var ModalDialog(const pp::Instance* instance,
210 const std::string& type,
211 const std::string& message,
212 const std::string& default_answer) {
213 const PPB_Instance_Private* interface =
Lei Zhang 2014/05/21 01:28:55 Is it possible to sanely handle the case where the
214 reinterpret_cast<const PPB_Instance_Private*>(
215 pp::Module::Get()->GetBrowserInterface(
216 PPB_INSTANCE_PRIVATE_INTERFACE));
217 pp::VarPrivate window(pp::PASS_REF,
218 interface->GetWindowObject(instance->pp_instance()));
219 if (default_answer.empty())
220 return window.Call(type, message);
221 else
222 return window.Call(type, message, default_answer);
223 }
224
194 } // namespace 225 } // namespace
195 226
196 OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) 227 OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
197 : pp::InstancePrivate(instance), 228 : pp::Instance(instance),
198 pp::Find_Private(this), 229 pp::Find_Private(this),
199 pp::Printing_Dev(this), 230 pp::Printing_Dev(this),
200 pp::Selection_Dev(this), 231 pp::Selection_Dev(this),
201 cursor_(PP_CURSORTYPE_POINTER), 232 cursor_(PP_CURSORTYPE_POINTER),
202 zoom_(1.0), 233 zoom_(1.0),
203 device_scale_(1.0), 234 device_scale_(1.0),
204 printing_enabled_(true), 235 printing_enabled_(true),
205 full_(false), 236 full_(false),
206 paint_manager_(this, this, true), 237 paint_manager_(this, this, true),
207 first_paint_(true), 238 first_paint_(true),
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 } 521 }
491 522
492 if (image_data_.is_null()) { 523 if (image_data_.is_null()) {
493 DCHECK(plugin_size_.IsEmpty()); 524 DCHECK(plugin_size_.IsEmpty());
494 return; 525 return;
495 } 526 }
496 527
497 OnGeometryChanged(zoom_, old_device_scale); 528 OnGeometryChanged(zoom_, old_device_scale);
498 } 529 }
499 530
500 pp::Var OutOfProcessInstance::GetInstanceObject() {
501 return pp::Var();
502 }
503
504 pp::Var OutOfProcessInstance::GetLinkAtPosition( 531 pp::Var OutOfProcessInstance::GetLinkAtPosition(
505 const pp::Point& point) { 532 const pp::Point& point) {
506 pp::Point offset_point(point); 533 pp::Point offset_point(point);
507 ScalePoint(device_scale_, &offset_point); 534 ScalePoint(device_scale_, &offset_point);
508 offset_point.set_x(offset_point.x() - available_area_.x()); 535 offset_point.set_x(offset_point.x() - available_area_.x());
509 return engine_->GetLinkAtPosition(offset_point); 536 return engine_->GetLinkAtPosition(offset_point);
510 } 537 }
511 538
512 pp::Var OutOfProcessInstance::GetSelectedText(bool html) { 539 pp::Var OutOfProcessInstance::GetSelectedText(bool html) {
513 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) 540 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY))
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 return; 827 return;
801 } 828 }
802 // Make sure |url_copy| is not only a scheme. 829 // Make sure |url_copy| is not only a scheme.
803 if (url_copy == "http://" || 830 if (url_copy == "http://" ||
804 url_copy == "https://" || 831 url_copy == "https://" ||
805 url_copy == "ftp://" || 832 url_copy == "ftp://" ||
806 url_copy == "mailto:") { 833 url_copy == "mailto:") {
807 return; 834 return;
808 } 835 }
809 } 836 }
810 if (open_in_new_tab) { 837 pp::VarDictionary message;
811 GetWindowObject().Call("open", url_copy); 838 message.Set(kType, kJSNavigateType);
812 } else { 839 message.Set(kJSNavigateUrl, url_copy);
813 GetWindowObject().GetProperty("top").GetProperty("location"). 840 message.Set(kJSNavigateNewTab, open_in_new_tab);
814 SetProperty("href", url_copy); 841 PostMessage(message);
815 }
816 } 842 }
817 843
818 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) { 844 void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) {
819 if (cursor == cursor_) 845 if (cursor == cursor_)
820 return; 846 return;
821 cursor_ = cursor; 847 cursor_ = cursor;
822 848
823 const PPB_CursorControl_Dev* cursor_interface = 849 const PPB_CursorControl_Dev* cursor_interface =
824 reinterpret_cast<const PPB_CursorControl_Dev*>( 850 reinterpret_cast<const PPB_CursorControl_Dev*>(
825 pp::Module::Get()->GetBrowserInterface(PPB_CURSOR_CONTROL_DEV_INTERFACE)); 851 pp::Module::Get()->GetBrowserInterface(PPB_CURSOR_CONTROL_DEV_INTERFACE));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 } 904 }
879 905
880 password_callback_.reset( 906 password_callback_.reset(
881 new pp::CompletionCallbackWithOutput<pp::Var>(callback)); 907 new pp::CompletionCallbackWithOutput<pp::Var>(callback));
882 pp::VarDictionary message; 908 pp::VarDictionary message;
883 message.Set(pp::Var(kType), pp::Var(kJSGetPasswordType)); 909 message.Set(pp::Var(kType), pp::Var(kJSGetPasswordType));
884 PostMessage(message); 910 PostMessage(message);
885 } 911 }
886 912
887 void OutOfProcessInstance::Alert(const std::string& message) { 913 void OutOfProcessInstance::Alert(const std::string& message) {
888 GetWindowObject().Call("alert", message); 914 ModalDialog(this, "alert", message, std::string());
889 } 915 }
890 916
891 bool OutOfProcessInstance::Confirm(const std::string& message) { 917 bool OutOfProcessInstance::Confirm(const std::string& message) {
892 pp::Var result = GetWindowObject().Call("confirm", message); 918 pp::Var result = ModalDialog(this, "confirm", message, std::string());
893 return result.is_bool() ? result.AsBool() : false; 919 return result.is_bool() ? result.AsBool() : false;
894 } 920 }
895 921
896 std::string OutOfProcessInstance::Prompt(const std::string& question, 922 std::string OutOfProcessInstance::Prompt(const std::string& question,
897 const std::string& default_answer) { 923 const std::string& default_answer) {
898 pp::Var result = GetWindowObject().Call("prompt", question, default_answer); 924 pp::Var result = ModalDialog(this, "prompt", question, default_answer);
899 return result.is_string() ? result.AsString() : std::string(); 925 return result.is_string() ? result.AsString() : std::string();
900 } 926 }
901 927
902 std::string OutOfProcessInstance::GetURL() { 928 std::string OutOfProcessInstance::GetURL() {
903 return url_; 929 return url_;
904 } 930 }
905 931
906 void OutOfProcessInstance::Email(const std::string& to, 932 void OutOfProcessInstance::Email(const std::string& to,
907 const std::string& cc, 933 const std::string& cc,
908 const std::string& bcc, 934 const std::string& bcc,
909 const std::string& subject, 935 const std::string& subject,
910 const std::string& body) { 936 const std::string& body) {
911 std::string javascript = 937 pp::VarDictionary message;
912 "var href = 'mailto:" + net::EscapeUrlEncodedData(to, false) + 938 message.Set(pp::Var(kType), pp::Var(kJSEmailType));
913 "?cc=" + net::EscapeUrlEncodedData(cc, false) + 939 message.Set(pp::Var(kJSEmailTo),
914 "&bcc=" + net::EscapeUrlEncodedData(bcc, false) + 940 pp::Var(net::EscapeUrlEncodedData(to, false)));
915 "&subject=" + net::EscapeUrlEncodedData(subject, false) + 941 message.Set(pp::Var(kJSEmailCc),
916 "&body=" + net::EscapeUrlEncodedData(body, false) + 942 pp::Var(net::EscapeUrlEncodedData(cc, false)));
917 "';var temp = window.open(href, '_blank', " + 943 message.Set(pp::Var(kJSEmailBcc),
918 "'width=1,height=1');if(temp) temp.close();"; 944 pp::Var(net::EscapeUrlEncodedData(bcc, false)));
919 ExecuteScript(javascript); 945 message.Set(pp::Var(kJSEmailSubject),
946 pp::Var(net::EscapeUrlEncodedData(subject, false)));
947 message.Set(pp::Var(kJSEmailBody),
948 pp::Var(net::EscapeUrlEncodedData(body, false)));
949 PostMessage(message);
920 } 950 }
921 951
922 void OutOfProcessInstance::Print() { 952 void OutOfProcessInstance::Print() {
923 if (!printing_enabled_ || 953 if (!printing_enabled_ ||
924 (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && 954 (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
925 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY))) { 955 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY))) {
926 return; 956 return;
927 } 957 }
928 958
929 pp::CompletionCallback callback = 959 pp::CompletionCallback callback =
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 LoadPreviewUrl(url); 1383 LoadPreviewUrl(url);
1354 } 1384 }
1355 1385
1356 void OutOfProcessInstance::UserMetricsRecordAction( 1386 void OutOfProcessInstance::UserMetricsRecordAction(
1357 const std::string& action) { 1387 const std::string& action) {
1358 // TODO(raymes): Move this function to PPB_UMA_Private. 1388 // TODO(raymes): Move this function to PPB_UMA_Private.
1359 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); 1389 pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
1360 } 1390 }
1361 1391
1362 } // namespace chrome_pdf 1392 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698