| 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/webrequest/webrequest_api.h" | 5 #include "chrome/browser/extensions/api/webrequest/webrequest_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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/profiles/profile_manager.h" | 28 #include "chrome/browser/profiles/profile_manager.h" |
| 29 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 29 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
| 30 #include "chrome/browser/renderer_host/web_cache_manager.h" | 30 #include "chrome/browser/renderer_host/web_cache_manager.h" |
| 31 #include "chrome/common/extensions/extension.h" | 31 #include "chrome/common/extensions/extension.h" |
| 32 #include "chrome/common/extensions/extension_constants.h" | 32 #include "chrome/common/extensions/extension_constants.h" |
| 33 #include "chrome/common/extensions/extension_error_utils.h" | 33 #include "chrome/common/extensions/extension_error_utils.h" |
| 34 #include "chrome/common/extensions/extension_messages.h" | 34 #include "chrome/common/extensions/extension_messages.h" |
| 35 #include "chrome/common/extensions/url_pattern.h" | 35 #include "chrome/common/extensions/url_pattern.h" |
| 36 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
| 37 #include "content/browser/renderer_host/resource_dispatcher_host.h" | |
| 38 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | |
| 39 #include "content/public/browser/browser_message_filter.h" | 37 #include "content/public/browser/browser_message_filter.h" |
| 40 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
| 40 #include "content/public/browser/resource_request_info.h" |
| 42 #include "googleurl/src/gurl.h" | 41 #include "googleurl/src/gurl.h" |
| 43 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
| 44 #include "net/base/auth.h" | 43 #include "net/base/auth.h" |
| 45 #include "net/base/net_errors.h" | 44 #include "net/base/net_errors.h" |
| 46 #include "net/base/net_log.h" | 45 #include "net/base/net_log.h" |
| 47 #include "net/http/http_response_headers.h" | 46 #include "net/http/http_response_headers.h" |
| 48 #include "net/url_request/url_request.h" | 47 #include "net/url_request/url_request.h" |
| 49 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
| 50 | 49 |
| 51 using content::BrowserMessageFilter; | 50 using content::BrowserMessageFilter; |
| 52 using content::BrowserThread; | 51 using content::BrowserThread; |
| 52 using content::ResourceRequestInfo; |
| 53 | 53 |
| 54 namespace helpers = extension_webrequest_api_helpers; | 54 namespace helpers = extension_webrequest_api_helpers; |
| 55 namespace keys = extension_webrequest_api_constants; | 55 namespace keys = extension_webrequest_api_constants; |
| 56 | 56 |
| 57 namespace { | 57 namespace { |
| 58 | 58 |
| 59 // List of all the webRequest events. | 59 // List of all the webRequest events. |
| 60 static const char* const kWebRequestEvents[] = { | 60 static const char* const kWebRequestEvents[] = { |
| 61 keys::kOnBeforeRedirect, | 61 keys::kOnBeforeRedirect, |
| 62 keys::kOnBeforeRequest, | 62 keys::kOnBeforeRequest, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Returns whether |request| has been triggered by an extension in | 121 // Returns whether |request| has been triggered by an extension in |
| 122 // |extension_info_map|. | 122 // |extension_info_map|. |
| 123 bool IsRequestFromExtension(const net::URLRequest* request, | 123 bool IsRequestFromExtension(const net::URLRequest* request, |
| 124 const ExtensionInfoMap* extension_info_map) { | 124 const ExtensionInfoMap* extension_info_map) { |
| 125 // |extension_info_map| is NULL for system-level requests. | 125 // |extension_info_map| is NULL for system-level requests. |
| 126 if (!extension_info_map) | 126 if (!extension_info_map) |
| 127 return false; | 127 return false; |
| 128 | 128 |
| 129 const ResourceDispatcherHostRequestInfo* info = | 129 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 130 ResourceDispatcherHost::InfoForRequest(request); | |
| 131 | 130 |
| 132 // If this request was not created by the ResourceDispatcher, |info| is NULL. | 131 // If this request was not created by the ResourceDispatcher, |info| is NULL. |
| 133 // All requests from extensions are created by the ResourceDispatcher. | 132 // All requests from extensions are created by the ResourceDispatcher. |
| 134 if (!info) | 133 if (!info) |
| 135 return false; | 134 return false; |
| 136 | 135 |
| 137 return extension_info_map->process_map().Contains(info->child_id()); | 136 return extension_info_map->process_map().Contains(info->child_id()); |
| 138 } | 137 } |
| 139 | 138 |
| 140 // Returns true if the URL is sensitive and requests to this URL must not be | 139 // Returns true if the URL is sensitive and requests to this URL must not be |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 bool* is_main_frame, | 201 bool* is_main_frame, |
| 203 int64* frame_id, | 202 int64* frame_id, |
| 204 bool* parent_is_main_frame, | 203 bool* parent_is_main_frame, |
| 205 int64* parent_frame_id, | 204 int64* parent_frame_id, |
| 206 int* tab_id, | 205 int* tab_id, |
| 207 int* window_id, | 206 int* window_id, |
| 208 ResourceType::Type* resource_type) { | 207 ResourceType::Type* resource_type) { |
| 209 if (!request->GetUserData(NULL)) | 208 if (!request->GetUserData(NULL)) |
| 210 return; | 209 return; |
| 211 | 210 |
| 212 ResourceDispatcherHostRequestInfo* info = | 211 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 213 ResourceDispatcherHost::InfoForRequest(request); | |
| 214 ExtensionTabIdMap::GetInstance()->GetTabAndWindowId( | 212 ExtensionTabIdMap::GetInstance()->GetTabAndWindowId( |
| 215 info->child_id(), info->route_id(), tab_id, window_id); | 213 info->child_id(), info->route_id(), tab_id, window_id); |
| 216 *frame_id = info->frame_id(); | 214 *frame_id = info->frame_id(); |
| 217 *is_main_frame = info->is_main_frame(); | 215 *is_main_frame = info->is_main_frame(); |
| 218 *parent_frame_id = info->parent_frame_id(); | 216 *parent_frame_id = info->parent_frame_id(); |
| 219 *parent_is_main_frame = info->parent_is_main_frame(); | 217 *parent_is_main_frame = info->parent_is_main_frame(); |
| 220 | 218 |
| 221 // Restrict the resource type to the values we care about. | 219 // Restrict the resource type to the values we care about. |
| 222 ResourceType::Type* iter = | 220 ResourceType::Type* iter = |
| 223 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), | 221 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), |
| (...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 1737 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
| 1740 adblock = true; | 1738 adblock = true; |
| 1741 } else { | 1739 } else { |
| 1742 other = true; | 1740 other = true; |
| 1743 } | 1741 } |
| 1744 } | 1742 } |
| 1745 } | 1743 } |
| 1746 | 1744 |
| 1747 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 1745 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
| 1748 } | 1746 } |
| OLD | NEW |