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

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

Issue 2240803002: Clean up some PDF code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 | « no previous file | pdf/out_of_process_instance.cc » ('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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 function PDFViewer(browserApi) { 124 function PDFViewer(browserApi) {
125 this.browserApi_ = browserApi; 125 this.browserApi_ = browserApi;
126 this.originalUrl_ = this.browserApi_.getStreamInfo().originalUrl; 126 this.originalUrl_ = this.browserApi_.getStreamInfo().originalUrl;
127 this.loadState_ = LoadState.LOADING; 127 this.loadState_ = LoadState.LOADING;
128 this.parentWindow_ = null; 128 this.parentWindow_ = null;
129 this.parentOrigin_ = null; 129 this.parentOrigin_ = null;
130 this.isFormFieldFocused_ = false; 130 this.isFormFieldFocused_ = false;
131 131
132 this.delayedScriptingMessages_ = []; 132 this.delayedScriptingMessages_ = [];
133 133
134 this.isPrintPreview_ = this.originalUrl_.indexOf( 134 this.isPrintPreview_ = this.originalUrl_.indexOf('chrome://print') == 0;
135 'chrome://print') == 0; 135
136 // Parse open pdf parameters. 136 // Parse open pdf parameters.
137 this.paramsParser_ = 137 this.paramsParser_ =
138 new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); 138 new OpenPDFParamsParser(this.getNamedDestination_.bind(this));
139 var toolbarEnabled = 139 var toolbarEnabled =
140 this.paramsParser_.getUiUrlParams(this.originalUrl_).toolbar && 140 this.paramsParser_.getUiUrlParams(this.originalUrl_).toolbar &&
141 !this.isPrintPreview_; 141 !this.isPrintPreview_;
142 142
143 // The sizer element is placed behind the plugin element to cause scrollbars 143 // The sizer element is placed behind the plugin element to cause scrollbars
144 // to be displayed in the window. It is sized according to the document size 144 // to be displayed in the window. It is sized according to the document size
145 // of the pdf and zoom level. 145 // of the pdf and zoom level.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 this.plugin_.type = 'application/x-google-chrome-pdf'; 181 this.plugin_.type = 'application/x-google-chrome-pdf';
182 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), 182 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this),
183 false); 183 false);
184 184
185 // Handle scripting messages from outside the extension that wish to interact 185 // Handle scripting messages from outside the extension that wish to interact
186 // with it. We also send a message indicating that extension has loaded and 186 // with it. We also send a message indicating that extension has loaded and
187 // is ready to receive messages. 187 // is ready to receive messages.
188 window.addEventListener('message', this.handleScriptingMessage.bind(this), 188 window.addEventListener('message', this.handleScriptingMessage.bind(this),
189 false); 189 false);
190 190
191 this.plugin_.setAttribute('src', 191 this.plugin_.setAttribute('src', this.originalUrl_);
192 this.originalUrl_);
193 this.plugin_.setAttribute('stream-url', 192 this.plugin_.setAttribute('stream-url',
194 this.browserApi_.getStreamInfo().streamUrl); 193 this.browserApi_.getStreamInfo().streamUrl);
195 var headers = ''; 194 var headers = '';
196 for (var header in this.browserApi_.getStreamInfo().responseHeaders) { 195 for (var header in this.browserApi_.getStreamInfo().responseHeaders) {
197 headers += header + ': ' + 196 headers += header + ': ' +
198 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n'; 197 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n';
199 } 198 }
200 this.plugin_.setAttribute('headers', headers); 199 this.plugin_.setAttribute('headers', headers);
201 200
202 var backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR; 201 var backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR;
(...skipping 20 matching lines...) Expand all
223 this.toolbar_.hidden = false; 222 this.toolbar_.hidden = false;
224 this.toolbar_.addEventListener('save', this.save_.bind(this)); 223 this.toolbar_.addEventListener('save', this.save_.bind(this));
225 this.toolbar_.addEventListener('print', this.print_.bind(this)); 224 this.toolbar_.addEventListener('print', this.print_.bind(this));
226 this.toolbar_.addEventListener('rotate-right', 225 this.toolbar_.addEventListener('rotate-right',
227 this.rotateClockwise_.bind(this)); 226 this.rotateClockwise_.bind(this));
228 // Must attach to mouseup on the plugin element, since it eats mousedown 227 // Must attach to mouseup on the plugin element, since it eats mousedown
229 // and click events. 228 // and click events.
230 this.plugin_.addEventListener('mouseup', 229 this.plugin_.addEventListener('mouseup',
231 this.toolbar_.hideDropdowns.bind(this.toolbar_)); 230 this.toolbar_.hideDropdowns.bind(this.toolbar_));
232 231
233 this.toolbar_.docTitle = 232 this.toolbar_.docTitle = getFilenameFromURL(this.originalUrl_);
234 getFilenameFromURL(this.originalUrl_);
235 } 233 }
236 234
237 document.body.addEventListener('change-page', function(e) { 235 document.body.addEventListener('change-page', function(e) {
238 this.viewport_.goToPage(e.detail.page); 236 this.viewport_.goToPage(e.detail.page);
239 }.bind(this)); 237 }.bind(this));
240 238
241 document.body.addEventListener('navigate', function(e) { 239 document.body.addEventListener('navigate', function(e) {
242 var disposition = 240 var disposition =
243 e.detail.newtab ? Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB : 241 e.detail.newtab ? Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB :
244 Navigator.WindowOpenDisposition.CURRENT_TAB; 242 Navigator.WindowOpenDisposition.CURRENT_TAB;
245 this.navigator_.navigate(e.detail.uri, disposition); 243 this.navigator_.navigate(e.detail.uri, disposition);
246 }.bind(this)); 244 }.bind(this));
247 245
248 this.toolbarManager_ = 246 this.toolbarManager_ =
249 new ToolbarManager(window, this.toolbar_, this.zoomToolbar_); 247 new ToolbarManager(window, this.toolbar_, this.zoomToolbar_);
250 248
251 // Set up the ZoomManager. 249 // Set up the ZoomManager.
252 this.zoomManager_ = new ZoomManager( 250 this.zoomManager_ = new ZoomManager(
253 this.viewport_, this.browserApi_.setZoom.bind(this.browserApi_), 251 this.viewport_, this.browserApi_.setZoom.bind(this.browserApi_),
254 this.browserApi_.getInitialZoom()); 252 this.browserApi_.getInitialZoom());
255 this.browserApi_.addZoomEventListener( 253 this.browserApi_.addZoomEventListener(
256 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); 254 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_));
257 255
258 // Setup the keyboard event listener. 256 // Setup the keyboard event listener.
259 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); 257 document.addEventListener('keydown', this.handleKeyEvent_.bind(this));
260 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this)); 258 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this));
261 document.addEventListener('mouseout', this.handleMouseEvent_.bind(this)); 259 document.addEventListener('mouseout', this.handleMouseEvent_.bind(this));
262 260
263 var isInTab = this.browserApi_.getStreamInfo().tabId != -1; 261 var isInTab = this.browserApi_.getStreamInfo().tabId != -1;
264 var isSourceFileUrl = 262 var isSourceFileUrl = this.originalUrl_.indexOf('file://') == 0;
265 this.originalUrl_.indexOf('file://') == 0;
266 this.navigator_ = new Navigator(this.originalUrl_, 263 this.navigator_ = new Navigator(this.originalUrl_,
267 this.viewport_, this.paramsParser_, 264 this.viewport_, this.paramsParser_,
268 onNavigateInCurrentTab.bind(undefined, 265 onNavigateInCurrentTab.bind(undefined,
269 isInTab, 266 isInTab,
270 isSourceFileUrl), 267 isSourceFileUrl),
271 onNavigateInNewTab); 268 onNavigateInNewTab);
272 this.viewportScroller_ = 269 this.viewportScroller_ =
273 new ViewportScroller(this.viewport_, this.plugin_, window); 270 new ViewportScroller(this.viewport_, this.plugin_, window);
274 271
275 // Request translated strings. 272 // Request translated strings.
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 position.y = message.data.y; 644 position.y = message.data.y;
648 this.viewport_.position = position; 645 this.viewport_.position = position;
649 break; 646 break;
650 case 'cancelStreamUrl': 647 case 'cancelStreamUrl':
651 chrome.mimeHandlerPrivate.abortStream(); 648 chrome.mimeHandlerPrivate.abortStream();
652 break; 649 break;
653 case 'metadata': 650 case 'metadata':
654 if (message.data.title) { 651 if (message.data.title) {
655 document.title = message.data.title; 652 document.title = message.data.title;
656 } else { 653 } else {
657 document.title = 654 document.title = getFilenameFromURL(this.originalUrl_);
658 getFilenameFromURL(this.originalUrl_);
659 } 655 }
660 this.bookmarks_ = message.data.bookmarks; 656 this.bookmarks_ = message.data.bookmarks;
661 if (this.toolbar_) { 657 if (this.toolbar_) {
662 this.toolbar_.docTitle = document.title; 658 this.toolbar_.docTitle = document.title;
663 this.toolbar_.bookmarks = this.bookmarks; 659 this.toolbar_.bookmarks = this.bookmarks;
664 } 660 }
665 break; 661 break;
666 case 'setIsSelecting': 662 case 'setIsSelecting':
667 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); 663 this.viewportScroller_.setEnableScrolling(message.data.isSelecting);
668 break; 664 break;
669 case 'getNamedDestinationReply': 665 case 'getNamedDestinationReply':
670 this.paramsParser_.onNamedDestinationReceived( 666 this.paramsParser_.onNamedDestinationReceived(message.data.pageNumber);
671 message.data.pageNumber);
672 break; 667 break;
673 case 'formFocusChange': 668 case 'formFocusChange':
674 this.isFormFieldFocused_ = message.data.focused; 669 this.isFormFieldFocused_ = message.data.focused;
675 break; 670 break;
676 } 671 }
677 }, 672 },
678 673
679 /** 674 /**
680 * @private 675 * @private
681 * A callback that's called before the zoom changes. Notify the plugin to stop 676 * A callback that's called before the zoom changes. Notify the plugin to stop
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 * Each bookmark is an Object containing a: 880 * Each bookmark is an Object containing a:
886 * - title 881 * - title
887 * - page (optional) 882 * - page (optional)
888 * - array of children (themselves bookmarks) 883 * - array of children (themselves bookmarks)
889 * @type {Array} the top-level bookmarks of the PDF. 884 * @type {Array} the top-level bookmarks of the PDF.
890 */ 885 */
891 get bookmarks() { 886 get bookmarks() {
892 return this.bookmarks_; 887 return this.bookmarks_;
893 } 888 }
894 }; 889 };
OLDNEW
« no previous file with comments | « no previous file | pdf/out_of_process_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698