| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/api/web_request/web_request_event_details.h" | 5 #include "extensions/browser/api/web_request/web_request_event_details.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 void WebRequestEventDetails::SetResponseSource(const net::URLRequest* request) { | 145 void WebRequestEventDetails::SetResponseSource(const net::URLRequest* request) { |
| 146 dict_.SetBoolean(keys::kFromCache, request->was_cached()); | 146 dict_.SetBoolean(keys::kFromCache, request->was_cached()); |
| 147 const std::string response_ip = request->GetSocketAddress().host(); | 147 const std::string response_ip = request->GetSocketAddress().host(); |
| 148 if (!response_ip.empty()) | 148 if (!response_ip.empty()) |
| 149 dict_.SetString(keys::kIpKey, response_ip); | 149 dict_.SetString(keys::kIpKey, response_ip); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void WebRequestEventDetails::DetermineFrameIdOnUI() { | 152 void WebRequestEventDetails::DetermineFrameDataOnUI() { |
| 153 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 153 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 154 content::RenderFrameHost* rfh = | 154 content::RenderFrameHost* rfh = |
| 155 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); | 155 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); |
| 156 dict_.SetInteger(keys::kFrameIdKey, ExtensionApiFrameIdMap::GetFrameId(rfh)); | 156 ExtensionApiFrameIdMap::FrameData frame_data = |
| 157 dict_.SetInteger(keys::kParentFrameIdKey, | 157 ExtensionApiFrameIdMap::Get()->GetFrameData(rfh); |
| 158 ExtensionApiFrameIdMap::GetParentFrameId(rfh)); | 158 |
| 159 dict_.SetInteger(keys::kTabIdKey, frame_data.tab_id); |
| 160 dict_.SetInteger(keys::kFrameIdKey, frame_data.frame_id); |
| 161 dict_.SetInteger(keys::kParentFrameIdKey, frame_data.parent_frame_id); |
| 159 } | 162 } |
| 160 | 163 |
| 161 void WebRequestEventDetails::DetermineFrameIdOnIO( | 164 void WebRequestEventDetails::DetermineFrameDataOnIO( |
| 162 const DeterminedFrameIdCallback& callback) { | 165 const DeterminedFrameDataCallback& callback) { |
| 163 std::unique_ptr<WebRequestEventDetails> self(this); | 166 std::unique_ptr<WebRequestEventDetails> self(this); |
| 164 ExtensionApiFrameIdMap::Get()->GetFrameDataOnIO( | 167 ExtensionApiFrameIdMap::Get()->GetFrameDataOnIO( |
| 165 render_process_id_, render_frame_id_, | 168 render_process_id_, render_frame_id_, |
| 166 base::Bind(&WebRequestEventDetails::OnDeterminedFrameId, | 169 base::Bind(&WebRequestEventDetails::OnDeterminedFrameData, |
| 167 base::Unretained(this), base::Passed(&self), callback)); | 170 base::Unretained(this), base::Passed(&self), callback)); |
| 168 } | 171 } |
| 169 | 172 |
| 170 std::unique_ptr<base::DictionaryValue> WebRequestEventDetails::GetFilteredDict( | 173 std::unique_ptr<base::DictionaryValue> WebRequestEventDetails::GetFilteredDict( |
| 171 int extra_info_spec) const { | 174 int extra_info_spec) const { |
| 172 std::unique_ptr<base::DictionaryValue> result = dict_.CreateDeepCopy(); | 175 std::unique_ptr<base::DictionaryValue> result = dict_.CreateDeepCopy(); |
| 173 if ((extra_info_spec & ExtraInfoSpec::REQUEST_BODY) && request_body_) | 176 if ((extra_info_spec & ExtraInfoSpec::REQUEST_BODY) && request_body_) |
| 174 result->Set(keys::kRequestBodyKey, request_body_->CreateDeepCopy()); | 177 result->Set(keys::kRequestBodyKey, request_body_->CreateDeepCopy()); |
| 175 if ((extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS) && request_headers_) | 178 if ((extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS) && request_headers_) |
| 176 result->Set(keys::kRequestHeadersKey, request_headers_->CreateDeepCopy()); | 179 result->Set(keys::kRequestHeadersKey, request_headers_->CreateDeepCopy()); |
| 177 if ((extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) && response_headers_) | 180 if ((extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) && response_headers_) |
| 178 result->Set(keys::kResponseHeadersKey, response_headers_->CreateDeepCopy()); | 181 result->Set(keys::kResponseHeadersKey, response_headers_->CreateDeepCopy()); |
| 179 return result; | 182 return result; |
| 180 } | 183 } |
| 181 | 184 |
| 182 std::unique_ptr<base::DictionaryValue> | 185 std::unique_ptr<base::DictionaryValue> |
| 183 WebRequestEventDetails::GetAndClearDict() { | 186 WebRequestEventDetails::GetAndClearDict() { |
| 184 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 187 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
| 185 dict_.Swap(result.get()); | 188 dict_.Swap(result.get()); |
| 186 return result; | 189 return result; |
| 187 } | 190 } |
| 188 | 191 |
| 189 void WebRequestEventDetails::OnDeterminedFrameId( | 192 void WebRequestEventDetails::OnDeterminedFrameData( |
| 190 std::unique_ptr<WebRequestEventDetails> self, | 193 std::unique_ptr<WebRequestEventDetails> self, |
| 191 const DeterminedFrameIdCallback& callback, | 194 const DeterminedFrameDataCallback& callback, |
| 192 const ExtensionApiFrameIdMap::FrameData& frame_data) { | 195 const ExtensionApiFrameIdMap::FrameData& frame_data) { |
| 196 dict_.SetInteger(keys::kTabIdKey, frame_data.tab_id); |
| 193 dict_.SetInteger(keys::kFrameIdKey, frame_data.frame_id); | 197 dict_.SetInteger(keys::kFrameIdKey, frame_data.frame_id); |
| 194 dict_.SetInteger(keys::kParentFrameIdKey, frame_data.parent_frame_id); | 198 dict_.SetInteger(keys::kParentFrameIdKey, frame_data.parent_frame_id); |
| 195 callback.Run(std::move(self)); | 199 callback.Run(std::move(self)); |
| 196 } | 200 } |
| 197 | 201 |
| 198 } // namespace extensions | 202 } // namespace extensions |
| OLD | NEW |