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/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 void RequestSender::StartRequest(Source* source, | 69 void RequestSender::StartRequest(Source* source, |
70 const std::string& name, | 70 const std::string& name, |
71 int request_id, | 71 int request_id, |
72 bool has_callback, | 72 bool has_callback, |
73 bool for_io_thread, | 73 bool for_io_thread, |
74 base::ListValue* value_args) { | 74 base::ListValue* value_args) { |
75 ScriptContext* context = source->GetContext(); | 75 ScriptContext* context = source->GetContext(); |
76 if (!context) | 76 if (!context) |
77 return; | 77 return; |
78 | 78 |
| 79 bool for_service_worker = |
| 80 context->context_type() == Feature::SERVICE_WORKER_CONTEXT; |
79 // Get the current RenderFrame so that we can send a routed IPC message from | 81 // Get the current RenderFrame so that we can send a routed IPC message from |
80 // the correct source. | 82 // the correct source. |
| 83 // Note that |render_frame| would be nullptr for Service Workers. Service |
| 84 // Workers use control IPC instead. |
81 content::RenderFrame* render_frame = context->GetRenderFrame(); | 85 content::RenderFrame* render_frame = context->GetRenderFrame(); |
82 if (!render_frame) | 86 if (!for_service_worker && !render_frame) { |
| 87 // It is important to early exit here for non Service Worker contexts so |
| 88 // that we do not create orphaned PendingRequests below. |
83 return; | 89 return; |
| 90 } |
84 | 91 |
85 // TODO(koz): See if we can make this a CHECK. | 92 // TODO(koz): See if we can make this a CHECK. |
86 if (!context->HasAccessOrThrowError(name)) | 93 if (!context->HasAccessOrThrowError(name)) |
87 return; | 94 return; |
88 | 95 |
89 GURL source_url; | 96 GURL source_url; |
90 if (blink::WebLocalFrame* webframe = context->web_frame()) | 97 if (blink::WebLocalFrame* webframe = context->web_frame()) |
91 source_url = webframe->document().url(); | 98 source_url = webframe->document().url(); |
92 | 99 |
93 InsertRequest(request_id, new PendingRequest(name, source, | 100 InsertRequest(request_id, new PendingRequest(name, source, |
94 blink::WebUserGestureIndicator::currentUserGestureToken())); | 101 blink::WebUserGestureIndicator::currentUserGestureToken())); |
95 | 102 |
96 ExtensionHostMsg_Request_Params params; | 103 ExtensionHostMsg_Request_Params params; |
97 params.name = name; | 104 params.name = name; |
98 params.arguments.Swap(value_args); | 105 params.arguments.Swap(value_args); |
99 params.extension_id = context->GetExtensionID(); | 106 params.extension_id = context->GetExtensionID(); |
100 params.source_url = source_url; | 107 params.source_url = source_url; |
101 params.source_tab_id = source_tab_id_; | 108 params.source_tab_id = source_tab_id_; |
102 params.request_id = request_id; | 109 params.request_id = request_id; |
103 params.has_callback = has_callback; | 110 params.has_callback = has_callback; |
104 params.user_gesture = | 111 params.user_gesture = |
105 blink::WebUserGestureIndicator::isProcessingUserGesture(); | 112 blink::WebUserGestureIndicator::isProcessingUserGesture(); |
| 113 |
| 114 // Set Service Worker specific params to default values. |
| 115 params.worker_thread_id = -1; |
| 116 params.embedded_worker_id = -1; |
| 117 |
| 118 SendRequest(render_frame, for_io_thread, params); |
| 119 } |
| 120 |
| 121 void RequestSender::SendRequest(content::RenderFrame* render_frame, |
| 122 bool for_io_thread, |
| 123 ExtensionHostMsg_Request_Params& params) { |
106 if (for_io_thread) { | 124 if (for_io_thread) { |
107 render_frame->Send(new ExtensionHostMsg_RequestForIOThread( | 125 render_frame->Send(new ExtensionHostMsg_RequestForIOThread( |
108 render_frame->GetRoutingID(), params)); | 126 render_frame->GetRoutingID(), params)); |
109 } else { | 127 } else { |
110 render_frame->Send( | 128 render_frame->Send( |
111 new ExtensionHostMsg_Request(render_frame->GetRoutingID(), params)); | 129 new ExtensionHostMsg_Request(render_frame->GetRoutingID(), params)); |
112 } | 130 } |
113 } | 131 } |
114 | 132 |
115 void RequestSender::HandleResponse(int request_id, | 133 void RequestSender::HandleResponse(int request_id, |
(...skipping 16 matching lines...) Expand all Loading... |
132 for (PendingRequestMap::iterator it = pending_requests_.begin(); | 150 for (PendingRequestMap::iterator it = pending_requests_.begin(); |
133 it != pending_requests_.end();) { | 151 it != pending_requests_.end();) { |
134 if (it->second->source == source) | 152 if (it->second->source == source) |
135 pending_requests_.erase(it++); | 153 pending_requests_.erase(it++); |
136 else | 154 else |
137 ++it; | 155 ++it; |
138 } | 156 } |
139 } | 157 } |
140 | 158 |
141 } // namespace extensions | 159 } // namespace extensions |
OLD | NEW |