| 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" |
| 11 #include "chrome/browser/profile.h" |
| 10 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 11 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 12 | 14 |
| 13 // Handles rewriting view-source URLs for what we'll actually load. | 15 // Handles rewriting view-source URLs for what we'll actually load. |
| 14 static bool HandleViewSource(GURL* url) { | 16 static bool HandleViewSource(GURL* url, Profile* profile) { |
| 15 if (url->SchemeIs(chrome::kViewSourceScheme)) { | 17 if (url->SchemeIs(chrome::kViewSourceScheme)) { |
| 16 // Load the inner URL instead. | 18 // Load the inner URL instead. |
| 17 *url = GURL(url->path()); | 19 *url = GURL(url->path()); |
| 18 return true; | 20 return true; |
| 19 } | 21 } |
| 20 return false; | 22 return false; |
| 21 } | 23 } |
| 22 | 24 |
| 23 // Handles URLs for DOM UI. These URLs need no rewriting. | 25 // Handles URLs for DOM UI. These URLs need no rewriting. |
| 24 static bool HandleDOMUI(GURL* url) { | 26 static bool HandleDOMUI(GURL* url, Profile* profile) { |
| 25 if (!DOMUIFactory::UseDOMUIForURL(*url)) | 27 if (!DOMUIFactory::UseDOMUIForURL(*url)) |
| 26 return false; | 28 return false; |
| 27 return true; | 29 return true; |
| 28 } | 30 } |
| 29 | 31 |
| 30 std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_; | 32 std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_; |
| 31 | 33 |
| 32 // static | 34 // static |
| 33 void BrowserURLHandler::InitURLHandlers() { | 35 void BrowserURLHandler::InitURLHandlers() { |
| 34 if (!url_handlers_.empty()) | 36 if (!url_handlers_.empty()) |
| 35 return; | 37 return; |
| 36 | 38 |
| 37 // Add the default URL handlers. | 39 // Add the default URL handlers. |
| 40 url_handlers_.push_back(&ExtensionDOMUI::HandleChromeURLOverride); |
| 38 url_handlers_.push_back(&WillHandleBrowserAboutURL); // about: | 41 url_handlers_.push_back(&WillHandleBrowserAboutURL); // about: |
| 39 url_handlers_.push_back(&HandleDOMUI); // chrome: & friends. | 42 url_handlers_.push_back(&HandleDOMUI); // chrome: & friends. |
| 40 url_handlers_.push_back(&HandleViewSource); // view-source: | 43 url_handlers_.push_back(&HandleViewSource); // view-source: |
| 41 } | 44 } |
| 42 | 45 |
| 43 // static | 46 // static |
| 44 void BrowserURLHandler::RewriteURLIfNecessary(GURL* url) { | 47 void BrowserURLHandler::RewriteURLIfNecessary(GURL* url, Profile* profile) { |
| 45 if (url_handlers_.empty()) | 48 if (url_handlers_.empty()) |
| 46 InitURLHandlers(); | 49 InitURLHandlers(); |
| 47 for (size_t i = 0; i < url_handlers_.size(); ++i) { | 50 for (size_t i = 0; i < url_handlers_.size(); ++i) { |
| 48 if ((*url_handlers_[i])(url)) | 51 if ((*url_handlers_[i])(url, profile)) |
| 49 return; | 52 return; |
| 50 } | 53 } |
| 51 } | 54 } |
| OLD | NEW |