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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 this.sendScriptingMessage_({ | 288 this.sendScriptingMessage_({ |
| 289 type: 'documentLoaded' | 289 type: 'documentLoaded' |
| 290 }); | 290 }); |
| 291 if (this.lastViewportPosition_) | 291 if (this.lastViewportPosition_) |
| 292 this.viewport_.position = this.lastViewportPosition_; | 292 this.viewport_.position = this.lastViewportPosition_; |
| 293 } | 293 } |
| 294 }, | 294 }, |
| 295 | 295 |
| 296 /** | 296 /** |
| 297 * @private | 297 * @private |
| 298 * Handle page param of open PDF parameters. | |
| 299 * @param {number} page value. | |
| 300 */ | |
| 301 handlePageParam_: function(value) { | |
| 302 if (value > 0) { | |
| 303 // value is 1-based. | |
| 304 this.viewport_.goToPage(value - 1); | |
| 305 } | |
| 306 }, | |
|
raymes
2014/08/15 01:07:18
I would suggest just inlining this function. viewp
Nikhil
2014/08/16 10:24:01
Done.
| |
| 307 | |
| 308 /** | |
| 309 * @private | |
| 310 * Handle open PDF parameters. | |
| 311 */ | |
| 312 handleOpenPDFParams_: function() { | |
| 313 var originalUrl = this.streamDetails.originalUrl; | |
| 314 var hasParams = originalUrl.search('#'); | |
| 315 if (hasParams == -1) | |
| 316 return; | |
| 317 | |
| 318 var paramTokens = originalUrl.substring(hasParams + 1).split('&'); | |
| 319 // Handle the case of http://foo.com/bar#NAMEDDEST. This is not explicitly | |
| 320 // mentioned except by example in the Adobe "PDF Open Parameters" document. | |
| 321 if ((paramTokens.length == 1) && (paramTokens[0].search('=') == -1)) { | |
| 322 // FIXME: Send message for GetNamedDestinationPage(); | |
|
raymes
2014/08/15 01:07:18
Are you going to add support for this soon? If not
Nikhil
2014/08/16 10:24:01
Yes, I'm planning to add support for this soon in
raymes
2014/08/18 00:39:34
I had a look at the API that pdfium exposes and it
Nikhil
2014/08/18 04:53:32
I'll check it further.
| |
| 323 return; | |
| 324 } | |
| 325 | |
| 326 var paramsDictionary = {}; | |
| 327 for (var i = 0; i < paramTokens.length; ++i) { | |
| 328 var keyValueSplit = paramTokens[i].split('='); | |
| 329 if (keyValueSplit.length != 2) | |
| 330 continue; | |
| 331 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; | |
| 332 } | |
| 333 | |
| 334 // Order is important as later actions can override the effects | |
| 335 // of previous actions. | |
| 336 if ('page' in paramsDictionary) | |
| 337 this.handlePageParam_(paramsDictionary['page']); | |
| 338 }, | |
| 339 | |
| 340 /** | |
| 341 * @private | |
| 298 * An event handler for handling password-submitted events. These are fired | 342 * An event handler for handling password-submitted events. These are fired |
| 299 * when an event is entered into the password screen. | 343 * when an event is entered into the password screen. |
| 300 * @param {Object} event a password-submitted event. | 344 * @param {Object} event a password-submitted event. |
| 301 */ | 345 */ |
| 302 onPasswordSubmitted_: function(event) { | 346 onPasswordSubmitted_: function(event) { |
| 303 this.plugin_.postMessage({ | 347 this.plugin_.postMessage({ |
| 304 type: 'getPasswordComplete', | 348 type: 'getPasswordComplete', |
| 305 password: event.detail.password | 349 password: event.detail.password |
| 306 }); | 350 }); |
| 307 }, | 351 }, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 this.viewport_.position = position; | 409 this.viewport_.position = position; |
| 366 break; | 410 break; |
| 367 case 'setTranslatedStrings': | 411 case 'setTranslatedStrings': |
| 368 this.passwordScreen_.text = message.data.getPasswordString; | 412 this.passwordScreen_.text = message.data.getPasswordString; |
| 369 this.progressBar_.text = message.data.loadingString; | 413 this.progressBar_.text = message.data.loadingString; |
| 370 this.errorScreen_.text = message.data.loadFailedString; | 414 this.errorScreen_.text = message.data.loadFailedString; |
| 371 break; | 415 break; |
| 372 case 'cancelStreamUrl': | 416 case 'cancelStreamUrl': |
| 373 chrome.streamsPrivate.abort(this.streamDetails.streamUrl); | 417 chrome.streamsPrivate.abort(this.streamDetails.streamUrl); |
| 374 break; | 418 break; |
| 419 case 'openPDFParams': | |
| 420 this.handleOpenPDFParams_(); | |
|
raymes
2014/08/15 01:07:17
Rather than calling this here, we can get rid of t
Nikhil
2014/08/16 10:24:01
Done.
| |
| 421 break; | |
| 375 } | 422 } |
| 376 }, | 423 }, |
| 377 | 424 |
| 378 /** | 425 /** |
| 379 * @private | 426 * @private |
| 380 * A callback that's called before the zoom changes. Notify the plugin to stop | 427 * A callback that's called before the zoom changes. Notify the plugin to stop |
| 381 * reacting to scroll events while zoom is taking place to avoid flickering. | 428 * reacting to scroll events while zoom is taking place to avoid flickering. |
| 382 */ | 429 */ |
| 383 beforeZoom_: function() { | 430 beforeZoom_: function() { |
| 384 this.plugin_.postMessage({ | 431 this.plugin_.postMessage({ |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 | 586 |
| 540 /** | 587 /** |
| 541 * @type {Viewport} the viewport of the PDF viewer. | 588 * @type {Viewport} the viewport of the PDF viewer. |
| 542 */ | 589 */ |
| 543 get viewport() { | 590 get viewport() { |
| 544 return this.viewport_; | 591 return this.viewport_; |
| 545 } | 592 } |
| 546 }; | 593 }; |
| 547 | 594 |
| 548 var viewer = new PDFViewer(); | 595 var viewer = new PDFViewer(); |
| OLD | NEW |