com.opera.core.systems.scope.services.ums
Class EcmascriptService

java.lang.Object
  extended by com.opera.core.systems.scope.AbstractService
      extended by com.opera.core.systems.scope.AbstractEcmascriptService
          extended by com.opera.core.systems.scope.services.ums.EcmascriptService
All Implemented Interfaces:
IEcmaScriptDebugger

public class EcmascriptService
extends AbstractEcmascriptService
implements IEcmaScriptDebugger

EcmascriptService is a lightweight service to enable JavaScript injection. Unlike EcmaScriptDebugger it does not disable JIT.


Field Summary
 
Fields inherited from class com.opera.core.systems.scope.AbstractEcmascriptService
activeWindowId, currentFramePath, driver, retries, root, sleepDuration, windowManager
 
Fields inherited from class com.opera.core.systems.scope.AbstractService
services
 
Constructor Summary
EcmascriptService(ScopeServices services, String version)
           
 
Method Summary
 void addRuntime(EsdbgProtos.RuntimeInfo info)
          Adds a runtime to the list of runtimes maintained in the service (STP/1 only)
 String callFunctionOnObject(String using, int objectId)
          The script to be executed on/using an object
 Object callFunctionOnObject(String using, int objectId, boolean responseExpected)
           
 void changeRuntime(int index)
          Changes the frame by index
 void changeRuntime(String frameName)
          Changes the frame by frame name address nested frames by dot (first.second)
 void cleanUpRuntimes(int windowId)
          Cleanup possible dead/suspended runtimes on runtime-started or window-closed
protected  void createAllRuntimes()
          Gets a list of runtimes and keeps the list, create runtimes for all pages so even if the pages don't have script we can still inject to a 'fake' runtime.
 List<Integer> examineObjects(Integer id)
           
 Object examineScriptResult(Integer id)
           
 String executeJavascript(String using, Integer windowId)
           
 Object executeScript(String using, boolean responseExpected)
          Executes a script and returns the response (based on responseExpected)
 Integer executeScriptOnObject(String using, int objectId)
           
protected  EcmascriptProtos.Runtime findRuntime()
          Find the runtime for injection (default).
protected  EcmascriptProtos.Runtime findRuntime(int windowId)
           
 Integer getObject(String using)
          Gets the object id using a script
 int getRuntimeId()
           
 void init()
          Initialize the debugger, set the configuration to NOT stop on error, exception, script or abort Create all runtimes and find a suitable runtime for injection (Currently has a workaround or 'return 1;' for GOGI dialog at opera:debug)
 List<String> listFramePaths()
          Lists the frame paths of available runtimes
 void readyStateChanged(EcmascriptProtos.ReadyStateChange change)
          Triggered on the ecmascript service when the state of a runtime changes
 void releaseObject(int objectId)
          Releases a specific object
 void releaseObjects()
          Makes objects available to gc, this doesn't free the objects immediately
 void removeRuntime(int runtimeId)
          Removes a runtime from the list, doesnt get called often due to runtime-stopped being sent late (runtimes get suspended)
 void resetFramePath()
           
 void resetRuntimesList()
          Resets the list of runtimes and fetches a fresh list from Opera, this can be used to recover in cases where runtimes go out of sync
 Object scriptExecutor(String script, Object... params)
          Executes the given javascript via eval call
 void setRuntime(EcmascriptProtos.Runtime runtime)
           
 void setRuntime(EsdbgProtos.RuntimeInfo runtime)
          Sets the runtime to be used in injection required for event handler (STP/1 only)
 boolean updateRuntime()
          Finds a valid runtime and updates the runtime reference (active runtime)
 
Methods inherited from class com.opera.core.systems.scope.AbstractEcmascriptService
buildEvalString, cleanUpRuntimes, executeJavascript, executeJavascript, isNumber, parseNumber, processArgument, recover, resetCounters, setDriver
 
Methods inherited from class com.opera.core.systems.scope.AbstractService
buildPayload, executeCommand, executeCommand, getVersion, isVersionInRange, sleep, xpathIterator, xpathPointer, xpathQuery
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.opera.core.systems.scope.services.IEcmaScriptDebugger
cleanUpRuntimes, executeJavascript, executeJavascript, setDriver
 

Constructor Detail

EcmascriptService

public EcmascriptService(ScopeServices services,
                         String version)
Method Detail

getRuntimeId

public int getRuntimeId()
Specified by:
getRuntimeId in interface IEcmaScriptDebugger

setRuntime

public void setRuntime(EcmascriptProtos.Runtime runtime)

setRuntime

public void setRuntime(EsdbgProtos.RuntimeInfo runtime)
Description copied from interface: IEcmaScriptDebugger
Sets the runtime to be used in injection required for event handler (STP/1 only)

Specified by:
setRuntime in interface IEcmaScriptDebugger

addRuntime

public void addRuntime(EsdbgProtos.RuntimeInfo info)
Description copied from interface: IEcmaScriptDebugger
Adds a runtime to the list of runtimes maintained in the service (STP/1 only)

Specified by:
addRuntime in interface IEcmaScriptDebugger

removeRuntime

public void removeRuntime(int runtimeId)
Description copied from interface: IEcmaScriptDebugger
Removes a runtime from the list, doesnt get called often due to runtime-stopped being sent late (runtimes get suspended)

Specified by:
removeRuntime in interface IEcmaScriptDebugger

init

