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/browser/extensions/api/web_request/web_request_api.h" | 5 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
36 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
37 #include "content/public/browser/browser_message_filter.h" | 37 #include "content/public/browser/browser_message_filter.h" |
38 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
39 #include "content/public/browser/render_frame_host.h" | 39 #include "content/public/browser/render_frame_host.h" |
40 #include "content/public/browser/render_process_host.h" | 40 #include "content/public/browser/render_process_host.h" |
41 #include "content/public/browser/resource_request_info.h" | 41 #include "content/public/browser/resource_request_info.h" |
42 #include "content/public/browser/user_metrics.h" | 42 #include "content/public/browser/user_metrics.h" |
43 #include "extensions/browser/api/declarative_webrequest/request_stage.h" | 43 #include "extensions/browser/api/declarative_webrequest/request_stage.h" |
44 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 44 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
| 45 #include "extensions/browser/api/web_request/web_request_api_utils.h" |
45 #include "extensions/browser/event_router.h" | 46 #include "extensions/browser/event_router.h" |
46 #include "extensions/browser/extension_message_filter.h" | 47 #include "extensions/browser/extension_message_filter.h" |
47 #include "extensions/browser/extension_prefs.h" | 48 #include "extensions/browser/extension_prefs.h" |
48 #include "extensions/browser/extension_registry.h" | 49 #include "extensions/browser/extension_registry.h" |
49 #include "extensions/browser/extension_system.h" | 50 #include "extensions/browser/extension_system.h" |
50 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | 51 #include "extensions/browser/guest_view/web_view/web_view_constants.h" |
51 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 52 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
52 #include "extensions/browser/info_map.h" | 53 #include "extensions/browser/info_map.h" |
53 #include "extensions/browser/runtime_data.h" | 54 #include "extensions/browser/runtime_data.h" |
54 #include "extensions/browser/warning_service.h" | 55 #include "extensions/browser/warning_service.h" |
(...skipping 25 matching lines...) Expand all Loading... |
80 using extensions::ErrorUtils; | 81 using extensions::ErrorUtils; |
81 using extensions::Extension; | 82 using extensions::Extension; |
82 using extensions::InfoMap; | 83 using extensions::InfoMap; |
83 using extensions::Feature; | 84 using extensions::Feature; |
84 using extensions::RulesRegistryService; | 85 using extensions::RulesRegistryService; |
85 using extensions::Warning; | 86 using extensions::Warning; |
86 using extensions::WarningService; | 87 using extensions::WarningService; |
87 using extensions::WarningSet; | 88 using extensions::WarningSet; |
88 | 89 |
89 namespace helpers = extension_web_request_api_helpers; | 90 namespace helpers = extension_web_request_api_helpers; |
| 91 namespace utils = extension_web_request_api_utils; |
90 namespace keys = extension_web_request_api_constants; | 92 namespace keys = extension_web_request_api_constants; |
91 namespace web_request = extensions::api::web_request; | 93 namespace web_request = extensions::api::web_request; |
92 namespace declarative_keys = extensions::declarative_webrequest_constants; | 94 namespace declarative_keys = extensions::declarative_webrequest_constants; |
93 namespace activitylog = activity_log_web_request_constants; | 95 namespace activitylog = activity_log_web_request_constants; |
94 | 96 |
95 namespace { | 97 namespace { |
96 | 98 |
97 const char kWebRequestEventPrefix[] = "webRequest."; | 99 const char kWebRequestEventPrefix[] = "webRequest."; |
98 | 100 |
99 // List of all the webRequest events. | 101 // List of all the webRequest events. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 ExtensionRendererState::GetInstance()->GetTabAndWindowId( | 215 ExtensionRendererState::GetInstance()->GetTabAndWindowId( |
214 info, tab_id, window_id); | 216 info, tab_id, window_id); |
215 *frame_id = info->GetRenderFrameID(); | 217 *frame_id = info->GetRenderFrameID(); |
216 *is_main_frame = info->IsMainFrame(); | 218 *is_main_frame = info->IsMainFrame(); |
217 *parent_frame_id = info->GetParentRenderFrameID(); | 219 *parent_frame_id = info->GetParentRenderFrameID(); |
218 *parent_is_main_frame = info->ParentIsMainFrame(); | 220 *parent_is_main_frame = info->ParentIsMainFrame(); |
219 *render_process_host_id = info->GetChildID(); | 221 *render_process_host_id = info->GetChildID(); |
220 *routing_id = info->GetRouteID(); | 222 *routing_id = info->GetRouteID(); |
221 | 223 |
222 // Restrict the resource type to the values we care about. | 224 // Restrict the resource type to the values we care about. |
223 if (helpers::IsRelevantResourceType(info->GetResourceType())) | 225 if (utils::IsRelevantResourceType(info->GetResourceType())) |
224 *resource_type = info->GetResourceType(); | 226 *resource_type = info->GetResourceType(); |
225 else | 227 else |
226 *resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 228 *resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
227 } | 229 } |
228 | 230 |
229 // Extracts from |request| information for the keys requestId, url, method, | 231 // Extracts from |request| information for the keys requestId, url, method, |
230 // frameId, tabId, type, and timeStamp and writes these into |out| to be passed | 232 // frameId, tabId, type, and timeStamp and writes these into |out| to be passed |
231 // on to extensions. | 233 // on to extensions. |
232 void ExtractRequestInfo(net::URLRequest* request, base::DictionaryValue* out) { | 234 void ExtractRequestInfo(net::URLRequest* request, base::DictionaryValue* out) { |
233 bool is_main_frame = false; | 235 bool is_main_frame = false; |
(...skipping 15 matching lines...) Expand all Loading... |
249 parent_frame_id_for_extension = GetFrameId(parent_is_main_frame, | 251 parent_frame_id_for_extension = GetFrameId(parent_is_main_frame, |
250 parent_frame_id); | 252 parent_frame_id); |
251 | 253 |
252 out->SetString(keys::kRequestIdKey, | 254 out->SetString(keys::kRequestIdKey, |
253 base::Uint64ToString(request->identifier())); | 255 base::Uint64ToString(request->identifier())); |
254 out->SetString(keys::kUrlKey, request->url().spec()); | 256 out->SetString(keys::kUrlKey, request->url().spec()); |
255 out->SetString(keys::kMethodKey, request->method()); | 257 out->SetString(keys::kMethodKey, request->method()); |
256 out->SetInteger(keys::kFrameIdKey, frame_id_for_extension); | 258 out->SetInteger(keys::kFrameIdKey, frame_id_for_extension); |
257 out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension); | 259 out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension); |
258 out->SetInteger(keys::kTabIdKey, tab_id); | 260 out->SetInteger(keys::kTabIdKey, tab_id); |
259 out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type)); | 261 out->SetString(keys::kTypeKey, utils::ResourceTypeToString(resource_type)); |
260 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); | 262 out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); |
261 } | 263 } |
262 | 264 |
263 // Extracts the body from |request| and writes the data into |out|. | 265 // Extracts the body from |request| and writes the data into |out|. |
264 void ExtractRequestInfoBody(const net::URLRequest* request, | 266 void ExtractRequestInfoBody(const net::URLRequest* request, |
265 base::DictionaryValue* out) { | 267 base::DictionaryValue* out) { |
266 const net::UploadDataStream* upload_data = request->get_upload(); | 268 const net::UploadDataStream* upload_data = request->get_upload(); |
267 if (!upload_data || | 269 if (!upload_data || |
268 (request->method() != "POST" && request->method() != "PUT")) | 270 (request->method() != "POST" && request->method() != "PUT")) |
269 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" . | 271 return; // Need to exit without "out->Set(keys::kRequestBodyKey, ...);" . |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 urls.AddPattern(pattern); | 622 urls.AddPattern(pattern); |
621 } | 623 } |
622 } else if (it.key() == "types") { | 624 } else if (it.key() == "types") { |
623 const base::ListValue* types_value = NULL; | 625 const base::ListValue* types_value = NULL; |
624 if (!it.value().GetAsList(&types_value)) | 626 if (!it.value().GetAsList(&types_value)) |
625 return false; | 627 return false; |
626 for (size_t i = 0; i < types_value->GetSize(); ++i) { | 628 for (size_t i = 0; i < types_value->GetSize(); ++i) { |
627 std::string type_str; | 629 std::string type_str; |
628 ResourceType type; | 630 ResourceType type; |
629 if (!types_value->GetString(i, &type_str) || | 631 if (!types_value->GetString(i, &type_str) || |
630 !helpers::ParseResourceType(type_str, &type)) | 632 !utils::ParseResourceType(type_str, &type)) |
631 return false; | 633 return false; |
632 types.push_back(type); | 634 types.push_back(type); |
633 } | 635 } |
634 } else if (it.key() == "tabId") { | 636 } else if (it.key() == "tabId") { |
635 if (!it.value().GetAsInteger(&tab_id)) | 637 if (!it.value().GetAsInteger(&tab_id)) |
636 return false; | 638 return false; |
637 } else if (it.key() == "windowId") { | 639 } else if (it.key() == "windowId") { |
638 if (!it.value().GetAsInteger(&window_id)) | 640 if (!it.value().GetAsInteger(&window_id)) |
639 return false; | 641 return false; |
640 } else { | 642 } else { |
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2483 extensions::RuntimeData* runtime_data = | 2485 extensions::RuntimeData* runtime_data = |
2484 extensions::ExtensionSystem::Get(profile)->runtime_data(); | 2486 extensions::ExtensionSystem::Get(profile)->runtime_data(); |
2485 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); | 2487 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); |
2486 !webrequest_used && it != extensions.end(); | 2488 !webrequest_used && it != extensions.end(); |
2487 ++it) { | 2489 ++it) { |
2488 webrequest_used |= runtime_data->HasUsedWebRequest(it->get()); | 2490 webrequest_used |= runtime_data->HasUsedWebRequest(it->get()); |
2489 } | 2491 } |
2490 | 2492 |
2491 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used)); | 2493 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used)); |
2492 } | 2494 } |
OLD | NEW |