| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_function.h" | 5 #include "chrome/browser/extensions/extension_function.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 9 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 CHECK(false); | 121 CHECK(false); |
| 122 } else { | 122 } else { |
| 123 NOTREACHED(); | 123 NOTREACHED(); |
| 124 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_EFD")); | 124 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_EFD")); |
| 125 if (process) | 125 if (process) |
| 126 base::KillProcess(process, content::RESULT_CODE_KILLED_BAD_MESSAGE, | 126 base::KillProcess(process, content::RESULT_CODE_KILLED_BAD_MESSAGE, |
| 127 false); | 127 false); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 UIThreadExtensionFunction::UIThreadExtensionFunction() | 130 UIThreadExtensionFunction::UIThreadExtensionFunction() |
| 131 : render_view_host_(NULL), profile_(NULL) { | 131 : render_view_host_(NULL), profile_(NULL), delegate_(NULL) { |
| 132 } | 132 } |
| 133 | 133 |
| 134 UIThreadExtensionFunction::~UIThreadExtensionFunction() { | 134 UIThreadExtensionFunction::~UIThreadExtensionFunction() { |
| 135 } | 135 } |
| 136 | 136 |
| 137 UIThreadExtensionFunction* | 137 UIThreadExtensionFunction* |
| 138 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { | 138 UIThreadExtensionFunction::AsUIThreadExtensionFunction() { |
| 139 return this; | 139 return this; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void UIThreadExtensionFunction::Destruct() const { | 142 void UIThreadExtensionFunction::Destruct() const { |
| 143 BrowserThread::DeleteOnUIThread::Destruct(this); | 143 BrowserThread::DeleteOnUIThread::Destruct(this); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void UIThreadExtensionFunction::SetRenderViewHost( | 146 void UIThreadExtensionFunction::SetRenderViewHost( |
| 147 RenderViewHost* render_view_host) { | 147 RenderViewHost* render_view_host) { |
| 148 render_view_host_ = render_view_host; | 148 render_view_host_ = render_view_host; |
| 149 tracker_.reset(render_view_host ? new RenderViewHostTracker(this) : NULL); | 149 tracker_.reset(render_view_host ? new RenderViewHostTracker(this) : NULL); |
| 150 } | 150 } |
| 151 | 151 |
| 152 Browser* UIThreadExtensionFunction::GetCurrentBrowser() { | 152 Browser* UIThreadExtensionFunction::GetCurrentBrowser() { |
| 153 return dispatcher()->GetCurrentBrowser(render_view_host_, include_incognito_); | 153 return dispatcher()->GetCurrentBrowser(render_view_host_, include_incognito_); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void UIThreadExtensionFunction::SendResponse(bool success) { | 156 void UIThreadExtensionFunction::SendResponse(bool success) { |
| 157 if (!render_view_host_ || !dispatcher()) | 157 if (delegate_) { |
| 158 return; | 158 delegate_->OnSendResponse(this, success); |
| 159 } else { |
| 160 if (!render_view_host_ || !dispatcher()) |
| 161 return; |
| 159 | 162 |
| 160 SendResponseImpl(render_view_host_->process()->GetHandle(), | 163 SendResponseImpl(render_view_host_->process()->GetHandle(), |
| 161 render_view_host_, | 164 render_view_host_, |
| 162 render_view_host_->routing_id(), | 165 render_view_host_->routing_id(), |
| 163 success); | 166 success); |
| 167 } |
| 164 } | 168 } |
| 165 | 169 |
| 166 IOThreadExtensionFunction::IOThreadExtensionFunction() | 170 IOThreadExtensionFunction::IOThreadExtensionFunction() |
| 167 : routing_id_(-1) { | 171 : routing_id_(-1) { |
| 168 } | 172 } |
| 169 | 173 |
| 170 IOThreadExtensionFunction::~IOThreadExtensionFunction() { | 174 IOThreadExtensionFunction::~IOThreadExtensionFunction() { |
| 171 } | 175 } |
| 172 | 176 |
| 173 IOThreadExtensionFunction* | 177 IOThreadExtensionFunction* |
| 174 IOThreadExtensionFunction::AsIOThreadExtensionFunction() { | 178 IOThreadExtensionFunction::AsIOThreadExtensionFunction() { |
| 175 return this; | 179 return this; |
| 176 } | 180 } |
| 177 | 181 |
| 178 void IOThreadExtensionFunction::Destruct() const { | 182 void IOThreadExtensionFunction::Destruct() const { |
| 179 BrowserThread::DeleteOnIOThread::Destruct(this); | 183 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 180 } | 184 } |
| 181 | 185 |
| 182 void IOThreadExtensionFunction::SendResponse(bool success) { | 186 void IOThreadExtensionFunction::SendResponse(bool success) { |
| 183 if (!ipc_sender()) | 187 if (!ipc_sender()) |
| 184 return; | 188 return; |
| 185 | 189 |
| 186 SendResponseImpl(ipc_sender()->peer_handle(), | 190 SendResponseImpl(ipc_sender()->peer_handle(), |
| 187 ipc_sender(), routing_id_, success); | 191 ipc_sender(), routing_id_, success); |
| 188 } | 192 } |
| 189 | 193 |
| 190 AsyncExtensionFunction::AsyncExtensionFunction() : delegate_(NULL) { | 194 AsyncExtensionFunction::AsyncExtensionFunction() { |
| 191 } | |
| 192 | |
| 193 void AsyncExtensionFunction::SendResponse(bool success) { | |
| 194 if (delegate_) | |
| 195 delegate_->OnSendResponse(this, success); | |
| 196 else | |
| 197 UIThreadExtensionFunction::SendResponse(success); | |
| 198 } | 195 } |
| 199 | 196 |
| 200 AsyncExtensionFunction::~AsyncExtensionFunction() { | 197 AsyncExtensionFunction::~AsyncExtensionFunction() { |
| 201 } | 198 } |
| 202 | 199 |
| 203 SyncExtensionFunction::SyncExtensionFunction() { | 200 SyncExtensionFunction::SyncExtensionFunction() { |
| 204 } | 201 } |
| 205 | 202 |
| 206 SyncExtensionFunction::~SyncExtensionFunction() { | 203 SyncExtensionFunction::~SyncExtensionFunction() { |
| 207 } | 204 } |
| 208 | 205 |
| 209 void SyncExtensionFunction::Run() { | 206 void SyncExtensionFunction::Run() { |
| 210 SendResponse(RunImpl()); | 207 SendResponse(RunImpl()); |
| 211 } | 208 } |
| 212 | 209 |
| 213 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { | 210 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { |
| 214 } | 211 } |
| 215 | 212 |
| 216 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { | 213 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { |
| 217 } | 214 } |
| 218 | 215 |
| 219 void SyncIOThreadExtensionFunction::Run() { | 216 void SyncIOThreadExtensionFunction::Run() { |
| 220 SendResponse(RunImpl()); | 217 SendResponse(RunImpl()); |
| 221 } | 218 } |
| OLD | NEW |