This is a convenience method to get the standard preferences object so
that within WebKit we don't have to deal with the fact that COM doesn't
support static methods.
Reviewed by Ada.
* WebHistory.cpp:
(WebHistory::WebHistory): Use sharedStandardPreferences.
* WebIconDatabase.cpp:
(WebIconDatabase::init): Ditto.
* WebPreferences.cpp:
(WebPreferences::sharedStandardPreferences): Added.
(WebPreferences::getInstanceForIdentifier): Use sharedStandardPreferences.
(WebPreferences::standardPreferences): Ditto.
* WebPreferences.h:
* WebView.cpp:
(WebView::preferences): Ditto.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25139
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-08-17 Adam Roben <aroben@apple.com>
+
+ Add WebPreferences::sharedStandardPreferences
+
+ This is a convenience method to get the standard preferences object so
+ that within WebKit we don't have to deal with the fact that COM doesn't
+ support static methods.
+
+ Reviewed by Ada.
+
+ * WebHistory.cpp:
+ (WebHistory::WebHistory): Use sharedStandardPreferences.
+ * WebIconDatabase.cpp:
+ (WebIconDatabase::init): Ditto.
+ * WebPreferences.cpp:
+ (WebPreferences::sharedStandardPreferences): Added.
+ (WebPreferences::getInstanceForIdentifier): Use sharedStandardPreferences.
+ (WebPreferences::standardPreferences): Ditto.
+ * WebPreferences.h:
+ * WebView.cpp:
+ (WebView::preferences): Ditto.
+
2007-08-17 Anders Carlsson <andersca@apple.com>
Build fix.
m_datesWithEntries.adoptCF(CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks));
m_entriesByDate.adoptCF(CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks));
- COMPtr<WebPreferences> tempPrefs(AdoptCOM, WebPreferences::createInstance());
- IWebPreferences* standardPrefs;
- tempPrefs->standardPreferences(&standardPrefs);
- m_preferences.adoptRef(static_cast<WebPreferences*>(standardPrefs)); // should be safe, since there's no setter for standardPrefs
+ m_preferences = WebPreferences::sharedStandardPreferences();
}
WebHistory::~WebHistory()
void WebIconDatabase::init()
{
- WebPreferences* prefs = WebPreferences::createInstance();
- COMPtr<IWebPreferences> standardPrefs;
+ WebPreferences* standardPrefs = WebPreferences::sharedStandardPreferences();
BOOL enabled = FALSE;
- if (SUCCEEDED(prefs->standardPreferences(&standardPrefs)))
- if (FAILED(standardPrefs->iconDatabaseEnabled(&enabled))) {
- enabled = FALSE;
- LOG_ERROR("Unable to get icon database enabled preference");
- }
+ if (FAILED(standardPrefs->iconDatabaseEnabled(&enabled))) {
+ enabled = FALSE;
+ LOG_ERROR("Unable to get icon database enabled preference");
+ }
iconDatabase()->setEnabled(!!enabled);
BSTR prefDatabasePath = 0;
if (FAILED(standardPrefs->iconDatabaseLocation(&prefDatabasePath)))
LOG_ERROR("Unable to get icon database location preference");
- prefs->Release();
-
String databasePath(prefDatabasePath, SysStringLen(prefDatabasePath));
SysFreeString(prefDatabasePath);
if (databasePath.isEmpty())
// WebPreferences ----------------------------------------------------------------
CFDictionaryRef WebPreferences::s_defaultSettings = 0;
-WebPreferences* WebPreferences::s_standardPreferences = 0;
static HashMap<WebCore::String, WebPreferences*> webPreferencesInstances;
+WebPreferences* WebPreferences::sharedStandardPreferences()
+{
+ static WebPreferences* standardPreferences;
+ if (!standardPreferences) {
+ standardPreferences = WebPreferences::createInstance();
+ standardPreferences->load();
+ standardPreferences->setAutosaves(TRUE);
+ standardPreferences->postPreferencesChangesNotification();
+ }
+
+ return standardPreferences;
+}
+
WebPreferences::WebPreferences()
: m_refCount(0)
, m_autoSaves(0)
WebPreferences* WebPreferences::getInstanceForIdentifier(BSTR identifier)
{
- if (!identifier) {
- if (s_standardPreferences)
- return s_standardPreferences;
- return 0;
- }
+ if (!identifier)
+ return sharedStandardPreferences();
WebCore::String identifierString(identifier, SysStringLen(identifier));
return webPreferencesInstances.get(identifierString);
HRESULT STDMETHODCALLTYPE WebPreferences::standardPreferences(
/* [retval][out] */ IWebPreferences** standardPreferences)
{
- HRESULT hr = S_OK;
-
- if (!s_standardPreferences) {
- IWebPreferences* standardPrefs;
- hr = initWithIdentifier(0, &standardPrefs);
- if (FAILED(hr))
- return hr;
- s_standardPreferences = static_cast<WebPreferences*>(standardPrefs);
- hr = s_standardPreferences->setAutosaves(TRUE);
- if (FAILED(hr))
- return hr;
- hr = s_standardPreferences->postPreferencesChangesNotification();
- if (FAILED(hr))
- return hr;
- }
-
- s_standardPreferences->AddRef();
- *standardPreferences = s_standardPreferences;
- return hr;
+ if (!standardPreferences)
+ return E_POINTER;
+ *standardPreferences = sharedStandardPreferences();
+ (*standardPreferences)->AddRef();
+ return S_OK;
}
HRESULT STDMETHODCALLTYPE WebPreferences::initWithIdentifier(
static BSTR webPreferencesChangedNotification();
static void setInstance(WebPreferences* instance, BSTR identifier);
static void removeReferenceForIdentifier(BSTR identifier);
+ static WebPreferences* sharedStandardPreferences();
// From WebHistory.h
HRESULT historyItemLimit(int* limit);
{
HRESULT hr = S_OK;
- if (!m_preferences) {
- WebPreferences* instance = WebPreferences::createInstance();
- if (!instance)
- return E_FAIL;
- hr = instance->standardPreferences(&m_preferences);
- instance->Release();
- }
+ if (!m_preferences)
+ m_preferences = WebPreferences::sharedStandardPreferences();
m_preferences.copyRefTo(prefs);
return hr;