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 #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 23 matching lines...) Expand all Loading... |
34 | 34 |
35 // Installs a new 'route' from |name| to |handler_function|. This means that | 35 // Installs a new 'route' from |name| to |handler_function|. This means that |
36 // NewInstance()s of this ObjectBackedNativeHandler will have a property | 36 // NewInstance()s of this ObjectBackedNativeHandler will have a property |
37 // |name| which will be handled by |handler_function|. | 37 // |name| which will be handled by |handler_function|. |
38 void RouteFunction(const std::string& name, | 38 void RouteFunction(const std::string& name, |
39 const HandlerFunction& handler_function); | 39 const HandlerFunction& handler_function); |
40 | 40 |
41 void RouteStaticFunction(const std::string& name, | 41 void RouteStaticFunction(const std::string& name, |
42 const HandlerFunc handler_func); | 42 const HandlerFunc handler_func); |
43 | 43 |
44 // Invalidate this object so it cannot be used any more. This is needed | |
45 // because it's possible for this to outlive |v8_context_|. Invalidate must | |
46 // be called before this happens. | |
47 // | |
48 // Subclasses may override to invalidate their own V8 state, but always | |
49 // call superclass eventually. | |
50 // | |
51 // This must be idempotent. Returns true if it was the first time this was | |
52 // called, false otherwise. | |
53 virtual bool Invalidate(); | |
54 | |
55 v8::Handle<v8::Context> v8_context() { return v8_context_; } | 44 v8::Handle<v8::Context> v8_context() { return v8_context_; } |
56 | 45 |
| 46 virtual void Invalidate() OVERRIDE; |
| 47 |
57 private: | 48 private: |
| 49 |
58 static v8::Handle<v8::Value> Router(const v8::Arguments& args); | 50 static v8::Handle<v8::Value> Router(const v8::Arguments& args); |
59 | 51 |
60 std::vector<linked_ptr<HandlerFunction> > handler_functions_; | 52 struct RouterData; |
| 53 std::vector<linked_ptr<RouterData> > router_data_; |
| 54 |
61 v8::Handle<v8::Context> v8_context_; | 55 v8::Handle<v8::Context> v8_context_; |
| 56 |
62 v8::Persistent<v8::ObjectTemplate> object_template_; | 57 v8::Persistent<v8::ObjectTemplate> object_template_; |
63 bool is_valid_; | |
64 | 58 |
65 DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler); | 59 DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler); |
66 }; | 60 }; |
67 | 61 |
68 } // extensions | 62 } // extensions |
69 | 63 |
70 #endif // CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_ | 64 #endif // CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_ |
OLD | NEW |