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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 1329213002: PDF: Use chrome.resourcesPrivate instead of Pepper to display translated strings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i18n_api
Patch Set: Remove test cases Created 5 years, 3 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/out_of_process_instance.h ('k') | ppapi/c/private/ppb_pdf.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 <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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 const char kJSPrintPreviewGrayscale[] = "grayscale"; 96 const char kJSPrintPreviewGrayscale[] = "grayscale";
97 const char kJSPrintPreviewPageCount[] = "pageCount"; 97 const char kJSPrintPreviewPageCount[] = "pageCount";
98 // Load preview page (Page -> Plugin) 98 // Load preview page (Page -> Plugin)
99 const char kJSLoadPreviewPageType[] = "loadPreviewPage"; 99 const char kJSLoadPreviewPageType[] = "loadPreviewPage";
100 const char kJSPreviewPageUrl[] = "url"; 100 const char kJSPreviewPageUrl[] = "url";
101 const char kJSPreviewPageIndex[] = "index"; 101 const char kJSPreviewPageIndex[] = "index";
102 // Set scroll position (Plugin -> Page) 102 // Set scroll position (Plugin -> Page)
103 const char kJSSetScrollPositionType[] = "setScrollPosition"; 103 const char kJSSetScrollPositionType[] = "setScrollPosition";
104 const char kJSPositionX[] = "x"; 104 const char kJSPositionX[] = "x";
105 const char kJSPositionY[] = "y"; 105 const char kJSPositionY[] = "y";
106 // Set translated strings (Plugin -> Page)
107 const char kJSSetTranslatedStringsType[] = "setTranslatedStrings";
108 const char kJSGetPasswordString[] = "getPasswordString";
109 const char kJSLoadingString[] = "loadingString";
110 const char kJSLoadFailedString[] = "loadFailedString";
111 // Request accessibility JSON data (Page -> Plugin) 106 // Request accessibility JSON data (Page -> Plugin)
112 const char kJSGetAccessibilityJSONType[] = "getAccessibilityJSON"; 107 const char kJSGetAccessibilityJSONType[] = "getAccessibilityJSON";
113 const char kJSAccessibilityPageNumber[] = "page"; 108 const char kJSAccessibilityPageNumber[] = "page";
114 // Reply with accessibility JSON data (Plugin -> Page) 109 // Reply with accessibility JSON data (Plugin -> Page)
115 const char kJSGetAccessibilityJSONReplyType[] = "getAccessibilityJSONReply"; 110 const char kJSGetAccessibilityJSONReplyType[] = "getAccessibilityJSONReply";
116 const char kJSAccessibilityJSON[] = "json"; 111 const char kJSAccessibilityJSON[] = "json";
117 // Cancel the stream URL request (Plugin -> Page) 112 // Cancel the stream URL request (Plugin -> Page)
118 const char kJSCancelStreamUrlType[] = "cancelStreamUrl"; 113 const char kJSCancelStreamUrlType[] = "cancelStreamUrl";
119 // Navigate to the given URL (Plugin -> Page) 114 // Navigate to the given URL (Plugin -> Page)
120 const char kJSNavigateType[] = "navigate"; 115 const char kJSNavigateType[] = "navigate";
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (strcmp(argn[i], "full-frame") == 0) { 316 if (strcmp(argn[i], "full-frame") == 0) {
322 full_ = true; 317 full_ = true;
323 break; 318 break;
324 } 319 }
325 } 320 }
326 321
327 // Only allow the plugin to handle find requests if it is full frame. 322 // Only allow the plugin to handle find requests if it is full frame.
328 if (full_) 323 if (full_)
329 SetPluginToHandleFindRequests(); 324 SetPluginToHandleFindRequests();
330 325
331 // Send translated strings to the extension where they will be displayed.
332 // TODO(raymes): It would be better to get these in the extension directly
333 // through an API but no such API currently exists.
334 pp::VarDictionary translated_strings;
335 translated_strings.Set(kType, kJSSetTranslatedStringsType);
336 translated_strings.Set(kJSGetPasswordString,
337 GetLocalizedString(PP_RESOURCESTRING_PDFGETPASSWORD));
338 translated_strings.Set(kJSLoadingString,
339 GetLocalizedString(PP_RESOURCESTRING_PDFLOADING));
340 translated_strings.Set(kJSLoadFailedString,
341 GetLocalizedString(PP_RESOURCESTRING_PDFLOAD_FAILED));
342 PostMessage(translated_strings);
343
344 text_input_.reset(new pp::TextInput_Dev(this)); 326 text_input_.reset(new pp::TextInput_Dev(this));
345 327
346 const char* stream_url = nullptr; 328 const char* stream_url = nullptr;
347 const char* original_url = nullptr; 329 const char* original_url = nullptr;
348 const char* headers = nullptr; 330 const char* headers = nullptr;
349 for (uint32_t i = 0; i < argc; ++i) { 331 for (uint32_t i = 0; i < argc; ++i) {
350 bool success = true; 332 bool success = true;
351 if (strcmp(argn[i], "src") == 0) 333 if (strcmp(argn[i], "src") == 0)
352 original_url = argv[i]; 334 original_url = argv[i];
353 else if (strcmp(argn[i], "stream-url") == 0) 335 else if (strcmp(argn[i], "stream-url") == 0)
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 trusted_interface->GrantUniversalAccess(loader.pp_resource()); 1334 trusted_interface->GrantUniversalAccess(loader.pp_resource());
1353 return loader; 1335 return loader;
1354 } 1336 }
1355 1337
1356 void OutOfProcessInstance::SetZoom(double scale) { 1338 void OutOfProcessInstance::SetZoom(double scale) {
1357 double old_zoom = zoom_; 1339 double old_zoom = zoom_;
1358 zoom_ = scale; 1340 zoom_ = scale;
1359 OnGeometryChanged(old_zoom, device_scale_); 1341 OnGeometryChanged(old_zoom, device_scale_);
1360 } 1342 }
1361 1343
1362 std::string OutOfProcessInstance::GetLocalizedString(PP_ResourceString id) {
1363 pp::Var rv(pp::PDF::GetLocalizedString(this, id));
1364 if (!rv.is_string())
1365 return std::string();
1366
1367 return rv.AsString();
1368 }
1369
1370 void OutOfProcessInstance::AppendBlankPrintPreviewPages() { 1344 void OutOfProcessInstance::AppendBlankPrintPreviewPages() {
1371 if (print_preview_page_count_ == 0) 1345 if (print_preview_page_count_ == 0)
1372 return; 1346 return;
1373 engine_->AppendBlankPages(print_preview_page_count_); 1347 engine_->AppendBlankPages(print_preview_page_count_);
1374 if (!preview_pages_info_.empty()) 1348 if (!preview_pages_info_.empty())
1375 LoadAvailablePreviewPage(); 1349 LoadAvailablePreviewPage();
1376 } 1350 }
1377 1351
1378 bool OutOfProcessInstance::IsPrintPreview() { 1352 bool OutOfProcessInstance::IsPrintPreview() {
1379 return IsPrintPreviewUrl(url_); 1353 return IsPrintPreviewUrl(url_);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 const pp::FloatPoint& scroll_offset) { 1406 const pp::FloatPoint& scroll_offset) {
1433 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1407 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1434 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1408 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1435 float min_y = -top_toolbar_height_; 1409 float min_y = -top_toolbar_height_;
1436 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1410 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1437 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); 1411 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1438 return pp::FloatPoint(x, y); 1412 return pp::FloatPoint(x, y);
1439 } 1413 }
1440 1414
1441 } // namespace chrome_pdf 1415 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | ppapi/c/private/ppb_pdf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698