Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Unified Diff: chrome/browser/resources/pdf/main.js

Issue 797183005: Add a mimeHandler extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@streams-lifetime
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/pdf/main.js
diff --git a/chrome/browser/resources/pdf/main.js b/chrome/browser/resources/pdf/main.js
index 47d795098f8d97c6788135d4a1090f4e899a89f4..977c015a25212ff5bda1b4356c7778bbf439e22d 100644
--- a/chrome/browser/resources/pdf/main.js
+++ b/chrome/browser/resources/pdf/main.js
@@ -40,6 +40,25 @@ var viewer;
viewer.handleScriptingMessage(pendingMessages.shift());
}
+ function generateStreamDetailsAndInitViewer() {
+ var url = window.location.search.substring(1);
+ var streamDetails = {
+ streamUrl: url,
+ originalUrl: url,
+ responseHeaders: '',
+ embedded: window.parent != window,
+ tabId: -1
+ };
+ if (chrome.tabs) {
+ chrome.tabs.getCurrent(function(tab) {
+ streamDetails.tabId = tab.id;
+ initViewer(streamDetails);
+ });
+ return;
+ }
+ initViewer(streamDetails);
raymes 2015/01/12 05:26:04 See my comment below about putting the synchronous
Sam McNally 2015/01/12 07:13:35 Done.
+ }
+
/**
* Entrypoint for starting the PDF viewer. This function obtains the details
* of the PDF 'stream' (the data that points to the PDF) and constructs a
@@ -50,44 +69,20 @@ var viewer;
// to the PDFViewer being created.
window.addEventListener('message', handleScriptingMessage, false);
- // If the viewer is started from the browser plugin, the view ID will be
- // passed in which identifies the instance of the plugin.
- var params = window.location.search.substring(1).split('=');
- if (params.length == 2 && params[0] == 'id') {
- var viewId = params[1];
-
- // Send a message to the background page to obtain the stream details. It
- // will run the callback function passed in to initialize the viewer.
- chrome.runtime.sendMessage(
- 'mhjfbmdgcfjbbpaeojofohoefgiehjai',
- {viewId: viewId},
- initViewer);
+ // If the viewer is started from the browser plugin, getStreamInfo will
+ // return the details of the stream.
+ if (chrome.mimeHandler) {
+ chrome.mimeHandler.getStreamInfo(function(streamDetails) {
+ if (streamDetails) {
+ initViewer(streamDetails);
+ return;
+ }
+ generateStreamDetailsAndInitViewer();
raymes 2015/01/12 05:26:04 I think an if/else here might be cleaer
Sam McNally 2015/01/12 07:13:35 Done.
+ });
return;
}
-
- // The viewer may be started directly by passing in the URL of the PDF to
- // load as the query string. This is used for print preview in particular.
- // The URL of this page will be of the form
- // 'chrome-extension://<extension id>?<pdf url>'. We pull out the <pdf url>
- // part here.
- var url = window.location.search.substring(1);
- var streamDetails = {
- streamUrl: url,
- originalUrl: url,
- responseHeaders: '',
- embedded: window.parent != window,
- tabId: -1
- };
- if (!chrome.tabs) {
- initViewer(streamDetails);
- return;
- }
- chrome.tabs.getCurrent(function(tab) {
- if (tab && tab.id != undefined)
- streamDetails.tabId = tab.id;
- initViewer(streamDetails);
- });
- }
+ generateStreamDetailsAndInitViewer();
raymes 2015/01/12 05:26:04 Could you put the synchronous case first? This mig
Sam McNally 2015/01/12 07:13:35 Done.
+ };
main();
})();

Powered by Google App Engine
This is Rietveld 408576698