2 * Copyright (C) 2006, 2007 Apple Inc.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "SearchPopupMenuWin.h"
24 #include <wtf/text/AtomicString.h>
27 #include <wtf/RetainPtr.h>
32 SearchPopupMenuWin::SearchPopupMenuWin(PopupMenuClient* client)
33 : m_popup(adoptRef(new PopupMenuWin(client)))
37 PopupMenu* SearchPopupMenuWin::popupMenu()
42 bool SearchPopupMenuWin::enabled()
52 static RetainPtr<CFStringRef> autosaveKey(const String& name)
54 String key = "com.apple.WebKit.searchField:" + name;
55 return RetainPtr<CFStringRef>(AdoptCF, key.createCFString());
59 void SearchPopupMenuWin::saveRecentSearches(const AtomicString& name, const Vector<String>& searchItems)
65 RetainPtr<CFMutableArrayRef> items;
67 size_t size = searchItems.size();
69 items.adoptCF(CFArrayCreateMutable(0, size, &kCFTypeArrayCallBacks));
70 for (size_t i = 0; i < size; ++i) {
71 RetainPtr<CFStringRef> item(AdoptCF, searchItems[i].createCFString());
72 CFArrayAppendValue(items.get(), item.get());
76 CFPreferencesSetAppValue(autosaveKey(name).get(), items.get(), kCFPreferencesCurrentApplication);
77 CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
81 void SearchPopupMenuWin::loadRecentSearches(const AtomicString& name, Vector<String>& searchItems)
88 RetainPtr<CFArrayRef> items(AdoptCF, reinterpret_cast<CFArrayRef>(CFPreferencesCopyAppValue(autosaveKey(name).get(), kCFPreferencesCurrentApplication)));
90 if (!items || CFGetTypeID(items.get()) != CFArrayGetTypeID())
93 size_t size = CFArrayGetCount(items.get());
94 for (size_t i = 0; i < size; ++i) {
95 CFStringRef item = (CFStringRef)CFArrayGetValueAtIndex(items.get(), i);
96 if (CFGetTypeID(item) == CFStringGetTypeID())
97 searchItems.append(item);