123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- (function () {
- "use strict";
- if (!chrome.fileBrowserHandler) {
-
- return;
- }
- chrome.fileBrowserHandler.onExecute.addListener(onExecuteFileBrowserHandler);
-
- function onExecuteFileBrowserHandler(id, details) {
- if (id !== "open-as-pdf") {
- return;
- }
- var fileEntries = details.entries;
-
-
- var tabId = details.tab_id || details.tabId;
- if (tabId > 0) {
- chrome.tabs.get(tabId, function (tab) {
- openViewer(tab && tab.windowId, fileEntries);
- });
- } else {
-
- chrome.windows.getLastFocused(function (chromeWindow) {
- var windowId = chromeWindow && chromeWindow.id;
- if (windowId) {
- chrome.windows.update(windowId, { focused: true });
- }
- openViewer(windowId, fileEntries);
- });
- }
- }
-
- function openViewer(windowId, fileEntries) {
- if (!fileEntries.length) {
- return;
- }
- var fileEntry = fileEntries.shift();
- var url = fileEntry.toURL();
-
- url = url.replace(
- /^filesystem:chrome-extension:\/\/[a-p]{32}\/external\//,
- "drive:"
- );
- url = getViewerURL(url);
- if (windowId) {
- chrome.tabs.create(
- {
- windowId,
- active: true,
- url,
- },
- function () {
- openViewer(windowId, fileEntries);
- }
- );
- } else {
- chrome.windows.create(
- {
- type: "normal",
- focused: true,
- url,
- },
- function (chromeWindow) {
- openViewer(chromeWindow.id, fileEntries);
- }
- );
- }
- }
- })();
|