• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2006-2008 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.
4 
5 // We handle some special browser-level URLs (like "about:version")
6 // before they're handed to a renderer.  This lets us do the URL handling
7 // on the browser side (which has access to more information than the
8 // renderers do) as well as sidestep the risk of exposing data to
9 // random web pages (because from the resource loader's perspective, these
10 // URL schemes don't exist).
11 
12 #ifndef CHROME_BROWSER_BROWSER_URL_HANDLER_H_
13 #define CHROME_BROWSER_BROWSER_URL_HANDLER_H_
14 #pragma once
15 
16 #include <vector>
17 #include <utility>
18 
19 class GURL;
20 class Profile;
21 
22 // BrowserURLHandler manages the list of all special URLs and manages
23 // dispatching the URL handling to registered handlers.
24 class BrowserURLHandler {
25  public:
26   // The type of functions that can process a URL.
27   // If a handler handles |url|, it should :
28   // - optionally modify |url| to the URL that should be sent to the renderer
29   // If the URL is not handled by a handler, it should return false.
30   typedef bool (*URLHandler)(GURL* url, Profile* profile);
31 
32   // RewriteURLIfNecessary gives all registered URLHandlers a shot at processing
33   // the given URL, and modifies it in place.
34   // If the original URL needs to be adjusted if the modified URL is redirected,
35   // this function sets |reverse_on_redirect| to true.
36   static void RewriteURLIfNecessary(GURL* url, Profile* profile,
37                                     bool* reverse_on_redirect);
38 
39   // Reverses the rewriting that was done for |original| using the new |url|.
40   static bool ReverseURLRewrite(GURL* url, const GURL& original,
41                                 Profile* profile);
42 
43   // We initialize the list of url_handlers_ lazily the first time
44   // RewriteURLIfNecessary is called.
45   static void InitURLHandlers();
46 
47  private:
48   // The list of known URLHandlers, optionally with reverse-rewriters.
49   typedef std::pair<URLHandler, URLHandler> HandlerPair;
50   static std::vector<HandlerPair> url_handlers_;
51 };
52 
53 #endif  // CHROME_BROWSER_BROWSER_URL_HANDLER_H_
54