Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_function_registry.cc
blobc8886d595ad41aca18938a1d9b66b97bdf452891
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.
5 #include "chrome/browser/extensions/extension_function_registry.h"
7 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h"
8 #include "chrome/browser/extensions/api/preference/preference_api.h"
9 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
10 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
11 #include "chrome/common/extensions/api/generated_api.h"
13 // static
14 ExtensionFunctionRegistry* ExtensionFunctionRegistry::GetInstance() {
15 return Singleton<ExtensionFunctionRegistry>::get();
18 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
19 ResetFunctions();
22 ExtensionFunctionRegistry::~ExtensionFunctionRegistry() {
25 void ExtensionFunctionRegistry::ResetFunctions() {
26 #if defined(ENABLE_EXTENSIONS)
28 // Register all functions here.
30 // WebRequest.
31 RegisterFunction<WebRequestAddEventListener>();
32 RegisterFunction<WebRequestEventHandled>();
34 // Preferences.
35 RegisterFunction<extensions::GetPreferenceFunction>();
36 RegisterFunction<extensions::SetPreferenceFunction>();
37 RegisterFunction<extensions::ClearPreferenceFunction>();
39 // Direct Preference Access for Component Extensions.
40 RegisterFunction<extensions::chromedirectsetting::GetDirectSettingFunction>();
41 RegisterFunction<extensions::chromedirectsetting::SetDirectSettingFunction>();
42 RegisterFunction<
43 extensions::chromedirectsetting::ClearDirectSettingFunction>();
45 // Runtime
46 RegisterFunction<extensions::RuntimeGetBackgroundPageFunction>();
47 RegisterFunction<extensions::RuntimeSetUninstallURLFunction>();
48 RegisterFunction<extensions::RuntimeReloadFunction>();
49 RegisterFunction<extensions::RuntimeRequestUpdateCheckFunction>();
50 RegisterFunction<extensions::RuntimeRestartFunction>();
52 // Generated APIs
53 extensions::api::GeneratedFunctionRegistry::RegisterAll(this);
54 #endif // defined(ENABLE_EXTENSIONS)
57 void ExtensionFunctionRegistry::GetAllNames(std::vector<std::string>* names) {
58 for (FactoryMap::iterator iter = factories_.begin();
59 iter != factories_.end(); ++iter) {
60 names->push_back(iter->first);
64 bool ExtensionFunctionRegistry::OverrideFunction(
65 const std::string& name,
66 ExtensionFunctionFactory factory) {
67 FactoryMap::iterator iter = factories_.find(name);
68 if (iter == factories_.end()) {
69 return false;
70 } else {
71 iter->second.factory_ = factory;
72 return true;
76 ExtensionFunction* ExtensionFunctionRegistry::NewFunction(
77 const std::string& name) {
78 FactoryMap::iterator iter = factories_.find(name);
79 if (iter == factories_.end()) {
80 return NULL;
82 ExtensionFunction* function = iter->second.factory_();
83 function->set_name(name);
84 function->set_histogram_value(iter->second.histogram_value_);
85 return function;
88 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
89 : factory_(0), histogram_value_(extensions::functions::UNKNOWN) {
92 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry(
93 ExtensionFunctionFactory factory,
94 extensions::functions::HistogramValue histogram_value)
95 : factory_(factory), histogram_value_(histogram_value) {