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.
5 #ifndef EXTENSIONS_RENDERER_CONTENT_WATCHER_H_
6 #define EXTENSIONS_RENDERER_CONTENT_WATCHER_H_
13 #include "third_party/WebKit/public/platform/WebVector.h"
21 namespace extensions
{
26 // Watches the content of WebFrames to notify extensions when they match various
27 // patterns. This class tracks the set of relevant patterns (set by
28 // ExtensionMsg_WatchPages) and the set that match on each WebFrame, and sends a
29 // ExtensionHostMsg_OnWatchedPageChange whenever a RenderView's set changes.
31 // There's one ContentWatcher per Dispatcher rather than per RenderView because
32 // WebFrames can move between RenderViews through adoptNode.
33 // TODO(devlin): This class isn't OOPI-safe.
34 class ContentWatcher
{
39 // Handler for ExtensionMsg_WatchPages.
40 void OnWatchPages(const std::vector
<std::string
>& css_selectors
);
42 // Uses WebDocument::watchCSSSelectors to watch the selectors in
43 // css_selectors_ and get a callback into DidMatchCSS() whenever the set of
44 // matching selectors in |frame| changes.
45 void DidCreateDocumentElement(blink::WebLocalFrame
* frame
);
47 // Records that |newly_matching_selectors| have started matching on |*frame|,
48 // and |stopped_matching_selectors| have stopped matching.
50 blink::WebLocalFrame
* frame
,
51 const blink::WebVector
<blink::WebString
>& newly_matching_selectors
,
52 const blink::WebVector
<blink::WebString
>& stopped_matching_selectors
);
55 // Given that we saw a change in the CSS selectors that |changed_frame|
56 // matched, tell the browser about the new set of matching selectors in its
57 // top-level page. We filter this so that if an extension were to be granted
58 // activeTab permission on that top-level page, we only send CSS selectors for
59 // frames that it could run on.
60 void NotifyBrowserOfChange(blink::WebLocalFrame
* changed_frame
) const;
62 // If any of these selectors match on a page, we need to send an
63 // ExtensionHostMsg_OnWatchedPageChange back to the browser.
64 blink::WebVector
<blink::WebString
> css_selectors_
;
66 // Maps live WebFrames to the set of CSS selectors they match. Blink sends
67 // back diffs, which we apply to these sets.
68 std::map
<blink::WebFrame
*, std::set
<std::string
> > matching_selectors_
;
71 } // namespace extensions
73 #endif // EXTENSIONS_RENDERER_CONTENT_WATCHER_H_