Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/request_sender.h" | 5 #include "extensions/renderer/request_sender.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "content/public/renderer/render_frame.h" | 8 #include "content/public/renderer/render_frame.h" |
| 9 #include "extensions/common/extension_messages.h" | 9 #include "extensions/common/extension_messages.h" |
| 10 #include "extensions/renderer/dispatcher.h" | 10 #include "extensions/renderer/dispatcher.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 void RequestSender::StartRequest(Source* source, | 71 void RequestSender::StartRequest(Source* source, |
| 72 const std::string& name, | 72 const std::string& name, |
| 73 int request_id, | 73 int request_id, |
| 74 bool has_callback, | 74 bool has_callback, |
| 75 bool for_io_thread, | 75 bool for_io_thread, |
| 76 base::ListValue* value_args) { | 76 base::ListValue* value_args) { |
| 77 ScriptContext* context = source->GetContext(); | 77 ScriptContext* context = source->GetContext(); |
| 78 if (!context) | 78 if (!context) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 // Get the current RenderFrame so that we can send a routed IPC message from | |
| 82 // the correct source. | |
| 83 content::RenderFrame* render_frame = context->GetRenderFrame(); | |
|
Devlin
2016/04/13 19:46:32
I think this early-out was important. Not least b
lazyboy
2016/04/14 02:07:53
Done.
| |
| 84 if (!render_frame) | |
| 85 return; | |
| 86 | |
| 87 // TODO(koz): See if we can make this a CHECK. | 81 // TODO(koz): See if we can make this a CHECK. |
| 88 if (!context->HasAccessOrThrowError(name)) | 82 if (!context->HasAccessOrThrowError(name)) |
| 89 return; | 83 return; |
| 90 | 84 |
| 91 GURL source_url; | 85 GURL source_url; |
| 92 if (blink::WebLocalFrame* webframe = context->web_frame()) | 86 if (blink::WebLocalFrame* webframe = context->web_frame()) |
| 93 source_url = webframe->document().url(); | 87 source_url = webframe->document().url(); |
| 94 | 88 |
| 95 InsertRequest(request_id, new PendingRequest(name, source, | 89 InsertRequest(request_id, new PendingRequest(name, source, |
| 96 blink::WebUserGestureIndicator::currentUserGestureToken())); | 90 blink::WebUserGestureIndicator::currentUserGestureToken())); |
| 97 | 91 |
| 98 ExtensionHostMsg_Request_Params params; | 92 ExtensionHostMsg_Request_Params params; |
| 99 params.name = name; | 93 params.name = name; |
| 100 params.arguments.Swap(value_args); | 94 params.arguments.Swap(value_args); |
| 101 params.extension_id = context->GetExtensionID(); | 95 params.extension_id = context->GetExtensionID(); |
| 102 params.source_url = source_url; | 96 params.source_url = source_url; |
| 103 params.source_tab_id = source_tab_id_; | 97 params.source_tab_id = source_tab_id_; |
| 104 params.request_id = request_id; | 98 params.request_id = request_id; |
| 105 params.has_callback = has_callback; | 99 params.has_callback = has_callback; |
| 106 params.user_gesture = | 100 params.user_gesture = |
| 107 blink::WebUserGestureIndicator::isProcessingUserGesture(); | 101 blink::WebUserGestureIndicator::isProcessingUserGesture(); |
| 102 | |
| 103 // Set Service Worker specific params to default values. | |
| 104 params.worker_thread_id = -1; | |
| 105 params.embedded_worker_id = -1; | |
| 106 | |
| 107 // Get the current RenderFrame so that we can send a routed IPC message from | |
| 108 // the correct source. | |
| 109 SendRequest(context->GetRenderFrame(), for_io_thread, params); | |
| 110 } | |
| 111 | |
| 112 void RequestSender::SendRequest(content::RenderFrame* render_frame, | |
| 113 bool for_io_thread, | |
| 114 ExtensionHostMsg_Request_Params& params) { | |
| 115 if (!render_frame) | |
| 116 return; | |
| 117 | |
| 108 if (for_io_thread) { | 118 if (for_io_thread) { |
| 109 render_frame->Send(new ExtensionHostMsg_RequestForIOThread( | 119 render_frame->Send(new ExtensionHostMsg_RequestForIOThread( |
| 110 render_frame->GetRoutingID(), params)); | 120 render_frame->GetRoutingID(), params)); |
| 111 } else { | 121 } else { |
| 112 render_frame->Send( | 122 render_frame->Send( |
| 113 new ExtensionHostMsg_Request(render_frame->GetRoutingID(), params)); | 123 new ExtensionHostMsg_Request(render_frame->GetRoutingID(), params)); |
| 114 } | 124 } |
| 115 } | 125 } |
| 116 | 126 |
| 117 void RequestSender::HandleResponse(int request_id, | 127 void RequestSender::HandleResponse(int request_id, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 134 for (PendingRequestMap::iterator it = pending_requests_.begin(); | 144 for (PendingRequestMap::iterator it = pending_requests_.begin(); |
| 135 it != pending_requests_.end();) { | 145 it != pending_requests_.end();) { |
| 136 if (it->second->source == source) | 146 if (it->second->source == source) |
| 137 pending_requests_.erase(it++); | 147 pending_requests_.erase(it++); |
| 138 else | 148 else |
| 139 ++it; | 149 ++it; |
| 140 } | 150 } |
| 141 } | 151 } |
| 142 | 152 |
| 143 } // namespace extensions | 153 } // namespace extensions |
| OLD | NEW |