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

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

Issue 2166193002: Handle ctrl + shift + left click on links in PDF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle ctrl + shift + left click on links in PDF. Created 4 years, 5 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 12 * @param {Function} navigateInCurrentTabCallback The Callback function that
13 * gets called when navigation happens in the current tab. 13 * gets called when navigation happens in the current tab.
14 * @param {Function} navigateInNewBackgroundTabCallback The Callback function 14 * @param {Function} navigateInNewTabCallback The Callback function
15 * that gets called when navigation happens in the new background tab. 15 * that gets called when navigation happens in the new tab.
16 */ 16 */
17 function Navigator(originalUrl, 17 function Navigator(originalUrl,
18 viewport, 18 viewport,
19 paramsParser, 19 paramsParser,
20 navigateInCurrentTabCallback, 20 navigateInCurrentTabCallback,
21 navigateInNewBackgroundTabCallback) { 21 navigateInNewTabCallback) {
22 this.originalUrl_ = originalUrl; 22 this.originalUrl_ = originalUrl;
23 this.viewport_ = viewport; 23 this.viewport_ = viewport;
24 this.paramsParser_ = paramsParser; 24 this.paramsParser_ = paramsParser;
25 this.navigateInCurrentTabCallback_ = navigateInCurrentTabCallback; 25 this.navigateInCurrentTabCallback_ = navigateInCurrentTabCallback;
26 this.navigateInNewBackgroundTabCallback_ = navigateInNewBackgroundTabCallback; 26 this.navigateInNewTabCallback_ = navigateInNewTabCallback;
27 } 27 }
28 28
29 /**
30 * Represents options when navigating to a new url. C++ counterpart of
31 * the enum is in ui/base/window_open_disposition.h. This enum represents
32 * the only values that are passed from Plugin.
33 * @enum {number}
34 */
35 Navigator.WindowOpenDisposition = {
36 CURRENT_TAB: 1,
37 NEW_FOREGROUND_TAB: 3,
38 NEW_BACKGROUND_TAB: 4,
39 NEW_WINDOW: 6,
40 SAVE_TO_DISK: 7
41 };
42
29 Navigator.prototype = { 43 Navigator.prototype = {
30 /** 44 /**
31 * @private 45 * @private
32 * Function to navigate to the given URL. This might involve navigating 46 * Function to navigate to the given URL. This might involve navigating
33 * within the PDF page or opening a new url (in the same tab or a new tab). 47 * within the PDF page or opening a new url (in the same tab or a new tab).
34 * @param {string} url The URL to navigate to. 48 * @param {string} url The URL to navigate to.
35 * @param {boolean} newTab Whether to perform the navigation in a new tab or 49 * @param {boolean} newTab Whether to perform the navigation in a new tab or
Lei Zhang 2016/07/25 22:10:02 Doc is out of date.
jaepark 2016/07/25 23:24:13 Done.
36 * in the current tab. 50 * in the current tab.
37 */ 51 */
38 navigate: function(url, newTab) { 52 navigate: function(url, disposition) {
39 if (url.length == 0) 53 if (url.length == 0)
40 return; 54 return;
41 55
42 // If |urlFragment| starts with '#', then it's for the same URL with a 56 // If |urlFragment| starts with '#', then it's for the same URL with a
43 // different URL fragment. 57 // different URL fragment.
44 if (url.charAt(0) == '#') { 58 if (url.charAt(0) == '#') {
45 // if '#' is already present in |originalUrl| then remove old fragment 59 // if '#' is already present in |originalUrl| then remove old fragment
46 // and add new url fragment. 60 // and add new url fragment.
47 var hashIndex = this.originalUrl_.search('#'); 61 var hashIndex = this.originalUrl_.search('#');
48 if (hashIndex != -1) 62 if (hashIndex != -1)
49 url = this.originalUrl_.substring(0, hashIndex) + url; 63 url = this.originalUrl_.substring(0, hashIndex) + url;
50 else 64 else
51 url = this.originalUrl_ + url; 65 url = this.originalUrl_ + url;
52 } 66 }
53 67
54 // If there's no scheme, then take a guess at the scheme. 68 // If there's no scheme, then take a guess at the scheme.
55 if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1) 69 if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1)
56 url = this.guessUrlWithoutScheme_(url); 70 url = this.guessUrlWithoutScheme_(url);
57 71
58 if (!this.isValidUrl_(url)) 72 if (!this.isValidUrl_(url))
59 return; 73 return;
60 74
61 if (newTab) { 75 switch (disposition) {
62 this.navigateInNewBackgroundTabCallback_(url); 76 case Navigator.WindowOpenDisposition.CURRENT_TAB:
63 } else { 77 this.paramsParser_.getViewportFromUrlParams(
64 this.paramsParser_.getViewportFromUrlParams( 78 url, this.onViewportReceived_.bind(this));
65 url, this.onViewportReceived_.bind(this)); 79 break;
80 case Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB:
81 this.navigateInNewTabCallback_(url, false);
82 break;
83 case Navigator.WindowOpenDisposition.NEW_FOREGROUND_TAB:
84 this.navigateInNewTabCallback_(url, true);
85 break;
86 case Navigator.WindowOpenDisposition.NEW_WINDOW:
87 // TODO (jaepark): It should navigate in a new window when
Lei Zhang 2016/07/25 22:10:02 no space after "TODO"
jaepark 2016/07/25 23:24:13 Done.
88 // shift + left clicking link in PDFs. See http://crbug.com/628057.
89 break;
Lei Zhang 2016/07/25 22:10:02 Previously these fell through to SAVE_TO_DISK, whi
jaepark 2016/07/25 23:24:13 Done.
90 case Navigator.WindowOpenDisposition.SAVE_TO_DISK:
91 // TODO (jaepark) : Alt + left clicking link in PDFs should
92 // donwload the link.
93 break;
94 default:
95 break;
66 } 96 }
67 }, 97 },
68 98
69 /** 99 /**
70 * @private 100 * @private
71 * Called when the viewport position is received. 101 * Called when the viewport position is received.
72 * @param {Object} viewportPosition Dictionary containing the viewport 102 * @param {Object} viewportPosition Dictionary containing the viewport
73 * position. 103 * position.
74 */ 104 */
75 onViewportReceived_: function(viewportPosition) { 105 onViewportReceived_: function(viewportPosition) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 if (isRelative) { 198 if (isRelative) {
169 var slashIndex = this.originalUrl_.lastIndexOf('/'); 199 var slashIndex = this.originalUrl_.lastIndexOf('/');
170 var path = slashIndex != -1 ? 200 var path = slashIndex != -1 ?
171 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; 201 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_;
172 return path + '/' + url; 202 return path + '/' + url;
173 } 203 }
174 204
175 return 'http://' + url; 205 return 'http://' + url;
176 } 206 }
177 }; 207 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698