content_watcher.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2014 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 EXTENSIONS_RENDERER_CONTENT_WATCHER_H_
  5. #define EXTENSIONS_RENDERER_CONTENT_WATCHER_H_
  6. #include <string>
  7. #include <vector>
  8. #include "third_party/blink/public/platform/web_vector.h"
  9. namespace blink {
  10. class WebString;
  11. }
  12. namespace content {
  13. class RenderFrame;
  14. }
  15. namespace extensions {
  16. // Handles watching the content of WebFrames to notify extensions when they
  17. // match various patterns. This class tracks the set of relevant patterns (set
  18. // by the WatchPages Mojo method) and the set that match on each WebFrame, and
  19. // calls extensions::mojom::LocalFrameHost::WatchedPageChange whenever a
  20. // RenderFrame's set changes.
  21. class ContentWatcher {
  22. public:
  23. ContentWatcher();
  24. ContentWatcher(const ContentWatcher&) = delete;
  25. ContentWatcher& operator=(const ContentWatcher&) = delete;
  26. ~ContentWatcher();
  27. // Handler for the WatchPages Mojo method in extensions.mojom.Renderer
  28. // interface.
  29. void OnWatchPages(const std::vector<std::string>& css_selectors);
  30. void OnRenderFrameCreated(content::RenderFrame* render_frame);
  31. private:
  32. // If any of these selectors match on a page, we need to call
  33. // extensions::mojom::LocalFrameHost::WatchedPageChange to notify the browser.
  34. blink::WebVector<blink::WebString> css_selectors_;
  35. };
  36. } // namespace extensions
  37. #endif // EXTENSIONS_RENDERER_CONTENT_WATCHER_H_