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

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

Issue 797183005: Add a mimeHandler extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@streams-lifetime
Patch Set: debug logspam 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 unified diff | Download patch
OLDNEW
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 /** 7 /**
8 * @return {number} Width of a scrollbar in pixels 8 * @return {number} Width of a scrollbar in pixels
9 */ 9 */
10 function getScrollbarWidth() { 10 function getScrollbarWidth() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 this.sizer_, 64 this.sizer_,
65 this.viewportChanged_.bind(this), 65 this.viewportChanged_.bind(this),
66 this.beforeZoom_.bind(this), 66 this.beforeZoom_.bind(this),
67 this.afterZoom_.bind(this), 67 this.afterZoom_.bind(this),
68 getScrollbarWidth()); 68 getScrollbarWidth());
69 // Create the plugin object dynamically so we can set its src. The plugin 69 // Create the plugin object dynamically so we can set its src. The plugin
70 // element is sized to fill the entire window and is set to be fixed 70 // element is sized to fill the entire window and is set to be fixed
71 // positioning, acting as a viewport. The plugin renders into this viewport 71 // positioning, acting as a viewport. The plugin renders into this viewport
72 // according to the scroll position of the window. 72 // according to the scroll position of the window.
73 this.plugin_ = document.createElement('embed'); 73 this.plugin_ = document.createElement('embed');
74 console.log('created plugin ' + this.plugin_ + ' ' +
75 this.plugin_.postMessage);
74 // NOTE: The plugin's 'id' field must be set to 'plugin' since 76 // NOTE: The plugin's 'id' field must be set to 'plugin' since
75 // chrome/renderer/printing/print_web_view_helper.cc actually references it. 77 // chrome/renderer/printing/print_web_view_helper.cc actually references it.
76 this.plugin_.id = 'plugin'; 78 this.plugin_.id = 'plugin';
77 this.plugin_.type = 'application/x-google-chrome-pdf'; 79 this.plugin_.type = 'application/x-google-chrome-pdf';
78 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), 80 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this),
79 false); 81 false);
80 82
81 // Handle scripting messages from outside the extension that wish to interact 83 // Handle scripting messages from outside the extension that wish to interact
82 // with it. We also send a message indicating that extension has loaded and 84 // with it. We also send a message indicating that extension has loaded and
83 // is ready to receive messages. 85 // is ready to receive messages.
84 window.addEventListener('message', this.handleScriptingMessage.bind(this), 86 window.addEventListener('message', this.handleScriptingMessage.bind(this),
85 false); 87 false);
86 88
87 document.title = getFilenameFromURL(this.streamDetails_.originalUrl); 89 document.title = getFilenameFromURL(this.streamDetails_.originalUrl);
88 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl); 90 this.plugin_.setAttribute('src', this.streamDetails_.originalUrl);
89 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl); 91 this.plugin_.setAttribute('stream-url', this.streamDetails_.streamUrl);
90 var headers = ''; 92 var headers = '';
91 for (var header in this.streamDetails_.responseHeaders) { 93 for (var header in this.streamDetails_.responseHeaders) {
92 headers += header + ': ' + 94 headers += header + ': ' +
93 this.streamDetails_.responseHeaders[header] + '\n'; 95 this.streamDetails_.responseHeaders[header] + '\n';
94 } 96 }
95 this.plugin_.setAttribute('headers', headers); 97 this.plugin_.setAttribute('headers', headers);
96 98
97 if (!this.streamDetails_.embedded) 99 if (!this.streamDetails_.embedded)
98 this.plugin_.setAttribute('full-frame', ''); 100 this.plugin_.setAttribute('full-frame', '');
99 document.body.appendChild(this.plugin_); 101 document.body.appendChild(this.plugin_);
102 console.log('added plugin to DOM ' + this.plugin_ + ' ' +
103 this.plugin_.postMessage);
100 104
101 // Setup the button event listeners. 105 // Setup the button event listeners.
102 $('fit-to-width-button').addEventListener('click', 106 $('fit-to-width-button').addEventListener('click',
103 this.viewport_.fitToWidth.bind(this.viewport_)); 107 this.viewport_.fitToWidth.bind(this.viewport_));
104 $('fit-to-page-button').addEventListener('click', 108 $('fit-to-page-button').addEventListener('click',
105 this.viewport_.fitToPage.bind(this.viewport_)); 109 this.viewport_.fitToPage.bind(this.viewport_));
106 $('zoom-in-button').addEventListener('click', 110 $('zoom-in-button').addEventListener('click',
107 this.viewport_.zoomIn.bind(this.viewport_)); 111 this.viewport_.zoomIn.bind(this.viewport_));
108 $('zoom-out-button').addEventListener('click', 112 $('zoom-out-button').addEventListener('click',
109 this.viewport_.zoomOut.bind(this.viewport_)); 113 this.viewport_.zoomOut.bind(this.viewport_));
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 position.y = message.data.y; 401 position.y = message.data.y;
398 this.viewport_.position = position; 402 this.viewport_.position = position;
399 break; 403 break;
400 case 'setTranslatedStrings': 404 case 'setTranslatedStrings':
401 this.passwordScreen_.text = message.data.getPasswordString; 405 this.passwordScreen_.text = message.data.getPasswordString;
402 this.progressBar_.text = message.data.loadingString; 406 this.progressBar_.text = message.data.loadingString;
403 this.progressBar_.style.visibility = 'visible'; 407 this.progressBar_.style.visibility = 'visible';
404 this.errorScreen_.text = message.data.loadFailedString; 408 this.errorScreen_.text = message.data.loadFailedString;
405 break; 409 break;
406 case 'cancelStreamUrl': 410 case 'cancelStreamUrl':
407 chrome.streamsPrivate.abort(this.streamDetails_.streamUrl); 411 chrome.mimeHandlerPrivate.abortStream();
408 break; 412 break;
409 } 413 }
410 }, 414 },
411 415
412 /** 416 /**
413 * @private 417 * @private
414 * A callback that's called before the zoom changes. Notify the plugin to stop 418 * A callback that's called before the zoom changes. Notify the plugin to stop
415 * reacting to scroll events while zoom is taking place to avoid flickering. 419 * reacting to scroll events while zoom is taking place to avoid flickering.
416 */ 420 */
417 beforeZoom_: function() { 421 beforeZoom_: function() {
418 this.plugin_.postMessage({ 422 this.plugin_.postMessage({
419 type: 'stopScrolling' 423 type: 'stopScrolling'
420 }); 424 });
421 }, 425 },
422 426
423 /** 427 /**
424 * @private 428 * @private
425 * A callback that's called after the zoom changes. Notify the plugin of the 429 * A callback that's called after the zoom changes. Notify the plugin of the
426 * zoom change and to continue reacting to scroll events. 430 * zoom change and to continue reacting to scroll events.
427 */ 431 */
428 afterZoom_: function() { 432 afterZoom_: function() {
429 var position = this.viewport_.position; 433 var position = this.viewport_.position;
430 var zoom = this.viewport_.zoom; 434 var zoom = this.viewport_.zoom;
431 if (this.shouldManageZoom_() && !this.setZoomInProgress_) { 435 if (this.shouldManageZoom_() && !this.setZoomInProgress_) {
432 this.setZoomInProgress_ = true; 436 this.setZoomInProgress_ = true;
433 chrome.tabs.setZoom(this.streamDetails_.tabId, zoom, 437 chrome.tabs.setZoom(this.streamDetails_.tabId, zoom,
434 this.setZoomComplete_.bind(this, zoom)); 438 this.setZoomComplete_.bind(this, zoom));
435 } 439 }
440 console.log('afterZoom_ ' + this.plugin_ + ' ' + this.plugin_.postMessage);
436 this.plugin_.postMessage({ 441 this.plugin_.postMessage({
437 type: 'viewport', 442 type: 'viewport',
438 zoom: zoom, 443 zoom: zoom,
439 xOffset: position.x, 444 xOffset: position.x,
440 yOffset: position.y 445 yOffset: position.y
441 }); 446 });
442 }, 447 },
443 448
444 /** 449 /**
445 * @private 450 * @private
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 this.streamDetails_.tabId != -1); 610 this.streamDetails_.tabId != -1);
606 }, 611 },
607 612
608 /** 613 /**
609 * @type {Viewport} the viewport of the PDF viewer. 614 * @type {Viewport} the viewport of the PDF viewer.
610 */ 615 */
611 get viewport() { 616 get viewport() {
612 return this.viewport_; 617 return this.viewport_;
613 } 618 }
614 }; 619 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698