public void init()
Description copied from interface: IEcmaScriptDebugger
Initialize the debugger, set the configuration to NOT stop on error, exception, script or abort Create all runtimes and find a suitable runtime for injection (Currently has a workaround or 'return 1;' for GOGI dialog at opera:debug)

Specified by:
init in interface IEcmaScriptDebugger

updateRuntime

public boolean updateRuntime()
Description copied from interface: IEcmaScriptDebugger
Finds a valid runtime and updates the runtime reference (active runtime)

Specified by:
updateRuntime in interface IEcmaScriptDebugger
Returns:
true if a runtime is found and updated

createAllRuntimes

protected void createAllRuntimes()
Gets a list of runtimes and keeps the list, create runtimes for all pages so even if the pages don't have script we can still inject to a 'fake' runtime.


scriptExecutor

public Object scriptExecutor(String script,
                             Object... params)
Description copied from interface: IEcmaScriptDebugger
Executes the given javascript via eval call

Specified by:
scriptExecutor in interface IEcmaScriptDebugger
Parameters:
script - The script to be executed on host
params - Array of params, can be string, long or web element(s)

executeScript

public Object executeScript(String using,
                            boolean responseExpected)
Description copied from interface: IEcmaScriptDebugger
Executes a script and returns the response (based on responseExpected)

Specified by:
executeScript in interface IEcmaScriptDebugger
Parameters:
using - The script to be injected
responseExpected - The flag to enable/disable parsing response
Returns:
The raw result object if response is expected, null otherwise

getObject

public Integer getObject(String using)
Description copied from interface: IEcmaScriptDebugger
Gets the object id using a script

Specified by:
getObject in interface IEcmaScriptDebugger
Parameters:
using - the script to find the object
Returns:
object id with the result

callFunctionOnObject

public String callFunctionOnObject(String using,
                                   int objectId)
Description copied from interface: IEcmaScriptDebugger
The script to be executed on/using an object

Specified by:
callFunctionOnObject in interface IEcmaScriptDebugger
Parameters:
using - Script with reference to the object "locator"
objectId - The object to be used for injection
Returns:
The string value returned by the executed Javascript

callFunctionOnObject

public Object callFunctionOnObject(String using,
                                   int objectId,
                                   boolean responseExpected)
Specified by:
callFunctionOnObject in interface IEcmaScriptDebugger

executeScriptOnObject

public Integer executeScriptOnObject(String using,
                                     int objectId)
Specified by:
executeScriptOnObject in interface IEcmaScriptDebugger

findRuntime

protected EcmascriptProtos.Runtime findRuntime()
Find the runtime for injection (default). Typically this is _top runtime with the active window that has focus.


findRuntime

protected EcmascriptProtos.Runtime findRuntime(int windowId)

changeRuntime

public void changeRuntime(int index)
Description copied from interface: IEcmaScriptDebugger
Changes the frame by index

Specified by:
changeRuntime in interface IEcmaScriptDebugger

changeRuntime

public void changeRuntime(String frameName)
Description copied from interface: IEcmaScriptDebugger
Changes the frame by frame name address nested frames by dot (first.second)

Specified by:
changeRuntime in interface IEcmaScriptDebugger

cleanUpRuntimes

public void cleanUpRuntimes(int windowId)
Description copied from interface: IEcmaScriptDebugger
Cleanup possible dead/suspended runtimes on runtime-started or window-closed

Specified by:
cleanUpRuntimes in interface IEcmaScriptDebugger

examineObjects

public List<Integer> examineObjects(Integer id)
Specified by:
examineObjects in interface IEcmaScriptDebugger

listFramePaths

public List<String> listFramePaths()
Description copied from interface: IEcmaScriptDebugger
Lists the frame paths of available runtimes

Specified by:
listFramePaths in interface IEcmaScriptDebugger
Returns:
a List of String framepaths

releaseObjects

public void releaseObjects()
Description copied from interface: IEcmaScriptDebugger
Makes objects available to gc, this doesn't free the objects immediately

Specified by:
releaseObjects in interface IEcmaScriptDebugger

resetRuntimesList

public void resetRuntimesList()
Description copied from interface: IEcmaScriptDebugger
Resets the list of runtimes and fetches a fresh list from Opera, this can be used to recover in cases where runtimes go out of sync

Specified by:
resetRuntimesList in interface IEcmaScriptDebugger

readyStateChanged

public void readyStateChanged(EcmascriptProtos.ReadyStateChange change)
Description copied from interface: IEcmaScriptDebugger
Triggered on the ecmascript service when the state of a runtime changes

Specified by:
readyStateChanged in interface IEcmaScriptDebugger
Parameters:
change - EcmascriptProtos.ReadyStateChange object with runtime info

releaseObject

public void releaseObject(int objectId)
Description copied from interface: IEcmaScriptDebugger
Releases a specific object

Specified by:
releaseObject in interface IEcmaScriptDebugger
Parameters:
objectId - Id of the object to be released

resetFramePath

public void resetFramePath()
Specified by:
resetFramePath in interface IEcmaScriptDebugger

executeJavascript

public String executeJavascript(String using,
                                Integer windowId)
Specified by:
executeJavascript in interface IEcmaScriptDebugger

examineScriptResult

public Object examineScriptResult(Integer id)
Specified by:
examineScriptResult in interface IEcmaScriptDebugger


Copyright © 2012. All Rights Reserved.