WebCore:
Add methods to FileSystemWin to get some user profile directories
These directories are used to hold things like preferences, caches,
etc.
Reviewed by Brady.
* platform/FileSystem.h: Added new method declarations for Windows
only.
* platform/win/FileSystemWin.cpp:
(WebCore::bundleName): Added.
(WebCore::storageDirectory): Added.
(WebCore::cachedStorageDirectory): Added.
(WebCore::localUserSpecificStorageDirectory): Added. Returns the
directory where WebKit should store any user-specific data that should
stay local to the current machine (i.e., shouldn't be stored in a
roaming profile).
(WebCore::roamingUserSpecificStorageDirectory): Added. Returns the
directory where WebKit should store any user-specific data that should
move with the user from machine to machine (i.e., should be stored in
a roaming profile).
WebKit/win:
Reduce code duplication by using WebCore's FileSystem functions
Reviewed by Brady.
* WebIconDatabase.cpp: Removed a now-unused function and a fixed
FIXME.
(WebIconDatabase::init): Changed to use FileSystem functions.
* WebPreferences.cpp:
(WebPreferences::preferencesPath): Ditto.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@26990
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-10-24 Adam Roben <aroben@apple.com>
+
+ Add methods to FileSystemWin to get some user profile directories
+
+ These directories are used to hold things like preferences, caches,
+ etc.
+
+ Reviewed by Brady.
+
+ * platform/FileSystem.h: Added new method declarations for Windows
+ only.
+ * platform/win/FileSystemWin.cpp:
+ (WebCore::bundleName): Added.
+ (WebCore::storageDirectory): Added.
+ (WebCore::cachedStorageDirectory): Added.
+ (WebCore::localUserSpecificStorageDirectory): Added. Returns the
+ directory where WebKit should store any user-specific data that should
+ stay local to the current machine (i.e., shouldn't be stored in a
+ roaming profile).
+ (WebCore::roamingUserSpecificStorageDirectory): Added. Returns the
+ directory where WebKit should store any user-specific data that should
+ move with the user from machine to machine (i.e., should be stored in
+ a roaming profile).
+
2007-10-24 Alp Toker <alp@atoker.com>
Reviewed by Mark Rowe.
#ifndef FileSystem_h
#define FileSystem_h
+#include <wtf/Platform.h>
#include <wtf/Vector.h>
namespace WebCore {
CString fileSystemRepresentation(const String&);
+#if PLATFORM(WIN)
+String localUserSpecificStorageDirectory();
+String roamingUserSpecificStorageDirectory();
+#endif
+
} // namespace WebCore
#endif // FileSystem_h
return "";\r
}\r
\r
+static String bundleName()\r
+{\r
+ static bool initialized;\r
+ static String name = "WebKit";\r
+\r
+ if (!initialized) {\r
+ initialized = true;\r
+\r
+ if (CFBundleRef bundle = CFBundleGetMainBundle())
+ if (CFTypeRef bundleExecutable = CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleExecutableKey))
+ if (CFGetTypeID(bundleExecutable) == CFStringGetTypeID())
+ name = reinterpret_cast<CFStringRef>(bundleExecutable);\r
+ }\r
+\r
+ return name;\r
+}\r
+\r
+static String storageDirectory(DWORD pathIdentifier)
+{
+ Vector<UChar> buffer(MAX_PATH);
+ if (FAILED(SHGetFolderPathW(0, pathIdentifier | CSIDL_FLAG_CREATE, 0, 0, buffer.data())))
+ return String();
+ buffer.resize(wcslen(buffer.data()));
+ String directory = String::adopt(buffer);
+
+ static const String companyNameDirectory = "Apple Computer\\";
+ directory = pathByAppendingComponent(directory, companyNameDirectory + bundleName());
+ if (!makeAllDirectories(directory))
+ return String();
+
+ return directory;
+}\r
+\r
+static String cachedStorageDirectory(DWORD pathIdentifier)\r
+{\r
+ static HashMap<DWORD, String> directories;\r
+\r
+ HashMap<DWORD, String>::iterator it = directories.find(pathIdentifier);\r
+ if (it != directories.end())\r
+ return it->second;\r
+\r
+ String directory = storageDirectory(pathIdentifier);\r
+ directories.add(pathIdentifier, directory);\r
+\r
+ return directory;\r
+}\r
+\r
+String localUserSpecificStorageDirectory()
+{
+ return cachedStorageDirectory(CSIDL_LOCAL_APPDATA);
+}
+
+String roamingUserSpecificStorageDirectory()
+{
+ return cachedStorageDirectory(CSIDL_APPDATA);
+}
+\r
} // namespace WebCore\r
+2007-10-23 Adam Roben <aroben@apple.com>
+
+ Reduce code duplication by using WebCore's FileSystem functions
+
+ Reviewed by Brady.
+
+ * WebIconDatabase.cpp: Removed a now-unused function and a fixed
+ FIXME.
+ (WebIconDatabase::init): Changed to use FileSystem functions.
+ * WebPreferences.cpp:
+ (WebPreferences::preferencesPath): Ditto.
+
2007-10-23 Sam Weinig <sam@webkit.org>
Make the WebNotificationCenter work with null (wildcard) and specific
#include "WebNotificationCenter.h"
#pragma warning(push, 0)
#include <WebCore/BString.h>
+#include <WebCore/FileSystem.h>
#include <WebCore/IconDatabase.h>
#include <WebCore/Image.h>
#include <WebCore/PlatformString.h>
gClassCount--;
}
-// FIXME - <rdar://problem/4721579>
-// This is code ripped directly from FileUtilities.cpp - it may be extremely useful
-// to have it in a centralized location in WebKit. But also, getting the icon database
-// path should use the WebPreferences system before it falls back to some reasonable default
-HRESULT userIconDatabasePath(String& path)
-{
- // get the path to the user's non-roaming application data folder (Example: C:\Documents and Settings\{username}\Local Settings\Application Data\)
- TCHAR appDataPath[MAX_PATH];
- HRESULT hr = SHGetFolderPath(0, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, appDataPath);
- if (FAILED(hr))
- return hr;
-
- // make the Apple Computer and WebKit subfolder
- path = String(appDataPath) + "\\Apple Computer\\";
-
- WebCore::String appName = "WebKit";
- CFBundleRef bundle = CFBundleGetMainBundle();
- if (bundle) {
- CFStringRef bundleExecutable = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleExecutableKey);
- if (bundleExecutable)
- appName = bundleExecutable;
- }
- path += appName;
-
- if (!CreateDirectory(path.charactersWithNullTermination(), 0)) {
- DWORD err = GetLastError();
- if (err != ERROR_ALREADY_EXISTS)
- return (HRESULT_FROM_WIN32(err));
- }
-
- return S_OK;
-}
-
void WebIconDatabase::init()
{
WebPreferences* standardPrefs = WebPreferences::sharedStandardPreferences();
String databasePath(prefDatabasePath, SysStringLen(prefDatabasePath));
SysFreeString(prefDatabasePath);
- if (databasePath.isEmpty())
- if (FAILED(userIconDatabasePath(databasePath)))
+
+ if (databasePath.isEmpty()) {
+ databasePath = localUserSpecificStorageDirectory();
+ if (databasePath.isEmpty())
LOG_ERROR("Failed to construct default icon database path");
+ }
if (!iconDatabase()->open(databasePath))
LOG_ERROR("Failed to open icon database path");
#include "WebPreferenceKeysPrivate.h"
#pragma warning( push, 0 )
+#include <WebCore/FileSystem.h>
#include <WebCore/Font.h>
#include <WebCore/PlatformString.h>
#include <WebCore/StringHash.h>
#include <wtf/OwnPtr.h>
#include <wtf/Vector.h>
+using namespace WebCore;
+
static unsigned long long WebSystemMainMemory()
{
MEMORYSTATUSEX statex;
HRESULT WebPreferences::preferencesPath(LPTSTR path, size_t cchPath)
{
- // get the path to the user's Application Data folder (Example: C:\Documents and Settings\{username}\Application Data\Apple Computer\WebKit)
- HRESULT hr = SHGetFolderPath(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, path);
- if (FAILED(hr))
- return hr;
-
- if (_tcscat_s(path, cchPath, TEXT("\\Apple Computer\\")))
- return E_FAIL;
-
- WebCore::String appName = "WebKit";
- CFBundleRef bundle = CFBundleGetMainBundle();
- if (bundle) {
- CFStringRef bundleExecutable = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleExecutableKey);
- if (bundleExecutable)
- appName = bundleExecutable;
- }
- if (_tcscat_s(path, cchPath, appName.charactersWithNullTermination()))
- return E_FAIL;
-
- int err = SHCreateDirectoryEx(0, path, 0);
- if (err != ERROR_SUCCESS && err != ERROR_ALREADY_EXISTS)
- return E_FAIL;
+ static const String filename = "WebKitPreferences.plist";
- if (_tcscat_s(path, cchPath, TEXT("\\WebKitPreferences.plist")))
- return E_FAIL;
+ String prefs = pathByAppendingComponent(roamingUserSpecificStorageDirectory(), filename);
+ if (int err = _tcscpy_s(path, cchPath, prefs.charactersWithNullTermination()))
+ return HRESULT_FROM_WIN32(err);
return S_OK;
}