| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return keys::kOnResponseStarted; | 131 return keys::kOnResponseStarted; |
| 132 case ExtensionWebRequestEventRouter::kOnErrorOccurred: | 132 case ExtensionWebRequestEventRouter::kOnErrorOccurred: |
| 133 return keys::kOnErrorOccurred; | 133 return keys::kOnErrorOccurred; |
| 134 case ExtensionWebRequestEventRouter::kOnCompleted: | 134 case ExtensionWebRequestEventRouter::kOnCompleted: |
| 135 return keys::kOnCompleted; | 135 return keys::kOnCompleted; |
| 136 } | 136 } |
| 137 NOTREACHED(); | 137 NOTREACHED(); |
| 138 return "Not reached"; | 138 return "Not reached"; |
| 139 } | 139 } |
| 140 | 140 |
| 141 // TODO(dcheng): Fix plumbing. Frame ID is not an int64--it's just an int. | 141 int GetFrameId(bool is_main_frame, int frame_id) { |
| 142 int GetFrameId(bool is_main_frame, int64 frame_id) { | 142 return is_main_frame ? 0 : frame_id; |
| 143 return is_main_frame ? 0 : static_cast<int>(frame_id); | |
| 144 } | 143 } |
| 145 | 144 |
| 146 bool IsWebRequestEvent(const std::string& event_name) { | 145 bool IsWebRequestEvent(const std::string& event_name) { |
| 147 std::string web_request_event_name(event_name); | 146 std::string web_request_event_name(event_name); |
| 148 if (StartsWithASCII( | 147 if (StartsWithASCII( |
| 149 web_request_event_name, webview::kWebViewEventPrefix, true)) { | 148 web_request_event_name, webview::kWebViewEventPrefix, true)) { |
| 150 web_request_event_name.replace( | 149 web_request_event_name.replace( |
| 151 0, strlen(webview::kWebViewEventPrefix), kWebRequestEventPrefix); | 150 0, strlen(webview::kWebViewEventPrefix), kWebRequestEventPrefix); |
| 152 } | 151 } |
| 153 return std::find(kWebRequestEvents, ARRAYEND(kWebRequestEvents), | 152 return std::find(kWebRequestEvents, ARRAYEND(kWebRequestEvents), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 WebViewRendererState::WebViewInfo* web_view_info) { | 189 WebViewRendererState::WebViewInfo* web_view_info) { |
| 191 int render_process_host_id = -1; | 190 int render_process_host_id = -1; |
| 192 int routing_id = -1; | 191 int routing_id = -1; |
| 193 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id); | 192 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id); |
| 194 return WebViewRendererState::GetInstance()-> | 193 return WebViewRendererState::GetInstance()-> |
| 195 GetInfo(render_process_host_id, routing_id, web_view_info); | 194 GetInfo(render_process_host_id, routing_id, web_view_info); |
| 196 } | 195 } |
| 197 | 196 |
| 198 void ExtractRequestInfoDetails(net::URLRequest* request, | 197 void ExtractRequestInfoDetails(net::URLRequest* request, |
| 199 bool* is_main_frame, | 198 bool* is_main_frame, |
| 200 int64* frame_id, | 199 int* frame_id, |
| 201 bool* parent_is_main_frame, | 200 bool* parent_is_main_frame, |
| 202 int64* parent_frame_id, | 201 int* parent_frame_id, |
| 203 int* tab_id, | 202 int* tab_id, |
| 204 int* window_id, | 203 int* window_id, |
| 205 int* render_process_host_id, | 204 int* render_process_host_id, |
| 206 int* routing_id, | 205 int* routing_id, |
| 207 ResourceType::Type* resource_type) { | 206 ResourceType::Type* resource_type) { |
| 208 if (!request->GetUserData(NULL)) | 207 if (!request->GetUserData(NULL)) |
| 209 return; | 208 return; |
| 210 | 209 |
| 211 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 210 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 212 ExtensionRendererState::GetInstance()->GetTabAndWindowId( | 211 ExtensionRendererState::GetInstance()->GetTabAndWindowId( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 223 *resource_type = info->GetResourceType(); | 222 *resource_type = info->GetResourceType(); |
| 224 else | 223 else |
| 225 *resource_type = ResourceType::LAST_TYPE; | 224 *resource_type = ResourceType::LAST_TYPE; |
| 226 } | 225 } |
| 227 | 226 |
| 228 // Extracts from |request| information for the keys requestId, url, method, | 227 // Extracts from |request| information for the keys requestId, url, method, |
| 229 // frameId, tabId, type, and timeStamp and writes these into |out| to be passed | 228 // frameId, tabId, type, and timeStamp and writes these into |out| to be passed |
| 230 // on to extensions. | 229 // on to extensions. |
| 231 void ExtractRequestInfo(net::URLRequest* request, base::DictionaryValue* out) { | 230 void ExtractRequestInfo(net::URLRequest* request, base::DictionaryValue* out) { |
| 232 bool is_main_frame = false; | 231 bool is_main_frame = false; |
| 233 int64 frame_id = -1; | 232 int frame_id = -1; |
| 234 bool parent_is_main_frame = false; | 233 bool parent_is_main_frame = false; |
| 235 int64 parent_frame_id = -1; | 234 int parent_frame_id = -1; |
| 236 int frame_id_for_extension = -1; | 235 int frame_id_for_extension = -1; |
| 237 int parent_frame_id_for_extension = -1; | 236 int parent_frame_id_for_extension = -1; |
| 238 int tab_id = -1; | 237 int tab_id = -1; |
| 239 int window_id = -1; | 238 int window_id = -1; |
| 240 int render_process_host_id = -1; | 239 int render_process_host_id = -1; |
| 241 int routing_id = -1; | 240 int routing_id = -1; |
| 242 ResourceType::Type resource_type = ResourceType::LAST_TYPE; | 241 ResourceType::Type resource_type = ResourceType::LAST_TYPE; |
| 243 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 242 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 244 &parent_is_main_frame, &parent_frame_id, &tab_id, | 243 &parent_is_main_frame, &parent_frame_id, &tab_id, |
| 245 &window_id, &render_process_host_id, &routing_id, | 244 &window_id, &render_process_host_id, &routing_id, |
| (...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 } | 1398 } |
| 1400 | 1399 |
| 1401 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad( | 1400 void ExtensionWebRequestEventRouter::AddCallbackForPageLoad( |
| 1402 const base::Closure& callback) { | 1401 const base::Closure& callback) { |
| 1403 callbacks_for_page_load_.push_back(callback); | 1402 callbacks_for_page_load_.push_back(callback); |
| 1404 } | 1403 } |
| 1405 | 1404 |
| 1406 bool ExtensionWebRequestEventRouter::IsPageLoad( | 1405 bool ExtensionWebRequestEventRouter::IsPageLoad( |
| 1407 net::URLRequest* request) const { | 1406 net::URLRequest* request) const { |
| 1408 bool is_main_frame = false; | 1407 bool is_main_frame = false; |
| 1409 int64 frame_id = -1; | 1408 int frame_id = -1; |
| 1410 bool parent_is_main_frame = false; | 1409 bool parent_is_main_frame = false; |
| 1411 int64 parent_frame_id = -1; | 1410 int parent_frame_id = -1; |
| 1412 int tab_id = -1; | 1411 int tab_id = -1; |
| 1413 int window_id = -1; | 1412 int window_id = -1; |
| 1414 int render_process_host_id = -1; | 1413 int render_process_host_id = -1; |
| 1415 int routing_id = -1; | 1414 int routing_id = -1; |
| 1416 ResourceType::Type resource_type = ResourceType::LAST_TYPE; | 1415 ResourceType::Type resource_type = ResourceType::LAST_TYPE; |
| 1417 | 1416 |
| 1418 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 1417 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 1419 &parent_is_main_frame, &parent_frame_id, | 1418 &parent_is_main_frame, &parent_frame_id, |
| 1420 &tab_id, &window_id, &render_process_host_id, | 1419 &tab_id, &window_id, &render_process_host_id, |
| 1421 &routing_id, &resource_type); | 1420 &routing_id, &resource_type); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1537 ExtensionWebRequestEventRouter::GetMatchingListeners( | 1536 ExtensionWebRequestEventRouter::GetMatchingListeners( |
| 1538 void* profile, | 1537 void* profile, |
| 1539 InfoMap* extension_info_map, | 1538 InfoMap* extension_info_map, |
| 1540 const std::string& event_name, | 1539 const std::string& event_name, |
| 1541 net::URLRequest* request, | 1540 net::URLRequest* request, |
| 1542 int* extra_info_spec) { | 1541 int* extra_info_spec) { |
| 1543 // TODO(mpcomplete): handle profile == NULL (should collect all listeners). | 1542 // TODO(mpcomplete): handle profile == NULL (should collect all listeners). |
| 1544 *extra_info_spec = 0; | 1543 *extra_info_spec = 0; |
| 1545 | 1544 |
| 1546 bool is_main_frame = false; | 1545 bool is_main_frame = false; |
| 1547 int64 frame_id = -1; | 1546 int frame_id = -1; |
| 1548 bool parent_is_main_frame = false; | 1547 bool parent_is_main_frame = false; |
| 1549 int64 parent_frame_id = -1; | 1548 int parent_frame_id = -1; |
| 1550 int tab_id = -1; | 1549 int tab_id = -1; |
| 1551 int window_id = -1; | 1550 int window_id = -1; |
| 1552 int render_process_host_id = -1; | 1551 int render_process_host_id = -1; |
| 1553 int routing_id = -1; | 1552 int routing_id = -1; |
| 1554 ResourceType::Type resource_type = ResourceType::LAST_TYPE; | 1553 ResourceType::Type resource_type = ResourceType::LAST_TYPE; |
| 1555 const GURL& url = request->url(); | 1554 const GURL& url = request->url(); |
| 1556 | 1555 |
| 1557 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 1556 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 1558 &parent_is_main_frame, &parent_frame_id, | 1557 &parent_is_main_frame, &parent_frame_id, |
| 1559 &tab_id, &window_id, &render_process_host_id, | 1558 &tab_id, &window_id, &render_process_host_id, |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2481 extensions::RuntimeData* runtime_data = | 2480 extensions::RuntimeData* runtime_data = |
| 2482 extensions::ExtensionSystem::Get(profile)->runtime_data(); | 2481 extensions::ExtensionSystem::Get(profile)->runtime_data(); |
| 2483 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); | 2482 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); |
| 2484 !webrequest_used && it != extensions.end(); | 2483 !webrequest_used && it != extensions.end(); |
| 2485 ++it) { | 2484 ++it) { |
| 2486 webrequest_used |= runtime_data->HasUsedWebRequest(it->get()); | 2485 webrequest_used |= runtime_data->HasUsedWebRequest(it->get()); |
| 2487 } | 2486 } |
| 2488 | 2487 |
| 2489 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used)); | 2488 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used)); |
| 2490 } | 2489 } |
| OLD | NEW |