diff options
Diffstat (limited to 'chrome/browser/extensions')
5 files changed, 44 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extension_webnavigation_api.cc b/chrome/browser/extensions/extension_webnavigation_api.cc index 28ee146..16894407 100644 --- a/chrome/browser/extensions/extension_webnavigation_api.cc +++ b/chrome/browser/extensions/extension_webnavigation_api.cc @@ -32,8 +32,11 @@ const char* kValidSchemes[] = { chrome::kFtpScheme, }; -// Returns 0 if the navigation happens in the main frame, or the frame ID +// Returns the frame ID as it will be passed to the extension: +// 0 if the navigation happens in the main frame, or the frame ID // modulo 32 bits otherwise. +// Keep this in sync with the GetFrameId() function in +// extension_webrequest_api.cc. int GetFrameId(bool is_main_frame, int64 frame_id) { return is_main_frame ? 0 : static_cast<int>(frame_id); } diff --git a/chrome/browser/extensions/extension_webrequest_api.cc b/chrome/browser/extensions/extension_webrequest_api.cc index 1cae4f8..01a9d1f 100644 --- a/chrome/browser/extensions/extension_webrequest_api.cc +++ b/chrome/browser/extensions/extension_webrequest_api.cc @@ -72,6 +72,15 @@ COMPILE_ASSERT( #define ARRAYEND(array) (array + arraysize(array)) +// Returns the frame ID as it will be passed to the extension: +// 0 if the navigation happens in the main frame, or the frame ID +// modulo 32 bits otherwise. +// Keep this in sync with the GetFrameId() function in +// extension_webnavigation_api.cc. +int GetFrameId(bool is_main_frame, int64 frame_id) { + return is_main_frame ? 0 : static_cast<int>(frame_id); +} + bool IsWebRequestEvent(const std::string& event_name) { return std::find(kWebRequestEvents, ARRAYEND(kWebRequestEvents), event_name) != ARRAYEND(kWebRequestEvents); @@ -108,6 +117,8 @@ bool ParseResourceType(const std::string& type_str, } void ExtractRequestInfo(net::URLRequest* request, + bool* is_main_frame, + int64* frame_id, int* tab_id, int* window_id, ResourceType::Type* resource_type) { @@ -118,6 +129,8 @@ void ExtractRequestInfo(net::URLRequest* request, ResourceDispatcherHost::InfoForRequest(request); ExtensionTabIdMap::GetInstance()->GetTabAndWindowId( info->child_id(), info->route_id(), tab_id, window_id); + *frame_id = info->frame_id(); + *is_main_frame = info->is_main_frame(); // Restrict the resource type to the values we care about. ResourceType::Type* iter = @@ -346,10 +359,15 @@ int ExtensionWebRequestEventRouter::OnBeforeRequest( if (!HasWebRequestScheme(request->url())) return net::OK; + bool is_main_frame = false; + int64 frame_id = -1; + int frame_id_for_extension = -1; int tab_id = -1; int window_id = -1; ResourceType::Type resource_type = ResourceType::LAST_TYPE; - ExtractRequestInfo(request, &tab_id, &window_id, &resource_type); + ExtractRequestInfo(request, &is_main_frame, &frame_id, &tab_id, &window_id, + &resource_type); + frame_id_for_extension = GetFrameId(is_main_frame, frame_id); int extra_info_spec = 0; std::vector<const EventListener*> listeners = @@ -368,6 +386,7 @@ int ExtensionWebRequestEventRouter::OnBeforeRequest( base::Uint64ToString(request->identifier())); dict->SetString(keys::kUrlKey, request->url().spec()); dict->SetString(keys::kMethodKey, request->method()); + dict->SetInteger(keys::kFrameIdKey, frame_id_for_extension); dict->SetInteger(keys::kTabIdKey, tab_id); dict->SetString(keys::kTypeKey, ResourceTypeToString(resource_type)); dict->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); @@ -494,6 +513,16 @@ void ExtensionWebRequestEventRouter::OnBeforeRedirect( if (listeners.empty()) return; + bool is_main_frame = false; + int64 frame_id = -1; + int frame_id_for_extension = -1; + int tab_id = -1; + int window_id = -1; + ResourceType::Type resource_type = ResourceType::LAST_TYPE; + ExtractRequestInfo(request, &is_main_frame, &frame_id, &tab_id, + &window_id, &resource_type); + frame_id_for_extension = GetFrameId(is_main_frame, frame_id); + int http_status_code = request->GetResponseCode(); std::string response_ip = request->GetSocketAddress().host(); @@ -505,6 +534,9 @@ void ExtensionWebRequestEventRouter::OnBeforeRedirect( dict->SetString(keys::kUrlKey, request->url().spec()); dict->SetString(keys::kRedirectUrlKey, new_location.spec()); dict->SetInteger(keys::kStatusCodeKey, http_status_code); + dict->SetInteger(keys::kFrameIdKey, frame_id_for_extension); + dict->SetInteger(keys::kTabIdKey, tab_id); + dict->SetString(keys::kTypeKey, ResourceTypeToString(resource_type)); if (!response_ip.empty()) dict->SetString(keys::kIpKey, response_ip); dict->SetBoolean(keys::kFromCache, request->was_cached()); @@ -892,10 +924,13 @@ ExtensionWebRequestEventRouter::GetMatchingListeners( const std::string& event_name, net::URLRequest* request, int* extra_info_spec) { + bool is_main_frame = false; + int64 frame_id = -1; int tab_id = -1; int window_id = -1; ResourceType::Type resource_type = ResourceType::LAST_TYPE; - ExtractRequestInfo(request, &tab_id, &window_id, &resource_type); + ExtractRequestInfo(request, &is_main_frame, &frame_id, &tab_id, &window_id, + &resource_type); return GetMatchingListeners( profile, extension_info_map, event_name, request->url(), diff --git a/chrome/browser/extensions/extension_webrequest_api_constants.cc b/chrome/browser/extensions/extension_webrequest_api_constants.cc index 2f49d37..efa5b2f 100644 --- a/chrome/browser/extensions/extension_webrequest_api_constants.cc +++ b/chrome/browser/extensions/extension_webrequest_api_constants.cc @@ -7,6 +7,7 @@ namespace extension_webrequest_api_constants { const char kErrorKey[] = "error"; +const char kFrameIdKey[] = "frameId"; const char kFromCache[] = "fromCache"; const char kIpKey[] = "ip"; const char kMethodKey[] = "method"; diff --git a/chrome/browser/extensions/extension_webrequest_api_constants.h b/chrome/browser/extensions/extension_webrequest_api_constants.h index 6715cd7..964c9bf 100644 --- a/chrome/browser/extensions/extension_webrequest_api_constants.h +++ b/chrome/browser/extensions/extension_webrequest_api_constants.h @@ -12,6 +12,7 @@ namespace extension_webrequest_api_constants { // Keys. extern const char kErrorKey[]; +extern const char kFrameIdKey[]; extern const char kFromCache[]; extern const char kIpKey[]; extern const char kMethodKey[]; diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc index 99b39cd..9d8064d 100644 --- a/chrome/browser/extensions/user_script_listener_unittest.cc +++ b/chrome/browser/extensions/user_script_listener_unittest.cc @@ -90,7 +90,7 @@ class DummyResourceHandler : public ResourceHandler { ResourceDispatcherHostRequestInfo* CreateRequestInfo(int request_id) { return new ResourceDispatcherHostRequestInfo( new DummyResourceHandler(), ChildProcessInfo::RENDER_PROCESS, 0, 0, 0, - request_id, ResourceType::MAIN_FRAME, 0, false, false, false, + request_id, false, -1, ResourceType::MAIN_FRAME, 0, false, false, false, content::MockResourceContext::GetInstance()); } |