Title: [193961] branches/safari-601-branch/Source

Diff

Modified: branches/safari-601-branch/Source/WebCore/ChangeLog (193960 => 193961)


--- branches/safari-601-branch/Source/WebCore/ChangeLog	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebCore/ChangeLog	2015-12-11 18:26:18 UTC (rev 193961)
@@ -1,5 +1,40 @@
 2015-12-11  Matthew Hanson  <[email protected]>
 
+        Merge r191628. rdar://problem/23715623
+
+    2015-10-27  Zhuo Li  <[email protected]>
+
+            Add WebKit API to clear data type Search Field Recent Searches.
+            https://bugs.webkit.org/show_bug.cgi?id=150019.
+
+            Reviewed by Anders Carlsson.
+
+            * platform/cocoa/SearchPopupMenuCocoa.h: Add a function to remove recent searches based on
+            time.
+            * platform/cocoa/SearchPopupMenuCocoa.mm:
+            (WebCore::typeCheckedRecentSearchesArray): Return nil if the recent searches array is
+            corrupted, otherwise return the array.
+            (WebCore::typeCheckedDateInRecentSearch): Return nil if the date in recent search is
+            corrupted, otherwise return the date.
+            (WebCore::typeCheckedRecentSearchesRemovingRecentSearchesAddedAfterDate): Return nil if the recent searches plist is
+            corrupted, otherwise return the recent searches plist.
+            (WebCore::writeEmptyRecentSearchesPlist): Replace the existing recent searches plist if there is
+            any with a clean one.
+            (WebCore::loadRecentSearches): Use -typeCheckedRecentSearchesArray and -typeCheckedDateInRecentSearch.
+            (WebCore::removeRecentlyModifiedRecentSearches):
+            When the time passed in is equivalent to [NSDate distantPast], clear all recent searches in
+            the Recent Searches plist. Otherwise, we only clear the recent searches that were created
+            after or at the time that is passed in as the parameter. If all recent searches associated
+            with an autosave name were created after or at the time that is passed in as the parameter,
+            remove this autosave name key and all of its values in the plist. If all recent searches
+            associated with every autosave name in the plist were created after or at the time that is
+            passed in as the parameter, clear all recent searches in the Recent Searches plist.
+
+            Also, we clear all recent searches in the Recent Searches plist when we find the plist is
+            corrupted.
+
+2015-12-11  Matthew Hanson  <[email protected]>
+
         Merge r191084. rdar://problem/23715623
 
     2015-10-14  Zhuo Li  <[email protected]>

Modified: branches/safari-601-branch/Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.h (193960 => 193961)


--- branches/safari-601-branch/Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.h	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.h	2015-12-11 18:26:18 UTC (rev 193961)
@@ -32,6 +32,7 @@
 
 WEBCORE_EXPORT void saveRecentSearches(const String& name, const Vector<RecentSearch>&);
 WEBCORE_EXPORT Vector<RecentSearch> loadRecentSearches(const String& name);
+WEBCORE_EXPORT void removeRecentlyModifiedRecentSearches(std::chrono::system_clock::time_point);
 
 }
 

Modified: branches/safari-601-branch/Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.mm (193960 => 193961)


--- branches/safari-601-branch/Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.mm	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.mm	2015-12-11 18:26:18 UTC (rev 193961)
@@ -66,6 +66,79 @@
     return [NSDate dateWithTimeIntervalSince1970:duration_cast<duration<double>>(time.time_since_epoch()).count()];
 }
 
