Revert 99759 - Add two new valgrind suppressions.
[chromium-blink-merge.git] / content / browser / browser_url_handler.h
blob881c080c3061cc79abee8a60d7f9f0884970ffd0
1 // Copyright (c) 2011 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 // 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).
12 #ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_H_
13 #define CONTENT_BROWSER_BROWSER_URL_HANDLER_H_
14 #pragma once
16 #include <vector>
17 #include <utility>
19 #include "base/gtest_prod_util.h"
20 #include "base/memory/singleton.h"
22 class GURL;
24 namespace content {
25 class BrowserContext;
28 // BrowserURLHandler manages the list of all special URLs and manages
29 // dispatching the URL handling to registered handlers.
30 class BrowserURLHandler {
31 public:
32 // The type of functions that can process a URL.
33 // If a handler handles |url|, it should :
34 // - optionally modify |url| to the URL that should be sent to the renderer
35 // If the URL is not handled by a handler, it should return false.
36 typedef bool (*URLHandler)(GURL* url,
37 content::BrowserContext* browser_context);
39 // Returns the singleton instance.
40 static BrowserURLHandler* GetInstance();
42 // RewriteURLIfNecessary gives all registered URLHandlers a shot at processing
43 // the given URL, and modifies it in place.
44 // If the original URL needs to be adjusted if the modified URL is redirected,
45 // this function sets |reverse_on_redirect| to true.
46 void RewriteURLIfNecessary(GURL* url,
47 content::BrowserContext* browser_context,
48 bool* reverse_on_redirect);
50 // Reverses the rewriting that was done for |original| using the new |url|.
51 bool ReverseURLRewrite(GURL* url, const GURL& original,
52 content::BrowserContext* browser_context);
54 // Add the specified handler pair to the list of URL handlers.
55 void AddHandlerPair(URLHandler handler, URLHandler reverse_handler);
57 // Returns the null handler for use with |AddHandlerPair()|.
58 static URLHandler null_handler();
60 private:
61 // This object is a singleton:
62 BrowserURLHandler();
63 ~BrowserURLHandler();
64 friend struct DefaultSingletonTraits<BrowserURLHandler>;
66 // The list of known URLHandlers, optionally with reverse-rewriters.
67 typedef std::pair<URLHandler, URLHandler> HandlerPair;
68 std::vector<HandlerPair> url_handlers_;
70 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, BasicRewriteAndReverse);
71 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, NullHandlerReverse);
73 DISALLOW_COPY_AND_ASSIGN(BrowserURLHandler);
76 #endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_H_