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

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: Addressing nit. 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
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 = {
30
31 /**
32 * @private
33 * Called when navigation happens in the current tab.
34 * @param {string} url The url to be opened in the current tab.
35 */
36 navigateInCurrentTab_: function(url) {
37 window.location.href = url;
38 this.navigateInCurrentTabCallback_();
39 },
40
41 /**
42 * @private
43 * Called when navigation happens in the new tab.
44 * @param {string} url The url to be opened in the new tab.
45 */
46 navigateInNewTab_: function(url) {
raymes 2015/01/30 03:45:03 These functions should be defined inside pdf.js an
Deepak 2015/01/30 04:39:21 Done.
47 if (chrome.tabs)
48 chrome.tabs.create({ url: url});
49 else
50 window.open(url);
51 this.navigateInNewTabCallback_();
52 },
53
20 /** 54 /**
21 * @private 55 * @private
22 * Function to navigate to the given URL. This might involve navigating 56 * 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). 57 * 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. 58 * @param {string} url The URL to navigate to.
25 * @param {boolean} newTab Whether to perform the navigation in a new tab or 59 * @param {boolean} newTab Whether to perform the navigation in a new tab or
26 * in the current tab. 60 * in the current tab.
27 */ 61 */
28 navigate: function(url, newTab) { 62 navigate: function(url, newTab) {
29 if (url.length == 0) 63 if (url.length == 0)
(...skipping 25 matching lines...) Expand all
55 // Make sure inputURL is not only a scheme. 89 // Make sure inputURL is not only a scheme.
56 if (url == 'http://' || 90 if (url == 'http://' ||
57 url == 'https://' || 91 url == 'https://' ||
58 url == 'ftp://' || 92 url == 'ftp://' ||
59 url == 'file://' || 93 url == 'file://' ||
60 url == 'mailto:') { 94 url == 'mailto:') {
61 return; 95 return;
62 } 96 }
63 97
64 if (newTab) { 98 if (newTab) {
65 // Prefer the tabs API because it guarantees we can just open a new tab. 99 this.navigateInNewTab_(url);
raymes 2015/01/30 03:45:03 this should just call this.navigateInNewTabCallbac
Deepak 2015/01/30 04:39:21 Done.
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 { 100 } else {
72 var pageNumber = 101 var pageNumber =
73 this.paramsParser_.getViewportFromUrlParams(url).page; 102 this.paramsParser_.getViewportFromUrlParams(url).page;
74 if (pageNumber != undefined) 103 if (pageNumber != undefined)
75 this.viewport_.goToPage(pageNumber); 104 this.viewport_.goToPage(pageNumber);
76 else 105 else
77 window.location.href = url; 106 this.navigateInCurrentTab_(url);
raymes 2015/01/30 03:45:03 this should just call this.navigateInCurrentTabCal
Deepak 2015/01/30 04:39:21 Done.
78 } 107 }
79 } 108 }
80 }; 109 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | chrome/test/data/pdf/navigator_test.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698