+static NSMutableArray *typeCheckedRecentSearchesArray(NSMutableDictionary *itemsDictionary, NSString *name)
+{
+    NSMutableDictionary *nameDictionary = [itemsDictionary objectForKey:name];
+    if (![nameDictionary isKindOfClass:[NSDictionary class]])
+        return nil;
+
+    NSMutableArray *recentSearches = [nameDictionary objectForKey:searchesKey];
+    if (![recentSearches isKindOfClass:[NSArray class]])
+        return nil;
+
+    return recentSearches;
+}
+
+static NSDate *typeCheckedDateInRecentSearch(NSDictionary *recentSearch)
+{
+    if (![recentSearch isKindOfClass:[NSDictionary class]])
+        return nil;
+
+    NSDate *date = [recentSearch objectForKey:dateKey];
+    if (![date isKindOfClass:[NSDate class]])
+        return nil;
+
+    return date;
+}
+
+static RetainPtr<NSDictionary> typeCheckedRecentSearchesRemovingRecentSearchesAddedAfterDate(NSDate *date)
+{
+    if ([date isEqualToDate:[NSDate distantPast]])
+        return nil;
+
+    RetainPtr<NSMutableDictionary> recentSearchesPlist = readSearchFieldRecentSearchesPlist();
+    NSMutableDictionary *itemsDictionary = [recentSearchesPlist objectForKey:itemsKey];
+    if (![itemsDictionary isKindOfClass:[NSDictionary class]])
+        return nil;
+
+    RetainPtr<NSMutableArray> keysToRemove = adoptNS([[NSMutableArray alloc] init]);
+    for (NSString *key in itemsDictionary) {
+        if (![key isKindOfClass:[NSString class]])
+            return nil;
+
+        NSMutableArray *recentSearches = typeCheckedRecentSearchesArray(itemsDictionary, key);
+        if (!recentSearches)
+            return nil;
+
+        RetainPtr<NSMutableArray> entriesToRemove = adoptNS([[NSMutableArray alloc] init]);
+        for (NSDictionary *recentSearch in recentSearches) {
+            NSDate *date = typeCheckedDateInRecentSearch(recentSearch);
+            if (!date)
+                return nil;
+
+            if ([date compare:date] == NSOrderedDescending)
+                [entriesToRemove addObject:recentSearch];
+        }
+
+        [recentSearches removeObjectsInArray:entriesToRemove.get()];
+        if (!recentSearches.count)
+            [keysToRemove addObject:key];
+    }
+
+    [itemsDictionary removeObjectsForKeys:keysToRemove.get()];
+    if (!itemsDictionary.count)
+        return nil;
+
+    return recentSearchesPlist;
+}
+
+static void writeEmptyRecentSearchesPlist()
+{
+    auto emptyItemsDictionary = adoptNS([[NSDictionary alloc] init]);
+    auto emptyRecentSearchesDictionary = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:emptyItemsDictionary.get(), itemsKey, nil]);
+    [emptyRecentSearchesDictionary writeToFile:searchFieldRecentSearchesPlistPath() atomically:YES];
+}
+
 void saveRecentSearches(const String& name, const Vector<RecentSearch>& searchItems)
 {
     if (name.isEmpty())
@@ -90,7 +163,7 @@
         [itemsDictionary setObject:adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:items.get(), searchesKey, nil]).get() forKey:name];
     }
 
-    [recentSearchesPlist writeToFile:searchFieldRecentSearchesPlistPath() atomically:NO];
+    [recentSearchesPlist writeToFile:searchFieldRecentSearchesPlistPath() atomically:YES];
 }
 
 Vector<RecentSearch> loadRecentSearches(const String& name)
@@ -104,34 +177,37 @@
     if (!recentSearchesPlist)
         return searchItems;
 
-    NSDictionary *items = [recentSearchesPlist objectForKey:itemsKey];
+    NSMutableDictionary *items = [recentSearchesPlist objectForKey:itemsKey];
     if (![items isKindOfClass:[NSDictionary class]])
         return searchItems;
 
-    NSDictionary *nameItems = [items objectForKey:name];
-    if (![nameItems isKindOfClass:[NSDictionary class]])
+    NSArray *recentSearches = typeCheckedRecentSearchesArray(items, name);
+    if (!recentSearches)
         return searchItems;
-
-    NSArray *recentSearches = [nameItems objectForKey:searchesKey];
-    if (![recentSearches isKindOfClass:[NSArray class]])
-        return searchItems;
     
     for (NSDictionary *item in recentSearches) {
-        if (![item isKindOfClass:[NSDictionary class]])
+        NSDate *date = typeCheckedDateInRecentSearch(item);
+        if (!date)
             continue;
-        
+
         NSString *searchString = [item objectForKey:searchStringKey];
         if (![searchString isKindOfClass:[NSString class]])
             continue;
         
-        NSDate *date = [item objectForKey:dateKey];
-        if (![date isKindOfClass:[NSDate class]])
-            continue;
-        
         searchItems.append({ String{ searchString }, toSystemClockTime(date) });
     }
 
     return searchItems;
 }
 
+void removeRecentlyModifiedRecentSearches(std::chrono::system_clock::time_point oldestTimeToRemove)
+{
+    NSDate *date = toNSDateFromSystemClock(oldestTimeToRemove);
+    auto recentSearchesPlist = typeCheckedRecentSearchesRemovingRecentSearchesAddedAfterDate(date);
+    if (recentSearchesPlist)
+        [recentSearchesPlist writeToFile:searchFieldRecentSearchesPlistPath() atomically:YES];
+    else
+        writeEmptyRecentSearchesPlist();
 }
+
+}

