summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-03 22:41:49 +0000
committermichaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-03 22:41:49 +0000
commit66b572e343c5b1adbe31dfec8f993969555e314e (patch)
treeafa91a66109b4ea2641f28c782d8e8e73320fab1
parente77c4c31482bc2ae769f1fc8b013726ef8089bec (diff)
downloadchromium_src-66b572e343c5b1adbe31dfec8f993969555e314e.zip
chromium_src-66b572e343c5b1adbe31dfec8f993969555e314e.tar.gz
chromium_src-66b572e343c5b1adbe31dfec8f993969555e314e.tar.bz2
Merge 220291 "WebContentObserver::RenderViewCreated should be ca..."
> WebContentObserver::RenderViewCreated should be called for empty document. > > JavaBridgeDispatcherHostManager uses RenderViewCreated() to register JavaScript interface. > Also WebView uses this callback to do some initial settings. > > BUG=273164 > > Review URL: https://chromiumcodereview.appspot.com/23600009 TBR=michaelbai@chromium.org Review URL: https://codereview.chromium.org/23500004 git-svn-id: svn://svn.chromium.org/chrome/branches/1599/src@221049 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java36
-rw-r--r--content/browser/web_contents/web_contents_impl.cc6
2 files changed, 37 insertions, 5 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
index 6d508ed..bb9d68f 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
@@ -15,6 +15,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.util.Pair;
import org.chromium.android_webview.AwContents;
+import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.test.util.CommonResources;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
@@ -57,7 +58,7 @@ public class AwContentsTest extends AwTestBase {
return mContentDisposition;
}
- public String getMimeType() {
+ public String getMimeType() {
assert getCallCount() > 0;
return mMimeType;
}
@@ -417,4 +418,37 @@ public class AwContentsTest extends AwTestBase {
assertEquals("true", executeJavaScriptAndWaitForResult(awContents, mContentsClient,
SCRIPT));
}
+
+
+ static class JavaScriptObject {
+ private CallbackHelper mCallbackHelper;
+ public JavaScriptObject(CallbackHelper callbackHelper) {
+ mCallbackHelper = callbackHelper;
+ }
+
+ public void run() {
+ mCallbackHelper.notifyCalled();
+ }
+ };
+
+ @Feature({"AndroidWebView", "JavaBridge"})
+ @SmallTest
+ public void testJavaBridge() throws Throwable {
+ final AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient);
+ final CallbackHelper callback = new CallbackHelper();
+
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ AwContents awContents = testView.getAwContents();
+ AwSettings awSettings = awContents.getSettings();
+ awSettings.setJavaScriptEnabled(true);
+ awContents.addPossiblyUnsafeJavascriptInterface(
+ new JavaScriptObject(callback), "bridge", null);
+ awContents.evaluateJavaScriptEvenIfNotYetNavigated(
+ "javascript:window.bridge.run();");
+ }
+ });
+ callback.waitForCallback(0, 1, 20, TimeUnit.SECONDS);
+ }
}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index fa6dddb..fe36a9b 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2865,16 +2865,14 @@ void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
Source<WebContents>(this),
Details<RenderViewHost>(render_view_host));
- NavigationEntry* entry = controller_.GetActiveEntry();
- if (!entry)
- return;
// When we're creating views, we're still doing initial setup, so we always
// use the pending Web UI rather than any possibly existing committed one.
if (render_manager_.pending_web_ui())
render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
- if (entry->IsViewSourceMode()) {
+ NavigationEntry* entry = controller_.GetActiveEntry();
+ if (entry && entry->IsViewSourceMode()) {
// Put the renderer in view source mode.
render_view_host->Send(
new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));