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

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

Issue 838723003: Testcases for nameddests and navigate for PDF (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 10 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 | 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 Navigator for navigating to links inside or outside the PDF. 8 * Creates a new Navigator for navigating to links inside or outside the PDF.
9 * @param {string} originalUrl The original page URL. 9 * @param {string} originalUrl The original page URL.
10 * @param {Object} viewport The viewport info of the page. 10 * @param {Object} viewport The viewport info of the page.
11 * @param {Object} paramsParser The object for URL parsing. 11 * @param {Object} paramsParser The object for URL parsing.
12 * @param {Function} navigateInCurrentTabCallback The Callback function that
13 * gets called when navigation happens in the current tab.
14 * @param {Function} navigateInNewTabCallback The Callback function that gets
15 * called when navigation happens in the new tab.
12 */ 16 */
13 function Navigator(originalUrl, viewport, paramsParser) { 17 function Navigator(originalUrl,
18 viewport,
19 paramsParser,
20 navigateInCurrentTabCallback,
21 navigateInNewTabCallback) {
14 this.originalUrl_ = originalUrl; 22 this.originalUrl_ = originalUrl;
15 this.viewport_ = viewport; 23 this.viewport_ = viewport;
16 this.paramsParser_ = paramsParser; 24 this.paramsParser_ = paramsParser;
25 this.navigateInCurrentTabCallback_ = navigateInCurrentTabCallback;
26 this.navigateInNewTabCallback_ = navigateInNewTabCallback;
17 } 27 }
18 28
19 Navigator.prototype = { 29 Navigator.prototype = {
20 /** 30 /**
21 * @private 31 * @private
22 * Function to navigate to the given URL. This might involve navigating 32 * Function to navigate to the given URL. This might involve navigating
23 * within the PDF page or opening a new url (in the same tab or a new tab). 33 * within the PDF page or opening a new url (in the same tab or a new tab).
24 * @param {string} url The URL to navigate to. 34 * @param {string} url The URL to navigate to.
25 * @param {boolean} newTab Whether to perform the navigation in a new tab or 35 * @param {boolean} newTab Whether to perform the navigation in a new tab or
26 * in the current tab. 36 * in the current tab.
(...skipping 28 matching lines...) Expand all
55 // Make sure inputURL is not only a scheme. 65 // Make sure inputURL is not only a scheme.
56 if (url == 'http://' || 66 if (url == 'http://' ||
57 url == 'https://' || 67 url == 'https://' ||
58 url == 'ftp://' || 68 url == 'ftp://' ||
59 url == 'file://' || 69 url == 'file://' ||
60 url == 'mailto:') { 70 url == 'mailto:') {
61 return; 71 return;
62 } 72 }
63 73
64 if (newTab) { 74 if (newTab) {
65 // Prefer the tabs API because it guarantees we can just open a new tab. 75 this.navigateInNewTabCallback_(url);
66 // window.open doesn't have this guarantee.
67 if (chrome.tabs)
68 chrome.tabs.create({ url: url });
69 else
70 window.open(url);
71 } else { 76 } else {
72 var pageNumber = 77 var pageNumber =
73 this.paramsParser_.getViewportFromUrlParams(url).page; 78 this.paramsParser_.getViewportFromUrlParams(url).page;
74 if (pageNumber != undefined) 79 if (pageNumber != undefined)
75 this.viewport_.goToPage(pageNumber); 80 this.viewport_.goToPage(pageNumber);
76 else 81 else
77 window.location.href = url; 82 this.navigateInCurrentTabCallback_(url);
78 } 83 }
79 } 84 }
80 }; 85 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698