2 * Copyright (C) 2006 Apple Computer, 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 #import "SearchPopupMenuMac.h"
24 #include <wtf/text/AtomicString.h>
28 SearchPopupMenuMac::SearchPopupMenuMac(PopupMenuClient* client)
29 : m_popup(adoptRef(new PopupMenuMac(client)))
33 static NSString* autosaveKey(const String& name)
35 return [@"com.apple.WebKit.searchField:" stringByAppendingString:name];
38 PopupMenu* SearchPopupMenuMac::popupMenu()
43 bool SearchPopupMenuMac::enabled()
48 void SearchPopupMenuMac::saveRecentSearches(const AtomicString& name, const Vector<String>& searchItems)
53 size_t size = searchItems.size();
55 [[NSUserDefaults standardUserDefaults] removeObjectForKey:autosaveKey(name)];
57 NSMutableArray* items = [[NSMutableArray alloc] initWithCapacity:size];
58 for (size_t i = 0; i < size; ++i)
59 [items addObject:searchItems[i]];
60 [[NSUserDefaults standardUserDefaults] setObject:items forKey:autosaveKey(name)];
65 void SearchPopupMenuMac::loadRecentSearches(const AtomicString& name, Vector<String>& searchItems)
71 NSArray* items = [[NSUserDefaults standardUserDefaults] arrayForKey:autosaveKey(name)];
72 size_t size = [items count];
73 for (size_t i = 0; i < size; ++i) {
74 NSString* item = [items objectAtIndex:i];
75 if ([item isKindOfClass:[NSString class]])
76 searchItems.append(item);