Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / child / appcache / appcache_frontend_impl.cc
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
11 using blink::WebApplicationCacheHost;
12 using blink::WebConsoleMessage;
13
14 namespace content {
15
16 // Inline helper to keep the lines shorter and unwrapped.
17 inline WebApplicationCacheHostImpl* GetHost(int id) {
18   return WebApplicationCacheHostImpl::FromId(id);
19 }
20
21 void AppCacheFrontendImpl::OnCacheSelected(int host_id,
22                                            const appcache::AppCacheInfo& info) {
23   WebApplicationCacheHostImpl* host = GetHost(host_id);
24   if (host)
25     host->OnCacheSelected(info);
26 }
27
28 void AppCacheFrontendImpl::OnStatusChanged(const std::vector<int>& host_ids,
29                                            appcache::Status 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
38 void AppCacheFrontendImpl::OnEventRaised(const std::vector<int>& host_ids,
39                                          appcache::EventID event_id) {
40   DCHECK(event_id != appcache::PROGRESS_EVENT);  // See OnProgressEventRaised.
41   DCHECK(event_id != appcache::ERROR_EVENT);  // See OnErrorEventRaised.
42   for (std::vector<int>::const_iterator i = host_ids.begin();
43        i != host_ids.end(); ++i) {
44     WebApplicationCacheHostImpl* host = GetHost(*i);
45     if (host)
46       host->OnEventRaised(event_id);
47   }
48 }
49
50 void AppCacheFrontendImpl::OnProgressEventRaised(
51     const std::vector<int>& host_ids,
52     const GURL& url,
53     int num_total,
54     int num_complete) {
55   for (std::vector<int>::const_iterator i = host_ids.begin();
56        i != host_ids.end(); ++i) {
57     WebApplicationCacheHostImpl* host = GetHost(*i);
58     if (host)
59       host->OnProgressEventRaised(url, num_total, num_complete);
60   }
61 }
62
63 void AppCacheFrontendImpl::OnErrorEventRaised(
64     const std::vector<int>& host_ids,
65     const appcache::ErrorDetails& details) {
66   for (std::vector<int>::const_iterator i = host_ids.begin();
67        i != host_ids.end(); ++i) {
68     WebApplicationCacheHostImpl* host = GetHost(*i);
69     if (host)
70       host->OnErrorEventRaised(details);
71   }
72 }
73
74 void AppCacheFrontendImpl::OnLogMessage(int host_id,
75                                         appcache::LogLevel log_level,
76                                         const std::string& message) {
77   WebApplicationCacheHostImpl* host = GetHost(host_id);
78   if (host)
79     host->OnLogMessage(log_level, message);
80 }
81
82 void AppCacheFrontendImpl::OnContentBlocked(int host_id,
83                                             const GURL& manifest_url) {
84   WebApplicationCacheHostImpl* host = GetHost(host_id);
85   if (host)
86     host->OnContentBlocked(manifest_url);
87 }
88
89 // Ensure that enum values never get out of sync with the
90 // ones declared for use within the WebKit api
91 COMPILE_ASSERT((int)WebApplicationCacheHost::Uncached ==
92                (int)appcache::UNCACHED, Uncached);
93 COMPILE_ASSERT((int)WebApplicationCacheHost::Idle ==
94                (int)appcache::IDLE, Idle);
95 COMPILE_ASSERT((int)WebApplicationCacheHost::Checking ==
96                (int)appcache::CHECKING, Checking);
97 COMPILE_ASSERT((int)WebApplicationCacheHost::Downloading ==
98                (int)appcache::DOWNLOADING, Downloading);
99 COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReady ==
100                (int)appcache::UPDATE_READY, UpdateReady);
101 COMPILE_ASSERT((int)WebApplicationCacheHost::Obsolete ==
102                (int)appcache::OBSOLETE, Obsolete);
103
104 COMPILE_ASSERT((int)WebApplicationCacheHost::CheckingEvent ==
105                (int)appcache::CHECKING_EVENT, CheckingEvent);
106 COMPILE_ASSERT((int)WebApplicationCacheHost::ErrorEvent ==
107                (int)appcache::ERROR_EVENT, ErrorEvent);
108 COMPILE_ASSERT((int)WebApplicationCacheHost::NoUpdateEvent ==
109                (int)appcache::NO_UPDATE_EVENT, NoUpdateEvent);
110 COMPILE_ASSERT((int)WebApplicationCacheHost::DownloadingEvent ==
111                (int)appcache::DOWNLOADING_EVENT, DownloadingEvent);
112 COMPILE_ASSERT((int)WebApplicationCacheHost::ProgressEvent ==
113                (int)appcache::PROGRESS_EVENT, ProgressEvent);
114 COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReadyEvent ==
115                (int)appcache::UPDATE_READY_EVENT, UpdateReadyEvent);
116 COMPILE_ASSERT((int)WebApplicationCacheHost::CachedEvent ==
117                (int)appcache::CACHED_EVENT, CachedEvent);
118 COMPILE_ASSERT((int)WebApplicationCacheHost::ObsoleteEvent ==
119                (int)appcache::OBSOLETE_EVENT, ObsoleteEvent);
120
121 COMPILE_ASSERT((int)WebConsoleMessage::LevelDebug ==
122                (int)appcache::LOG_DEBUG, LevelDebug);
123 COMPILE_ASSERT((int)WebConsoleMessage::LevelLog ==
124                (int)appcache::LOG_INFO, LevelLog);
125 COMPILE_ASSERT((int)WebConsoleMessage::LevelWarning ==
126                (int)appcache::LOG_WARNING, LevelWarning);
127 COMPILE_ASSERT((int)WebConsoleMessage::LevelError ==
128                (int)appcache::LOG_ERROR, LevelError);
129
130 COMPILE_ASSERT((int)WebApplicationCacheHost::ManifestError ==
131                    (int)appcache::MANIFEST_ERROR,
132                ManifestError);
133 COMPILE_ASSERT((int)WebApplicationCacheHost::SignatureError ==
134                    (int)appcache::SIGNATURE_ERROR,
135                SignatureError);
136 COMPILE_ASSERT((int)WebApplicationCacheHost::ResourceError ==
137                    (int)appcache::RESOURCE_ERROR,
138                ResourceError);
139 COMPILE_ASSERT((int)WebApplicationCacheHost::ChangedError ==
140                    (int)appcache::CHANGED_ERROR,
141                ChangedError);
142 COMPILE_ASSERT((int)WebApplicationCacheHost::AbortError ==
143                    (int)appcache::ABORT_ERROR,
144                AbortError);
145 COMPILE_ASSERT((int)WebApplicationCacheHost::QuotaError ==
146                    (int)appcache::QUOTA_ERROR,
147                QuotaError);
148 COMPILE_ASSERT((int)WebApplicationCacheHost::PolicyError ==
149                    (int)appcache::POLICY_ERROR,
150                PolicyError);
151 COMPILE_ASSERT((int)WebApplicationCacheHost::UnknownError ==
152                    (int)appcache::UNKNOWN_ERROR,
153                UnknownError);
154
155 }  // namespace content