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 bool for_service_worker = | |
82 context->context_type() == Feature::SERVICE_WORKER_CONTEXT; | |
81 // Get the current RenderFrame so that we can send a routed IPC message from | 83 // Get the current RenderFrame so that we can send a routed IPC message from |
82 // the correct source. | 84 // the correct source. |
85 // Note that |render_frame| would be nullptr for Service Workers. Service | |
86 // Workers use control IPC instead. | |
83 content::RenderFrame* render_frame = context->GetRenderFrame(); | 87 content::RenderFrame* render_frame = context->GetRenderFrame(); |
84 if (!render_frame) | 88 if (!for_service_worker && !render_frame) { |
89 // It is important to early exit here for non Service Worker contexts so | |
90 // that we do not create orphaned | |
91 // RenderFrame cannot be found PendingRequest below. | |
Devlin
2016/04/14 22:34:52
this comment needs to be reworded
lazyboy
2016/04/15 00:57:47
Done.
| |
85 return; | 92 return; |
93 } | |
86 | 94 |
87 // TODO(koz): See if we can make this a CHECK. | 95 // TODO(koz): See if we can make this a CHECK. |
88 if (!context->HasAccessOrThrowError(name)) | 96 if (!context->HasAccessOrThrowError(name)) |
89 return; | 97 return; |
90 | 98 |
91 GURL source_url; | 99 GURL source_url; |
92 if (blink::WebLocalFrame* webframe = context->web_frame()) | 100 if (blink::WebLocalFrame* webframe = context->web_frame()) |
93 source_url = webframe->document().url(); | 101 source_url = webframe->document().url(); |
94 | 102 |
95 InsertRequest(request_id, new PendingRequest(name, source, | 103 InsertRequest(request_id, new PendingRequest(name, source, |
96 blink::WebUserGestureIndicator::currentUserGestureToken())); | 104 blink::WebUserGestureIndicator::currentUserGestureToken())); |
97 | 105 |
98 ExtensionHostMsg_Request_Params params; | 106 ExtensionHostMsg_Request_Params params; |
99 params.name = name; | 107 params.name = name; |
100 params.arguments.Swap(value_args); | 108 params.arguments.Swap(value_args); |
101 params.extension_id = context->GetExtensionID(); | 109 params.extension_id = context->GetExtensionID(); |
102 params.source_url = source_url; | 110 params.source_url = source_url; |
103 params.source_tab_id = source_tab_id_; | 111 params.source_tab_id = source_tab_id_; |
104 params.request_id = request_id; | 112 params.request_id = request_id; |
105 params.has_callback = has_callback; | 113 params.has_callback = has_callback; |
106 params.user_gesture = | 114 params.user_gesture = |
107 blink::WebUserGestureIndicator::isProcessingUserGesture(); | 115 blink::WebUserGestureIndicator::isProcessingUserGesture(); |
116 | |
117 // Set Service Worker specific params to default values. | |
118 params.worker_thread_id = -1; | |
119 params.embedded_worker_id = -1; | |
120 | |
121 SendRequest(render_frame, for_io_thread, params); | |
122 } | |
123 | |
124 void RequestSender::SendRequest(content::RenderFrame* render_frame, | |
125 bool for_io_thread, | |
126 ExtensionHostMsg_Request_Params& params) { | |
108 if (for_io_thread) { | 127 if (for_io_thread) { |
109 render_frame->Send(new ExtensionHostMsg_RequestForIOThread( | 128 render_frame->Send(new ExtensionHostMsg_RequestForIOThread( |
110 render_frame->GetRoutingID(), params)); | 129 render_frame->GetRoutingID(), params)); |
111 } else { | 130 } else { |
112 render_frame->Send( | 131 render_frame->Send( |
113 new ExtensionHostMsg_Request(render_frame->GetRoutingID(), params)); | 132 new ExtensionHostMsg_Request(render_frame->GetRoutingID(), params)); |
114 } | 133 } |
115 } | 134 } |
116 | 135 |
117 void RequestSender::HandleResponse(int request_id, | 136 void RequestSender::HandleResponse(int request_id, |
(...skipping 16 matching lines...) Expand all Loading... | |
134 for (PendingRequestMap::iterator it = pending_requests_.begin(); | 153 for (PendingRequestMap::iterator it = pending_requests_.begin(); |
135 it != pending_requests_.end();) { | 154 it != pending_requests_.end();) { |
136 if (it->second->source == source) | 155 if (it->second->source == source) |
137 pending_requests_.erase(it++); | 156 pending_requests_.erase(it++); |
138 else | 157 else |
139 ++it; | 158 ++it; |
140 } | 159 } |
141 } | 160 } |
142 | 161 |
143 } // namespace extensions | 162 } // namespace extensions |
OLD | NEW |