web_message_reply_proxy_impl.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 WEBLAYER_BROWSER_JS_COMMUNICATION_WEB_MESSAGE_REPLY_PROXY_IMPL_H_
  5. #define WEBLAYER_BROWSER_JS_COMMUNICATION_WEB_MESSAGE_REPLY_PROXY_IMPL_H_
  6. #include <string>
  7. #include "base/android/scoped_java_ref.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "components/js_injection/browser/web_message_host.h"
  10. #include "weblayer/public/js_communication/web_message_host.h"
  11. namespace weblayer {
  12. class WebMessageReplyProxy;
  13. // Created only on the Android side to support post-message.
  14. // WebMessageReplyProxyImpl creates the Java WebMessageReplyProxy that is then
  15. // sent over to the client side for communication with the page.
  16. class WebMessageReplyProxyImpl : public WebMessageHost {
  17. public:
  18. WebMessageReplyProxyImpl(int id,
  19. base::android::ScopedJavaGlobalRef<jobject> client,
  20. const std::string& origin_string,
  21. bool is_main_frame,
  22. WebMessageReplyProxy* reply_proxy);
  23. WebMessageReplyProxyImpl(const WebMessageReplyProxyImpl&) = delete;
  24. WebMessageReplyProxyImpl& operator=(const WebMessageReplyProxyImpl&) = delete;
  25. ~WebMessageReplyProxyImpl() override;
  26. void PostMessage(
  27. JNIEnv* env,
  28. const base::android::JavaParamRef<jstring>& message_contents);
  29. bool IsActive(JNIEnv* env);
  30. // WebMessageHost:
  31. void OnPostMessage(std::unique_ptr<WebMessage> message) override;
  32. void OnBackForwardCacheStateChanged() override;
  33. private:
  34. raw_ptr<WebMessageReplyProxy> reply_proxy_;
  35. // The Java WebMessageReplyProxy.
  36. base::android::ScopedJavaGlobalRef<jobject> java_object_;
  37. };
  38. } // namespace weblayer
  39. #endif // WEBLAYER_BROWSER_JS_COMMUNICATION_WEB_MESSAGE_REPLY_PROXY_IMPL_H_