Modifying hosted.html so it only reaches up to windows that it has permission to access.

Patch by: jlabanca
Review by: jat

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6381 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html b/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html
index 65d375e..8436325 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html
+++ b/dev/core/src/com/google/gwt/core/ext/linker/impl/hosted.html
@@ -30,7 +30,16 @@
 function getTopWindow() {
   var topWin = window.top;
   while (topWin.opener) {
-    topWin = topWin.opener.top;
+    // Check that we can access the url of the opener. If we can't, then return
+    // the window up to the current point. This happens with selenium because
+    // the parent window is a file, but the child window is the hosted URL.
+    var nextTopWin = topWin.opener.top;
+    try {
+      nextTopWin.location.href;
+    } catch (e) {
+      return topWin;
+    }
+    topWin = nextTopWin;
   }
   return topWin;
 }