OSDN Git Service

Merge "WebView: clarify docs regarding base64 encoding"
authorTreeHugger Robot <treehugger-gerrit@google.com>
Fri, 5 Jan 2018 20:55:02 +0000 (20:55 +0000)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Fri, 5 Jan 2018 20:55:02 +0000 (20:55 +0000)
1  2 
core/java/android/webkit/WebView.java

@@@ -989,18 -976,22 +991,26 @@@ public class WebView extends AbsoluteLa
       * #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 {@code mimeType} parameter specifies the format of the data.
 +     * If WebView can't handle the specified MIME type, it will download the data.
 +     * If {@code null}, defaults to 'text/html'.
 +     * <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
       * 'data' scheme URL which explicitly specifies a charset parameter in the