attach agent to applet running in firefox (attach api)

Discussion in 'Java' started by craiget@gmail.com, Jun 14, 2007.

  1. Guest

    Hi,

    I am trying to use the Java 6 "Attach API" to examine the contents of
    a running applet's top-level Frame via reflection. I can get at the
    frame by attaching to Firefox's PID and calling Frame.getFrames().
    This returns a single frame and works fine. However, what I *really*
    want is to get the top-level frame from a *second* applet that is
    loaded in a new browser window by clicking on a button in the first
    applet. Even though two applets are running, Frame.getFrames() only
    returns the single frame of the original. Any suggestions on how to
    get at that second frame?

    If you're still with me, here's a bit more detail:

    I wanted to fool around with the Attach API as demonstrated at
    http://www.fasterj.com/articles/hotpatch1.shtml

    After a bit, I ended up with something like this to attach my Agent to
    a running instance of Firefox:

    class Attach {
    public static void main(String args[]) {
    String pid = "1234"; //get firefox's pid
    VirtualMachine vm = VirtualMachine.attach(pid);
    vm.loadAgent("myagent.jar", null);
    }
    }

    So far so good. When I run that code, it successfully attaches to FF
    and my Agent ends up with an instance of Instrumentation that has
    access to all the classes currently loaded by the JVM.

    class MyAgent {
    public static void agentmain(String agentArgs, Instrumentation inst)
    {
    for(Class klass : inst.getAllLoadedClasses())
    {
    //do stuff
    }
    }
    }

    By invoking the static Frame.getFrames() method via reflection, I am
    able to get the top-level frame for ONE but not BOTH of the running
    Applets. There are a couple of static calls available, (getWindows(),
    getOwnerlessWindows()) and they all return the same instance of
    java.awt.Frame.

    So, any suggestions on how I can get at that second Frame?

    Thanks!
    , Jun 14, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    419
  2. moon
    Replies:
    1
    Views:
    3,875
    Thomas Weidenfeller
    Aug 5, 2005
  3. Warren Tang
    Replies:
    1
    Views:
    531
    Warren Tang
    Sep 17, 2008
  4. poz
    Replies:
    0
    Views:
    244
  5. Replies:
    3
    Views:
    97
Loading...

Share This Page