Index: chrome/browser/extensions/api/web_request/web_request_api.cc |
diff --git a/chrome/browser/extensions/api/web_request/web_request_api.cc b/chrome/browser/extensions/api/web_request/web_request_api.cc |
index eef2a8075936f7784ace561b25dd44f2d2f08ca9..93d9a45ab73188c70cae82e33f519918c2b6f1b1 100644 |
--- a/chrome/browser/extensions/api/web_request/web_request_api.cc |
+++ b/chrome/browser/extensions/api/web_request/web_request_api.cc |
@@ -33,6 +33,7 @@ |
#include "chrome/browser/extensions/extension_renderer_state.h" |
#include "chrome/browser/extensions/extension_warning_service.h" |
#include "chrome/browser/extensions/extension_warning_set.h" |
+#include "chrome/browser/guest_view/web_view/web_view_constants.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/common/extensions/api/web_request.h" |
@@ -163,6 +164,25 @@ bool IsRequestFromExtension(const net::URLRequest* request, |
return extension_info_map->process_map().Contains(info->GetChildID()); |
} |
+void ExtractRequestRoutingInfo(net::URLRequest* request, |
+ int* render_process_host_id, |
+ int* routing_id) { |
+ if (!request->GetUserData(NULL)) |
+ return; |
+ const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
+ *render_process_host_id = info->GetChildID(); |
+ *routing_id = info->GetRouteID(); |
+} |
+ |
+bool IsWebViewGuest(net::URLRequest* request, |
+ ExtensionRendererState::WebViewInfo* webview_info) { |
battre
2014/05/28 13:24:45
I think this function should be called Get[somethi
Fady Samuel
2014/05/28 14:18:24
Done.
|
+ int render_process_host_id = -1; |
+ int routing_id = -1; |
+ ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id); |
+ return ExtensionRendererState::GetInstance()-> |
+ GetWebViewInfo(render_process_host_id, routing_id, webview_info); |
+} |
+ |
void ExtractRequestInfoDetails(net::URLRequest* request, |
bool* is_main_frame, |
int64* frame_id, |
@@ -369,6 +389,8 @@ void RemoveEventListenerOnUI( |
void SendOnMessageEventOnUI( |
void* profile_id, |
const std::string& extension_id, |
+ int is_guest, |
battre
2014/05/28 13:24:45
What does |is_guest| mean?
Would you mind adding
Fady Samuel
2014/05/28 14:18:24
Done.
|
+ const ExtensionRendererState::WebViewInfo& webview_info, |
scoped_ptr<base::DictionaryValue> event_argument) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
@@ -381,10 +403,16 @@ void SendOnMessageEventOnUI( |
extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); |
+ extensions::EventFilteringInfo event_filtering_info; |
+ event_filtering_info.SetURL(GURL()); |
+ if (is_guest) |
+ event_filtering_info.SetInstanceID(webview_info.instance_id); |
+ |
scoped_ptr<extensions::Event> event(new extensions::Event( |
- declarative_keys::kOnMessage, event_args.Pass(), profile, |
- GURL(), extensions::EventRouter::USER_GESTURE_UNKNOWN, |
- extensions::EventFilteringInfo())); |
+ is_guest ? webview::kEventMessage : declarative_keys::kOnMessage, |
+ event_args.Pass(), profile, GURL(), |
+ extensions::EventRouter::USER_GESTURE_UNKNOWN, |
+ event_filtering_info)); |
event_router->DispatchEventToExtension(extension_id, event.Pass()); |
} |
@@ -1793,6 +1821,8 @@ void ExtensionWebRequestEventRouter::SendMessages( |
message != messages.end(); ++message) { |
scoped_ptr<base::DictionaryValue> argument(new base::DictionaryValue); |
ExtractRequestInfo(blocked_request.request, argument.get()); |
+ ExtensionRendererState::WebViewInfo webview_info; |
+ bool is_guest = IsWebViewGuest(blocked_request.request, &webview_info); |
argument->SetString(keys::kMessageKey, *message); |
argument->SetString(keys::kStageKey, |
GetRequestStageAsString(blocked_request.event)); |
@@ -1803,6 +1833,8 @@ void ExtensionWebRequestEventRouter::SendMessages( |
base::Bind(&SendOnMessageEventOnUI, |
profile, |
(*delta)->extension_id, |
+ is_guest, |
+ webview_info, |
base::Passed(&argument))); |
} |
} |
@@ -1917,29 +1949,13 @@ bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( |
net::URLRequest* request, |
extensions::RequestStage request_stage, |
const net::HttpResponseHeaders* original_response_headers) { |
- 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; |
- int render_process_host_id = -1; |
- int routing_id = -1; |
- ResourceType::Type resource_type = ResourceType::LAST_TYPE; |
- |
- ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
- &parent_is_main_frame, &parent_frame_id, |
- &tab_id, &window_id, &render_process_host_id, |
- &routing_id, &resource_type); |
ExtensionRendererState::WebViewInfo webview_info; |
- bool is_guest = ExtensionRendererState::GetInstance()-> |
- GetWebViewInfo(render_process_host_id, routing_id, &webview_info); |
+ bool is_guest = IsWebViewGuest(request, &webview_info); |
RulesRegistryService::WebViewKey webview_key( |
is_guest ? webview_info.embedder_process_id : 0, |
is_guest ? webview_info.instance_id : 0); |
RulesRegistryKey rules_key(profile, webview_key); |
- |
// If this check fails, check that the active stages are up-to-date in |
// browser/extensions/api/declarative_webrequest/request_stage.h . |
DCHECK(request_stage & extensions::kActiveStages); |