| 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 | 95 |
| 100 std::string extension_id = current_context->GetExtensionID(); | 96 std::string extension_id = current_context->GetExtensionID(); |
| 101 InsertRequest(request_id, new PendingRequest( | 97 InsertRequest(request_id, new PendingRequest( |
| 102 v8_context, name, extension_id)); | 98 v8_context, name, extension_id)); |
| 103 | 99 |
| 104 ExtensionHostMsg_Request_Params params; | 100 ExtensionHostMsg_Request_Params params; |
| 105 params.name = name; | 101 params.name = name; |
| 106 params.arguments.Swap(value_args); | 102 params.arguments.Swap(value_args); |
| 107 params.extension_id = extension_id; | 103 params.extension_id = extension_id; |
| 108 params.source_url = source_url; | 104 params.source_url = source_url; |
| 109 params.source_origin = source_origin.toString(); | 105 params.source_origin = source_origin.toString(); |
| 110 params.request_id = request_id; | 106 params.request_id = request_id; |
| 111 params.has_callback = has_callback; | 107 params.has_callback = has_callback; |
| 112 params.user_gesture = | 108 params.user_gesture = |
| 113 webframe ? webframe->isProcessingUserGesture() : false; | 109 webframe ? webframe->isProcessingUserGesture() : false; |
| 110 params.source_context_type = current_context->context_type(); |
| 114 if (for_io_thread) { | 111 if (for_io_thread) { |
| 115 renderview->Send(new ExtensionHostMsg_RequestForIOThread( | 112 renderview->Send(new ExtensionHostMsg_RequestForIOThread( |
| 116 renderview->GetRoutingID(), params)); | 113 renderview->GetRoutingID(), params)); |
| 117 } else { | 114 } else { |
| 118 renderview->Send(new ExtensionHostMsg_Request( | 115 renderview->Send(new ExtensionHostMsg_Request( |
| 119 renderview->GetRoutingID(), params)); | 116 renderview->GetRoutingID(), params)); |
| 120 } | 117 } |
| 121 } | 118 } |
| 122 | 119 |
| 123 void ExtensionRequestSender::HandleResponse(int request_id, | 120 void ExtensionRequestSender::HandleResponse(int request_id, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 152 &retval)); | 149 &retval)); |
| 153 // In debug, the js will validate the callback parameters and return a | 150 // In debug, the js will validate the callback parameters and return a |
| 154 // string if a validation error has occured. | 151 // string if a validation error has occured. |
| 155 #ifndef NDEBUG | 152 #ifndef NDEBUG |
| 156 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 153 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
| 157 std::string error = *v8::String::AsciiValue(retval); | 154 std::string error = *v8::String::AsciiValue(retval); |
| 158 DCHECK(false) << error; | 155 DCHECK(false) << error; |
| 159 } | 156 } |
| 160 #endif | 157 #endif |
| 161 } | 158 } |
| OLD | NEW |