Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api.cc

Issue 425653002: content: ResourceType cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: REBASE Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 void ExtractRequestInfoDetails(net::URLRequest* request, 197 void ExtractRequestInfoDetails(net::URLRequest* request,
198 bool* is_main_frame, 198 bool* is_main_frame,
199 int* frame_id, 199 int* frame_id,
200 bool* parent_is_main_frame, 200 bool* parent_is_main_frame,
201 int* parent_frame_id, 201 int* parent_frame_id,
202 int* tab_id, 202 int* tab_id,
203 int* window_id, 203 int* window_id,
204 int* render_process_host_id, 204 int* render_process_host_id,
205 int* routing_id, 205 int* routing_id,
206 ResourceType::Type* resource_type) { 206 ResourceType* resource_type) {
207 if (!request->GetUserData(NULL)) 207 if (!request->GetUserData(NULL))
208 return; 208 return;
209 209
210 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 210 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
211 ExtensionRendererState::GetInstance()->GetTabAndWindowId( 211 ExtensionRendererState::GetInstance()->GetTabAndWindowId(
212 info, tab_id, window_id); 212 info, tab_id, window_id);
213 *frame_id = info->GetRenderFrameID(); 213 *frame_id = info->GetRenderFrameID();
214 *is_main_frame = info->IsMainFrame(); 214 *is_main_frame = info->IsMainFrame();
215 *parent_frame_id = info->GetParentRenderFrameID(); 215 *parent_frame_id = info->GetParentRenderFrameID();
216 *parent_is_main_frame = info->ParentIsMainFrame(); 216 *parent_is_main_frame = info->ParentIsMainFrame();
217 *render_process_host_id = info->GetChildID(); 217 *render_process_host_id = info->GetChildID();
218 *routing_id = info->GetRouteID(); 218 *routing_id = info->GetRouteID();
219 219
220 // Restrict the resource type to the values we care about. 220 // Restrict the resource type to the values we care about.
221 if (helpers::IsRelevantResourceType(info->GetResourceType())) 221 if (helpers::IsRelevantResourceType(info->GetResourceType()))
222 *resource_type = info->GetResourceType(); 222 *resource_type = info->GetResourceType();
223 else 223 else
224 *resource_type = ResourceType::LAST_TYPE; 224 *resource_type = content::RESOURCE_TYPE_LAST_TYPE;
225 } 225 }
226 226
227 // Extracts from |request| information for the keys requestId, url, method, 227 // Extracts from |request| information for the keys requestId, url, method,
228 // 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
229 // on to extensions. 229 // on to extensions.
230 void ExtractRequestInfo(net::URLRequest* request, base::DictionaryValue* out) { 230 void ExtractRequestInfo(net::URLRequest* request, base::DictionaryValue* out) {
231 bool is_main_frame = false; 231 bool is_main_frame = false;
232 int frame_id = -1; 232 int frame_id = -1;
233 bool parent_is_main_frame = false; 233 bool parent_is_main_frame = false;
234 int parent_frame_id = -1; 234 int parent_frame_id = -1;
235 int frame_id_for_extension = -1; 235 int frame_id_for_extension = -1;
236 int parent_frame_id_for_extension = -1; 236 int parent_frame_id_for_extension = -1;
237 int tab_id = -1; 237 int tab_id = -1;
238 int window_id = -1; 238 int window_id = -1;
239 int render_process_host_id = -1; 239 int render_process_host_id = -1;
240 int routing_id = -1; 240 int routing_id = -1;
241 ResourceType::Type resource_type = ResourceType::LAST_TYPE; 241 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE;
242 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, 242 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id,
243 &parent_is_main_frame, &parent_frame_id, &tab_id, 243 &parent_is_main_frame, &parent_frame_id, &tab_id,
244 &window_id, &render_process_host_id, &routing_id, 244 &window_id, &render_process_host_id, &routing_id,
245 &resource_type); 245 &resource_type);
246 frame_id_for_extension = GetFrameId(is_main_frame, frame_id); 246 frame_id_for_extension = GetFrameId(is_main_frame, frame_id);
247 parent_frame_id_for_extension = GetFrameId(parent_is_main_frame, 247 parent_frame_id_for_extension = GetFrameId(parent_is_main_frame,
248 parent_frame_id); 248 parent_frame_id);
249 249
250 out->SetString(keys::kRequestIdKey, 250 out->SetString(keys::kRequestIdKey,
251 base::Uint64ToString(request->identifier())); 251 base::Uint64ToString(request->identifier()));
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 return false; 616 return false;
617 } 617 }
618 urls.AddPattern(pattern); 618 urls.AddPattern(pattern);
619 } 619 }
620 } else if (it.key() == "types") { 620 } else if (it.key() == "types") {
621 const base::ListValue* types_value = NULL; 621 const base::ListValue* types_value = NULL;
622 if (!it.value().GetAsList(&types_value)) 622 if (!it.value().GetAsList(&types_value))
623 return false; 623 return false;
624 for (size_t i = 0; i < types_value->GetSize(); ++i) { 624 for (size_t i = 0; i < types_value->GetSize(); ++i) {
625 std::string type_str; 625 std::string type_str;
626 ResourceType::Type type; 626 ResourceType type;
627 if (!types_value->GetString(i, &type_str) || 627 if (!types_value->GetString(i, &type_str) ||
628 !helpers::ParseResourceType(type_str, &type)) 628 !helpers::ParseResourceType(type_str, &type))
629 return false; 629 return false;
630 types.push_back(type); 630 types.push_back(type);
631 } 631 }
632 } else if (it.key() == "tabId") { 632 } else if (it.key() == "tabId") {
633 if (!it.value().GetAsInteger(&tab_id)) 633 if (!it.value().GetAsInteger(&tab_id))
634 return false; 634 return false;
635 } else if (it.key() == "windowId") { 635 } else if (it.key() == "windowId") {
636 if (!it.value().GetAsInteger(&window_id)) 636 if (!it.value().GetAsInteger(&window_id))
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 bool ExtensionWebRequestEventRouter::IsPageLoad( 1405 bool ExtensionWebRequestEventRouter::IsPageLoad(
1406 net::URLRequest* request) const { 1406 net::URLRequest* request) const {
1407 bool is_main_frame = false; 1407 bool is_main_frame = false;
1408 int frame_id = -1; 1408 int frame_id = -1;
1409 bool parent_is_main_frame = false; 1409 bool parent_is_main_frame = false;
1410 int parent_frame_id = -1; 1410 int parent_frame_id = -1;
1411 int tab_id = -1; 1411 int tab_id = -1;
1412 int window_id = -1; 1412 int window_id = -1;
1413 int render_process_host_id = -1; 1413 int render_process_host_id = -1;
1414 int routing_id = -1; 1414 int routing_id = -1;
1415 ResourceType::Type resource_type = ResourceType::LAST_TYPE; 1415 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE;
1416 1416
1417 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, 1417 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id,
1418 &parent_is_main_frame, &parent_frame_id, 1418 &parent_is_main_frame, &parent_frame_id,
1419 &tab_id, &window_id, &render_process_host_id, 1419 &tab_id, &window_id, &render_process_host_id,
1420 &routing_id, &resource_type); 1420 &routing_id, &resource_type);
1421 1421
1422 return resource_type == ResourceType::MAIN_FRAME; 1422 return resource_type == content::RESOURCE_TYPE_MAIN_FRAME;
1423 } 1423 }
1424 1424
1425 void ExtensionWebRequestEventRouter::NotifyPageLoad() { 1425 void ExtensionWebRequestEventRouter::NotifyPageLoad() {
1426 for (CallbacksForPageLoad::const_iterator i = 1426 for (CallbacksForPageLoad::const_iterator i =
1427 callbacks_for_page_load_.begin(); 1427 callbacks_for_page_load_.begin();
1428 i != callbacks_for_page_load_.end(); ++i) { 1428 i != callbacks_for_page_load_.end(); ++i) {
1429 i->Run(); 1429 i->Run();
1430 } 1430 }
1431 callbacks_for_page_load_.clear(); 1431 callbacks_for_page_load_.clear();
1432 } 1432 }
(...skipping 24 matching lines...) Expand all
1457 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl( 1457 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl(
1458 void* profile, 1458 void* profile,
1459 InfoMap* extension_info_map, 1459 InfoMap* extension_info_map,
1460 bool crosses_incognito, 1460 bool crosses_incognito,
1461 const std::string& event_name, 1461 const std::string& event_name,
1462 const GURL& url, 1462 const GURL& url,
1463 int tab_id, 1463 int tab_id,
1464 int window_id, 1464 int window_id,
1465 int render_process_host_id, 1465 int render_process_host_id,
1466 int routing_id, 1466 int routing_id,
1467 ResourceType::Type resource_type, 1467 ResourceType resource_type,
1468 bool is_async_request, 1468 bool is_async_request,
1469 bool is_request_from_extension, 1469 bool is_request_from_extension,
1470 int* extra_info_spec, 1470 int* extra_info_spec,
1471 std::vector<const ExtensionWebRequestEventRouter::EventListener*>* 1471 std::vector<const ExtensionWebRequestEventRouter::EventListener*>*
1472 matching_listeners) { 1472 matching_listeners) {
1473 std::string web_request_event_name(event_name); 1473 std::string web_request_event_name(event_name);
1474 WebViewRendererState::WebViewInfo web_view_info; 1474 WebViewRendererState::WebViewInfo web_view_info;
1475 bool is_web_view_guest = WebViewRendererState::GetInstance()-> 1475 bool is_web_view_guest = WebViewRendererState::GetInstance()->
1476 GetInfo(render_process_host_id, routing_id, &web_view_info); 1476 GetInfo(render_process_host_id, routing_id, &web_view_info);
1477 if (is_web_view_guest) { 1477 if (is_web_view_guest) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 bool blocking_listener = 1513 bool blocking_listener =
1514 (it->extra_info_spec & 1514 (it->extra_info_spec &
1515 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) != 0; 1515 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) != 0;
1516 1516
1517 // We do not want to notify extensions about XHR requests that are 1517 // We do not want to notify extensions about XHR requests that are
1518 // triggered by themselves. This is a workaround to prevent deadlocks 1518 // triggered by themselves. This is a workaround to prevent deadlocks
1519 // in case of synchronous XHR requests that block the extension renderer 1519 // in case of synchronous XHR requests that block the extension renderer
1520 // and therefore prevent the extension from processing the request 1520 // and therefore prevent the extension from processing the request
1521 // handler. This is only a problem for blocking listeners. 1521 // handler. This is only a problem for blocking listeners.
1522 // http://crbug.com/105656 1522 // http://crbug.com/105656
1523 bool synchronous_xhr_from_extension = !is_async_request && 1523 bool synchronous_xhr_from_extension =
1524 is_request_from_extension && resource_type == ResourceType::XHR; 1524 !is_async_request && is_request_from_extension &&
1525 resource_type == content::RESOURCE_TYPE_XHR;
1525 1526
1526 // Only send webRequest events for URLs the extension has access to. 1527 // Only send webRequest events for URLs the extension has access to.
1527 if (blocking_listener && synchronous_xhr_from_extension) 1528 if (blocking_listener && synchronous_xhr_from_extension)
1528 continue; 1529 continue;
1529 1530
1530 matching_listeners->push_back(&(*it)); 1531 matching_listeners->push_back(&(*it));
1531 *extra_info_spec |= it->extra_info_spec; 1532 *extra_info_spec |= it->extra_info_spec;
1532 } 1533 }
1533 } 1534 }
1534 1535
1535 std::vector<const ExtensionWebRequestEventRouter::EventListener*> 1536 std::vector<const ExtensionWebRequestEventRouter::EventListener*>
1536 ExtensionWebRequestEventRouter::GetMatchingListeners( 1537 ExtensionWebRequestEventRouter::GetMatchingListeners(
1537 void* profile, 1538 void* profile,
1538 InfoMap* extension_info_map, 1539 InfoMap* extension_info_map,
1539 const std::string& event_name, 1540 const std::string& event_name,
1540 net::URLRequest* request, 1541 net::URLRequest* request,
1541 int* extra_info_spec) { 1542 int* extra_info_spec) {
1542 // TODO(mpcomplete): handle profile == NULL (should collect all listeners). 1543 // TODO(mpcomplete): handle profile == NULL (should collect all listeners).
1543 *extra_info_spec = 0; 1544 *extra_info_spec = 0;
1544 1545
1545 bool is_main_frame = false; 1546 bool is_main_frame = false;
1546 int frame_id = -1; 1547 int frame_id = -1;
1547 bool parent_is_main_frame = false; 1548 bool parent_is_main_frame = false;
1548 int parent_frame_id = -1; 1549 int parent_frame_id = -1;
1549 int tab_id = -1; 1550 int tab_id = -1;
1550 int window_id = -1; 1551 int window_id = -1;
1551 int render_process_host_id = -1; 1552 int render_process_host_id = -1;
1552 int routing_id = -1; 1553 int routing_id = -1;
1553 ResourceType::Type resource_type = ResourceType::LAST_TYPE; 1554 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE;
1554 const GURL& url = request->url(); 1555 const GURL& url = request->url();
1555 1556
1556 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, 1557 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id,
1557 &parent_is_main_frame, &parent_frame_id, 1558 &parent_is_main_frame, &parent_frame_id,
1558 &tab_id, &window_id, &render_process_host_id, 1559 &tab_id, &window_id, &render_process_host_id,
1559 &routing_id, &resource_type); 1560 &routing_id, &resource_type);
1560 1561
1561 std::vector<const ExtensionWebRequestEventRouter::EventListener*> 1562 std::vector<const ExtensionWebRequestEventRouter::EventListener*>
1562 matching_listeners; 1563 matching_listeners;
1563 1564
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
2482 extensions::RuntimeData* runtime_data = 2483 extensions::RuntimeData* runtime_data =
2483 extensions::ExtensionSystem::Get(profile)->runtime_data(); 2484 extensions::ExtensionSystem::Get(profile)->runtime_data();
2484 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); 2485 for (extensions::ExtensionSet::const_iterator it = extensions.begin();
2485 !webrequest_used && it != extensions.end(); 2486 !webrequest_used && it != extensions.end();
2486 ++it) { 2487 ++it) {
2487 webrequest_used |= runtime_data->HasUsedWebRequest(it->get()); 2488 webrequest_used |= runtime_data->HasUsedWebRequest(it->get());
2488 } 2489 }
2489 2490
2490 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used)); 2491 host->Send(new ExtensionMsg_UsingWebRequestAPI(webrequest_used));
2491 } 2492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698