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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 } | 140 } |
141 const auto web_request_events_end = | 141 const auto web_request_events_end = |
142 kWebRequestEvents + arraysize(kWebRequestEvents); | 142 kWebRequestEvents + arraysize(kWebRequestEvents); |
143 return std::find(kWebRequestEvents, web_request_events_end, | 143 return std::find(kWebRequestEvents, web_request_events_end, |
144 web_request_event_name) != web_request_events_end; | 144 web_request_event_name) != web_request_events_end; |
145 } | 145 } |
146 | 146 |
147 // Returns whether |request| has been triggered by an extension in | 147 // Returns whether |request| has been triggered by an extension in |
148 // |extension_info_map|. | 148 // |extension_info_map|. |
149 bool IsRequestFromExtension(const net::URLRequest* request, | 149 bool IsRequestFromExtension(const net::URLRequest* request, |
150 const InfoMap* extension_info_map) { | 150 const InfoMap* extension_info_map, |
151 void* browser_context_id) { | |
151 // |extension_info_map| is NULL for system-level requests. | 152 // |extension_info_map| is NULL for system-level requests. |
152 if (!extension_info_map) | 153 if (!extension_info_map) |
153 return false; | 154 return false; |
154 | 155 |
155 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 156 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
156 | 157 |
157 // If this request was not created by the ResourceDispatcher, |info| is NULL. | 158 // If this request was not created by the ResourceDispatcher, |info| is NULL. |
158 // All requests from extensions are created by the ResourceDispatcher. | 159 // All requests from extensions are created by the ResourceDispatcher. |
159 if (!info) | 160 if (!info) |
160 return false; | 161 return false; |
161 | 162 |
162 return extension_info_map->process_map().Contains(info->GetChildID()); | 163 const std::set<std::string> extension_ids = |
164 extension_info_map->process_map().GetExtensionsInProcess( | |
165 info->GetChildID()); | |
166 if (extension_ids.empty()) | |
167 return false; | |
168 | |
169 content::BrowserContext* browser_context = | |
170 reinterpret_cast<content::BrowserContext*>(browser_context_id); | |
171 if (browser_context) { | |
robwu
2015/09/05 17:29:10
I'm not sure whether it is safe to use |browser_co
not at google - send to devlin
2015/09/08 16:09:20
It's not valid to use the BrowserContext on the IO
robwu
2015/09/08 17:19:48
Yes, of course.
| |
172 // Hosted apps are like normal web pages (crbug.com/526413). | |
173 const ExtensionSet& enabled_extensions = | |
174 ExtensionRegistry::Get(browser_context)->enabled_extensions(); | |
175 for (const std::string& extension_id : extension_ids) { | |
176 const Extension* extension = enabled_extensions.GetByID(extension_id); | |
177 if (extension && !extension->is_hosted_app()) | |
178 return true; | |
179 } | |
180 } | |
181 return false; | |
163 } | 182 } |
164 | 183 |
165 void ExtractRequestRoutingInfo(const net::URLRequest* request, | 184 void ExtractRequestRoutingInfo(const net::URLRequest* request, |
166 int* render_process_host_id, | 185 int* render_process_host_id, |
167 int* routing_id) { | 186 int* routing_id) { |
168 if (!request->GetUserData(NULL)) | 187 if (!request->GetUserData(NULL)) |
169 return; | 188 return; |
170 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 189 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
171 *render_process_host_id = info->GetChildID(); | 190 *render_process_host_id = info->GetChildID(); |
172 *routing_id = info->GetRouteID(); | 191 *routing_id = info->GetRouteID(); |
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1580 int routing_id = -1; | 1599 int routing_id = -1; |
1581 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 1600 ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
1582 const GURL& url = request->url(); | 1601 const GURL& url = request->url(); |
1583 | 1602 |
1584 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | 1603 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
1585 &parent_is_main_frame, &parent_frame_id, | 1604 &parent_is_main_frame, &parent_frame_id, |
1586 &render_process_host_id, | 1605 &render_process_host_id, |
1587 &routing_id, &resource_type); | 1606 &routing_id, &resource_type); |
1588 | 1607 |
1589 bool is_request_from_extension = | 1608 bool is_request_from_extension = |
1590 IsRequestFromExtension(request, extension_info_map); | 1609 IsRequestFromExtension(request, extension_info_map, browser_context); |
1591 | 1610 |
1592 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 1611 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
1593 // We are conservative here and assume requests are asynchronous in case | 1612 // We are conservative here and assume requests are asynchronous in case |
1594 // we don't have an info object. We don't want to risk a deadlock. | 1613 // we don't have an info object. We don't want to risk a deadlock. |
1595 bool is_async_request = !info || info->IsAsync(); | 1614 bool is_async_request = !info || info->IsAsync(); |
1596 | 1615 |
1597 EventListeners matching_listeners; | 1616 EventListeners matching_listeners; |
1598 GetMatchingListenersImpl( | 1617 GetMatchingListenersImpl( |
1599 browser_context, request, extension_info_map, false, event_name, | 1618 browser_context, request, extension_info_map, false, event_name, |
1600 url, render_process_host_id, routing_id, resource_type, | 1619 url, render_process_host_id, routing_id, resource_type, |
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2469 // Continue gracefully. | 2488 // Continue gracefully. |
2470 RunSync(); | 2489 RunSync(); |
2471 } | 2490 } |
2472 | 2491 |
2473 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { | 2492 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { |
2474 helpers::ClearCacheOnNavigation(); | 2493 helpers::ClearCacheOnNavigation(); |
2475 return true; | 2494 return true; |
2476 } | 2495 } |
2477 | 2496 |
2478 } // namespace extensions | 2497 } // namespace extensions |
OLD | NEW |