page_impl.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2021 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/page_impl.h"
  5. #include "build/build_config.h"
  6. #include "content/public/browser/page.h"
  7. #include "content/public/browser/web_contents.h"
  8. #include "weblayer/browser/navigation_controller_impl.h"
  9. #include "weblayer/browser/tab_impl.h"
  10. #if BUILDFLAG(IS_ANDROID)
  11. #include "weblayer/browser/java/jni/PageImpl_jni.h"
  12. #endif
  13. #if BUILDFLAG(IS_ANDROID)
  14. using base::android::AttachCurrentThread;
  15. using base::android::ScopedJavaLocalRef;
  16. #endif
  17. namespace weblayer {
  18. PAGE_USER_DATA_KEY_IMPL(PageImpl);
  19. PageImpl::PageImpl(content::Page& page)
  20. : content::PageUserData<PageImpl>(page) {}
  21. PageImpl::~PageImpl() {
  22. auto* rfh = &(page().GetMainDocument());
  23. auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
  24. auto* tab = TabImpl::FromWebContents(web_contents);
  25. if (tab) {
  26. auto* navigation_controller =
  27. static_cast<NavigationControllerImpl*>(tab->GetNavigationController());
  28. navigation_controller->OnPageDestroyed(this);
  29. }
  30. #if BUILDFLAG(IS_ANDROID)
  31. if (java_page_) {
  32. Java_PageImpl_onNativeDestroyed(AttachCurrentThread(), java_page_);
  33. }
  34. #endif
  35. }
  36. #if BUILDFLAG(IS_ANDROID)
  37. void PageImpl::SetJavaPage(
  38. JNIEnv* env,
  39. const base::android::JavaParamRef<jobject>& java_page) {
  40. java_page_ = java_page;
  41. }
  42. #endif
  43. } // namespace weblayer