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

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

Issue 1350073002: PDFs viewed inside a <webview> should navigate the same as PDFs in tabs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass tabId to Navigator() instead of browserApi_. 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/navigator.js ('k') | chrome/test/data/pdf/navigator_test.js » ('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 26 matching lines...) Expand all
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 {string} url The url to be opened in the current tab. 44 * @param {string} url The url to be opened in the current tab.
45 */ 45 */
46 function onNavigateInCurrentTab(url) { 46 function onNavigateInCurrentTab(url) {
47 // Prefer the tabs API because it can navigate from one file:// URL to 47 // When the PDFviewer is not inside a <webview>, prefer the tabs API because
48 // another. 48 // it can navigate from one file:// URL to another.
49 if (chrome.tabs) 49 if (chrome.tabs && this.tabId_ != -1)
50 chrome.tabs.update({url: url}); 50 chrome.tabs.update(this.tabId_, {url: url});
51 else 51 else
52 window.location.href = url; 52 window.location.href = url;
53 } 53 }
54 54
55 /** 55 /**
56 * Called when navigation happens in the new tab. 56 * Called when navigation happens in the new tab.
57 * @param {string} url The url to be opened in the new tab. 57 * @param {string} url The url to be opened in the new tab.
58 */ 58 */
59 function onNavigateInNewTab(url) { 59 function onNavigateInNewTab(url) {
60 // Prefer the tabs API because it guarantees we can just open a new tab. 60 // Prefer the tabs API because it guarantees we can just open a new tab.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 * @param {!BrowserApi} browserApi An object providing an API to the browser. 111 * @param {!BrowserApi} browserApi An object providing an API to the browser.
112 */ 112 */
113 function PDFViewer(browserApi) { 113 function PDFViewer(browserApi) {
114 this.browserApi_ = browserApi; 114 this.browserApi_ = browserApi;
115 this.loadState_ = LoadState.LOADING; 115 this.loadState_ = LoadState.LOADING;
116 this.parentWindow_ = null; 116 this.parentWindow_ = null;
117 this.parentOrigin_ = null; 117 this.parentOrigin_ = null;
118 118
119 this.delayedScriptingMessages_ = []; 119 this.delayedScriptingMessages_ = [];
120 120
121 this.tabId_ = this.browserApi_.getStreamInfo().tabId;
121 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf( 122 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf(
122 'chrome://print') == 0; 123 'chrome://print') == 0;
123 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html'; 124 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html';
124 125
125 // The sizer element is placed behind the plugin element to cause scrollbars 126 // The sizer element is placed behind the plugin element to cause scrollbars
126 // to be displayed in the window. It is sized according to the document size 127 // to be displayed in the window. It is sized according to the document size
127 // of the pdf and zoom level. 128 // of the pdf and zoom level.
128 this.sizer_ = $('sizer'); 129 this.sizer_ = $('sizer');
129 this.toolbar_ = $('toolbar'); 130 this.toolbar_ = $('toolbar');
130 if (!this.isMaterial_ || this.isPrintPreview_) 131 if (!this.isMaterial_ || this.isPrintPreview_)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
250 // Parse open pdf parameters. 251 // Parse open pdf parameters.
251 this.paramsParser_ = 252 this.paramsParser_ =
252 new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); 253 new OpenPDFParamsParser(this.getNamedDestination_.bind(this));
253 this.navigator_ = new Navigator(this.browserApi_.getStreamInfo().originalUrl, 254 this.navigator_ = new Navigator(this.tabId_,
255 this.browserApi_.getStreamInfo().originalUrl,
254 this.viewport_, this.paramsParser_, 256 this.viewport_, this.paramsParser_,
255 onNavigateInCurrentTab, onNavigateInNewTab); 257 onNavigateInCurrentTab, onNavigateInNewTab);
raymes 2015/09/24 00:09:42 can we bind the tabId to onNavigateInCurrentTab ra
256 this.viewportScroller_ = 258 this.viewportScroller_ =
257 new ViewportScroller(this.viewport_, this.plugin_, window); 259 new ViewportScroller(this.viewport_, this.plugin_, window);
258 } 260 }
259 261
260 PDFViewer.prototype = { 262 PDFViewer.prototype = {
261 /** 263 /**
262 * @private 264 * @private
263 * Handle key events. These may come from the user directly or via the 265 * Handle key events. These may come from the user directly or via the
264 * scripting API. 266 * scripting API.
265 * @param {KeyboardEvent} e the event to handle. 267 * @param {KeyboardEvent} e the event to handle.
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 * Each bookmark is an Object containing a: 874 * Each bookmark is an Object containing a:
873 * - title 875 * - title
874 * - page (optional) 876 * - page (optional)
875 * - array of children (themselves bookmarks) 877 * - array of children (themselves bookmarks)
876 * @type {Array} the top-level bookmarks of the PDF. 878 * @type {Array} the top-level bookmarks of the PDF.
877 */ 879 */
878 get bookmarks() { 880 get bookmarks() {
879 return this.bookmarks_; 881 return this.bookmarks_;
880 } 882 }
881 }; 883 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/navigator.js ('k') | chrome/test/data/pdf/navigator_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698