blob: 37f65c6e4db18e747da0ecda99bc6eb8153a362c [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/web/browser_url_rewriter_impl.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "ios/web/public/browser_state.h"
#import "ios/web/public/web_client.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
namespace web {
namespace {
// The scheme used to view the source of a page using WebUI in content/.
const char kViewSourceScheme[] = "view-source";
// Handles rewriting view-source URLs for what we'll actually load. Since
// WebUI-based view-source isn't supported on iOS, simply strip out the scheme
// and load the URL. This is to gracefully handle tabs synced from other
// platforms with the "view-source:" scheme.
static bool HandleViewSource(GURL* url, BrowserState* browser_state) {
if (url->SchemeIs(kViewSourceScheme)) {
// Load the inner URL instead.
*url = GURL(url->GetContent());
return true;
return false;
} // namespace
// static
BrowserURLRewriter* BrowserURLRewriter::GetInstance() {
return BrowserURLRewriterImpl::GetInstance();
// static
bool BrowserURLRewriter::RewriteURLWithWriters(
GURL* url,
web::BrowserState* browser_state,
const std::vector<BrowserURLRewriter::URLRewriter>& rewriters) {
bool rewritten = false;
for (URLRewriter rewriter : rewriters) {
if ((rewritten = rewriter(url, browser_state)))
return rewritten;
// static
BrowserURLRewriterImpl* BrowserURLRewriterImpl::GetInstance() {
return base::Singleton<BrowserURLRewriterImpl>::get();
BrowserURLRewriterImpl::BrowserURLRewriterImpl() {
web::WebClient* web_client = web::GetWebClient();
if (web_client)
// view-source:
BrowserURLRewriterImpl::~BrowserURLRewriterImpl() {}
void BrowserURLRewriterImpl::AddURLRewriter(URLRewriter rewriter) {
bool BrowserURLRewriterImpl::RewriteURLIfNecessary(
GURL* url,
BrowserState* browser_state) {
return BrowserURLRewriter::RewriteURLWithWriters(url, browser_state,
} // namespace web