Making extensions/chromium/pdfHandler-v2.js adhere to the style guide and fixing a small lint issue in pdfHandler-vcros.js

This commit is contained in:
Tim van der Meij 2014-03-09 23:07:42 +01:00
parent 8ec46e6413
commit ce6e269d02
2 changed files with 237 additions and 221 deletions

View File

@ -25,7 +25,8 @@ if (!chrome.streamsPrivate) {
console.warn('streamsPrivate not available, PDF from FTP or POST ' +
'requests will not be displayed using this extension! ' +
'See http://crbug.com/326949');
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
chrome.runtime.onMessage.addListener(function(message, sender,
sendResponse) {
if (message && message.action === 'getPDFStream') {
sendResponse();
}
@ -49,7 +50,7 @@ var STREAM_NO_TABID = 0;
function hasStream(tabId, pdfUrl) {
var streams = urlToStream[streamSupportsTabId ? tabId : STREAM_NO_TABID];
return streams && streams[pdfUrl] && streams[pdfUrl].length > 0;
return (streams && streams[pdfUrl] && streams[pdfUrl].length > 0);
}
/**
@ -59,7 +60,9 @@ function hasStream(tabId, pdfUrl) {
* property contentLength (= expected size)
*/
function getStream(tabId, pdfUrl) {
if (!streamSupportsTabId) tabId = STREAM_NO_TABID;
if (!streamSupportsTabId) {
tabId = STREAM_NO_TABID;
}
if (hasStream(tabId, pdfUrl)) {
var streamInfo = urlToStream[tabId][pdfUrl].shift();
if (urlToStream[tabId][pdfUrl].length === 0) {
@ -74,8 +77,12 @@ function getStream(tabId, pdfUrl) {
function setStream(tabId, pdfUrl, streamUrl, expectedSize) {
tabId = tabId || STREAM_NO_TABID;
if (!urlToStream[tabId]) urlToStream[tabId] = {};
if (!urlToStream[tabId][pdfUrl]) urlToStream[tabId][pdfUrl] = [];
if (!urlToStream[tabId]) {
urlToStream[tabId] = {};
}
if (!urlToStream[tabId][pdfUrl]) {
urlToStream[tabId][pdfUrl] = [];
}
urlToStream[tabId][pdfUrl].push({
streamUrl: streamUrl,
contentLength: expectedSize
@ -115,19 +122,27 @@ function transferStreamToIncognitoProfile(tabId, pdfUrl) {
});
});
}
if (chrome.extension.inIncognitoContext) {
var importStream = function(itemId, streamInfo) {
if (itemId.lastIndexOf('streamInfo:', 0) !== 0) return;
console.log('Importing stream info from non-incognito profile', streamInfo);
handleStream('', streamInfo.pdfUrl, streamInfo.streamUrl, streamInfo.tabId,
streamInfo.contentLength);
if (itemId.lastIndexOf('streamInfo:', 0) !== 0) {
return;
}
console.log('Importing stream info from non-incognito profile',
streamInfo);
handleStream('', streamInfo.pdfUrl, streamInfo.streamUrl,
streamInfo.tabId, streamInfo.contentLength);
chrome.storage.local.remove(itemId);
};
var handleStorageItems = function(items) {
Object.keys(items).forEach(function(itemId) {
var item = items[itemId];
if (item.oldValue && !item.newValue) return; // storage remove event
if (item.newValue) item = item.newValue; // storage setter event
if (item.oldValue && !item.newValue) {
return; // storage remove event
}
if (item.newValue) {
item = item.newValue; // storage setter event
}
importStream(itemId, item);
});
};
@ -184,7 +199,7 @@ function handleStream(mimeType, pdfUrl, streamUrl, tabId, expectedSize) {
}, function(details) {
if (details) {
details = details.filter(function(frame) {
return frame.url === pdfUrl;
return (frame.url === pdfUrl);
});
if (details.length > 0) {
if (details.length !== 1) {
@ -221,10 +236,11 @@ function handleStream(mimeType, pdfUrl, streamUrl, tabId, expectedSize) {
*
* @param details {object}
* @param details.tabId {number} The ID of the tab
* @param details.url {string} The URL being navigated when the error occurred.
* @param details.frameId {number} 0 indicates the navigation happens in the tab
* content window; a positive value indicates
* navigation in a subframe.
* @param details.url {string} The URL being navigated when the error
* occurred.
* @param details.frameId {number} 0 indicates the navigation happens in
* the tab content window; a positive value
* indicates navigation in a subframe.
*/
function handleWebNavigation(details) {
var tabId = details.tabId;
@ -257,5 +273,4 @@ function handleWebNavigation(details) {
});
}
}
})();

View File

@ -29,7 +29,8 @@ limitations under the License.
/**
* Invoked when "Open with PDF Viewer" is chosen in the File browser.
*
* @param {String} id File browser action ID as specified in manifest.json
* @param {String} id File browser action ID as specified in
* manifest.json
* @param {Object} details Object of type FileHandlerExecuteEventDetails
*/
function onExecuteFileBrowserHandler(id, details) {