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