Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var SendResponse = requireNative('pepper_request_natives').SendResponse; | |
| 6 var GetAvailability = requireNative('v8_context').GetAvailability; | |
| 7 | |
| 8 function checkAvailability(name) { | |
| 9 var availability = GetAvailability(name); | |
| 10 if (!availability.is_available) | |
| 11 throw Error(availability.message); | |
| 12 } | |
| 13 | |
| 14 function resolveName(name) { | |
| 15 checkAvailability(name); | |
|
not at google - send to devlin
2013/12/03 17:32:50
having checkAvailability be a separate method does
Sam McNally
2013/12/04 00:01:36
Done.
| |
| 16 var item = chrome; | |
| 17 var nameComponents = $String.split(name, '.'); | |
| 18 for (var i = 0; i < nameComponents.length; i++) { | |
| 19 item = item[nameComponents[i]]; | |
| 20 } | |
| 21 return item; | |
| 22 } | |
| 23 | |
| 24 function callMethod(targetName, requestId) { | |
| 25 var args = $Array.slice(arguments, 2); | |
| 26 args.push(function() { | |
| 27 var error = null; | |
| 28 if (chrome.runtime.lastError) | |
| 29 error = chrome.runtime.lastError.message; | |
| 30 SendResponse(requestId, $Array.slice(arguments), error); | |
| 31 }); | |
| 32 try { | |
| 33 var target = resolveName(targetName); | |
| 34 $Function.apply(target, null, args); | |
| 35 } catch (e) { | |
| 36 return e.message; | |
|
not at google - send to devlin
2013/12/03 17:32:50
It would probably be nicer to catch this error fro
Sam McNally
2013/12/04 00:01:36
Done.
| |
| 37 } | |
| 38 } | |
| 39 | |
| 40 function postMethod(targetName) { | |
|
not at google - send to devlin
2013/12/03 17:32:50
if you kill StartPost then you'd kill this method
Sam McNally
2013/12/04 00:01:36
Done.
| |
| 41 var args = $Array.slice(arguments, 1); | |
| 42 try { | |
| 43 var target = resolveName(targetName); | |
| 44 $Function.apply(target, null, args); | |
| 45 } catch (e) { | |
| 46 return e.message; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 exports.callMethod = callMethod; | |
| 51 exports.postMethod = postMethod; | |
| OLD | NEW |