Make shake-to-reload actually work
We need to create a new service provider when we navigate to a new page otherwise the new page is sad that the old page took its service provider. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/962383003
This commit is contained in:
@@ -10,7 +10,7 @@ dot {
|
||||
border-radius: 50px;
|
||||
}
|
||||
</style>
|
||||
<log>Ready</log>
|
||||
<log>Ready!</log>
|
||||
<script>
|
||||
import "dart:sky";
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "base/android/jni_android.h"
|
||||
#include "jni/JavaServiceProvider_jni.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
@@ -14,11 +15,12 @@ bool RegisterJavaServiceProvider(JNIEnv* env) {
|
||||
return RegisterNativesImpl(env);
|
||||
}
|
||||
|
||||
mojo::ScopedMessagePipeHandle CreateJavaServiceProvider() {
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
return mojo::ScopedMessagePipeHandle(
|
||||
mojo::MessagePipeHandle(Java_JavaServiceProvider_create(
|
||||
env, base::android::GetApplicationContext())));
|
||||
void CreateJavaServiceProvider(
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> request) {
|
||||
Java_JavaServiceProvider_create(
|
||||
base::android::AttachCurrentThread(),
|
||||
base::android::GetApplicationContext(),
|
||||
request.PassMessagePipe().release().value());
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
|
||||
#include <jni.h>
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
#include "mojo/public/interfaces/application/service_provider.mojom.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
bool RegisterJavaServiceProvider(JNIEnv* env);
|
||||
mojo::ScopedMessagePipeHandle CreateJavaServiceProvider();
|
||||
void CreateJavaServiceProvider(mojo::InterfaceRequest<mojo::ServiceProvider>);
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.chromium.base.JNINamespace;
|
||||
import org.chromium.mojo.system.Core;
|
||||
import org.chromium.mojo.system.MessagePipeHandle;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
import org.chromium.mojo.system.Pair;
|
||||
import org.chromium.mojo.system.impl.CoreImpl;
|
||||
import org.chromium.mojom.mojo.NetworkService;
|
||||
import org.chromium.mojom.mojo.ServiceProvider;
|
||||
@@ -29,11 +28,10 @@ public class JavaServiceProvider implements ServiceProvider {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@CalledByNative
|
||||
public static int create(Context context) {
|
||||
public static void create(Context context, int nativeHandle) {
|
||||
Core core = CoreImpl.getInstance();
|
||||
Pair<MessagePipeHandle, MessagePipeHandle> messagePipe = core.createMessagePipe(null);
|
||||
ServiceProvider.MANAGER.bind(new JavaServiceProvider(core, context), messagePipe.first);
|
||||
return messagePipe.second.releaseNativeHandle();
|
||||
MessagePipeHandle pipe = core.acquireNativeHandle(nativeHandle).toMessagePipeHandle();
|
||||
ServiceProvider.MANAGER.bind(new JavaServiceProvider(core, context), pipe);
|
||||
}
|
||||
|
||||
public JavaServiceProvider(Core core, Context context) {
|
||||
|
||||
@@ -64,13 +64,13 @@ void Shell::InitUI(const base::Thread::Options& options) {
|
||||
ui_thread_->StartWithOptions(options);
|
||||
|
||||
Engine::Config config;
|
||||
config.java_task_runner = java_task_runner_;
|
||||
config.gpu_task_runner = gpu_thread_->message_loop()->task_runner();
|
||||
config.gpu_delegate = rasterizer_->GetWeakPtr();
|
||||
engine_.reset(new Engine(config));
|
||||
|
||||
ui_thread_->message_loop()->PostTask(
|
||||
FROM_HERE, base::Bind(&Engine::Init, engine_->GetWeakPtr(),
|
||||
base::Passed(CreateJavaServiceProvider())));
|
||||
FROM_HERE, base::Bind(&Engine::Init, engine_->GetWeakPtr()));
|
||||
}
|
||||
|
||||
void Shell::InitView() {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "sky/engine/public/web/WebSettings.h"
|
||||
#include "sky/engine/public/web/WebView.h"
|
||||
#include "sky/services/platform/platform_impl.h"
|
||||
#include "sky/shell/java_service_provider.h"
|
||||
#include "sky/shell/ui/animator.h"
|
||||
#include "sky/shell/ui/input_event_converter.h"
|
||||
#include "sky/shell/ui/internals.h"
|
||||
@@ -32,7 +33,8 @@ void ConfigureSettings(blink::WebSettings* settings) {
|
||||
}
|
||||
|
||||
Engine::Engine(const Config& config)
|
||||
: animator_(new Animator(config, this)),
|
||||
: java_task_runner_(config.java_task_runner),
|
||||
animator_(new Animator(config, this)),
|
||||
web_view_(nullptr),
|
||||
device_pixel_ratio_(1.0f),
|
||||
viewport_observer_binding_(this),
|
||||
@@ -48,9 +50,17 @@ base::WeakPtr<Engine> Engine::GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
void Engine::Init(mojo::ScopedMessagePipeHandle service_provider_handle) {
|
||||
service_provider_ =
|
||||
mojo::MakeProxy<mojo::ServiceProvider>(service_provider_handle.Pass());
|
||||
mojo::ServiceProviderPtr Engine::CreateServiceProvider() {
|
||||
mojo::MessagePipe pipe;
|
||||
java_task_runner_->PostTask(FROM_HERE, base::Bind(
|
||||
CreateJavaServiceProvider,
|
||||
base::Passed(mojo::MakeRequest<mojo::ServiceProvider>(
|
||||
pipe.handle1.Pass()))));
|
||||
return mojo::MakeProxy<mojo::ServiceProvider>(pipe.handle0.Pass());
|
||||
}
|
||||
|
||||
void Engine::Init() {
|
||||
service_provider_ = CreateServiceProvider();
|
||||
mojo::NetworkServicePtr network_service;
|
||||
mojo::ConnectToService(service_provider_.get(), &network_service);
|
||||
platform_impl_.reset(new PlatformImpl(network_service.Pass()));
|
||||
@@ -144,7 +154,7 @@ void Engine::scheduleVisualUpdate() {
|
||||
|
||||
void Engine::didCreateIsolate(blink::WebLocalFrame* frame,
|
||||
Dart_Isolate isolate) {
|
||||
Internals::Create(isolate, service_provider_.Pass());
|
||||
Internals::Create(isolate, CreateServiceProvider());
|
||||
}
|
||||
|
||||
blink::ServiceProvider* Engine::services() {
|
||||
|
||||
@@ -35,6 +35,8 @@ class Engine : public UIDelegate,
|
||||
public blink::WebViewClient {
|
||||
public:
|
||||
struct Config {
|
||||
scoped_refptr<base::SingleThreadTaskRunner> java_task_runner;
|
||||
|
||||
base::WeakPtr<GPUDelegate> gpu_delegate;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner;
|
||||
};
|
||||
@@ -44,7 +46,7 @@ class Engine : public UIDelegate,
|
||||
|
||||
base::WeakPtr<Engine> GetWeakPtr();
|
||||
|
||||
void Init(mojo::ScopedMessagePipeHandle service_provider);
|
||||
void Init();
|
||||
|
||||
void BeginFrame(base::TimeTicks frame_time);
|
||||
skia::RefPtr<SkPicture> Paint();
|
||||
@@ -78,8 +80,10 @@ class Engine : public UIDelegate,
|
||||
void DidNavigateLocally(const mojo::String& url) override;
|
||||
void RequestNavigateHistory(int32_t delta) override;
|
||||
|
||||
mojo::ServiceProviderPtr CreateServiceProvider();
|
||||
void UpdateWebViewSize();
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> java_task_runner_;
|
||||
mojo::ServiceProviderPtr service_provider_;
|
||||
scoped_ptr<PlatformImpl> platform_impl_;
|
||||
scoped_ptr<Animator> animator_;
|
||||
|
||||
Reference in New Issue
Block a user