Home | History | Annotate | Download | only in appcache
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef WEBKIT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_
      6 #define WEBKIT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/files/file_path.h"
     13 #include "base/time/time.h"
     14 #include "url/gurl.h"
     15 #include "webkit/common/webkit_storage_common_export.h"
     16 
     17 namespace net {
     18 class URLRequest;
     19 }
     20 
     21 namespace appcache {
     22 
     23 // Defines constants, types, and abstract classes used in the main
     24 // process and in child processes.
     25 
     26 static const int kNoHostId = 0;
     27 static const int64 kNoCacheId = 0;
     28 static const int64 kNoResponseId = 0;
     29 static const int64 kUnknownCacheId = -1;
     30 
     31 enum Status {
     32   UNCACHED,
     33   IDLE,
     34   CHECKING,
     35   DOWNLOADING,
     36   UPDATE_READY,
     37   OBSOLETE
     38 };
     39 
     40 enum EventID {
     41   CHECKING_EVENT,
     42   ERROR_EVENT,
     43   NO_UPDATE_EVENT,
     44   DOWNLOADING_EVENT,
     45   PROGRESS_EVENT,
     46   UPDATE_READY_EVENT,
     47   CACHED_EVENT,
     48   OBSOLETE_EVENT
     49 };
     50 
     51 // Temporarily renumber them in wierd way, to help remove LOG_TIP from WebKit
     52 enum LogLevel {
     53   LOG_DEBUG = 4,
     54   LOG_INFO = 1,
     55   LOG_WARNING = 2,
     56   LOG_ERROR = 3,
     57 };
     58 
     59 enum NamespaceType {
     60   FALLBACK_NAMESPACE,
     61   INTERCEPT_NAMESPACE,
     62   NETWORK_NAMESPACE
     63 };
     64 
     65 struct WEBKIT_STORAGE_COMMON_EXPORT AppCacheInfo {
     66   AppCacheInfo();
     67   ~AppCacheInfo();
     68 
     69   GURL manifest_url;
     70   base::Time creation_time;
     71   base::Time last_update_time;
     72   base::Time last_access_time;
     73   int64 cache_id;
     74   int64 group_id;
     75   Status status;
     76   int64 size;
     77   bool is_complete;
     78 };
     79 
     80 typedef std::vector<AppCacheInfo> AppCacheInfoVector;
     81 
     82 // Type to hold information about a single appcache resource.
     83 struct WEBKIT_STORAGE_COMMON_EXPORT AppCacheResourceInfo {
     84   AppCacheResourceInfo();
     85   ~AppCacheResourceInfo();
     86 
     87   GURL url;
     88   int64 size;
     89   bool is_master;
     90   bool is_manifest;
     91   bool is_intercept;
     92   bool is_fallback;
     93   bool is_foreign;
     94   bool is_explicit;
     95   int64 response_id;
     96 };
     97 
     98 typedef std::vector<AppCacheResourceInfo> AppCacheResourceInfoVector;
     99 
    100 struct WEBKIT_STORAGE_COMMON_EXPORT Namespace {
    101   Namespace();  // Type is set to FALLBACK_NAMESPACE by default.
    102   Namespace(NamespaceType type, const GURL& url, const GURL& target,
    103             bool is_pattern);
    104   Namespace(NamespaceType type, const GURL& url, const GURL& target,
    105             bool is_pattern, bool is_executable);
    106   ~Namespace();
    107 
    108   bool IsMatch(const GURL& url) const;
    109 
    110   NamespaceType type;
    111   GURL namespace_url;
    112   GURL target_url;
    113   bool is_pattern;
    114   bool is_executable;
    115 };
    116 
    117 typedef std::vector<Namespace> NamespaceVector;
    118 
    119 // Interface used by backend (browser-process) to talk to frontend (renderer).
    120 class WEBKIT_STORAGE_COMMON_EXPORT AppCacheFrontend {
    121  public:
    122   virtual void OnCacheSelected(
    123       int host_id, const appcache::AppCacheInfo& info) = 0;
    124   virtual void OnStatusChanged(const std::vector<int>& host_ids,
    125                                Status status) = 0;
    126   virtual void OnEventRaised(const std::vector<int>& host_ids,
    127                              EventID event_id) = 0;
    128   virtual void OnProgressEventRaised(const std::vector<int>& host_ids,
    129                                      const GURL& url,
    130                                      int num_total, int num_complete) = 0;
    131   virtual void OnErrorEventRaised(const std::vector<int>& host_ids,
    132                                   const std::string& message) = 0;
    133   virtual void OnContentBlocked(int host_id,
    134                                 const GURL& manifest_url) = 0;
    135   virtual void OnLogMessage(int host_id, LogLevel log_level,
    136                             const std::string& message) = 0;
    137   virtual ~AppCacheFrontend() {}
    138 };
    139 
    140 // Interface used by frontend (renderer) to talk to backend (browser-process).
    141 class WEBKIT_STORAGE_COMMON_EXPORT AppCacheBackend {
    142  public:
    143   virtual void RegisterHost(int host_id) = 0;
    144   virtual void UnregisterHost(int host_id) = 0;
    145   virtual void SetSpawningHostId(int host_id, int spawning_host_id) = 0;
    146   virtual void SelectCache(int host_id,
    147                            const GURL& document_url,
    148                            const int64 cache_document_was_loaded_from,
    149                            const GURL& manifest_url) = 0;
    150   virtual void SelectCacheForWorker(
    151                            int host_id,
    152                            int parent_process_id,
    153                            int parent_host_id) = 0;
    154   virtual void SelectCacheForSharedWorker(
    155                            int host_id,
    156                            int64 appcache_id) = 0;
    157   virtual void MarkAsForeignEntry(int host_id, const GURL& document_url,
    158                                   int64 cache_document_was_loaded_from) = 0;
    159   virtual Status GetStatus(int host_id) = 0;
    160   virtual bool StartUpdate(int host_id) = 0;
    161   virtual bool SwapCache(int host_id) = 0;
    162   virtual void GetResourceList(
    163       int host_id, std::vector<AppCacheResourceInfo>* resource_infos) = 0;
    164 
    165  protected:
    166   virtual ~AppCacheBackend() {}
    167 };
    168 
    169 // Useful string constants.
    170 // Note: These are also defined elsewhere in the chrome code base in
    171 // url_contants.h .cc, however the appcache library doesn't not have
    172 // any dependencies on the chrome library, so we can't use them in here.
    173 WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpScheme[];
    174 WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpsScheme[];
    175 WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpGETMethod[];
    176 WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpHEADMethod[];
    177 
    178 // CommandLine flag to turn this experimental feature on.
    179 WEBKIT_STORAGE_COMMON_EXPORT extern const char kEnableExecutableHandlers[];
    180 
    181 WEBKIT_STORAGE_COMMON_EXPORT bool IsSchemeSupported(const GURL& url);
    182 WEBKIT_STORAGE_COMMON_EXPORT bool IsMethodSupported(const std::string& method);
    183 WEBKIT_STORAGE_COMMON_EXPORT bool IsSchemeAndMethodSupported(
    184     const net::URLRequest* request);
    185 
    186 WEBKIT_STORAGE_COMMON_EXPORT extern const base::FilePath::CharType
    187     kAppCacheDatabaseName[];
    188 
    189 }  // namespace
    190 
    191 #endif  // WEBKIT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_
    192