Bug 1006379 - don't attempt language detection if the document is gone, r=felipe
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 15 May 2014 13:56:37 +0100
changeset 183449 d2214e4edf1bab324d18f05c51b1b35a6885d4d7
parent 183448 d65835b006b49688caf8ec6843665a66f5ee5581
child 183450 753285b8309a68a6fa9fad43ec65dd73a14a9a49
push idunknown
push userunknown
push dateunknown
reviewersfelipe
bugs1006379
milestone32.0a1
Bug 1006379 - don't attempt language detection if the document is gone, r=felipe
browser/base/content/content.js
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -1,16 +1,14 @@
 /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-let Cc = Components.classes;
-let Ci = Components.interfaces;
-let Cu = Components.utils;
+let {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "ContentLinkHandler",
   "resource:///modules/ContentLinkHandler.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "LanguageDetector",
   "resource:///modules/translation/LanguageDetector.jsm");
@@ -448,18 +446,21 @@ let TranslationHandler = {
   init: function() {
     let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                               .getInterface(Ci.nsIWebProgress);
     webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
   },
 
   /* nsIWebProgressListener implementation */
   onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
+    // Don't bother if we're not a toplevel document, if this isn't the 'stop'
+    // notification, or if the content document has gone away
     if (!aWebProgress.isTopLevel ||
-        !(aStateFlags & Ci.nsIWebProgressListener.STATE_STOP))
+        !(aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) ||
+        !content)
       return;
 
     let url = aRequest.name;
     if (!url.startsWith("http://") && !url.startsWith("https://"))
       return;
 
     // Grab a 60k sample of text from the page.
     let encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]