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 "extensions/browser/api/web_request/web_request_api.h" | 5 #include "extensions/browser/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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 // <webview> events will be removed in RemoveWebViewEventListeners. Ideally, | 409 // <webview> events will be removed in RemoveWebViewEventListeners. Ideally, |
410 // this code should be decoupled from extensions, we should use the host ID | 410 // this code should be decoupled from extensions, we should use the host ID |
411 // instead, and not have two different code paths. This is a huge undertaking | 411 // instead, and not have two different code paths. This is a huge undertaking |
412 // unfortunately, so we'll resort to two code paths for now. | 412 // unfortunately, so we'll resort to two code paths for now. |
413 BrowserThread::PostTask(BrowserThread::IO, | 413 BrowserThread::PostTask(BrowserThread::IO, |
414 FROM_HERE, | 414 FROM_HERE, |
415 base::Bind(&RemoveEventListenerOnIOThread, | 415 base::Bind(&RemoveEventListenerOnIOThread, |
416 details.browser_context, | 416 details.browser_context, |
417 details.extension_id, | 417 details.extension_id, |
418 details.event_name, | 418 details.event_name, |
419 0 /* embedder_process_id */, | 419 0 /* embedder_process_id (ignored) */, |
420 0 /* web_view_instance_id */)); | 420 0 /* web_view_instance_id */)); |
421 } | 421 } |
422 | 422 |
423 // Represents a single unique listener to an event, along with whatever filter | 423 // Represents a single unique listener to an event, along with whatever filter |
424 // parameters and extra_info_spec were specified at the time the listener was | 424 // parameters and extra_info_spec were specified at the time the listener was |
425 // added. | 425 // added. |
426 // NOTE(benjhayden) New APIs should not use this sub_event_name trick! It does | 426 // NOTE(benjhayden) New APIs should not use this sub_event_name trick! It does |
427 // not play well with event pages. See downloads.onDeterminingFilename and | 427 // not play well with event pages. See downloads.onDeterminingFilename and |
428 // ExtensionDownloadsEventRouter for an alternative approach. | 428 // ExtensionDownloadsEventRouter for an alternative approach. |
429 struct ExtensionWebRequestEventRouter::EventListener { | 429 struct ExtensionWebRequestEventRouter::EventListener { |
430 std::string extension_id; | 430 std::string extension_id; |
431 std::string extension_name; | 431 std::string extension_name; |
432 std::string sub_event_name; | 432 std::string sub_event_name; |
433 RequestFilter filter; | 433 RequestFilter filter; |
434 int extra_info_spec; | 434 int extra_info_spec; |
435 int embedder_process_id; | 435 int embedder_process_id; |
436 int web_view_instance_id; | 436 int web_view_instance_id; |
437 base::WeakPtr<IPC::Sender> ipc_sender; | 437 base::WeakPtr<IPC::Sender> ipc_sender; |
438 mutable std::set<uint64> blocked_requests; | 438 mutable std::set<uint64> blocked_requests; |
439 | 439 |
440 // Comparator to work with std::set. | 440 // Comparator to work with std::set. |
441 bool operator<(const EventListener& that) const { | 441 bool operator<(const EventListener& that) const { |
442 if (extension_id != that.extension_id) | 442 if (extension_id != that.extension_id) |
443 return extension_id < that.extension_id; | 443 return extension_id < that.extension_id; |
444 | 444 |
445 if (sub_event_name != that.sub_event_name) | 445 if (sub_event_name != that.sub_event_name) |
446 return sub_event_name < that.sub_event_name; | 446 return sub_event_name < that.sub_event_name; |
447 | 447 |
448 if (web_view_instance_id != that.web_view_instance_id) | |
449 return web_view_instance_id < that.web_view_instance_id; | |
450 | |
451 if (web_view_instance_id == 0) { | |
452 // Do not filter by process ID for non-webviews, because this comparator | |
453 // is also used to find and remove an event listener when an extension is | |
454 // unloaded. At this point, the event listener cannot be mapped back to | |
455 // the original process, so 0 is used instead of the actual process ID. | |
456 DCHECK(embedder_process_id == 0 || that.embedder_process_id == 0); | |
457 return false; | |
458 } | |
459 | |
448 if (embedder_process_id != that.embedder_process_id) | 460 if (embedder_process_id != that.embedder_process_id) |
449 return embedder_process_id < that.embedder_process_id; | 461 return embedder_process_id < that.embedder_process_id; |
450 | 462 |
451 if (web_view_instance_id != that.web_view_instance_id) | |
452 return web_view_instance_id < that.web_view_instance_id; | |
453 | |
454 return false; | 463 return false; |
455 } | 464 } |
456 | 465 |
457 EventListener() : | 466 EventListener() : |
458 extra_info_spec(0), | 467 extra_info_spec(0), |
459 embedder_process_id(0), | 468 embedder_process_id(0), |
460 web_view_instance_id(0) {} | 469 web_view_instance_id(0) {} |
461 }; | 470 }; |
462 | 471 |
463 // Contains info about requests that are blocked waiting for a response from | 472 // Contains info about requests that are blocked waiting for a response from |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1231 return false; | 1240 return false; |
1232 } | 1241 } |
1233 | 1242 |
1234 void ExtensionWebRequestEventRouter::OnEventHandled( | 1243 void ExtensionWebRequestEventRouter::OnEventHandled( |
1235 void* browser_context, | 1244 void* browser_context, |
1236 const std::string& extension_id, | 1245 const std::string& extension_id, |
1237 const std::string& event_name, | 1246 const std::string& event_name, |
1238 const std::string& sub_event_name, | 1247 const std::string& sub_event_name, |
1239 uint64 request_id, | 1248 uint64 request_id, |
1240 EventResponse* response) { | 1249 EventResponse* response) { |
1250 // TODO(robwu): Does this also work with webviews? operator< (used by find) | |
1251 // takes the webview ID into account, which is not set on |listener|. | |
1241 EventListener listener; | 1252 EventListener listener; |
1242 listener.extension_id = extension_id; | 1253 listener.extension_id = extension_id; |
1243 listener.sub_event_name = sub_event_name; | 1254 listener.sub_event_name = sub_event_name; |
1244 | 1255 |
1245 // The listener may have been removed (e.g. due to the process going away) | 1256 // The listener may have been removed (e.g. due to the process going away) |
1246 // before we got here. | 1257 // before we got here. |
1247 std::set<EventListener>::iterator found = | 1258 std::set<EventListener>::iterator found = |
1248 listeners_[browser_context][event_name].find(listener); | 1259 listeners_[browser_context][event_name].find(listener); |
1249 if (found != listeners_[browser_context][event_name].end()) | 1260 if (found != listeners_[browser_context][event_name].end()) |
1250 found->blocked_requests.erase(request_id); | 1261 found->blocked_requests.erase(request_id); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1463 // The IPC sender has been deleted. This listener will be removed soon | 1474 // The IPC sender has been deleted. This listener will be removed soon |
1464 // via a call to RemoveEventListener. For now, just skip it. | 1475 // via a call to RemoveEventListener. For now, just skip it. |
1465 continue; | 1476 continue; |
1466 } | 1477 } |
1467 | 1478 |
1468 if (is_web_view_guest && | 1479 if (is_web_view_guest && |
1469 (it->embedder_process_id != web_view_info.embedder_process_id || | 1480 (it->embedder_process_id != web_view_info.embedder_process_id || |
1470 it->web_view_instance_id != web_view_info.instance_id)) | 1481 it->web_view_instance_id != web_view_info.instance_id)) |
1471 continue; | 1482 continue; |
1472 | 1483 |
1484 // Filter requests from other extensions / apps. This does not work for | |
1485 // content scripts, or extension pages in non-extension processes. | |
battre
2015/08/05 13:49:46
Also extensions can be hosted in the same process.
robwu
2015/08/05 16:38:09
You mean another extension within some webRequest
not at google - send to devlin
2015/08/05 16:49:59
I think the question is can extensions share a ren
| |
1486 if (is_request_from_extension && | |
1487 it->embedder_process_id != render_process_host_id) | |
1488 continue; | |
1489 | |
1473 if (!it->filter.urls.is_empty() && !it->filter.urls.MatchesURL(url)) | 1490 if (!it->filter.urls.is_empty() && !it->filter.urls.MatchesURL(url)) |
1474 continue; | 1491 continue; |
1475 if (web_request_event_router_delegate_ && | 1492 if (web_request_event_router_delegate_ && |
1476 web_request_event_router_delegate_->OnGetMatchingListenersImplCheck( | 1493 web_request_event_router_delegate_->OnGetMatchingListenersImplCheck( |
1477 it->filter.tab_id, it->filter.window_id, request)) | 1494 it->filter.tab_id, it->filter.window_id, request)) |
1478 continue; | 1495 continue; |
1479 if (!it->filter.types.empty() && | 1496 if (!it->filter.types.empty() && |
1480 std::find(it->filter.types.begin(), it->filter.types.end(), | 1497 std::find(it->filter.types.begin(), it->filter.types.end(), |
1481 resource_type) == it->filter.types.end()) | 1498 resource_type) == it->filter.types.end()) |
1482 continue; | 1499 continue; |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2183 std::string event_name; | 2200 std::string event_name; |
2184 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name)); | 2201 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name)); |
2185 | 2202 |
2186 std::string sub_event_name; | 2203 std::string sub_event_name; |
2187 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name)); | 2204 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name)); |
2188 | 2205 |
2189 int web_view_instance_id = 0; | 2206 int web_view_instance_id = 0; |
2190 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(5, &web_view_instance_id)); | 2207 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(5, &web_view_instance_id)); |
2191 | 2208 |
2192 base::WeakPtr<IOThreadExtensionMessageFilter> ipc_sender = ipc_sender_weak(); | 2209 base::WeakPtr<IOThreadExtensionMessageFilter> ipc_sender = ipc_sender_weak(); |
2193 int embedder_process_id = | 2210 int embedder_process_id = ipc_sender ? ipc_sender->render_process_id() : 0; |
2194 ipc_sender.get() && web_view_instance_id > 0 ? | |
2195 ipc_sender->render_process_id() : 0; | |
2196 | 2211 |
2197 const Extension* extension = | 2212 const Extension* extension = |
2198 extension_info_map()->extensions().GetByID(extension_id_safe()); | 2213 extension_info_map()->extensions().GetByID(extension_id_safe()); |
2199 std::string extension_name = | 2214 std::string extension_name = |
2200 extension ? extension->name() : extension_id_safe(); | 2215 extension ? extension->name() : extension_id_safe(); |
2201 | 2216 |
2202 if (!web_view_instance_id) { | 2217 if (!web_view_instance_id) { |
2203 // We check automatically whether the extension has the 'webRequest' | 2218 // We check automatically whether the extension has the 'webRequest' |
2204 // permission. For blocking calls we require the additional permission | 2219 // permission. For blocking calls we require the additional permission |
2205 // 'webRequestBlocking'. | 2220 // 'webRequestBlocking'. |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2438 // Continue gracefully. | 2453 // Continue gracefully. |
2439 RunSync(); | 2454 RunSync(); |
2440 } | 2455 } |
2441 | 2456 |
2442 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { | 2457 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { |
2443 helpers::ClearCacheOnNavigation(); | 2458 helpers::ClearCacheOnNavigation(); |
2444 return true; | 2459 return true; |
2445 } | 2460 } |
2446 | 2461 |
2447 } // namespace extensions | 2462 } // namespace extensions |
OLD | NEW |