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 #include "chrome/common/extensions/extension_messages.h" | 5 #include "chrome/common/extensions/extension_messages.h" |
6 #include "chrome/renderer/extensions/chrome_v8_context.h" | 6 #include "chrome/renderer/extensions/chrome_v8_context.h" |
7 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 7 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
8 #include "chrome/renderer/extensions/content_watcher.h" | 8 #include "chrome/renderer/extensions/content_watcher.h" |
9 #include "chrome/renderer/extensions/dispatcher.h" | 9 #include "chrome/renderer/extensions/dispatcher.h" |
10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
11 #include "content/public/renderer/render_view_visitor.h" | 11 #include "content/public/renderer/render_view_visitor.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 | 17 |
18 namespace { | 18 namespace { |
| 19 |
19 class MutationHandler : public ChromeV8Extension { | 20 class MutationHandler : public ChromeV8Extension { |
20 public: | 21 public: |
21 explicit MutationHandler(Dispatcher* dispatcher, | 22 explicit MutationHandler(Dispatcher* dispatcher, |
| 23 v8::Handle<v8::Context> v8_context, |
22 base::WeakPtr<ContentWatcher> content_watcher) | 24 base::WeakPtr<ContentWatcher> content_watcher) |
23 : ChromeV8Extension(dispatcher), | 25 : ChromeV8Extension(dispatcher, v8_context), |
24 content_watcher_(content_watcher) { | 26 content_watcher_(content_watcher) { |
25 RouteFunction("FrameMutated", | 27 RouteFunction("FrameMutated", |
26 base::Bind(&MutationHandler::FrameMutated, | 28 base::Bind(&MutationHandler::FrameMutated, |
27 base::Unretained(this))); | 29 base::Unretained(this))); |
28 } | 30 } |
29 | 31 |
30 private: | 32 private: |
31 v8::Handle<v8::Value> FrameMutated(const v8::Arguments& args) { | 33 v8::Handle<v8::Value> FrameMutated(const v8::Arguments& args) { |
32 if (content_watcher_) { | 34 if (content_watcher_) { |
33 content_watcher_->ScanAndNotify( | 35 content_watcher_->ScanAndNotify( |
34 WebKit::WebFrame::frameForCurrentContext()); | 36 WebKit::WebFrame::frameForContext(v8_context())); |
35 } | 37 } |
36 return v8::Undefined(); | 38 return v8::Undefined(); |
37 } | 39 } |
38 | 40 |
39 base::WeakPtr<ContentWatcher> content_watcher_; | 41 base::WeakPtr<ContentWatcher> content_watcher_; |
40 }; | 42 }; |
41 | 43 |
42 } // namespace | 44 } // namespace |
43 | 45 |
44 ContentWatcher::ContentWatcher(Dispatcher* dispatcher) | 46 ContentWatcher::ContentWatcher(Dispatcher* dispatcher) |
45 : weak_ptr_factory_(this), | 47 : weak_ptr_factory_(this), |
46 dispatcher_(dispatcher) {} | 48 dispatcher_(dispatcher) {} |
47 ContentWatcher::~ContentWatcher() {} | 49 ContentWatcher::~ContentWatcher() {} |
48 | 50 |
49 scoped_ptr<NativeHandler> ContentWatcher::MakeNatives() { | 51 scoped_ptr<NativeHandler> ContentWatcher::MakeNatives( |
50 return scoped_ptr<NativeHandler>( | 52 v8::Handle<v8::Context> v8_context) { |
51 new MutationHandler(dispatcher_, weak_ptr_factory_.GetWeakPtr())); | 53 return scoped_ptr<NativeHandler>(new MutationHandler( |
| 54 dispatcher_, v8_context, weak_ptr_factory_.GetWeakPtr())); |
52 } | 55 } |
53 | 56 |
54 void ContentWatcher::OnWatchPages( | 57 void ContentWatcher::OnWatchPages( |
55 const std::vector<std::string>& new_css_selectors) { | 58 const std::vector<std::string>& new_css_selectors) { |
56 if (new_css_selectors == css_selectors_) | 59 if (new_css_selectors == css_selectors_) |
57 return; | 60 return; |
58 | 61 |
59 css_selectors_ = new_css_selectors; | 62 css_selectors_ = new_css_selectors; |
60 | 63 |
61 for (std::map<WebKit::WebFrame*, | 64 for (std::map<WebKit::WebFrame*, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 it = transitive_selectors.begin(); | 203 it = transitive_selectors.begin(); |
201 it != transitive_selectors.end(); ++it) | 204 it != transitive_selectors.end(); ++it) |
202 selector_strings.push_back(it->as_string()); | 205 selector_strings.push_back(it->as_string()); |
203 content::RenderView* view = | 206 content::RenderView* view = |
204 content::RenderView::FromWebView(top_frame->view()); | 207 content::RenderView::FromWebView(top_frame->view()); |
205 view->Send(new ExtensionHostMsg_OnWatchedPageChange( | 208 view->Send(new ExtensionHostMsg_OnWatchedPageChange( |
206 view->GetRoutingID(), selector_strings)); | 209 view->GetRoutingID(), selector_strings)); |
207 } | 210 } |
208 | 211 |
209 } // namespace extensions | 212 } // namespace extensions |
OLD | NEW |