Index: chrome/browser/resources/pdf/background.js |
diff --git a/chrome/browser/resources/pdf/background.js b/chrome/browser/resources/pdf/background.js |
index 2114010193fb47095da2464de33d67fdede00557..3c514b679fde33b02899d49b871eb2dde3403111 100644 |
--- a/chrome/browser/resources/pdf/background.js |
+++ b/chrome/browser/resources/pdf/background.js |
@@ -5,29 +5,43 @@ |
(function() { |
'use strict'; |
- /** |
- * Keep a stack of stream details for requests. These are pushed onto the |
- * stack as requests come in and popped off the stack as they are handled by a |
- * renderer. |
- * TODO(raymes): This is probably racy for multiple requests. We could |
- * associate an ID with the request but this code will probably change |
- * completely when MIME type handling is improved. |
- */ |
- var streamsCache = []; |
+ var streams = {}; |
+ var pluginInitFunctions = {}; |
+ function flush(viewId) { |
+ if (viewId in streams && viewId in pluginInitFunctions) { |
+ pluginInitFunctions[viewId](streams[viewId]); |
+ delete streams[viewId]; |
+ delete pluginInitFunctions[viewId]; |
+ } |
+ } |
+ |
+ // Legacy. |
window.popStreamDetails = function() { |
- if (streamsCache.length > 0) |
- return streamsCache.pop(); |
+ for (var viewId in streams) { |
+ var result = streams[viewId]; |
+ delete streams[viewId]; |
+ delete pluginInitFunctions[viewId]; |
+ return result; |
+ } |
}; |
chrome.streamsPrivate.onExecuteMimeTypeHandler.addListener( |
function(streamDetails) { |
- // TODO(raymes): Currently this doesn't work with embedded PDFs (it |
- // causes the entire frame to navigate). Also work out how we can |
- // mask the URL with the URL of the PDF. |
- streamsCache.push(streamDetails); |
- chrome.tabs.update(streamDetails.tabId, {url: 'index.html'}); |
+ if (!streamDetails.viewId) { |
+ streams.push(streamDetails); |
+ chrome.tabs.update(streamDetails.tabId, {url: 'index.html'}); |
+ } else { |
+ streams[streamDetails.viewId] = streamDetails; |
+ flush(streamDetails.viewId); |
+ } |
} |
); |
+ chrome.runtime.onMessage.addListener( |
+ function(request, sender, responseFunction) { |
+ pluginInitFunctions[request.viewId] = responseFunction; |
+ flush(request.viewId); |
+ } |
+ ); |
}()); |