| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_RENDERER_CONTENT_WATCHER_H_ | 5 #ifndef EXTENSIONS_RENDERER_CONTENT_WATCHER_H_ |
| 6 #define EXTENSIONS_RENDERER_CONTENT_WATCHER_H_ | 6 #define EXTENSIONS_RENDERER_CONTENT_WATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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(const std::string& event_name); |
| 35 ~ContentWatcher(); | 35 virtual ~ContentWatcher(); |
| 36 | 36 |
| 37 // Handler for ExtensionMsg_WatchPages. | 37 // Indirect handler for ExtensionMsg_WatchPages (mediated by |
| 38 // Dispatcher::OnWatchPages). |
| 38 void OnWatchPages(const std::vector<std::string>& css_selectors); | 39 void OnWatchPages(const std::vector<std::string>& css_selectors); |
| 39 | 40 |
| 40 // Uses WebDocument::watchCSSSelectors to watch the selectors in | 41 // Uses WebDocument::watchCSSSelectors to watch the selectors in |
| 41 // css_selectors_ and get a callback into DidMatchCSS() whenever the set of | 42 // css_selectors_ and get a callback into DidMatchCSS() whenever the set of |
| 42 // matching selectors in |frame| changes. | 43 // matching selectors in |frame| changes. |
| 43 void DidCreateDocumentElement(blink::WebFrame* frame); | 44 void DidCreateDocumentElement(blink::WebFrame* frame); |
| 44 | 45 |
| 45 // Records that |newly_matching_selectors| have started matching on |*frame|, | 46 // Records that |newly_matching_selectors| have started matching on |*frame|, |
| 46 // and |stopped_matching_selectors| have stopped matching. | 47 // and |stopped_matching_selectors| have stopped matching. |
| 47 void DidMatchCSS( | 48 void DidMatchCSS( |
| 48 blink::WebFrame* frame, | 49 blink::WebFrame* frame, |
| 49 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 50 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 50 const blink::WebVector<blink::WebString>& stopped_matching_selectors); | 51 const blink::WebVector<blink::WebString>& stopped_matching_selectors); |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 // Given that we saw a change in the CSS selectors that |changed_frame| | 54 // 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 // 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 // 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 // activeTab permission on that top-level page, we only send CSS selectors for |
| 57 // frames that it could run on. | 58 // frames that it could run on. |
| 58 void NotifyBrowserOfChange(blink::WebFrame* changed_frame) const; | 59 void NotifyBrowserOfChange(blink::WebFrame* changed_frame) const; |
| 59 | 60 |
| 61 // Event name associated with the browser-side component that corresponds to |
| 62 // this content watcher (included in ExtensionMsg_WatchPages messages). |
| 63 std::string event_name_; |
| 64 |
| 60 // If any of these selectors match on a page, we need to send an | 65 // If any of these selectors match on a page, we need to send an |
| 61 // ExtensionHostMsg_OnWatchedPageChange back to the browser. | 66 // ExtensionHostMsg_OnWatchedPageChange back to the browser. |
| 62 blink::WebVector<blink::WebString> css_selectors_; | 67 blink::WebVector<blink::WebString> css_selectors_; |
| 63 | 68 |
| 64 // Maps live WebFrames to the set of CSS selectors they match. Blink sends | 69 // Maps live WebFrames to the set of CSS selectors they match. Blink sends |
| 65 // back diffs, which we apply to these sets. | 70 // back diffs, which we apply to these sets. |
| 66 std::map<blink::WebFrame*, std::set<std::string> > matching_selectors_; | 71 std::map<blink::WebFrame*, std::set<std::string> > matching_selectors_; |
| 67 }; | 72 }; |
| 68 | 73 |
| 69 } // namespace extensions | 74 } // namespace extensions |
| 70 | 75 |
| 71 #endif // EXTENSIONS_RENDERER_CONTENT_WATCHER_H_ | 76 #endif // EXTENSIONS_RENDERER_CONTENT_WATCHER_H_ |
| OLD | NEW |