| 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 "base/string_util.h" |
| 8 #include "chrome/browser/browser_about_handler.h" | 8 #include "chrome/browser/browser_about_handler.h" |
| 9 #include "chrome/browser/dom_ui/dom_ui_factory.h" | 9 #include "chrome/browser/dom_ui/dom_ui_factory.h" |
| 10 #include "chrome/browser/extensions/extension_dom_ui.h" | 10 #include "chrome/browser/extensions/extension_dom_ui.h" |
| 11 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 | 14 |
| 15 // Handles rewriting view-source URLs for what we'll actually load. | 15 // Handles rewriting view-source URLs for what we'll actually load. |
| 16 static bool HandleViewSource(GURL* url, Profile* profile) { | 16 static bool HandleViewSource(GURL* url, Profile* profile) { |
| 17 if (url->SchemeIs(chrome::kViewSourceScheme)) { | 17 if (url->SchemeIs(chrome::kViewSourceScheme)) { |
| 18 // Load the inner URL instead. | 18 // Load the inner URL instead. |
| 19 *url = GURL(url->path()); | 19 *url = GURL(url->path()); |
| 20 return true; | 20 return true; |
| 21 } | 21 } |
| 22 return false; | 22 return false; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // Handles URLs for DOM UI. These URLs need no rewriting. | 25 // Handles rewriting DOM UI URLs. |
| 26 static bool HandleDOMUI(GURL* url, Profile* profile) { | 26 static bool HandleDOMUI(GURL* url, Profile* profile) { |
| 27 if (!DOMUIFactory::UseDOMUIForURL(*url)) | 27 if (!DOMUIFactory::UseDOMUIForURL(*url)) |
| 28 return false; | 28 return false; |
| 29 |
| 30 // Special case the new tab page. In older versions of Chrome, the new tab |
| 31 // page was hosted at chrome-internal:<blah>. This might be in people's saved |
| 32 // sessions or bookmarks, so we say any URL with that scheme triggers the new |
| 33 // tab page. |
| 34 if (url->SchemeIs(chrome::kChromeInternalScheme)) { |
| 35 // Rewrite it with the proper new tab URL. |
| 36 *url = GURL(chrome::kChromeUINewTabURL); |
| 37 } |
| 38 |
| 29 return true; | 39 return true; |
| 30 } | 40 } |
| 31 | 41 |
| 32 std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_; | 42 std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_; |
| 33 | 43 |
| 34 // static | 44 // static |
| 35 void BrowserURLHandler::InitURLHandlers() { | 45 void BrowserURLHandler::InitURLHandlers() { |
| 36 if (!url_handlers_.empty()) | 46 if (!url_handlers_.empty()) |
| 37 return; | 47 return; |
| 38 | 48 |
| 39 // Add the default URL handlers. | 49 // Add the default URL handlers. |
| 40 url_handlers_.push_back(&ExtensionDOMUI::HandleChromeURLOverride); | 50 url_handlers_.push_back(&ExtensionDOMUI::HandleChromeURLOverride); |
| 41 url_handlers_.push_back(&WillHandleBrowserAboutURL); // about: | 51 url_handlers_.push_back(&WillHandleBrowserAboutURL); // about: |
| 42 url_handlers_.push_back(&HandleDOMUI); // chrome: & friends. | 52 url_handlers_.push_back(&HandleDOMUI); // chrome: & friends. |
| 43 url_handlers_.push_back(&HandleViewSource); // view-source: | 53 url_handlers_.push_back(&HandleViewSource); // view-source: |
| 44 } | 54 } |
| 45 | 55 |
| 46 // static | 56 // static |
| 47 void BrowserURLHandler::RewriteURLIfNecessary(GURL* url, Profile* profile) { | 57 void BrowserURLHandler::RewriteURLIfNecessary(GURL* url, Profile* profile) { |
| 48 if (url_handlers_.empty()) | 58 if (url_handlers_.empty()) |
| 49 InitURLHandlers(); | 59 InitURLHandlers(); |
| 50 for (size_t i = 0; i < url_handlers_.size(); ++i) { | 60 for (size_t i = 0; i < url_handlers_.size(); ++i) { |
| 51 if ((*url_handlers_[i])(url, profile)) | 61 if ((*url_handlers_[i])(url, profile)) |
| 52 return; | 62 return; |
| 53 } | 63 } |
| 54 } | 64 } |
| OLD | NEW |