OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Provides a representation of a web request sender, and | 6 * @fileoverview Provides a representation of a web request sender, and |
7 * utility functions for creating them. | 7 * utility functions for creating them. |
8 */ | 8 */ |
9 'use strict'; | 9 'use strict'; |
10 | 10 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 reject(false); | 124 reject(false); |
125 } | 125 } |
126 }); | 126 }); |
127 } | 127 } |
128 }); | 128 }); |
129 }); | 129 }); |
130 }); | 130 }); |
131 }); | 131 }); |
132 } | 132 } |
133 } | 133 } |
| 134 |
| 135 /** |
| 136 * Checks whether the given tab is in the foreground, i.e. is the active tab |
| 137 * of the focused window. |
| 138 * @param {number} tabId The tab id to check. |
| 139 * @return {Promise.<boolean>} A promise for the result of the check. |
| 140 */ |
| 141 function tabInForeground(tabId) { |
| 142 return new Promise(function(resolve, reject) { |
| 143 if (!chrome.tabs || !chrome.tabs.get) { |
| 144 reject(); |
| 145 return; |
| 146 } |
| 147 if (!chrome.windows || !chrome.windows.get) { |
| 148 reject(); |
| 149 return; |
| 150 } |
| 151 chrome.tabs.get(tabId, function(tab) { |
| 152 if (chrome.runtime.lastError) { |
| 153 resolve(false); |
| 154 return; |
| 155 } |
| 156 if (!tab.active) { |
| 157 resolve(false); |
| 158 return; |
| 159 } |
| 160 chrome.windows.get(tab.windowId, function(aWindow) { |
| 161 resolve(aWindow && aWindow.focused); |
| 162 }); |
| 163 }); |
| 164 }); |
| 165 } |
OLD | NEW |