Skip to content

Commit

Permalink
Added parentFrameId to webRequest API calls
Browse files Browse the repository at this point in the history
BUG=98048
TEST=no


Review URL: http://codereview.chromium.org/8429007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108666 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
battre@chromium.org committed Nov 4, 2011
1 parent f557255 commit 91043a8
Show file tree
Hide file tree
Showing 22 changed files with 810 additions and 92 deletions.
33 changes: 18 additions & 15 deletions chrome/browser/chromeos/gview_request_interceptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,24 @@ class GViewRequestInterceptorTest : public testing::Test {
content::ResourceContext* context =
content::MockResourceContext::GetInstance();
ResourceDispatcherHostRequestInfo* info =
new ResourceDispatcherHostRequestInfo(handler_,
ChildProcessInfo::RENDER_PROCESS,
-1, // child_id
MSG_ROUTING_NONE,
0, // origin_pid
request->identifier(),
false, // is_main_frame
-1, // frame_id
ResourceType::MAIN_FRAME,
content::PAGE_TRANSITION_LINK,
0, // upload_size
false, // is_download
true, // allow_download
false, // has_user_gesture
context);
new ResourceDispatcherHostRequestInfo(
handler_,
ChildProcessInfo::RENDER_PROCESS,
-1, // child_id
MSG_ROUTING_NONE,
0, // origin_pid
request->identifier(),
false, // is_main_frame
-1, // frame_id
false, // parent_is_main_frame
-1, // parent_frame_id
ResourceType::MAIN_FRAME,
content::PAGE_TRANSITION_LINK,
0, // upload_size
false, // is_download
true, // allow_download
false, // has_user_gesture
context);
request->SetUserData(NULL, info);
request->set_context(context->request_context());
}
Expand Down
27 changes: 22 additions & 5 deletions chrome/browser/extensions/extension_webrequest_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ bool ParseResourceType(const std::string& type_str,
void ExtractRequestInfoDetails(net::URLRequest* request,
bool* is_main_frame,
int64* frame_id,
bool* parent_is_main_frame,
int64* parent_frame_id,
int* tab_id,
int* window_id,
ResourceType::Type* resource_type) {
Expand All @@ -216,6 +218,8 @@ void ExtractRequestInfoDetails(net::URLRequest* request,
info->child_id(), info->route_id(), tab_id, window_id);
*frame_id = info->frame_id();
*is_main_frame = info->is_main_frame();
*parent_frame_id = info->parent_frame_id();
*parent_is_main_frame = info->parent_is_main_frame();

// Restrict the resource type to the values we care about.
ResourceType::Type* iter =
Expand All @@ -231,19 +235,26 @@ void ExtractRequestInfoDetails(net::URLRequest* request,
void ExtractRequestInfo(net::URLRequest* request, DictionaryValue* out) {
bool is_main_frame = false;
int64 frame_id = -1;
bool parent_is_main_frame = false;
int64 parent_frame_id = -1;
int frame_id_for_extension = -1;
int parent_frame_id_for_extension = -1;
int tab_id = -1;
int window_id = -1;
ResourceType::Type resource_type = ResourceType::LAST_TYPE;
ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, &tab_id,
ExtractRequestInfoDetails(request, &is_main_frame, &frame_id,
&parent_is_main_frame, &parent_frame_id, &tab_id,
&window_id, &resource_type);
frame_id_for_extension = GetFrameId(is_main_frame, frame_id);
parent_frame_id_for_extension = GetFrameId(parent_is_main_frame,
parent_frame_id);

out->SetString(keys::kRequestIdKey,
base::Uint64ToString(request->identifier()));
out->SetString(keys::kUrlKey, request->url().spec());
out->SetString(keys::kMethodKey, request->method());
out->SetInteger(keys::kFrameIdKey, frame_id_for_extension);
out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension);
out->SetInteger(keys::kTabIdKey, tab_id);
out->SetString(keys::kTypeKey, ResourceTypeToString(resource_type));
out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000);
Expand Down Expand Up @@ -1083,12 +1094,15 @@ bool ExtensionWebRequestEventRouter::IsPageLoad(
net::URLRequest* request) const {
bool is_main_frame = false;
int64 frame_id = -1;
bool parent_is_main_frame = false;
int64 parent_frame_id = -1;
int tab_id = -1;
int window_id = -1;
ResourceType::Type resource_type = ResourceType::LAST_TYPE;

ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, &tab_id,
&window_id, &resource_type);
ExtractRequestInfoDetails(request, &is_main_frame, &frame_id,
&parent_is_main_frame, &parent_frame_id,
&tab_id, &window_id, &resource_type);

return resource_type == ResourceType::MAIN_FRAME;
}
Expand Down Expand Up @@ -1167,13 +1181,16 @@ ExtensionWebRequestEventRouter::GetMatchingListeners(

bool is_main_frame = false;
int64 frame_id = -1;
bool parent_is_main_frame = false;
int64 parent_frame_id = -1;
int tab_id = -1;
int window_id = -1;
ResourceType::Type resource_type = ResourceType::LAST_TYPE;
const GURL& url = request->url();

ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, &tab_id,
&window_id, &resource_type);
ExtractRequestInfoDetails(request, &is_main_frame, &frame_id,
&parent_is_main_frame, &parent_frame_id,
&tab_id, &window_id, &resource_type);

std::vector<const ExtensionWebRequestEventRouter::EventListener*>
matching_listeners;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace extension_webrequest_api_constants {
const char kChallengerKey[] = "challenger";
const char kErrorKey[] = "error";
const char kFrameIdKey[] = "frameId";
const char kParentFrameIdKey[] = "parentFrameId";
const char kFromCache[] = "fromCache";
const char kHostKey[] = "host";
const char kIpKey[] = "ip";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace extension_webrequest_api_constants {
extern const char kChallengerKey[];
extern const char kErrorKey[];
extern const char kFrameIdKey[];
extern const char kParentFrameIdKey[];
extern const char kFromCache[];
extern const char kHostKey[];
extern const char kIpKey[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const char kTestExtensionNoNetworkDelay[] = "aocebcndggcnnmflapdklcmnfojmkmie";
ResourceDispatcherHostRequestInfo* CreateRequestInfo(int request_id) {
return new ResourceDispatcherHostRequestInfo(
new DummyResourceHandler(), ChildProcessInfo::RENDER_PROCESS, 0, 0, 0,
request_id, false, -1, ResourceType::MAIN_FRAME,
request_id, false, -1, false, -1, ResourceType::MAIN_FRAME,
content::PAGE_TRANSITION_LINK, 0, false, false, false,
content::MockResourceContext::GetInstance());
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/extensions/user_script_listener_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const char kTestData[] = "Hello, World!";
ResourceDispatcherHostRequestInfo* CreateRequestInfo(int request_id) {
return new ResourceDispatcherHostRequestInfo(
new DummyResourceHandler(), ChildProcessInfo::RENDER_PROCESS, 0, 0, 0,
request_id, false, -1, ResourceType::MAIN_FRAME,
request_id, false, -1, false, -1, ResourceType::MAIN_FRAME,
content::PAGE_TRANSITION_LINK, 0, false, false, false,
content::MockResourceContext::GetInstance());
}
Expand Down
9 changes: 9 additions & 0 deletions chrome/common/extensions/api/extension_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -5912,6 +5912,7 @@
"url": {"type": "string"},
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."}
Expand Down Expand Up @@ -5955,6 +5956,7 @@
"url": {"type": "string"},
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},
Expand Down Expand Up @@ -5999,6 +6001,7 @@
"url": {"type": "string"},
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},
Expand Down Expand Up @@ -6038,6 +6041,7 @@
"url": {"type": "string"},
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},
Expand Down Expand Up @@ -6083,6 +6087,7 @@
"url": {"type": "string"},
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},
Expand Down Expand Up @@ -6140,6 +6145,7 @@
"url": {"type": "string"},
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},
Expand Down Expand Up @@ -6183,6 +6189,7 @@
"url": {"type": "string"},
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},
Expand Down Expand Up @@ -6227,6 +6234,7 @@
"url": {"type": "string"},
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},
Expand Down Expand Up @@ -6270,6 +6278,7 @@
"url": {"type": "string"},
"method": {"type": "string", "description": "Standard HTTP method."},
"frameId": {"type": "integer", "description": "0 indicates the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},
"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},
"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},
"type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."},
"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},
Expand Down
Loading

0 comments on commit 91043a8

Please sign in to comment.