1ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 5ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "content/child/appcache/appcache_frontend_impl.h" 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/logging.h" 8ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "content/child/appcache/web_application_cache_host_impl.h" 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebConsoleMessage.h" 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using blink::WebApplicationCacheHost; 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using blink::WebConsoleMessage; 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 14ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochnamespace content { 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Inline helper to keep the lines shorter and unwrapped. 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)inline WebApplicationCacheHostImpl* GetHost(int id) { 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return WebApplicationCacheHostImpl::FromId(id); 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 21ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid AppCacheFrontendImpl::OnCacheSelected(int host_id, 22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const AppCacheInfo& info) { 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(host_id); 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnCacheSelected(info); 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void AppCacheFrontendImpl::OnStatusChanged(const std::vector<int>& host_ids, 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch AppCacheStatus status) { 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (std::vector<int>::const_iterator i = host_ids.begin(); 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) i != host_ids.end(); ++i) { 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(*i); 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnStatusChanged(status); 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void AppCacheFrontendImpl::OnEventRaised(const std::vector<int>& host_ids, 39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch AppCacheEventID event_id) { 40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) DCHECK(event_id != 41116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch APPCACHE_PROGRESS_EVENT); // See OnProgressEventRaised. 42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DCHECK(event_id != APPCACHE_ERROR_EVENT); // See OnErrorEventRaised. 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (std::vector<int>::const_iterator i = host_ids.begin(); 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) i != host_ids.end(); ++i) { 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(*i); 46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnEventRaised(event_id); 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void AppCacheFrontendImpl::OnProgressEventRaised( 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::vector<int>& host_ids, 53ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const GURL& url, 54ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch int num_total, 55ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch int num_complete) { 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (std::vector<int>::const_iterator i = host_ids.begin(); 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) i != host_ids.end(); ++i) { 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(*i); 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnProgressEventRaised(url, num_total, num_complete); 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 64e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochvoid AppCacheFrontendImpl::OnErrorEventRaised( 65e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const std::vector<int>& host_ids, 66116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const AppCacheErrorDetails& details) { 67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (std::vector<int>::const_iterator i = host_ids.begin(); 68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) i != host_ids.end(); ++i) { 69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(*i); 70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 71e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch host->OnErrorEventRaised(details); 72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 75ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid AppCacheFrontendImpl::OnLogMessage(int host_id, 76116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch AppCacheLogLevel log_level, 77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::string& message) { 78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(host_id); 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnLogMessage(log_level, message); 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void AppCacheFrontendImpl::OnContentBlocked(int host_id, 84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const GURL& manifest_url) { 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebApplicationCacheHostImpl* host = GetHost(host_id); 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (host) 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) host->OnContentBlocked(manifest_url); 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Ensure that enum values never get out of sync with the 91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// ones declared for use within the WebKit api 92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Uncached == 93116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_STATUS_UNCACHED, Uncached); 94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Idle == 95116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_STATUS_IDLE, Idle); 96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Checking == 97116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_STATUS_CHECKING, Checking); 98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Downloading == 99116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_STATUS_DOWNLOADING, Downloading); 100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReady == 101116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_STATUS_UPDATE_READY, UpdateReady); 102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::Obsolete == 103116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_STATUS_OBSOLETE, Obsolete); 104e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::CheckingEvent == 106116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_CHECKING_EVENT, CheckingEvent); 107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::ErrorEvent == 108116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_ERROR_EVENT, ErrorEvent); 109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::NoUpdateEvent == 110116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_NO_UPDATE_EVENT, NoUpdateEvent); 111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::DownloadingEvent == 112116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_DOWNLOADING_EVENT, DownloadingEvent); 113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::ProgressEvent == 114116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_PROGRESS_EVENT, ProgressEvent); 115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReadyEvent == 116116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_UPDATE_READY_EVENT, UpdateReadyEvent); 117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::CachedEvent == 118116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_CACHED_EVENT, CachedEvent); 119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebApplicationCacheHost::ObsoleteEvent == 120116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_OBSOLETE_EVENT, ObsoleteEvent); 121e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebConsoleMessage::LevelDebug == 123116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_LOG_DEBUG, LevelDebug); 124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebConsoleMessage::LevelLog == 125116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_LOG_INFO, LevelLog); 126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebConsoleMessage::LevelWarning == 127116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_LOG_WARNING, LevelWarning); 128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)COMPILE_ASSERT((int)WebConsoleMessage::LevelError == 129116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_LOG_ERROR, LevelError); 130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 131e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochCOMPILE_ASSERT((int)WebApplicationCacheHost::ManifestError == 132116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_MANIFEST_ERROR, 133e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ManifestError); 134e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochCOMPILE_ASSERT((int)WebApplicationCacheHost::SignatureError == 135116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_SIGNATURE_ERROR, 136e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch SignatureError); 137e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochCOMPILE_ASSERT((int)WebApplicationCacheHost::ResourceError == 138116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_RESOURCE_ERROR, 139e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ResourceError); 140e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochCOMPILE_ASSERT((int)WebApplicationCacheHost::ChangedError == 141116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_CHANGED_ERROR, 142e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch ChangedError); 143e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochCOMPILE_ASSERT((int)WebApplicationCacheHost::AbortError == 144116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_ABORT_ERROR, 145e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch AbortError); 146e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochCOMPILE_ASSERT((int)WebApplicationCacheHost::QuotaError == 147116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_QUOTA_ERROR, 148e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch QuotaError); 149e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochCOMPILE_ASSERT((int)WebApplicationCacheHost::PolicyError == 150116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_POLICY_ERROR, 151e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch PolicyError); 152e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochCOMPILE_ASSERT((int)WebApplicationCacheHost::UnknownError == 153116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (int)APPCACHE_UNKNOWN_ERROR, 154e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch UnknownError); 155e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 156ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch} // namespace content 157