OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ANDROID_WEBVIEW_NATIVE_AW_MESSAGE_PORT_SERVICE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_APP_WEB_MESSAGE_PORT_SERVICE_IMPL_H_ |
6 #define ANDROID_WEBVIEW_NATIVE_AW_MESSAGE_PORT_SERVICE_IMPL_H_ | 6 #define CONTENT_BROWSER_ANDROID_APP_WEB_MESSAGE_PORT_SERVICE_IMPL_H_ |
7 | 7 |
8 #include <jni.h> | |
9 #include <map> | 8 #include <map> |
10 | 9 |
11 #include "android_webview/browser/aw_message_port_service.h" | |
12 #include "base/android/jni_weak_ref.h" | 10 #include "base/android/jni_weak_ref.h" |
13 #include "base/macros.h" | 11 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/singleton.h" |
15 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "content/public/browser/android/app_web_message_port_service.h" |
16 | 16 |
17 namespace android_webview { | |
18 | 17 |
19 // This class is the native peer of AwMessagePortService.java. Please see the | 18 namespace content { |
20 // java class for an explanation of use, ownership and lifetime. | 19 class AppWebMessagePortMessageFilter; |
| 20 |
| 21 // This class is the native peer of AppWebMessagePortService.java. |
| 22 // Please see the java class for an explanation of use, ownership and lifetime. |
21 | 23 |
22 // Threading: Created and initialized on UI thread. For other methods, see | 24 // Threading: Created and initialized on UI thread. For other methods, see |
23 // the method level DCHECKS or documentation. | 25 // the method level DCHECKS or documentation. |
24 class AwMessagePortServiceImpl : public AwMessagePortService { | 26 class AppWebMessagePortServiceImpl : public AppWebMessagePortService { |
25 public: | 27 public: |
26 static AwMessagePortServiceImpl* GetInstance(); | |
27 | 28 |
28 AwMessagePortServiceImpl(); | 29 // Returns the AppWebMessagePortServiceImpl singleton. |
29 ~AwMessagePortServiceImpl() override; | 30 static AppWebMessagePortServiceImpl* GetInstance(); |
| 31 |
| 32 AppWebMessagePortServiceImpl(); |
| 33 ~AppWebMessagePortServiceImpl() override; |
30 void Init(JNIEnv* env, jobject object); | 34 void Init(JNIEnv* env, jobject object); |
31 | 35 |
32 void CreateMessageChannel(JNIEnv* env, jobjectArray ports, | 36 // AppWebMessagePortService implementation |
33 scoped_refptr<AwMessagePortMessageFilter> filter); | |
34 | 37 |
35 // AwMessagePortService implementation | 38 void CreateMessageChannel( |
36 void OnConvertedWebToAppMessage( | 39 JNIEnv* env, jobjectArray ports, WebContents* web_contents) override; |
37 int message_port_id, | |
38 const base::ListValue& message, | |
39 const std::vector<int>& sent_message_port_ids) override; | |
40 void OnMessagePortMessageFilterClosing( | |
41 AwMessagePortMessageFilter* filter) override; | |
42 void CleanupPort(int message_port_id) override; | 40 void CleanupPort(int message_port_id) override; |
43 | 41 |
44 // Methods called from Java. | 42 // Methods called from Java. |
45 void PostAppToWebMessage( | 43 void PostAppToWebMessage( |
46 JNIEnv* env, | 44 JNIEnv* env, |
47 const base::android::JavaParamRef<jobject>& object, | 45 const base::android::JavaParamRef<jobject>& object, |
48 int sender_id, | 46 int sender_id, |
49 const base::android::JavaParamRef<jstring>& message, | 47 const base::android::JavaParamRef<jstring>& message, |
50 const base::android::JavaParamRef<jintArray>& sent_ports); | 48 const base::android::JavaParamRef<jintArray>& sent_ports); |
51 void ClosePort(JNIEnv* env, | 49 void ClosePort(JNIEnv* env, |
52 const base::android::JavaParamRef<jobject>& object, | 50 const base::android::JavaParamRef<jobject>& object, |
53 int message_port_id); | 51 int message_port_id); |
54 void ReleaseMessages(JNIEnv* env, | 52 void ReleaseMessages(JNIEnv* env, |
55 const base::android::JavaParamRef<jobject>& object, | 53 const base::android::JavaParamRef<jobject>& object, |
56 int message_port_id); | 54 int message_port_id); |
57 | 55 |
| 56 void OnMessagePortMessageFilterClosing( |
| 57 AppWebMessagePortMessageFilter* filter); |
| 58 |
| 59 // AppWebMessagePortServiceImpl specific calls |
| 60 void OnConvertedWebToAppMessage( |
| 61 int message_port_id, |
| 62 const base::ListValue& message, |
| 63 const std::vector<int>& sent_message_port_ids); |
58 void RemoveSentPorts(const std::vector<int>& sent_ports); | 64 void RemoveSentPorts(const std::vector<int>& sent_ports); |
59 | 65 |
60 private: | 66 private: |
| 67 friend struct base::DefaultSingletonTraits<AppWebMessagePortServiceImpl>; |
| 68 |
61 void PostAppToWebMessageOnIOThread( | 69 void PostAppToWebMessageOnIOThread( |
62 int sender_id, | 70 int sender_id, |
63 base::string16* message, | 71 base::string16* message, |
64 std::vector<int>* sent_ports); | 72 std::vector<int>* sent_ports); |
65 void CreateMessageChannelOnIOThread( | 73 void CreateMessageChannelOnIOThread( |
66 scoped_refptr<AwMessagePortMessageFilter> filter, | 74 scoped_refptr<AppWebMessagePortMessageFilter> filter, |
67 int* port1, | 75 int* port1, |
68 int* port2); | 76 int* port2); |
69 void OnMessageChannelCreated( | 77 void OnMessageChannelCreated( |
70 base::android::ScopedJavaGlobalRef<jobjectArray>* ports, | 78 base::android::ScopedJavaGlobalRef<jobjectArray>* ports, |
71 int* port1, | 79 int* port1, |
72 int* port2); | 80 int* port2); |
73 void AddPort(int message_port_id, AwMessagePortMessageFilter* filter); | 81 void AddPort(int message_port_id, AppWebMessagePortMessageFilter* filter); |
74 void PostClosePortMessage(int message_port_id); | 82 void PostClosePortMessage(int message_port_id); |
75 | 83 |
76 JavaObjectWeakGlobalRef java_ref_; | 84 JavaObjectWeakGlobalRef java_ref_; |
77 typedef std::map<int, AwMessagePortMessageFilter*> MessagePorts; | 85 typedef std::map<int, AppWebMessagePortMessageFilter*> MessagePorts; |
78 MessagePorts ports_; // Access on IO thread | 86 MessagePorts ports_; // Access on IO thread |
79 | 87 |
80 DISALLOW_COPY_AND_ASSIGN(AwMessagePortServiceImpl); | 88 DISALLOW_COPY_AND_ASSIGN(AppWebMessagePortServiceImpl); |
81 }; | 89 }; |
82 | 90 |
83 bool RegisterAwMessagePortService(JNIEnv* env); | 91 bool RegisterAppWebMessagePortService(JNIEnv* env); |
84 | 92 |
85 } // namespace android_webview | 93 } // namespace content |
86 | 94 |
87 #endif // ANDROID_WEBVIEW_NATIVE_AW_MESSAGE_PORT_SERVICE_IMPL_H_ | 95 #endif // CONTENT_BROWSER_ANDROID_APP_WEB_MESSAGE_PORT_SERVICE_IMPL_H_ |
OLD | NEW |