title: Android WebView addJavascriptInterface does not work if the webview is created in the callback of WebChromeClient#onCreateWindow
body: <p>The following is my test code. My problem is that in the page two I can not reference <i>AndroidFunction2</i>. I'm testing this on Nexus 7 with Android 4.4. But it's OK on sumsang i9100 with Android 4.0.
   Am I doing something wrong, or there is an Android's bug? </p>
  
  <p><b>MainActivity</b></p>
  
  <pre><code>public class MainActivity extends Activity {
      WebView mWebView1;
      WebView mWebView2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          final FrameLayout mainFrame = (FrameLayout) this.findViewById(R.id.mainFrame);
  
          mWebView1 = new WebView(this);
          mWebView1.getSettings().setJavaScriptEnabled(true);
          mWebView1.getSettings().setSupportMultipleWindows(true);
          mWebView1.setWebViewClient(new WebViewClient() {
              @Override
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
                  return false;
              }
          });
          mWebView1.setWebChromeClient(new WebChromeClient() {
              @Override
              public boolean onCreateWindow(WebView view, boolean isDialog,
                      boolean isUserGesture, Message resultMsg) {
                  mWebView2 = new WebView(MainActivity.this);
                  mWebView2.getSettings().setJavaScriptEnabled(true);
                  mWebView2.getSettings().setSupportMultipleWindows(true);
                  mWebView2.setWebChromeClient(new WebChromeClient() {
                      @Override
                      public void onConsoleMessage(String message, int lineNumber, String sourceID) {
                          Log.d("WebView", "Line: " + lineNumber + ", " + message);
                      }
                  });
                  mWebView2.addJavascriptInterface(new Object() {
                      @JavascriptInterface
                      public void hello2() {
                      }
                  }, "AndroidFunction2");
  
                  (( WebViewTransport )resultMsg.obj).setWebView(mWebView2);
                  resultMsg.sendToTarget();
                  mainFrame.addView(mWebView2);
                  return true;
              }
          });
          mWebView1.addJavascriptInterface(new Object() {
              @JavascriptInterface
              public void hello1() {
              }
          }, "AndroidFunction1");
          mWebView1.loadUrl("file:///sdcard/test_1.html");
  
          mainFrame.addView(mWebView1);
      }
  }
  </code></pre>
  
  <p>And the two web page, <p><b>test_1.html</b>:</p></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;a href="test_2.html" target="_blank"&gt;goto test 2&lt;/a&gt;
      &lt;div&gt;&lt;a href="javascript:alert(typeof AndroidFunction1);"&gt; alert(typeof AndroidFunction1);&lt;/a&gt; &lt;/div&gt;
      &lt;div&gt;&lt;a href="javascript:alert(typeof window.AndroidFunction1);"&gt; alert(typeof window.AndroidFunction1);&lt;/a&gt; &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><b>test_2.html</b></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;div&gt;&lt;a href="javascript:alert(AndroidFunction2);"&gt; alert(AndroidFunction2);&lt;/a&gt; &lt;/div&gt;
      &lt;div&gt;&lt;a href="javascript:alert(typeof window.AndroidFunction2);"&gt; alert(typeof window.AndroidFunction2);&lt;/a&gt; &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>