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

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

Issue 12632004: Revert 186643 - Caused a 10% regression on SunSpider benchmark (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_
6 #define CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/bind.h"
12 #include "base/memory/linked_ptr.h"
13 #include "chrome/renderer/extensions/native_handler.h"
14 #include "v8/include/v8.h"
15
16 namespace extensions {
17
18 // An ObjectBackedNativeHandler is a factory for JS objects with functions on
19 // them that map to native C++ functions. Subclasses should call RouteFunction()
20 // in their constructor to define functions on the created JS objects.
21 class ObjectBackedNativeHandler : public NativeHandler {
22 public:
23 explicit ObjectBackedNativeHandler(v8::Handle<v8::Context> context);
24 virtual ~ObjectBackedNativeHandler();
25
26 // Create an object with bindings to the native functions defined through
27 // RouteFunction().
28 virtual v8::Handle<v8::Object> NewInstance() OVERRIDE;
29
30 protected:
31 typedef v8::Handle<v8::Value> (*HandlerFunc)(const v8::Arguments&);
32 typedef base::Callback<v8::Handle<v8::Value>(const v8::Arguments&)>
33 HandlerFunction;
34
35 // Installs a new 'route' from |name| to |handler_function|. This means that
36 // NewInstance()s of this ObjectBackedNativeHandler will have a property
37 // |name| which will be handled by |handler_function|.
38 void RouteFunction(const std::string& name,
39 const HandlerFunction& handler_function);
40
41 void RouteStaticFunction(const std::string& name,
42 const HandlerFunc handler_func);
43
44 v8::Handle<v8::Context> v8_context() { return v8_context_; }
45
46 virtual void Invalidate() OVERRIDE;
47
48 private:
49
50 static v8::Handle<v8::Value> Router(const v8::Arguments& args);
51
52 struct RouterData;
53 std::vector<linked_ptr<RouterData> > router_data_;
54
55 v8::Handle<v8::Context> v8_context_;
56
57 v8::Persistent<v8::ObjectTemplate> object_template_;
58
59 DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler);
60 };
61
62 } // extensions
63
64 #endif // CHROME_RENDERER_EXTENSIONS_OBJECT_BACKED_NATIVE_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/native_handler.cc ('k') | chrome/renderer/extensions/object_backed_native_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698