Modified: branches/safari-601-branch/Source/WebKit2/ChangeLog (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/ChangeLog	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/ChangeLog	2015-12-11 18:26:18 UTC (rev 193961)
@@ -1,5 +1,36 @@
 2015-12-11  Matthew Hanson  <[email protected]>
 
+        Merge r191628. rdar://problem/23715623
+
+    2015-10-27  Zhuo Li  <[email protected]>
+
+            Add WebKit API to clear data type Search Field Recent Searches.
+            https://bugs.webkit.org/show_bug.cgi?id=150019.
+
+            Reviewed by Anders Carlsson.
+
+            * Shared/WebsiteData/WebsiteDataTypes.h: Add data type Search Field Recent Searches.
+            * UIProcess/API/Cocoa/WKWebsiteDataRecord.mm:
+            (dataTypesToString): Ditto.
+            * UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h:
+            (WebKit::toWebsiteDataTypes): Ditto.
+            (WebKit::toWKWebsiteDataTypes): Ditto.
+            * UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h: Ditto.
+            * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+            (WebKit::WebsiteDataStore::removeData): Handle the case when data type is Search
+            Field Recent Searches.
+            * UIProcess/WebsiteData/WebsiteDataStore.h: Add a private function for removing
+            recent searches based on time.
+            * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+            (WebKit::WebsiteDataStoreCocoa::platformRemoveRecentSearches): Call the removing
+            recent searches logic in WebCore.
+            * UIProcess/efl/WebPageProxyEfl.cpp:
+            (WebKit::WebsiteDataStore::platformRemoveRecentSearches): Not implemented.
+            * UIProcess/gtk/WebPageProxyGtk.cpp:
+            (WebKit::WebsiteDataStore::platformRemoveRecentSearches): Not implemented.
+
+2015-12-11  Matthew Hanson  <[email protected]>
+
         Merge r191084. rdar://problem/23715623
 
     2015-10-14  Zhuo Li  <[email protected]>

Modified: branches/safari-601-branch/Source/WebKit2/Shared/WebsiteData/WebsiteDataTypes.h (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/Shared/WebsiteData/WebsiteDataTypes.h	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/Shared/WebsiteData/WebsiteDataTypes.h	2015-12-11 18:26:18 UTC (rev 193961)
@@ -39,8 +39,9 @@
     WebsiteDataTypeIndexedDBDatabases = 1 << 7,
     WebsiteDataTypeMediaKeys = 1 << 8,
     WebsiteDataTypeHSTSCache = 1 << 9,
+    WebsiteDataTypeSearchFieldRecentSearches = 1 << 10,
 #if ENABLE(NETSCAPE_PLUGIN_API)
-    WebsiteDataTypePlugInData = 1 << 10,
+    WebsiteDataTypePlugInData = 1 << 11,
 #endif
 };
 

Modified: branches/safari-601-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecord.mm (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecord.mm	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecord.mm	2015-12-11 18:26:18 UTC (rev 193961)
@@ -41,6 +41,7 @@
 
 NSString * const _WKWebsiteDataTypeMediaKeys = @"_WKWebsiteDataTypeMediaKeys";
 NSString * const _WKWebsiteDataTypeHSTSCache = @"_WKWebsiteDataTypeHSTSCache";
+NSString * const _WKWebsiteDataTypeSearchFieldRecentSearches = @"_WKWebsiteDataTypeSearchFieldRecentSearches";
 
 #if PLATFORM(MAC)
 NSString * const _WKWebsiteDataTypePlugInData = @"_WKWebsiteDataTypePlugInData";
@@ -79,6 +80,8 @@
         [array addObject:@"HSTS Cache"];
     if ([dataTypes containsObject:_WKWebsiteDataTypeMediaKeys])
         [array addObject:@"Media Keys"];
+    if ([dataTypes containsObject:_WKWebsiteDataTypeSearchFieldRecentSearches])
+        [array addObject:@"Search Field Recent Searches"];
 #if PLATFORM(MAC)
     if ([dataTypes containsObject:_WKWebsiteDataTypePlugInData])
         [array addObject:@"Plug-in Data"];

Modified: branches/safari-601-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecordInternal.h	2015-12-11 18:26:18 UTC (rev 193961)
@@ -64,6 +64,8 @@
         websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeHSTSCache;
     if ([wkWebsiteDataTypes containsObject:_WKWebsiteDataTypeMediaKeys])
         websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeMediaKeys;
+    if ([wkWebsiteDataTypes containsObject:_WKWebsiteDataTypeSearchFieldRecentSearches])
+        websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeSearchFieldRecentSearches;
 #if ENABLE(NETSCAPE_PLUGIN_API)
     if ([wkWebsiteDataTypes containsObject:_WKWebsiteDataTypePlugInData])
         websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypePlugInData;
@@ -97,6 +99,8 @@
         [wkWebsiteDataTypes addObject:_WKWebsiteDataTypeHSTSCache];
     if (websiteDataTypes & WebsiteDataTypes::WebsiteDataTypeMediaKeys)
         [wkWebsiteDataTypes addObject:_WKWebsiteDataTypeMediaKeys];
+    if (websiteDataTypes & WebsiteDataTypes::WebsiteDataTypeSearchFieldRecentSearches)
+        [wkWebsiteDataTypes addObject:_WKWebsiteDataTypeSearchFieldRecentSearches];
 #if ENABLE(NETSCAPE_PLUGIN_API)
     if (websiteDataTypes & WebsiteDataTypes::WebsiteDataTypePlugInData)
         [wkWebsiteDataTypes addObject:_WKWebsiteDataTypePlugInData];

Modified: branches/safari-601-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h	2015-12-11 18:26:18 UTC (rev 193961)
@@ -29,6 +29,7 @@
 
 WK_EXTERN NSString * const _WKWebsiteDataTypeHSTSCache WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 WK_EXTERN NSString * const _WKWebsiteDataTypeMediaKeys WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+WK_EXTERN NSString * const _WKWebsiteDataTypeSearchFieldRecentSearches WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 
 #if !TARGET_OS_IPHONE
 WK_EXTERN NSString * const _WKWebsiteDataTypePlugInData WK_AVAILABLE(WK_MAC_TBA, NA);

Modified: branches/safari-601-branch/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm	2015-12-11 18:26:18 UTC (rev 193961)
@@ -27,6 +27,7 @@
 #import "WebsiteDataStore.h"
 
 #import "StorageManager.h"
+#import <WebCore/SearchPopupMenuCocoa.h>
 #import <wtf/NeverDestroyed.h>
 
 #if PLATFORM(IOS)
@@ -84,4 +85,9 @@
     }
 }
 
