| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/appcache/appcache_dispatcher_host.h" | 5 #include "content/browser/appcache/appcache_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <map> |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "content/browser/appcache/appcache_navigation_handle_core.h" |
| 9 #include "content/browser/appcache/chrome_appcache_service.h" | 11 #include "content/browser/appcache/chrome_appcache_service.h" |
| 10 #include "content/browser/bad_message.h" | 12 #include "content/browser/bad_message.h" |
| 11 #include "content/common/appcache_messages.h" | 13 #include "content/common/appcache_messages.h" |
| 12 #include "content/public/browser/user_metrics.h" | 14 #include "content/public/browser/user_metrics.h" |
| 15 #include "content/public/common/browser_side_navigation_policy.h" |
| 13 | 16 |
| 14 namespace content { | 17 namespace content { |
| 15 | 18 |
| 16 AppCacheDispatcherHost::AppCacheDispatcherHost( | 19 AppCacheDispatcherHost::AppCacheDispatcherHost( |
| 17 ChromeAppCacheService* appcache_service, | 20 ChromeAppCacheService* appcache_service, |
| 18 int process_id) | 21 int process_id) |
| 19 : BrowserMessageFilter(AppCacheMsgStart), | 22 : BrowserMessageFilter(AppCacheMsgStart), |
| 20 appcache_service_(appcache_service), | 23 appcache_service_(appcache_service), |
| 21 frontend_proxy_(this), | 24 frontend_proxy_(this), |
| 22 process_id_(process_id), | 25 process_id_(process_id), |
| 23 weak_factory_(this) { | 26 weak_factory_(this) { |
| 24 } | 27 } |
| 25 | 28 |
| 26 void AppCacheDispatcherHost::OnChannelConnected(int32_t peer_pid) { | 29 void AppCacheDispatcherHost::OnChannelConnected(int32_t peer_pid) { |
| 27 if (appcache_service_.get()) { | 30 if (!appcache_service_.get()) |
| 28 backend_impl_.Initialize( | 31 return; |
| 29 appcache_service_.get(), &frontend_proxy_, process_id_); | 32 |
| 30 get_status_callback_ = | 33 backend_impl_.Initialize(appcache_service_.get(), &frontend_proxy_, |
| 31 base::Bind(&AppCacheDispatcherHost::GetStatusCallback, | 34 process_id_); |
| 32 weak_factory_.GetWeakPtr()); | 35 get_status_callback_ = base::Bind(&AppCacheDispatcherHost::GetStatusCallback, |
| 33 start_update_callback_ = | 36 weak_factory_.GetWeakPtr()); |
| 34 base::Bind(&AppCacheDispatcherHost::StartUpdateCallback, | 37 start_update_callback_ = base::Bind( |
| 35 weak_factory_.GetWeakPtr()); | 38 &AppCacheDispatcherHost::StartUpdateCallback, weak_factory_.GetWeakPtr()); |
| 36 swap_cache_callback_ = | 39 swap_cache_callback_ = base::Bind(&AppCacheDispatcherHost::SwapCacheCallback, |
| 37 base::Bind(&AppCacheDispatcherHost::SwapCacheCallback, | 40 weak_factory_.GetWeakPtr()); |
| 38 weak_factory_.GetWeakPtr()); | |
| 39 } | |
| 40 } | 41 } |
| 41 | 42 |
| 42 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) { | 43 bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| 43 bool handled = true; | 44 bool handled = true; |
| 44 IPC_BEGIN_MESSAGE_MAP(AppCacheDispatcherHost, message) | 45 IPC_BEGIN_MESSAGE_MAP(AppCacheDispatcherHost, message) |
| 45 IPC_MESSAGE_HANDLER(AppCacheHostMsg_RegisterHost, OnRegisterHost) | 46 IPC_MESSAGE_HANDLER(AppCacheHostMsg_RegisterHost, OnRegisterHost) |
| 46 IPC_MESSAGE_HANDLER(AppCacheHostMsg_UnregisterHost, OnUnregisterHost) | 47 IPC_MESSAGE_HANDLER(AppCacheHostMsg_UnregisterHost, OnUnregisterHost) |
| 47 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SetSpawningHostId, OnSetSpawningHostId) | 48 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SetSpawningHostId, OnSetSpawningHostId) |
| 48 IPC_MESSAGE_HANDLER(AppCacheHostMsg_GetResourceList, OnGetResourceList) | 49 IPC_MESSAGE_HANDLER(AppCacheHostMsg_GetResourceList, OnGetResourceList) |
| 49 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCache, OnSelectCache) | 50 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCache, OnSelectCache) |
| 50 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForWorker, | 51 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForWorker, |
| 51 OnSelectCacheForWorker) | 52 OnSelectCacheForWorker) |
| 52 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForSharedWorker, | 53 IPC_MESSAGE_HANDLER(AppCacheHostMsg_SelectCacheForSharedWorker, |
| 53 OnSelectCacheForSharedWorker) | 54 OnSelectCacheForSharedWorker) |
| 54 IPC_MESSAGE_HANDLER(AppCacheHostMsg_MarkAsForeignEntry, | 55 IPC_MESSAGE_HANDLER(AppCacheHostMsg_MarkAsForeignEntry, |
| 55 OnMarkAsForeignEntry) | 56 OnMarkAsForeignEntry) |
| 56 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_GetStatus, OnGetStatus) | 57 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_GetStatus, OnGetStatus) |
| 57 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_StartUpdate, OnStartUpdate) | 58 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_StartUpdate, OnStartUpdate) |
| 58 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_SwapCache, OnSwapCache) | 59 IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheHostMsg_SwapCache, OnSwapCache) |
| 59 IPC_MESSAGE_UNHANDLED(handled = false) | 60 IPC_MESSAGE_UNHANDLED(handled = false) |
| 60 IPC_END_MESSAGE_MAP() | 61 IPC_END_MESSAGE_MAP() |
| 61 | 62 |
| 62 return handled; | 63 return handled; |
| 63 } | 64 } |
| 64 | 65 |
| 65 AppCacheDispatcherHost::~AppCacheDispatcherHost() {} | 66 AppCacheDispatcherHost::~AppCacheDispatcherHost() { |
| 67 } |
| 66 | 68 |
| 67 void AppCacheDispatcherHost::OnRegisterHost(int host_id) { | 69 void AppCacheDispatcherHost::OnRegisterHost(int host_id) { |
| 68 if (appcache_service_.get()) { | 70 if (appcache_service_.get()) { |
| 71 // PlzNavigate |
| 72 // The AppCacheHost could have been precreated in which case we want to |
| 73 // register it with the backend here. |
| 74 if (IsBrowserSideNavigationEnabled()) { |
| 75 std::unique_ptr<AppCacheHost> host = |
| 76 AppCacheNavigationHandleCore::GetPrecreatedHost(host_id); |
| 77 if (host.get()) { |
| 78 backend_impl_.RegisterPrecreatedHost(std::move(host)); |
| 79 return; |
| 80 } |
| 81 } |
| 69 if (!backend_impl_.RegisterHost(host_id)) { | 82 if (!backend_impl_.RegisterHost(host_id)) { |
| 70 bad_message::ReceivedBadMessage(this, bad_message::ACDH_REGISTER); | 83 bad_message::ReceivedBadMessage(this, bad_message::ACDH_REGISTER); |
| 71 } | 84 } |
| 72 } | 85 } |
| 73 } | 86 } |
| 74 | 87 |
| 75 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { | 88 void AppCacheDispatcherHost::OnUnregisterHost(int host_id) { |
| 76 if (appcache_service_.get()) { | 89 if (appcache_service_.get()) { |
| 77 if (!backend_impl_.UnregisterHost(host_id)) { | 90 if (!backend_impl_.UnregisterHost(host_id)) { |
| 78 bad_message::ReceivedBadMessage(this, bad_message::ACDH_UNREGISTER); | 91 bad_message::ReceivedBadMessage(this, bad_message::ACDH_UNREGISTER); |
| 79 } | 92 } |
| 80 } | 93 } |
| 81 } | 94 } |
| 82 | 95 |
| 83 void AppCacheDispatcherHost::OnSetSpawningHostId( | 96 void AppCacheDispatcherHost::OnSetSpawningHostId( |
| 84 int host_id, int spawning_host_id) { | 97 int host_id, int spawning_host_id) { |
| 85 if (appcache_service_.get()) { | 98 if (appcache_service_.get()) { |
| 86 if (!backend_impl_.SetSpawningHostId(host_id, spawning_host_id)) | 99 if (!backend_impl_.SetSpawningHostId(host_id, spawning_host_id)) |
| 87 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SET_SPAWNING); | 100 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SET_SPAWNING); |
| 88 } | 101 } |
| 89 } | 102 } |
| 90 | 103 |
| 91 void AppCacheDispatcherHost::OnSelectCache( | 104 void AppCacheDispatcherHost::OnSelectCache( |
| 92 int host_id, | 105 int host_id, |
| 93 const GURL& document_url, | 106 const GURL& document_url, |
| 94 int64_t cache_document_was_loaded_from, | 107 int64_t cache_document_was_loaded_from, |
| 95 const GURL& opt_manifest_url) { | 108 const GURL& opt_manifest_url) { |
| 96 if (appcache_service_.get()) { | 109 if (appcache_service_.get()) { |
| 97 if (!backend_impl_.SelectCache(host_id, | 110 if (!backend_impl_.SelectCache(host_id, document_url, |
| 98 document_url, | |
| 99 cache_document_was_loaded_from, | 111 cache_document_was_loaded_from, |
| 100 opt_manifest_url)) { | 112 opt_manifest_url)) { |
| 101 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SELECT_CACHE); | 113 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SELECT_CACHE); |
| 102 } | 114 } |
| 103 } else { | 115 } else { |
| 104 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); | 116 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); |
| 105 } | 117 } |
| 106 } | 118 } |
| 107 | 119 |
| 108 void AppCacheDispatcherHost::OnSelectCacheForWorker( | 120 void AppCacheDispatcherHost::OnSelectCacheForWorker( |
| 109 int host_id, int parent_process_id, int parent_host_id) { | 121 int host_id, int parent_process_id, int parent_host_id) { |
| 110 if (appcache_service_.get()) { | 122 if (appcache_service_.get()) { |
| 111 if (!backend_impl_.SelectCacheForWorker( | 123 if (!backend_impl_.SelectCacheForWorker(host_id, parent_process_id, |
| 112 host_id, parent_process_id, parent_host_id)) { | 124 parent_host_id)) { |
| 113 bad_message::ReceivedBadMessage( | 125 bad_message::ReceivedBadMessage( |
| 114 this, bad_message::ACDH_SELECT_CACHE_FOR_WORKER); | 126 this, bad_message::ACDH_SELECT_CACHE_FOR_WORKER); |
| 115 } | 127 } |
| 116 } else { | 128 } else { |
| 117 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); | 129 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); |
| 118 } | 130 } |
| 119 } | 131 } |
| 120 | 132 |
| 121 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker(int host_id, | 133 void AppCacheDispatcherHost::OnSelectCacheForSharedWorker(int host_id, |
| 122 int64_t appcache_id) { | 134 int64_t appcache_id) { |
| 123 if (appcache_service_.get()) { | 135 if (appcache_service_.get()) { |
| 124 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id)) | 136 if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id)) |
| 125 bad_message::ReceivedBadMessage( | 137 bad_message::ReceivedBadMessage( |
| 126 this, bad_message::ACDH_SELECT_CACHE_FOR_SHARED_WORKER); | 138 this, bad_message::ACDH_SELECT_CACHE_FOR_SHARED_WORKER); |
| 127 } else { | 139 } else { |
| 128 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); | 140 frontend_proxy_.OnCacheSelected(host_id, AppCacheInfo()); |
| 129 } | 141 } |
| 130 } | 142 } |
| 131 | 143 |
| 132 void AppCacheDispatcherHost::OnMarkAsForeignEntry( | 144 void AppCacheDispatcherHost::OnMarkAsForeignEntry( |
| 133 int host_id, | 145 int host_id, |
| 134 const GURL& document_url, | 146 const GURL& document_url, |
| 135 int64_t cache_document_was_loaded_from) { | 147 int64_t cache_document_was_loaded_from) { |
| 136 if (appcache_service_.get()) { | 148 if (appcache_service_.get()) { |
| 137 if (!backend_impl_.MarkAsForeignEntry( | 149 if (!backend_impl_.MarkAsForeignEntry(host_id, document_url, |
| 138 host_id, document_url, cache_document_was_loaded_from)) { | 150 cache_document_was_loaded_from)) { |
| 139 bad_message::ReceivedBadMessage(this, | 151 bad_message::ReceivedBadMessage(this, |
| 140 bad_message::ACDH_MARK_AS_FOREIGN_ENTRY); | 152 bad_message::ACDH_MARK_AS_FOREIGN_ENTRY); |
| 141 } | 153 } |
| 142 } | 154 } |
| 143 } | 155 } |
| 144 | 156 |
| 145 void AppCacheDispatcherHost::OnGetResourceList( | 157 void AppCacheDispatcherHost::OnGetResourceList( |
| 146 int host_id, std::vector<AppCacheResourceInfo>* params) { | 158 int host_id, std::vector<AppCacheResourceInfo>* params) { |
| 147 if (appcache_service_.get()) | 159 if (appcache_service_.get()) |
| 148 backend_impl_.GetResourceList(host_id, params); | 160 backend_impl_.GetResourceList(host_id, params); |
| 149 } | 161 } |
| 150 | 162 |
| 151 void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) { | 163 void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) { |
| 152 if (pending_reply_msg_) { | 164 if (pending_reply_msg_) { |
| 153 bad_message::ReceivedBadMessage( | 165 bad_message::ReceivedBadMessage( |
| 154 this, bad_message::ACDH_PENDING_REPLY_IN_GET_STATUS); | 166 this, bad_message::ACDH_PENDING_REPLY_IN_GET_STATUS); |
| 155 delete reply_msg; | 167 delete reply_msg; |
| 156 return; | 168 return; |
| 157 } | 169 } |
| 158 | 170 |
| 159 pending_reply_msg_.reset(reply_msg); | 171 pending_reply_msg_.reset(reply_msg); |
| 160 if (appcache_service_.get()) { | 172 if (appcache_service_.get()) { |
| 161 if (!backend_impl_.GetStatusWithCallback( | 173 if (!backend_impl_.GetStatusWithCallback(host_id, get_status_callback_, |
| 162 host_id, get_status_callback_, reply_msg)) { | 174 reply_msg)) { |
| 163 bad_message::ReceivedBadMessage(this, bad_message::ACDH_GET_STATUS); | 175 bad_message::ReceivedBadMessage(this, bad_message::ACDH_GET_STATUS); |
| 164 } | 176 } |
| 165 return; | 177 return; |
| 166 } | 178 } |
| 167 | 179 |
| 168 GetStatusCallback(APPCACHE_STATUS_UNCACHED, reply_msg); | 180 GetStatusCallback(APPCACHE_STATUS_UNCACHED, reply_msg); |
| 169 } | 181 } |
| 170 | 182 |
| 171 void AppCacheDispatcherHost::OnStartUpdate(int host_id, | 183 void AppCacheDispatcherHost::OnStartUpdate(int host_id, |
| 172 IPC::Message* reply_msg) { | 184 IPC::Message* reply_msg) { |
| 173 if (pending_reply_msg_) { | 185 if (pending_reply_msg_) { |
| 174 bad_message::ReceivedBadMessage( | 186 bad_message::ReceivedBadMessage( |
| 175 this, bad_message::ACDH_PENDING_REPLY_IN_START_UPDATE); | 187 this, bad_message::ACDH_PENDING_REPLY_IN_START_UPDATE); |
| 176 delete reply_msg; | 188 delete reply_msg; |
| 177 return; | 189 return; |
| 178 } | 190 } |
| 179 | 191 |
| 180 pending_reply_msg_.reset(reply_msg); | 192 pending_reply_msg_.reset(reply_msg); |
| 181 if (appcache_service_.get()) { | 193 if (appcache_service_.get()) { |
| 182 if (!backend_impl_.StartUpdateWithCallback( | 194 if (!backend_impl_.StartUpdateWithCallback(host_id, start_update_callback_, |
| 183 host_id, start_update_callback_, reply_msg)) { | 195 reply_msg)) { |
| 184 bad_message::ReceivedBadMessage(this, bad_message::ACDH_START_UPDATE); | 196 bad_message::ReceivedBadMessage(this, bad_message::ACDH_START_UPDATE); |
| 185 } | 197 } |
| 186 return; | 198 return; |
| 187 } | 199 } |
| 188 | 200 |
| 189 StartUpdateCallback(false, reply_msg); | 201 StartUpdateCallback(false, reply_msg); |
| 190 } | 202 } |
| 191 | 203 |
| 192 void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) { | 204 void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) { |
| 193 if (pending_reply_msg_) { | 205 if (pending_reply_msg_) { |
| 194 bad_message::ReceivedBadMessage( | 206 bad_message::ReceivedBadMessage( |
| 195 this, bad_message::ACDH_PENDING_REPLY_IN_SWAP_CACHE); | 207 this, bad_message::ACDH_PENDING_REPLY_IN_SWAP_CACHE); |
| 196 delete reply_msg; | 208 delete reply_msg; |
| 197 return; | 209 return; |
| 198 } | 210 } |
| 199 | 211 |
| 200 pending_reply_msg_.reset(reply_msg); | 212 pending_reply_msg_.reset(reply_msg); |
| 201 if (appcache_service_.get()) { | 213 if (appcache_service_.get()) { |
| 202 if (!backend_impl_.SwapCacheWithCallback( | 214 if (!backend_impl_.SwapCacheWithCallback(host_id, swap_cache_callback_, |
| 203 host_id, swap_cache_callback_, reply_msg)) { | 215 reply_msg)) { |
| 204 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SWAP_CACHE); | 216 bad_message::ReceivedBadMessage(this, bad_message::ACDH_SWAP_CACHE); |
| 205 } | 217 } |
| 206 return; | 218 return; |
| 207 } | 219 } |
| 208 | 220 |
| 209 SwapCacheCallback(false, reply_msg); | 221 SwapCacheCallback(false, reply_msg); |
| 210 } | 222 } |
| 211 | 223 |
| 212 void AppCacheDispatcherHost::GetStatusCallback( | 224 void AppCacheDispatcherHost::GetStatusCallback( |
| 213 AppCacheStatus status, void* param) { | 225 AppCacheStatus status, void* param) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 225 } | 237 } |
| 226 | 238 |
| 227 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { | 239 void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) { |
| 228 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); | 240 IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param); |
| 229 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); | 241 DCHECK_EQ(pending_reply_msg_.get(), reply_msg); |
| 230 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result); | 242 AppCacheHostMsg_SwapCache::WriteReplyParams(reply_msg, result); |
| 231 Send(pending_reply_msg_.release()); | 243 Send(pending_reply_msg_.release()); |
| 232 } | 244 } |
| 233 | 245 |
| 234 } // namespace content | 246 } // namespace content |
| OLD | NEW |