Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 828 string16 default_title; | 828 string16 default_title; |
| 829 if (extension_sidebar->HasKey(keys::kSidebarDefaultTitle)) { | 829 if (extension_sidebar->HasKey(keys::kSidebarDefaultTitle)) { |
| 830 if (!extension_sidebar->GetString(keys::kSidebarDefaultTitle, | 830 if (!extension_sidebar->GetString(keys::kSidebarDefaultTitle, |
| 831 &default_title)) { | 831 &default_title)) { |
| 832 *error = errors::kInvalidSidebarDefaultTitle; | 832 *error = errors::kInvalidSidebarDefaultTitle; |
| 833 return NULL; | 833 return NULL; |
| 834 } | 834 } |
| 835 } | 835 } |
| 836 result->set_default_title(default_title); | 836 result->set_default_title(default_title); |
| 837 | 837 |
| 838 // Read sidebar's |default_url| (optional). | 838 // Read sidebar's |default_page| (optional). |
| 839 std::string default_url; | 839 std::string default_page; |
| 840 if (extension_sidebar->HasKey(keys::kSidebarDefaultUrl)) { | 840 if (extension_sidebar->HasKey(keys::kSidebarDefaultPage)) { |
|
Aaron Boodman
2011/01/24 19:57:49
You should also validate that this path exists in
Aleksey Shlyapnikov
2011/01/24 21:29:03
Done.
| |
| 841 if (!extension_sidebar->GetString(keys::kSidebarDefaultUrl, &default_url) || | 841 if (!extension_sidebar->GetString(keys::kSidebarDefaultPage, |
| 842 default_url.empty()) { | 842 &default_page) || |
| 843 *error = errors::kInvalidSidebarDefaultUrl; | 843 default_page.empty()) { |
| 844 *error = errors::kInvalidSidebarDefaultPage; | |
| 844 return NULL; | 845 return NULL; |
| 845 } | 846 } |
| 846 GURL resolved_url = extension_sidebar_utils::ResolveAndVerifyUrl( | 847 GURL url = extension_sidebar_utils::ResolveRelativePath( |
| 847 default_url, this, error); | 848 default_page, this, error); |
| 848 if (!resolved_url.is_valid()) | 849 if (!url.is_valid()) |
| 849 return NULL; | 850 return NULL; |
| 850 result->set_default_url(resolved_url); | 851 result->set_default_page(url); |
| 851 } | 852 } |
| 852 | 853 |
| 853 return result.release(); | 854 return result.release(); |
| 854 } | 855 } |
| 855 | 856 |
| 856 bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) const { | 857 bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) const { |
| 857 for (DictionaryValue::key_iterator key = source.begin_keys(); | 858 for (DictionaryValue::key_iterator key = source.begin_keys(); |
| 858 key != source.end_keys(); ++key) { | 859 key != source.end_keys(); ++key) { |
| 859 if (!IsBaseCrxKey(*key) && *key != keys::kTheme) | 860 if (!IsBaseCrxKey(*key) && *key != keys::kTheme) |
| 860 return true; | 861 return true; |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1890 *error = errors::kInvalidDevToolsPage; | 1891 *error = errors::kInvalidDevToolsPage; |
| 1891 return false; | 1892 return false; |
| 1892 } | 1893 } |
| 1893 if (!HasApiPermission(Extension::kExperimentalPermission)) { | 1894 if (!HasApiPermission(Extension::kExperimentalPermission)) { |
| 1894 *error = errors::kDevToolsExperimental; | 1895 *error = errors::kDevToolsExperimental; |
| 1895 return false; | 1896 return false; |
| 1896 } | 1897 } |
| 1897 devtools_url_ = GetResourceURL(devtools_str); | 1898 devtools_url_ = GetResourceURL(devtools_str); |
| 1898 } | 1899 } |
| 1899 | 1900 |
| 1901 // Initialize sidebar action (optional). | |
| 1902 if (source.HasKey(keys::kSidebar)) { | |
| 1903 DictionaryValue* sidebar_value; | |
| 1904 if (!source.GetDictionary(keys::kSidebar, &sidebar_value)) { | |
| 1905 *error = errors::kInvalidSidebar; | |
| 1906 return false; | |
| 1907 } | |
| 1908 if (!HasApiPermission(Extension::kExperimentalPermission)) { | |
| 1909 *error = errors::kSidebarExperimental; | |
| 1910 return false; | |
| 1911 } | |
| 1912 sidebar_defaults_.reset(LoadExtensionSidebarDefaults(sidebar_value, error)); | |
| 1913 if (!sidebar_defaults_.get()) | |
| 1914 return false; // Failed to parse sidebar definition. | |
| 1915 } | |
| 1916 | |
| 1900 // Initialize text-to-speech voices (optional). | 1917 // Initialize text-to-speech voices (optional). |
| 1901 if (source.HasKey(keys::kTts)) { | 1918 if (source.HasKey(keys::kTts)) { |
| 1902 DictionaryValue* tts_dict; | 1919 DictionaryValue* tts_dict; |
| 1903 if (!source.GetDictionary(keys::kTts, &tts_dict)) { | 1920 if (!source.GetDictionary(keys::kTts, &tts_dict)) { |
| 1904 *error = errors::kInvalidTts; | 1921 *error = errors::kInvalidTts; |
| 1905 return false; | 1922 return false; |
| 1906 } | 1923 } |
| 1907 | 1924 |
| 1908 if (tts_dict->HasKey(keys::kTtsVoices)) { | 1925 if (tts_dict->HasKey(keys::kTtsVoices)) { |
| 1909 ListValue* tts_voices; | 1926 ListValue* tts_voices; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1969 } | 1986 } |
| 1970 } | 1987 } |
| 1971 | 1988 |
| 1972 if (HasMultipleUISurfaces()) { | 1989 if (HasMultipleUISurfaces()) { |
| 1973 *error = errors::kOneUISurfaceOnly; | 1990 *error = errors::kOneUISurfaceOnly; |
| 1974 return false; | 1991 return false; |
| 1975 } | 1992 } |
| 1976 | 1993 |
| 1977 InitEffectiveHostPermissions(); | 1994 InitEffectiveHostPermissions(); |
| 1978 | 1995 |
| 1979 // Initialize sidebar action (optional). It has to be done after host | |
| 1980 // permissions are initialized to verify default sidebar url. | |
| 1981 if (source.HasKey(keys::kSidebar)) { | |
| 1982 DictionaryValue* sidebar_value; | |
| 1983 if (!source.GetDictionary(keys::kSidebar, &sidebar_value)) { | |
| 1984 *error = errors::kInvalidSidebar; | |
| 1985 return false; | |
| 1986 } | |
| 1987 if (!HasApiPermission(Extension::kExperimentalPermission)) { | |
| 1988 *error = errors::kSidebarExperimental; | |
| 1989 return false; | |
| 1990 } | |
| 1991 sidebar_defaults_.reset(LoadExtensionSidebarDefaults(sidebar_value, error)); | |
| 1992 if (!sidebar_defaults_.get()) | |
| 1993 return false; // Failed to parse sidebar definition. | |
| 1994 } | |
| 1995 | |
| 1996 // Although |source| is passed in as a const, it's still possible to modify | 1996 // Although |source| is passed in as a const, it's still possible to modify |
| 1997 // it. This is dangerous since the utility process re-uses |source| after | 1997 // it. This is dangerous since the utility process re-uses |source| after |
| 1998 // it calls InitFromValue, passing it up to the browser process which calls | 1998 // it calls InitFromValue, passing it up to the browser process which calls |
| 1999 // InitFromValue again. As a result, we need to make sure that nobody | 1999 // InitFromValue again. As a result, we need to make sure that nobody |
| 2000 // accidentally modifies it. | 2000 // accidentally modifies it. |
| 2001 DCHECK(source.Equals(manifest_value_.get())); | 2001 DCHECK(source.Equals(manifest_value_.get())); |
| 2002 | 2002 |
| 2003 return true; | 2003 return true; |
| 2004 } | 2004 } |
| 2005 | 2005 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2372 | 2372 |
| 2373 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} | 2373 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} |
| 2374 | 2374 |
| 2375 | 2375 |
| 2376 UnloadedExtensionInfo::UnloadedExtensionInfo( | 2376 UnloadedExtensionInfo::UnloadedExtensionInfo( |
| 2377 const Extension* extension, | 2377 const Extension* extension, |
| 2378 Reason reason) | 2378 Reason reason) |
| 2379 : reason(reason), | 2379 : reason(reason), |
| 2380 already_disabled(false), | 2380 already_disabled(false), |
| 2381 extension(extension) {} | 2381 extension(extension) {} |
| OLD | NEW |