OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 #include "chrome_frame/navigation_constraints.h" |
| 6 |
| 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/common/url_constants.h" |
| 10 #include "chrome_frame/utils.h" |
| 11 |
| 12 // NavigationConstraintsImpl method definitions. |
| 13 bool NavigationConstraintsImpl::AllowUnsafeUrls() { |
| 14 // No sanity checks if unsafe URLs are allowed |
| 15 return GetConfigBool(false, kAllowUnsafeURLs); |
| 16 } |
| 17 |
| 18 bool NavigationConstraintsImpl::IsSchemeAllowed(const GURL& url) { |
| 19 if (url.is_empty()) |
| 20 return false; |
| 21 |
| 22 if (!url.is_valid()) |
| 23 return false; |
| 24 |
| 25 if (url.SchemeIs(chrome::kHttpScheme) || |
| 26 url.SchemeIs(chrome::kHttpsScheme)) |
| 27 return true; |
| 28 |
| 29 // Additional checking for view-source. Allow only http and https |
| 30 // URLs in view source. |
| 31 if (url.SchemeIs(chrome::kViewSourceScheme)) { |
| 32 GURL sub_url(url.path()); |
| 33 if (sub_url.SchemeIs(chrome::kHttpScheme) || |
| 34 sub_url.SchemeIs(chrome::kHttpsScheme)) |
| 35 return true; |
| 36 } |
| 37 |
| 38 // Allow only about:blank or about:version |
| 39 if (url.SchemeIs(chrome::kAboutScheme)) { |
| 40 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutBlankURL) || |
| 41 LowerCaseEqualsASCII(url.spec(), chrome::kAboutVersionURL)) { |
| 42 return true; |
| 43 } |
| 44 } |
| 45 return false; |
| 46 } |
| 47 |
| 48 bool NavigationConstraintsImpl::IsZoneAllowed(const GURL& url) { |
| 49 if (!security_manager_) { |
| 50 HRESULT hr = security_manager_.CreateInstance( |
| 51 CLSID_InternetSecurityManager); |
| 52 if (FAILED(hr)) { |
| 53 NOTREACHED() << __FUNCTION__ |
| 54 << " Failed to create SecurityManager. Error: 0x%x" |
| 55 << hr; |
| 56 return true; |
| 57 } |
| 58 DWORD zone = URLZONE_INVALID; |
| 59 std::wstring unicode_url = UTF8ToWide(url.spec()); |
| 60 security_manager_->MapUrlToZone(unicode_url.c_str(), &zone, 0); |
| 61 if (zone == URLZONE_UNTRUSTED) { |
| 62 DLOG(WARNING) << __FUNCTION__ |
| 63 << " Disallowing navigation to restricted url: " << url; |
| 64 return false; |
| 65 } |
| 66 } |
| 67 return true; |
| 68 } |
| 69 |
OLD | NEW |