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

Side by Side Diff: chrome/browser/resources/pdf/pdf.js

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 | « chrome/browser/resources/pdf/manifest.json ('k') | chrome/common/extensions/api/OWNERS » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @return {number} Width of a scrollbar in pixels 8 * @return {number} Width of a scrollbar in pixels
9 */ 9 */
10 function getScrollbarWidth() { 10 function getScrollbarWidth() {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this)); 248 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this));
249 249
250 // Parse open pdf parameters. 250 // Parse open pdf parameters.
251 this.paramsParser_ = 251 this.paramsParser_ =
252 new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); 252 new OpenPDFParamsParser(this.getNamedDestination_.bind(this));
253 this.navigator_ = new Navigator(this.browserApi_.getStreamInfo().originalUrl, 253 this.navigator_ = new Navigator(this.browserApi_.getStreamInfo().originalUrl,
254 this.viewport_, this.paramsParser_, 254 this.viewport_, this.paramsParser_,
255 onNavigateInCurrentTab, onNavigateInNewTab); 255 onNavigateInCurrentTab, onNavigateInNewTab);
256 this.viewportScroller_ = 256 this.viewportScroller_ =
257 new ViewportScroller(this.viewport_, this.plugin_, window); 257 new ViewportScroller(this.viewport_, this.plugin_, window);
258
259 // Request translated strings.
260 chrome.resourcesPrivate.getStrings('pdf', this.handleStrings_.bind(this));
258 } 261 }
259 262
260 PDFViewer.prototype = { 263 PDFViewer.prototype = {
261 /** 264 /**
262 * @private 265 * @private
263 * Handle key events. These may come from the user directly or via the 266 * Handle key events. These may come from the user directly or via the
264 * scripting API. 267 * scripting API.
265 * @param {KeyboardEvent} e the event to handle. 268 * @param {KeyboardEvent} e the event to handle.
266 */ 269 */
267 handleKeyEvent_: function(e) { 270 handleKeyEvent_: function(e) {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 while (this.delayedScriptingMessages_.length > 0) 535 while (this.delayedScriptingMessages_.length > 0)
533 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); 536 this.handleScriptingMessage(this.delayedScriptingMessages_.shift());
534 537
535 if (this.isMaterial_) 538 if (this.isMaterial_)
536 this.toolbarManager_.hideToolbarsAfterTimeout(); 539 this.toolbarManager_.hideToolbarsAfterTimeout();
537 } 540 }
538 }, 541 },
539 542
540 /** 543 /**
541 * @private 544 * @private
545 * Load a dictionary of translated strings into the UI. Used as a callback for
546 * chrome.resourcesPrivate.
547 * @param {Object} strings Dictionary of translated strings
548 */
549 handleStrings_: function(strings) {
550 this.passwordScreen_.text = strings.passwordPrompt;
551 if (!this.isMaterial_) {
552 this.progressBar_.text = strings.pageLoading;
553 if (!this.isPrintPreview_)
554 this.progressBar_.style.visibility = 'visible';
555 }
556 this.errorScreen_.text = strings.pageLoadFailed;
557 },
558
559 /**
560 * @private
542 * An event handler for handling password-submitted events. These are fired 561 * An event handler for handling password-submitted events. These are fired
543 * when an event is entered into the password screen. 562 * when an event is entered into the password screen.
544 * @param {Object} event a password-submitted event. 563 * @param {Object} event a password-submitted event.
545 */ 564 */
546 onPasswordSubmitted_: function(event) { 565 onPasswordSubmitted_: function(event) {
547 this.plugin_.postMessage({ 566 this.plugin_.postMessage({
548 type: 'getPasswordComplete', 567 type: 'getPasswordComplete',
549 password: event.detail.password 568 password: event.detail.password
550 }); 569 });
551 }, 570 },
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 this.navigator_.navigate(message.data.url, message.data.newTab); 630 this.navigator_.navigate(message.data.url, message.data.newTab);
612 break; 631 break;
613 case 'setScrollPosition': 632 case 'setScrollPosition':
614 var position = this.viewport_.position; 633 var position = this.viewport_.position;
615 if (message.data.x !== undefined) 634 if (message.data.x !== undefined)
616 position.x = message.data.x; 635 position.x = message.data.x;
617 if (message.data.y !== undefined) 636 if (message.data.y !== undefined)
618 position.y = message.data.y; 637 position.y = message.data.y;
619 this.viewport_.position = position; 638 this.viewport_.position = position;
620 break; 639 break;
621 case 'setTranslatedStrings':
622 this.passwordScreen_.text = message.data.getPasswordString;
623 if (!this.isMaterial_) {
624 this.progressBar_.text = message.data.loadingString;
625 if (!this.isPrintPreview_)
626 this.progressBar_.style.visibility = 'visible';
627 }
628 this.errorScreen_.text = message.data.loadFailedString;
629 break;
630 case 'cancelStreamUrl': 640 case 'cancelStreamUrl':
631 chrome.mimeHandlerPrivate.abortStream(); 641 chrome.mimeHandlerPrivate.abortStream();
632 break; 642 break;
633 case 'metadata': 643 case 'metadata':
634 if (message.data.title) { 644 if (message.data.title) {
635 document.title = message.data.title; 645 document.title = message.data.title;
636 } else { 646 } else {
637 document.title = 647 document.title =
638 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl); 648 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl);
639 } 649 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 * Each bookmark is an Object containing a: 882 * Each bookmark is an Object containing a:
873 * - title 883 * - title
874 * - page (optional) 884 * - page (optional)
875 * - array of children (themselves bookmarks) 885 * - array of children (themselves bookmarks)
876 * @type {Array} the top-level bookmarks of the PDF. 886 * @type {Array} the top-level bookmarks of the PDF.
877 */ 887 */
878 get bookmarks() { 888 get bookmarks() {
879 return this.bookmarks_; 889 return this.bookmarks_;
880 } 890 }
881 }; 891 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/manifest.json ('k') | chrome/common/extensions/api/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698