accuracy_web_contents_observer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef COMPONENTS_ACCURACY_TIPS_ACCURACY_WEB_CONTENTS_OBSERVER_H_
  5. #define COMPONENTS_ACCURACY_TIPS_ACCURACY_WEB_CONTENTS_OBSERVER_H_
  6. #include "base/callback_forward.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "components/accuracy_tips/accuracy_service.h"
  9. #include "components/accuracy_tips/accuracy_tip_status.h"
  10. #include "content/public/browser/visibility.h"
  11. #include "content/public/browser/web_contents.h"
  12. #include "content/public/browser/web_contents_observer.h"
  13. #include "content/public/browser/web_contents_user_data.h"
  14. namespace content {
  15. class NavigationHandle;
  16. } // namespace content
  17. namespace accuracy_tips {
  18. // Observes navigations and triggers a warning if a visited site is determined
  19. // if a visited site is determined to be news-related.
  20. class AccuracyWebContentsObserver
  21. : public content::WebContentsObserver,
  22. public content::WebContentsUserData<AccuracyWebContentsObserver> {
  23. public:
  24. static bool IsEnabled(content::WebContents* web_contents);
  25. ~AccuracyWebContentsObserver() override;
  26. AccuracyWebContentsObserver(const AccuracyWebContentsObserver&) = delete;
  27. AccuracyWebContentsObserver& operator=(const AccuracyWebContentsObserver&) =
  28. delete;
  29. // content::WebContentsObserver:
  30. void DidFinishNavigation(
  31. content::NavigationHandle* navigation_handle) override;
  32. private:
  33. // Callback handler for accuracy result from AccuracyService.
  34. void OnAccuracyStatusObtained(const GURL& url, AccuracyTipStatus result);
  35. friend class content::WebContentsUserData<AccuracyWebContentsObserver>;
  36. AccuracyWebContentsObserver(content::WebContents* web_contents,
  37. AccuracyService* accuracy_service);
  38. raw_ptr<AccuracyService> accuracy_service_;
  39. base::WeakPtrFactory<AccuracyWebContentsObserver> weak_factory_{this};
  40. WEB_CONTENTS_USER_DATA_KEY_DECL();
  41. };
  42. } // namespace accuracy_tips
  43. #endif // COMPONENTS_ACCURACY_TIPS_ACCURACY_WEB_CONTENTS_OBSERVER_H_