Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: extensions/renderer/content_watcher.h

Issue 344433003: Prepare declarativeContent API for new script injection feature. Added Javascript types and functio… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add note about what it means to revert RequestContentScript Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "extensions/common/watched_pages_recipient.h"
13 #include "third_party/WebKit/public/platform/WebVector.h" 14 #include "third_party/WebKit/public/platform/WebVector.h"
14 15
15 namespace blink { 16 namespace blink {
16 class WebFrame; 17 class WebFrame;
17 class WebString; 18 class WebString;
18 } 19 }
19 20
20 namespace extensions { 21 namespace extensions {
21 class Dispatcher; 22 class Dispatcher;
22 class Extension; 23 class Extension;
23 class NativeHandler; 24 class NativeHandler;
24 25
25 // Watches the content of WebFrames to notify extensions when they match various 26 // 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 // 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 // ExtensionMsg_WatchPages) and the set that match on each WebFrame, and sends a
28 // ExtensionHostMsg_OnWatchedPageChange whenever a RenderView's set changes. 29 // ExtensionHostMsg_OnWatchedPageChange whenever a RenderView's set changes.
29 // 30 //
30 // There's one ContentWatcher per Dispatcher rather than per RenderView because 31 // There's one ContentWatcher per Dispatcher rather than per RenderView because
31 // WebFrames can move between RenderViews through adoptNode. 32 // WebFrames can move between RenderViews through adoptNode.
32 class ContentWatcher { 33 class ContentWatcher {
33 public: 34 public:
34 ContentWatcher(); 35 ContentWatcher(const std::string& event_name,
35 ~ContentWatcher(); 36 WatchedPagesRecipient watched_pages_recipient);
37 virtual ~ContentWatcher();
36 38
37 // Handler for ExtensionMsg_WatchPages. 39 // Indirect handler for ExtensionMsg_WatchPages (mediated by
40 // Dispatcher::OnWatchPages).
38 void OnWatchPages(const std::vector<std::string>& css_selectors); 41 void OnWatchPages(const std::vector<std::string>& css_selectors);
39 42
40 // Uses WebDocument::watchCSSSelectors to watch the selectors in 43 // Uses WebDocument::watchCSSSelectors to watch the selectors in
41 // css_selectors_ and get a callback into DidMatchCSS() whenever the set of 44 // css_selectors_ and get a callback into DidMatchCSS() whenever the set of
42 // matching selectors in |frame| changes. 45 // matching selectors in |frame| changes.
43 void DidCreateDocumentElement(blink::WebFrame* frame); 46 void DidCreateDocumentElement(blink::WebFrame* frame);
44 47
45 // Records that |newly_matching_selectors| have started matching on |*frame|, 48 // Records that |newly_matching_selectors| have started matching on |*frame|,
46 // and |stopped_matching_selectors| have stopped matching. 49 // and |stopped_matching_selectors| have stopped matching.
47 void DidMatchCSS( 50 void DidMatchCSS(
48 blink::WebFrame* frame, 51 blink::WebFrame* frame,
49 const blink::WebVector<blink::WebString>& newly_matching_selectors, 52 const blink::WebVector<blink::WebString>& newly_matching_selectors,
50 const blink::WebVector<blink::WebString>& stopped_matching_selectors); 53 const blink::WebVector<blink::WebString>& stopped_matching_selectors);
51 54
52 private: 55 private:
53 // Given that we saw a change in the CSS selectors that |changed_frame| 56 // 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 57 // 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 58 // 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 59 // activeTab permission on that top-level page, we only send CSS selectors for
57 // frames that it could run on. 60 // frames that it could run on.
58 void NotifyBrowserOfChange(blink::WebFrame* changed_frame) const; 61 void NotifyBrowserOfChange(blink::WebFrame* changed_frame) const;
59 62
63 // Event name associated with the browser-side component that corresponds to
64 // this content watcher (included in ExtensionMsg_WatchPages messages).
65 std::string event_name_;
66
67 // Indicator of where to send watched page updates (included in
68 // ExtensionMsg_WatchPages messages).
69 WatchedPagesRecipient watched_pages_recipient_;
70
60 // If any of these selectors match on a page, we need to send an 71 // If any of these selectors match on a page, we need to send an
61 // ExtensionHostMsg_OnWatchedPageChange back to the browser. 72 // ExtensionHostMsg_OnWatchedPageChange back to the browser.
62 blink::WebVector<blink::WebString> css_selectors_; 73 blink::WebVector<blink::WebString> css_selectors_;
63 74
64 // Maps live WebFrames to the set of CSS selectors they match. Blink sends 75 // Maps live WebFrames to the set of CSS selectors they match. Blink sends
65 // back diffs, which we apply to these sets. 76 // back diffs, which we apply to these sets.
66 std::map<blink::WebFrame*, std::set<std::string> > matching_selectors_; 77 std::map<blink::WebFrame*, std::set<std::string> > matching_selectors_;
67 }; 78 };
68 79
69 } // namespace extensions 80 } // namespace extensions
70 81
71 #endif // EXTENSIONS_RENDERER_CONTENT_WATCHER_H_ 82 #endif // EXTENSIONS_RENDERER_CONTENT_WATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698