Implementing a WebView database quota delegate

2020-07-18 10:34发布

How do I implement this method (see below)? I'm new to Objective-C and I'm just not getting it right.

From: http://lists.apple.com/archives/Webkitsdk-dev/2008/Apr/msg00027.html

By default databases have a quota of 0; this quota must be increased before any database will be stored on disk.

WebKit clients should implement the WebUIDelegate method - webView:frame:exceededDatabaseQuotaForSecurityOrigin:database: and increase the quota as desired when that method is called. This method is defined in WebUIDelegatePrivate.h. It was added too late in the previous release cycle to make it into a non-private header. It would be worthwhile to file a bug about moving this call to WebUIDelegate.h so that it is part of the official API.

John

4条回答
▲ chillily
2楼-- · 2020-07-18 10:48

Here's the final answer.

I was using the MiniBrowser sample app.

In MyDocument.m I added this function:

- (void)webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(id)origin database:(NSString *)databaseIdentifier
{
    static const unsigned long long defaultQuota = 5 * 1024 * 1024;
    if ([origin respondsToSelector: @selector(setQuota:)]) {
        [origin setQuota: defaultQuota];
    } else { 
        NSLog(@"could not increase quota for %@", defaultQuota); 
    }
} 
查看更多
该账号已被封号
3楼-- · 2020-07-18 10:51

Got some help from a discussion board:

There seems to be an implementation of this method included in WebKit's WebKitTools in their public SVN. (The class is named UIDelegate). http://trac.webkit.org/browser/trunk/WebKitTools/DumpRenderTree/mac/U...

I'm assuming you've created a delegate for your WebKit view. In that delegate class, create a method with the signature:

- (void)webView:(WebView *)sender frame:(WebFrame *)frame
exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin
database:(NSString *)databaseIdentifier;

You can probably use a modified version of UIDelegate's implementation:

- (void)webView:(WebView *)sender frame:(WebFrame *)frame
exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin
database:(NSString *)databaseIdentifier
{
    static const unsigned long long defaultQuota = 5 * 1024 * 1024;
    [origin setQuota:defaultQuota];
}

I haven't tried this, so YMMV.

Jon

查看更多
爷的心禁止访问
4楼-- · 2020-07-18 11:06

In whatever class you've defined as the delegate for your WebView you need to implement that method, something like this:

- (void)webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)databaseIdentifier {
    unsigned long long newQuotaBytes = 10 * 1024 * 1024;
    [origin setQuota:newQuotaBytes];

    // origin also responds to -usage method to return current size for all databases in this origin
}
查看更多
我想做一个坏孩纸
5楼-- · 2020-07-18 11:10

This worked for me: https://stackoverflow.com/a/8975014/146099 - it's a slight variation on Jeff's Answer.

查看更多
登录 后发表回答