Home | History | Annotate | Download | only in common
      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 CONTENT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_
      6 #define CONTENT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/files/file_path.h"
     12 #include "content/public/common/appcache_info.h"
     13 
     14 namespace net {
     15 class URLRequest;
     16 }
     17 
     18 namespace content {
     19 
     20 // Defines constants, types, and abstract classes used in the main
     21 // process and in child processes.
     22 
     23 enum AppCacheEventID {
     24   APPCACHE_CHECKING_EVENT,
     25   APPCACHE_ERROR_EVENT,
     26   APPCACHE_NO_UPDATE_EVENT,
     27   APPCACHE_DOWNLOADING_EVENT,
     28   APPCACHE_PROGRESS_EVENT,
     29   APPCACHE_UPDATE_READY_EVENT,
     30   APPCACHE_CACHED_EVENT,
     31   APPCACHE_OBSOLETE_EVENT,
     32   APPCACHE_EVENT_ID_LAST = APPCACHE_OBSOLETE_EVENT
     33 };
     34 
     35 // Temporarily renumber them in wierd way, to help remove LOG_TIP from WebKit
     36 enum AppCacheLogLevel {
     37   APPCACHE_LOG_DEBUG = 4,
     38   APPCACHE_LOG_INFO = 1,
     39   APPCACHE_LOG_WARNING = 2,
     40   APPCACHE_LOG_ERROR = 3,
     41 };
     42 
     43 enum AppCacheNamespaceType {
     44   APPCACHE_FALLBACK_NAMESPACE,
     45   APPCACHE_INTERCEPT_NAMESPACE,
     46   APPCACHE_NETWORK_NAMESPACE
     47 };
     48 
     49 enum AppCacheErrorReason {
     50   APPCACHE_MANIFEST_ERROR,
     51   APPCACHE_SIGNATURE_ERROR,
     52   APPCACHE_RESOURCE_ERROR,
     53   APPCACHE_CHANGED_ERROR,
     54   APPCACHE_ABORT_ERROR,
     55   APPCACHE_QUOTA_ERROR,
     56   APPCACHE_POLICY_ERROR,
     57   APPCACHE_UNKNOWN_ERROR,
     58   APPCACHE_ERROR_REASON_LAST = APPCACHE_UNKNOWN_ERROR
     59 };
     60 
     61 // Type to hold information about a single appcache resource.
     62 struct CONTENT_EXPORT AppCacheResourceInfo {
     63   AppCacheResourceInfo();
     64   ~AppCacheResourceInfo();
     65 
     66   GURL url;
     67   int64 size;
     68   bool is_master;
     69   bool is_manifest;
     70   bool is_intercept;
     71   bool is_fallback;
     72   bool is_foreign;
     73   bool is_explicit;
     74   int64 response_id;
     75 };
     76 
     77 struct CONTENT_EXPORT AppCacheErrorDetails {
     78   AppCacheErrorDetails();
     79   AppCacheErrorDetails(std::string message,
     80                AppCacheErrorReason reason,
     81                GURL url,
     82                int status,
     83                bool is_cross_origin);
     84   ~AppCacheErrorDetails();
     85 
     86   std::string message;
     87   AppCacheErrorReason reason;
     88   GURL url;
     89   int status;
     90   bool is_cross_origin;
     91 };
     92 
     93 typedef std::vector<AppCacheResourceInfo> AppCacheResourceInfoVector;
     94 
     95 struct CONTENT_EXPORT AppCacheNamespace {
     96   AppCacheNamespace();  // Type is APPCACHE_FALLBACK_NAMESPACE by default.
     97   AppCacheNamespace(AppCacheNamespaceType type, const GURL& url,
     98       const GURL& target, bool is_pattern);
     99   AppCacheNamespace(AppCacheNamespaceType type, const GURL& url,
    100       const GURL& target, bool is_pattern, bool is_executable);
    101   ~AppCacheNamespace();
    102 
    103   bool IsMatch(const GURL& url) const;
    104 
    105   AppCacheNamespaceType type;
    106   GURL namespace_url;
    107   GURL target_url;
    108   bool is_pattern;
    109   bool is_executable;
    110 };
    111 
    112 typedef std::vector<AppCacheNamespace> AppCacheNamespaceVector;
    113 
    114 // Interface used by backend (browser-process) to talk to frontend (renderer).
    115 class CONTENT_EXPORT AppCacheFrontend {
    116  public:
    117   virtual void OnCacheSelected(
    118       int host_id, const AppCacheInfo& info) = 0;
    119   virtual void OnStatusChanged(const std::vector<int>& host_ids,
    120                                AppCacheStatus status) = 0;
    121   virtual void OnEventRaised(const std::vector<int>& host_ids,
    122                              AppCacheEventID event_id) = 0;
    123   virtual void OnProgressEventRaised(const std::vector<int>& host_ids,
    124                                      const GURL& url,
    125                                      int num_total, int num_complete) = 0;
    126   virtual void OnErrorEventRaised(
    127       const std::vector<int>& host_ids,
    128       const AppCacheErrorDetails& details) = 0;
    129   virtual void OnContentBlocked(int host_id,
    130                                 const GURL& manifest_url) = 0;
    131   virtual void OnLogMessage(int host_id, AppCacheLogLevel log_level,
    132                             const std::string& message) = 0;
    133   virtual ~AppCacheFrontend() {}
    134 };
    135 
    136 // Interface used by frontend (renderer) to talk to backend (browser-process).
    137 class CONTENT_EXPORT AppCacheBackend {
    138  public:
    139   virtual void RegisterHost(int host_id) = 0;
    140   virtual void UnregisterHost(int host_id) = 0;
    141   virtual void SetSpawningHostId(int host_id, int spawning_host_id) = 0;
    142   virtual void SelectCache(int host_id,
    143                            const GURL& document_url,
    144                            const int64 cache_document_was_loaded_from,
    145                            const GURL& manifest_url) = 0;
    146   virtual void SelectCacheForWorker(
    147                            int host_id,
    148                            int parent_process_id,
    149                            int parent_host_id) = 0;
    150   virtual void SelectCacheForSharedWorker(
    151                            int host_id,
    152                            int64 appcache_id) = 0;
    153   virtual void MarkAsForeignEntry(int host_id, const GURL& document_url,
    154                                   int64 cache_document_was_loaded_from) = 0;
    155   virtual AppCacheStatus GetStatus(int host_id) = 0;
    156   virtual bool StartUpdate(int host_id) = 0;
    157   virtual bool SwapCache(int host_id) = 0;
    158   virtual void GetResourceList(
    159       int host_id, std::vector<AppCacheResourceInfo>* resource_infos) = 0;
    160 
    161  protected:
    162   virtual ~AppCacheBackend() {}
    163 };
    164 
    165 // Useful string constants.
    166 // Note: These are also defined elsewhere in the chrome code base in
    167 // url_contants.h .cc, however the content library can not have
    168 // any dependencies on the chrome library, so we can't use them in here.
    169 CONTENT_EXPORT extern const char kHttpScheme[];
    170 CONTENT_EXPORT extern const char kHttpsScheme[];
    171 CONTENT_EXPORT extern const char kHttpGETMethod[];
    172 CONTENT_EXPORT extern const char kHttpHEADMethod[];
    173 
    174 // CommandLine flag to turn this experimental feature on.
    175 CONTENT_EXPORT extern const char kEnableExecutableHandlers[];
    176 
    177 CONTENT_EXPORT bool IsSchemeSupportedForAppCache(const GURL& url);
    178 CONTENT_EXPORT bool IsMethodSupportedForAppCache(
    179     const std::string& method);
    180 CONTENT_EXPORT bool IsSchemeAndMethodSupportedForAppCache(
    181     const net::URLRequest* request);
    182 
    183 CONTENT_EXPORT extern const base::FilePath::CharType
    184     kAppCacheDatabaseName[];
    185 
    186 }  // namespace
    187 
    188 #endif  // CONTENT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_
    189