Remove missing plugin warnings with XPCOM, fix reference to external.initModule
for OOPHM, and close memory leak in dispatch wrappers.

Patch by: sgross
Review by: jat


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@4415 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/linker/IFrameTemplate.js b/dev/core/src/com/google/gwt/core/linker/IFrameTemplate.js
index 6ce0131..80c148d 100644
--- a/dev/core/src/com/google/gwt/core/linker/IFrameTemplate.js
+++ b/dev/core/src/com/google/gwt/core/linker/IFrameTemplate.js
@@ -346,7 +346,7 @@
   var strongName;
   var initialHtml;
   if (isHostedMode()) {
-    if ($wnd.external.initModule && $wnd.external.initModule('__MODULE_NAME__')) {
+    if ($wnd.external && $wnd.external.initModule && $wnd.external.initModule('__MODULE_NAME__')) {
       // Refresh the page to update this selection script!
       $wnd.location.reload();
       return;
diff --git a/dev/oophm/overlay/com/google/gwt/core/ext/linker/impl/hosted.html b/dev/oophm/overlay/com/google/gwt/core/ext/linker/impl/hosted.html
index c1c95ad..1777bea 100644
--- a/dev/oophm/overlay/com/google/gwt/core/ext/linker/impl/hosted.html
+++ b/dev/oophm/overlay/com/google/gwt/core/ext/linker/impl/hosted.html
@@ -18,15 +18,6 @@
     return __eval(s);
   }
 }
-
-</script></head>
-<body>
-<embed id="pluginEmbed" type="application/x-gwt-hosted-mode" width="10" height="10">
-</embed>
-<object id="pluginObject" CLASSID="CLSID:1D6156B6-002B-49E7-B5CA-C138FB843B4E">
-</object>
-<font face='arial' size='-1'>This html file is for hosted mode support.</font>
-<script><!--
 var $hosted = "localhost:9997";
 
 // wrapper to call JS methods, which we need both to be able to supply a
@@ -191,6 +182,17 @@
 };
 
 window.__gwt_module_id = 0;
+</script></head>
+<body>
+<font face='arial' size='-1'>This html file is for hosted mode support.</font>
+<script><!--
+
+if (!findPluginXPCOM()) {
+  document.write('<embed id="pluginEmbed" type="application/x-gwt-hosted-mode" width="10" height="10">');
+  document.write('</embed>');
+  document.write('<object id="pluginObject" CLASSID="CLSID:1D6156B6-002B-49E7-B5CA-C138FB843B4E">');
+  document.write('</object>');
+}
 
 var query = parent.location.search;
 $stats && $stats({moduleName:$moduleName,subSystem:'startup',evtGroup:'moduleStartup',millis:(new Date()).getTime(),type:'moduleEvalEnd'});
diff --git a/dev/oophm/src/com/google/gwt/dev/shell/JsValueOOPHM.java b/dev/oophm/src/com/google/gwt/dev/shell/JsValueOOPHM.java
index ace9b72..4ab0c77 100644
--- a/dev/oophm/src/com/google/gwt/dev/shell/JsValueOOPHM.java
+++ b/dev/oophm/src/com/google/gwt/dev/shell/JsValueOOPHM.java
@@ -20,6 +20,7 @@
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Field;
 import java.util.IdentityHashMap;
+import java.util.Map;
 
 /**
  * Represents a JavaScript value in OOPHM.
@@ -109,7 +110,7 @@
 
   public static final String JSE_CLASS = "com.google.gwt.core.client.JavaScriptException";
 
-  private static final IdentityHashMap<Object, DispatchObject> dispatchObjectCache = new IdentityHashMap<Object, DispatchObject>();
+  private static final ThreadLocal<Map<Object, DispatchObject>> dispatchObjectCache = new ThreadLocal<Map<Object, DispatchObject>>();
 
   private static final UndefinedValue undefValue = new UndefinedValue();
 
@@ -358,10 +359,15 @@
     if (val instanceof DispatchObject) {
       value = val;
     } else {
-      DispatchObject dispObj = dispatchObjectCache.get(val);
+      Map<Object, DispatchObject> cache = dispatchObjectCache.get();
+      if (cache == null) {
+        cache = new IdentityHashMap<Object, DispatchObject>();
+        dispatchObjectCache.set(cache);
+      }
+      DispatchObject dispObj = cache.get(val);
       if (dispObj == null) {
         dispObj = new DispatchObjectOOPHM(cl, val);
-        dispatchObjectCache.put(val, dispObj);
+        cache.put(val, dispObj);
       }
       value = dispObj;
     }