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 visible in the toolbar. | |
|
Aaron Boodman
2012/05/14 18:36:17
Change this to:
Whether the browser action is pin
yefimt
2012/05/14 18:50:45
Done.
| |
| 119 // It is replacing kBrowserActionVisible, an old one eventualy will be gone. | |
| 120 const char kBrowserActionPined[] = "browser_action_pined"; | |
|
Aaron Boodman
2012/05/14 18:36:17
Spelling here and elsewhere: pinned (two 'n's).
yefimt
2012/05/14 18:50:45
Done.
| |
| 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 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1261 | 1267 |
| 1262 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, | 1268 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, |
| 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 |
| 1277 bool ExtensionPrefs::GetBrowserActionPined(const Extension* extension) { | |
| 1278 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); | |
| 1279 if (!extension_prefs) | |
| 1280 return true; | |
|
Aaron Boodman
2012/05/14 18:36:17
return false. Default to not-pinned.
yefimt
2012/05/14 18:50:45
Done.
| |
| 1281 | |
| 1282 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 1283 if (command_line.HasSwitch(switches::kEnableActionBox)) { | |
|
Aaron Boodman
2012/05/14 18:36:17
Do we expect this method to be called when the swi
yefimt
2012/05/14 18:50:45
We do, could be call from ExtensionToolbarModel wh
| |
| 1284 bool pined = false; | |
| 1285 bool pref_exists = extension_prefs->GetBoolean(kBrowserActionPined, | |
| 1286 &pined); | |
| 1287 if (pref_exists && pined) | |
| 1288 return true; | |
| 1289 } else { | |
| 1290 return GetBrowserActionVisibility(extension); | |
| 1291 } | |
| 1292 | |
| 1293 return false; | |
| 1294 } | |
| 1295 | |
| 1296 void ExtensionPrefs::SetBrowserActionPined(const Extension* extension, | |
| 1297 bool pined) { | |
| 1298 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 1299 bool enable_action_box = command_line.HasSwitch(switches::kEnableActionBox); | |
| 1300 | |
| 1301 if (enable_action_box) { | |
| 1302 if (GetBrowserActionPined(extension) == pined) | |
| 1303 return; | |
| 1304 | |
| 1305 UpdateExtensionPref(extension->id(), kBrowserActionPined, | |
| 1306 Value::CreateBooleanValue(pined)); | |
| 1307 content::NotificationService::current()->Notify( | |
| 1308 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_PINED_CHANGED, | |
| 1309 content::Source<ExtensionPrefs>(this), | |
| 1310 content::Details<const Extension>(extension)); | |
| 1311 } else { | |
| 1312 SetBrowserActionVisibility(extension, pined); | |
| 1313 } | |
| 1314 } | |
| 1315 | |
| 1271 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { | 1316 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { |
| 1272 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); | 1317 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); |
| 1273 if (!extension_prefs) | 1318 if (!extension_prefs) |
| 1274 return true; | 1319 return true; |
| 1320 | |
| 1275 bool visible = false; | 1321 bool visible = false; |
| 1276 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible) | 1322 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible) |
| 1277 return true; | 1323 return true; |
| 1278 | 1324 |
| 1279 return false; | 1325 return false; |
| 1280 } | 1326 } |
| 1281 | 1327 |
| 1282 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, | 1328 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, |
| 1283 bool visible) { | 1329 bool visible) { |
| 1284 if (GetBrowserActionVisibility(extension) == visible) | 1330 if (GetBrowserActionVisibility(extension) == visible) |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1894 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1940 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
| 1895 "0", // default value | 1941 "0", // default value |
| 1896 PrefService::UNSYNCABLE_PREF); | 1942 PrefService::UNSYNCABLE_PREF); |
| 1897 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1943 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
| 1898 0, // default value | 1944 0, // default value |
| 1899 PrefService::UNSYNCABLE_PREF); | 1945 PrefService::UNSYNCABLE_PREF); |
| 1900 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1946 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1901 0, // default value | 1947 0, // default value |
| 1902 PrefService::UNSYNCABLE_PREF); | 1948 PrefService::UNSYNCABLE_PREF); |
| 1903 } | 1949 } |
| OLD | NEW |