| 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/command_line.h" |
| 8 #include "base/prefs/pref_notifier.h" | 8 #include "base/prefs/pref_notifier.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // A preference set by the the NTP to persist the desired launch container type | 143 // A preference set by the the NTP to persist the desired launch container type |
| 144 // used for apps. | 144 // used for apps. |
| 145 const char kPrefLaunchType[] = "launchType"; | 145 const char kPrefLaunchType[] = "launchType"; |
| 146 | 146 |
| 147 // A preference specifying if the user dragged the app on the NTP. | 147 // A preference specifying if the user dragged the app on the NTP. |
| 148 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; | 148 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; |
| 149 | 149 |
| 150 // A preference for storing extra data sent in update checks for an extension. | 150 // A preference for storing extra data sent in update checks for an extension. |
| 151 const char kUpdateUrlData[] = "update_url_data"; | 151 const char kUpdateUrlData[] = "update_url_data"; |
| 152 | 152 |
| 153 // Whether the browser action is visible in the toolbar. | |
| 154 const char kBrowserActionVisible[] = "browser_action_visible"; | |
| 155 | |
| 156 // Preferences that hold which permissions the user has granted the extension. | 153 // Preferences that hold which permissions the user has granted the extension. |
| 157 // We explicitly keep track of these so that extensions can contain unknown | 154 // We explicitly keep track of these so that extensions can contain unknown |
| 158 // permissions, for backwards compatibility reasons, and we can still prompt | 155 // permissions, for backwards compatibility reasons, and we can still prompt |
| 159 // the user to accept them once recognized. We store the active permission | 156 // the user to accept them once recognized. We store the active permission |
| 160 // permissions because they may differ from those defined in the manifest. | 157 // permissions because they may differ from those defined in the manifest. |
| 161 const char kPrefActivePermissions[] = "active_permissions"; | 158 const char kPrefActivePermissions[] = "active_permissions"; |
| 162 const char kPrefGrantedPermissions[] = "granted_permissions"; | 159 const char kPrefGrantedPermissions[] = "granted_permissions"; |
| 163 | 160 |
| 164 // The preference names for PermissionSet values. | 161 // The preference names for PermissionSet values. |
| 165 const char kPrefAPIs[] = "api"; | 162 const char kPrefAPIs[] = "api"; |
| (...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 | 1407 |
| 1411 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, | 1408 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, |
| 1412 Extension::State state) { | 1409 Extension::State state) { |
| 1413 UpdateExtensionPref(extension_id, kPrefState, | 1410 UpdateExtensionPref(extension_id, kPrefState, |
| 1414 Value::CreateIntegerValue(state)); | 1411 Value::CreateIntegerValue(state)); |
| 1415 bool enabled = (state == Extension::ENABLED); | 1412 bool enabled = (state == Extension::ENABLED); |
| 1416 extension_pref_value_map_->SetExtensionState(extension_id, enabled); | 1413 extension_pref_value_map_->SetExtensionState(extension_id, enabled); |
| 1417 content_settings_store_->SetExtensionState(extension_id, enabled); | 1414 content_settings_store_->SetExtensionState(extension_id, enabled); |
| 1418 } | 1415 } |
| 1419 | 1416 |
| 1420 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { | |
| 1421 const DictionaryValue* extension_prefs = | |
| 1422 GetExtensionPref(extension->id()); | |
| 1423 if (!extension_prefs) | |
| 1424 return true; | |
| 1425 | |
| 1426 bool visible = false; | |
| 1427 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible)) | |
| 1428 return true; | |
| 1429 | |
| 1430 return visible; | |
| 1431 } | |
| 1432 | |
| 1433 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, | |
| 1434 bool visible) { | |
| 1435 if (GetBrowserActionVisibility(extension) == visible) | |
| 1436 return; | |
| 1437 | |
| 1438 UpdateExtensionPref(extension->id(), kBrowserActionVisible, | |
| 1439 Value::CreateBooleanValue(visible)); | |
| 1440 content::NotificationService::current()->Notify( | |
| 1441 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | |
| 1442 content::Source<ExtensionPrefs>(this), | |
| 1443 content::Details<const Extension>(extension)); | |
| 1444 } | |
| 1445 | |
| 1446 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { | 1417 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { |
| 1447 const DictionaryValue* extension = GetExtensionPref(extension_id); | 1418 const DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1448 if (!extension) | 1419 if (!extension) |
| 1449 return std::string(); | 1420 return std::string(); |
| 1450 | 1421 |
| 1451 std::string version; | 1422 std::string version; |
| 1452 extension->GetString(kPrefVersion, &version); | 1423 extension->GetString(kPrefVersion, &version); |
| 1453 | 1424 |
| 1454 return version; | 1425 return version; |
| 1455 } | 1426 } |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2245 is_enabled = initial_state == Extension::ENABLED; | 2216 is_enabled = initial_state == Extension::ENABLED; |
| 2246 } | 2217 } |
| 2247 | 2218 |
| 2248 extension_pref_value_map_->RegisterExtension(extension_id, install_time, | 2219 extension_pref_value_map_->RegisterExtension(extension_id, install_time, |
| 2249 is_enabled); | 2220 is_enabled); |
| 2250 content_settings_store_->RegisterExtension(extension_id, install_time, | 2221 content_settings_store_->RegisterExtension(extension_id, install_time, |
| 2251 is_enabled); | 2222 is_enabled); |
| 2252 } | 2223 } |
| 2253 | 2224 |
| 2254 } // namespace extensions | 2225 } // namespace extensions |
| OLD | NEW |