1 // Copyright 2013 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_CHILD_APPCACHE_WEB_APPLICATION_CACHE_HOST_IMPL_H_ 6 #define CONTENT_CHILD_APPCACHE_WEB_APPLICATION_CACHE_HOST_IMPL_H_ 7 8 #include <string> 9 10 #include "third_party/WebKit/public/platform/WebURLResponse.h" 11 #include "third_party/WebKit/public/platform/WebVector.h" 12 #include "third_party/WebKit/public/web/WebApplicationCacheHostClient.h" 13 #include "url/gurl.h" 14 #include "webkit/common/appcache/appcache_interfaces.h" 15 16 namespace blink { 17 class WebFrame; 18 } 19 20 namespace content { 21 22 class WebApplicationCacheHostImpl NON_EXPORTED_BASE(public blink::WebApplicationCacheHost)23 : NON_EXPORTED_BASE(public blink::WebApplicationCacheHost) { 24 public: 25 // Returns the host having given id or NULL if there is no such host. 26 static WebApplicationCacheHostImpl* FromId(int id); 27 28 // Returns the host associated with the current document in frame. 29 static WebApplicationCacheHostImpl* FromFrame(const blink::WebFrame* frame); 30 31 WebApplicationCacheHostImpl(blink::WebApplicationCacheHostClient* client, 32 appcache::AppCacheBackend* backend); 33 virtual ~WebApplicationCacheHostImpl(); 34 35 int host_id() const { return host_id_; } 36 appcache::AppCacheBackend* backend() const { return backend_; } 37 blink::WebApplicationCacheHostClient* client() const { return client_; } 38 39 virtual void OnCacheSelected(const appcache::AppCacheInfo& info); 40 void OnStatusChanged(appcache::Status); 41 void OnEventRaised(appcache::EventID); 42 void OnProgressEventRaised(const GURL& url, int num_total, int num_complete); 43 void OnErrorEventRaised(const std::string& message); 44 virtual void OnLogMessage(appcache::LogLevel log_level, 45 const std::string& message) {} 46 virtual void OnContentBlocked(const GURL& manifest_url) {} 47 48 // blink::WebApplicationCacheHost: 49 virtual void willStartMainResourceRequest(blink::WebURLRequest&, 50 const blink::WebFrame*); 51 virtual void willStartSubResourceRequest(blink::WebURLRequest&); 52 virtual void selectCacheWithoutManifest(); 53 virtual bool selectCacheWithManifest(const blink::WebURL& manifestURL); 54 virtual void didReceiveResponseForMainResource(const blink::WebURLResponse&); 55 virtual void didReceiveDataForMainResource(const char* data, int len); 56 virtual void didFinishLoadingMainResource(bool success); 57 virtual blink::WebApplicationCacheHost::Status status(); 58 virtual bool startUpdate(); 59 virtual bool swapCache(); 60 virtual void getResourceList(blink::WebVector<ResourceInfo>* resources); 61 virtual void getAssociatedCacheInfo(CacheInfo* info); 62 63 private: 64 enum IsNewMasterEntry { 65 MAYBE, 66 YES, 67 NO 68 }; 69 70 blink::WebApplicationCacheHostClient* client_; 71 appcache::AppCacheBackend* backend_; 72 int host_id_; 73 appcache::Status status_; 74 blink::WebURLResponse document_response_; 75 GURL document_url_; 76 bool is_scheme_supported_; 77 bool is_get_method_; 78 IsNewMasterEntry is_new_master_entry_; 79 appcache::AppCacheInfo cache_info_; 80 GURL original_main_resource_url_; // Used to detect redirection. 81 bool was_select_cache_called_; 82 }; 83 84 } // namespace content 85 86 #endif // CONTENT_CHILD_APPCACHE_WEB_APPLICATION_CACHE_HOST_IMPL_H_ 87