OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/renderer/extensions/renderer_extension_bindings.h" | 5 #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/singleton.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/common/extensions/extension_message_bundle.h" | 13 #include "chrome/common/extensions/extension_message_bundle.h" |
14 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
16 #include "chrome/renderer/extensions/bindings_utils.h" | 16 #include "chrome/renderer/extensions/bindings_utils.h" |
17 #include "chrome/renderer/extensions/event_bindings.h" | 17 #include "chrome/renderer/extensions/event_bindings.h" |
18 #include "chrome/renderer/render_thread.h" | 18 #include "chrome/renderer/render_thread.h" |
19 #include "chrome/renderer/render_view.h" | 19 #include "chrome/renderer/render_view.h" |
20 #include "grit/renderer_resources.h" | 20 #include "grit/renderer_resources.h" |
21 | 21 |
(...skipping 14 matching lines...) Loading... |
36 | 36 |
37 struct ExtensionData { | 37 struct ExtensionData { |
38 struct PortData { | 38 struct PortData { |
39 int ref_count; // how many contexts have a handle to this port | 39 int ref_count; // how many contexts have a handle to this port |
40 bool disconnected; // true if this port was forcefully disconnected | 40 bool disconnected; // true if this port was forcefully disconnected |
41 PortData() : ref_count(0), disconnected(false) {} | 41 PortData() : ref_count(0), disconnected(false) {} |
42 }; | 42 }; |
43 std::map<int, PortData> ports; // port ID -> data | 43 std::map<int, PortData> ports; // port ID -> data |
44 }; | 44 }; |
45 | 45 |
| 46 static base::LazyInstance<ExtensionData> g_extension_data( |
| 47 base::LINKER_INITIALIZED); |
| 48 |
46 static bool HasPortData(int port_id) { | 49 static bool HasPortData(int port_id) { |
47 return Singleton<ExtensionData>::get()->ports.find(port_id) != | 50 return g_extension_data.Get().ports.find(port_id) != |
48 Singleton<ExtensionData>::get()->ports.end(); | 51 g_extension_data.Get().ports.end(); |
49 } | 52 } |
50 | 53 |
51 static ExtensionData::PortData& GetPortData(int port_id) { | 54 static ExtensionData::PortData& GetPortData(int port_id) { |
52 return Singleton<ExtensionData>::get()->ports[port_id]; | 55 return g_extension_data.Get().ports[port_id]; |
53 } | 56 } |
54 | 57 |
55 static void ClearPortData(int port_id) { | 58 static void ClearPortData(int port_id) { |
56 Singleton<ExtensionData>::get()->ports.erase(port_id); | 59 g_extension_data.Get().ports.erase(port_id); |
57 } | 60 } |
58 | 61 |
59 const char kPortClosedError[] = "Attempting to use a disconnected port object"; | 62 const char kPortClosedError[] = "Attempting to use a disconnected port object"; |
60 const char* kExtensionDeps[] = { EventBindings::kName }; | 63 const char* kExtensionDeps[] = { EventBindings::kName }; |
61 | 64 |
62 class ExtensionImpl : public ExtensionBase { | 65 class ExtensionImpl : public ExtensionBase { |
63 public: | 66 public: |
64 ExtensionImpl() | 67 ExtensionImpl() |
65 : ExtensionBase(RendererExtensionBindings::kName, | 68 : ExtensionBase(RendererExtensionBindings::kName, |
66 GetStringResource(IDR_RENDERER_EXTENSION_BINDINGS_JS), | 69 GetStringResource(IDR_RENDERER_EXTENSION_BINDINGS_JS), |
(...skipping 237 matching lines...) Loading... |
304 const GURL& event_url) { | 307 const GURL& event_url) { |
305 v8::HandleScope handle_scope; | 308 v8::HandleScope handle_scope; |
306 std::vector< v8::Handle<v8::Value> > argv = ListValueToV8(args); | 309 std::vector< v8::Handle<v8::Value> > argv = ListValueToV8(args); |
307 EventBindings::CallFunction(extension_id, | 310 EventBindings::CallFunction(extension_id, |
308 function_name, | 311 function_name, |
309 argv.size(), | 312 argv.size(), |
310 &argv[0], | 313 &argv[0], |
311 renderview, | 314 renderview, |
312 event_url); | 315 event_url); |
313 } | 316 } |
OLD | NEW |