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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/lazy_instance.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_tokenizer.h" | 16 #include "base/strings/string_tokenizer.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "chrome/app/breakpad_mac.h" | 18 #include "chrome/app/breakpad_mac.h" |
18 #include "chrome/browser/browser_about_handler.h" | 19 #include "chrome/browser/browser_about_handler.h" |
19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 21 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
21 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 22 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
22 #include "chrome/browser/character_encoding.h" | 23 #include "chrome/browser/character_encoding.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 using content::RenderViewHost; | 174 using content::RenderViewHost; |
174 using content::SiteInstance; | 175 using content::SiteInstance; |
175 using content::WebContents; | 176 using content::WebContents; |
176 using extensions::APIPermission; | 177 using extensions::APIPermission; |
177 using extensions::Extension; | 178 using extensions::Extension; |
178 using extensions::Manifest; | 179 using extensions::Manifest; |
179 using webkit_glue::WebPreferences; | 180 using webkit_glue::WebPreferences; |
180 | 181 |
181 namespace { | 182 namespace { |
182 | 183 |
| 184 // Cached version of the locale so we can return the locale on the I/O |
| 185 // thread. |
| 186 base::LazyInstance<std::string> g_io_thread_application_locale; |
| 187 |
183 const char* kPredefinedAllowedSocketOrigins[] = { | 188 const char* kPredefinedAllowedSocketOrigins[] = { |
184 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client | 189 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client |
185 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client) | 190 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client) |
186 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 | 191 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 |
187 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop | 192 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop |
188 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop | 193 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop |
189 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop | 194 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop |
190 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary | 195 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary |
191 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 | 196 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 |
192 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 | 197 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 GURL effective_url(SigninManager::kChromeSigninEffectiveSite); | 459 GURL effective_url(SigninManager::kChromeSigninEffectiveSite); |
455 // Copy the path because the argument to SetPathStr must outlive | 460 // Copy the path because the argument to SetPathStr must outlive |
456 // the Replacements object. | 461 // the Replacements object. |
457 const std::string path_copy(url.path()); | 462 const std::string path_copy(url.path()); |
458 GURL::Replacements replacements; | 463 GURL::Replacements replacements; |
459 replacements.SetPathStr(path_copy); | 464 replacements.SetPathStr(path_copy); |
460 effective_url = effective_url.ReplaceComponents(replacements); | 465 effective_url = effective_url.ReplaceComponents(replacements); |
461 return effective_url; | 466 return effective_url; |
462 } | 467 } |
463 | 468 |
| 469 void SetApplicationLocaleOnIOThread(const std::string& locale) { |
| 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 471 g_io_thread_application_locale.Get() = locale; |
| 472 } |
| 473 |
464 } // namespace | 474 } // namespace |
465 | 475 |
466 namespace chrome { | 476 namespace chrome { |
467 | 477 |
468 ChromeContentBrowserClient::ChromeContentBrowserClient() { | 478 ChromeContentBrowserClient::ChromeContentBrowserClient() { |
469 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) | 479 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) |
470 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); | 480 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
471 } | 481 } |
472 | 482 |
473 ChromeContentBrowserClient::~ChromeContentBrowserClient() { | 483 ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
474 } | 484 } |
475 | 485 |
476 // static | 486 // static |
477 void ChromeContentBrowserClient::RegisterUserPrefs( | 487 void ChromeContentBrowserClient::RegisterUserPrefs( |
478 PrefRegistrySyncable* registry) { | 488 PrefRegistrySyncable* registry) { |
479 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, | 489 registry->RegisterBooleanPref(prefs::kDisable3DAPIs, |
480 false, | 490 false, |
481 PrefRegistrySyncable::UNSYNCABLE_PREF); | 491 PrefRegistrySyncable::UNSYNCABLE_PREF); |
482 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, | 492 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, |
483 true, | 493 true, |
484 PrefRegistrySyncable::UNSYNCABLE_PREF); | 494 PrefRegistrySyncable::UNSYNCABLE_PREF); |
485 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo, | 495 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo, |
486 false, | 496 false, |
487 PrefRegistrySyncable::UNSYNCABLE_PREF); | 497 PrefRegistrySyncable::UNSYNCABLE_PREF); |
488 } | 498 } |
489 | 499 |
| 500 // static |
| 501 void ChromeContentBrowserClient::SetApplicationLocale( |
| 502 const std::string& locale) { |
| 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 504 |
| 505 // This object is guaranteed to outlive all threads so we don't have to |
| 506 // worry about the lack of refcounting and can just post as Unretained. |
| 507 // |
| 508 // The common case is that this function is called early in Chrome startup |
| 509 // before any threads are created (it will also be called later if the user |
| 510 // changes the pref). In this case, there will be no threads created and |
| 511 // posting will fail. When there are no threads, we can just set the string |
| 512 // without worrying about threadsafety. |
| 513 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 514 base::Bind(&SetApplicationLocaleOnIOThread, locale))) { |
| 515 g_io_thread_application_locale.Get() = locale; |
| 516 } |
| 517 } |
| 518 |
490 content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( | 519 content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( |
491 const content::MainFunctionParams& parameters) { | 520 const content::MainFunctionParams& parameters) { |
492 ChromeBrowserMainParts* main_parts; | 521 ChromeBrowserMainParts* main_parts; |
493 // Construct the Main browser parts based on the OS type. | 522 // Construct the Main browser parts based on the OS type. |
494 #if defined(OS_WIN) | 523 #if defined(OS_WIN) |
495 main_parts = new ChromeBrowserMainPartsWin(parameters); | 524 main_parts = new ChromeBrowserMainPartsWin(parameters); |
496 #elif defined(OS_MACOSX) | 525 #elif defined(OS_MACOSX) |
497 main_parts = new ChromeBrowserMainPartsMac(parameters); | 526 main_parts = new ChromeBrowserMainPartsMac(parameters); |
498 #elif defined(OS_CHROMEOS) | 527 #elif defined(OS_CHROMEOS) |
499 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters); | 528 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters); |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 | 1285 |
1257 // The command line switch kEnableBenchmarking needs to be specified along | 1286 // The command line switch kEnableBenchmarking needs to be specified along |
1258 // with the kEnableStatsTable switch to ensure that the stats table global | 1287 // with the kEnableStatsTable switch to ensure that the stats table global |
1259 // is initialized correctly. | 1288 // is initialized correctly. |
1260 if (command_line->HasSwitch(switches::kEnableBenchmarking)) | 1289 if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
1261 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); | 1290 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); |
1262 } | 1291 } |
1263 | 1292 |
1264 std::string ChromeContentBrowserClient::GetApplicationLocale() { | 1293 std::string ChromeContentBrowserClient::GetApplicationLocale() { |
1265 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) | 1294 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
1266 return io_thread_application_locale_; | 1295 return g_io_thread_application_locale.Get(); |
1267 return g_browser_process->GetApplicationLocale(); | 1296 return g_browser_process->GetApplicationLocale(); |
1268 } | 1297 } |
1269 | 1298 |
1270 std::string ChromeContentBrowserClient::GetAcceptLangs( | 1299 std::string ChromeContentBrowserClient::GetAcceptLangs( |
1271 content::BrowserContext* context) { | 1300 content::BrowserContext* context) { |
1272 Profile* profile = Profile::FromBrowserContext(context); | 1301 Profile* profile = Profile::FromBrowserContext(context); |
1273 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 1302 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
1274 } | 1303 } |
1275 | 1304 |
1276 gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() { | 1305 gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() { |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 content::BrowserContext* browser_context = | 1923 content::BrowserContext* browser_context = |
1895 rvh->GetProcess()->GetBrowserContext(); | 1924 rvh->GetProcess()->GetBrowserContext(); |
1896 DictionaryPrefUpdate update( | 1925 DictionaryPrefUpdate update( |
1897 Profile::FromBrowserContext(browser_context)->GetPrefs(), | 1926 Profile::FromBrowserContext(browser_context)->GetPrefs(), |
1898 prefs::kWebKitInspectorSettings); | 1927 prefs::kWebKitInspectorSettings); |
1899 DictionaryValue* inspector_settings = update.Get(); | 1928 DictionaryValue* inspector_settings = update.Get(); |
1900 inspector_settings->SetWithoutPathExpansion(key, | 1929 inspector_settings->SetWithoutPathExpansion(key, |
1901 Value::CreateStringValue(value)); | 1930 Value::CreateStringValue(value)); |
1902 } | 1931 } |
1903 | 1932 |
1904 void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) { | |
1905 content::BrowserContext* browser_context = | |
1906 rvh->GetProcess()->GetBrowserContext(); | |
1907 Profile::FromBrowserContext(browser_context)->GetPrefs()-> | |
1908 ClearPref(prefs::kWebKitInspectorSettings); | |
1909 } | |
1910 | |
1911 void ChromeContentBrowserClient::BrowserURLHandlerCreated( | 1933 void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
1912 BrowserURLHandler* handler) { | 1934 BrowserURLHandler* handler) { |
1913 // Add the default URL handlers. | 1935 // Add the default URL handlers. |
1914 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, | 1936 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, |
1915 BrowserURLHandler::null_handler()); | 1937 BrowserURLHandler::null_handler()); |
1916 handler->AddHandlerPair(BrowserURLHandler::null_handler(), | 1938 handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
1917 &ExtensionWebUI::HandleChromeURLOverrideReverse); | 1939 &ExtensionWebUI::HandleChromeURLOverrideReverse); |
1918 | 1940 |
1919 // about: handler. Must come before chrome: handler, since it will | 1941 // about: handler. Must come before chrome: handler, since it will |
1920 // rewrite about: urls to chrome: URLs and then expect chrome: to | 1942 // rewrite about: urls to chrome: URLs and then expect chrome: to |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2160 | 2182 |
2161 #if defined(USE_NSS) | 2183 #if defined(USE_NSS) |
2162 crypto::CryptoModuleBlockingPasswordDelegate* | 2184 crypto::CryptoModuleBlockingPasswordDelegate* |
2163 ChromeContentBrowserClient::GetCryptoPasswordDelegate( | 2185 ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
2164 const GURL& url) { | 2186 const GURL& url) { |
2165 return chrome::NewCryptoModuleBlockingDialogDelegate( | 2187 return chrome::NewCryptoModuleBlockingDialogDelegate( |
2166 chrome::kCryptoModulePasswordKeygen, url.host()); | 2188 chrome::kCryptoModulePasswordKeygen, url.host()); |
2167 } | 2189 } |
2168 #endif | 2190 #endif |
2169 | 2191 |
2170 void ChromeContentBrowserClient::SetApplicationLocale( | |
2171 const std::string& locale) { | |
2172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2173 | |
2174 // This object is guaranteed to outlive all threads so we don't have to | |
2175 // worry about the lack of refcounting and can just post as Unretained. | |
2176 // | |
2177 // The common case is that this function is called early in Chrome startup | |
2178 // before any threads are created (it will also be called later if the user | |
2179 // changes the pref). In this case, there will be no threads created and | |
2180 // posting will fail. When there are no threads, we can just set the string | |
2181 // without worrying about threadsafety. | |
2182 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
2183 base::Bind( | |
2184 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread, | |
2185 base::Unretained(this), locale))) | |
2186 io_thread_application_locale_ = locale; | |
2187 } | |
2188 | |
2189 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( | |
2190 const std::string& locale) { | |
2191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
2192 io_thread_application_locale_ = locale; | |
2193 } | |
2194 | |
2195 } // namespace chrome | 2192 } // namespace chrome |
OLD | NEW |