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

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 "pdf_engine.h" and they need to stay in sync.
32 * @enum {number}
33 */
34 Navigator.NavigateOption = {
35 OPEN_IN_CURRENT_TAB: 0,
36 OPEN_IN_NEW_BACKGROUND_TAB: 1,
37 OPEN_IN_NEW_FOREGROUND_TAB: 2,
38 OPEN_IN_NEW_WINDOW: 3
39 };
40
29 Navigator.prototype = { 41 Navigator.prototype = {
30 /** 42 /**
31 * @private 43 * @private
32 * Function to navigate to the given URL. This might involve navigating 44 * 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). 45 * 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. 46 * @param {string} url The URL to navigate to.
35 * @param {boolean} newTab Whether to perform the navigation in a new tab or 47 * @param {boolean} newTab Whether to perform the navigation in a new tab or
36 * in the current tab. 48 * in the current tab.
37 */ 49 */
38 navigate: function(url, newTab) { 50 navigate: function(url, navigateOption) {
39 if (url.length == 0) 51 if (url.length == 0)
40 return; 52 return;
41 53
42 // If |urlFragment| starts with '#', then it's for the same URL with a 54 // If |urlFragment| starts with '#', then it's for the same URL with a
43 // different URL fragment. 55 // different URL fragment.
44 if (url.charAt(0) == '#') { 56 if (url.charAt(0) == '#') {
45 // if '#' is already present in |originalUrl| then remove old fragment 57 // if '#' is already present in |originalUrl| then remove old fragment
46 // and add new url fragment. 58 // and add new url fragment.
47 var hashIndex = this.originalUrl_.search('#'); 59 var hashIndex = this.originalUrl_.search('#');
48 if (hashIndex != -1) 60 if (hashIndex != -1)
49 url = this.originalUrl_.substring(0, hashIndex) + url; 61 url = this.originalUrl_.substring(0, hashIndex) + url;
50 else 62 else
51 url = this.originalUrl_ + url; 63 url = this.originalUrl_ + url;
52 } 64 }
53 65
54 // If there's no scheme, then take a guess at the scheme. 66 // If there's no scheme, then take a guess at the scheme.
55 if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1) 67 if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1)
56 url = this.guessUrlWithoutScheme_(url); 68 url = this.guessUrlWithoutScheme_(url);
57 69
58 if (!this.isValidUrl_(url)) 70 if (!this.isValidUrl_(url))
59 return; 71 return;
60 72
61 if (newTab) { 73 var NavigateOption = Navigator.NavigateOption;
62 this.navigateInNewBackgroundTabCallback_(url); 74 switch (navigateOption) {
63 } else { 75 case NavigateOption.OPEN_IN_CURRENT_TAB:
64 this.paramsParser_.getViewportFromUrlParams( 76 case NavigateOption.OPEN_IN_NEW_WINDOW:
65 url, this.onViewportReceived_.bind(this)); 77 // TODO (jaepark): It should navigate in a new window when
78 // shift + left clicking link in PDFs. See http://crbug.com/628057.
79 this.paramsParser_.getViewportFromUrlParams(
80 url, this.onViewportReceived_.bind(this));
81 break;
82 case NavigateOption.OPEN_IN_NEW_BACKGROUND_TAB:
83 this.navigateInNewTabCallback_(url, false);
84 break;
85 case NavigateOption.OPEN_IN_NEW_FOREGROUND_TAB:
86 this.navigateInNewTabCallback_(url, true);
87 break;
88 default:
89 break;
66 } 90 }
67 }, 91 },
68 92
69 /** 93 /**
70 * @private 94 * @private
71 * Called when the viewport position is received. 95 * Called when the viewport position is received.
72 * @param {Object} viewportPosition Dictionary containing the viewport 96 * @param {Object} viewportPosition Dictionary containing the viewport
73 * position. 97 * position.
74 */ 98 */
75 onViewportReceived_: function(viewportPosition) { 99 onViewportReceived_: function(viewportPosition) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 if (isRelative) { 192 if (isRelative) {
169 var slashIndex = this.originalUrl_.lastIndexOf('/'); 193 var slashIndex = this.originalUrl_.lastIndexOf('/');
170 var path = slashIndex != -1 ? 194 var path = slashIndex != -1 ?
171 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; 195 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_;
172 return path + '/' + url; 196 return path + '/' + url;
173 } 197 }
174 198
175 return 'http://' + url; 199 return 'http://' + url;
176 } 200 }
177 }; 201 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698