initialize webui with message handlers
This commit is contained in:
parent
a7ed7068f6
commit
8a2b9c893e
4 changed files with 81 additions and 88 deletions
|
@ -71,13 +71,13 @@ class BrowserApi {
|
|||
* @param {boolean} manageZoom Whether to manage zoom.
|
||||
*/
|
||||
static create(streamInfo, manageZoom) {
|
||||
/*return Promise.all([
|
||||
lookupDefaultZoom(streamInfo),
|
||||
lookupInitialZoom(streamInfo)
|
||||
]).then(function(zoomFactors) {*/
|
||||
return Promise.all([
|
||||
lookupDefaultZoom(streamInfo),
|
||||
lookupInitialZoom(streamInfo)
|
||||
]).then(function(zoomFactors) {
|
||||
return new BrowserApi(
|
||||
streamInfo, 1.0, 1.0, manageZoom);
|
||||
//});
|
||||
streamInfo, zoomFactors[0], zoomFactors[1], manageZoom);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,34 +143,12 @@ class BrowserApi {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a BrowserApi for an extension running as a mime handler.
|
||||
* @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed
|
||||
* using the mimeHandlerPrivate API.
|
||||
*/
|
||||
function createBrowserApiForMimeHandlerView() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
chrome.mimeHandlerPrivate.getStreamInfo(resolve);
|
||||
}).then(function(streamInfo) {
|
||||
let manageZoom = !streamInfo.embedded && streamInfo.tabId != -1;
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!manageZoom) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
chrome.tabs.setZoomSettings(
|
||||
streamInfo.tabId, {mode: 'manual', scope: 'per-tab'}, resolve);
|
||||
}).then(function() { return BrowserApi.create(streamInfo, manageZoom); });
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a BrowserApi instance for an extension not running as a mime handler.
|
||||
* @return {Promise<BrowserApi>} A promise to a BrowserApi instance constructed
|
||||
* from the URL.
|
||||
*/
|
||||
function createBrowserApi(streamURL, originalURL) {
|
||||
//let url = window.location.search.substring(1);
|
||||
let streamInfo = {
|
||||
streamUrl: streamURL,
|
||||
originalUrl: originalURL,
|
||||
|
@ -189,16 +167,3 @@ function createBrowserApi(streamURL, originalURL) {
|
|||
//});
|
||||
}).then(function() { return BrowserApi.create(streamInfo, false); });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a promise that will resolve to a BrowserApi instance.
|
||||
* @return {Promise<BrowserApi>} A promise to a BrowserApi instance for the
|
||||
* current environment.
|
||||
|
||||
function createBrowserApi(streamURL, originalURL) {
|
||||
//if (window.location.search)
|
||||
return createBrowserApiForStandaloneExtension();
|
||||
|
||||
//return createBrowserApiForMimeHandlerView();
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -10,46 +10,43 @@
|
|||
*/
|
||||
var viewer;
|
||||
|
||||
/**
|
||||
* Stores any pending messages received which should be passed to the
|
||||
* PDFViewer when it is created.
|
||||
* @type Array
|
||||
*/
|
||||
var pendingMessages = [];
|
||||
|
||||
//(function() {
|
||||
/**
|
||||
* Stores any pending messages received which should be passed to the
|
||||
* PDFViewer when it is created.
|
||||
* @type Array
|
||||
*/
|
||||
var pendingMessages = [];
|
||||
/**
|
||||
* Handles events that are received prior to the PDFViewer being created.
|
||||
* @param {Object} message A message event received.
|
||||
*/
|
||||
function handleScriptingMessage(message) {
|
||||
pendingMessages.push(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles events that are received prior to the PDFViewer being created.
|
||||
* @param {Object} message A message event received.
|
||||
*/
|
||||
function handleScriptingMessage(message) {
|
||||
pendingMessages.push(message);
|
||||
}
|
||||
/**
|
||||
* Initialize the global PDFViewer and pass any outstanding messages to it.
|
||||
* @param {Object} browserApi An object providing an API to the browser.
|
||||
*/
|
||||
function initViewer(browserApi) {
|
||||
// PDFViewer will handle any messages after it is created.
|
||||
window.removeEventListener('message', handleScriptingMessage, false);
|
||||
viewer = new PDFViewer(browserApi);
|
||||
while (pendingMessages.length > 0)
|
||||
viewer.handleScriptingMessage(pendingMessages.shift());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the global PDFViewer and pass any outstanding messages to it.
|
||||
* @param {Object} browserApi An object providing an API to the browser.
|
||||
*/
|
||||
function initViewer(browserApi) {
|
||||
// PDFViewer will handle any messages after it is created.
|
||||
window.removeEventListener('message', handleScriptingMessage, false);
|
||||
viewer = new PDFViewer(browserApi);
|
||||
while (pendingMessages.length > 0)
|
||||
viewer.handleScriptingMessage(pendingMessages.shift());
|
||||
}
|
||||
/**
|
||||
* Entrypoint for starting the PDF viewer. This function obtains the browser
|
||||
* API for the PDF and constructs a PDFViewer object with it.
|
||||
*/
|
||||
function main(streamURL, originalURL) {
|
||||
// Set up an event listener to catch scripting messages which are sent prior
|
||||
// to the PDFViewer being created.
|
||||
window.addEventListener('message', handleScriptingMessage, false);
|
||||
|
||||
/**
|
||||
* Entrypoint for starting the PDF viewer. This function obtains the browser
|
||||
* API for the PDF and constructs a PDFViewer object with it.
|
||||
*/
|
||||
function main(streamURL, originalURL) {
|
||||
// Set up an event listener to catch scripting messages which are sent prior
|
||||
// to the PDFViewer being created.
|
||||
window.addEventListener('message', handleScriptingMessage, false);
|
||||
createBrowserApi(streamURL, originalURL).then(initViewer);
|
||||
};
|
||||
|
||||
createBrowserApi(streamURL, originalURL).then(initViewer);
|
||||
};
|
||||
|
||||
//main();
|
||||
//})();
|
||||
chrome.send('initialize');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue