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.
5 #include "content/child/appcache/appcache_frontend_impl.h"
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"
11 using blink::WebApplicationCacheHost
;
12 using blink::WebConsoleMessage
;
16 // Inline helper to keep the lines shorter and unwrapped.
17 inline WebApplicationCacheHostImpl
* GetHost(int id
) {
18 return WebApplicationCacheHostImpl::FromId(id
);
21 void AppCacheFrontendImpl::OnCacheSelected(int host_id
,
22 const AppCacheInfo
& info
) {
23 WebApplicationCacheHostImpl
* host
= GetHost(host_id
);
25 host
->OnCacheSelected(info
);
28 void 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
);
34 host
->OnStatusChanged(status
);
38 void AppCacheFrontendImpl::OnEventRaised(const std::vector
<int>& host_ids
,
39 AppCacheEventID 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
);
47 host
->OnEventRaised(event_id
);
51 void AppCacheFrontendImpl::OnProgressEventRaised(
52 const std::vector
<int>& host_ids
,
56 for (std::vector
<int>::const_iterator i
= host_ids
.begin();
57 i
!= host_ids
.end(); ++i
) {
58 WebApplicationCacheHostImpl
* host
= GetHost(*i
);
60 host
->OnProgressEventRaised(url
, num_total
, num_complete
);
64 void 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
);
71 host
->OnErrorEventRaised(details
);
75 void AppCacheFrontendImpl::OnLogMessage(int host_id
,
76 AppCacheLogLevel log_level
,
77 const std::string
& message
) {
78 WebApplicationCacheHostImpl
* host
= GetHost(host_id
);
80 host
->OnLogMessage(log_level
, message
);
83 void AppCacheFrontendImpl::OnContentBlocked(int host_id
,
84 const GURL
& manifest_url
) {
85 WebApplicationCacheHostImpl
* host
= GetHost(host_id
);
87 host
->OnContentBlocked(manifest_url
);
90 // Ensure that enum values never get out of sync with the
91 // ones declared for use within the WebKit api
92 COMPILE_ASSERT((int)WebApplicationCacheHost::Uncached
==
93 (int)APPCACHE_STATUS_UNCACHED
, Uncached
);
94 COMPILE_ASSERT((int)WebApplicationCacheHost::Idle
==
95 (int)APPCACHE_STATUS_IDLE
, Idle
);
96 COMPILE_ASSERT((int)WebApplicationCacheHost::Checking
==
97 (int)APPCACHE_STATUS_CHECKING
, Checking
);
98 COMPILE_ASSERT((int)WebApplicationCacheHost::Downloading
==
99 (int)APPCACHE_STATUS_DOWNLOADING
, Downloading
);
100 COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReady
==
101 (int)APPCACHE_STATUS_UPDATE_READY
, UpdateReady
);
102 COMPILE_ASSERT((int)WebApplicationCacheHost::Obsolete
==
103 (int)APPCACHE_STATUS_OBSOLETE
, Obsolete
);
105 COMPILE_ASSERT((int)WebApplicationCacheHost::CheckingEvent
==
106 (int)APPCACHE_CHECKING_EVENT
, CheckingEvent
);
107 COMPILE_ASSERT((int)WebApplicationCacheHost::ErrorEvent
==
108 (int)APPCACHE_ERROR_EVENT
, ErrorEvent
);
109 COMPILE_ASSERT((int)WebApplicationCacheHost::NoUpdateEvent
==
110 (int)APPCACHE_NO_UPDATE_EVENT
, NoUpdateEvent
);
111 COMPILE_ASSERT((int)WebApplicationCacheHost::DownloadingEvent
==
112 (int)APPCACHE_DOWNLOADING_EVENT
, DownloadingEvent
);
113 COMPILE_ASSERT((int)WebApplicationCacheHost::ProgressEvent
==
114 (int)APPCACHE_PROGRESS_EVENT
, ProgressEvent
);
115 COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReadyEvent
==
116 (int)APPCACHE_UPDATE_READY_EVENT
, UpdateReadyEvent
);
117 COMPILE_ASSERT((int)WebApplicationCacheHost::CachedEvent
==
118 (int)APPCACHE_CACHED_EVENT
, CachedEvent
);
119 COMPILE_ASSERT((int)WebApplicationCacheHost::ObsoleteEvent
==
120 (int)APPCACHE_OBSOLETE_EVENT
, ObsoleteEvent
);
122 COMPILE_ASSERT((int)WebConsoleMessage::LevelDebug
==
123 (int)APPCACHE_LOG_DEBUG
, LevelDebug
);
124 COMPILE_ASSERT((int)WebConsoleMessage::LevelLog
==
125 (int)APPCACHE_LOG_INFO
, LevelLog
);
126 COMPILE_ASSERT((int)WebConsoleMessage::LevelWarning
==
127 (int)APPCACHE_LOG_WARNING
, LevelWarning
);
128 COMPILE_ASSERT((int)WebConsoleMessage::LevelError
==
129 (int)APPCACHE_LOG_ERROR
, LevelError
);
131 COMPILE_ASSERT((int)WebApplicationCacheHost::ManifestError
==
132 (int)APPCACHE_MANIFEST_ERROR
,
134 COMPILE_ASSERT((int)WebApplicationCacheHost::SignatureError
==
135 (int)APPCACHE_SIGNATURE_ERROR
,
137 COMPILE_ASSERT((int)WebApplicationCacheHost::ResourceError
==
138 (int)APPCACHE_RESOURCE_ERROR
,
140 COMPILE_ASSERT((int)WebApplicationCacheHost::ChangedError
==
141 (int)APPCACHE_CHANGED_ERROR
,
143 COMPILE_ASSERT((int)WebApplicationCacheHost::AbortError
==
144 (int)APPCACHE_ABORT_ERROR
,
146 COMPILE_ASSERT((int)WebApplicationCacheHost::QuotaError
==
147 (int)APPCACHE_QUOTA_ERROR
,
149 COMPILE_ASSERT((int)WebApplicationCacheHost::PolicyError
==
150 (int)APPCACHE_POLICY_ERROR
,
152 COMPILE_ASSERT((int)WebApplicationCacheHost::UnknownError
==
153 (int)APPCACHE_UNKNOWN_ERROR
,
156 } // namespace content