Changeset 180585 in webkit


Ignore:
Timestamp:
Feb 24, 2015 2:40:30 PM (9 years ago)
Author:
andersca@apple.com
Message:

Pass _WKWebsiteDataRecord objects to the fetchData completion handler
https://bugs.webkit.org/show_bug.cgi?id=141984

Reviewed by Andreas Kling.

  • Shared/Cocoa/APIObject.mm:

(API::Object::newObject):
Create _WKWebsiteDataRecord objects for WebsiteDataRecord API objects.

  • UIProcess/API/APIWebsiteDataRecord.h:

Add WebsiteDataRecord getter.

  • UIProcess/API/Cocoa/_WKWebsiteDataRecord.h:

Add displayName and dataTypes properties.

  • UIProcess/API/Cocoa/_WKWebsiteDataRecord.mm:

(dataTypesToString):
Helper function to convert dataTypes bit-fields to strings.

(-[_WKWebsiteDataRecord description]):
Include the display name and data types in the description.

(-[_WKWebsiteDataRecord displayName]):
Return the display name.

(-[_WKWebsiteDataRecord dataTypes]):
Return the data types.

  • UIProcess/API/Cocoa/_WKWebsiteDataRecordInternal.h:

(WebKit::toWebsiteDataTypes):
Move this here from _WKWebsiteDataStore.mm.

(WebKit::toWKWebsiteDataTypes):
Add new function to convert WebsiteDataTypes to WKWebsiteDataTypes.

  • UIProcess/API/Cocoa/_WKWebsiteDataStore.mm:

(-[_WKWebsiteDataStore fetchDataRecordsOfTypes:completionHandler:]):
(-[_WKWebsiteDataStore removeDataOfTypes:modifiedSince:completionHandler:]):
Qualify toWebsiteDataTypes calls.

  • UIProcess/WebsiteData/WebsiteDataRecord.cpp: Added.

(WebKit::WebsiteDataRecord::displayNameForOrigin):
New helper that returns a display name given an origin.

(WebKit::WebsiteDataRecord::add):
Add the origin as well as the type.

  • UIProcess/WebsiteData/WebsiteDataRecord.h:

Add new members.

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::fetchData):
Loop through the entries and add them to the m_websiteDataRecords hash map, which
is keyed off of the display name. Pass the m_websiteDataRecords values to the completion handler.

  • WebKit2.xcodeproj/project.pbxproj:
