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

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

Issue 2931243002: Unframe chrome://extensions as it's the last (and only) uber item (Closed)
Patch Set: policy_android.css 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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 // to given path. Other parts of the url will be the same. 585 // to given path. Other parts of the url will be the same.
586 GURL ReplaceURLHostAndPath(const GURL& url, 586 GURL ReplaceURLHostAndPath(const GURL& url,
587 const std::string& host, 587 const std::string& host,
588 const std::string& path) { 588 const std::string& path) {
589 url::Replacements<char> replacements; 589 url::Replacements<char> replacements;
590 replacements.SetHost(host.c_str(), url::Component(0, host.length())); 590 replacements.SetHost(host.c_str(), url::Component(0, host.length()));
591 replacements.SetPath(path.c_str(), url::Component(0, path.length())); 591 replacements.SetPath(path.c_str(), url::Component(0, path.length()));
592 return url.ReplaceComponents(replacements); 592 return url.ReplaceComponents(replacements);
593 } 593 }
594 594
595 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
596 GURL AddUberHost(const GURL& url) {
597 const std::string uber_host = chrome::kChromeUIUberHost;
598 std::string new_path;
599 url.host_piece().AppendToString(&new_path);
600 url.path_piece().AppendToString(&new_path);
601
602 return ReplaceURLHostAndPath(url, uber_host, new_path);
603 }
604
605 // If url->host() is "chrome" and url->path() has characters other than the
606 // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
607 // returns true. Otherwise returns false.
608 bool RemoveUberHost(GURL* url) {
609 if (url->host() != chrome::kChromeUIUberHost)
610 return false;
611
612 if (url->path().empty() || url->path() == "/")
613 return false;
614
615 const std::string old_path = url->path();
616
617 const std::string::size_type separator = old_path.find('/', 1);
618 std::string new_host;
619 std::string new_path;
620 if (separator == std::string::npos) {
621 new_host = old_path.substr(1);
622 } else {
623 new_host = old_path.substr(1, separator - 1);
624 new_path = old_path.substr(separator);
625 }
626
627 // Do not allow URLs with paths empty before the first slash since we can't
628 // have an empty host. (e.g "foo://chrome//")
629 if (new_host.empty())
630 return false;
631
632 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
633
634 DCHECK(url->is_valid());
635
636 return true;
637 }
638
639 // Handles the rewriting of the new tab page URL based on group policy. 595 // Handles the rewriting of the new tab page URL based on group policy.
640 bool HandleNewTabPageLocationOverride( 596 bool HandleNewTabPageLocationOverride(
641 GURL* url, 597 GURL* url,
642 content::BrowserContext* browser_context) { 598 content::BrowserContext* browser_context) {
643 if (!url->SchemeIs(content::kChromeUIScheme) || 599 if (!url->SchemeIs(content::kChromeUIScheme) ||
644 url->host() != chrome::kChromeUINewTabHost) 600 url->host() != chrome::kChromeUINewTabHost)
645 return false; 601 return false;
646 602
647 Profile* profile = Profile::FromBrowserContext(browser_context); 603 Profile* profile = Profile::FromBrowserContext(browser_context);
648 std::string ntp_location = 604 std::string ntp_location =
649 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride); 605 profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride);
650 if (ntp_location.empty()) 606 if (ntp_location.empty())
651 return false; 607 return false;
652 608
653 *url = GURL(ntp_location); 609 *url = GURL(ntp_location);
654 return true; 610 return true;
655 } 611 }
656 612
657 // Handles rewriting Web UI URLs. 613 // Handles rewriting Web UI URLs.
658 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { 614 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
659 // Rewrite chrome://help and chrome://chrome to chrome://settings/help. 615 // Rewrite chrome://help and chrome://chrome to chrome://settings/help.
660 if (url->host() == chrome::kChromeUIHelpHost || 616 if (url->host() == chrome::kChromeUIHelpHost ||
661 (url->host() == chrome::kChromeUIUberHost && 617 (url->host() == chrome::kChromeUIUberHost &&
662 (url->path().empty() || url->path() == "/"))) { 618 (url->path().empty() || url->path() == "/"))) {
663 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost, 619 *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost,
664 chrome::kChromeUIHelpHost); 620 chrome::kChromeUIHelpHost);
665 return true; // Return true to update the displayed URL. 621 return true; // Return true to update the displayed URL.
666 } 622 }
667 623
668 // Do not handle special URLs such as "about:foo" 624 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
669 if (!url->host().empty()) { 625 browser_context, *url)) {
670 const GURL chrome_url = AddUberHost(*url); 626 return false;
671
672 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
673 // be called.
674 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
675 browser_context, chrome_url))
676 return true;
677 } 627 }
678 628
679 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
680 browser_context, *url))
681 return false;
682
683 #if defined(OS_CHROMEOS) 629 #if defined(OS_CHROMEOS)
684 // Special case : in ChromeOS in Guest mode bookmarks and history are 630 // Special case : in ChromeOS in Guest mode bookmarks and history are
685 // disabled for security reasons. New tab page explains the reasons, so 631 // disabled for security reasons. New tab page explains the reasons, so
686 // we redirect user to new tab page. 632 // we redirect user to new tab page.
687 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { 633 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) {
688 if (url->SchemeIs(content::kChromeUIScheme) && 634 if (url->SchemeIs(content::kChromeUIScheme) &&
689 (url->DomainIs(chrome::kChromeUIBookmarksHost) || 635 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
690 url->DomainIs(chrome::kChromeUIHistoryHost))) { 636 url->DomainIs(chrome::kChromeUIHistoryHost))) {
691 // Rewrite with new tab URL 637 // Rewrite with new tab URL
692 *url = GURL(chrome::kChromeUINewTabURL); 638 *url = GURL(chrome::kChromeUINewTabURL);
693 } 639 }
694 } 640 }
695 #endif 641 #endif
696 642
697 return true; 643 return true;
698 } 644 }
699 645
700 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to 646 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
701 // "chrome://foo/". 647 // "chrome://foo/".
702 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) { 648 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
703 // No need to actually reverse-rewrite the URL, but return true to update the 649 // No need to actually reverse-rewrite the URL, but return true to update the
704 // displayed URL when rewriting chrome://help to chrome://settings/help. 650 // displayed URL when rewriting chrome://help to chrome://settings/help.
705 if (url->host() == chrome::kChromeUISettingsHost) 651 return url->host() == chrome::kChromeUISettingsHost;
706 return true;
707
708 if (!url->is_valid() || !url->SchemeIs(content::kChromeUIScheme))
709 return false;
710
711 return RemoveUberHost(url);
712 } 652 }
713 653
714 bool CertMatchesFilter(const net::X509Certificate& cert, 654 bool CertMatchesFilter(const net::X509Certificate& cert,
715 const base::DictionaryValue& filter) { 655 const base::DictionaryValue& filter) {
716 // TODO(markusheintz): This is the minimal required filter implementation. 656 // TODO(markusheintz): This is the minimal required filter implementation.
717 // Implement a better matcher. 657 // Implement a better matcher.
718 658
719 // An empty filter matches any client certificate since no requirements are 659 // An empty filter matches any client certificate since no requirements are
720 // specified at all. 660 // specified at all.
721 if (filter.empty()) 661 if (filter.empty())
(...skipping 2782 matching lines...) Expand 10 before | Expand all | Expand 10 after
3504 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { 3444 RedirectNonUINonIOBrowserThreadsToTaskScheduler() {
3505 return variations::GetVariationParamValue( 3445 return variations::GetVariationParamValue(
3506 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; 3446 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true";
3507 } 3447 }
3508 3448
3509 // static 3449 // static
3510 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( 3450 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
3511 const storage::QuotaSettings* settings) { 3451 const storage::QuotaSettings* settings) {
3512 g_default_quota_settings = settings; 3452 g_default_quota_settings = settings;
3513 } 3453 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_resources.grd ('k') | chrome/browser/extensions/extension_webui_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698