Changeset 170320 in webkit


Ignore:
Timestamp:
Jun 23, 2014 2:32:43 PM (10 years ago)
Author:
mitz@apple.com
Message:

[Cocoa] No way to grant storage quotas for web application cache
https://bugs.webkit.org/show_bug.cgi?id=134213

Reviewed by Anders Carlsson.

  • UIProcess/API/APIUIClient.h:

(API::UIClient::reachedApplicationCacheOriginQuota): Added this new client function, with
a default implementation that calls the completion handler with the current quota.

  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h: Declared a new delegate method.
  • UIProcess/API/Cocoa/_WKSecurityOrigin.mm:

(-[_WKSecurityOrigin _initWithSecurityOrigin:WebCore::]): Changed the parameter into a const
reference, since we copy it.

  • UIProcess/API/Cocoa/_WKSecurityOriginInternal.h:
  • UIProcess/Cocoa/UIDelegate.h: Override API::UIClient::reachedApplicationCacheOriginQuota.

Added flag to m_delegateMethods struct for new delegate method.

  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::setDelegate): Set new flag in m_delegateMethods struct.
(WebKit::UIDelegate::UIClient::exceededDatabaseQuota): Updated for change in
_WKSecurityOrigin initializer.
(WebKit::UIDelegate::UIClient::reachedApplicationCacheOriginQuota): Added. Calls the new
delegate method.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::reachedApplicationCacheOriginQuota): Added. Forwards the message to
the UI client.

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in: Added ReachedApplicationCacheOriginQuota message.
  • WebProcess/InjectedBundle/API/APIInjectedBundlePageUIClient.h:

(API::InjectedBundle::PageUIClient::didReachApplicationCacheOriginQuota): Changed the return
type to bool, indicating whether the client handled the callback.

  • WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp:

(WebKit::InjectedBundlePageUIClient::didReachApplicationCacheOriginQuota): Return the
appropriate value.

  • WebProcess/InjectedBundle/InjectedBundlePageUIClient.h:
  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::reachedApplicationCacheOriginQuota): If the bundle client didn’t
handle the callback, send a message the the UI process, and update the quota with the reply.

