Reland the ULONG -> SIZE_T change from 317177
[chromium-blink-merge.git] / extensions / renderer / content_watcher.h
blob3e3e79622f712a1eb0d01efdb461755f3f03db34
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_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "third_party/WebKit/public/platform/WebVector.h"
15 namespace blink {
16 class WebFrame;
17 class WebString;
20 namespace extensions {
21 class Dispatcher;
22 class Extension;
23 class NativeHandler;
25 // Watches the content of WebFrames to notify extensions when they match various
26 // patterns. This class tracks the set of relevant patterns (set by
27 // ExtensionMsg_WatchPages) and the set that match on each WebFrame, and sends a
28 // ExtensionHostMsg_OnWatchedPageChange whenever a RenderView's set changes.
30 // There's one ContentWatcher per Dispatcher rather than per RenderView because
31 // WebFrames can move between RenderViews through adoptNode.
32 class ContentWatcher {
33 public:
34 ContentWatcher();
35 ~ContentWatcher();
37 // Handler for ExtensionMsg_WatchPages.
38 void OnWatchPages(const std::vector<std::string>& css_selectors);
40 // Uses WebDocument::watchCSSSelectors to watch the selectors in
41 // css_selectors_ and get a callback into DidMatchCSS() whenever the set of
42 // matching selectors in |frame| changes.
43 void DidCreateDocumentElement(blink::WebFrame* frame);
45 // Records that |newly_matching_selectors| have started matching on |*frame|,
46 // and |stopped_matching_selectors| have stopped matching.
47 void DidMatchCSS(
48 blink::WebFrame* frame,
49 const blink::WebVector<blink::WebString>& newly_matching_selectors,
50 const blink::WebVector<blink::WebString>& stopped_matching_selectors);
52 private:
53 // Given that we saw a change in the CSS selectors that |changed_frame|
54 // matched, tell the browser about the new set of matching selectors in its
55 // top-level page. We filter this so that if an extension were to be granted
56 // activeTab permission on that top-level page, we only send CSS selectors for
57 // frames that it could run on.
58 void NotifyBrowserOfChange(blink::WebFrame* changed_frame) const;
60 // If any of these selectors match on a page, we need to send an
61 // ExtensionHostMsg_OnWatchedPageChange back to the browser.
62 blink::WebVector<blink::WebString> css_selectors_;
64 // Maps live WebFrames to the set of CSS selectors they match. Blink sends
65 // back diffs, which we apply to these sets.
66 std::map<blink::WebFrame*, std::set<std::string> > matching_selectors_;
69 } // namespace extensions
71 #endif // EXTENSIONS_RENDERER_CONTENT_WATCHER_H_