Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1112)

Unified Diff: content/browser/message_port_provider.cc

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Address feedback from yusuf Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/message_port_provider.cc
diff --git a/content/browser/message_port_provider.cc b/content/browser/message_port_provider.cc
index aa6ae9567bf6aba436ec979b8773282dde027690..d01696c4d4b533a21f2663ae51a1923c58b4a2e3 100644
--- a/content/browser/message_port_provider.cc
+++ b/content/browser/message_port_provider.cc
@@ -5,57 +5,74 @@
#include "content/public/browser/message_port_provider.h"
#include "content/browser/browser_thread_impl.h"
-#include "content/browser/message_port_message_filter.h"
-#include "content/browser/message_port_service.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/frame_messages.h"
-#include "content/public/browser/message_port_delegate.h"
#if defined(OS_ANDROID)
-#include "content/browser/android/app_web_message_port_service_impl.h"
+#include "base/android/jni_string.h"
+#include "content/browser/android/app_web_message_port.h"
#endif
namespace content {
+namespace {
-// static
-void MessagePortProvider::PostMessageToFrame(
+void PostMessageToFrameInternal(
WebContents* web_contents,
const base::string16& source_origin,
const base::string16& target_origin,
const base::string16& data,
- const std::vector<int>& ports) {
+ std::vector<MessagePort> ports) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
-#if defined(OS_ANDROID)
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&content::AppWebMessagePortServiceImpl::RemoveSentPorts,
- base::Unretained(AppWebMessagePortServiceImpl::GetInstance()),
- ports));
-#endif
FrameMsg_PostMessage_Params params;
params.is_data_raw_string = true;
params.data = data;
params.source_routing_id = MSG_ROUTING_NONE;
params.source_origin = source_origin;
params.target_origin = target_origin;
- params.message_ports = ports;
-
- RenderProcessHostImpl* rph =
- static_cast<RenderProcessHostImpl*>(web_contents->GetRenderProcessHost());
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts,
- rph->message_port_message_filter(),
- web_contents->GetMainFrame()->GetRoutingID(), params));
+ params.message_ports = std::move(ports);
+
+ RenderFrameHost* rfh = web_contents->GetMainFrame();
+ rfh->Send(new FrameMsg_PostMessageEvent(rfh->GetRoutingID(), params));
}
#if defined(OS_ANDROID)
+base::string16 ToString16(JNIEnv* env,
+ const base::android::JavaParamRef<jstring>& s) {
+ if (s.is_null())
+ return base::string16();
+ return base::android::ConvertJavaStringToUTF16(env, s);
+}
+#endif
+
+} // namespace
+
// static
-AppWebMessagePortService* MessagePortProvider::GetAppWebMessagePortService() {
- return AppWebMessagePortServiceImpl::GetInstance();
+void MessagePortProvider::PostMessageToFrame(
+ WebContents* web_contents,
+ const base::string16& source_origin,
+ const base::string16& target_origin,
+ const base::string16& data) {
+ PostMessageToFrameInternal(web_contents, source_origin, target_origin, data,
+ std::vector<MessagePort>());
+}
+
+#if defined(OS_ANDROID)
+void MessagePortProvider::PostMessageToFrame(
+ WebContents* web_contents,
+ JNIEnv* env,
+ const base::android::JavaParamRef<jstring>& source_origin,
+ const base::android::JavaParamRef<jstring>& target_origin,
+ const base::android::JavaParamRef<jstring>& data,
+ const base::android::JavaParamRef<jobjectArray>& ports) {
+ PostMessageToFrameInternal(
+ web_contents,
+ ToString16(env, source_origin),
+ ToString16(env, target_origin),
+ ToString16(env, data),
+ AppWebMessagePort::UnwrapJavaArray(env, ports));
}
#endif

Powered by Google App Engine
This is Rietveld 408576698