OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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/browser_url_handler.h" | 5 #include "chrome/browser/browser_url_handler.h" |
6 | 6 |
| 7 #include "base/string_util.h" |
7 #include "chrome/browser/browser_about_handler.h" | 8 #include "chrome/browser/browser_about_handler.h" |
8 #include "chrome/browser/dom_ui/dom_ui_contents.h" | 9 #include "chrome/browser/dom_ui/dom_ui_contents.h" |
| 10 #include "chrome/common/url_constants.h" |
| 11 |
| 12 // Handles rewriting view-source URLs for what we'll actually load. |
| 13 static bool HandleViewSource(GURL* url, TabContentsType* type) { |
| 14 if (url->SchemeIs(chrome::kViewSourceScheme)) { |
| 15 // Load the inner URL instead. |
| 16 *url = GURL(url->path()); |
| 17 *type = TAB_CONTENTS_WEB; |
| 18 return true; |
| 19 } |
| 20 return false; |
| 21 } |
9 | 22 |
10 std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_; | 23 std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_; |
11 | 24 |
12 // static | 25 // static |
13 void BrowserURLHandler::InitURLHandlers() { | 26 void BrowserURLHandler::InitURLHandlers() { |
14 if (!url_handlers_.empty()) | 27 if (!url_handlers_.empty()) |
15 return; | 28 return; |
16 | 29 |
17 // Here is where we initialize the global list of handlers for special URLs. | 30 // Add the default URL handlers. |
18 // about:* | 31 url_handlers_.push_back(&WillHandleBrowserAboutURL); // about: |
19 url_handlers_.push_back(&BrowserAboutHandler::MaybeHandle); | 32 url_handlers_.push_back(&DOMUIContentsCanHandleURL); // chrome-ui: |
20 // chrome-ui:* | 33 url_handlers_.push_back(&HandleViewSource); // view-source: |
21 url_handlers_.push_back(&DOMUIContentsCanHandleURL); | |
22 } | 34 } |
23 | 35 |
24 // static | 36 // static |
25 bool BrowserURLHandler::HandleBrowserURL(GURL* url, TabContentsType* type) { | 37 bool BrowserURLHandler::HandleBrowserURL(GURL* url, TabContentsType* type) { |
26 if (url_handlers_.empty()) | 38 if (url_handlers_.empty()) |
27 InitURLHandlers(); | 39 InitURLHandlers(); |
28 for (size_t i = 0; i < url_handlers_.size(); ++i) { | 40 for (size_t i = 0; i < url_handlers_.size(); ++i) { |
29 if ((*url_handlers_[i])(url, type)) | 41 if ((*url_handlers_[i])(url, type)) |
30 return true; | 42 return true; |
31 } | 43 } |
32 return false; | 44 return false; |
33 } | 45 } |
34 | |
OLD | NEW |