+void WebsiteDataStore::platformRemoveRecentSearches(std::chrono::system_clock::time_point oldestTimeToRemove)
+{
+    WebCore::removeRecentlyModifiedRecentSearches(oldestTimeToRemove);
 }
+
+}

Modified: branches/safari-601-branch/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp	2015-12-11 18:26:18 UTC (rev 193961)
@@ -632,6 +632,18 @@
         });
     }
 
+    if (dataTypes & WebsiteDataTypeSearchFieldRecentSearches && isPersistent()) {
+        callbackAggregator->addPendingCallback();
+
+        m_queue->dispatch([modifiedSince, callbackAggregator] {
+            platformRemoveRecentSearches(modifiedSince);
+
+            RunLoop::main().dispatch([callbackAggregator] {
+                callbackAggregator->removePendingCallback();
+            });
+        });
+    }
+
 #if ENABLE(NETSCAPE_PLUGIN_API)
     if (dataTypes & WebsiteDataTypePlugInData && isPersistent()) {
         class State {

Modified: branches/safari-601-branch/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h	2015-12-11 18:26:18 UTC (rev 193961)
@@ -93,6 +93,7 @@
 
     void platformInitialize();
     void platformDestroy();
+    static void platformRemoveRecentSearches(std::chrono::system_clock::time_point);
 
     HashSet<RefPtr<WebProcessPool>> processPools() const;
 

Modified: branches/safari-601-branch/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp	2015-12-11 18:26:18 UTC (rev 193961)
@@ -33,6 +33,7 @@
 #include "WebPageMessages.h"
 #include "WebProcessProxy.h"
 #include "WebView.h"
+#include "WebsiteDataStore.h"
 
 #include <sys/utsname.h>
 
@@ -83,6 +84,11 @@
     notImplemented();
 }
 
+void WebsiteDataStore::platformRemoveRecentSearches(std::chrono::system_clock::time_point oldestTimeToRemove)
+{
+    notImplemented();
+}
+
 void WebPageProxy::editorStateChanged(const EditorState& editorState)
 {
     m_editorState = editorState;

Modified: branches/safari-601-branch/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp (193960 => 193961)


--- branches/safari-601-branch/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp	2015-12-11 18:26:12 UTC (rev 193960)
+++ branches/safari-601-branch/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp	2015-12-11 18:26:18 UTC (rev 193961)
@@ -32,6 +32,7 @@
 #include "WebKitWebViewBasePrivate.h"
 #include "WebPageMessages.h"
 #include "WebProcessProxy.h"
+#include "WebsiteDataStore.h"
 #include <WebCore/UserAgentGtk.h>
 #include <gtk/gtkx.h>
 #include <wtf/NeverDestroyed.h>
@@ -67,6 +68,11 @@
     notImplemented();
 }
 
+void WebsiteDataStore::platformRemoveRecentSearches(std::chrono::system_clock::time_point oldestTimeToRemove)
+{
+    notImplemented();
+}
+
 void WebPageProxy::editorStateChanged(const EditorState& editorState)
 {
     m_editorState = editorState;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to