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#include "content/child/appcache/appcache_frontend_impl.h" 6 7#include "base/logging.h" 8#include "content/child/appcache/web_application_cache_host_impl.h" 9#include "third_party/WebKit/public/web/WebConsoleMessage.h" 10 11using blink::WebApplicationCacheHost; 12using blink::WebConsoleMessage; 13 14namespace content { 15 16// Inline helper to keep the lines shorter and unwrapped. 17inline WebApplicationCacheHostImpl* GetHost(int id) { 18 return WebApplicationCacheHostImpl::FromId(id); 19} 20 21void AppCacheFrontendImpl::OnCacheSelected(int host_id, 22 const AppCacheInfo& info) { 23 WebApplicationCacheHostImpl* host = GetHost(host_id); 24 if (host) 25 host->OnCacheSelected(info); 26} 27 28void AppCacheFrontendImpl::OnStatusChanged(const std::vector<int>& host_ids, 29 AppCacheStatus status) { 30 for (std::vector<int>::const_iterator i = host_ids.begin(); 31 i != host_ids.end(); ++i) { 32 WebApplicationCacheHostImpl* host = GetHost(*i); 33 if (host) 34 host->OnStatusChanged(status); 35 } 36} 37 38void AppCacheFrontendImpl::OnEventRaised(const std::vector<int>& host_ids, 39 AppCacheEventID event_id) { 40 DCHECK(event_id != 41 APPCACHE_PROGRESS_EVENT); // See OnProgressEventRaised. 42 DCHECK(event_id != APPCACHE_ERROR_EVENT); // See OnErrorEventRaised. 43 for (std::vector<int>::const_iterator i = host_ids.begin(); 44 i != host_ids.end(); ++i) { 45 WebApplicationCacheHostImpl* host = GetHost(*i); 46 if (host) 47 host->OnEventRaised(event_id); 48 } 49} 50 51void AppCacheFrontendImpl::OnProgressEventRaised( 52 const std::vector<int>& host_ids, 53 const GURL& url, 54 int num_total, 55 int num_complete) { 56 for (std::vector<int>::const_iterator i = host_ids.begin(); 57 i != host_ids.end(); ++i) { 58 WebApplicationCacheHostImpl* host = GetHost(*i); 59 if (host) 60 host->OnProgressEventRaised(url, num_total, num_complete); 61 } 62} 63 64void AppCacheFrontendImpl::OnErrorEventRaised( 65 const std::vector<int>& host_ids, 66 const AppCacheErrorDetails& details) { 67 for (std::vector<int>::const_iterator i = host_ids.begin(); 68 i != host_ids.end(); ++i) { 69 WebApplicationCacheHostImpl* host = GetHost(*i); 70 if (host) 71 host->OnErrorEventRaised(details); 72 } 73} 74 75void AppCacheFrontendImpl::OnLogMessage(int host_id, 76 AppCacheLogLevel log_level, 77 const std::string& message) { 78 WebApplicationCacheHostImpl* host = GetHost(host_id); 79 if (host) 80 host->OnLogMessage(log_level, message); 81} 82 83void AppCacheFrontendImpl::OnContentBlocked(int host_id, 84 const GURL& manifest_url) { 85 WebApplicationCacheHostImpl* host = GetHost(host_id); 86 if (host) 87 host->OnContentBlocked(manifest_url); 88} 89 90// Ensure that enum values never get out of sync with the 91// ones declared for use within the WebKit api 92COMPILE_ASSERT((int)WebApplicationCacheHost::Uncached == 93 (int)APPCACHE_STATUS_UNCACHED, Uncached); 94COMPILE_ASSERT((int)WebApplicationCacheHost::Idle == 95 (int)APPCACHE_STATUS_IDLE, Idle); 96COMPILE_ASSERT((int)WebApplicationCacheHost::Checking == 97 (int)APPCACHE_STATUS_CHECKING, Checking); 98COMPILE_ASSERT((int)WebApplicationCacheHost::Downloading == 99 (int)APPCACHE_STATUS_DOWNLOADING, Downloading); 100COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReady == 101 (int)APPCACHE_STATUS_UPDATE_READY, UpdateReady); 102COMPILE_ASSERT((int)WebApplicationCacheHost::Obsolete == 103 (int)APPCACHE_STATUS_OBSOLETE, Obsolete); 104 105COMPILE_ASSERT((int)WebApplicationCacheHost::CheckingEvent == 106 (int)APPCACHE_CHECKING_EVENT, CheckingEvent); 107COMPILE_ASSERT((int)WebApplicationCacheHost::ErrorEvent == 108 (int)APPCACHE_ERROR_EVENT, ErrorEvent); 109COMPILE_ASSERT((int)WebApplicationCacheHost::NoUpdateEvent == 110 (int)APPCACHE_NO_UPDATE_EVENT, NoUpdateEvent); 111COMPILE_ASSERT((int)WebApplicationCacheHost::DownloadingEvent == 112 (int)APPCACHE_DOWNLOADING_EVENT, DownloadingEvent); 113COMPILE_ASSERT((int)WebApplicationCacheHost::ProgressEvent == 114 (int)APPCACHE_PROGRESS_EVENT, ProgressEvent); 115COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReadyEvent == 116 (int)APPCACHE_UPDATE_READY_EVENT, UpdateReadyEvent); 117COMPILE_ASSERT((int)WebApplicationCacheHost::CachedEvent == 118 (int)APPCACHE_CACHED_EVENT, CachedEvent); 119COMPILE_ASSERT((int)WebApplicationCacheHost::ObsoleteEvent == 120 (int)APPCACHE_OBSOLETE_EVENT, ObsoleteEvent); 121 122COMPILE_ASSERT((int)WebConsoleMessage::LevelDebug == 123 (int)APPCACHE_LOG_DEBUG, LevelDebug); 124COMPILE_ASSERT((int)WebConsoleMessage::LevelLog == 125 (int)APPCACHE_LOG_INFO, LevelLog); 126COMPILE_ASSERT((int)WebConsoleMessage::LevelWarning == 127 (int)APPCACHE_LOG_WARNING, LevelWarning); 128COMPILE_ASSERT((int)WebConsoleMessage::LevelError == 129 (int)APPCACHE_LOG_ERROR, LevelError); 130 131COMPILE_ASSERT((int)WebApplicationCacheHost::ManifestError == 132 (int)APPCACHE_MANIFEST_ERROR, 133 ManifestError); 134COMPILE_ASSERT((int)WebApplicationCacheHost::SignatureError == 135 (int)APPCACHE_SIGNATURE_ERROR, 136 SignatureError); 137COMPILE_ASSERT((int)WebApplicationCacheHost::ResourceError == 138 (int)APPCACHE_RESOURCE_ERROR, 139 ResourceError); 140COMPILE_ASSERT((int)WebApplicationCacheHost::ChangedError == 141 (int)APPCACHE_CHANGED_ERROR, 142 ChangedError); 143COMPILE_ASSERT((int)WebApplicationCacheHost::AbortError == 144 (int)APPCACHE_ABORT_ERROR, 145 AbortError); 146COMPILE_ASSERT((int)WebApplicationCacheHost::QuotaError == 147 (int)APPCACHE_QUOTA_ERROR, 148 QuotaError); 149COMPILE_ASSERT((int)WebApplicationCacheHost::PolicyError == 150 (int)APPCACHE_POLICY_ERROR, 151 PolicyError); 152COMPILE_ASSERT((int)WebApplicationCacheHost::UnknownError == 153 (int)APPCACHE_UNKNOWN_ERROR, 154 UnknownError); 155 156} // namespace content 157