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

Unified Diff: content/browser/android/app_web_message_port_message_filter.cc

Issue 2375133002: Move MessagePort implementation from android_webview to content (Closed)
Patch Set: Created 4 years, 3 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/android/app_web_message_port_message_filter.cc
diff --git a/content/browser/android/app_web_message_port_message_filter.cc b/content/browser/android/app_web_message_port_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a46dc02a3083ddecfd7df9f2d93e61debfc25235
--- /dev/null
+++ b/content/browser/android/app_web_message_port_message_filter.cc
@@ -0,0 +1,99 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/android/app_web_message_port_message_filter.h"
sgurun-gerrit only 2016/09/30 23:40:59 can you lower the similarity parameter so rietveld
Yusuf 2016/10/04 21:33:14 Umm, sorry I am not sure I understand how I do tha
+#include "content/browser/android/app_web_message_port_service_impl.h"
+#include "content/browser/message_port_service.h"
+#include "content/common/app_web_message_port_messages.h"
+#include "content/public/browser/android/app_web_message_port_service.h"
+#include "content/public/browser/message_port_provider.h"
+
+using content::BrowserThread;
+using content::MessagePortProvider;
+
+namespace content {
+
+AppWebMessagePortMessageFilter::AppWebMessagePortMessageFilter(int route_id)
+ : BrowserMessageFilter(AwMessagePortMsgStart), route_id_(route_id) {
+}
+
+AppWebMessagePortMessageFilter::~AppWebMessagePortMessageFilter() {
+}
+
+void AppWebMessagePortMessageFilter::OnChannelClosing() {
+ MessagePortService::GetInstance()->OnMessagePortDelegateClosing(this);
+ AppWebMessagePortServiceImpl::GetInstance()->
+ OnMessagePortMessageFilterClosing(this);
+}
+
+bool AppWebMessagePortMessageFilter::OnMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(AppWebMessagePortMessageFilter, message)
+ IPC_MESSAGE_FORWARD(AppWebMessagePortHostMsg_ConvertedWebToAppMessage,
+ content::MessagePortProvider
+ ::GetAppWebMessagePortService(),
+ AppWebMessagePortService::OnConvertedWebToAppMessage)
sgurun-gerrit only 2016/09/30 23:40:59 directly use the impl class
Yusuf 2016/10/04 21:33:14 Done.
+ IPC_MESSAGE_HANDLER(AppWebMessagePortHostMsg_ConvertedAppToWebMessage,
+ OnConvertedAppToWebMessage)
+ IPC_MESSAGE_HANDLER(AppWebMessagePortHostMsg_ClosePortAck, OnClosePortAck)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void AppWebMessagePortMessageFilter::OnConvertedAppToWebMessage(
+ int msg_port_id,
+ const base::string16& message,
+ const std::vector<int>& sent_message_port_ids) {
+ MessagePortService* msp = MessagePortService::GetInstance();
+ msp->PostMessage(msg_port_id, message, sent_message_port_ids);
+}
+
+void AppWebMessagePortMessageFilter::OnClosePortAck(int message_port_id) {
+ MessagePortService* msp = MessagePortService::GetInstance();
+ msp->ClosePort(message_port_id);
+ AppWebMessagePortServiceImpl::GetInstance()->
+ CleanupPort(message_port_id);
+}
+
+void AppWebMessagePortMessageFilter::OnDestruct() const {
+ BrowserThread::DeleteOnIOThread::Destruct(this);
+}
+
+void AppWebMessagePortMessageFilter::SendAppToWebMessage(
+ int msg_port_route_id,
+ const base::string16& message,
+ const std::vector<int>& sent_message_port_ids) {
+ Send(new AppWebMessagePortMsg_AppToWebMessage(
+ route_id_,
+ msg_port_route_id, // same as the port id
+ message, sent_message_port_ids));
+}
+
+void AppWebMessagePortMessageFilter::SendClosePortMessage(int message_port_id) {
+ Send(new AppWebMessagePortMsg_ClosePort(route_id_, message_port_id));
+}
+
+void AppWebMessagePortMessageFilter::SendMessage(
+ int msg_port_route_id,
+ const base::string16& message,
+ const std::vector<int>& sent_message_port_ids) {
+ MessagePortService* msp = MessagePortService::GetInstance();
+ for (int sent_port_id : sent_message_port_ids) {
+ msp->HoldMessages(sent_port_id);
+ msp->UpdateMessagePort(sent_port_id, this, sent_port_id);
+ }
+ Send(new AppWebMessagePortMsg_WebToAppMessage(
+ route_id_,
+ msg_port_route_id, // same as the port id
+ message, sent_message_port_ids));
+}
+
+void AppWebMessagePortMessageFilter::SendMessagesAreQueued(int route_id) {
+ // TODO(sgurun) implement
+ NOTREACHED();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698