summaryrefslogtreecommitdiff
path: root/core/java/android/webkit/WebView.java
diff options
context:
space:
mode:
authorNate Fischer <ntfschr@google.com>2018-01-04 21:57:33 -0800
committerNate Fischer <ntfschr@google.com>2018-01-04 21:57:33 -0800
commit867d10944d7d2bcf38609629edfc7e75d68a0e34 (patch)
tree7626afc8f71759fa8975c1c76355b87a8fb317e8 /core/java/android/webkit/WebView.java
parent670c338751ce3f8175e84845f20bd99ea12e5f1d (diff)
WebView: clarify docs regarding base64 encoding
Docs change only, no change to logic. This CL provides a better loadData() example, using base64 encoding. This uses the Base64 class already provided by Android to automatically handle the encoding. This also changes the percent-encoding docs to: * Link to the official RFC * No longer provide examples of characters to encode (one example was incorrect, '\' is not %27) Bug: 70555565 Test: make docs (manually verify things look good) Test: I built a sample app and tested Base64#encodetoString to make sure the flags are correct Change-Id: If9f810e6b568efdc5d1ad84ac64f2abf3788f40b
Diffstat (limited to 'core/java/android/webkit/WebView.java')
-rw-r--r--core/java/android/webkit/WebView.java26
1 files changed, 18 insertions, 8 deletions
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index dfc81b2bcb5a..cce20da04f13 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -129,8 +129,10 @@ import java.util.Map;
* String summary = "&lt;html>&lt;body>You scored &lt;b>192&lt;/b> points.&lt;/body>&lt;/html>";
* webview.loadData(summary, "text/html", null);
* // ... although note that there are restrictions on what this HTML can do.
- * // See the JavaDocs for {@link #loadData(String,String,String) loadData()} and {@link
- * #loadDataWithBaseURL(String,String,String,String,String) loadDataWithBaseURL()} for more info.
+ * // See {@link #loadData(String,String,String)} and {@link
+ * #loadDataWithBaseURL(String,String,String,String,String)} for more info.
+ * // Also see {@link #loadData(String,String,String)} for information on encoding special
+ * // characters.
* </pre>
*
* <p>A WebView has several customization points where you can add your
@@ -974,13 +976,21 @@ public class WebView extends AbsoluteLayout
* #loadDataWithBaseURL(String,String,String,String,String)
* loadDataWithBaseURL()} with an appropriate base URL.
* <p>
- * The encoding parameter specifies whether the data is base64 or URL
+ * The {@code encoding} parameter specifies whether the data is base64 or URL
* encoded. If the data is base64 encoded, the value of the encoding
- * parameter must be 'base64'. For all other values of the parameter,
- * including {@code null}, it is assumed that the data uses ASCII encoding for
- * octets inside the range of safe URL characters and use the standard %xx
- * hex encoding of URLs for octets outside that range. For example, '#',
- * '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.
+ * parameter must be 'base64'. HTML can be encoded with {@link
+ * android.util.Base64#encodeToString(byte[],int)} like so:
+ * <pre>
+ * String unencodedHtml =
+ * "&lt;html&gt;&lt;body&gt;'%28' is the code for '('&lt;/body&gt;&lt;/html&gt;";
+ * String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(), Base64.NO_PADDING);
+ * webView.loadData(encodedHtml, "text/html", "base64");
+ * </pre>
+ * <p>
+ * For all other values of {@code encoding} (including {@code null}) it is assumed that the
+ * data uses ASCII encoding for octets inside the range of safe URL characters and use the
+ * standard %xx hex encoding of URLs for octets outside that range. See <a
+ * href="https://tools.ietf.org/html/rfc3986#section-2.2">RFC 3986</a> for more information.
* <p>
* The 'data' scheme URL formed by this method uses the default US-ASCII
* charset. If you need need to set a different charset, you should form a