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

Side by Side Diff: chrome/browser/extensions/api/webrequest/webrequest_api.cc

Issue 9580002: Add ResourceRequestInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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/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
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
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->GetChildID());
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
141 // modified/canceled by extensions, e.g. because it is targeted to the webstore 140 // modified/canceled by extensions, e.g. because it is targeted to the webstore
142 // to check for updates, extension blacklisting, etc. 141 // to check for updates, extension blacklisting, etc.
143 bool IsSensitiveURL(const GURL& url) { 142 bool IsSensitiveURL(const GURL& url) {
144 bool is_webstore_gallery_url = 143 bool is_webstore_gallery_url =
145 StartsWithASCII(url.spec(), extension_urls::kGalleryBrowsePrefix, true); 144 StartsWithASCII(url.spec(), extension_urls::kGalleryBrowsePrefix, true);
146 bool is_google_com_chrome_url = 145 bool is_google_com_chrome_url =
147 EndsWith(url.host(), "google.com", true) && 146 EndsWith(url.host(), "google.com", true) &&
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->GetChildID(), info->GetRouteID(), tab_id, window_id);
216 *frame_id = info->frame_id(); 214 *frame_id = info->GetFrameID();
217 *is_main_frame = info->is_main_frame(); 215 *is_main_frame = info->IsMainFrame();
218 *parent_frame_id = info->parent_frame_id(); 216 *parent_frame_id = info->GetParentFrameID();
219 *parent_is_main_frame = info->parent_is_main_frame(); 217 *parent_is_main_frame = info->ParentIsMainFrame();
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),
224 info->resource_type()); 222 info->GetResourceType());
225 *resource_type = (iter != ARRAYEND(kResourceTypeValues)) ? 223 *resource_type = (iter != ARRAYEND(kResourceTypeValues)) ?
226 *iter : ResourceType::LAST_TYPE; 224 *iter : ResourceType::LAST_TYPE;
227 } 225 }
228 226
229 // Extracts from |request| information for the keys requestId, url, method, 227 // Extracts from |request| information for the keys requestId, url, method,
230 // 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
231 // on to extensions. 229 // on to extensions.
232 void ExtractRequestInfo(net::URLRequest* request, DictionaryValue* out) { 230 void ExtractRequestInfo(net::URLRequest* request, DictionaryValue* out) {
233 bool is_main_frame = false; 231 bool is_main_frame = false;
234 int64 frame_id = -1; 232 int64 frame_id = -1;
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gview_request_interceptor_unittest.cc ('k') | chrome/browser/extensions/extension_protocols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698