Chromium Code Reviews| 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 // For non-webviews, ignore the process ID because the extension id and | |
| 453 // subevent name already identifies a listener. This allows for the use | |
| 454 // of find() without specifying the process ID of the extension. | |
| 
 
not at google - send to devlin
2015/08/04 20:27:02
Huh, funky. Where does this actually make a differ
 
robwu
2015/08/04 21:57:24
WebRequestAPI::OnListenerRemoved doesn't provide a
 
not at google - send to devlin
2015/08/04 23:12:02
Makes sense that you're guarding against a bug her
 
robwu
2015/08/05 16:38:08
Done.
 
 | |
| 455 DCHECK(embedder_process_id == 0 || that.embedder_process_id == 0); | |
| 456 return false; | |
| 457 } | |
| 458 | |
| 448 if (embedder_process_id != that.embedder_process_id) | 459 if (embedder_process_id != that.embedder_process_id) | 
| 449 return embedder_process_id < that.embedder_process_id; | 460 return embedder_process_id < that.embedder_process_id; | 
| 450 | 461 | 
| 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; | 462 return false; | 
| 455 } | 463 } | 
| 456 | 464 | 
| 457 EventListener() : | 465 EventListener() : | 
| 458 extra_info_spec(0), | 466 extra_info_spec(0), | 
| 459 embedder_process_id(0), | 467 embedder_process_id(0), | 
| 460 web_view_instance_id(0) {} | 468 web_view_instance_id(0) {} | 
| 461 }; | 469 }; | 
| 462 | 470 | 
| 463 // Contains info about requests that are blocked waiting for a response from | 471 // 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; | 1239 return false; | 
| 1232 } | 1240 } | 
| 1233 | 1241 | 
| 1234 void ExtensionWebRequestEventRouter::OnEventHandled( | 1242 void ExtensionWebRequestEventRouter::OnEventHandled( | 
| 1235 void* browser_context, | 1243 void* browser_context, | 
| 1236 const std::string& extension_id, | 1244 const std::string& extension_id, | 
| 1237 const std::string& event_name, | 1245 const std::string& event_name, | 
| 1238 const std::string& sub_event_name, | 1246 const std::string& sub_event_name, | 
| 1239 uint64 request_id, | 1247 uint64 request_id, | 
| 1240 EventResponse* response) { | 1248 EventResponse* response) { | 
| 1249 // TODO(robwu): Does this also work with webviews? operator< (used by find) | |
| 1250 // takes the webview ID into account, which is not set on |listener|. | |
| 
 
robwu
2015/08/04 16:18:15
Fady / Istiaque: This new TODO item is completely
 
 | |
| 1241 EventListener listener; | 1251 EventListener listener; | 
| 1242 listener.extension_id = extension_id; | 1252 listener.extension_id = extension_id; | 
| 1243 listener.sub_event_name = sub_event_name; | 1253 listener.sub_event_name = sub_event_name; | 
| 1244 | 1254 | 
| 1245 // The listener may have been removed (e.g. due to the process going away) | 1255 // The listener may have been removed (e.g. due to the process going away) | 
| 1246 // before we got here. | 1256 // before we got here. | 
| 1247 std::set<EventListener>::iterator found = | 1257 std::set<EventListener>::iterator found = | 
| 1248 listeners_[browser_context][event_name].find(listener); | 1258 listeners_[browser_context][event_name].find(listener); | 
| 1249 if (found != listeners_[browser_context][event_name].end()) | 1259 if (found != listeners_[browser_context][event_name].end()) | 
| 1250 found->blocked_requests.erase(request_id); | 1260 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 | 1473 // The IPC sender has been deleted. This listener will be removed soon | 
| 1464 // via a call to RemoveEventListener. For now, just skip it. | 1474 // via a call to RemoveEventListener. For now, just skip it. | 
| 1465 continue; | 1475 continue; | 
| 1466 } | 1476 } | 
| 1467 | 1477 | 
| 1468 if (is_web_view_guest && | 1478 if (is_web_view_guest && | 
| 1469 (it->embedder_process_id != web_view_info.embedder_process_id || | 1479 (it->embedder_process_id != web_view_info.embedder_process_id || | 
| 1470 it->web_view_instance_id != web_view_info.instance_id)) | 1480 it->web_view_instance_id != web_view_info.instance_id)) | 
| 1471 continue; | 1481 continue; | 
| 1472 | 1482 | 
| 1483 if (is_request_from_extension && | |
| 
 
not at google - send to devlin
2015/08/04 20:27:02
Comment this ("allow requests from the extension")
 
robwu
2015/08/04 21:57:24
Done.
 
 | |
| 1484 it->embedder_process_id != render_process_host_id) | |
| 1485 continue; | |
| 1486 | |
| 1473 if (!it->filter.urls.is_empty() && !it->filter.urls.MatchesURL(url)) | 1487 if (!it->filter.urls.is_empty() && !it->filter.urls.MatchesURL(url)) | 
| 1474 continue; | 1488 continue; | 
| 1475 if (web_request_event_router_delegate_ && | 1489 if (web_request_event_router_delegate_ && | 
| 1476 web_request_event_router_delegate_->OnGetMatchingListenersImplCheck( | 1490 web_request_event_router_delegate_->OnGetMatchingListenersImplCheck( | 
| 1477 it->filter.tab_id, it->filter.window_id, request)) | 1491 it->filter.tab_id, it->filter.window_id, request)) | 
| 1478 continue; | 1492 continue; | 
| 1479 if (!it->filter.types.empty() && | 1493 if (!it->filter.types.empty() && | 
| 1480 std::find(it->filter.types.begin(), it->filter.types.end(), | 1494 std::find(it->filter.types.begin(), it->filter.types.end(), | 
| 1481 resource_type) == it->filter.types.end()) | 1495 resource_type) == it->filter.types.end()) | 
| 1482 continue; | 1496 continue; | 
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2183 std::string event_name; | 2197 std::string event_name; | 
| 2184 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name)); | 2198 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &event_name)); | 
| 2185 | 2199 | 
| 2186 std::string sub_event_name; | 2200 std::string sub_event_name; | 
| 2187 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name)); | 2201 EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &sub_event_name)); | 
| 2188 | 2202 | 
| 2189 int web_view_instance_id = 0; | 2203 int web_view_instance_id = 0; | 
| 2190 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(5, &web_view_instance_id)); | 2204 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(5, &web_view_instance_id)); | 
| 2191 | 2205 | 
| 2192 base::WeakPtr<IOThreadExtensionMessageFilter> ipc_sender = ipc_sender_weak(); | 2206 base::WeakPtr<IOThreadExtensionMessageFilter> ipc_sender = ipc_sender_weak(); | 
| 2193 int embedder_process_id = | 2207 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 | 2208 | 
| 2197 const Extension* extension = | 2209 const Extension* extension = | 
| 2198 extension_info_map()->extensions().GetByID(extension_id_safe()); | 2210 extension_info_map()->extensions().GetByID(extension_id_safe()); | 
| 2199 std::string extension_name = | 2211 std::string extension_name = | 
| 2200 extension ? extension->name() : extension_id_safe(); | 2212 extension ? extension->name() : extension_id_safe(); | 
| 2201 | 2213 | 
| 2202 if (!web_view_instance_id) { | 2214 if (!web_view_instance_id) { | 
| 2203 // We check automatically whether the extension has the 'webRequest' | 2215 // We check automatically whether the extension has the 'webRequest' | 
| 2204 // permission. For blocking calls we require the additional permission | 2216 // permission. For blocking calls we require the additional permission | 
| 2205 // 'webRequestBlocking'. | 2217 // 'webRequestBlocking'. | 
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2438 // Continue gracefully. | 2450 // Continue gracefully. | 
| 2439 RunSync(); | 2451 RunSync(); | 
| 2440 } | 2452 } | 
| 2441 | 2453 | 
| 2442 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { | 2454 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { | 
| 2443 helpers::ClearCacheOnNavigation(); | 2455 helpers::ClearCacheOnNavigation(); | 
| 2444 return true; | 2456 return true; | 
| 2445 } | 2457 } | 
| 2446 | 2458 | 
| 2447 } // namespace extensions | 2459 } // namespace extensions | 
| OLD | NEW |