Merge "WebView: clarify docs for addJavascriptInterface" into oc-mr1-dev

This commit is contained in:
TreeHugger Robot
2017-08-23 23:41:56 +00:00
committed by Android (Google) Code Review

View File

@@ -1926,13 +1926,14 @@ public class WebView extends AbsoluteLayout
* For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
* all public methods (including the inherited ones) can be accessed, see the
* important security note below for implications.
* <p> Note that injected objects will not
* appear in JavaScript until the page is next (re)loaded. For example:
* <p> Note that injected objects will not appear in JavaScript until the page is next
* (re)loaded. JavaScript should be enabled before injecting the object. For example:
* <pre>
* class JsObject {
* {@literal @}JavascriptInterface
* public String toString() { return "injectedObject"; }
* }
* webview.getSettings().setJavaScriptEnabled(true);
* webView.addJavascriptInterface(new JsObject(), "injectedObject");
* webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
* webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>