зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 4 changesets (bug 1533840, bug 1522451) for failing dom/manifest/test/test_ManifestProcessor_background_color.html on a CLOSED TREE
Backed out changeset 4fd7ce83efe1 (bug 1533840) Backed out changeset 5a892aa56e37 (bug 1522451) Backed out changeset 2ddf151f9535 (bug 1522451) Backed out changeset 49ebb69e8893 (bug 1522451)
This commit is contained in:
Родитель
3f8d31ac5b
Коммит
d6a864b0c0
|
@ -50,10 +50,7 @@ ValueExtractor.prototype = {
|
|||
const value = this.extractValue(spec);
|
||||
let color;
|
||||
if (InspectorUtils.isValidCSSColor(value)) {
|
||||
const rgba = InspectorUtils.colorToRGBA(value);
|
||||
color = "#" + ((rgba.r << 16) |
|
||||
(rgba.g << 8) |
|
||||
rgba.b).toString(16);
|
||||
color = value;
|
||||
} else if (value) {
|
||||
this.console.warn(this.domBundle.formatStringFromName("ManifestInvalidCSSColor",
|
||||
[spec.property, value],
|
||||
|
|
|
@ -31,7 +31,6 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.ActivityHandlerHelper;
|
||||
import org.mozilla.gecko.BrowserApp;
|
||||
import org.mozilla.gecko.Clipboard;
|
||||
|
|
|
@ -21,7 +21,6 @@ import android.view.Window;
|
|||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.ActivityHandlerHelper;
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.BrowserApp;
|
||||
|
|
|
@ -21,7 +21,6 @@ const SCROLL_BEHAVIOR_AUTO = 1;
|
|||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
FormLikeFactory: "resource://gre/modules/FormLikeFactory.jsm",
|
||||
GeckoViewAutoFill: "resource://gre/modules/GeckoViewAutoFill.jsm",
|
||||
ManifestObtainer: "resource://gre/modules/ManifestObtainer.jsm",
|
||||
PrivacyFilter: "resource://gre/modules/sessionstore/PrivacyFilter.jsm",
|
||||
SessionHistory: "resource://gre/modules/sessionstore/SessionHistory.jsm",
|
||||
});
|
||||
|
@ -78,7 +77,6 @@ class GeckoViewContentChild extends GeckoViewChildModule {
|
|||
addEventListener("MozDOMFullscreen:Exited", this, false);
|
||||
addEventListener("MozDOMFullscreen:Request", this, false);
|
||||
addEventListener("contextmenu", this, { capture: true });
|
||||
addEventListener("DOMContentLoaded", this, false);
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
|
@ -92,7 +90,6 @@ class GeckoViewContentChild extends GeckoViewChildModule {
|
|||
removeEventListener("MozDOMFullscreen:Exited", this);
|
||||
removeEventListener("MozDOMFullscreen:Request", this);
|
||||
removeEventListener("contextmenu", this, { capture: true });
|
||||
removeEventListener("DOMContentLoaded", this);
|
||||
}
|
||||
|
||||
collectSessionState() {
|
||||
|
@ -428,24 +425,6 @@ class GeckoViewContentChild extends GeckoViewChildModule {
|
|||
});
|
||||
}
|
||||
break;
|
||||
case "DOMContentLoaded": {
|
||||
content.requestIdleCallback(async () => {
|
||||
let manifest = null;
|
||||
try {
|
||||
manifest = await ManifestObtainer.contentObtainManifest(content);
|
||||
} catch (e) {
|
||||
// Unfortunately, this throws if there is no manifest present, so we
|
||||
// probably don't want to log anything here. Bug 1534756.
|
||||
}
|
||||
|
||||
if (manifest) {
|
||||
this.eventDispatcher.sendRequest({
|
||||
type: "GeckoView:WebAppManifest",
|
||||
manifest,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -353,7 +353,6 @@ package org.mozilla.geckoview {
|
|||
method @android.support.annotation.UiThread default public void onFocusRequest(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession);
|
||||
method @android.support.annotation.UiThread default public void onFullScreen(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, boolean);
|
||||
method @android.support.annotation.UiThread default public void onTitleChange(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, @android.support.annotation.Nullable java.lang.String);
|
||||
method @android.support.annotation.UiThread default public void onWebAppManifest(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, @android.support.annotation.NonNull org.json.JSONObject);
|
||||
}
|
||||
|
||||
public static class GeckoSession.ContentDelegate.ContextElement {
|
||||
|
@ -957,9 +956,6 @@ package org.mozilla.geckoview {
|
|||
@android.support.annotation.AnyThread public static class WebRequest.Builder extends org.mozilla.geckoview.WebMessage.Builder {
|
||||
ctor public Builder(@android.support.annotation.NonNull java.lang.String);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.WebRequest.Builder body(@android.support.annotation.Nullable java.nio.ByteBuffer);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.WebRequest.Builder body(@android.support.annotation.NonNull byte[]);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.WebRequest.Builder body(@android.support.annotation.NonNull java.lang.String);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.WebRequest.Builder body(@android.support.annotation.NonNull org.json.JSONObject);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.WebRequest build();
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.WebRequest.Builder cacheMode(int);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.WebRequest.Builder method(@android.support.annotation.NonNull java.lang.String);
|
||||
|
@ -1016,9 +1012,6 @@ package org.mozilla.geckoview {
|
|||
|
||||
@android.support.annotation.AnyThread public class WebResponse extends org.mozilla.geckoview.WebMessage {
|
||||
ctor protected WebResponse(@android.support.annotation.NonNull org.mozilla.geckoview.WebResponse.Builder);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoResult<byte[]> byteArray();
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoResult<org.json.JSONObject> json();
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoResult<java.lang.String> text();
|
||||
field @android.support.annotation.Nullable public final java.io.InputStream body;
|
||||
field public final boolean redirected;
|
||||
field public final int statusCode;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Hello, world!</title>
|
||||
<link rel="manifest" href="manifest.webmanifest">
|
||||
</head>
|
||||
<head><title>Hello, world!</title></head>
|
||||
<body>
|
||||
<p>Hello, world!</p>
|
||||
</body>
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
"name": "App",
|
||||
"short_name": "app",
|
||||
"start_url": "./start/index.html",
|
||||
"display": "standalone",
|
||||
"background_color": "#c0feee",
|
||||
"theme_color": "cadetblue",
|
||||
"icons": [{
|
||||
"src": "images/test.gif",
|
||||
"sizes": "192x192",
|
||||
"type": "image/gif"
|
||||
}],
|
||||
"related_applications": [{
|
||||
"platform": "play",
|
||||
"url": "https://play.google.com/store/apps/details?id=my.first.webapp"
|
||||
}]
|
||||
}
|
|
@ -6,9 +6,9 @@ package org.mozilla.geckoview.test
|
|||
|
||||
import android.app.assist.AssistStructure
|
||||
import android.graphics.SurfaceTexture
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import org.mozilla.geckoview.AllowOrDeny
|
||||
import org.mozilla.geckoview.GeckoDisplay
|
||||
import org.mozilla.geckoview.GeckoResult
|
||||
import org.mozilla.geckoview.GeckoSession
|
||||
import org.mozilla.geckoview.GeckoSession.NavigationDelegate.LoadRequest
|
||||
|
@ -21,7 +21,6 @@ import org.mozilla.geckoview.test.util.Callbacks
|
|||
import org.mozilla.geckoview.test.util.UiThreadUtils
|
||||
|
||||
import android.os.Looper
|
||||
import android.support.test.InstrumentationRegistry
|
||||
import android.support.test.filters.MediumTest
|
||||
import android.support.test.filters.SdkSuppress
|
||||
import android.support.test.runner.AndroidJUnit4
|
||||
|
@ -32,22 +31,15 @@ import android.view.View
|
|||
import android.view.ViewStructure
|
||||
import android.widget.EditText
|
||||
import org.hamcrest.Matchers.*
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assume.assumeThat
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.geckoview.test.util.HttpBin
|
||||
|
||||
import java.net.URI
|
||||
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@MediumTest
|
||||
class ContentDelegateTest : BaseSessionTest() {
|
||||
companion object {
|
||||
val TEST_ENDPOINT: String = "http://localhost:4243"
|
||||
}
|
||||
|
||||
@Test fun titleChange() {
|
||||
sessionRule.session.loadTestPath(TITLE_CHANGE_HTML_PATH)
|
||||
|
@ -588,44 +580,4 @@ class ContentDelegateTest : BaseSessionTest() {
|
|||
display.surfaceDestroyed()
|
||||
mainSession.releaseDisplay(display)
|
||||
}
|
||||
|
||||
@Test fun webAppManifest() {
|
||||
val httpBin = HttpBin(InstrumentationRegistry.getTargetContext(), URI.create(TEST_ENDPOINT))
|
||||
|
||||
try {
|
||||
httpBin.start()
|
||||
|
||||
mainSession.loadUri("$TEST_ENDPOINT$HELLO_HTML_PATH")
|
||||
mainSession.waitUntilCalled(object : Callbacks.All {
|
||||
|
||||
@AssertCalled(count = 1)
|
||||
override fun onPageStop(session: GeckoSession, success: Boolean) {
|
||||
assertThat("Page load should succeed", success, equalTo(true))
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1)
|
||||
override fun onWebAppManifest(session: GeckoSession, manifest: JSONObject) {
|
||||
// These values come from the manifest at assets/www/manifest.webmanifest
|
||||
assertThat("name should match", manifest.getString("name"), equalTo("App"))
|
||||
assertThat("short_name should match", manifest.getString("short_name"), equalTo("app"))
|
||||
assertThat("display should match", manifest.getString("display"), equalTo("standalone"))
|
||||
|
||||
// The color here is "cadetblue" converted to hex.
|
||||
assertThat("theme_color should match", manifest.getString("theme_color"), equalTo("#5f9ea0"))
|
||||
assertThat("background_color should match", manifest.getString("background_color"), equalTo("#c0feee"))
|
||||
assertThat("start_url should match", manifest.getString("start_url"), equalTo("$TEST_ENDPOINT/assets/www/start/index.html"))
|
||||
|
||||
val icon = manifest.getJSONArray("icons").getJSONObject(0);
|
||||
|
||||
val iconSrc = Uri.parse(icon.getString("src"))
|
||||
assertThat("icon should have a valid src", iconSrc, notNullValue())
|
||||
assertThat("icon src should be absolute", iconSrc.isAbsolute, equalTo(true))
|
||||
assertThat("icon should have sizes", icon.getString("sizes"), not(isEmptyOrNullString()))
|
||||
assertThat("icon type should match", icon.getString("type"), equalTo("image/gif"))
|
||||
}
|
||||
})
|
||||
} finally {
|
||||
httpBin.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package org.mozilla.geckoview.test;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.geckoview.AllowOrDeny;
|
||||
import org.mozilla.geckoview.GeckoDisplay;
|
||||
import org.mozilla.geckoview.GeckoResult;
|
||||
|
@ -114,10 +113,6 @@ public class TestRunnerActivity extends Activity {
|
|||
@Override
|
||||
public void onFirstComposite(final GeckoSession session) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebAppManifest(final GeckoSession session, final JSONObject manifest) {
|
||||
}
|
||||
};
|
||||
|
||||
private GeckoSession createSession() {
|
||||
|
|
|
@ -8,7 +8,6 @@ import android.os.Build
|
|||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.SystemClock
|
||||
import android.support.test.InstrumentationRegistry
|
||||
|
||||
import android.support.test.filters.MediumTest
|
||||
import android.support.test.filters.SdkSuppress
|
||||
|
@ -18,6 +17,10 @@ import java.math.BigInteger
|
|||
|
||||
import java.net.URI
|
||||
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.CharBuffer
|
||||
import java.nio.charset.Charset
|
||||
|
||||
import java.security.MessageDigest
|
||||
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
@ -40,7 +43,6 @@ import org.mozilla.geckoview.test.util.Environment
|
|||
import org.mozilla.geckoview.test.util.HttpBin
|
||||
import org.mozilla.geckoview.test.util.RuntimeCreator
|
||||
import java.net.UnknownHostException
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
@MediumTest
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
|
@ -64,7 +66,7 @@ class WebExecutorTest {
|
|||
val latch = CountDownLatch(1)
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
executor = GeckoWebExecutor(RuntimeCreator.getRuntime())
|
||||
server = HttpBin(InstrumentationRegistry.getTargetContext(), URI.create(TEST_ENDPOINT))
|
||||
server = HttpBin(URI.create(TEST_ENDPOINT))
|
||||
server.start()
|
||||
latch.countDown()
|
||||
}
|
||||
|
@ -85,18 +87,23 @@ class WebExecutorTest {
|
|||
return executor.fetch(request, flags).poll(env.defaultTimeoutMillis)!!
|
||||
}
|
||||
|
||||
fun WebResponse.getBodyBytes(): ByteBuffer {
|
||||
return ByteBuffer.wrap(byteArray().poll()!!);
|
||||
fun String.toDirectByteBuffer(): ByteBuffer {
|
||||
val chars = CharBuffer.wrap(this)
|
||||
val buffer = ByteBuffer.allocateDirect(this.length)
|
||||
Charset.forName("UTF-8").newEncoder().encode(chars, buffer, true)
|
||||
|
||||
return buffer
|
||||
}
|
||||
|
||||
fun WebResponse.getJSONBody(): JSONObject {
|
||||
return json().poll()!!
|
||||
val bytes = ByteBuffer.wrap(body!!.readBytes())
|
||||
return JSONObject(Charset.forName("UTF-8").decode(bytes).toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun smoke() {
|
||||
val uri = "$TEST_ENDPOINT/anything"
|
||||
val requestBody = JSONObject("{ \"foo\": 42 }")
|
||||
val bodyString = "This is the POST data"
|
||||
val referrer = "http://foo/bar"
|
||||
|
||||
val request = WebRequest.Builder(uri)
|
||||
|
@ -107,7 +114,7 @@ class WebExecutorTest {
|
|||
.addHeader("Header2", "Value2")
|
||||
.referrer(referrer)
|
||||
.header("Content-Type", "text/plain")
|
||||
.body(requestBody)
|
||||
.body(bodyString.toDirectByteBuffer())
|
||||
.build()
|
||||
|
||||
val response = fetch(request)
|
||||
|
@ -123,14 +130,7 @@ class WebExecutorTest {
|
|||
assertThat("Headers should match", body.getJSONObject("headers").getString("Header2"), equalTo("Value1, Value2"))
|
||||
assertThat("Headers should match", body.getJSONObject("headers").getString("Content-Type"), equalTo("text/plain"))
|
||||
assertThat("Referrer should match", body.getJSONObject("headers").getString("Referer"), equalTo(referrer))
|
||||
assertThat("Data should match", body.getString("data"), equalTo(requestBody.toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFetchAsset() {
|
||||
val response = fetch(WebRequest("$TEST_ENDPOINT/assets/www/hello.html"))
|
||||
assertThat("Status should match", response.statusCode, equalTo(200))
|
||||
assertThat("Body should have bytes", response.getBodyBytes().remaining(), greaterThan(0))
|
||||
assertThat("Data should match", body.getString("data"), equalTo(bodyString));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.mozilla.geckoview.WebRequestError
|
|||
import android.view.inputmethod.CursorAnchorInfo
|
||||
import android.view.inputmethod.ExtractedText
|
||||
import android.view.inputmethod.ExtractedTextRequest
|
||||
import org.json.JSONObject
|
||||
|
||||
class Callbacks private constructor() {
|
||||
object Default : All
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.mozilla.geckoview.test.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.StrictMode;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -43,8 +42,8 @@ public final class HttpBin {
|
|||
org.eclipse.jetty.util.log.Log.setLog(new AndroidLogger());
|
||||
}
|
||||
|
||||
public HttpBin(@NonNull Context context, @NonNull URI endpoint) {
|
||||
this(endpoint, new HttpBinHandler(context));
|
||||
public HttpBin(@NonNull URI endpoint) {
|
||||
this(endpoint, new HttpBinHandler());
|
||||
}
|
||||
|
||||
public HttpBin(@NonNull URI endpoint, @NonNull HttpBinHandler handler) {
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package org.mozilla.geckoview.test.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
|
@ -48,14 +46,6 @@ class HttpBinHandler extends AbstractHandler {
|
|||
private static final String LOGTAG = "HttpBinHandler";
|
||||
private static final int BUFSIZE = 4096;
|
||||
|
||||
private AssetManager mAssets;
|
||||
|
||||
public HttpBinHandler(@NonNull Context context) {
|
||||
super();
|
||||
|
||||
mAssets = context.getResources().getAssets();
|
||||
}
|
||||
|
||||
private static void pipe(final @NonNull InputStream is) throws IOException {
|
||||
pipe(is, null);
|
||||
}
|
||||
|
@ -197,11 +187,6 @@ class HttpBinHandler extends AbstractHandler {
|
|||
os.write(payload);
|
||||
os.flush();
|
||||
|
||||
baseRequest.setHandled(true);
|
||||
} else if (uri.startsWith("/assets")) {
|
||||
pipe(is);
|
||||
pipe(mAssets.open(uri.substring("/assets/".length())), os);
|
||||
os.flush();
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
|
||||
|
@ -217,10 +202,6 @@ class HttpBinHandler extends AbstractHandler {
|
|||
Log.e(LOGTAG, "Failed to generate digest", e);
|
||||
servletResponse.setStatus(500);
|
||||
baseRequest.setHandled(true);
|
||||
} catch (IOException e) {
|
||||
Log.e(LOGTAG, "Failed to respond", e);
|
||||
servletResponse.setStatus(500);
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@ import java.lang.annotation.RetentionPolicy;
|
|||
import java.lang.ref.WeakReference;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
|
@ -345,7 +343,6 @@ public class GeckoSession implements Parcelable {
|
|||
"GeckoView:ExternalResponse",
|
||||
"GeckoView:FullScreenEnter",
|
||||
"GeckoView:FullScreenExit",
|
||||
"GeckoView:WebAppManifest",
|
||||
}
|
||||
) {
|
||||
@Override
|
||||
|
@ -385,17 +382,6 @@ public class GeckoSession implements Parcelable {
|
|||
delegate.onFullScreen(GeckoSession.this, false);
|
||||
} else if ("GeckoView:ExternalResponse".equals(event)) {
|
||||
delegate.onExternalResponse(GeckoSession.this, new WebResponseInfo(message));
|
||||
} else if ("GeckoView:WebAppManifest".equals(event)) {
|
||||
final GeckoBundle manifest = message.getBundle("manifest");
|
||||
if (manifest == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
delegate.onWebAppManifest(GeckoSession.this, manifest.toJSONObject());
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOGTAG, "Failed to convert web app manifest to JSON", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -2771,16 +2757,6 @@ public class GeckoSession implements Parcelable {
|
|||
*/
|
||||
@UiThread
|
||||
default void onFirstComposite(@NonNull GeckoSession session) {}
|
||||
|
||||
/**
|
||||
* This is fired when the loaded document has a valid Web App Manifest present.
|
||||
*
|
||||
* @param session The GeckoSession that contains the Web App Manifest
|
||||
* @param manifest A parsed and validated {@link JSONObject} containing the manifest contents.
|
||||
* @see <a href="https://www.w3.org/TR/appmanifest/">Web App Manifest specification</a>
|
||||
*/
|
||||
@UiThread
|
||||
default void onWebAppManifest(@NonNull GeckoSession session, @NonNull JSONObject manifest) {}
|
||||
}
|
||||
|
||||
public interface SelectionActionDelegate {
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
package org.mozilla.geckoview;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
|
||||
import android.support.annotation.AnyThread;
|
||||
|
@ -19,7 +17,6 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* WebRequest represents an HTTP[S] request. The typical pattern is to create instances of this
|
||||
|
@ -172,42 +169,6 @@ public class WebRequest extends WebMessage {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the body.
|
||||
*
|
||||
* @param bytes A non-null byte array.
|
||||
* @return This Builder instance.
|
||||
*/
|
||||
public @NonNull Builder body(final @NonNull byte[] bytes) {
|
||||
final ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.length);
|
||||
buffer.put(bytes);
|
||||
|
||||
body(buffer);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the body.
|
||||
*
|
||||
* @param bodyString A non-null {@link String}.
|
||||
* @return This Builder instance.
|
||||
*/
|
||||
public @NonNull Builder body(final @NonNull String bodyString) {
|
||||
body(bodyString.getBytes(Charset.forName("UTF-8")));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the body.
|
||||
*
|
||||
* @param object A non-null {@link JSONObject}.
|
||||
* @return This Builder instance.
|
||||
*/
|
||||
public @NonNull Builder body(final @NonNull JSONObject object) {
|
||||
body(object.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HTTP method.
|
||||
*
|
||||
|
|
|
@ -6,19 +6,14 @@
|
|||
|
||||
package org.mozilla.geckoview;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
|
||||
import android.support.annotation.AnyThread;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* WebResponse represents an HTTP[S] response. It is normally created
|
||||
|
@ -27,9 +22,6 @@ import java.util.concurrent.Executors;
|
|||
@WrapForJNI
|
||||
@AnyThread
|
||||
public class WebResponse extends WebMessage {
|
||||
private static final ExecutorService sExecutorService = Executors.newCachedThreadPool();
|
||||
private static final int BUFSIZE = 8192;
|
||||
|
||||
/**
|
||||
* The HTTP status code for the response, e.g. 200.
|
||||
*/
|
||||
|
@ -53,77 +45,6 @@ public class WebResponse extends WebMessage {
|
|||
this.body = builder.mBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the {@link #body} stream into a byte array.
|
||||
*
|
||||
* @return A {@link GeckoResult} which resolves to a byte array containing the response body.
|
||||
*/
|
||||
public @NonNull GeckoResult<byte[]> byteArray() {
|
||||
if (body == null) {
|
||||
return GeckoResult.fromValue(new byte[0]);
|
||||
}
|
||||
|
||||
final GeckoResult<byte[]> result = new GeckoResult<>();
|
||||
sExecutorService.submit(() -> {
|
||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
final byte buf[] = new byte[BUFSIZE];
|
||||
int count;
|
||||
|
||||
try {
|
||||
while ((count = body.read(buf)) > 0) {
|
||||
os.write(buf, 0, count);
|
||||
}
|
||||
|
||||
os.flush();
|
||||
|
||||
result.complete(os.toByteArray());
|
||||
} catch (Exception e) {
|
||||
result.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the {@link #body} stream into a {@link String}.
|
||||
*
|
||||
* @return A {@link GeckoResult} which resolves to a {@link String} containing the response body.
|
||||
*/
|
||||
public @NonNull GeckoResult<String> text() {
|
||||
final GeckoResult<String> result = new GeckoResult<>();
|
||||
|
||||
sExecutorService.submit(() -> {
|
||||
try {
|
||||
final ByteBuffer bytes = ByteBuffer.wrap(byteArray().poll());
|
||||
result.complete(Charset.forName("UTF-8").decode(bytes).toString());
|
||||
} catch (Throwable t) {
|
||||
result.completeExceptionally(t);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the {@link #body} stream into a {@link JSONObject}.
|
||||
*
|
||||
* @return A {@link GeckoResult} which resolves to a {@link JSONObject} containing the response body.
|
||||
*/
|
||||
public @NonNull GeckoResult<JSONObject> json() {
|
||||
final GeckoResult<JSONObject> result = new GeckoResult<>();
|
||||
|
||||
sExecutorService.submit(() -> {
|
||||
try {
|
||||
result.complete(new JSONObject(text().poll()));
|
||||
} catch (Throwable t) {
|
||||
result.completeExceptionally(t);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder offers a convenient way to create WebResponse instances.
|
||||
*/
|
||||
|
|
|
@ -90,25 +90,6 @@ exclude: true
|
|||
|
||||
- Added `default` implementations for all non-functional `interface`s.
|
||||
|
||||
- Added [`ContentDelegate.onWebAppManifest`][67.22], which will deliver the contents of a parsed
|
||||
and validated Web App Manifest on pages that contain one.
|
||||
|
||||
[67.22]: ../GeckoSession.ContentDelegate.html#onWebAppManifest-org.mozilla.geckoview.GeckoSession-org.json.JSONObject
|
||||
|
||||
- Added [`WebResponse.byteArray()`][67.22], [`WebResponse.text()`][67.23], and
|
||||
[`WebResponse.json()`][67.24] as convenience methods for accessing the response body.
|
||||
|
||||
[67.23]: ../WebResponse.html#byteArray--
|
||||
[67.24]: ../WebResponse.html#text--
|
||||
[67.25]: ../WebResponse.html#json--
|
||||
|
||||
- Added [`byte[]`][67.25], [`String`][67.26], and [`JSONObject`][67.27] overloads of
|
||||
`WebRequest.Body.Builder.body()` as convenience methods for setting the request body.
|
||||
|
||||
[67.26]: ../WebRequest.Builder.html#body-byte:A-
|
||||
[67.27]: ../WebRequest.Builder.html#body-java.lang.String-
|
||||
[67.28]: ../WebRequest.Builder.html#body-org.json.JSONObject-
|
||||
|
||||
## v66
|
||||
- Removed redundant field `trackingMode` from [`SecurityInformation`][66.6].
|
||||
Use `TrackingProtectionDelegate.onTrackerBlocked` for notification of blocked
|
||||
|
@ -228,4 +209,4 @@ exclude: true
|
|||
[65.24]: ../CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
|
||||
[65.25]: ../GeckoResult.html
|
||||
|
||||
[api-version]: bf7527ba15aeda260dbfb8dd134e963ab062fba8
|
||||
[api-version]: 09c473360eb5e17aa801fa0f966cd8671cf2f3d2
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package org.mozilla.geckoview_example;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.geckoview.AllowOrDeny;
|
||||
import org.mozilla.geckoview.BasicSelectionActionDelegate;
|
||||
import org.mozilla.geckoview.ContentBlocking;
|
||||
|
@ -534,11 +533,6 @@ public class GeckoViewActivity extends AppCompatActivity {
|
|||
public void onFirstComposite(final GeckoSession session) {
|
||||
Log.d(LOGTAG, "onFirstComposite");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebAppManifest(final GeckoSession session, JSONObject manifest) {
|
||||
Log.d(LOGTAG, "onWebAppManifest: " + manifest);
|
||||
}
|
||||
}
|
||||
|
||||
private class ExampleProgressDelegate implements GeckoSession.ProgressDelegate {
|
||||
|
|
Загрузка…
Ссылка в новой задаче