web_message_host_factory_proxy.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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_HOST_FACTORY_PROXY_H_
  5. #define WEBLAYER_BROWSER_JS_COMMUNICATION_WEB_MESSAGE_HOST_FACTORY_PROXY_H_
  6. #include "base/android/scoped_java_ref.h"
  7. #include "weblayer/public/js_communication/web_message_host_factory.h"
  8. namespace weblayer {
  9. // TabImpl, on android, creates a WebMessageHostFactoryProxy for every call
  10. // to RegisterWebMessageCallback(). This is used to delegate the calls back to
  11. // the Java side.
  12. class WebMessageHostFactoryProxy : public WebMessageHostFactory {
  13. public:
  14. explicit WebMessageHostFactoryProxy(
  15. const base::android::JavaParamRef<jobject>& client);
  16. WebMessageHostFactoryProxy(const WebMessageHostFactoryProxy&) = delete;
  17. WebMessageHostFactoryProxy& operator=(const WebMessageHostFactoryProxy&) =
  18. delete;
  19. ~WebMessageHostFactoryProxy() override;
  20. // WebMessageHostFactory:
  21. std::unique_ptr<WebMessageHost> CreateHost(
  22. const std::string& origin_string,
  23. bool is_main_frame,
  24. WebMessageReplyProxy* proxy) override;
  25. private:
  26. base::android::ScopedJavaGlobalRef<jobject> client_;
  27. int next_id_ = 0;
  28. };
  29. } // namespace weblayer
  30. #endif // WEBLAYER_BROWSER_JS_COMMUNICATION_WEB_MESSAGE_HOST_FACTORY_PROXY_H_