OLD | NEW |
---|---|
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 23 matching lines...) Expand all Loading... | |
34 return decodeURIComponent(filename); | 34 return decodeURIComponent(filename); |
35 } catch (e) { | 35 } catch (e) { |
36 if (e instanceof URIError) | 36 if (e instanceof URIError) |
37 return filename; | 37 return filename; |
38 throw e; | 38 throw e; |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 /** | 42 /** |
43 * Called when navigation happens in the current tab. | 43 * Called when navigation happens in the current tab. |
44 * @param {int} tabId The id of the current tab; -1 if no current tab. | |
Dan Beam
2015/09/25 20:57:31
there are no ints in javascript. this should be nu
wjmaclean
2015/09/28 13:29:35
Done.
| |
44 * @param {string} url The url to be opened in the current tab. | 45 * @param {string} url The url to be opened in the current tab. |
45 */ | 46 */ |
46 function onNavigateInCurrentTab(url) { | 47 function onNavigateInCurrentTab(tabId, url) { |
47 // Prefer the tabs API because it can navigate from one file:// URL to | 48 // When the PDFviewer is not inside a <webview>, prefer the tabs API because |
48 // another. | 49 // it can navigate from one file:// URL to another. |
49 if (chrome.tabs) | 50 if (chrome.tabs && tabId != -1) |
50 chrome.tabs.update({url: url}); | 51 chrome.tabs.update(tabId, {url: url}); |
51 else | 52 else |
52 window.location.href = url; | 53 window.location.href = url; |
53 } | 54 } |
54 | 55 |
55 /** | 56 /** |
56 * Called when navigation happens in the new tab. | 57 * Called when navigation happens in the new tab. |
57 * @param {string} url The url to be opened in the new tab. | 58 * @param {string} url The url to be opened in the new tab. |
58 */ | 59 */ |
59 function onNavigateInNewTab(url) { | 60 function onNavigateInNewTab(url) { |
60 // Prefer the tabs API because it guarantees we can just open a new tab. | 61 // Prefer the tabs API because it guarantees we can just open a new tab. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 this.zoomManager_ = new ZoomManager( | 241 this.zoomManager_ = new ZoomManager( |
241 this.viewport_, this.browserApi_.setZoom.bind(this.browserApi_), | 242 this.viewport_, this.browserApi_.setZoom.bind(this.browserApi_), |
242 this.browserApi_.getInitialZoom()); | 243 this.browserApi_.getInitialZoom()); |
243 this.browserApi_.addZoomEventListener( | 244 this.browserApi_.addZoomEventListener( |
244 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); | 245 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); |
245 | 246 |
246 // Setup the keyboard event listener. | 247 // Setup the keyboard event listener. |
247 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); | 248 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); |
248 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this)); | 249 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this)); |
249 | 250 |
251 var onNavigateBoundToCurrentTab = function(browserApi, url) { | |
Dan Beam
2015/09/25 20:57:31
browserApi is already a local variable to this met
wjmaclean
2015/09/28 13:29:35
Acknowledged.
| |
252 var tabId = browserApi ? browserApi.getStreamInfo().tabId : -1; | |
Dan Beam
2015/09/25 20:57:31
you're binding this.browserApi_ from outside, and
wjmaclean
2015/09/28 13:29:35
Acknowledged.
| |
253 onNavigateInCurrentTab(tabId, url); | |
254 }.bind(undefined, this.browserApi_); | |
255 | |
250 // Parse open pdf parameters. | 256 // Parse open pdf parameters. |
251 this.paramsParser_ = | 257 this.paramsParser_ = |
252 new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); | 258 new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); |
253 this.navigator_ = new Navigator(this.browserApi_.getStreamInfo().originalUrl, | 259 this.navigator_ = new Navigator(this.browserApi_.getStreamInfo().originalUrl, |
254 this.viewport_, this.paramsParser_, | 260 this.viewport_, this.paramsParser_, |
255 onNavigateInCurrentTab, onNavigateInNewTab); | 261 onNavigateBoundToCurrentTab, |
raymes
2015/09/27 23:02:02
I think you should be able to delete onNavigateBou
wjmaclean
2015/09/28 13:29:35
Ok.
I wasn't sure if it was safe to assume that t
| |
262 onNavigateInNewTab); | |
256 this.viewportScroller_ = | 263 this.viewportScroller_ = |
257 new ViewportScroller(this.viewport_, this.plugin_, window); | 264 new ViewportScroller(this.viewport_, this.plugin_, window); |
258 } | 265 } |
259 | 266 |
260 PDFViewer.prototype = { | 267 PDFViewer.prototype = { |
261 /** | 268 /** |
262 * @private | 269 * @private |
263 * Handle key events. These may come from the user directly or via the | 270 * Handle key events. These may come from the user directly or via the |
264 * scripting API. | 271 * scripting API. |
265 * @param {KeyboardEvent} e the event to handle. | 272 * @param {KeyboardEvent} e the event to handle. |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 * Each bookmark is an Object containing a: | 879 * Each bookmark is an Object containing a: |
873 * - title | 880 * - title |
874 * - page (optional) | 881 * - page (optional) |
875 * - array of children (themselves bookmarks) | 882 * - array of children (themselves bookmarks) |
876 * @type {Array} the top-level bookmarks of the PDF. | 883 * @type {Array} the top-level bookmarks of the PDF. |
877 */ | 884 */ |
878 get bookmarks() { | 885 get bookmarks() { |
879 return this.bookmarks_; | 886 return this.bookmarks_; |
880 } | 887 } |
881 }; | 888 }; |
OLD | NEW |