1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_WEB_PUBLIC_BROWSER_URL_REWRITER_H_
6 #define IOS_WEB_PUBLIC_BROWSER_URL_REWRITER_H_
14 // Some special browser-level URLs (like "about:version") are handled before
15 // actually being loaded by the web view, allowing the embedder to optionally
16 // convert them to app-specific URLs that to be handled using
17 // CRWNativeContentProviders.
18 class BrowserURLRewriter
{
20 // The type of functions that can process a URL. URLRewriters return true if
21 // |url| is ready to be loaded and added to the NavigationManager. They can
22 // optionally modify |url| regardless of whether they return true or false.
23 typedef bool (*URLRewriter
)(GURL
* url
, BrowserState
* browser_state
);
25 // Returns the singleton instance.
26 static BrowserURLRewriter
* GetInstance();
28 // Gives every URLRewriter in |rewriters| a chance to process |url|, modifying
29 // it in place. Returns whether or not a URLRewriter returned |true|.
30 static bool RewriteURLWithWriters(
32 BrowserState
* browser_state
,
33 const std::vector
<BrowserURLRewriter::URLRewriter
>& rewriters
);
35 // Gives every URLRewriter added via |AddURLRewriter()| a chance to process
36 // |url|, modifying it in place. Returns whether or not a URLRewriter
38 virtual bool RewriteURLIfNecessary(GURL
* url
,
39 BrowserState
* browser_state
) = 0;
41 // Adds |rewriter| to the list of URL rewriters. |rewriter| must not be null.
42 virtual void AddURLRewriter(URLRewriter rewriter
) = 0;
45 virtual ~BrowserURLRewriter() {}
50 #endif // IOS_WEB_PUBLIC_BROWSER_URL_REWRITER_H_