Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(775)

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 2949053004: MD Settings: fix help/ redirection to only happen on chrome://help (Closed)
Patch Set: whoops Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 Profile* profile = Profile::FromBrowserContext(browser_context); 604 Profile* profile = Profile::FromBrowserContext(browser_context);
605 std::string ntp_location = 605 std::string ntp_location =
606 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride); 606 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
607 if (ntp_location.empty()) 607 if (ntp_location.empty())
608 return false; 608 return false;
609 609
610 *url = GURL(ntp_location); 610 *url = GURL(ntp_location);
611 return true; 611 return true;
612 } 612 }
613 613
614 // Handles rewriting Web UI URLs.
615 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
616 // Rewrite chrome://help and chrome://chrome to chrome://settings/help.
617 if (url->host() == chrome::kChromeUIHelpHost ||
618 (url->host() == chrome::kChromeUIUberHost &&
619 (url->path().empty() || url->path() == "/"))) {
620 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
621 chrome::kChromeUIHelpHost);
622 return true; // Return true to update the displayed URL.
623 }
624
625 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
626 browser_context, *url)) {
627 return false;
628 }
629
630 #if defined(OS_CHROMEOS)
631 // Special case : in ChromeOS in Guest mode bookmarks and history are
632 // disabled for security reasons. New tab page explains the reasons, so
633 // we redirect user to new tab page.
634 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
635 if (url->SchemeIs(content::kChromeUIScheme) &&
636 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
637 url->DomainIs(chrome::kChromeUIHistoryHost))) {
638 // Rewrite with new tab URL
639 *url = GURL(chrome::kChromeUINewTabURL);
640 }
641 }
642 #endif
643
644 return true;
645 }
646
647 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
648 // "chrome://foo/".
649 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
650 // No need to actually reverse-rewrite the URL, but return true to update the
651 // displayed URL when rewriting chrome://help to chrome://settings/help.
652 return url->host() == chrome::kChromeUISettingsHost;
653 }
654
655 bool CertMatchesFilter(const net::X509Certificate& cert, 614 bool CertMatchesFilter(const net::X509Certificate& cert,
656 const base::DictionaryValue& filter) { 615 const base::DictionaryValue& filter) {
657 // TODO(markusheintz): This is the minimal required filter implementation. 616 // TODO(markusheintz): This is the minimal required filter implementation.
658 // Implement a better matcher. 617 // Implement a better matcher.
659 618
660 // An empty filter matches any client certificate since no requirements are 619 // An empty filter matches any client certificate since no requirements are
661 // specified at all. 620 // specified at all.
662 if (filter.empty()) 621 if (filter.empty())
663 return true; 622 return true;
664 623
(...skipping 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 // Handler to rewrite chrome://newtab on Android. 2622 // Handler to rewrite chrome://newtab on Android.
2664 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL, 2623 handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL,
2665 BrowserURLHandler::null_handler()); 2624 BrowserURLHandler::null_handler());
2666 #else 2625 #else
2667 // Handler to rewrite chrome://newtab for InstantExtended. 2626 // Handler to rewrite chrome://newtab for InstantExtended.
2668 handler->AddHandlerPair(&search::HandleNewTabURLRewrite, 2627 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
2669 &search::HandleNewTabURLReverseRewrite); 2628 &search::HandleNewTabURLReverseRewrite);
2670 #endif 2629 #endif
2671 2630
2672 // chrome: & friends. 2631 // chrome: & friends.
2673 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse); 2632 handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI,
2633 &ChromeContentBrowserClient::HandleWebUIReverse);
2674 } 2634 }
2675 2635
2676 base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { 2636 base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2677 return DownloadPrefs::GetDefaultDownloadDirectory(); 2637 return DownloadPrefs::GetDefaultDownloadDirectory();
2678 } 2638 }
2679 2639
2680 std::string ChromeContentBrowserClient::GetDefaultDownloadName() { 2640 std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2681 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); 2641 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2682 } 2642 }
2683 2643
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
3459 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 3419 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
3460 switches::kEnableNetworkService)); 3420 switches::kEnableNetworkService));
3461 3421
3462 std::vector<std::unique_ptr<content::URLLoaderThrottle>> result; 3422 std::vector<std::unique_ptr<content::URLLoaderThrottle>> result;
3463 result.push_back(base::MakeUnique<safe_browsing::BrowserURLLoaderThrottle>( 3423 result.push_back(base::MakeUnique<safe_browsing::BrowserURLLoaderThrottle>(
3464 safe_browsing_service_->database_manager(), 3424 safe_browsing_service_->database_manager(),
3465 safe_browsing_service_->ui_manager(), wc_getter)); 3425 safe_browsing_service_->ui_manager(), wc_getter));
3466 return result; 3426 return result;
3467 } 3427 }
3468 3428
3429 // Static; handles rewriting Web UI URLs.
3430 bool ChromeContentBrowserClient::HandleWebUI(
3431 GURL* url,
3432 content::BrowserContext* browser_context) {
3433 // Rewrite chrome://help and chrome://chrome to chrome://settings/help.
3434 if (url->SchemeIs(content::kChromeUIScheme) &&
3435 (url->host() == chrome::kChromeUIHelpHost ||
3436 (url->host() == chrome::kChromeUIUberHost &&
3437 (url->path().empty() || url->path() == "/")))) {
3438 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
3439 chrome::kChromeUIHelpHost);
3440 return true; // Return true to update the displayed URL.
3441 }
3442
3443 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
3444 browser_context, *url)) {
3445 return false;
3446 }
3447
3448 #if defined(OS_CHROMEOS)
3449 // Special case : in ChromeOS in Guest mode bookmarks and history are
3450 // disabled for security reasons. New tab page explains the reasons, so
3451 // we redirect user to new tab page.
3452 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
3453 if (url->SchemeIs(content::kChromeUIScheme) &&
3454 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
3455 url->DomainIs(chrome::kChromeUIHistoryHost))) {
3456 // Rewrite with new tab URL
3457 *url = GURL(chrome::kChromeUINewTabURL);
3458 }
3459 }
3460 #endif
3461
3462 return true;
3463 }
3464
3465 // Static; reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
3466 // "chrome://foo/".
3467 bool ChromeContentBrowserClient::HandleWebUIReverse(
3468 GURL* url,
3469 content::BrowserContext* browser_context) {
3470 // No need to actually reverse-rewrite the URL, but return true to update the
3471 // displayed URL when rewriting chrome://help to chrome://settings/help.
3472 return url->SchemeIs(content::kChromeUIScheme) &&
3473 url->host() == chrome::kChromeUISettingsHost;
3474 }
3475
3469 // static 3476 // static
3470 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( 3477 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
3471 const storage::QuotaSettings* settings) { 3478 const storage::QuotaSettings* settings) {
3472 g_default_quota_settings = settings; 3479 g_default_quota_settings = settings;
3473 } 3480 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.h ('k') | chrome/browser/chrome_content_browser_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698