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/chrome_content_browser_client.h" | 5 #include "chrome/browser/chrome_content_browser_client.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1048 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1049 | 1049 |
1050 // This object is guaranteed to outlive all threads so we don't have to | 1050 // This object is guaranteed to outlive all threads so we don't have to |
1051 // worry about the lack of refcounting and can just post as Unretained. | 1051 // worry about the lack of refcounting and can just post as Unretained. |
1052 // | 1052 // |
1053 // The common case is that this function is called early in Chrome startup | 1053 // The common case is that this function is called early in Chrome startup |
1054 // before any threads are created (it will also be called later if the user | 1054 // before any threads are created (it will also be called later if the user |
1055 // changes the pref). In this case, there will be no threads created and | 1055 // changes the pref). In this case, there will be no threads created and |
1056 // posting will fail. When there are no threads, we can just set the string | 1056 // posting will fail. When there are no threads, we can just set the string |
1057 // without worrying about threadsafety. | 1057 // without worrying about threadsafety. |
1058 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 1058 if (!BrowserThread::PostTask( |
1059 base::Bind(&SetApplicationLocaleOnIOThread, locale))) { | 1059 BrowserThread::IO, FROM_HERE, |
| 1060 base::BindOnce(&SetApplicationLocaleOnIOThread, locale))) { |
1060 g_io_thread_application_locale.Get() = locale; | 1061 g_io_thread_application_locale.Get() = locale; |
1061 } | 1062 } |
1062 } | 1063 } |
1063 | 1064 |
1064 content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( | 1065 content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( |
1065 const content::MainFunctionParams& parameters) { | 1066 const content::MainFunctionParams& parameters) { |
1066 ChromeBrowserMainParts* main_parts; | 1067 ChromeBrowserMainParts* main_parts; |
1067 // Construct the Main browser parts based on the OS type. | 1068 // Construct the Main browser parts based on the OS type. |
1068 #if defined(OS_WIN) | 1069 #if defined(OS_WIN) |
1069 main_parts = new ChromeBrowserMainPartsWin(parameters); | 1070 main_parts = new ChromeBrowserMainPartsWin(parameters); |
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2082 | 2083 |
2083 // Check if cookies are allowed. | 2084 // Check if cookies are allowed. |
2084 bool allow_serviceworker = | 2085 bool allow_serviceworker = |
2085 io_data->GetCookieSettings()->IsCookieAccessAllowed(scope, | 2086 io_data->GetCookieSettings()->IsCookieAccessAllowed(scope, |
2086 first_party_url); | 2087 first_party_url); |
2087 // Record access to database for potential display in UI. | 2088 // Record access to database for potential display in UI. |
2088 // Only post the task if this is for a specific tab. | 2089 // Only post the task if this is for a specific tab. |
2089 if (!wc_getter.is_null()) { | 2090 if (!wc_getter.is_null()) { |
2090 BrowserThread::PostTask( | 2091 BrowserThread::PostTask( |
2091 BrowserThread::UI, FROM_HERE, | 2092 BrowserThread::UI, FROM_HERE, |
2092 base::Bind(&TabSpecificContentSettings::ServiceWorkerAccessed, | 2093 base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed, |
2093 wc_getter, scope, !allow_javascript, !allow_serviceworker)); | 2094 wc_getter, scope, !allow_javascript, |
| 2095 !allow_serviceworker)); |
2094 } | 2096 } |
2095 return allow_javascript && allow_serviceworker; | 2097 return allow_javascript && allow_serviceworker; |
2096 } | 2098 } |
2097 | 2099 |
2098 bool ChromeContentBrowserClient::AllowGetCookie( | 2100 bool ChromeContentBrowserClient::AllowGetCookie( |
2099 const GURL& url, | 2101 const GURL& url, |
2100 const GURL& first_party, | 2102 const GURL& first_party, |
2101 const net::CookieList& cookie_list, | 2103 const net::CookieList& cookie_list, |
2102 content::ResourceContext* context, | 2104 content::ResourceContext* context, |
2103 int render_process_id, | 2105 int render_process_id, |
2104 int render_frame_id) { | 2106 int render_frame_id) { |
2105 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2107 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
2106 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); | 2108 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
2107 bool allow = | 2109 bool allow = |
2108 io_data->GetCookieSettings()->IsCookieAccessAllowed(url, first_party); | 2110 io_data->GetCookieSettings()->IsCookieAccessAllowed(url, first_party); |
2109 | 2111 |
2110 base::Callback<content::WebContents*(void)> wc_getter = | 2112 base::Callback<content::WebContents*(void)> wc_getter = |
2111 base::Bind(&GetWebContents, render_process_id, render_frame_id); | 2113 base::Bind(&GetWebContents, render_process_id, render_frame_id); |
2112 BrowserThread::PostTask( | 2114 BrowserThread::PostTask( |
2113 BrowserThread::UI, FROM_HERE, | 2115 BrowserThread::UI, FROM_HERE, |
2114 base::Bind(&TabSpecificContentSettings::CookiesRead, wc_getter, url, | 2116 base::BindOnce(&TabSpecificContentSettings::CookiesRead, wc_getter, url, |
2115 first_party, cookie_list, !allow)); | 2117 first_party, cookie_list, !allow)); |
2116 return allow; | 2118 return allow; |
2117 } | 2119 } |
2118 | 2120 |
2119 bool ChromeContentBrowserClient::AllowSetCookie( | 2121 bool ChromeContentBrowserClient::AllowSetCookie( |
2120 const GURL& url, | 2122 const GURL& url, |
2121 const GURL& first_party, | 2123 const GURL& first_party, |
2122 const std::string& cookie_line, | 2124 const std::string& cookie_line, |
2123 content::ResourceContext* context, | 2125 content::ResourceContext* context, |
2124 int render_process_id, | 2126 int render_process_id, |
2125 int render_frame_id, | 2127 int render_frame_id, |
2126 const net::CookieOptions& options) { | 2128 const net::CookieOptions& options) { |
2127 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2129 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
2128 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); | 2130 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
2129 content_settings::CookieSettings* cookie_settings = | 2131 content_settings::CookieSettings* cookie_settings = |
2130 io_data->GetCookieSettings(); | 2132 io_data->GetCookieSettings(); |
2131 bool allow = cookie_settings->IsCookieAccessAllowed(url, first_party); | 2133 bool allow = cookie_settings->IsCookieAccessAllowed(url, first_party); |
2132 | 2134 |
2133 base::Callback<content::WebContents*(void)> wc_getter = | 2135 base::Callback<content::WebContents*(void)> wc_getter = |
2134 base::Bind(&GetWebContents, render_process_id, render_frame_id); | 2136 base::Bind(&GetWebContents, render_process_id, render_frame_id); |
2135 BrowserThread::PostTask( | 2137 BrowserThread::PostTask( |
2136 BrowserThread::UI, FROM_HERE, | 2138 BrowserThread::UI, FROM_HERE, |
2137 base::Bind(&TabSpecificContentSettings::CookieChanged, wc_getter, url, | 2139 base::BindOnce(&TabSpecificContentSettings::CookieChanged, wc_getter, url, |
2138 first_party, cookie_line, options, !allow)); | 2140 first_party, cookie_line, options, !allow)); |
2139 return allow; | 2141 return allow; |
2140 } | 2142 } |
2141 | 2143 |
2142 bool ChromeContentBrowserClient::AllowSaveLocalState( | 2144 bool ChromeContentBrowserClient::AllowSaveLocalState( |
2143 content::ResourceContext* context) { | 2145 content::ResourceContext* context) { |
2144 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2146 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
2145 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); | 2147 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
2146 content_settings::CookieSettings* cookie_settings = | 2148 content_settings::CookieSettings* cookie_settings = |
2147 io_data->GetCookieSettings(); | 2149 io_data->GetCookieSettings(); |
2148 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL); | 2150 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2191 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i->first)) | 2193 if (extensions::WebViewRendererState::GetInstance()->IsGuest(i->first)) |
2192 has_web_view_guest = true; | 2194 has_web_view_guest = true; |
2193 } | 2195 } |
2194 if (!has_web_view_guest) { | 2196 if (!has_web_view_guest) { |
2195 FileSystemAccessed(url, render_frames, callback, allow); | 2197 FileSystemAccessed(url, render_frames, callback, allow); |
2196 return; | 2198 return; |
2197 } | 2199 } |
2198 DCHECK_EQ(1U, process_map.size()); | 2200 DCHECK_EQ(1U, process_map.size()); |
2199 it = process_map.begin(); | 2201 it = process_map.begin(); |
2200 BrowserThread::PostTask( | 2202 BrowserThread::PostTask( |
2201 BrowserThread::UI, | 2203 BrowserThread::UI, FROM_HERE, |
2202 FROM_HERE, | 2204 base::BindOnce( |
2203 base::Bind(&ChromeContentBrowserClient:: | 2205 &ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread, |
2204 RequestFileSystemPermissionOnUIThread, | 2206 it->first, it->second, url, allow, |
2205 it->first, | 2207 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed, |
2206 it->second, | 2208 weak_factory_.GetWeakPtr(), url, render_frames, |
2207 url, | 2209 callback))); |
2208 allow, | |
2209 base::Bind(&ChromeContentBrowserClient::FileSystemAccessed, | |
2210 weak_factory_.GetWeakPtr(), | |
2211 url, | |
2212 render_frames, | |
2213 callback))); | |
2214 } | 2210 } |
2215 | 2211 |
2216 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread( | 2212 void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread( |
2217 int render_process_id, | 2213 int render_process_id, |
2218 int render_frame_id, | 2214 int render_frame_id, |
2219 const GURL& url, | 2215 const GURL& url, |
2220 bool allowed_by_default, | 2216 bool allowed_by_default, |
2221 const base::Callback<void(bool)>& callback) { | 2217 const base::Callback<void(bool)>& callback) { |
2222 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2218 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2223 extensions::WebViewPermissionHelper* web_view_permission_helper = | 2219 extensions::WebViewPermissionHelper* web_view_permission_helper = |
2224 extensions::WebViewPermissionHelper::FromFrameID( | 2220 extensions::WebViewPermissionHelper::FromFrameID( |
2225 render_process_id, render_frame_id); | 2221 render_process_id, render_frame_id); |
2226 web_view_permission_helper->RequestFileSystemPermission(url, | 2222 web_view_permission_helper->RequestFileSystemPermission(url, |
2227 allowed_by_default, | 2223 allowed_by_default, |
2228 callback); | 2224 callback); |
2229 } | 2225 } |
2230 #endif | 2226 #endif |
2231 | 2227 |
2232 void ChromeContentBrowserClient::FileSystemAccessed( | 2228 void ChromeContentBrowserClient::FileSystemAccessed( |
2233 const GURL& url, | 2229 const GURL& url, |
2234 const std::vector<std::pair<int, int> >& render_frames, | 2230 const std::vector<std::pair<int, int> >& render_frames, |
2235 base::Callback<void(bool)> callback, | 2231 base::Callback<void(bool)> callback, |
2236 bool allow) { | 2232 bool allow) { |
2237 // Record access to file system for potential display in UI. | 2233 // Record access to file system for potential display in UI. |
2238 std::vector<std::pair<int, int> >::const_iterator i; | 2234 std::vector<std::pair<int, int> >::const_iterator i; |
2239 for (i = render_frames.begin(); i != render_frames.end(); ++i) { | 2235 for (i = render_frames.begin(); i != render_frames.end(); ++i) { |
2240 BrowserThread::PostTask( | 2236 BrowserThread::PostTask( |
2241 BrowserThread::UI, | 2237 BrowserThread::UI, FROM_HERE, |
2242 FROM_HERE, | 2238 base::BindOnce(&TabSpecificContentSettings::FileSystemAccessed, |
2243 base::Bind(&TabSpecificContentSettings::FileSystemAccessed, | 2239 i->first, i->second, url, !allow)); |
2244 i->first, i->second, url, !allow)); | |
2245 } | 2240 } |
2246 callback.Run(allow); | 2241 callback.Run(allow); |
2247 } | 2242 } |
2248 | 2243 |
2249 bool ChromeContentBrowserClient::AllowWorkerIndexedDB( | 2244 bool ChromeContentBrowserClient::AllowWorkerIndexedDB( |
2250 const GURL& url, | 2245 const GURL& url, |
2251 const base::string16& name, | 2246 const base::string16& name, |
2252 content::ResourceContext* context, | 2247 content::ResourceContext* context, |
2253 const std::vector<std::pair<int, int> >& render_frames) { | 2248 const std::vector<std::pair<int, int> >& render_frames) { |
2254 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2249 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
2255 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); | 2250 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
2256 content_settings::CookieSettings* cookie_settings = | 2251 content_settings::CookieSettings* cookie_settings = |
2257 io_data->GetCookieSettings(); | 2252 io_data->GetCookieSettings(); |
2258 bool allow = cookie_settings->IsCookieAccessAllowed(url, url); | 2253 bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
2259 | 2254 |
2260 // Record access to IndexedDB for potential display in UI. | 2255 // Record access to IndexedDB for potential display in UI. |
2261 std::vector<std::pair<int, int> >::const_iterator i; | 2256 std::vector<std::pair<int, int> >::const_iterator i; |
2262 for (i = render_frames.begin(); i != render_frames.end(); ++i) { | 2257 for (i = render_frames.begin(); i != render_frames.end(); ++i) { |
2263 BrowserThread::PostTask( | 2258 BrowserThread::PostTask( |
2264 BrowserThread::UI, FROM_HERE, | 2259 BrowserThread::UI, FROM_HERE, |
2265 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed, | 2260 base::BindOnce(&TabSpecificContentSettings::IndexedDBAccessed, i->first, |
2266 i->first, i->second, url, name, !allow)); | 2261 i->second, url, name, !allow)); |
2267 } | 2262 } |
2268 | 2263 |
2269 return allow; | 2264 return allow; |
2270 } | 2265 } |
2271 | 2266 |
2272 #if BUILDFLAG(ENABLE_WEBRTC) | 2267 #if BUILDFLAG(ENABLE_WEBRTC) |
2273 bool ChromeContentBrowserClient::AllowWebRTCIdentityCache( | 2268 bool ChromeContentBrowserClient::AllowWebRTCIdentityCache( |
2274 const GURL& url, | 2269 const GURL& url, |
2275 const GURL& first_party_url, | 2270 const GURL& first_party_url, |
2276 content::ResourceContext* context) { | 2271 content::ResourceContext* context) { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2537 | 2532 |
2538 HostContentSettingsMap* content_settings = | 2533 HostContentSettingsMap* content_settings = |
2539 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); | 2534 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); |
2540 | 2535 |
2541 #if BUILDFLAG(ENABLE_PLUGINS) | 2536 #if BUILDFLAG(ENABLE_PLUGINS) |
2542 if (FlashDownloadInterception::ShouldStopFlashDownloadAction( | 2537 if (FlashDownloadInterception::ShouldStopFlashDownloadAction( |
2543 content_settings, opener_top_level_frame_url, target_url, | 2538 content_settings, opener_top_level_frame_url, target_url, |
2544 user_gesture)) { | 2539 user_gesture)) { |
2545 BrowserThread::PostTask( | 2540 BrowserThread::PostTask( |
2546 BrowserThread::UI, FROM_HERE, | 2541 BrowserThread::UI, FROM_HERE, |
2547 base::Bind(&HandleFlashDownloadActionOnUIThread, | 2542 base::BindOnce(&HandleFlashDownloadActionOnUIThread, |
2548 opener_render_process_id, opener_render_frame_id, | 2543 opener_render_process_id, opener_render_frame_id, |
2549 opener_top_level_frame_url)); | 2544 opener_top_level_frame_url)); |
2550 return false; | 2545 return false; |
2551 } | 2546 } |
2552 #endif | 2547 #endif |
2553 | 2548 |
2554 BlockedWindowParams blocked_params( | 2549 BlockedWindowParams blocked_params( |
2555 target_url, referrer, frame_name, disposition, features, user_gesture, | 2550 target_url, referrer, frame_name, disposition, features, user_gesture, |
2556 opener_suppressed, opener_render_process_id, opener_render_frame_id); | 2551 opener_suppressed, opener_render_process_id, opener_render_frame_id); |
2557 | 2552 |
2558 if (!user_gesture && | 2553 if (!user_gesture && |
2559 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 2554 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
2560 switches::kDisablePopupBlocking)) { | 2555 switches::kDisablePopupBlocking)) { |
2561 if (content_settings->GetContentSetting(opener_top_level_frame_url, | 2556 if (content_settings->GetContentSetting(opener_top_level_frame_url, |
2562 opener_top_level_frame_url, | 2557 opener_top_level_frame_url, |
2563 CONTENT_SETTINGS_TYPE_POPUPS, | 2558 CONTENT_SETTINGS_TYPE_POPUPS, |
2564 std::string()) != | 2559 std::string()) != |
2565 CONTENT_SETTING_ALLOW) { | 2560 CONTENT_SETTING_ALLOW) { |
2566 BrowserThread::PostTask(BrowserThread::UI, | 2561 BrowserThread::PostTask( |
2567 FROM_HERE, | 2562 BrowserThread::UI, FROM_HERE, |
2568 base::Bind(&HandleBlockedPopupOnUIThread, | 2563 base::BindOnce(&HandleBlockedPopupOnUIThread, blocked_params)); |
2569 blocked_params)); | |
2570 return false; | 2564 return false; |
2571 } | 2565 } |
2572 } | 2566 } |
2573 | 2567 |
2574 #if defined(OS_ANDROID) | 2568 #if defined(OS_ANDROID) |
2575 if (SingleTabModeTabHelper::IsRegistered(opener_render_process_id, | 2569 if (SingleTabModeTabHelper::IsRegistered(opener_render_process_id, |
2576 opener_render_frame_id)) { | 2570 opener_render_frame_id)) { |
2577 BrowserThread::PostTask(BrowserThread::UI, | 2571 BrowserThread::PostTask(BrowserThread::UI, |
2578 FROM_HERE, | 2572 FROM_HERE, |
2579 base::Bind(&HandleSingleTabModeBlockOnUIThread, | 2573 base::Bind(&HandleSingleTabModeBlockOnUIThread, |
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3646 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { | 3640 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { |
3647 return variations::GetVariationParamValue( | 3641 return variations::GetVariationParamValue( |
3648 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; | 3642 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; |
3649 } | 3643 } |
3650 | 3644 |
3651 // static | 3645 // static |
3652 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( | 3646 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( |
3653 const storage::QuotaSettings* settings) { | 3647 const storage::QuotaSettings* settings) { |
3654 g_default_quota_settings = settings; | 3648 g_default_quota_settings = settings; |
3655 } | 3649 } |
OLD | NEW |