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