| Index: android_webview/native/aw_contents.cc
|
| diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
|
| index 2a9a35f91f331150de1ec2da90f48a63b31fb181..522057a74e09fb0de49b0be7627dd83aca41d3bc 100644
|
| --- a/android_webview/native/aw_contents.cc
|
| +++ b/android_webview/native/aw_contents.cc
|
| @@ -21,6 +21,7 @@
|
| #include "android_webview/native/aw_browser_dependency_factory.h"
|
| #include "android_webview/native/aw_contents_client_bridge.h"
|
| #include "android_webview/native/aw_contents_io_thread_client_impl.h"
|
| +#include "android_webview/native/aw_message_port_service_impl.h"
|
| #include "android_webview/native/aw_pdf_exporter.h"
|
| #include "android_webview/native/aw_picture.h"
|
| #include "android_webview/native/aw_web_contents_delegate.h"
|
| @@ -133,14 +134,6 @@ void OnIoThreadClientReady(content::RenderFrameHost* rfh) {
|
| render_process_id, render_frame_id);
|
| }
|
|
|
| -void OnMessageChannelCreated(ScopedJavaGlobalRef<jobject>* callback,
|
| - int* port1,
|
| - int* port2) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - Java_AwContents_onMessageChannelCreated(env, *port1, *port2,
|
| - callback->obj());
|
| -}
|
| -
|
| void PostMessageToFrameOnIOThread(WebContents* web_contents,
|
| base::string16* source_origin,
|
| base::string16* target_origin,
|
| @@ -1106,24 +1099,39 @@ void AwContents::PostMessageToFrame(JNIEnv* env, jobject obj,
|
| base::Owned(j_ports)));
|
| }
|
|
|
| +scoped_refptr<AwMessagePortMessageFilter>
|
| +AwContents::GetMessagePortMessageFilter() {
|
| + // Create a message port message filter if necessary
|
| + if (message_port_message_filter_.get() == nullptr) {
|
| + message_port_message_filter_ =
|
| + new AwMessagePortMessageFilter(
|
| + web_contents_->GetMainFrame()->GetRoutingID());
|
| + web_contents_->GetRenderProcessHost()->AddFilter(
|
| + message_port_message_filter_.get());
|
| + }
|
| + return message_port_message_filter_;
|
| +}
|
| +
|
| void AwContents::CreateMessageChannel(JNIEnv* env, jobject obj,
|
| jobject callback) {
|
| ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>();
|
| j_callback->Reset(env, callback);
|
|
|
| - int* port1 = new int;
|
| - int* port2 = new int;
|
| + int* portId1 = new int;
|
| + int* portId2 = new int;
|
| BrowserThread::PostTaskAndReply(
|
| BrowserThread::IO,
|
| FROM_HERE,
|
| base::Bind(&content::MessagePortProvider::CreateMessageChannel,
|
| - web_contents_.get(),
|
| - port1,
|
| - port2),
|
| - base::Bind(&OnMessageChannelCreated,
|
| + GetMessagePortMessageFilter(),
|
| + portId1,
|
| + portId2),
|
| + base::Bind(&AwMessagePortServiceImpl::OnMessageChannelCreated,
|
| + base::Unretained(AwMessagePortServiceImpl::GetInstance()),
|
| + GetMessagePortMessageFilter(),
|
| base::Owned(j_callback),
|
| - base::Owned(port1),
|
| - base::Owned(port2)));
|
| + base::Owned(portId1),
|
| + base::Owned(portId2)));
|
| }
|
|
|
|
|
|
|