Bug 721729 - GCLI failed to update page resources when page changes; r=dcamp
authorJoe Walker <jwalker@mozilla.com>
Tue, 07 Feb 2012 10:20:20 +0000
changeset 87822 2c5df7e190ce50139b241d360ad454ce57dfe43d
parent 87821 99d735b9cf8cf9f0c70789f698527c19b6253b49
child 87823 3e9fbc7eb4471d35117b5f1b243728a48c9689bc
push id975
push userffxbld
push dateTue, 13 Mar 2012 21:39:16 +0000
treeherdermozilla-aurora@99faebf9dc36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdcamp
bugs721729
milestone13.0a1
Bug 721729 - GCLI failed to update page resources when page changes; r=dcamp
browser/devtools/webconsole/HUDService.jsm
browser/devtools/webconsole/gcli.jsm
--- a/browser/devtools/webconsole/HUDService.jsm
+++ b/browser/devtools/webconsole/HUDService.jsm
@@ -6943,16 +6943,22 @@ GcliTerm.prototype = {
    * @param object aConsole
    *        Console object to use within the GcliTerm.
    */
   reattachConsole: function Gcli_reattachConsole(aContentWindow, aConsole)
   {
     this.context = Cu.getWeakReference(aContentWindow);
     this.console = aConsole;
     this.createSandbox();
+
+    this.opts.environment.contentDocument = aContentWindow.document;
+    this.opts.contentDocument = aContentWindow.document;
+    this.opts.jsEnvironment.globalObject = unwrap(aContentWindow);
+
+    gcli._internal.reattachConsole(this.opts);
   },
 
   /**
    * Generates and attaches the GCLI Terminal part of the Web Console, which
    * essentially consists of the interactive JavaScript input facility.
    */
   createUI: function Gcli_createUI()
   {
--- a/browser/devtools/webconsole/gcli.jsm
+++ b/browser/devtools/webconsole/gcli.jsm
@@ -747,16 +747,30 @@ define('gcli/index', ['require', 'export
       if (opts.requisition == null) {
         opts.requisition = new Requisition(opts.environment, opts.chromeDocument);
       }
 
       opts.console = new Console(opts);
     },
 
     /**
+     * Called when the page to which we're attached changes
+     */
+    reattachConsole: function(opts) {
+      jstype.setGlobalObject(opts.jsEnvironment.globalObject);
+      nodetype.setDocument(opts.contentDocument);
+      cli.setEvalFunction(opts.jsEnvironment.evalFunction);
+
+      opts.requisition.environment = opts.environment;
+      opts.requisition.document = opts.chromeDocument;
+
+      opts.console.reattachConsole(opts);
+    },
+
+    /**
      * Undo the effects of createView() to prevent memory leaks
      */
     removeView: function(opts) {
       opts.console.destroy();
       delete opts.console;
 
       opts.requisition.destroy();
       delete opts.requisition;
@@ -5806,16 +5820,31 @@ function Console(options) {
 
   this.chromeWindow = options.chromeDocument.defaultView;
   this.resizer = this.resizer.bind(this);
   this.chromeWindow.addEventListener('resize', this.resizer, false);
   this.requisition.commandChange.add(this.resizer, this);
 }
 
 /**
+ * Called when the page to which we're attached changes
+ */
+Console.prototype.reattachConsole = function(options) {
+  this.chromeWindow.removeEventListener('resize', this.resizer, false);
+  this.chromeWindow = options.chromeDocument.defaultView;
+  this.chromeWindow.addEventListener('resize', this.resizer, false);
+
+  this.focusManager.document = options.chromeDocument;
+  this.inputter.document = options.chromeDocument;
+  this.inputter.completer.document = options.chromeDocument;
+  this.menu.document = options.chromeDocument;
+  this.argFetcher.document = options.chromeDocument;
+};
+
+/**
  * Avoid memory leaks
  */
 Console.prototype.destroy = function() {
   this.chromeWindow.removeEventListener('resize', this.resizer, false);
   delete this.resizer;
   delete this.chromeWindow;
   delete this.consoleWrap;