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

Side by Side Diff: chrome/renderer/extensions/content_watcher.cc

Issue 16032015: Extensions: pass ChromeV8Context around instead of v8::Handle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review (kalman) Created 7 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 | Annotate | Revision Log
OLDNEW
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
20 class MutationHandler : public ChromeV8Extension { 20 class MutationHandler : public ChromeV8Extension {
21 public: 21 public:
22 explicit MutationHandler(Dispatcher* dispatcher, 22 explicit MutationHandler(Dispatcher* dispatcher,
23 v8::Handle<v8::Context> v8_context, 23 ChromeV8Context* context,
24 base::WeakPtr<ContentWatcher> content_watcher) 24 base::WeakPtr<ContentWatcher> content_watcher)
25 : ChromeV8Extension(dispatcher, v8_context), 25 : ChromeV8Extension(dispatcher, context),
26 content_watcher_(content_watcher) { 26 content_watcher_(content_watcher) {
27 RouteFunction("FrameMutated", 27 RouteFunction("FrameMutated",
28 base::Bind(&MutationHandler::FrameMutated, 28 base::Bind(&MutationHandler::FrameMutated,
29 base::Unretained(this))); 29 base::Unretained(this)));
30 } 30 }
31 31
32 private: 32 private:
33 v8::Handle<v8::Value> FrameMutated(const v8::Arguments& args) { 33 v8::Handle<v8::Value> FrameMutated(const v8::Arguments& args) {
34 if (content_watcher_) { 34 if (content_watcher_) {
35 content_watcher_->ScanAndNotify( 35 content_watcher_->ScanAndNotify(
36 WebKit::WebFrame::frameForContext(v8_context())); 36 WebKit::WebFrame::frameForContext(context()->v8_context()));
not at google - send to devlin 2013/05/29 17:41:55 I am curious: how will this work in a world where
marja 2013/05/31 10:06:44 Yeah, we need a HandleScope whenever we're dealing
37 } 37 }
38 return v8::Undefined(); 38 return v8::Undefined();
39 } 39 }
40 40
41 base::WeakPtr<ContentWatcher> content_watcher_; 41 base::WeakPtr<ContentWatcher> content_watcher_;
42 }; 42 };
43 43
44 } // namespace 44 } // namespace
45 45
46 ContentWatcher::ContentWatcher(Dispatcher* dispatcher) 46 ContentWatcher::ContentWatcher(Dispatcher* dispatcher)
47 : weak_ptr_factory_(this), 47 : weak_ptr_factory_(this),
48 dispatcher_(dispatcher) {} 48 dispatcher_(dispatcher) {}
49 ContentWatcher::~ContentWatcher() {} 49 ContentWatcher::~ContentWatcher() {}
50 50
51 scoped_ptr<NativeHandler> ContentWatcher::MakeNatives( 51 scoped_ptr<NativeHandler> ContentWatcher::MakeNatives(
52 v8::Handle<v8::Context> v8_context) { 52 ChromeV8Context* context) {
53 return scoped_ptr<NativeHandler>(new MutationHandler( 53 return scoped_ptr<NativeHandler>(new MutationHandler(
54 dispatcher_, v8_context, weak_ptr_factory_.GetWeakPtr())); 54 dispatcher_, context, weak_ptr_factory_.GetWeakPtr()));
55 } 55 }
56 56
57 void ContentWatcher::OnWatchPages( 57 void ContentWatcher::OnWatchPages(
58 const std::vector<std::string>& new_css_selectors) { 58 const std::vector<std::string>& new_css_selectors) {
59 if (new_css_selectors == css_selectors_) 59 if (new_css_selectors == css_selectors_)
60 return; 60 return;
61 61
62 css_selectors_ = new_css_selectors; 62 css_selectors_ = new_css_selectors;
63 63
64 for (std::map<WebKit::WebFrame*, 64 for (std::map<WebKit::WebFrame*,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 it = transitive_selectors.begin(); 203 it = transitive_selectors.begin();
204 it != transitive_selectors.end(); ++it) 204 it != transitive_selectors.end(); ++it)
205 selector_strings.push_back(it->as_string()); 205 selector_strings.push_back(it->as_string());
206 content::RenderView* view = 206 content::RenderView* view =
207 content::RenderView::FromWebView(top_frame->view()); 207 content::RenderView::FromWebView(top_frame->view());
208 view->Send(new ExtensionHostMsg_OnWatchedPageChange( 208 view->Send(new ExtensionHostMsg_OnWatchedPageChange(
209 view->GetRoutingID(), selector_strings)); 209 view->GetRoutingID(), selector_strings));
210 } 210 }
211 211
212 } // namespace extensions 212 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698