aw_web_message_host_factory.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ANDROID_WEBVIEW_BROWSER_JS_JAVA_INTERACTION_AW_WEB_MESSAGE_HOST_FACTORY_H_
  5. #define ANDROID_WEBVIEW_BROWSER_JS_JAVA_INTERACTION_AW_WEB_MESSAGE_HOST_FACTORY_H_
  6. #include "base/android/scoped_java_ref.h"
  7. #include "components/js_injection/browser/web_message_host_factory.h"
  8. namespace js_injection {
  9. class JsCommunicationHost;
  10. }
  11. namespace android_webview {
  12. // Adapts WebMessageHostFactory for use by WebView. An AwWebMessageHostFactory
  13. // is created per WebMessageListener. More specifically, every call to
  14. // AwContents::AddWebMessageListener() creates a new AwWebMessageHostFactory.
  15. class AwWebMessageHostFactory : public js_injection::WebMessageHostFactory {
  16. public:
  17. explicit AwWebMessageHostFactory(
  18. const base::android::JavaParamRef<jobject>& listener);
  19. AwWebMessageHostFactory(const AwWebMessageHostFactory&) = delete;
  20. AwWebMessageHostFactory& operator=(const AwWebMessageHostFactory&) = delete;
  21. ~AwWebMessageHostFactory() override;
  22. // Returns an array of WebMessageListenerInfos based on the registered
  23. // factories.
  24. static base::android::ScopedJavaLocalRef<jobjectArray>
  25. GetWebMessageListenerInfo(js_injection::JsCommunicationHost* host,
  26. JNIEnv* env,
  27. const base::android::JavaParamRef<jclass>& clazz);
  28. // js_injection::WebMessageConnection:
  29. std::unique_ptr<js_injection::WebMessageHost> CreateHost(
  30. const std::string& origin_string,
  31. bool is_main_frame,
  32. js_injection::WebMessageReplyProxy* proxy) override;
  33. private:
  34. // The WebMessageListenerHost that was supplied to
  35. // AwContents::AddWebMessageListener().
  36. base::android::ScopedJavaGlobalRef<jobject> listener_;
  37. };
  38. } // namespace android_webview
  39. #endif // ANDROID_WEBVIEW_BROWSER_JS_JAVA_INTERACTION_AW_WEB_MESSAGE_HOST_FACTORY_H_