Chromium Code Reviews| 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/command_line.h" | |
| 7 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" | 11 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" |
| 11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 12 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 12 #include "chrome/browser/extensions/extension_pref_store.h" | 13 #include "chrome/browser/extensions/extension_pref_store.h" |
| 13 #include "chrome/browser/extensions/extension_sorting.h" | 14 #include "chrome/browser/extensions/extension_sorting.h" |
| 14 #include "chrome/browser/prefs/pref_notifier.h" | 15 #include "chrome/browser/prefs/pref_notifier.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/chrome_switches.h" | |
| 18 #include "chrome/common/extensions/manifest.h" | 20 #include "chrome/common/extensions/manifest.h" |
| 19 #include "chrome/common/extensions/url_pattern.h" | 21 #include "chrome/common/extensions/url_pattern.h" |
| 20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 22 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Additional preferences keys | 28 // Additional preferences keys |
| 27 | 29 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 108 |
| 107 // A preference specifying if the user dragged the app on the NTP. | 109 // A preference specifying if the user dragged the app on the NTP. |
| 108 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; | 110 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; |
| 109 | 111 |
| 110 // A preference for storing extra data sent in update checks for an extension. | 112 // A preference for storing extra data sent in update checks for an extension. |
| 111 const char kUpdateUrlData[] = "update_url_data"; | 113 const char kUpdateUrlData[] = "update_url_data"; |
| 112 | 114 |
| 113 // Whether the browser action is visible in the toolbar. | 115 // Whether the browser action is visible in the toolbar. |
| 114 const char kBrowserActionVisible[] = "browser_action_visible"; | 116 const char kBrowserActionVisible[] = "browser_action_visible"; |
| 115 | 117 |
| 118 // Whether the browser action is pinned in the toolbar. This will eventually | |
| 119 // replace kBrowserActionVisible. | |
| 120 const char kBrowserActionPinned[] = "browser_action_pinned"; | |
| 121 | |
| 116 // Preferences that hold which permissions the user has granted the extension. | 122 // Preferences that hold which permissions the user has granted the extension. |
| 117 // We explicitly keep track of these so that extensions can contain unknown | 123 // We explicitly keep track of these so that extensions can contain unknown |
| 118 // permissions, for backwards compatibility reasons, and we can still prompt | 124 // permissions, for backwards compatibility reasons, and we can still prompt |
| 119 // the user to accept them once recognized. We store the active permission | 125 // the user to accept them once recognized. We store the active permission |
| 120 // permissions because they may differ from those defined in the manifest. | 126 // permissions because they may differ from those defined in the manifest. |
| 121 const char kPrefActivePermissions[] = "active_permissions"; | 127 const char kPrefActivePermissions[] = "active_permissions"; |
| 122 const char kPrefGrantedPermissions[] = "granted_permissions"; | 128 const char kPrefGrantedPermissions[] = "granted_permissions"; |
| 123 | 129 |
| 124 // The preference names for ExtensionPermissionSet values. | 130 // The preference names for ExtensionPermissionSet values. |
| 125 const char kPrefAPIs[] = "api"; | 131 const char kPrefAPIs[] = "api"; |
| (...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1263 Extension::State state) { | 1269 Extension::State state) { |
| 1264 UpdateExtensionPref(extension_id, kPrefState, | 1270 UpdateExtensionPref(extension_id, kPrefState, |
| 1265 Value::CreateIntegerValue(state)); | 1271 Value::CreateIntegerValue(state)); |
| 1266 bool enabled = (state == Extension::ENABLED); | 1272 bool enabled = (state == Extension::ENABLED); |
| 1267 extension_pref_value_map_->SetExtensionState(extension_id, enabled); | 1273 extension_pref_value_map_->SetExtensionState(extension_id, enabled); |
| 1268 content_settings_store_->SetExtensionState(extension_id, enabled); | 1274 content_settings_store_->SetExtensionState(extension_id, enabled); |
| 1269 } | 1275 } |
| 1270 | 1276 |
| 1271 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { | 1277 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { |
| 1272 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); | 1278 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); |
| 1273 if (!extension_prefs) | 1279 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1274 return true; | 1280 bool enable_action_box = command_line.HasSwitch(switches::kEnableActionBox); |
|
Aaron Boodman
2012/05/14 20:18:13
Nit: variable should not have typically have verb
yefimt
2012/05/14 21:07:36
Done.
| |
| 1281 if (!extension_prefs) { | |
|
Aaron Boodman
2012/05/14 20:18:13
Nit: If an if statement is less than two lines tot
Aaron Boodman
2012/05/14 20:18:13
You can simplify this logic somewhat:
bool defaul
yefimt
2012/05/14 21:07:36
Done.
yefimt
2012/05/14 21:07:36
Done.
yefimt
2012/05/14 21:07:36
Done.
| |
| 1282 return enable_action_box ? false : true; | |
| 1283 } | |
| 1284 | |
| 1275 bool visible = false; | 1285 bool visible = false; |
| 1276 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible) | 1286 const char* browser_action_pref = enable_action_box ? kBrowserActionPinned : |
| 1277 return true; | 1287 kBrowserActionVisible; |
| 1288 bool pref_exists = extension_prefs->GetBoolean(browser_action_pref, | |
| 1289 &visible); | |
| 1290 if (enable_action_box) { | |
| 1291 if (pref_exists && visible) | |
| 1292 return true; | |
| 1293 } else { | |
| 1294 if (!pref_exists || visible) | |
| 1295 return true; | |
| 1296 } | |
| 1278 | 1297 |
| 1279 return false; | 1298 return false; |
| 1280 } | 1299 } |
| 1281 | 1300 |
| 1282 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, | 1301 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, |
| 1283 bool visible) { | 1302 bool visible) { |
| 1284 if (GetBrowserActionVisibility(extension) == visible) | 1303 if (GetBrowserActionVisibility(extension) == visible) |
| 1285 return; | 1304 return; |
| 1286 | 1305 |
| 1287 UpdateExtensionPref(extension->id(), kBrowserActionVisible, | 1306 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1307 bool enable_action_box = command_line.HasSwitch(switches::kEnableActionBox); | |
|
Aaron Boodman
2012/05/14 20:18:13
Since you are checking this in multiple places, ca
| |
| 1308 const char* browser_action_pref = enable_action_box ? kBrowserActionPinned : | |
| 1309 kBrowserActionVisible; | |
| 1310 UpdateExtensionPref(extension->id(), browser_action_pref, | |
| 1288 Value::CreateBooleanValue(visible)); | 1311 Value::CreateBooleanValue(visible)); |
| 1289 content::NotificationService::current()->Notify( | 1312 content::NotificationService::current()->Notify( |
| 1290 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 1313 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| 1291 content::Source<ExtensionPrefs>(this), | 1314 content::Source<ExtensionPrefs>(this), |
| 1292 content::Details<const Extension>(extension)); | 1315 content::Details<const Extension>(extension)); |
| 1293 } | 1316 } |
| 1294 | 1317 |
| 1295 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { | 1318 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { |
| 1296 const DictionaryValue* extension = GetExtensionPref(extension_id); | 1319 const DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1297 if (!extension) | 1320 if (!extension) |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1894 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1917 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
| 1895 "0", // default value | 1918 "0", // default value |
| 1896 PrefService::UNSYNCABLE_PREF); | 1919 PrefService::UNSYNCABLE_PREF); |
| 1897 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1920 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
| 1898 0, // default value | 1921 0, // default value |
| 1899 PrefService::UNSYNCABLE_PREF); | 1922 PrefService::UNSYNCABLE_PREF); |
| 1900 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1923 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1901 0, // default value | 1924 0, // default value |
| 1902 PrefService::UNSYNCABLE_PREF); | 1925 PrefService::UNSYNCABLE_PREF); |
| 1903 } | 1926 } |
| OLD | NEW |