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 <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 (kWidthForMaxFSM - kWidthForMinFSM); | 623 (kWidthForMaxFSM - kWidthForMinFSM); |
624 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; | 624 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
625 } | 625 } |
626 | 626 |
627 #endif // defined(OS_ANDROID) | 627 #endif // defined(OS_ANDROID) |
628 | 628 |
629 } // namespace | 629 } // namespace |
630 | 630 |
631 namespace chrome { | 631 namespace chrome { |
632 | 632 |
633 ChromeContentBrowserClient::ChromeContentBrowserClient() { | 633 ChromeContentBrowserClient::ChromeContentBrowserClient() |
| 634 : prerender_tracker_(NULL) { |
634 #if defined(ENABLE_PLUGINS) | 635 #if defined(ENABLE_PLUGINS) |
635 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) | 636 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) |
636 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); | 637 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); |
637 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) | 638 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) |
638 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); | 639 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
639 #endif | 640 #endif |
640 | 641 |
641 permissions_policy_delegate_.reset( | 642 permissions_policy_delegate_.reset( |
642 new extensions::BrowserPermissionsPolicyDelegate()); | 643 new extensions::BrowserPermissionsPolicyDelegate()); |
643 } | 644 } |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 return true; | 1208 return true; |
1208 | 1209 |
1209 // Otherwise, just make sure the process privilege matches the privilege | 1210 // Otherwise, just make sure the process privilege matches the privilege |
1210 // required by the site. | 1211 // required by the site. |
1211 RenderProcessHostPrivilege privilege_required = | 1212 RenderProcessHostPrivilege privilege_required = |
1212 GetPrivilegeRequiredByUrl(site_url, service); | 1213 GetPrivilegeRequiredByUrl(site_url, service); |
1213 return GetProcessPrivilege(process_host, process_map, service) == | 1214 return GetProcessPrivilege(process_host, process_map, service) == |
1214 privilege_required; | 1215 privilege_required; |
1215 } | 1216 } |
1216 | 1217 |
| 1218 bool ChromeContentBrowserClient::MayReuseHost( |
| 1219 content::RenderProcessHost* process_host) { |
| 1220 // If there is currently a prerender in progress for the host provided, |
| 1221 // it may not be shared. We require prerenders to be by themselves in a |
| 1222 // separate process, so that we can monitor their resource usage, and so that |
| 1223 // we can track the cookies that they change. |
| 1224 Profile* profile = Profile::FromBrowserContext( |
| 1225 process_host->GetBrowserContext()); |
| 1226 prerender::PrerenderManager* prerender_manager = |
| 1227 prerender::PrerenderManagerFactory::GetForProfile(profile); |
| 1228 if (prerender_manager && |
| 1229 prerender_manager->IsProcessPrerendering(process_host)) { |
| 1230 return false; |
| 1231 } |
| 1232 |
| 1233 return true; |
| 1234 } |
| 1235 |
1217 // This function is trying to limit the amount of processes used by extensions | 1236 // This function is trying to limit the amount of processes used by extensions |
1218 // with background pages. It uses a globally set percentage of processes to | 1237 // with background pages. It uses a globally set percentage of processes to |
1219 // run such extensions and if the limit is exceeded, it returns true, to | 1238 // run such extensions and if the limit is exceeded, it returns true, to |
1220 // indicate to the content module to group extensions together. | 1239 // indicate to the content module to group extensions together. |
1221 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( | 1240 bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
1222 content::BrowserContext* browser_context, const GURL& url) { | 1241 content::BrowserContext* browser_context, const GURL& url) { |
1223 // It has to be a valid URL for us to check for an extension. | 1242 // It has to be a valid URL for us to check for an extension. |
1224 if (!url.is_valid()) | 1243 if (!url.is_valid()) |
1225 return false; | 1244 return false; |
1226 | 1245 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 const std::string& cookie_line, | 1777 const std::string& cookie_line, |
1759 content::ResourceContext* context, | 1778 content::ResourceContext* context, |
1760 int render_process_id, | 1779 int render_process_id, |
1761 int render_frame_id, | 1780 int render_frame_id, |
1762 net::CookieOptions* options) { | 1781 net::CookieOptions* options) { |
1763 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1764 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); | 1783 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
1765 CookieSettings* cookie_settings = io_data->GetCookieSettings(); | 1784 CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
1766 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); | 1785 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); |
1767 | 1786 |
| 1787 if (prerender_tracker_) { |
| 1788 prerender_tracker_->OnCookieChangedForURL( |
| 1789 render_process_id, |
| 1790 context->GetRequestContext()->cookie_store()->GetCookieMonster(), |
| 1791 url); |
| 1792 } |
| 1793 |
1768 BrowserThread::PostTask( | 1794 BrowserThread::PostTask( |
1769 BrowserThread::UI, FROM_HERE, | 1795 BrowserThread::UI, FROM_HERE, |
1770 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, | 1796 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, |
1771 render_frame_id, url, first_party, cookie_line, *options, | 1797 render_frame_id, url, first_party, cookie_line, *options, |
1772 !allow)); | 1798 !allow)); |
1773 return allow; | 1799 return allow; |
1774 } | 1800 } |
1775 | 1801 |
1776 bool ChromeContentBrowserClient::AllowSaveLocalState( | 1802 bool ChromeContentBrowserClient::AllowSaveLocalState( |
1777 content::ResourceContext* context) { | 1803 content::ResourceContext* context) { |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2205 // Check if it's an extension-created worker, in which case we want to use | 2231 // Check if it's an extension-created worker, in which case we want to use |
2206 // the name of the extension. | 2232 // the name of the extension. |
2207 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); | 2233 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
2208 const Extension* extension = | 2234 const Extension* extension = |
2209 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); | 2235 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
2210 return extension ? extension->name() : std::string(); | 2236 return extension ? extension->name() : std::string(); |
2211 } | 2237 } |
2212 | 2238 |
2213 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { | 2239 void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { |
| 2240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2241 prerender_tracker_ = g_browser_process->prerender_tracker(); |
2214 return g_browser_process->ResourceDispatcherHostCreated(); | 2242 return g_browser_process->ResourceDispatcherHostCreated(); |
2215 } | 2243 } |
2216 | 2244 |
2217 // TODO(tommi): Rename from Get to Create. | 2245 // TODO(tommi): Rename from Get to Create. |
2218 content::SpeechRecognitionManagerDelegate* | 2246 content::SpeechRecognitionManagerDelegate* |
2219 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() { | 2247 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() { |
2220 return new speech::ChromeSpeechRecognitionManagerDelegate(); | 2248 return new speech::ChromeSpeechRecognitionManagerDelegate(); |
2221 } | 2249 } |
2222 | 2250 |
2223 net::NetLog* ChromeContentBrowserClient::GetNetLog() { | 2251 net::NetLog* ChromeContentBrowserClient::GetNetLog() { |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2691 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 2719 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
2692 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown" | 2720 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown" |
2693 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on | 2721 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on |
2694 // Chromium builds as well. | 2722 // Chromium builds as well. |
2695 return channel <= chrome::VersionInfo::CHANNEL_DEV; | 2723 return channel <= chrome::VersionInfo::CHANNEL_DEV; |
2696 #else | 2724 #else |
2697 return false; | 2725 return false; |
2698 #endif | 2726 #endif |
2699 } | 2727 } |
2700 | 2728 |
| 2729 net::CookieStore* |
| 2730 ChromeContentBrowserClient::OverrideCookieStoreForRenderProcess( |
| 2731 int render_process_id) { |
| 2732 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2733 if (!prerender_tracker_) |
| 2734 return NULL; |
| 2735 return prerender_tracker_-> |
| 2736 GetPrerenderCookieStoreForRenderProcess(render_process_id); |
| 2737 } |
| 2738 |
2701 #if defined(ENABLE_WEBRTC) | 2739 #if defined(ENABLE_WEBRTC) |
2702 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( | 2740 void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( |
2703 CommandLine* to_command_line, | 2741 CommandLine* to_command_line, |
2704 const CommandLine& from_command_line, | 2742 const CommandLine& from_command_line, |
2705 VersionInfo::Channel channel) { | 2743 VersionInfo::Channel channel) { |
2706 #if defined(OS_ANDROID) | 2744 #if defined(OS_ANDROID) |
2707 const VersionInfo::Channel kMaxDisableEncryptionChannel = | 2745 const VersionInfo::Channel kMaxDisableEncryptionChannel = |
2708 VersionInfo::CHANNEL_BETA; | 2746 VersionInfo::CHANNEL_BETA; |
2709 #else | 2747 #else |
2710 const VersionInfo::Channel kMaxDisableEncryptionChannel = | 2748 const VersionInfo::Channel kMaxDisableEncryptionChannel = |
2711 VersionInfo::CHANNEL_DEV; | 2749 VersionInfo::CHANNEL_DEV; |
2712 #endif | 2750 #endif |
2713 if (channel <= kMaxDisableEncryptionChannel) { | 2751 if (channel <= kMaxDisableEncryptionChannel) { |
2714 static const char* const kWebRtcDevSwitchNames[] = { | 2752 static const char* const kWebRtcDevSwitchNames[] = { |
2715 switches::kDisableWebRtcEncryption, | 2753 switches::kDisableWebRtcEncryption, |
2716 }; | 2754 }; |
2717 to_command_line->CopySwitchesFrom(from_command_line, | 2755 to_command_line->CopySwitchesFrom(from_command_line, |
2718 kWebRtcDevSwitchNames, | 2756 kWebRtcDevSwitchNames, |
2719 arraysize(kWebRtcDevSwitchNames)); | 2757 arraysize(kWebRtcDevSwitchNames)); |
2720 } | 2758 } |
2721 } | 2759 } |
2722 #endif // defined(ENABLE_WEBRTC) | 2760 #endif // defined(ENABLE_WEBRTC) |
2723 | 2761 |
2724 } // namespace chrome | 2762 } // namespace chrome |
OLD | NEW |