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/extension_process_bindings.h" | 5 #include "chrome/renderer/extensions/extension_process_bindings.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 14 #include "base/lazy_instance.h" |
14 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
15 #include "base/singleton.h" | |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
20 #include "chrome/common/extensions/url_pattern.h" | 20 #include "chrome/common/extensions/url_pattern.h" |
21 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
22 #include "chrome/common/render_messages_params.h" | 22 #include "chrome/common/render_messages_params.h" |
23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
24 #include "chrome/renderer/extensions/bindings_utils.h" | 24 #include "chrome/renderer/extensions/bindings_utils.h" |
25 #include "chrome/renderer/extensions/event_bindings.h" | 25 #include "chrome/renderer/extensions/event_bindings.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 RendererExtensionBindings::kName, | 71 RendererExtensionBindings::kName, |
72 ExtensionApiTestV8Extension::kName, | 72 ExtensionApiTestV8Extension::kName, |
73 }; | 73 }; |
74 | 74 |
75 struct SingletonData { | 75 struct SingletonData { |
76 std::set<std::string> function_names_; | 76 std::set<std::string> function_names_; |
77 PageActionIdMap page_action_ids_; | 77 PageActionIdMap page_action_ids_; |
78 ExtensionPermissionsList permissions_; | 78 ExtensionPermissionsList permissions_; |
79 }; | 79 }; |
80 | 80 |
| 81 static base::LazyInstance<SingletonData> g_singleton_data( |
| 82 base::LINKER_INITIALIZED); |
| 83 |
81 static std::set<std::string>* GetFunctionNameSet() { | 84 static std::set<std::string>* GetFunctionNameSet() { |
82 return &Singleton<SingletonData>()->function_names_; | 85 return &g_singleton_data.Get().function_names_; |
83 } | 86 } |
84 | 87 |
85 static PageActionIdMap* GetPageActionMap() { | 88 static PageActionIdMap* GetPageActionMap() { |
86 return &Singleton<SingletonData>()->page_action_ids_; | 89 return &g_singleton_data.Get().page_action_ids_; |
87 } | 90 } |
88 | 91 |
89 static PermissionsList* GetPermissionsList(const std::string& extension_id) { | 92 static PermissionsList* GetPermissionsList(const std::string& extension_id) { |
90 return &Singleton<SingletonData>()->permissions_[extension_id]; | 93 return &g_singleton_data.Get().permissions_[extension_id]; |
91 } | 94 } |
92 | 95 |
93 static void GetActiveExtensionIDs(std::set<std::string>* extension_ids) { | 96 static void GetActiveExtensionIDs(std::set<std::string>* extension_ids) { |
94 ExtensionPermissionsList& permissions = | 97 ExtensionPermissionsList& permissions = g_singleton_data.Get().permissions_; |
95 Singleton<SingletonData>()->permissions_; | |
96 | 98 |
97 for (ExtensionPermissionsList::iterator iter = permissions.begin(); | 99 for (ExtensionPermissionsList::iterator iter = permissions.begin(); |
98 iter != permissions.end(); ++iter) { | 100 iter != permissions.end(); ++iter) { |
99 extension_ids->insert(iter->first); | 101 extension_ids->insert(iter->first); |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 // A RenderViewVisitor class that iterates through the set of available | 105 // A RenderViewVisitor class that iterates through the set of available |
104 // views, looking for a view of the given type, in the given browser window | 106 // views, looking for a view of the given type, in the given browser window |
105 // and within the given extension. | 107 // and within the given extension. |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 const std::string& function_name) { | 671 const std::string& function_name) { |
670 static const char kMessage[] = | 672 static const char kMessage[] = |
671 "You do not have permission to use '%s'. Be sure to declare" | 673 "You do not have permission to use '%s'. Be sure to declare" |
672 " in your manifest what permissions you need."; | 674 " in your manifest what permissions you need."; |
673 std::string error_msg = StringPrintf(kMessage, function_name.c_str()); | 675 std::string error_msg = StringPrintf(kMessage, function_name.c_str()); |
674 | 676 |
675 return v8::ThrowException(v8::Exception::Error( | 677 return v8::ThrowException(v8::Exception::Error( |
676 v8::String::New(error_msg.c_str()))); | 678 v8::String::New(error_msg.c_str()))); |
677 } | 679 } |
678 | 680 |
OLD | NEW |