diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 23:48:34 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 23:48:34 +0000 |
commit | 1952c7d55e5f3cb5d7d75eeab965af32459d2b31 (patch) | |
tree | cc32dc77802bbd5b87031a7edb54c936f602d2da /chrome/common | |
parent | 495839a63f9516e20abbf0ab2258aa5d7dfa7180 (diff) | |
download | chromium_src-1952c7d55e5f3cb5d7d75eeab965af32459d2b31.zip chromium_src-1952c7d55e5f3cb5d7d75eeab965af32459d2b31.tar.gz chromium_src-1952c7d55e5f3cb5d7d75eeab965af32459d2b31.tar.bz2 |
Load the bookmark manager extension at Chrome startup.
Review URL: http://codereview.chromium.org/660232
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40683 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/chrome_paths.cc | 13 | ||||
-rw-r--r-- | chrome/common/chrome_paths.h | 53 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 58 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 22 | ||||
-rw-r--r-- | chrome/common/extensions/extension_unittest.cc | 11 |
5 files changed, 88 insertions, 69 deletions
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index d423507..58e8f68 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -111,7 +111,7 @@ bool PathProvider(int key, FilePath* result) { if (!GetUserDesktop(&cur)) return false; break; - case chrome::DIR_INSPECTOR: + case chrome::DIR_RESOURCES: #if defined(OS_MACOSX) cur = mac_util::MainAppBundlePath(); cur = cur.Append(FILE_PATH_LITERAL("Resources")); @@ -120,6 +120,15 @@ bool PathProvider(int key, FilePath* result) { return false; cur = cur.Append(FILE_PATH_LITERAL("resources")); #endif + break; + case chrome::DIR_BOOKMARK_MANAGER: + if (!PathService::Get(chrome::DIR_RESOURCES, &cur)) + return false; + cur = cur.Append(FILE_PATH_LITERAL("bookmark_manager")); + break; + case chrome::DIR_INSPECTOR: + if (!PathService::Get(chrome::DIR_RESOURCES, &cur)) + return false; cur = cur.Append(FILE_PATH_LITERAL("inspector")); break; case chrome::DIR_APP_DICTIONARIES: diff --git a/chrome/common/chrome_paths.h b/chrome/common/chrome_paths.h index 3b0521b..2bfaeea 100644 --- a/chrome/common/chrome_paths.h +++ b/chrome/common/chrome_paths.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,38 +15,41 @@ namespace chrome { enum { PATH_START = 1000, - DIR_APP = PATH_START, // directory where dlls and data reside - DIR_LOGS, // directory where logs should be written - DIR_USER_DATA, // directory where user data can be written - DIR_CRASH_DUMPS, // directory where crash dumps are written - DIR_USER_DESKTOP, // directory that correspond to the desktop - DIR_INSPECTOR, // directory where web inspector is located - DIR_APP_DICTIONARIES, // directory where the global dictionaries are - DIR_USER_DOCUMENTS, // directory for a user's "My Documents" - DIR_DEFAULT_DOWNLOADS_SAFE, // directory for a user's - // "My Documents/Downloads" - DIR_DEFAULT_DOWNLOADS, // directory for a user's downloads - FILE_RESOURCE_MODULE, // full path and filename of the module that + DIR_APP = PATH_START, // Directory where dlls and data reside. + DIR_LOGS, // Directory where logs should be written. + DIR_USER_DATA, // Directory where user data can be written. + DIR_CRASH_DUMPS, // Directory where crash dumps are written. + DIR_USER_DESKTOP, // Directory that correspond to the desktop. + DIR_RESOURCES, // Directory containing separate file resources + // used by Chrome at runtime. + DIR_BOOKMARK_MANAGER, // Directory containing the bookmark manager. + DIR_INSPECTOR, // Directory where web inspector is located. + DIR_APP_DICTIONARIES, // Directory where the global dictionaries are. + DIR_USER_DOCUMENTS, // Directory for a user's "My Documents". + DIR_DEFAULT_DOWNLOADS_SAFE, // Directory for a user's + // "My Documents/Downloads". + DIR_DEFAULT_DOWNLOADS, // Directory for a user's downloads. + FILE_RESOURCE_MODULE, // Full path and filename of the module that // contains embedded resources (version, - // strings, images, etc.) - FILE_LOCAL_STATE, // path and filename to the file in which - // machine/installation-specific state is saved - FILE_RECORDED_SCRIPT, // full path to the script.log file that - // contains recorded browser events for playback - FILE_GEARS_PLUGIN, // full path to the gears.dll plugin file. - FILE_LIBAVCODEC, // full path to libavcodec media decoding + // strings, images, etc.). + FILE_LOCAL_STATE, // Path and filename to the file in which + // machine/installation-specific state is saved. + FILE_RECORDED_SCRIPT, // Full path to the script.log file that + // contains recorded browser events for playback. + FILE_GEARS_PLUGIN, // Full path to the gears.dll plugin file. + FILE_LIBAVCODEC, // Full path to libavcodec media decoding // library. - FILE_LIBAVFORMAT, // full path to libavformat media parsing + FILE_LIBAVFORMAT, // Full path to libavformat media parsing // library. - FILE_LIBAVUTIL, // full path to libavutil media utility library. + FILE_LIBAVUTIL, // Full path to libavutil media utility library. #if defined(OS_CHROMEOS) - FILE_CHROMEOS_API, // full path to chrome os api shared object. + FILE_CHROMEOS_API, // Full path to chrome os api shared object. #endif // Valid only in development environment; TODO(darin): move these - DIR_TEST_DATA, // directory where unit test data resides - DIR_TEST_TOOLS, // directory where unit test tools reside + DIR_TEST_DATA, // Directory where unit test data resides. + DIR_TEST_TOOLS, // Directory where unit test tools reside. PATH_END }; diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 0130929..4436b72 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -58,25 +58,6 @@ static void ConvertHexadecimalToIDAlphabet(std::string* id) { (*id)[i] = HexStringToInt(id->substr(i, 1)) + 'a'; } -// Returns true if the given string is an API permission (see kPermissionNames). -static bool IsAPIPermission(const std::string& str) { - for (size_t i = 0; i < Extension::kNumPermissions; ++i) { - if (str == Extension::kPermissionNames[i]) { - if (str == Extension::kExperimentalPermission && - !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableExperimentalExtensionApis) && - // TODO(arv): Tighten this so that not all extensions can access the - // experimental APIs. - !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableTabbedBookmarkManager)) { - return false; - } - return true; - } - } - return false; -} - } // namespace const FilePath::CharType Extension::kManifestFilename[] = @@ -177,19 +158,6 @@ GURL Extension::GetResourceURL(const GURL& extension_url, return ret_val; } -Extension::Location Extension::ExternalExtensionInstallType( - std::string registry_path) { -#if defined(OS_WIN) - HKEY reg_root = HKEY_LOCAL_MACHINE; - RegKey key; - registry_path.append("\\"); - registry_path.append(id_); - if (key.Open(reg_root, ASCIIToWide(registry_path).c_str())) - return Extension::EXTERNAL_REGISTRY; -#endif - return Extension::EXTERNAL_PREF; -} - bool Extension::GenerateId(const std::string& input, std::string* output) { CHECK(output); if (input.length() == 0) @@ -788,7 +756,7 @@ void Extension::DecodeIconFromPath(const FilePath& icon_path, result->swap(decoded); } -bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, +bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, std::string* error) { if (source.HasKey(keys::kPublicKey)) { std::string public_key_bytes; @@ -798,7 +766,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, *error = errors::kInvalidKey; return false; } - } else if (require_id) { + } else if (require_key) { *error = errors::kInvalidKey; return false; } else { @@ -1447,3 +1415,25 @@ bool Extension::HasAccessToAllHosts() const { return false; } + +bool Extension::IsAPIPermission(const std::string& str) { + for (size_t i = 0; i < Extension::kNumPermissions; ++i) { + if (str == Extension::kPermissionNames[i]) { + // Only allow the experimental API permission if the command line + // flag is present, or if the extension is a component of Chrome. + if (str == Extension::kExperimentalPermission) { + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableExperimentalExtensionApis)) { + return true; + } else if (location() == Extension::COMPONENT) { + return true; + } else { + return false; + } + } else { + return true; + } + } + } + return false; +} diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 88d093f..78e75a6 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -28,13 +28,18 @@ class Extension { typedef std::map<const std::string, GURL> URLOverrideMap; // What an extension was loaded from. + // NOTE: These values are stored as integers in the preferences, so you + // really don't want to change any existing ones. enum Location { INVALID, INTERNAL, // A crx file from the internal Extensions directory. EXTERNAL_PREF, // A crx file from an external directory (via prefs). EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the // registry on Windows). - LOAD // --load-extension. + LOAD, // --load-extension. + COMPONENT // An integral component of Chrome itself, which happens + // to be implemented as an extension. We don't show + // these in the management UI. }; enum State { @@ -188,9 +193,10 @@ class Extension { scoped_ptr<SkBitmap>* result); // Initialize the extension from a parsed manifest. - // If |require_id| is true, will return an error if the "id" key is missing - // from the value. - bool InitFromValue(const DictionaryValue& value, bool require_id, + // Usually, the id of an extension is generated by the "key" property of + // its manifest, but if |require_key| is |false|, a temporary ID will be + // generated based on the path. + bool InitFromValue(const DictionaryValue& value, bool require_key, std::string* error); const FilePath& path() const { return path_; } @@ -247,10 +253,6 @@ class Extension { const GURL& update_url() const { return update_url_; } const std::map<int, std::string>& icons() const { return icons_; } - // Returns the origin of this extension. This function takes a |registry_path| - // so that the registry location can be overwritten during testing. - Location ExternalExtensionInstallType(std::string registry_path); - // Theme-related. DictionaryValue* GetThemeImages() const { return theme_images_.get(); } DictionaryValue* GetThemeColors() const { return theme_colors_.get(); } @@ -334,6 +336,10 @@ class Extension { // Helper method to verify the app section of the manifest. bool LoadAppHelper(const DictionaryValue* app, std::string* error); + // Returns true if the string is one of the known api permissions (see + // kPermissionNames). + bool IsAPIPermission(const std::string& permission); + // The absolute path to the directory the extension is stored in. FilePath path_; diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc index d0d1f89..29ba032e 100644 --- a/chrome/common/extensions/extension_unittest.cc +++ b/chrome/common/extensions/extension_unittest.cc @@ -25,6 +25,17 @@ namespace errors = extension_manifest_errors; class ExtensionTest : public testing::Test { }; +// We persist location values in the preferences, so this is a sanity test that +// someone doesn't accidentally change them. +TEST(ExtensionTest, LocationValuesTest) { + ASSERT_EQ(0, Extension::INVALID); + ASSERT_EQ(1, Extension::INTERNAL); + ASSERT_EQ(2, Extension::EXTERNAL_PREF); + ASSERT_EQ(3, Extension::EXTERNAL_REGISTRY); + ASSERT_EQ(4, Extension::LOAD); + ASSERT_EQ(5, Extension::COMPONENT); +} + TEST(ExtensionTest, InitFromValueInvalid) { #if defined(OS_WIN) FilePath path(FILE_PATH_LITERAL("c:\\foo")); |