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 binding for the browserAction API. | 5 // Custom binding for the browserAction API. |
6 | 6 |
7 var binding = apiBridge || require('binding').Binding.create('browserAction'); | 7 var binding = apiBridge || require('binding').Binding.create('browserAction'); |
8 | 8 |
9 var setIcon = require('setIcon').setIcon; | 9 var setIcon = require('setIcon').setIcon; |
10 var getExtensionViews = requireNative('runtime').GetExtensionViews; | 10 var getExtensionViews = requireNative('runtime').GetExtensionViews; |
11 var sendRequest = bindingUtil ? | 11 var sendRequest = bindingUtil ? |
12 $Function.bind(bindingUtil.sendRequest, bindingUtil) : | 12 $Function.bind(bindingUtil.sendRequest, bindingUtil) : |
13 require('sendRequest').sendRequest; | 13 require('sendRequest').sendRequest; |
14 var lastError = require('lastError'); | 14 |
| 15 var jsLastError = bindingUtil ? undefined : require('lastError'); |
| 16 function hasLastError() { |
| 17 return bindingUtil ? |
| 18 bindingUtil.hasLastError() : jsLastError.hasError(chrome); |
| 19 } |
15 | 20 |
16 binding.registerCustomHook(function(bindingsAPI) { | 21 binding.registerCustomHook(function(bindingsAPI) { |
17 var apiFunctions = bindingsAPI.apiFunctions; | 22 var apiFunctions = bindingsAPI.apiFunctions; |
18 | 23 |
19 apiFunctions.setHandleRequest('setIcon', function(details, callback) { | 24 apiFunctions.setHandleRequest('setIcon', function(details, callback) { |
20 setIcon(details, function(args) { | 25 setIcon(details, function(args) { |
21 sendRequest('browserAction.setIcon', | 26 sendRequest('browserAction.setIcon', |
22 [args, callback], | 27 [args, callback], |
23 apiBridge ? undefined : this.definition.parameters, | 28 apiBridge ? undefined : this.definition.parameters, |
24 undefined); | 29 undefined); |
25 }.bind(this)); | 30 }.bind(this)); |
26 }); | 31 }); |
27 | 32 |
28 apiFunctions.setCustomCallback('openPopup', | 33 apiFunctions.setCustomCallback('openPopup', |
29 function(name, request, callback, response) { | 34 function(name, request, callback, response) { |
30 if (!callback) | 35 if (!callback) |
31 return; | 36 return; |
32 | 37 |
33 if (lastError.hasError(chrome)) { | 38 if (hasLastError()) { |
34 callback(); | 39 callback(); |
35 } else { | 40 } else { |
36 var views = getExtensionViews(-1, -1, 'POPUP'); | 41 var views = getExtensionViews(-1, -1, 'POPUP'); |
37 callback(views.length > 0 ? views[0] : null); | 42 callback(views.length > 0 ? views[0] : null); |
38 } | 43 } |
39 }); | 44 }); |
40 }); | 45 }); |
41 | 46 |
42 if (!apiBridge) | 47 if (!apiBridge) |
43 exports.$set('binding', binding.generate()); | 48 exports.$set('binding', binding.generate()); |
OLD | NEW |