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/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 const char kPrefScriptableHosts[] = "scriptable_host"; | 155 const char kPrefScriptableHosts[] = "scriptable_host"; |
156 | 156 |
157 // The preference names for the old granted permissions scheme. | 157 // The preference names for the old granted permissions scheme. |
158 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; | 158 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; |
159 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; | 159 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; |
160 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; | 160 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; |
161 | 161 |
162 // A preference that indicates when an extension was installed. | 162 // A preference that indicates when an extension was installed. |
163 const char kPrefInstallTime[] = "install_time"; | 163 const char kPrefInstallTime[] = "install_time"; |
164 | 164 |
165 // A preference which saves the creation flags for extensions. | |
166 const char kPrefCreationFlags[] = "creation_flags"; | |
167 | |
165 // A preference that indicates whether the extension was installed from the | 168 // A preference that indicates whether the extension was installed from the |
166 // Chrome Web Store. | 169 // Chrome Web Store. |
167 const char kPrefFromWebStore[] = "from_webstore"; | 170 const char kPrefFromWebStore[] = "from_webstore"; |
168 | 171 |
169 // A preference that indicates whether the extension was installed from a | 172 // A preference that indicates whether the extension was installed from a |
170 // mock App created from a bookmark. | 173 // mock App created from a bookmark. |
171 const char kPrefFromBookmark[] = "from_bookmark"; | 174 const char kPrefFromBookmark[] = "from_bookmark"; |
172 | 175 |
173 // A prefrence that indicates whethere the extension was installed as | 176 // A prefrence that indicates whethere the extension was installed as |
174 // default apps. | 177 // default apps. |
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1435 return GetExtensionPrefAsVector(kExtensionActionBox); | 1438 return GetExtensionPrefAsVector(kExtensionActionBox); |
1436 } | 1439 } |
1437 | 1440 |
1438 void ExtensionPrefs::SetActionBoxOrder(const ExtensionIdList& extension_ids) { | 1441 void ExtensionPrefs::SetActionBoxOrder(const ExtensionIdList& extension_ids) { |
1439 SetExtensionPrefFromVector(kExtensionActionBox, extension_ids); | 1442 SetExtensionPrefFromVector(kExtensionActionBox, extension_ids); |
1440 } | 1443 } |
1441 | 1444 |
1442 void ExtensionPrefs::OnExtensionInstalled( | 1445 void ExtensionPrefs::OnExtensionInstalled( |
1443 const Extension* extension, | 1446 const Extension* extension, |
1444 Extension::State initial_state, | 1447 Extension::State initial_state, |
1445 bool from_webstore, | 1448 bool from_webstore, |
Mihai Parparita -not on Chrome
2012/09/29 00:22:25
This parameter should be equivalent to extension->
Gaurav
2012/10/01 22:09:36
Done.
| |
1446 const syncer::StringOrdinal& page_ordinal) { | 1449 const syncer::StringOrdinal& page_ordinal) { |
1447 const std::string& id = extension->id(); | 1450 const std::string& id = extension->id(); |
1448 CHECK(Extension::IdIsValid(id)); | 1451 CHECK(Extension::IdIsValid(id)); |
1449 ScopedExtensionPrefUpdate update(prefs_, id); | 1452 ScopedExtensionPrefUpdate update(prefs_, id); |
1450 DictionaryValue* extension_dict = update.Get(); | 1453 DictionaryValue* extension_dict = update.Get(); |
1451 const base::Time install_time = GetCurrentTime(); | 1454 const base::Time install_time = GetCurrentTime(); |
1452 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state)); | 1455 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state)); |
1453 extension_dict->Set(kPrefLocation, | 1456 extension_dict->Set(kPrefLocation, |
1454 Value::CreateIntegerValue(extension->location())); | 1457 Value::CreateIntegerValue(extension->location())); |
1458 extension_dict->Set(kPrefCreationFlags, | |
1459 Value::CreateIntegerValue(extension->creation_flags())); | |
1455 extension_dict->Set(kPrefFromWebStore, | 1460 extension_dict->Set(kPrefFromWebStore, |
1456 Value::CreateBooleanValue(from_webstore)); | 1461 Value::CreateBooleanValue(from_webstore)); |
1457 extension_dict->Set(kPrefFromBookmark, | 1462 extension_dict->Set(kPrefFromBookmark, |
1458 Value::CreateBooleanValue(extension->from_bookmark())); | 1463 Value::CreateBooleanValue(extension->from_bookmark())); |
1459 extension_dict->Set(kPrefWasInstalledByDefault, | 1464 extension_dict->Set(kPrefWasInstalledByDefault, |
1460 Value::CreateBooleanValue(extension->was_installed_by_default())); | 1465 Value::CreateBooleanValue(extension->was_installed_by_default())); |
1461 extension_dict->Set(kPrefInstallTime, | 1466 extension_dict->Set(kPrefInstallTime, |
1462 Value::CreateStringValue( | 1467 Value::CreateStringValue( |
1463 base::Int64ToString(install_time.ToInternalValue()))); | 1468 base::Int64ToString(install_time.ToInternalValue()))); |
1464 extension_dict->Set(kPrefPreferences, new DictionaryValue()); | 1469 extension_dict->Set(kPrefPreferences, new DictionaryValue()); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1858 | 1863 |
1859 bool ExtensionPrefs::IsFromBookmark( | 1864 bool ExtensionPrefs::IsFromBookmark( |
1860 const std::string& extension_id) const { | 1865 const std::string& extension_id) const { |
1861 const DictionaryValue* dictionary = GetExtensionPref(extension_id); | 1866 const DictionaryValue* dictionary = GetExtensionPref(extension_id); |
1862 bool result = false; | 1867 bool result = false; |
1863 if (dictionary && dictionary->GetBoolean(kPrefFromBookmark, &result)) | 1868 if (dictionary && dictionary->GetBoolean(kPrefFromBookmark, &result)) |
1864 return result; | 1869 return result; |
1865 return false; | 1870 return false; |
1866 } | 1871 } |
1867 | 1872 |
1873 int ExtensionPrefs::GetCreationFlags(const std::string& extension_id) const { | |
1874 const DictionaryValue* dictionary = GetExtensionPref(extension_id); | |
1875 int creation_flags = 0; | |
Mihai Parparita -not on Chrome
2012/09/29 00:22:25
There's an Extension::NO_FLAGS value that you can
Gaurav
2012/10/01 22:09:36
Done.
| |
1876 if (dictionary) { | |
1877 dictionary->GetInteger(kPrefCreationFlags, &creation_flags); | |
Mihai Parparita -not on Chrome
2012/09/29 00:22:25
This can still fail (the extension preference dict
Gaurav
2012/10/01 22:09:36
Done.
| |
1878 } else { | |
1879 // Since kPrefCreationFlags was added later, it will be missing for | |
1880 // previously installed extensions. | |
1881 creation_flags |= IsFromBookmark(extension_id); | |
Mihai Parparita -not on Chrome
2012/09/29 00:22:25
This won't quite work. You're trying to say:
creat
Gaurav
2012/09/29 00:30:28
My mad, will fix this.
On 2012/09/29 00:22:25, Mi
Gaurav
2012/10/01 22:09:36
Done.
| |
1882 creation_flags |= IsFromWebStore(extension_id); | |
1883 creation_flags |= WasInstalledByDefault(extension_id); | |
1884 } | |
1885 return creation_flags; | |
1886 } | |
1887 | |
1868 bool ExtensionPrefs::WasInstalledByDefault( | 1888 bool ExtensionPrefs::WasInstalledByDefault( |
1869 const std::string& extension_id) const { | 1889 const std::string& extension_id) const { |
1870 const DictionaryValue* dictionary = GetExtensionPref(extension_id); | 1890 const DictionaryValue* dictionary = GetExtensionPref(extension_id); |
1871 bool result = false; | 1891 bool result = false; |
1872 if (dictionary && | 1892 if (dictionary && |
1873 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result)) | 1893 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result)) |
1874 return result; | 1894 return result; |
1875 return false; | 1895 return false; |
1876 } | 1896 } |
1877 | 1897 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2200 const ExtensionIdList& strings) { | 2220 const ExtensionIdList& strings) { |
2201 ListPrefUpdate update(prefs_, pref); | 2221 ListPrefUpdate update(prefs_, pref); |
2202 ListValue* list_of_values = update.Get(); | 2222 ListValue* list_of_values = update.Get(); |
2203 list_of_values->Clear(); | 2223 list_of_values->Clear(); |
2204 for (ExtensionIdList::const_iterator iter = strings.begin(); | 2224 for (ExtensionIdList::const_iterator iter = strings.begin(); |
2205 iter != strings.end(); ++iter) | 2225 iter != strings.end(); ++iter) |
2206 list_of_values->Append(new StringValue(*iter)); | 2226 list_of_values->Append(new StringValue(*iter)); |
2207 } | 2227 } |
2208 | 2228 |
2209 } // namespace extensions | 2229 } // namespace extensions |
OLD | NEW |