OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_RENDERER_EXTENSIONS_CONTENT_WATCHER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_CONTENT_WATCHER_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_CONTENT_WATCHER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_CONTENT_WATCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "third_party/WebKit/public/platform/WebVector.h" | 13 #include "third_party/WebKit/public/platform/WebVector.h" |
14 | 14 |
15 namespace WebKit { | 15 namespace blink { |
16 class WebFrame; | 16 class WebFrame; |
17 class WebString; | 17 class WebString; |
18 } | 18 } |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 class Dispatcher; | 21 class Dispatcher; |
22 class Extension; | 22 class Extension; |
23 class NativeHandler; | 23 class NativeHandler; |
24 | 24 |
25 // Watches the content of WebFrames to notify extensions when they match various | 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 | 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 | 27 // ExtensionMsg_WatchPages) and the set that match on each WebFrame, and sends a |
28 // ExtensionHostMsg_OnWatchedPageChange whenever a RenderView's set changes. | 28 // ExtensionHostMsg_OnWatchedPageChange whenever a RenderView's set changes. |
29 // | 29 // |
30 // There's one ContentWatcher per Dispatcher rather than per RenderView because | 30 // There's one ContentWatcher per Dispatcher rather than per RenderView because |
31 // WebFrames can move between RenderViews through adoptNode. | 31 // WebFrames can move between RenderViews through adoptNode. |
32 class ContentWatcher { | 32 class ContentWatcher { |
33 public: | 33 public: |
34 ContentWatcher(); | 34 ContentWatcher(); |
35 ~ContentWatcher(); | 35 ~ContentWatcher(); |
36 | 36 |
37 // Handler for ExtensionMsg_WatchPages. | 37 // Handler for ExtensionMsg_WatchPages. |
38 void OnWatchPages(const std::vector<std::string>& css_selectors); | 38 void OnWatchPages(const std::vector<std::string>& css_selectors); |
39 | 39 |
40 // Uses WebDocument::watchCSSSelectors to watch the selectors in | 40 // Uses WebDocument::watchCSSSelectors to watch the selectors in |
41 // css_selectors_ and get a callback into DidMatchCSS() whenever the set of | 41 // css_selectors_ and get a callback into DidMatchCSS() whenever the set of |
42 // matching selectors in |frame| changes. | 42 // matching selectors in |frame| changes. |
43 void DidCreateDocumentElement(WebKit::WebFrame* frame); | 43 void DidCreateDocumentElement(blink::WebFrame* frame); |
44 | 44 |
45 // Records that |newly_matching_selectors| have started matching on |*frame|, | 45 // Records that |newly_matching_selectors| have started matching on |*frame|, |
46 // and |stopped_matching_selectors| have stopped matching. | 46 // and |stopped_matching_selectors| have stopped matching. |
47 void DidMatchCSS( | 47 void DidMatchCSS( |
48 WebKit::WebFrame* frame, | 48 blink::WebFrame* frame, |
49 const WebKit::WebVector<WebKit::WebString>& newly_matching_selectors, | 49 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
50 const WebKit::WebVector<WebKit::WebString>& stopped_matching_selectors); | 50 const blink::WebVector<blink::WebString>& stopped_matching_selectors); |
51 | 51 |
52 private: | 52 private: |
53 // Given that we saw a change in the CSS selectors that |changed_frame| | 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 | 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 | 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 | 56 // activeTab permission on that top-level page, we only send CSS selectors for |
57 // frames that it could run on. | 57 // frames that it could run on. |
58 void NotifyBrowserOfChange(WebKit::WebFrame* changed_frame) const; | 58 void NotifyBrowserOfChange(blink::WebFrame* changed_frame) const; |
59 | 59 |
60 // If any of these selectors match on a page, we need to send an | 60 // If any of these selectors match on a page, we need to send an |
61 // ExtensionHostMsg_OnWatchedPageChange back to the browser. | 61 // ExtensionHostMsg_OnWatchedPageChange back to the browser. |
62 WebKit::WebVector<WebKit::WebString> css_selectors_; | 62 blink::WebVector<blink::WebString> css_selectors_; |
63 | 63 |
64 // Maps live WebFrames to the set of CSS selectors they match. Blink sends | 64 // Maps live WebFrames to the set of CSS selectors they match. Blink sends |
65 // back diffs, which we apply to these sets. | 65 // back diffs, which we apply to these sets. |
66 std::map<WebKit::WebFrame*, std::set<std::string> > matching_selectors_; | 66 std::map<blink::WebFrame*, std::set<std::string> > matching_selectors_; |
67 }; | 67 }; |
68 | 68 |
69 } // namespace extensions | 69 } // namespace extensions |
70 | 70 |
71 #endif // CHROME_RENDERER_EXTENSIONS_CONTENT_WATCHER_H_ | 71 #endif // CHROME_RENDERER_EXTENSIONS_CONTENT_WATCHER_H_ |
OLD | NEW |