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

Side by Side Diff: chrome/renderer/extensions/object_backed_native_handler.h

Issue 12693008: Prevent ObjectBackedNativeHandler from calling itself once invalid. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/renderer/extensions/object_backed_native_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_ 5 #ifndef CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_
6 #define CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_ 6 #define CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 22 matching lines...) Expand all
33 typedef base::Callback<v8::Handle<v8::Value>(const v8::Arguments&)> 33 typedef base::Callback<v8::Handle<v8::Value>(const v8::Arguments&)>
34 HandlerFunction; 34 HandlerFunction;
35 35
36 // Installs a new 'route' from |name| to |handler_function|. This means that 36 // Installs a new 'route' from |name| to |handler_function|. This means that
37 // NewInstance()s of this ObjectBackedNativeHandler will have a property 37 // NewInstance()s of this ObjectBackedNativeHandler will have a property
38 // |name| which will be handled by |handler_function|. 38 // |name| which will be handled by |handler_function|.
39 void RouteFunction(const std::string& name, 39 void RouteFunction(const std::string& name,
40 const HandlerFunction& handler_function); 40 const HandlerFunction& handler_function);
41 41
42 void RouteStaticFunction(const std::string& name, 42 void RouteStaticFunction(const std::string& name,
43 const HandlerFunc handler_func); 43 const HandlerFunc& handler_func);
44 44
45 v8::Handle<v8::Context> v8_context() { return v8_context_.get(); } 45 v8::Handle<v8::Context> v8_context() { return v8_context_.get(); }
46 46
47 virtual void Invalidate() OVERRIDE; 47 virtual void Invalidate() OVERRIDE;
48 48
49 private: 49 private:
50 50 // Callback for RouteFunction which routes the V8 call to the correct
51 // base::Bound callback.
51 static v8::Handle<v8::Value> Router(const v8::Arguments& args); 52 static v8::Handle<v8::Value> Router(const v8::Arguments& args);
52 53
53 struct RouterData; 54 // When RouteFunction is called we create a v8::Object to hold the data we
54 std::vector<linked_ptr<RouterData> > router_data_; 55 // need when handling it in Router() - this is the base::Bound function to
56 // route to.
57 //
58 // We need a v8::Object because it's possible for v8 to outlive the
59 // base::Bound function; the lifetime of an ObjectBackedNativeHandler is the
60 // lifetime of webkit's involvement with it, not the life of the v8 context.
61 // A scenario when v8 will outlive us is if a frame holds onto the
62 // contentWindow of an iframe after it's removed.
63 //
64 // So, we use v8::Objects here to hold that data, effectively refcounting
65 // the data. When |this| is destroyed we remove the base::Bound function from
66 // the object to indicate that it shoudn't be called.
67 typedef std::vector<v8::Persistent<v8::Object> > RouterData;
68 RouterData router_data_;
55 69
56 // TODO(kalman): Just pass around a ChromeV8Context. It already has a 70 // TODO(kalman): Just pass around a ChromeV8Context. It already has a
57 // persistent handle to this context. 71 // persistent handle to this context.
58 ScopedPersistent<v8::Context> v8_context_; 72 ScopedPersistent<v8::Context> v8_context_;
59 73
60 ScopedPersistent<v8::ObjectTemplate> object_template_; 74 ScopedPersistent<v8::ObjectTemplate> object_template_;
61 75
62 DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler); 76 DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler);
63 }; 77 };
64 78
65 } // extensions 79 } // extensions
66 80
67 #endif // CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_ 81 #endif // CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/renderer/extensions/object_backed_native_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698