| 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/renderer/extensions/extension_request_sender.h" | 5 #include "chrome/renderer/extensions/extension_request_sender.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/common/extensions/extension_messages.h" | 8 #include "chrome/common/extensions/extension_messages.h" |
| 9 #include "chrome/renderer/extensions/chrome_v8_context.h" | 9 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 10 #include "chrome/renderer/extensions/chrome_v8_context_set.h" | 10 #include "chrome/renderer/extensions/chrome_v8_context_set.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return; | 74 return; |
| 75 | 75 |
| 76 const std::set<std::string>& function_names = | 76 const std::set<std::string>& function_names = |
| 77 extension_dispatcher_->function_names(); | 77 extension_dispatcher_->function_names(); |
| 78 if (function_names.find(name) == function_names.end()) { | 78 if (function_names.find(name) == function_names.end()) { |
| 79 NOTREACHED() << "Unexpected function " << name << | 79 NOTREACHED() << "Unexpected function " << name << |
| 80 ". Did you remember to register it with ExtensionFunctionRegistry?"; | 80 ". Did you remember to register it with ExtensionFunctionRegistry?"; |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // TODO(koz): See if we can make this a CHECK. | |
| 85 if (!extension_dispatcher_->CheckCurrentContextAccessToExtensionAPI(name)) | |
| 86 return; | |
| 87 | |
| 88 GURL source_url; | 84 GURL source_url; |
| 89 WebKit::WebSecurityOrigin source_origin; | 85 WebKit::WebSecurityOrigin source_origin; |
| 90 WebKit::WebFrame* webframe = current_context->web_frame(); | 86 WebKit::WebFrame* webframe = current_context->web_frame(); |
| 91 if (webframe) { | 87 if (webframe) { |
| 92 source_url = webframe->document().url(); | 88 source_url = webframe->document().url(); |
| 93 source_origin = webframe->document().securityOrigin(); | 89 source_origin = webframe->document().securityOrigin(); |
| 94 } | 90 } |
| 95 | 91 |
| 96 v8::Persistent<v8::Context> v8_context = | 92 v8::Persistent<v8::Context> v8_context = |
| 97 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); | 93 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); |
| 98 DCHECK(!v8_context.IsEmpty()); | 94 DCHECK(!v8_context.IsEmpty()); |
| 99 InsertRequest(request_id, new PendingRequest( | 95 InsertRequest(request_id, new PendingRequest( |
| 100 v8_context, name, current_context->extension_id())); | 96 v8_context, name, current_context->extension_id())); |
| 101 | 97 |
| 102 ExtensionHostMsg_Request_Params params; | 98 ExtensionHostMsg_Request_Params params; |
| 103 params.name = name; | 99 params.name = name; |
| 104 params.arguments.Swap(value_args); | 100 params.arguments.Swap(value_args); |
| 105 params.extension_id = current_context->extension_id(); | 101 params.extension_id = current_context->extension_id(); |
| 106 params.source_url = source_url; | 102 params.source_url = source_url; |
| 107 params.source_origin = source_origin.toString(); | 103 params.source_origin = source_origin.toString(); |
| 108 params.request_id = request_id; | 104 params.request_id = request_id; |
| 109 params.has_callback = has_callback; | 105 params.has_callback = has_callback; |
| 110 params.user_gesture = | 106 params.user_gesture = |
| 111 webframe ? webframe->isProcessingUserGesture() : false; | 107 webframe ? webframe->isProcessingUserGesture() : false; |
| 108 params.source_context_type = current_context->context_type(); |
| 112 if (for_io_thread) { | 109 if (for_io_thread) { |
| 113 renderview->Send(new ExtensionHostMsg_RequestForIOThread( | 110 renderview->Send(new ExtensionHostMsg_RequestForIOThread( |
| 114 renderview->GetRoutingID(), params)); | 111 renderview->GetRoutingID(), params)); |
| 115 } else { | 112 } else { |
| 116 renderview->Send(new ExtensionHostMsg_Request( | 113 renderview->Send(new ExtensionHostMsg_Request( |
| 117 renderview->GetRoutingID(), params)); | 114 renderview->GetRoutingID(), params)); |
| 118 } | 115 } |
| 119 } | 116 } |
| 120 | 117 |
| 121 void ExtensionRequestSender::HandleResponse(int request_id, | 118 void ExtensionRequestSender::HandleResponse(int request_id, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 150 &retval)); | 147 &retval)); |
| 151 // In debug, the js will validate the callback parameters and return a | 148 // In debug, the js will validate the callback parameters and return a |
| 152 // string if a validation error has occured. | 149 // string if a validation error has occured. |
| 153 #ifndef NDEBUG | 150 #ifndef NDEBUG |
| 154 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 151 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
| 155 std::string error = *v8::String::AsciiValue(retval); | 152 std::string error = *v8::String::AsciiValue(retval); |
| 156 DCHECK(false) << error; | 153 DCHECK(false) << error; |
| 157 } | 154 } |
| 158 #endif | 155 #endif |
| 159 } | 156 } |
| OLD | NEW |