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:
parent
8ec46e6413
commit
ce6e269d02
@ -25,7 +25,8 @@ if (!chrome.streamsPrivate) {
|
|||||||
console.warn('streamsPrivate not available, PDF from FTP or POST ' +
|
console.warn('streamsPrivate not available, PDF from FTP or POST ' +
|
||||||
'requests will not be displayed using this extension! ' +
|
'requests will not be displayed using this extension! ' +
|
||||||
'See http://crbug.com/326949');
|
'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') {
|
if (message && message.action === 'getPDFStream') {
|
||||||
sendResponse();
|
sendResponse();
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ var STREAM_NO_TABID = 0;
|
|||||||
|
|
||||||
function hasStream(tabId, pdfUrl) {
|
function hasStream(tabId, pdfUrl) {
|
||||||
var streams = urlToStream[streamSupportsTabId ? tabId : STREAM_NO_TABID];
|
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)
|
* property contentLength (= expected size)
|
||||||
*/
|
*/
|
||||||
function getStream(tabId, pdfUrl) {
|
function getStream(tabId, pdfUrl) {
|
||||||
if (!streamSupportsTabId) tabId = STREAM_NO_TABID;
|
if (!streamSupportsTabId) {
|
||||||
|
tabId = STREAM_NO_TABID;
|
||||||
|
}
|
||||||
if (hasStream(tabId, pdfUrl)) {
|
if (hasStream(tabId, pdfUrl)) {
|
||||||
var streamInfo = urlToStream[tabId][pdfUrl].shift();
|
var streamInfo = urlToStream[tabId][pdfUrl].shift();
|
||||||
if (urlToStream[tabId][pdfUrl].length === 0) {
|
if (urlToStream[tabId][pdfUrl].length === 0) {
|
||||||
@ -74,8 +77,12 @@ function getStream(tabId, pdfUrl) {
|
|||||||
|
|
||||||
function setStream(tabId, pdfUrl, streamUrl, expectedSize) {
|
function setStream(tabId, pdfUrl, streamUrl, expectedSize) {
|
||||||
tabId = tabId || STREAM_NO_TABID;
|
tabId = tabId || STREAM_NO_TABID;
|
||||||
if (!urlToStream[tabId]) urlToStream[tabId] = {};
|
if (!urlToStream[tabId]) {
|
||||||
if (!urlToStream[tabId][pdfUrl]) urlToStream[tabId][pdfUrl] = [];
|
urlToStream[tabId] = {};
|
||||||
|
}
|
||||||
|
if (!urlToStream[tabId][pdfUrl]) {
|
||||||
|
urlToStream[tabId][pdfUrl] = [];
|
||||||
|
}
|
||||||
urlToStream[tabId][pdfUrl].push({
|
urlToStream[tabId][pdfUrl].push({
|
||||||
streamUrl: streamUrl,
|
streamUrl: streamUrl,
|
||||||
contentLength: expectedSize
|
contentLength: expectedSize
|
||||||
@ -115,19 +122,27 @@ function transferStreamToIncognitoProfile(tabId, pdfUrl) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chrome.extension.inIncognitoContext) {
|
if (chrome.extension.inIncognitoContext) {
|
||||||
var importStream = function(itemId, streamInfo) {
|
var importStream = function(itemId, streamInfo) {
|
||||||
if (itemId.lastIndexOf('streamInfo:', 0) !== 0) return;
|
if (itemId.lastIndexOf('streamInfo:', 0) !== 0) {
|
||||||
console.log('Importing stream info from non-incognito profile', streamInfo);
|
return;
|
||||||
handleStream('', streamInfo.pdfUrl, streamInfo.streamUrl, streamInfo.tabId,
|
}
|
||||||
streamInfo.contentLength);
|
console.log('Importing stream info from non-incognito profile',
|
||||||
|
streamInfo);
|
||||||
|
handleStream('', streamInfo.pdfUrl, streamInfo.streamUrl,
|
||||||
|
streamInfo.tabId, streamInfo.contentLength);
|
||||||
chrome.storage.local.remove(itemId);
|
chrome.storage.local.remove(itemId);
|
||||||
};
|
};
|
||||||
var handleStorageItems = function(items) {
|
var handleStorageItems = function(items) {
|
||||||
Object.keys(items).forEach(function(itemId) {
|
Object.keys(items).forEach(function(itemId) {
|
||||||
var item = items[itemId];
|
var item = items[itemId];
|
||||||
if (item.oldValue && !item.newValue) return; // storage remove event
|
if (item.oldValue && !item.newValue) {
|
||||||
if (item.newValue) item = item.newValue; // storage setter event
|
return; // storage remove event
|
||||||
|
}
|
||||||
|
if (item.newValue) {
|
||||||
|
item = item.newValue; // storage setter event
|
||||||
|
}
|
||||||
importStream(itemId, item);
|
importStream(itemId, item);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -184,7 +199,7 @@ function handleStream(mimeType, pdfUrl, streamUrl, tabId, expectedSize) {
|
|||||||
}, function(details) {
|
}, function(details) {
|
||||||
if (details) {
|
if (details) {
|
||||||
details = details.filter(function(frame) {
|
details = details.filter(function(frame) {
|
||||||
return frame.url === pdfUrl;
|
return (frame.url === pdfUrl);
|
||||||
});
|
});
|
||||||
if (details.length > 0) {
|
if (details.length > 0) {
|
||||||
if (details.length !== 1) {
|
if (details.length !== 1) {
|
||||||
@ -221,10 +236,11 @@ function handleStream(mimeType, pdfUrl, streamUrl, tabId, expectedSize) {
|
|||||||
*
|
*
|
||||||
* @param details {object}
|
* @param details {object}
|
||||||
* @param details.tabId {number} The ID of the tab
|
* @param details.tabId {number} The ID of the tab
|
||||||
* @param details.url {string} The URL being navigated when the error occurred.
|
* @param details.url {string} The URL being navigated when the error
|
||||||
* @param details.frameId {number} 0 indicates the navigation happens in the tab
|
* occurred.
|
||||||
* content window; a positive value indicates
|
* @param details.frameId {number} 0 indicates the navigation happens in
|
||||||
* navigation in a subframe.
|
* the tab content window; a positive value
|
||||||
|
* indicates navigation in a subframe.
|
||||||
*/
|
*/
|
||||||
function handleWebNavigation(details) {
|
function handleWebNavigation(details) {
|
||||||
var tabId = details.tabId;
|
var tabId = details.tabId;
|
||||||
@ -257,5 +273,4 @@ function handleWebNavigation(details) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -29,7 +29,8 @@ limitations under the License.
|
|||||||
/**
|
/**
|
||||||
* Invoked when "Open with PDF Viewer" is chosen in the File browser.
|
* 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
|
* @param {Object} details Object of type FileHandlerExecuteEventDetails
|
||||||
*/
|
*/
|
||||||
function onExecuteFileBrowserHandler(id, details) {
|
function onExecuteFileBrowserHandler(id, details) {
|
||||||
|
Loading…
Reference in New Issue
Block a user