Location:
trunk/Source/WebKit2
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r180579 r180585  
     12015-02-24  Anders Carlsson  <andersca@apple.com>
     2
     3        Pass _WKWebsiteDataRecord objects to the fetchData completion handler
     4        https://bugs.webkit.org/show_bug.cgi?id=141984
     5
     6        Reviewed by Andreas Kling.
     7
     8        * Shared/Cocoa/APIObject.mm:
     9        (API::Object::newObject):
     10        Create _WKWebsiteDataRecord objects for WebsiteDataRecord API objects.
     11
     12        * UIProcess/API/APIWebsiteDataRecord.h:
     13        Add WebsiteDataRecord getter.
     14
     15        * UIProcess/API/Cocoa/_WKWebsiteDataRecord.h:
     16        Add displayName and dataTypes properties.
     17
     18        * UIProcess/API/Cocoa/_WKWebsiteDataRecord.mm:
     19        (dataTypesToString):
     20        Helper function to convert dataTypes bit-fields to strings.
     21
     22        (-[_WKWebsiteDataRecord description]):
     23        Include the display name and data types in the description.
     24
     25        (-[_WKWebsiteDataRecord displayName]):
     26        Return the display name.
     27
     28        (-[_WKWebsiteDataRecord dataTypes]):
     29        Return the data types.
     30
     31        * UIProcess/API/Cocoa/_WKWebsiteDataRecordInternal.h:
     32        (WebKit::toWebsiteDataTypes):
     33        Move this here from _WKWebsiteDataStore.mm.
     34
     35        (WebKit::toWKWebsiteDataTypes):
     36        Add new function to convert WebsiteDataTypes to WKWebsiteDataTypes.
     37
     38        * UIProcess/API/Cocoa/_WKWebsiteDataStore.mm:
     39        (-[_WKWebsiteDataStore fetchDataRecordsOfTypes:completionHandler:]):
     40        (-[_WKWebsiteDataStore removeDataOfTypes:modifiedSince:completionHandler:]):
     41        Qualify toWebsiteDataTypes calls.
     42
     43        * UIProcess/WebsiteData/WebsiteDataRecord.cpp: Added.
     44        (WebKit::WebsiteDataRecord::displayNameForOrigin):
     45        New helper that returns a display name given an origin.
     46
     47        (WebKit::WebsiteDataRecord::add):
     48        Add the origin as well as the type.
     49
     50        * UIProcess/WebsiteData/WebsiteDataRecord.h:
     51        Add new members.
     52
     53        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     54        (WebKit::WebsiteDataStore::fetchData):
     55        Loop through the entries and add them to the m_websiteDataRecords hash map, which
     56        is keyed off of the display name. Pass the m_websiteDataRecords values to the completion handler.
     57
     58        * WebKit2.xcodeproj/project.pbxproj:
     59
    1602015-02-24  Csaba Osztrogonác  <ossy@webkit.org>
    261
  • trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm

    r180362 r180585  
    6262#import "_WKProcessPoolConfigurationInternal.h"
    6363#import "_WKVisitedLinkProviderInternal.h"
     64#import "_WKWebsiteDataRecordInternal.h"
    6465#import "_WKWebsiteDataStoreInternal.h"
    6566#import <objc/objc-auto.h>
     
    192193    case Type::VisitedLinkProvider:
    193194        wrapper = [_WKVisitedLinkProvider alloc];
     195        break;
     196
     197    case Type::WebsiteDataRecord:
     198        wrapper = [_WKWebsiteDataRecord alloc];
    194199        break;
    195200
  • trunk/Source/WebKit2/UIProcess/API/APIWebsiteDataRecord.h

    r180519 r180585  
    3737    virtual ~WebsiteDataRecord();
    3838
     39    const WebKit::WebsiteDataRecord& websiteDataRecord() const { return m_websiteDataRecord; }
     40
    3941private:
    4042    explicit WebsiteDataRecord(WebKit::WebsiteDataRecord&&);
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKWebsiteDataRecord.h

    r180513 r180585  
    4141WK_CLASS_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA)
    4242@interface _WKWebsiteDataRecord : NSObject
     43
     44@property (nonatomic, readonly, copy) NSString *displayName;
     45
     46@property (nonatomic, readonly) WKWebsiteDataTypes dataTypes;
    4347@end
    4448
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKWebsiteDataRecord.mm

    r180513 r180585  
    3838}
    3939
     40static NSString *dataTypesToString(WKWebsiteDataTypes dataTypes)
     41{
     42    auto array = adoptNS([[NSMutableArray alloc] init]);
     43
     44    if (dataTypes & WKWebsiteDataTypeCookies)
     45        [array addObject:@"Cookies"];
     46    if (dataTypes & WKWebsiteDataTypeDiskCache)
     47        [array addObject:@"Disk Cache"];
     48    if (dataTypes & WKWebsiteDataTypeMemoryCache)
     49        [array addObject:@"Memory Cache"];
     50    if (dataTypes & WKWebsiteDataTypeLocalStorage)
     51        [array addObject:@"Local Storage"];
     52
     53    return [array componentsJoinedByString:@", "];
     54}
     55
     56- (NSString *)description
     57{
     58    return [NSString stringWithFormat:@"<%@: %p; displayName = %@; dataTypes = { %@ }>", NSStringFromClass(self.class), self, self.displayName, dataTypesToString(self.dataTypes)];
     59}
     60
     61- (NSString *)displayName
     62{
     63    return _websiteDataRecord->websiteDataRecord().displayName;
     64}
     65
     66- (WKWebsiteDataTypes)dataTypes
     67{
     68    return WebKit::toWKWebsiteDataTypes(_websiteDataRecord->websiteDataRecord().types);
     69}
     70
    4071#pragma mark WKObject protocol implementation
    4172
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKWebsiteDataRecordInternal.h

    r180513 r180585  
    3939}
    4040
     41static inline WebKit::WebsiteDataTypes toWebsiteDataTypes(WKWebsiteDataTypes wkWebsiteDataTypes)
     42{
     43    using WebsiteDataTypes = WebKit::WebsiteDataTypes;
     44
     45    int websiteDataTypes = 0;
     46
     47    if (wkWebsiteDataTypes & WKWebsiteDataTypeCookies)
     48        websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeCookies;
     49    if (wkWebsiteDataTypes & WKWebsiteDataTypeDiskCache)
     50        websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeDiskCache;
     51    if (wkWebsiteDataTypes & WKWebsiteDataTypeMemoryCache)
     52        websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeMemoryCache;
     53    if (wkWebsiteDataTypes & WKWebsiteDataTypeLocalStorage)
     54        websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeLocalStorage;
     55
     56    return static_cast<WebsiteDataTypes>(websiteDataTypes);
     57}
     58
     59static inline WKWebsiteDataTypes toWKWebsiteDataTypes(int websiteDataTypes)
     60{
     61    using WebsiteDataTypes = WebKit::WebsiteDataTypes;
     62
     63    WKWebsiteDataTypes wkWebsiteDataTypes = 0;
     64
     65    if (websiteDataTypes & WebsiteDataTypes::WebsiteDataTypeCookies)
     66        wkWebsiteDataTypes |= WKWebsiteDataTypeCookies;
     67    if (websiteDataTypes & WebsiteDataTypes::WebsiteDataTypeDiskCache)
     68        wkWebsiteDataTypes |= WKWebsiteDataTypeDiskCache;
     69    if (websiteDataTypes & WebsiteDataTypes::WebsiteDataTypeMemoryCache)
     70        wkWebsiteDataTypes |= WKWebsiteDataTypeMemoryCache;
     71    if (websiteDataTypes & WebsiteDataTypes::WebsiteDataTypeLocalStorage)
     72        wkWebsiteDataTypes |= WKWebsiteDataTypeLocalStorage;
     73
     74    return wkWebsiteDataTypes;
     75}
     76
    4177}
    4278
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKWebsiteDataStore.mm

    r180519 r180585  
    3030
    3131#import "APIArray.h"
    32 #import "APIWebsiteDataRecord.h"
    3332#import "WKNSArray.h"
     33#import "_WKWebsiteDataRecordInternal.h"
    3434
    3535@implementation _WKWebsiteDataStore
     
    5757}
    5858
    59 static WebKit::WebsiteDataTypes toWebsiteDataTypes(WKWebsiteDataTypes wkWebsiteDataTypes)
    60 {
    61     using WebsiteDataTypes = WebKit::WebsiteDataTypes;
    62 
    63     int websiteDataTypes = 0;
    64 
    65     if (wkWebsiteDataTypes & WKWebsiteDataTypeCookies)
    66         websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeCookies;
    67     if (wkWebsiteDataTypes & WKWebsiteDataTypeDiskCache)
    68         websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeDiskCache;
    69     if (wkWebsiteDataTypes & WKWebsiteDataTypeMemoryCache)
    70         websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeMemoryCache;
    71     if (wkWebsiteDataTypes & WKWebsiteDataTypeLocalStorage)
    72         websiteDataTypes |= WebsiteDataTypes::WebsiteDataTypeLocalStorage;
    73 
    74     return static_cast<WebsiteDataTypes>(websiteDataTypes);
    75 }
    76 
    7759static std::chrono::system_clock::time_point toSystemClockTime(NSDate *date)
    7860{
     
    8769    auto completionHandlerCopy = Block_copy(completionHandler);
    8870
    89     _websiteDataStore->websiteDataStore().fetchData(toWebsiteDataTypes(websiteDataTypes), [completionHandlerCopy](Vector<WebKit::WebsiteDataRecord> websiteDataRecords) {
     71    _websiteDataStore->websiteDataStore().fetchData(WebKit::toWebsiteDataTypes(websiteDataTypes), [completionHandlerCopy](Vector<WebKit::WebsiteDataRecord> websiteDataRecords) {
    9072        Vector<RefPtr<API::Object>> elements;
    9173        elements.reserveInitialCapacity(websiteDataRecords.size());
     
    10385{
    10486    auto completionHandlerCopy = Block_copy(completionHandler);
    105     _websiteDataStore->websiteDataStore().removeData(toWebsiteDataTypes(websiteDataTypes), toSystemClockTime(date ? date : [NSDate distantPast]), [completionHandlerCopy] {
     87    _websiteDataStore->websiteDataStore().removeData(WebKit::toWebsiteDataTypes(websiteDataTypes), toSystemClockTime(date ? date : [NSDate distantPast]), [completionHandlerCopy] {
    10688        completionHandlerCopy();
    10789        Block_release(completionHandlerCopy);
  • trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataRecord.cpp

    r180579 r180585  
    2424 */
    2525
    26 #ifndef APIWebsiteDataRecord_h
    27 #define APIWebsiteDataRecord_h
    28 
    29 #include "APIObject.h"
     26#include "config.h"
    3027#include "WebsiteDataRecord.h"
    3128
    32 namespace API {
     29#include <WebCore/PublicSuffix.h>
     30#include <WebCore/SecurityOrigin.h>
    3331
    34 class WebsiteDataRecord final : public ObjectImpl<Object::Type::WebsiteDataRecord> {
    35 public:
    36     static Ref<WebsiteDataRecord> create(WebKit::WebsiteDataRecord&&);
    37     virtual ~WebsiteDataRecord();
     32namespace WebKit {
    3833
    39 private:
    40     explicit WebsiteDataRecord(WebKit::WebsiteDataRecord&&);
     34String WebsiteDataRecord::displayNameForOrigin(const WebCore::SecurityOrigin& securityOrigin)
     35{
     36    const auto& protocol = securityOrigin.protocol();
    4137
    42     const WebKit::WebsiteDataRecord m_websiteDataRecord;
    43 };
     38    if (protocol == "file") {
     39        // FIXME: Handle this. Return a localized display name.
     40        ASSERT_NOT_REACHED();
     41    }
     42
     43    if (protocol == "http" || protocol == "https")
     44        return WebCore::topPrivatelyControlledDomain(securityOrigin.host());
     45
     46    return String();
     47}
     48
     49void WebsiteDataRecord::add(WebsiteDataTypes type, RefPtr<WebCore::SecurityOrigin>&& origin)
     50{
     51    types |= type;
     52
     53    origins.add(WTF::move(origin));
     54}
    4455
    4556}
    46 
    47 #endif // APIWebsiteDataRecord_h
  • trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataRecord.h

    r180519 r180585  
    2727#define WebsiteDataRecord_h
    2828
     29#include "WebsiteDataTypes.h"
     30#include <WebCore/SecurityOriginHash.h>
     31#include <wtf/HashSet.h>
     32#include <wtf/text/WTFString.h>
     33
     34namespace WebCore {
     35class SecurityOrigin;
     36}
     37
    2938namespace WebKit {
    3039
    3140struct WebsiteDataRecord {
    32     // FIXME: Fill this in.
     41    static String displayNameForOrigin(const WebCore::SecurityOrigin&);
     42
     43    void add(WebsiteDataTypes, RefPtr<WebCore::SecurityOrigin>&&);
     44
     45    String displayName;
     46    unsigned types;
     47    HashSet<RefPtr<WebCore::SecurityOrigin>> origins;
    3348};
    3449
  • trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r180575 r180585  
    134134            --pendingCallbacks;
    135135
    136             // FIXME: Do something with the website data.
     136            for (auto& entry : websiteData.entries) {
     137                auto displayName = WebsiteDataRecord::displayNameForOrigin(*entry.origin);
     138                if (!displayName)
     139                    continue;
     140
     141                auto& record = m_websiteDataRecords.add(displayName, WebsiteDataRecord { }).iterator->value;
     142                if (!record.displayName)
     143                    record.displayName = WTF::move(displayName);
     144
     145                record.add(entry.type, WTF::move(entry.origin));
     146            }
     147
    137148            callIfNeeded();
    138149        }
     
    145156            RefPtr<CallbackAggregator> callbackAggregator(this);
    146157            RunLoop::main().dispatch([callbackAggregator] {
    147                 // FIXME: Pass data records to the completion handler.
    148                 callbackAggregator->completionHandler({ });
     158
     159                WTF::Vector<WebsiteDataRecord> records;
     160                records.reserveInitialCapacity(callbackAggregator->m_websiteDataRecords.size());
     161
     162                for (auto& record : callbackAggregator->m_websiteDataRecords.values())
     163                    records.uncheckedAppend(WTF::move(record));
     164
     165                callbackAggregator->completionHandler(WTF::move(records));
    149166            });
    150167        }
     
    152169        unsigned pendingCallbacks = 0;
    153170        std::function<void (Vector<WebsiteDataRecord>)> completionHandler;
     171
     172        HashMap<String, WebsiteDataRecord> m_websiteDataRecords;
    154173    };
    155174
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r180575 r180585  
    257257                1A4832D61A9CDF96008B4DFE /* WebsiteData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A4832D41A9CDF96008B4DFE /* WebsiteData.cpp */; };
    258258                1A4832D71A9CDF96008B4DFE /* WebsiteData.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A4832D51A9CDF96008B4DFE /* WebsiteData.h */; };
     259                1A4832D91A9D1FD2008B4DFE /* WebsiteDataRecord.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A4832D81A9D1FD2008B4DFE /* WebsiteDataRecord.cpp */; };
    259260                1A4A9C5512B816CF008FE984 /* NetscapePluginModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A4A9C5312B816CF008FE984 /* NetscapePluginModule.cpp */; };
    260261                1A4A9C5612B816CF008FE984 /* NetscapePluginModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A4A9C5412B816CF008FE984 /* NetscapePluginModule.h */; };
     
    23372338                1A4832D41A9CDF96008B4DFE /* WebsiteData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebsiteData.cpp; sourceTree = "<group>"; };
    23382339                1A4832D51A9CDF96008B4DFE /* WebsiteData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebsiteData.h; sourceTree = "<group>"; };
     2340                1A4832D81A9D1FD2008B4DFE /* WebsiteDataRecord.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebsiteDataRecord.cpp; sourceTree = "<group>"; };
    23392341                1A4A9C5312B816CF008FE984 /* NetscapePluginModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetscapePluginModule.cpp; sourceTree = "<group>"; };
    23402342                1A4A9C5412B816CF008FE984 /* NetscapePluginModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetscapePluginModule.h; sourceTree = "<group>"; };
     
    44824484                        children = (
    44834485                                1A4832C01A965A33008B4DFE /* Cocoa */,
     4486                                1A4832D81A9D1FD2008B4DFE /* WebsiteDataRecord.cpp */,
    44844487                                1A4832CF1A9BD821008B4DFE /* WebsiteDataRecord.h */,
    44854488                                1A53C2A41A32569F004E8C70 /* WebsiteDataStore.cpp */,
     
    98599862                                BC20528211C94284008F3375 /* WKBundlePage.cpp in Sources */,
    98609863                                7CF47FF617275B71008ACB91 /* WKBundlePageBanner.cpp in Sources */,
     9864                                1A4832D91A9D1FD2008B4DFE /* WebsiteDataRecord.cpp in Sources */,
    98619865                                7CF47FFE17276AE3008ACB91 /* WKBundlePageBannerMac.mm in Sources */,
    98629866                                BC7B633E12A45D1200D174A4 /* WKBundlePageGroup.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.