test_infobar.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "weblayer/browser/test/test_infobar.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "base/bind.h"
  8. #include "components/infobars/content/content_infobar_manager.h"
  9. #include "components/infobars/core/infobar_delegate.h"
  10. #include "weblayer/browser/java/test_jni/TestInfoBar_jni.h"
  11. using base::android::JavaParamRef;
  12. using base::android::ScopedJavaLocalRef;
  13. namespace weblayer {
  14. class TestInfoBarDelegate : public infobars::InfoBarDelegate {
  15. public:
  16. TestInfoBarDelegate() = default;
  17. ~TestInfoBarDelegate() override = default;
  18. infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override {
  19. return InfoBarDelegate::InfoBarIdentifier::TEST_INFOBAR;
  20. }
  21. };
  22. TestInfoBar::TestInfoBar(std::unique_ptr<TestInfoBarDelegate> delegate)
  23. : infobars::InfoBarAndroid(std::move(delegate)) {}
  24. TestInfoBar::~TestInfoBar() = default;
  25. void TestInfoBar::ProcessButton(int action) {}
  26. ScopedJavaLocalRef<jobject> TestInfoBar::CreateRenderInfoBar(
  27. JNIEnv* env,
  28. const ResourceIdMapper& resource_id_mapper) {
  29. return Java_TestInfoBar_create(env);
  30. }
  31. // static
  32. void TestInfoBar::Show(content::WebContents* web_contents) {
  33. infobars::ContentInfoBarManager* manager =
  34. infobars::ContentInfoBarManager::FromWebContents(web_contents);
  35. manager->AddInfoBar(
  36. std::make_unique<TestInfoBar>(std::make_unique<TestInfoBarDelegate>()));
  37. }
  38. static void JNI_TestInfoBar_Show(
  39. JNIEnv* env,
  40. const base::android::JavaParamRef<jobject>& j_web_contents) {
  41. auto* web_contents =
  42. content::WebContents::FromJavaWebContents(j_web_contents);
  43. TestInfoBar::Show(web_contents);
  44. }
  45. } // namespace weblayer