| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/bindings_utils.h" | 5 #include "chrome/renderer/extensions/bindings_utils.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" |
| 7 #include "base/string_split.h" | 8 #include "base/string_split.h" |
| 8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 9 #include "chrome/renderer/render_view.h" | 10 #include "chrome/renderer/render_view.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 11 | 12 |
| 12 using WebKit::WebFrame; | 13 using WebKit::WebFrame; |
| 13 using WebKit::WebView; | 14 using WebKit::WebView; |
| 14 | 15 |
| 15 namespace bindings_utils { | 16 namespace bindings_utils { |
| 16 | 17 |
| 17 const char* kChromeHidden = "chromeHidden"; | 18 const char* kChromeHidden = "chromeHidden"; |
| 18 const char* kValidateCallbacks = "validateCallbacks"; | 19 const char* kValidateCallbacks = "validateCallbacks"; |
| 19 | 20 |
| 20 struct SingletonData { | 21 struct SingletonData { |
| 21 ContextList contexts; | 22 ContextList contexts; |
| 22 PendingRequestMap pending_requests; | 23 PendingRequestMap pending_requests; |
| 23 }; | 24 }; |
| 25 static base::LazyInstance<SingletonData> g_singleton_data( |
| 26 base::LINKER_INITIALIZED); |
| 24 | 27 |
| 25 typedef std::map<int, std::string> StringMap; | 28 typedef std::map<int, std::string> StringMap; |
| 29 static base::LazyInstance<StringMap> g_string_map(base::LINKER_INITIALIZED); |
| 26 | 30 |
| 27 const char* GetStringResource(int resource_id) { | 31 const char* GetStringResource(int resource_id) { |
| 28 StringMap* strings = Singleton<StringMap>::get(); | 32 StringMap* strings = g_string_map.Pointer(); |
| 29 StringMap::iterator it = strings->find(resource_id); | 33 StringMap::iterator it = strings->find(resource_id); |
| 30 if (it == strings->end()) { | 34 if (it == strings->end()) { |
| 31 it = strings->insert(std::make_pair( | 35 it = strings->insert(std::make_pair( |
| 32 resource_id, | 36 resource_id, |
| 33 ResourceBundle::GetSharedInstance().GetRawDataResource( | 37 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 34 resource_id).as_string())).first; | 38 resource_id).as_string())).first; |
| 35 } | 39 } |
| 36 return it->second.c_str(); | 40 return it->second.c_str(); |
| 37 } | 41 } |
| 38 | 42 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 : context(context), | 81 : context(context), |
| 78 extension_id(extension_id), | 82 extension_id(extension_id), |
| 79 parent_frame(parent_frame), | 83 parent_frame(parent_frame), |
| 80 render_view(render_view), | 84 render_view(render_view), |
| 81 num_connected_events(0) { | 85 num_connected_events(0) { |
| 82 } | 86 } |
| 83 | 87 |
| 84 ContextInfo::~ContextInfo() {} | 88 ContextInfo::~ContextInfo() {} |
| 85 | 89 |
| 86 ContextList& GetContexts() { | 90 ContextList& GetContexts() { |
| 87 return Singleton<SingletonData>::get()->contexts; | 91 return g_singleton_data.Get().contexts; |
| 88 } | 92 } |
| 89 | 93 |
| 90 ContextList GetContextsForExtension(const std::string& extension_id) { | 94 ContextList GetContextsForExtension(const std::string& extension_id) { |
| 91 ContextList& all_contexts = GetContexts(); | 95 ContextList& all_contexts = GetContexts(); |
| 92 ContextList contexts; | 96 ContextList contexts; |
| 93 | 97 |
| 94 for (ContextList::iterator it = all_contexts.begin(); | 98 for (ContextList::iterator it = all_contexts.begin(); |
| 95 it != all_contexts.end(); ++it) { | 99 it != all_contexts.end(); ++it) { |
| 96 if ((*it)->extension_id == extension_id) | 100 if ((*it)->extension_id == extension_id) |
| 97 contexts.push_back(*it); | 101 contexts.push_back(*it); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 127 ContextList::iterator it = all_contexts.begin(); | 131 ContextList::iterator it = all_contexts.begin(); |
| 128 for (; it != all_contexts.end(); ++it) { | 132 for (; it != all_contexts.end(); ++it) { |
| 129 if ((*it)->context == context) | 133 if ((*it)->context == context) |
| 130 break; | 134 break; |
| 131 } | 135 } |
| 132 | 136 |
| 133 return it; | 137 return it; |
| 134 } | 138 } |
| 135 | 139 |
| 136 PendingRequestMap& GetPendingRequestMap() { | 140 PendingRequestMap& GetPendingRequestMap() { |
| 137 return Singleton<SingletonData>::get()->pending_requests; | 141 return g_singleton_data.Get().pending_requests; |
| 138 } | 142 } |
| 139 | 143 |
| 140 RenderView* GetRenderViewForCurrentContext() { | 144 RenderView* GetRenderViewForCurrentContext() { |
| 141 WebFrame* webframe = WebFrame::frameForCurrentContext(); | 145 WebFrame* webframe = WebFrame::frameForCurrentContext(); |
| 142 DCHECK(webframe) << "RetrieveCurrentFrame called when not in a V8 context."; | 146 DCHECK(webframe) << "RetrieveCurrentFrame called when not in a V8 context."; |
| 143 if (!webframe) | 147 if (!webframe) |
| 144 return NULL; | 148 return NULL; |
| 145 | 149 |
| 146 WebView* webview = webframe->view(); | 150 WebView* webview = webframe->view(); |
| 147 if (!webview) | 151 if (!webview) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 173 } | 177 } |
| 174 | 178 |
| 175 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | 179 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
| 176 if (!function.IsEmpty()) | 180 if (!function.IsEmpty()) |
| 177 return function->Call(v8::Object::New(), argc, argv); | 181 return function->Call(v8::Object::New(), argc, argv); |
| 178 | 182 |
| 179 return v8::Undefined(); | 183 return v8::Undefined(); |
| 180 } | 184 } |
| 181 | 185 |
| 182 } // namespace bindings_utils | 186 } // namespace bindings_utils |
| OLD | NEW |