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