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/web_request/web_request_api.h" | 5 #include "chrome/browser/extensions/api/web_request/web_request_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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" | 26 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" |
27 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" | 27 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" |
28 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h" | 28 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h" |
29 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h" | 29 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h" |
30 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" | 30 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" |
31 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" | 31 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
32 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h" | 32 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h" |
33 #include "chrome/browser/extensions/extension_renderer_state.h" | 33 #include "chrome/browser/extensions/extension_renderer_state.h" |
34 #include "chrome/browser/extensions/extension_warning_service.h" | 34 #include "chrome/browser/extensions/extension_warning_service.h" |
35 #include "chrome/browser/extensions/extension_warning_set.h" | 35 #include "chrome/browser/extensions/extension_warning_set.h" |
36 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | |
36 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
37 #include "chrome/browser/profiles/profile_manager.h" | 38 #include "chrome/browser/profiles/profile_manager.h" |
38 #include "chrome/common/extensions/api/web_request.h" | 39 #include "chrome/common/extensions/api/web_request.h" |
39 #include "chrome/common/extensions/extension_constants.h" | 40 #include "chrome/common/extensions/extension_constants.h" |
40 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
41 #include "content/public/browser/browser_message_filter.h" | 42 #include "content/public/browser/browser_message_filter.h" |
42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/browser/render_process_host.h" | 44 #include "content/public/browser/render_process_host.h" |
44 #include "content/public/browser/resource_request_info.h" | 45 #include "content/public/browser/resource_request_info.h" |
45 #include "content/public/browser/user_metrics.h" | 46 #include "content/public/browser/user_metrics.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 157 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
157 | 158 |
158 // If this request was not created by the ResourceDispatcher, |info| is NULL. | 159 // If this request was not created by the ResourceDispatcher, |info| is NULL. |
159 // All requests from extensions are created by the ResourceDispatcher. | 160 // All requests from extensions are created by the ResourceDispatcher. |
160 if (!info) | 161 if (!info) |
161 return false; | 162 return false; |
162 | 163 |
163 return extension_info_map->process_map().Contains(info->GetChildID()); | 164 return extension_info_map->process_map().Contains(info->GetChildID()); |
164 } | 165 } |
165 | 166 |
167 void ExtractRequestRoutingInfo(net::URLRequest* request, | |
168 int* render_process_host_id, | |
169 int* routing_id) { | |
170 if (!request->GetUserData(NULL)) | |
171 return; | |
172 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | |
173 *render_process_host_id = info->GetChildID(); | |
174 *routing_id = info->GetRouteID(); | |
175 } | |
176 | |
177 bool IsWebViewGuest(net::URLRequest* request, | |
178 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.
| |
179 int render_process_host_id = -1; | |
180 int routing_id = -1; | |
181 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id); | |
182 return ExtensionRendererState::GetInstance()-> | |
183 GetWebViewInfo(render_process_host_id, routing_id, webview_info); | |
184 } | |
185 | |
166 void ExtractRequestInfoDetails(net::URLRequest* request, | 186 void ExtractRequestInfoDetails(net::URLRequest* request, |
167 bool* is_main_frame, | 187 bool* is_main_frame, |
168 int64* frame_id, | 188 int64* frame_id, |
169 bool* parent_is_main_frame, | 189 bool* parent_is_main_frame, |
170 int64* parent_frame_id, | 190 int64* parent_frame_id, |
171 int* tab_id, | 191 int* tab_id, |
172 int* window_id, | 192 int* window_id, |
173 int* render_process_host_id, | 193 int* render_process_host_id, |
174 int* routing_id, | 194 int* routing_id, |
175 ResourceType::Type* resource_type) { | 195 ResourceType::Type* resource_type) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 content::RenderProcessHost* process = | 378 content::RenderProcessHost* process = |
359 content::RenderProcessHost::FromID(process_id); | 379 content::RenderProcessHost::FromID(process_id); |
360 if (!process) | 380 if (!process) |
361 return; | 381 return; |
362 | 382 |
363 event_router->RemoveEventListener(event_name, process, extension_id); | 383 event_router->RemoveEventListener(event_name, process, extension_id); |
364 } | 384 } |
365 | 385 |
366 // Sends an event to subscribers of chrome.declarativeWebRequest.onMessage. | 386 // Sends an event to subscribers of chrome.declarativeWebRequest.onMessage. |
367 // |extension_id| identifies the extension that sends and receives the event. | 387 // |extension_id| identifies the extension that sends and receives the event. |
368 // |event_argument| is passed to the event listener. | 388 // |event_argument| is passed to the event listener. |
battre
2014/05/28 13:24:45
I guess this needs to be updated.
Fady Samuel
2014/05/28 14:18:24
Done.
| |
369 void SendOnMessageEventOnUI( | 389 void SendOnMessageEventOnUI( |
370 void* profile_id, | 390 void* profile_id, |
371 const std::string& extension_id, | 391 const std::string& extension_id, |
392 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.
| |
393 const ExtensionRendererState::WebViewInfo& webview_info, | |
372 scoped_ptr<base::DictionaryValue> event_argument) { | 394 scoped_ptr<base::DictionaryValue> event_argument) { |
373 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 395 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
374 | 396 |
375 Profile* profile = reinterpret_cast<Profile*>(profile_id); | 397 Profile* profile = reinterpret_cast<Profile*>(profile_id); |
376 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | 398 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
377 return; | 399 return; |
378 | 400 |
379 scoped_ptr<base::ListValue> event_args(new base::ListValue); | 401 scoped_ptr<base::ListValue> event_args(new base::ListValue); |
380 event_args->Append(event_argument.release()); | 402 event_args->Append(event_argument.release()); |
381 | 403 |
382 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); | 404 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); |
383 | 405 |
406 extensions::EventFilteringInfo event_filtering_info; | |
407 event_filtering_info.SetURL(GURL()); | |
408 if (is_guest) | |
409 event_filtering_info.SetInstanceID(webview_info.instance_id); | |
410 | |
384 scoped_ptr<extensions::Event> event(new extensions::Event( | 411 scoped_ptr<extensions::Event> event(new extensions::Event( |
385 declarative_keys::kOnMessage, event_args.Pass(), profile, | 412 is_guest ? webview::kEventMessage : declarative_keys::kOnMessage, |
386 GURL(), extensions::EventRouter::USER_GESTURE_UNKNOWN, | 413 event_args.Pass(), profile, GURL(), |
387 extensions::EventFilteringInfo())); | 414 extensions::EventRouter::USER_GESTURE_UNKNOWN, |
415 event_filtering_info)); | |
388 event_router->DispatchEventToExtension(extension_id, event.Pass()); | 416 event_router->DispatchEventToExtension(extension_id, event.Pass()); |
389 } | 417 } |
390 | 418 |
391 void RemoveEventListenerOnIOThread( | 419 void RemoveEventListenerOnIOThread( |
392 content::BrowserContext* browser_context, | 420 content::BrowserContext* browser_context, |
393 const std::string& extension_id, | 421 const std::string& extension_id, |
394 const std::string& sub_event_name) { | 422 const std::string& sub_event_name) { |
395 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 423 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
396 browser_context, extension_id, sub_event_name); | 424 browser_context, extension_id, sub_event_name); |
397 } | 425 } |
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1786 void* profile, | 1814 void* profile, |
1787 const BlockedRequest& blocked_request) { | 1815 const BlockedRequest& blocked_request) { |
1788 const helpers::EventResponseDeltas& deltas = blocked_request.response_deltas; | 1816 const helpers::EventResponseDeltas& deltas = blocked_request.response_deltas; |
1789 for (helpers::EventResponseDeltas::const_iterator delta = deltas.begin(); | 1817 for (helpers::EventResponseDeltas::const_iterator delta = deltas.begin(); |
1790 delta != deltas.end(); ++delta) { | 1818 delta != deltas.end(); ++delta) { |
1791 const std::set<std::string>& messages = (*delta)->messages_to_extension; | 1819 const std::set<std::string>& messages = (*delta)->messages_to_extension; |
1792 for (std::set<std::string>::const_iterator message = messages.begin(); | 1820 for (std::set<std::string>::const_iterator message = messages.begin(); |
1793 message != messages.end(); ++message) { | 1821 message != messages.end(); ++message) { |
1794 scoped_ptr<base::DictionaryValue> argument(new base::DictionaryValue); | 1822 scoped_ptr<base::DictionaryValue> argument(new base::DictionaryValue); |
1795 ExtractRequestInfo(blocked_request.request, argument.get()); | 1823 ExtractRequestInfo(blocked_request.request, argument.get()); |
1824 ExtensionRendererState::WebViewInfo webview_info; | |
1825 bool is_guest = IsWebViewGuest(blocked_request.request, &webview_info); | |
1796 argument->SetString(keys::kMessageKey, *message); | 1826 argument->SetString(keys::kMessageKey, *message); |
1797 argument->SetString(keys::kStageKey, | 1827 argument->SetString(keys::kStageKey, |
1798 GetRequestStageAsString(blocked_request.event)); | 1828 GetRequestStageAsString(blocked_request.event)); |
1799 | 1829 |
1800 BrowserThread::PostTask( | 1830 BrowserThread::PostTask( |
1801 BrowserThread::UI, | 1831 BrowserThread::UI, |
1802 FROM_HERE, | 1832 FROM_HERE, |
1803 base::Bind(&SendOnMessageEventOnUI, | 1833 base::Bind(&SendOnMessageEventOnUI, |
1804 profile, | 1834 profile, |
1805 (*delta)->extension_id, | 1835 (*delta)->extension_id, |
1836 is_guest, | |
1837 webview_info, | |
1806 base::Passed(&argument))); | 1838 base::Passed(&argument))); |
1807 } | 1839 } |
1808 } | 1840 } |
1809 } | 1841 } |
1810 | 1842 |
1811 int ExtensionWebRequestEventRouter::ExecuteDeltas( | 1843 int ExtensionWebRequestEventRouter::ExecuteDeltas( |
1812 void* profile, | 1844 void* profile, |
1813 uint64 request_id, | 1845 uint64 request_id, |
1814 bool call_callback) { | 1846 bool call_callback) { |
1815 BlockedRequest& blocked_request = blocked_requests_[request_id]; | 1847 BlockedRequest& blocked_request = blocked_requests_[request_id]; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1910 return rv; | 1942 return rv; |
1911 } | 1943 } |
1912 | 1944 |
1913 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( | 1945 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( |
1914 void* profile, | 1946 void* profile, |
1915 InfoMap* extension_info_map, | 1947 InfoMap* extension_info_map, |
1916 const std::string& event_name, | 1948 const std::string& event_name, |
1917 net::URLRequest* request, | 1949 net::URLRequest* request, |
1918 extensions::RequestStage request_stage, | 1950 extensions::RequestStage request_stage, |
1919 const net::HttpResponseHeaders* original_response_headers) { | 1951 const net::HttpResponseHeaders* original_response_headers) { |
1920 bool is_main_frame = false; | |
1921 int64 frame_id = -1; | |
1922 bool parent_is_main_frame = false; | |
1923 int64 parent_frame_id = -1; | |
1924 int tab_id = -1; | |
1925 int window_id = -1; | |
1926 int render_process_host_id = -1; | |
1927 int routing_id = -1; | |
1928 ResourceType::Type resource_type = ResourceType::LAST_TYPE; | |
1929 | |
1930 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | |
1931 &parent_is_main_frame, &parent_frame_id, | |
1932 &tab_id, &window_id, &render_process_host_id, | |
1933 &routing_id, &resource_type); | |
1934 ExtensionRendererState::WebViewInfo webview_info; | 1952 ExtensionRendererState::WebViewInfo webview_info; |
1935 bool is_guest = ExtensionRendererState::GetInstance()-> | 1953 bool is_guest = IsWebViewGuest(request, &webview_info); |
1936 GetWebViewInfo(render_process_host_id, routing_id, &webview_info); | |
1937 | 1954 |
1938 RulesRegistryService::WebViewKey webview_key( | 1955 RulesRegistryService::WebViewKey webview_key( |
1939 is_guest ? webview_info.embedder_process_id : 0, | 1956 is_guest ? webview_info.embedder_process_id : 0, |
1940 is_guest ? webview_info.instance_id : 0); | 1957 is_guest ? webview_info.instance_id : 0); |
1941 RulesRegistryKey rules_key(profile, webview_key); | 1958 RulesRegistryKey rules_key(profile, webview_key); |
1942 | |
1943 // If this check fails, check that the active stages are up-to-date in | 1959 // If this check fails, check that the active stages are up-to-date in |
1944 // browser/extensions/api/declarative_webrequest/request_stage.h . | 1960 // browser/extensions/api/declarative_webrequest/request_stage.h . |
1945 DCHECK(request_stage & extensions::kActiveStages); | 1961 DCHECK(request_stage & extensions::kActiveStages); |
1946 | 1962 |
1947 // Rules of the current |profile| may apply but we need to check also whether | 1963 // Rules of the current |profile| may apply but we need to check also whether |
1948 // there are applicable rules from extensions whose background page | 1964 // there are applicable rules from extensions whose background page |
1949 // spans from regular to incognito mode. | 1965 // spans from regular to incognito mode. |
1950 | 1966 |
1951 // First parameter identifies the registry, the second indicates whether the | 1967 // First parameter identifies the registry, the second indicates whether the |
1952 // registry belongs to the cross profile. | 1968 // registry belongs to the cross profile. |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2445 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 2461 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
2446 adblock = true; | 2462 adblock = true; |
2447 } else { | 2463 } else { |
2448 other = true; | 2464 other = true; |
2449 } | 2465 } |
2450 } | 2466 } |
2451 } | 2467 } |
2452 | 2468 |
2453 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 2469 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
2454 } | 2470 } |
OLD | NEW |