15267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/*
25267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Copyright (C) 2010 Google Inc. All rights reserved.
35267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
45267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * modification, are permitted provided that the following conditions are
65267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * met:
75267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
85267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *     * Redistributions of source code must retain the above copyright
95267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * notice, this list of conditions and the following disclaimer.
105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *     * Redistributions in binary form must reproduce the above
115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * in the documentation and/or other materials provided with the
135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * distribution.
145267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
155267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * contributors may be used to endorse or promote products derived from
165267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * this software without specific prior written permission.
175267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
185267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) */
305267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
315267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#ifndef WebApplicationCacheHost_h
325267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#define WebApplicationCacheHost_h
335267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
34d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "WebCommon.h"
35d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "WebURL.h"
36d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "WebVector.h"
375267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
3851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace blink {
395267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebApplicationCacheHostClient;
415267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebURL;
425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebURLRequest;
435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebURLResponse;
445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)struct WebURLError;
455267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)// This interface is used by webkit to call out to the embedder. Webkit uses
475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)// the WebFrameClient::createApplicationCacheHost method to create instances,
485267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)// and calls delete when the instance is no longer needed.
495267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebApplicationCacheHost {
505267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)public:
51c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    // These values must match blink::ApplicationCacheHost::Status values
525267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    enum Status {
535267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        Uncached,
545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        Idle,
555267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        Checking,
565267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        Downloading,
575267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        UpdateReady,
585267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        Obsolete
595267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    };
605267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
61c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    // These values must match blink::ApplicationCacheHost::EventID values
625267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    enum EventID {
635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        CheckingEvent,
645267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        ErrorEvent,
655267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        NoUpdateEvent,
665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        DownloadingEvent,
675267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        ProgressEvent,
685267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        UpdateReadyEvent,
695267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        CachedEvent,
705267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        ObsoleteEvent
715267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    };
725267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
7307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    enum ErrorReason {
7407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        ManifestError,
7507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        SignatureError,
7607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        ResourceError,
7707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        ChangedError,
7807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        AbortError,
7907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        QuotaError,
8007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        PolicyError,
8107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        UnknownError
8207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    };
8307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual ~WebApplicationCacheHost() { }
855267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
865267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called for every request made within the context.
8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual void willStartMainResourceRequest(WebURLRequest& r, const WebApplicationCacheHost* spawningHost) { }
885267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void willStartSubResourceRequest(WebURLRequest&) { }
895267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
905267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // One or the other selectCache methods is called after having parsed the <html> tag.
915267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // The latter returns false if the current document has been identified as a "foreign"
925267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // entry, in which case the frame navigation will be restarted by webkit.
935267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void selectCacheWithoutManifest() { }
945267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual bool selectCacheWithManifest(const WebURL& manifestURL) { return true; }
955267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
965267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called as the main resource is retrieved.
975267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didReceiveResponseForMainResource(const WebURLResponse&) { }
985267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didReceiveDataForMainResource(const char* data, int len) { }
995267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didFinishLoadingMainResource(bool success) { }
1005267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1015267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called on behalf of the scriptable interface.
1025267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual Status status() { return Uncached; }
1035267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual bool startUpdate() { return false; }
1045267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual bool swapCache() { return false; }
1055267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void abort() { }
1065267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1075267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Structures and methods to support inspecting Application Caches.
1085267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    struct CacheInfo {
1095267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        WebURL manifestURL; // Empty if there is no associated cache.
1105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        double creationTime;
1115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        double updateTime;
1125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        long long totalSize;
1135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        CacheInfo() : creationTime(0), updateTime(0), totalSize(0) { }
1145267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    };
1155267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    struct ResourceInfo {
1165267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        WebURL url;
1175267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        long long size;
1185267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        bool isMaster;
1195267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        bool isManifest;
1205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        bool isExplicit;
1215267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        bool isForeign;
1225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        bool isFallback;
1235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        ResourceInfo() : size(0), isMaster(false), isManifest(false), isExplicit(false), isForeign(false), isFallback(false) { }
1245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    };
1255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void getAssociatedCacheInfo(CacheInfo*) { }
1265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void getResourceList(WebVector<ResourceInfo>*) { }
1275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void deleteAssociatedCacheGroup() { }
1285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)};
1295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
130d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} // namespace blink
1315267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
132d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#endif // WebApplicationCacheHost_h
133