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

Unified Diff: chrome/browser/resources/pdf/pdf.js

Issue 855323002: Refactoring of code by moving navigate_() to separate file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/pdf/pdf.js
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
index cb4c9ac9912d5810841fc39e690339208cc8a7f1..0c2ba1fce9eb7a24cb96f15e9371f6ae229a643b 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -141,6 +141,7 @@ function PDFViewer(streamDetails) {
// Parse open pdf parameters.
this.paramsParser_ = new OpenPDFParamsParser();
+ this.navigator_ = new Navigator();
}
PDFViewer.prototype = {
@@ -347,68 +348,6 @@ PDFViewer.prototype = {
/**
* @private
- * Helper function to navigate to given URL. This might involve navigating
- * within the PDF page or opening a new url (in the same tab or a new tab).
- * @param {string} url The URL to navigate to.
- * @param {boolean} newTab Whether to perform the navigation in a new tab or
- * in the current tab.
- */
- navigate_: function(url, newTab) {
- if (url.length == 0)
- return;
- var originalUrl = this.streamDetails_.originalUrl;
- // If |urlFragment| starts with '#', then it's for the same URL with a
- // different URL fragment.
- if (url.charAt(0) == '#') {
- // if '#' is already present in |originalUrl| then remove old fragment
- // and add new url fragment.
- var hashIndex = originalUrl.search('#');
- if (hashIndex != -1)
- url = originalUrl.substring(0, hashIndex) + url;
- else
- url = originalUrl + url;
- }
-
- // If there's no scheme, add http.
- if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1)
- url = 'http://' + url;
-
- // Make sure url starts with a valid scheme.
- if (url.indexOf('http://') != 0 &&
- url.indexOf('https://') != 0 &&
- url.indexOf('ftp://') != 0 &&
- url.indexOf('file://') != 0 &&
- url.indexOf('mailto:') != 0) {
- return;
- }
- // Make sure url is not only a scheme.
- if (url == 'http://' ||
- url == 'https://' ||
- url == 'ftp://' ||
- url == 'file://' ||
- url == 'mailto:') {
- return;
- }
-
- if (newTab) {
- // Prefer the tabs API because it guarantees we can just open a new tab.
- // window.open doesn't have this guarantee.
- if (chrome.tabs)
- chrome.tabs.create({ url: url });
- else
- window.open(url);
- } else {
- var pageNumber =
- this.paramsParser_.getViewportFromUrlParams(url).page;
- if (pageNumber != undefined)
- this.viewport_.goToPage(pageNumber);
- else
- window.location.href = url;
- }
- },
-
- /**
- * @private
* An event handler for handling message events received from the plugin.
* @param {MessageObject} message a message event.
*/
@@ -453,10 +392,12 @@ PDFViewer.prototype = {
break;
case 'navigate':
// If in print preview, always open a new tab.
- if (this.isPrintPreview_)
+ if (this.isPrintPreview_) {
this.navigate_(message.data.url, true);
- else
- this.navigate_(message.data.url, message.data.newTab);
+ } else {
+ this.navigator_.navigate(message.data.url, message.data.newTab,
+ this.streamDetails_.originalUrl, this.viewport_, this.paramsParser_);
raymes 2015/01/21 07:03:44 Can you please pass in the original URL, viewport
Deepak 2015/01/21 08:33:41 Done.
+ }
break;
case 'setNamedDestinations':
this.paramsParser_.namedDestinations = message.data.namedDestinations;

Powered by Google App Engine
This is Rietveld 408576698