| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Custom bindings for the extension API. | 5 // Custom bindings for the extension API. |
| 6 | 6 |
| 7 (function() { | 7 (function() { |
| 8 | 8 |
| 9 native function GetChromeHidden(); | 9 native function GetChromeHidden(); |
| 10 native function GetExtensionViews(); | 10 native function GetExtensionViews(); |
| 11 | 11 |
| 12 // This should match chrome.windows.WINDOW_ID_NONE. |
| 13 // |
| 14 // We can't use chrome.windows.WINDOW_ID_NONE directly because the |
| 15 // chrome.windows API won't exist unless this extension has permission for it; |
| 16 // which may not be the case. |
| 17 var WINDOW_ID_NONE = -1; |
| 18 |
| 12 GetChromeHidden().registerCustomHook('extension', function(bindingsAPI) { | 19 GetChromeHidden().registerCustomHook('extension', function(bindingsAPI) { |
| 13 // getTabContentses is retained for backwards compatibility. | 20 // getTabContentses is retained for backwards compatibility. |
| 14 // See http://crbug.com/21433 | 21 // See http://crbug.com/21433 |
| 15 chrome.extension.getTabContentses = chrome.extension.getExtensionTabs; | 22 chrome.extension.getTabContentses = chrome.extension.getExtensionTabs; |
| 16 | 23 |
| 17 var apiFunctions = bindingsAPI.apiFunctions; | 24 var apiFunctions = bindingsAPI.apiFunctions; |
| 18 | 25 |
| 19 apiFunctions.setHandleRequest("extension.getViews", function(properties) { | 26 apiFunctions.setHandleRequest("extension.getViews", function(properties) { |
| 20 var windowId = chrome.windows.WINDOW_ID_NONE; | 27 var windowId = WINDOW_ID_NONE; |
| 21 var type = "ALL"; | 28 var type = "ALL"; |
| 22 if (typeof(properties) != "undefined") { | 29 if (typeof(properties) != "undefined") { |
| 23 if (typeof(properties.type) != "undefined") { | 30 if (typeof(properties.type) != "undefined") { |
| 24 type = properties.type; | 31 type = properties.type; |
| 25 } | 32 } |
| 26 if (typeof(properties.windowId) != "undefined") { | 33 if (typeof(properties.windowId) != "undefined") { |
| 27 windowId = properties.windowId; | 34 windowId = properties.windowId; |
| 28 } | 35 } |
| 29 } | 36 } |
| 30 return GetExtensionViews(windowId, type) || null; | 37 return GetExtensionViews(windowId, type) || null; |
| 31 }); | 38 }); |
| 32 | 39 |
| 33 apiFunctions.setHandleRequest("extension.getBackgroundPage", function() { | 40 apiFunctions.setHandleRequest("extension.getBackgroundPage", function() { |
| 34 return GetExtensionViews(-1, "BACKGROUND")[0] || null; | 41 return GetExtensionViews(-1, "BACKGROUND")[0] || null; |
| 35 }); | 42 }); |
| 36 | 43 |
| 37 apiFunctions.setHandleRequest("extension.getExtensionTabs", | 44 apiFunctions.setHandleRequest("extension.getExtensionTabs", |
| 38 function(windowId) { | 45 function(windowId) { |
| 39 if (typeof(windowId) == "undefined") | 46 if (typeof(windowId) == "undefined") |
| 40 windowId = chrome.windows.WINDOW_ID_NONE; | 47 windowId = WINDOW_ID_NONE; |
| 41 return GetExtensionViews(windowId, "TAB"); | 48 return GetExtensionViews(windowId, "TAB"); |
| 42 }); | 49 }); |
| 43 }); | 50 }); |
| 44 | 51 |
| 45 })(); | 52 })(); |
| OLD | NEW |