Reviewed by Darin Adler and Adam Roben.
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Nov 2007 16:47:39 +0000 (16:47 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Nov 2007 16:47:39 +0000 (16:47 +0000)
        - <rdar://problem/5057218> Reenable "recent searches" search field menu when menu is fully implemented

        * platform/win/SearchPopupMenuWin.cpp:
        (WebCore::SearchPopupMenu::enabled): Changed to return true.
        (WebCore::autosaveKey): Added. Returns a preferences key for the
        autosave name by prefixing it with "com.apple.WebKit.searchField:".
        (WebCore::SearchPopupMenu::saveRecentSearches): Implemented.
        (WebCore::SearchPopupMenu::loadRecentSearches): Implemented.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28111 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/win/SearchPopupMenuWin.cpp

index 9e0c71fd01c8e23ce5398a50c7a942db0c5bdf47..d995eebc86ccfdd89ebff8ea7d205f5ceed00e89 100644 (file)
@@ -1,3 +1,16 @@
+2007-11-28  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Darin Adler and Adam Roben.
+
+        - <rdar://problem/5057218> Reenable "recent searches" search field menu when menu is fully implemented
+
+        * platform/win/SearchPopupMenuWin.cpp:
+        (WebCore::SearchPopupMenu::enabled): Changed to return true.
+        (WebCore::autosaveKey): Added. Returns a preferences key for the
+        autosave name by prefixing it with "com.apple.WebKit.searchField:".
+        (WebCore::SearchPopupMenu::saveRecentSearches): Implemented.
+        (WebCore::SearchPopupMenu::loadRecentSearches): Implemented.
+
 2007-11-28  Alp Toker  <alp@atoker.com>
 
         Reviewed by Mark Rowe.
 2007-11-28  Alp Toker  <alp@atoker.com>
 
         Reviewed by Mark Rowe.
index 0c969616b5bac438c0f4d7ec2d00e2dca7cdf3a4..f2709bbe767f54a91d5a66e0bf9ec5b47a10b736 100644 (file)
@@ -21,7 +21,7 @@
 #include "SearchPopupMenu.h"
 
 #include "AtomicString.h"
 #include "SearchPopupMenu.h"
 
 #include "AtomicString.h"
-#include "NotImplemented.h"
+#include <wtf/RetainPtr.h>
 
 namespace WebCore {
 
 
 namespace WebCore {
 
@@ -32,18 +32,52 @@ SearchPopupMenu::SearchPopupMenu(PopupMenuClient* client)
 
 bool SearchPopupMenu::enabled()
 {
 
 bool SearchPopupMenu::enabled()
 {
-    // FIXME: <rdar://problem/5057218> Reenable "recent searches" search field menu when menu is fully implemented
-    return false;
+    return true;
+}
+
+static RetainPtr<CFStringRef> autosaveKey(const String& name)
+{
+    String key = "com.apple.WebKit.searchField:" + name;
+    return RetainPtr<CFStringRef>(AdoptCF, key.createCFString());
 }
 
 void SearchPopupMenu::saveRecentSearches(const AtomicString& name, const Vector<String>& searchItems)
 {
 }
 
 void SearchPopupMenu::saveRecentSearches(const AtomicString& name, const Vector<String>& searchItems)
 {
-    notImplemented();
+    if (name.isEmpty())
+        return;
+
+    RetainPtr<CFMutableArrayRef> items;
+
+    size_t size = searchItems.size();
+    if (size) {
+        items.adoptCF(CFArrayCreateMutable(0, size, &kCFTypeArrayCallBacks));
+        for (size_t i = 0; i < size; ++i) {
+            RetainPtr<CFStringRef> item(AdoptCF, searchItems[i].createCFString());
+            CFArrayAppendValue(items.get(), item.get());
+        }
+    }
+
+    CFPreferencesSetAppValue(autosaveKey(name).get(), items.get(), kCFPreferencesCurrentApplication);
+    CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
 }
 
 void SearchPopupMenu::loadRecentSearches(const AtomicString& name, Vector<String>& searchItems)
 {
 }
 
 void SearchPopupMenu::loadRecentSearches(const AtomicString& name, Vector<String>& searchItems)
 {
-    notImplemented();
+    if (name.isEmpty())
+        return;
+
+    searchItems.clear();
+    RetainPtr<CFArrayRef> items(AdoptCF, reinterpret_cast<CFArrayRef>(CFPreferencesCopyAppValue(autosaveKey(name).get(), kCFPreferencesCurrentApplication)));
+
+    if (!items || CFGetTypeID(items.get()) != CFArrayGetTypeID())
+        return;
+
+    size_t size = CFArrayGetCount(items.get());
+    for (size_t i = 0; i < size; ++i) {
+        CFStringRef item = (CFStringRef)CFArrayGetValueAtIndex(items.get(), i);
+        if (CFGetTypeID(item) == CFStringGetTypeID())
+            searchItems.append(item);
+    }
 }
 
 }
 }
 
 }