| 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 "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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return false; | 114 return false; |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool ExtensionFunction::HasOptionalArgument(size_t index) { | 117 bool ExtensionFunction::HasOptionalArgument(size_t index) { |
| 118 Value* value; | 118 Value* value; |
| 119 return args_->Get(index, &value) && !value->IsType(Value::TYPE_NULL); | 119 return args_->Get(index, &value) && !value->IsType(Value::TYPE_NULL); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void ExtensionFunction::SendResponseImpl(base::ProcessHandle process, | 122 void ExtensionFunction::SendResponseImpl(base::ProcessHandle process, |
| 123 IPC::Sender* ipc_sender, | 123 IPC::Sender* ipc_sender, |
| 124 int routing_id, | |
| 125 bool success) { | 124 bool success) { |
| 126 DCHECK(ipc_sender); | 125 DCHECK(ipc_sender); |
| 127 if (bad_message_) { | 126 if (bad_message_) { |
| 128 HandleBadMessage(process); | 127 HandleBadMessage(process); |
| 129 return; | 128 return; |
| 130 } | 129 } |
| 131 | 130 |
| 132 // Value objects can't be directly serialized in our IPC code, so we wrap the | 131 // Value objects can't be directly serialized in our IPC code, so we wrap the |
| 133 // result_ Value with a ListValue (also transferring ownership of result_). | 132 // result_ Value with a ListValue (also transferring ownership of result_). |
| 134 base::ListValue result_wrapper; | 133 base::ListValue result_wrapper; |
| 135 if (result_.get()) | 134 if (result_.get()) |
| 136 result_wrapper.Append(result_.release()); | 135 result_wrapper.Append(result_.release()); |
| 137 | 136 |
| 138 ipc_sender->Send(new ExtensionMsg_Response( | 137 ipc_sender->Send(new ExtensionMsg_Response( |
| 139 routing_id, request_id_, success, result_wrapper, GetError())); | 138 request_id_, success, result_wrapper, GetError())); |
| 140 } | 139 } |
| 141 | 140 |
| 142 void ExtensionFunction::HandleBadMessage(base::ProcessHandle process) { | 141 void ExtensionFunction::HandleBadMessage(base::ProcessHandle process) { |
| 143 LOG(ERROR) << "bad extension message " << name_ << " : terminating renderer."; | 142 LOG(ERROR) << "bad extension message " << name_ << " : terminating renderer."; |
| 144 if (content::RenderProcessHost::run_renderer_in_process()) { | 143 if (content::RenderProcessHost::run_renderer_in_process()) { |
| 145 // In single process mode it is better if we don't suicide but just crash. | 144 // In single process mode it is better if we don't suicide but just crash. |
| 146 CHECK(false); | 145 CHECK(false); |
| 147 } else { | 146 } else { |
| 148 NOTREACHED(); | 147 NOTREACHED(); |
| 149 content::RecordAction(UserMetricsAction("BadMessageTerminate_EFD")); | 148 content::RecordAction(UserMetricsAction("BadMessageTerminate_EFD")); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 240 |
| 242 void UIThreadExtensionFunction::SendResponse(bool success) { | 241 void UIThreadExtensionFunction::SendResponse(bool success) { |
| 243 if (delegate_) { | 242 if (delegate_) { |
| 244 delegate_->OnSendResponse(this, success, bad_message_); | 243 delegate_->OnSendResponse(this, success, bad_message_); |
| 245 } else { | 244 } else { |
| 246 if (!render_view_host_ || !dispatcher()) | 245 if (!render_view_host_ || !dispatcher()) |
| 247 return; | 246 return; |
| 248 | 247 |
| 249 SendResponseImpl(render_view_host_->GetProcess()->GetHandle(), | 248 SendResponseImpl(render_view_host_->GetProcess()->GetHandle(), |
| 250 render_view_host_, | 249 render_view_host_, |
| 251 render_view_host_->GetRoutingID(), | |
| 252 success); | 250 success); |
| 253 } | 251 } |
| 254 } | 252 } |
| 255 | 253 |
| 256 IOThreadExtensionFunction::IOThreadExtensionFunction() | 254 IOThreadExtensionFunction::IOThreadExtensionFunction() { |
| 257 : routing_id_(-1) { | |
| 258 } | 255 } |
| 259 | 256 |
| 260 IOThreadExtensionFunction::~IOThreadExtensionFunction() { | 257 IOThreadExtensionFunction::~IOThreadExtensionFunction() { |
| 261 } | 258 } |
| 262 | 259 |
| 263 IOThreadExtensionFunction* | 260 IOThreadExtensionFunction* |
| 264 IOThreadExtensionFunction::AsIOThreadExtensionFunction() { | 261 IOThreadExtensionFunction::AsIOThreadExtensionFunction() { |
| 265 return this; | 262 return this; |
| 266 } | 263 } |
| 267 | 264 |
| 268 void IOThreadExtensionFunction::Destruct() const { | 265 void IOThreadExtensionFunction::Destruct() const { |
| 269 BrowserThread::DeleteOnIOThread::Destruct(this); | 266 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 270 } | 267 } |
| 271 | 268 |
| 272 void IOThreadExtensionFunction::SendResponse(bool success) { | 269 void IOThreadExtensionFunction::SendResponse(bool success) { |
| 273 if (!ipc_sender()) | 270 if (!ipc_sender()) |
| 274 return; | 271 return; |
| 275 | 272 |
| 276 SendResponseImpl(ipc_sender()->peer_handle(), | 273 SendResponseImpl(ipc_sender()->peer_handle(), ipc_sender(), success); |
| 277 ipc_sender(), routing_id_, success); | |
| 278 } | 274 } |
| 279 | 275 |
| 280 AsyncExtensionFunction::AsyncExtensionFunction() { | 276 AsyncExtensionFunction::AsyncExtensionFunction() { |
| 281 } | 277 } |
| 282 | 278 |
| 283 AsyncExtensionFunction::~AsyncExtensionFunction() { | 279 AsyncExtensionFunction::~AsyncExtensionFunction() { |
| 284 } | 280 } |
| 285 | 281 |
| 286 SyncExtensionFunction::SyncExtensionFunction() { | 282 SyncExtensionFunction::SyncExtensionFunction() { |
| 287 } | 283 } |
| 288 | 284 |
| 289 SyncExtensionFunction::~SyncExtensionFunction() { | 285 SyncExtensionFunction::~SyncExtensionFunction() { |
| 290 } | 286 } |
| 291 | 287 |
| 292 void SyncExtensionFunction::Run() { | 288 void SyncExtensionFunction::Run() { |
| 293 SendResponse(RunImpl()); | 289 SendResponse(RunImpl()); |
| 294 } | 290 } |
| 295 | 291 |
| 296 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { | 292 SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { |
| 297 } | 293 } |
| 298 | 294 |
| 299 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { | 295 SyncIOThreadExtensionFunction::~SyncIOThreadExtensionFunction() { |
| 300 } | 296 } |
| 301 | 297 |
| 302 void SyncIOThreadExtensionFunction::Run() { | 298 void SyncIOThreadExtensionFunction::Run() { |
| 303 SendResponse(RunImpl()); | 299 SendResponse(RunImpl()); |
| 304 } | 300 } |
| OLD | NEW |