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

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

Issue 2568903002: PDF viewer: Specify tabId when navigating with chrome.tabs.update. (Closed)
Patch Set: Fix nits. Created 4 years 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/pdf/pdf_extension_test.cc ('k') | chrome/browser/resources/pdf/pdf.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 * Creates a new NavigatorDelegate for calling browser-specific functions to 8 * Creates a new NavigatorDelegate for calling browser-specific functions to
9 * do the actual navigating. 9 * do the actual navigating.
10 * @param {boolean} isInTab Indicates if the PDF viewer is displayed in a tab. 10 * @param {number} tabId The tab ID of the PDF viewer or -1 if the viewer is
11 * not displayed in a tab.
11 */ 12 */
12 function NavigatorDelegate(isInTab) { 13 function NavigatorDelegate(tabId) {
13 this.isInTab_ = isInTab; 14 this.tabId_ = tabId;
14 } 15 }
15 16
16 /** 17 /**
17 * Creates a new Navigator for navigating to links inside or outside the PDF. 18 * Creates a new Navigator for navigating to links inside or outside the PDF.
18 * @param {string} originalUrl The original page URL. 19 * @param {string} originalUrl The original page URL.
19 * @param {Object} viewport The viewport info of the page. 20 * @param {Object} viewport The viewport info of the page.
20 * @param {Object} paramsParser The object for URL parsing. 21 * @param {Object} paramsParser The object for URL parsing.
21 * @param {Object} navigatorDelegate The object with callback functions that 22 * @param {Object} navigatorDelegate The object with callback functions that
22 * get called when navigation happens in the current tab, a new tab, 23 * get called when navigation happens in the current tab, a new tab,
23 * and a new window. 24 * and a new window.
24 */ 25 */
25 function Navigator(originalUrl, viewport, paramsParser, navigatorDelegate) { 26 function Navigator(originalUrl, viewport, paramsParser, navigatorDelegate) {
26 this.originalUrl_ = originalUrl; 27 this.originalUrl_ = originalUrl;
27 this.viewport_ = viewport; 28 this.viewport_ = viewport;
28 this.paramsParser_ = paramsParser; 29 this.paramsParser_ = paramsParser;
29 this.navigatorDelegate_ = navigatorDelegate; 30 this.navigatorDelegate_ = navigatorDelegate;
30 } 31 }
31 32
32 NavigatorDelegate.prototype = { 33 NavigatorDelegate.prototype = {
33 /** 34 /**
34 * @public 35 * @public
35 * Called when navigation should happen in the current tab. 36 * Called when navigation should happen in the current tab.
36 * @param {string} url The url to be opened in the current tab. 37 * @param {string} url The url to be opened in the current tab.
37 */ 38 */
38 navigateInCurrentTab: function(url) { 39 navigateInCurrentTab: function(url) {
39 // When the PDFviewer is inside a browser tab, prefer the tabs API because 40 // When the PDFviewer is inside a browser tab, prefer the tabs API because
40 // it can navigate from one file:// URL to another. 41 // it can navigate from one file:// URL to another.
41 if (chrome.tabs && this.isInTab_) 42 if (chrome.tabs && this.tabId_ != -1)
42 chrome.tabs.update({url: url}); 43 chrome.tabs.update(this.tabId_, {url: url});
43 else 44 else
44 window.location.href = url; 45 window.location.href = url;
45 }, 46 },
46 47
47 /** 48 /**
48 * @public 49 * @public
49 * Called when navigation should happen in the new tab. 50 * Called when navigation should happen in the new tab.
50 * @param {string} url The url to be opened in the new tab. 51 * @param {string} url The url to be opened in the new tab.
51 * @param {boolean} active Indicates if the new tab should be the active tab. 52 * @param {boolean} active Indicates if the new tab should be the active tab.
52 */ 53 */
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 if (isRelative) { 253 if (isRelative) {
253 var slashIndex = this.originalUrl_.lastIndexOf('/'); 254 var slashIndex = this.originalUrl_.lastIndexOf('/');
254 var path = slashIndex != -1 ? 255 var path = slashIndex != -1 ?
255 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; 256 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_;
256 return path + '/' + url; 257 return path + '/' + url;
257 } 258 }
258 259
259 return 'http://' + url; 260 return 'http://' + url;
260 } 261 }
261 }; 262 };
OLDNEW
« no previous file with comments | « chrome/browser/pdf/pdf_extension_test.cc ('k') | chrome/browser/resources/pdf/pdf.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698