diff options
Diffstat (limited to 'android_webview/native/aw_contents.cc')
-rw-r--r-- | android_webview/native/aw_contents.cc | 79 |
1 files changed, 27 insertions, 52 deletions
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index 2a9a35f..64cd9a9 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,23 +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, - base::string16* data, - std::vector<int>* ports) { - content::MessagePortProvider::PostMessageToFrame(web_contents, - *source_origin, *target_origin, *data, *ports); -} - } // namespace // static @@ -1084,49 +1068,40 @@ void AwContents::PostMessageToFrame(JNIEnv* env, jobject obj, jstring frame_name, jstring message, jstring source_origin, jstring target_origin, jintArray msgPorts) { - base::string16* j_source_origin = new base::string16; - ConvertJavaStringToUTF16(env, source_origin, j_source_origin); - base::string16* j_target_origin = new base::string16; - ConvertJavaStringToUTF16(env, target_origin, j_target_origin); - base::string16* j_message = new base::string16; - ConvertJavaStringToUTF16(env, message, j_message); - std::vector<int>* j_ports = new std::vector<int>; - + base::string16 j_source_origin(ConvertJavaStringToUTF16(env, source_origin)); + base::string16 j_target_origin(ConvertJavaStringToUTF16(env, target_origin)); + base::string16 j_message(ConvertJavaStringToUTF16(env, message)); + std::vector<int> j_ports; if (msgPorts != nullptr) - base::android::JavaIntArrayToIntVector(env, msgPorts, j_ports); - - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - base::Bind(&PostMessageToFrameOnIOThread, - web_contents_.get(), - base::Owned(j_source_origin), - base::Owned(j_target_origin), - base::Owned(j_message), - base::Owned(j_ports))); + base::android::JavaIntArrayToIntVector(env, msgPorts, &j_ports); + + content::MessagePortProvider::PostMessageToFrame(web_contents_.get(), + j_source_origin, + j_target_origin, + j_message, + 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; - BrowserThread::PostTaskAndReply( - BrowserThread::IO, - FROM_HERE, - base::Bind(&content::MessagePortProvider::CreateMessageChannel, - web_contents_.get(), - port1, - port2), - base::Bind(&OnMessageChannelCreated, - base::Owned(j_callback), - base::Owned(port1), - base::Owned(port2))); + AwMessagePortServiceImpl::GetInstance()->CreateMessageChannel(env, callback, + GetMessagePortMessageFilter()); } - void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) { g_should_download_favicons = true; } |