Location:
trunk/Source/WebKit2
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r170319 r170320  
     12014-06-23  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] No way to grant storage quotas for web application cache
     4        https://bugs.webkit.org/show_bug.cgi?id=134213
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * UIProcess/API/APIUIClient.h:
     9        (API::UIClient::reachedApplicationCacheOriginQuota): Added this new client function, with
     10        a default implementation that calls the completion handler with the current quota.
     11
     12        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: Declared a new delegate method.
     13
     14        * UIProcess/API/Cocoa/_WKSecurityOrigin.mm:
     15        (-[_WKSecurityOrigin _initWithSecurityOrigin:WebCore::]): Changed the parameter into a const
     16        reference, since we copy it.
     17        * UIProcess/API/Cocoa/_WKSecurityOriginInternal.h:
     18
     19        * UIProcess/Cocoa/UIDelegate.h: Override API::UIClient::reachedApplicationCacheOriginQuota.
     20        Added flag to m_delegateMethods struct for new delegate method.
     21        * UIProcess/Cocoa/UIDelegate.mm:
     22        (WebKit::UIDelegate::setDelegate): Set new flag in m_delegateMethods struct.
     23        (WebKit::UIDelegate::UIClient::exceededDatabaseQuota): Updated for change in
     24        _WKSecurityOrigin initializer.
     25        (WebKit::UIDelegate::UIClient::reachedApplicationCacheOriginQuota): Added. Calls the new
     26        delegate method.
     27
     28        * UIProcess/WebPageProxy.cpp:
     29        (WebKit::WebPageProxy::reachedApplicationCacheOriginQuota): Added. Forwards the message to
     30        the UI client.
     31        * UIProcess/WebPageProxy.h:
     32
     33        * UIProcess/WebPageProxy.messages.in: Added ReachedApplicationCacheOriginQuota message.
     34
     35        * WebProcess/InjectedBundle/API/APIInjectedBundlePageUIClient.h:
     36        (API::InjectedBundle::PageUIClient::didReachApplicationCacheOriginQuota): Changed the return
     37        type to bool, indicating whether the client handled the callback.
     38
     39        * WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp:
     40        (WebKit::InjectedBundlePageUIClient::didReachApplicationCacheOriginQuota): Return the
     41        appropriate value.
     42        * WebProcess/InjectedBundle/InjectedBundlePageUIClient.h:
     43
     44        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     45        (WebKit::WebChromeClient::reachedApplicationCacheOriginQuota): If the bundle client didn’t
     46        handle the callback, send a message the the UI process, and update the quota with the reply.
     47
    1482014-06-23  Tim Horton  <timothy_horton@apple.com>
    249
  • trunk/Source/WebKit2/UIProcess/API/APIUIClient.h

    r170303 r170320  
    116116    }
    117117
     118    virtual void reachedApplicationCacheOriginQuota(WebKit::WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, std::function<void (unsigned long long)> completionHandler)
     119    {
     120        completionHandler(currentQuota);
     121    }
     122
    118123    virtual bool runOpenPanel(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebKit::WebOpenPanelParameters*, WebKit::WebOpenPanelResultListenerProxy*) { return false; }
    119124    virtual bool decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, WebKit::WebSecurityOrigin*, WebKit::GeolocationPermissionRequestProxy*) { return false; }
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r170303 r170320  
    4040- (void)_webView:(WKWebView *)webView decideDatabaseQuotaForSecurityOrigin:(_WKSecurityOrigin *)securityOrigin currentQuota:(unsigned long long)currentQuota currentOriginUsage:(unsigned long long)currentOriginUsage currentDatabaseUsage:(unsigned long long)currentUsage expectedUsage:(unsigned long long)expectedUsage decisionHandler:(void (^)(unsigned long long newQuota))decisionHandler;
    4141
     42// FIXME: This should be handled by the WKWebsiteDataStore delegate.
     43- (void)_webView:(WKWebView *)webView decideWebApplicationCacheQuotaForSecurityOrigin:(_WKSecurityOrigin *)securityOrigin currentQuota:(unsigned long long)currentQuota totalBytesNeeded:(unsigned long long)totalBytesNeeded decisionHandler:(void (^)(unsigned long long newQuota))decisionHandler;
     44
    4245- (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame;
    4346
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSecurityOrigin.mm

    r170303 r170320  
    3636}
    3737
    38 - (instancetype)_initWithSecurityOrigin:(PassRefPtr<WebCore::SecurityOrigin>)origin
     38- (instancetype)_initWithSecurityOrigin:(const WebCore::SecurityOrigin&)origin
    3939{
    4040    if (!(self = [super init]))
    4141        return nil;
    4242
    43     if (!origin) {
    44         [self release];
    45         return nil;
    46     }
    47 
    48     _origin = origin->isolatedCopy();
     43    _origin = origin.isolatedCopy();
    4944    return self;
    5045}
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKSecurityOriginInternal.h

    r170303 r170320  
    3636@interface _WKSecurityOrigin ()
    3737
    38 - (instancetype)_initWithSecurityOrigin:(PassRefPtr<WebCore::SecurityOrigin>)origin;
     38- (instancetype)_initWithSecurityOrigin:(const WebCore::SecurityOrigin&)origin;
    3939
    4040@end
  • trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h

    r170303 r170320  
    6464        virtual void runJavaScriptPrompt(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy*, std::function<void (const WTF::String&)> completionHandler) override;
    6565        virtual void exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, WebSecurityOrigin*, const WTF::String& databaseName, const WTF::String& displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentUsage, unsigned long long expectedUsage, std::function<void (unsigned long long)>) override;
     66        virtual void reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, std::function<void (unsigned long long)> completionHandler) override;
    6667        virtual void printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy*) override;
    6768    #if PLATFORM(IOS)
     
    8384        bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
    8485        bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
     86        bool webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded : 1;
    8587        bool webViewPrintFrame : 1;
    8688#if PLATFORM(IOS)
  • trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm

    r170303 r170320  
    7070    m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)];
    7171    m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler = [delegate respondsToSelector:@selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:)];
     72    m_delegateMethods.webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded = [delegate respondsToSelector:@selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:)];
    7273    m_delegateMethods.webViewPrintFrame = [delegate respondsToSelector:@selector(_webView:printFrame:)];
    7374#if PLATFORM(IOS)
     
    188189
    189190    RefPtr<CompletionHandlerCallChecker> checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:));
    190     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideDatabaseQuotaForSecurityOrigin:adoptNS([[_WKSecurityOrigin alloc] _initWithSecurityOrigin:&securityOrigin->securityOrigin()]).get() currentQuota:currentQuota currentOriginUsage:currentOriginUsage currentDatabaseUsage:currentUsage expectedUsage:expectedUsage decisionHandler:[completionHandler, checker](unsigned long long newQuota) {
     191    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideDatabaseQuotaForSecurityOrigin:adoptNS([[_WKSecurityOrigin alloc] _initWithSecurityOrigin:securityOrigin->securityOrigin()]).get() currentQuota:currentQuota currentOriginUsage:currentOriginUsage currentDatabaseUsage:currentUsage expectedUsage:expectedUsage decisionHandler:[completionHandler, checker](unsigned long long newQuota) {
     192        checker->didCallCompletionHandler();
     193        completionHandler(newQuota);
     194    }];
     195}
     196
     197void UIDelegate::UIClient::reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin& securityOrigin, uint64_t currentQuota, uint64_t totalBytesNeeded, std::function<void (unsigned long long)> completionHandler)
     198{
     199    if (!m_uiDelegate.m_delegateMethods.webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded) {
     200        completionHandler(currentQuota);
     201        return;
     202    }
     203
     204    auto delegate = m_uiDelegate.m_delegate.get();
     205    if (!delegate) {
     206        completionHandler(currentQuota);
     207        return;
     208    }
     209
     210    RefPtr<CompletionHandlerCallChecker> checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:));
     211    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideWebApplicationCacheQuotaForSecurityOrigin:adoptNS([[_WKSecurityOrigin alloc] _initWithSecurityOrigin:securityOrigin]).get() currentQuota:currentQuota totalBytesNeeded:totalBytesNeeded decisionHandler:[completionHandler, checker](unsigned long long newQuota) {
    191212        checker->didCallCompletionHandler();
    192213        completionHandler(newQuota);
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r170319 r170320  
    44654465}
    44664466
     4467void WebPageProxy::reachedApplicationCacheOriginQuota(const String& originIdentifier, uint64_t currentQuota, uint64_t totalBytesNeeded, PassRefPtr<Messages::WebPageProxy::ReachedApplicationCacheOriginQuota::DelayedReply> reply)
     4468{
     4469    RefPtr<SecurityOrigin> securityOrigin = SecurityOrigin::createFromDatabaseIdentifier(originIdentifier);
     4470    MESSAGE_CHECK(securityOrigin);
     4471
     4472    m_uiClient->reachedApplicationCacheOriginQuota(this, *securityOrigin.get(), currentQuota, totalBytesNeeded, [reply](unsigned long long newQuota) { reply->send(newQuota); });
     4473}
     4474
    44674475void WebPageProxy::requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier)
    44684476{
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r170319 r170320  
    10021002    void printFrame(uint64_t frameID);
    10031003    void exceededDatabaseQuota(uint64_t frameID, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, PassRefPtr<Messages::WebPageProxy::ExceededDatabaseQuota::DelayedReply>);
     1004    void reachedApplicationCacheOriginQuota(const String& originIdentifier, uint64_t currentQuota, uint64_t totalBytesNeeded, PassRefPtr<Messages::WebPageProxy::ReachedApplicationCacheOriginQuota::DelayedReply>);
    10041005    void requestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier);
    10051006    void runModal();
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r169310 r170320  
    242242    ExceededDatabaseQuota(uint64_t frameID, String originIdentifier, String databaseName, String databaseDisplayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage) -> (uint64_t newQuota) Delayed
    243243
     244    # Application cache messages
     245    ReachedApplicationCacheOriginQuota(String originIdentifier, uint64_t currentQuota, uint64_t totalBytesNeeded) -> (uint64_t newQuota) Delayed
     246
    244247    # Geolocation messages
    245248    RequestGeolocationPermissionForFrame(uint64_t geolocationID, uint64_t frameID, String originIdentifier)
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/APIInjectedBundlePageUIClient.h

    r167514 r170320  
    7070    virtual UIElementVisibility toolbarsAreVisible(WebKit::WebPage*) { return UIElementVisibility::Unknown; }
    7171
    72     virtual void didReachApplicationCacheOriginQuota(WebKit::WebPage*, WebKit::WebSecurityOrigin*, int64_t totalBytesNeeded) { UNUSED_PARAM(totalBytesNeeded); }
     72    virtual bool didReachApplicationCacheOriginQuota(WebKit::WebPage*, WebKit::WebSecurityOrigin*, int64_t totalBytesNeeded) { UNUSED_PARAM(totalBytesNeeded); return false; }
    7373    virtual uint64_t didExceedDatabaseQuota(WebKit::WebPage*, WebKit::WebSecurityOrigin*, const WTF::String& databaseName, const WTF::String& databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes)
    7474    {
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp

    r167514 r170320  
    147147}
    148148
    149 void InjectedBundlePageUIClient::didReachApplicationCacheOriginQuota(WebPage* page, WebSecurityOrigin* origin, int64_t totalBytesNeeded)
     149bool InjectedBundlePageUIClient::didReachApplicationCacheOriginQuota(WebPage* page, WebSecurityOrigin* origin, int64_t totalBytesNeeded)
    150150{
    151151    if (!m_client.didReachApplicationCacheOriginQuota)
    152         return;
     152        return false;
    153153
    154154    m_client.didReachApplicationCacheOriginQuota(toAPI(page), toAPI(origin), totalBytesNeeded, m_client.base.clientInfo);
     155    return true;
    155156}
    156157
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.h

    r166890 r170320  
    6363    UIElementVisibility toolbarsAreVisible(WebPage*) override;
    6464
    65     void didReachApplicationCacheOriginQuota(WebPage*, WebSecurityOrigin*, int64_t totalBytesNeeded) override;
     65    bool didReachApplicationCacheOriginQuota(WebPage*, WebSecurityOrigin*, int64_t totalBytesNeeded) override;
    6666    uint64_t didExceedDatabaseQuota(WebPage*, WebSecurityOrigin*, const String& databaseName, const String& databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes) override;
    6767
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r170133 r170320  
    5050#include "WebSearchPopupMenu.h"
    5151#include "WebSecurityOrigin.h"
     52#include <WebCore/ApplicationCacheStorage.h>
    5253#include <WebCore/AXObjectCache.h>
    5354#include <WebCore/ColorChooser.h>
     
    675676{
    676677    RefPtr<WebSecurityOrigin> webSecurityOrigin = WebSecurityOrigin::createFromString(origin->toString());
    677     m_page->injectedBundleUIClient().didReachApplicationCacheOriginQuota(m_page, webSecurityOrigin.get(), totalBytesNeeded);
     678    if (m_page->injectedBundleUIClient().didReachApplicationCacheOriginQuota(m_page, webSecurityOrigin.get(), totalBytesNeeded))
     679        return;
     680
     681    unsigned syncSendFlags = IPC::InformPlatformProcessWillSuspend;
     682    if (WebPage::synchronousMessagesShouldSpinRunLoop())
     683        syncSendFlags |= IPC::SpinRunLoopWhileWaitingForReply;
     684
     685    int64_t currentQuota = 0;
     686    if (!cacheStorage().calculateQuotaForOrigin(origin, currentQuota))
     687        return;
     688
     689    uint64_t newQuota = 0;
     690    WebProcess::shared().parentProcessConnection()->sendSync(
     691        Messages::WebPageProxy::ReachedApplicationCacheOriginQuota(origin->databaseIdentifier(), currentQuota, totalBytesNeeded),
     692        Messages::WebPageProxy::ReachedApplicationCacheOriginQuota::Reply(newQuota), m_page->pageID(), std::chrono::milliseconds::max(), syncSendFlags);
     693
     694    cacheStorage().storeUpdatedQuotaForOrigin(origin, newQuota);
    678695}
    679696
Note: See TracChangeset for help on using the changeset viewer.