Add WebPreferences::sharedStandardPreferences
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Aug 2007 02:00:30 +0000 (02:00 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Aug 2007 02:00:30 +0000 (02:00 +0000)
         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

WebKit/win/ChangeLog
WebKit/win/WebHistory.cpp
WebKit/win/WebIconDatabase.cpp
WebKit/win/WebPreferences.cpp
WebKit/win/WebPreferences.h
WebKit/win/WebView.cpp

index e21b962ac27d4889c43168112745a6647063575f..51718383b455bc61c820702563b8bd3a14814d3a 100644 (file)
@@ -1,3 +1,25 @@
+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.
index f9d1744b8f49293032b721457aa6f9891406c2ce..a29e6638e8eddde30b849a2a60eeeb6d1c8796d4 100644 (file)
@@ -110,10 +110,7 @@ WebHistory::WebHistory()
     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()
index 13de48cf374f853c248e476b241893297e21166b..c4b05919067d45adf7bc9eabc1bf9aadc6bb02d7 100644 (file)
@@ -89,22 +89,18 @@ HRESULT userIconDatabasePath(String& path)
 
 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())
index c7308045c8cbf8367beb8b05c668e9e599066ee7..a4f4c2c384a692629a09b99b4aa01f2b6cca8323 100644 (file)
@@ -58,10 +58,22 @@ static unsigned long long WebSystemMainMemory()
 // 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)
@@ -93,11 +105,8 @@ HRESULT WebPreferences::postPreferencesChangesNotification()
 
 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);
@@ -567,25 +576,11 @@ ULONG STDMETHODCALLTYPE WebPreferences::Release(void)
 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( 
index 1e1dc5cb455916d1ad7025089e360690b2804541..06528b25441bb1b12a7fdf630c1dbfc98e77d139 100644 (file)
@@ -275,6 +275,7 @@ public:
     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);
index 26d98ae43675a8f90df172c8a17f54c6de447e7a..b444a2ba61d35d9e17580de4a451c0003152fcf5 100644 (file)
@@ -2267,13 +2267,8 @@ HRESULT STDMETHODCALLTYPE WebView::preferences(
 {
     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;