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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 }); | 129 }); |
130 }); | 130 }); |
131 }); | 131 }); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 /** | 135 /** |
136 * Checks whether the given tab is in the foreground, i.e. is the active tab | 136 * Checks whether the given tab is in the foreground, i.e. is the active tab |
137 * of the focused window. | 137 * of the focused window. |
138 * @param {number} tabId The tab id to check. | 138 * @param {number} tabId The tab id to check. |
139 * @return {Promise.<boolean>} A promise for the result of the check. | 139 * @return {Promise<boolean>} A promise for the result of the check. |
140 */ | 140 */ |
141 function tabInForeground(tabId) { | 141 function tabInForeground(tabId) { |
142 return new Promise(function(resolve, reject) { | 142 return new Promise(function(resolve, reject) { |
143 if (!chrome.tabs || !chrome.tabs.get) { | 143 if (!chrome.tabs || !chrome.tabs.get) { |
144 reject(); | 144 reject(); |
145 return; | 145 return; |
146 } | 146 } |
147 if (!chrome.windows || !chrome.windows.get) { | 147 if (!chrome.windows || !chrome.windows.get) { |
148 reject(); | 148 reject(); |
149 return; | 149 return; |
150 } | 150 } |
151 chrome.tabs.get(tabId, function(tab) { | 151 chrome.tabs.get(tabId, function(tab) { |
152 if (chrome.runtime.lastError) { | 152 if (chrome.runtime.lastError) { |
153 resolve(false); | 153 resolve(false); |
154 return; | 154 return; |
155 } | 155 } |
156 if (!tab.active) { | 156 if (!tab.active) { |
157 resolve(false); | 157 resolve(false); |
158 return; | 158 return; |
159 } | 159 } |
160 chrome.windows.get(tab.windowId, function(aWindow) { | 160 chrome.windows.get(tab.windowId, function(aWindow) { |
161 resolve(aWindow && aWindow.focused); | 161 resolve(aWindow && aWindow.focused); |
162 }); | 162 }); |
163 }); | 163 }); |
164 }); | 164 }); |
165 } | 165 } |
OLD | NEW |