OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/extension_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" | 10 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" |
11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
12 #include "chrome/browser/extensions/extension_pref_store.h" | 12 #include "chrome/browser/extensions/extension_pref_store.h" |
13 #include "chrome/browser/extensions/extension_sorting.h" | 13 #include "chrome/browser/extensions/extension_sorting.h" |
14 #include "chrome/browser/prefs/pref_notifier.h" | 14 #include "chrome/browser/prefs/pref_notifier.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/extensions/extension_switch_utils.h" |
18 #include "chrome/common/extensions/manifest.h" | 19 #include "chrome/common/extensions/manifest.h" |
19 #include "chrome/common/extensions/url_pattern.h" | 20 #include "chrome/common/extensions/url_pattern.h" |
20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // Additional preferences keys | 27 // Additional preferences keys |
27 | 28 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 107 |
107 // A preference specifying if the user dragged the app on the NTP. | 108 // A preference specifying if the user dragged the app on the NTP. |
108 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; | 109 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; |
109 | 110 |
110 // A preference for storing extra data sent in update checks for an extension. | 111 // A preference for storing extra data sent in update checks for an extension. |
111 const char kUpdateUrlData[] = "update_url_data"; | 112 const char kUpdateUrlData[] = "update_url_data"; |
112 | 113 |
113 // Whether the browser action is visible in the toolbar. | 114 // Whether the browser action is visible in the toolbar. |
114 const char kBrowserActionVisible[] = "browser_action_visible"; | 115 const char kBrowserActionVisible[] = "browser_action_visible"; |
115 | 116 |
| 117 // Whether the browser action is pinned in the toolbar. This will eventually |
| 118 // replace kBrowserActionVisible. |
| 119 const char kBrowserActionPinned[] = "browser_action_pinned"; |
| 120 |
116 // Preferences that hold which permissions the user has granted the extension. | 121 // Preferences that hold which permissions the user has granted the extension. |
117 // We explicitly keep track of these so that extensions can contain unknown | 122 // We explicitly keep track of these so that extensions can contain unknown |
118 // permissions, for backwards compatibility reasons, and we can still prompt | 123 // permissions, for backwards compatibility reasons, and we can still prompt |
119 // the user to accept them once recognized. We store the active permission | 124 // the user to accept them once recognized. We store the active permission |
120 // permissions because they may differ from those defined in the manifest. | 125 // permissions because they may differ from those defined in the manifest. |
121 const char kPrefActivePermissions[] = "active_permissions"; | 126 const char kPrefActivePermissions[] = "active_permissions"; |
122 const char kPrefGrantedPermissions[] = "granted_permissions"; | 127 const char kPrefGrantedPermissions[] = "granted_permissions"; |
123 | 128 |
124 // The preference names for ExtensionPermissionSet values. | 129 // The preference names for ExtensionPermissionSet values. |
125 const char kPrefAPIs[] = "api"; | 130 const char kPrefAPIs[] = "api"; |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, | 1267 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, |
1263 Extension::State state) { | 1268 Extension::State state) { |
1264 UpdateExtensionPref(extension_id, kPrefState, | 1269 UpdateExtensionPref(extension_id, kPrefState, |
1265 Value::CreateIntegerValue(state)); | 1270 Value::CreateIntegerValue(state)); |
1266 bool enabled = (state == Extension::ENABLED); | 1271 bool enabled = (state == Extension::ENABLED); |
1267 extension_pref_value_map_->SetExtensionState(extension_id, enabled); | 1272 extension_pref_value_map_->SetExtensionState(extension_id, enabled); |
1268 content_settings_store_->SetExtensionState(extension_id, enabled); | 1273 content_settings_store_->SetExtensionState(extension_id, enabled); |
1269 } | 1274 } |
1270 | 1275 |
1271 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { | 1276 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { |
| 1277 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
| 1278 bool default_value = !action_box_enabled; |
| 1279 |
1272 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); | 1280 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); |
1273 if (!extension_prefs) | 1281 if (!extension_prefs) |
1274 return true; | 1282 return default_value; |
| 1283 |
1275 bool visible = false; | 1284 bool visible = false; |
1276 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible) | 1285 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned : |
1277 return true; | 1286 kBrowserActionVisible; |
| 1287 bool pref_exists = extension_prefs->GetBoolean(browser_action_pref, &visible); |
| 1288 if (!pref_exists) |
| 1289 return default_value; |
1278 | 1290 |
1279 return false; | 1291 return visible; |
1280 } | 1292 } |
1281 | 1293 |
1282 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, | 1294 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, |
1283 bool visible) { | 1295 bool visible) { |
1284 if (GetBrowserActionVisibility(extension) == visible) | 1296 if (GetBrowserActionVisibility(extension) == visible) |
1285 return; | 1297 return; |
1286 | 1298 |
1287 UpdateExtensionPref(extension->id(), kBrowserActionVisible, | 1299 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
| 1300 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned : |
| 1301 kBrowserActionVisible; |
| 1302 UpdateExtensionPref(extension->id(), browser_action_pref, |
1288 Value::CreateBooleanValue(visible)); | 1303 Value::CreateBooleanValue(visible)); |
1289 content::NotificationService::current()->Notify( | 1304 content::NotificationService::current()->Notify( |
1290 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 1305 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
1291 content::Source<ExtensionPrefs>(this), | 1306 content::Source<ExtensionPrefs>(this), |
1292 content::Details<const Extension>(extension)); | 1307 content::Details<const Extension>(extension)); |
1293 } | 1308 } |
1294 | 1309 |
1295 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { | 1310 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { |
1296 const DictionaryValue* extension = GetExtensionPref(extension_id); | 1311 const DictionaryValue* extension = GetExtensionPref(extension_id); |
1297 if (!extension) | 1312 if (!extension) |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1909 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
1895 "0", // default value | 1910 "0", // default value |
1896 PrefService::UNSYNCABLE_PREF); | 1911 PrefService::UNSYNCABLE_PREF); |
1897 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1912 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
1898 0, // default value | 1913 0, // default value |
1899 PrefService::UNSYNCABLE_PREF); | 1914 PrefService::UNSYNCABLE_PREF); |
1900 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1915 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1901 0, // default value | 1916 0, // default value |
1902 PrefService::UNSYNCABLE_PREF); | 1917 PrefService::UNSYNCABLE_PREF); |
1903 } | 1918 } |
OLD | NEW |