Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <include src="../../../../ui/webui/resources/js/util.js"> | 7 <include src="../../../../ui/webui/resources/js/util.js"> |
| 8 <include src="pdf_scripting_api.js"> | 8 <include src="pdf_scripting_api.js"> |
| 9 <include src="viewport.js"> | 9 <include src="viewport.js"> |
| 10 | 10 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 * @private | 257 * @private |
| 258 * Notify the plugin to print. | 258 * Notify the plugin to print. |
| 259 */ | 259 */ |
| 260 print_: function() { | 260 print_: function() { |
| 261 this.plugin_.postMessage({ | 261 this.plugin_.postMessage({ |
| 262 type: 'print', | 262 type: 'print', |
| 263 }); | 263 }); |
| 264 }, | 264 }, |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * Handle zoom parameter of open PDF parameters. If this | |
| 268 * parameter is passed while opening PDF then PDF should be opened | |
| 269 * at the specified zoom level. | |
| 270 * @param {number} zoom value. | |
| 271 */ | |
| 272 handleZoomParam_: function(paramValue) { | |
| 273 var paramValueSplit = paramValue.split(','); | |
| 274 if ((paramValueSplit.length != 1) && (paramValueSplit.length != 3)) | |
| 275 return; | |
| 276 | |
| 277 // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0. | |
| 278 var zoomFactor = parseFloat(paramValueSplit[0]) / 100; | |
| 279 | |
| 280 // Handle #zoom=scale. | |
| 281 if (paramValueSplit.length == 1) { | |
| 282 this.viewport_.setZoom(zoomFactor); | |
|
Nikhil
2014/08/19 15:09:42
setZoom() isn't working as intended. Is this not t
raymes
2014/08/20 00:14:21
This looks correct. What is it that isn't working?
Nikhil
2014/08/20 04:46:55
It didn't work as intended since zoom didn't chang
Nikhil
2014/08/21 11:36:50
It wasn't working because chrome.tabs.onZoomChange
| |
| 283 return; | |
| 284 } | |
| 285 | |
| 286 // Handle #zoom=scale,left,top. | |
| 287 var position = {x: parseFloat(paramValueSplit[1]), | |
|
Lei Zhang
2014/08/20 00:37:07
The Adobe open parameters document is rather vague
Nikhil
2014/08/20 04:46:54
Yep, it's a bit vague on units. Unlike page which
| |
| 288 y: parseFloat(paramValueSplit[2])}; | |
| 289 this.viewport_.position = position; | |
| 290 this.viewport_.setZoom(zoomFactor); | |
| 291 }, | |
| 292 | |
| 293 /** | |
| 267 * @private | 294 * @private |
| 268 * Handle open PDF parameters. These parameters are mentioned in the URL | 295 * Handle open PDF parameters. These parameters are mentioned in the URL |
| 269 * and specify actions to be performed when opening PDF files. | 296 * and specify actions to be performed when opening PDF files. |
| 270 * See http://crbug.com/64309 for details. | 297 * See http://crbug.com/64309 for details. |
|
raymes
2014/08/20 00:14:21
nit: we don't need the crbug link,but a link to a
Nikhil
2014/08/21 11:36:50
Done.
| |
| 271 */ | 298 */ |
| 272 handleOpenPDFParams_: function() { | 299 handleOpenPDFParams_: function() { |
| 273 var originalUrl = this.streamDetails.originalUrl; | 300 var originalUrl = this.streamDetails.originalUrl; |
| 274 var paramIndex = originalUrl.search('#'); | 301 var paramIndex = originalUrl.search('#'); |
| 275 if (paramIndex == -1) | 302 if (paramIndex == -1) |
| 276 return; | 303 return; |
| 277 | 304 |
| 278 var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); | 305 var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); |
| 279 var paramsDictionary = {}; | 306 var paramsDictionary = {}; |
| 280 for (var i = 0; i < paramTokens.length; ++i) { | 307 for (var i = 0; i < paramTokens.length; ++i) { |
| 281 var keyValueSplit = paramTokens[i].split('='); | 308 var keyValueSplit = paramTokens[i].split('='); |
| 282 if (keyValueSplit.length != 2) | 309 if (keyValueSplit.length != 2) |
| 283 continue; | 310 continue; |
| 284 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; | 311 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; |
| 285 } | 312 } |
| 286 | 313 |
| 287 // Order is important as later actions can override the effects | 314 // Order is important as later actions can override the effects |
| 288 // of previous actions. | 315 // of previous actions. |
| 289 if ('page' in paramsDictionary) { | 316 if ('page' in paramsDictionary) { |
| 290 // value is 1-based. | 317 // value is 1-based. |
| 291 this.viewport_.goToPage(paramsDictionary['page'] - 1); | 318 this.viewport_.goToPage(paramsDictionary['page'] - 1); |
| 292 } | 319 } |
| 320 if ('zoom' in paramsDictionary) | |
|
Lei Zhang
2014/08/20 00:37:07
I think order might also matter between page and z
Nikhil
2014/08/20 04:46:55
As I understand, page should always be handled bef
| |
| 321 this.handleZoomParam_(paramsDictionary['zoom']); | |
| 293 }, | 322 }, |
| 294 | 323 |
| 295 /** | 324 /** |
| 296 * @private | 325 * @private |
| 297 * Update the loading progress of the document in response to a progress | 326 * Update the loading progress of the document in response to a progress |
| 298 * message being received from the plugin. | 327 * message being received from the plugin. |
| 299 * @param {number} progress the progress as a percentage. | 328 * @param {number} progress the progress as a percentage. |
| 300 */ | 329 */ |
| 301 updateProgress_: function(progress) { | 330 updateProgress_: function(progress) { |
| 302 this.progressBar_.progress = progress; | 331 this.progressBar_.progress = progress; |
| 303 if (progress == -1) { | 332 if (progress == -1) { |
| 304 // Document load failed. | 333 // Document load failed. |
| 305 this.errorScreen_.style.visibility = 'visible'; | 334 this.errorScreen_.style.visibility = 'visible'; |
| 306 this.sizer_.style.display = 'none'; | 335 this.sizer_.style.display = 'none'; |
| 307 this.toolbar_.style.visibility = 'hidden'; | 336 this.toolbar_.style.visibility = 'hidden'; |
| 308 if (this.passwordScreen_.active) { | 337 if (this.passwordScreen_.active) { |
| 309 this.passwordScreen_.deny(); | 338 this.passwordScreen_.deny(); |
| 310 this.passwordScreen_.active = false; | 339 this.passwordScreen_.active = false; |
| 311 } | 340 } |
| 312 } else if (progress == 100) { | 341 } else if (progress == 100) { |
| 313 // Document load complete. | 342 // Document load complete. |
| 314 this.handleOpenPDFParams_(); | 343 this.handleOpenPDFParams_(); |
| 315 this.loaded = true; | 344 this.loaded = true; |
| 316 var loadEvent = new Event('pdfload'); | 345 var loadEvent = new Event('pdfload'); |
| 317 window.dispatchEvent(loadEvent); | 346 window.dispatchEvent(loadEvent); |
| 318 this.sendScriptingMessage_({ | 347 this.sendScriptingMessage_({ |
| 319 type: 'documentLoaded' | 348 type: 'documentLoaded' |
| 320 }); | 349 }); |
| 321 if (this.lastViewportPosition_) | 350 if (this.lastViewportPosition_) |
| 322 this.viewport_.position = this.lastViewportPosition_; | 351 this.viewport_.position = this.lastViewportPosition_; |
|
raymes
2014/08/20 00:14:21
It shouldn't make a difference at present but I th
Nikhil
2014/08/21 11:36:50
Done.
| |
| 323 } | 352 } |
| 324 }, | 353 }, |
| 325 | 354 |
| 326 /** | 355 /** |
| 327 * @private | 356 * @private |
| 328 * An event handler for handling password-submitted events. These are fired | 357 * An event handler for handling password-submitted events. These are fired |
| 329 * when an event is entered into the password screen. | 358 * when an event is entered into the password screen. |
| 330 * @param {Object} event a password-submitted event. | 359 * @param {Object} event a password-submitted event. |
| 331 */ | 360 */ |
| 332 onPasswordSubmitted_: function(event) { | 361 onPasswordSubmitted_: function(event) { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 | 598 |
| 570 /** | 599 /** |
| 571 * @type {Viewport} the viewport of the PDF viewer. | 600 * @type {Viewport} the viewport of the PDF viewer. |
| 572 */ | 601 */ |
| 573 get viewport() { | 602 get viewport() { |
| 574 return this.viewport_; | 603 return this.viewport_; |
| 575 } | 604 } |
| 576 }; | 605 }; |
| 577 | 606 |
| 578 var viewer = new PDFViewer(); | 607 var viewer = new PDFViewer(); |
| OLD | NEW |