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

Unified Diff: chrome/browser/resources/cryptotoken/webrequestsender.js

Issue 872603003: Only release the result of a register request to a tab if it's still the foreground tab when the re… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
« no previous file with comments | « chrome/browser/resources/cryptotoken/cryptotokenbackground.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/cryptotoken/webrequestsender.js
diff --git a/chrome/browser/resources/cryptotoken/webrequestsender.js b/chrome/browser/resources/cryptotoken/webrequestsender.js
index d3fdf3d239a1b0e586ac3e167f625c0f2c02bf78..7907120ed942d412dc4ff015b90f3249cb240e27 100644
--- a/chrome/browser/resources/cryptotoken/webrequestsender.js
+++ b/chrome/browser/resources/cryptotoken/webrequestsender.js
@@ -131,3 +131,35 @@ function getTabIdWhenPossible(sender) {
});
}
}
+
+/**
+ * Checks whether the given tab is in the foreground, i.e. is the active tab
+ * of the focused window.
+ * @param {number} tabId The tab id to check.
+ * @return {Promise.<boolean>} A promise for the result of the check.
+ */
+function tabInForeground(tabId) {
+ return new Promise(function(resolve, reject) {
+ if (!chrome.tabs || !chrome.tabs.get) {
+ reject();
+ return;
+ }
+ if (!chrome.windows || !chrome.windows.get) {
+ reject();
+ return;
+ }
+ chrome.tabs.get(tabId, function(tab) {
+ if (chrome.runtime.lastError) {
+ resolve(false);
+ return;
+ }
+ if (!tab.active) {
+ resolve(false);
+ return;
+ }
+ chrome.windows.get(tab.windowId, function(aWindow) {
+ resolve(aWindow && aWindow.focused);
+ });
+ });
+ });
+}
« no previous file with comments | « chrome/browser/resources/cryptotoken/cryptotokenbackground.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698