| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 var InjectedScriptAccess = {}; | 32 function InjectedScriptAccess(injectedScriptId) { |
| 33 this._injectedScriptId = injectedScriptId; |
| 34 } |
| 35 |
| 36 InjectedScriptAccess.get = function(injectedScriptId) |
| 37 { |
| 38 return new InjectedScriptAccess(injectedScriptId); |
| 39 } |
| 40 |
| 41 InjectedScriptAccess.getDefault = function() |
| 42 { |
| 43 return InjectedScriptAccess.get(0); |
| 44 } |
| 45 |
| 46 InjectedScriptAccess.prototype = {}; |
| 33 | 47 |
| 34 InjectedScriptAccess._installHandler = function(methodName, async) | 48 InjectedScriptAccess._installHandler = function(methodName, async) |
| 35 { | 49 { |
| 36 InjectedScriptAccess[methodName] = function() | 50 InjectedScriptAccess.prototype[methodName] = function() |
| 37 { | 51 { |
| 38 var allArgs = Array.prototype.slice.call(arguments); | 52 var allArgs = Array.prototype.slice.call(arguments); |
| 39 var callback = allArgs[allArgs.length - 1]; | 53 var callback = allArgs[allArgs.length - 1]; |
| 40 var argsString = JSON.stringify(Array.prototype.slice.call(allArgs, 0, a
llArgs.length - 1)); | 54 var argsString = JSON.stringify(Array.prototype.slice.call(allArgs, 0, a
llArgs.length - 1)); |
| 41 | 55 |
| 42 function myCallback(result, isException) | 56 function myCallback(result, isException) |
| 43 { | 57 { |
| 44 if (!isException) | 58 if (!isException) |
| 45 callback(JSON.parse(result)); | 59 callback(JSON.parse(result)); |
| 46 else | 60 else |
| 47 WebInspector.console.addMessage(new WebInspector.ConsoleTextMess
age("Error dispatching: " + methodName)); | 61 WebInspector.console.addMessage(new WebInspector.ConsoleTextMess
age("Error dispatching: " + methodName)); |
| 48 } | 62 } |
| 49 var callId = WebInspector.Callback.wrap(myCallback); | 63 var callId = WebInspector.Callback.wrap(myCallback); |
| 50 InspectorBackend.dispatchOnInjectedScript(callId, methodName, argsString
, !!async); | 64 |
| 65 InspectorBackend.dispatchOnInjectedScript(callId, this._injectedScriptId
, methodName, argsString, !!async); |
| 51 }; | 66 }; |
| 52 } | 67 } |
| 53 | 68 |
| 54 // InjectedScriptAccess message forwarding puts some constraints on the way meth
ods are implemented and called: | 69 // InjectedScriptAccess message forwarding puts some constraints on the way meth
ods are implemented and called: |
| 55 // - Make sure corresponding methods in InjectedScript return non-null and non-u
ndefined values, | 70 // - Make sure corresponding methods in InjectedScript return non-null and non-u
ndefined values, |
| 56 // - Make sure last parameter of all the InjectedSriptAccess.* calls is a callba
ck function. | 71 // - Make sure last parameter of all the InjectedSriptAccess.* calls is a callba
ck function. |
| 57 // We keep these sorted. | 72 // We keep these sorted. |
| 58 InjectedScriptAccess._installHandler("addInspectedNode"); | 73 InjectedScriptAccess._installHandler("addInspectedNode"); |
| 59 InjectedScriptAccess._installHandler("addStyleSelector"); | 74 InjectedScriptAccess._installHandler("addStyleSelector"); |
| 60 InjectedScriptAccess._installHandler("applyStyleRuleText"); | 75 InjectedScriptAccess._installHandler("applyStyleRuleText"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 79 InjectedScriptAccess._installHandler("setStyleProperty"); | 94 InjectedScriptAccess._installHandler("setStyleProperty"); |
| 80 InjectedScriptAccess._installHandler("setStyleText"); | 95 InjectedScriptAccess._installHandler("setStyleText"); |
| 81 InjectedScriptAccess._installHandler("toggleStyleEnabled"); | 96 InjectedScriptAccess._installHandler("toggleStyleEnabled"); |
| 82 InjectedScriptAccess._installHandler("evaluateOnSelf"); | 97 InjectedScriptAccess._installHandler("evaluateOnSelf"); |
| 83 | 98 |
| 84 // Some methods can't run synchronously even on the injected script side (such a
s DB transactions). | 99 // Some methods can't run synchronously even on the injected script side (such a
s DB transactions). |
| 85 // Mark them as asynchronous here. | 100 // Mark them as asynchronous here. |
| 86 InjectedScriptAccess._installHandler("executeSql", true); | 101 InjectedScriptAccess._installHandler("executeSql", true); |
| 87 | 102 |
| 88 WebInspector.didDispatchOnInjectedScript = WebInspector.Callback.processCallback
; | 103 WebInspector.didDispatchOnInjectedScript = WebInspector.Callback.processCallback
; |
| OLD | NEW |