OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/browser/extensions/settings_api_helpers.h" | 5 #include "chrome/browser/extensions/settings_api_helpers.h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/preference/preference_api.h" | 7 #include "chrome/browser/extensions/api/preference/preference_api.h" |
8 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
| 9 #include "chrome/common/url_constants.h" |
9 #include "components/proxy_config/proxy_config_pref_names.h" | 10 #include "components/proxy_config/proxy_config_pref_names.h" |
10 #include "components/search_engines/search_engines_pref_names.h" | 11 #include "components/search_engines/search_engines_pref_names.h" |
| 12 #include "content/public/browser/browser_url_handler.h" |
11 #include "extensions/browser/extension_pref_value_map.h" | 13 #include "extensions/browser/extension_pref_value_map.h" |
12 #include "extensions/browser/extension_pref_value_map_factory.h" | 14 #include "extensions/browser/extension_pref_value_map_factory.h" |
13 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/common/constants.h" |
14 #include "extensions/common/extension_set.h" | 17 #include "extensions/common/extension_set.h" |
| 18 #include "url/gurl.h" |
15 | 19 |
16 namespace extensions { | 20 namespace extensions { |
17 | 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 // Returns which |extension| (if any) is overriding a particular |type| of | 24 // Returns which |extension| (if any) is overriding a particular |type| of |
21 // setting. | 25 // setting. |
22 const Extension* FindOverridingExtension( | 26 const Extension* FindOverridingExtension( |
23 content::BrowserContext* browser_context, | 27 content::BrowserContext* browser_context, |
24 SettingsApiOverrideType type) { | 28 SettingsApiOverrideType type) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return NULL; | 68 return NULL; |
65 } | 69 } |
66 | 70 |
67 } // namespace | 71 } // namespace |
68 | 72 |
69 const Extension* GetExtensionOverridingHomepage( | 73 const Extension* GetExtensionOverridingHomepage( |
70 content::BrowserContext* browser_context) { | 74 content::BrowserContext* browser_context) { |
71 return FindOverridingExtension(browser_context, BUBBLE_TYPE_HOME_PAGE); | 75 return FindOverridingExtension(browser_context, BUBBLE_TYPE_HOME_PAGE); |
72 } | 76 } |
73 | 77 |
| 78 const Extension* GetExtensionOverridingNewTabPage( |
| 79 content::BrowserContext* browser_context) { |
| 80 GURL ntp_url(chrome::kChromeUINewTabURL); |
| 81 bool ignored; |
| 82 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| 83 &ntp_url, browser_context, &ignored); |
| 84 if (ntp_url.SchemeIs(kExtensionScheme)) { |
| 85 return ExtensionRegistry::Get(browser_context)->GetExtensionById( |
| 86 ntp_url.host(), ExtensionRegistry::ENABLED); |
| 87 } |
| 88 return nullptr; |
| 89 } |
| 90 |
74 const Extension* GetExtensionOverridingStartupPages( | 91 const Extension* GetExtensionOverridingStartupPages( |
75 content::BrowserContext* browser_context) { | 92 content::BrowserContext* browser_context) { |
76 return FindOverridingExtension(browser_context, BUBBLE_TYPE_STARTUP_PAGES); | 93 return FindOverridingExtension(browser_context, BUBBLE_TYPE_STARTUP_PAGES); |
77 } | 94 } |
78 | 95 |
79 const Extension* GetExtensionOverridingSearchEngine( | 96 const Extension* GetExtensionOverridingSearchEngine( |
80 content::BrowserContext* browser_context) { | 97 content::BrowserContext* browser_context) { |
81 return FindOverridingExtension(browser_context, BUBBLE_TYPE_SEARCH_ENGINE); | 98 return FindOverridingExtension(browser_context, BUBBLE_TYPE_SEARCH_ENGINE); |
82 } | 99 } |
83 | 100 |
84 const Extension* GetExtensionOverridingProxy( | 101 const Extension* GetExtensionOverridingProxy( |
85 content::BrowserContext* browser_context) { | 102 content::BrowserContext* browser_context) { |
86 ExtensionPrefValueMap* extension_prefs_value_map = | 103 ExtensionPrefValueMap* extension_prefs_value_map = |
87 ExtensionPrefValueMapFactory::GetForBrowserContext(browser_context); | 104 ExtensionPrefValueMapFactory::GetForBrowserContext(browser_context); |
88 if (!extension_prefs_value_map) | 105 if (!extension_prefs_value_map) |
89 return NULL; // Can be null during testing. | 106 return NULL; // Can be null during testing. |
90 std::string extension_id = | 107 std::string extension_id = |
91 extension_prefs_value_map->GetExtensionControllingPref( | 108 extension_prefs_value_map->GetExtensionControllingPref( |
92 proxy_config::prefs::kProxy); | 109 proxy_config::prefs::kProxy); |
93 if (extension_id.empty()) | 110 if (extension_id.empty()) |
94 return NULL; | 111 return NULL; |
95 return ExtensionRegistry::Get(browser_context)->GetExtensionById( | 112 return ExtensionRegistry::Get(browser_context)->GetExtensionById( |
96 extension_id, ExtensionRegistry::ENABLED); | 113 extension_id, ExtensionRegistry::ENABLED); |
97 } | 114 } |
98 | 115 |
99 } // namespace extensions | 116 } // namespace extensions |
OLD | NEW |