| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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_frame/navigation_constraints.h" | 5 #include "chrome_frame/navigation_constraints.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "chrome_frame/utils.h" | 10 #include "chrome_frame/utils.h" |
| 11 | 11 |
| 12 NavigationConstraintsImpl::NavigationConstraintsImpl() : is_privileged_(false) { |
| 13 } |
| 14 |
| 12 // NavigationConstraintsImpl method definitions. | 15 // NavigationConstraintsImpl method definitions. |
| 13 bool NavigationConstraintsImpl::AllowUnsafeUrls() { | 16 bool NavigationConstraintsImpl::AllowUnsafeUrls() { |
| 14 // No sanity checks if unsafe URLs are allowed | 17 // No sanity checks if unsafe URLs are allowed |
| 15 return GetConfigBool(false, kAllowUnsafeURLs); | 18 return GetConfigBool(false, kAllowUnsafeURLs); |
| 16 } | 19 } |
| 17 | 20 |
| 18 bool NavigationConstraintsImpl::IsSchemeAllowed(const GURL& url) { | 21 bool NavigationConstraintsImpl::IsSchemeAllowed(const GURL& url) { |
| 19 if (url.is_empty()) | 22 if (url.is_empty()) |
| 20 return false; | 23 return false; |
| 21 | 24 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 return true; | 38 return true; |
| 36 } | 39 } |
| 37 | 40 |
| 38 // Allow only about:blank or about:version | 41 // Allow only about:blank or about:version |
| 39 if (url.SchemeIs(chrome::kAboutScheme)) { | 42 if (url.SchemeIs(chrome::kAboutScheme)) { |
| 40 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutBlankURL) || | 43 if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutBlankURL) || |
| 41 LowerCaseEqualsASCII(url.spec(), chrome::kAboutVersionURL)) { | 44 LowerCaseEqualsASCII(url.spec(), chrome::kAboutVersionURL)) { |
| 42 return true; | 45 return true; |
| 43 } | 46 } |
| 44 } | 47 } |
| 48 |
| 49 if (is_privileged_ && |
| 50 (url.SchemeIs(chrome::kDataScheme) || |
| 51 url.SchemeIs(chrome::kExtensionScheme))) { |
| 52 return true; |
| 53 } |
| 54 |
| 45 return false; | 55 return false; |
| 46 } | 56 } |
| 47 | 57 |
| 48 bool NavigationConstraintsImpl::IsZoneAllowed(const GURL& url) { | 58 bool NavigationConstraintsImpl::IsZoneAllowed(const GURL& url) { |
| 49 if (!security_manager_) { | 59 if (!security_manager_) { |
| 50 HRESULT hr = security_manager_.CreateInstance( | 60 HRESULT hr = security_manager_.CreateInstance( |
| 51 CLSID_InternetSecurityManager); | 61 CLSID_InternetSecurityManager); |
| 52 if (FAILED(hr)) { | 62 if (FAILED(hr)) { |
| 53 NOTREACHED() << __FUNCTION__ | 63 NOTREACHED() << __FUNCTION__ |
| 54 << " Failed to create SecurityManager. Error: 0x%x" | 64 << " Failed to create SecurityManager. Error: 0x%x" |
| 55 << hr; | 65 << hr; |
| 56 return true; | 66 return true; |
| 57 } | 67 } |
| 58 DWORD zone = URLZONE_INVALID; | 68 DWORD zone = URLZONE_INVALID; |
| 59 std::wstring unicode_url = UTF8ToWide(url.spec()); | 69 std::wstring unicode_url = UTF8ToWide(url.spec()); |
| 60 security_manager_->MapUrlToZone(unicode_url.c_str(), &zone, 0); | 70 security_manager_->MapUrlToZone(unicode_url.c_str(), &zone, 0); |
| 61 if (zone == URLZONE_UNTRUSTED) { | 71 if (zone == URLZONE_UNTRUSTED) { |
| 62 DLOG(WARNING) << __FUNCTION__ | 72 DLOG(WARNING) << __FUNCTION__ |
| 63 << " Disallowing navigation to restricted url: " << url; | 73 << " Disallowing navigation to restricted url: " << url; |
| 64 return false; | 74 return false; |
| 65 } | 75 } |
| 66 } | 76 } |
| 67 return true; | 77 return true; |
| 68 } | 78 } |
| 69 | 79 |
| 80 bool NavigationConstraintsImpl::is_privileged() const { |
| 81 return is_privileged_; |
| 82 } |
| 83 |
| 84 void NavigationConstraintsImpl::set_is_privileged(bool is_privileged) { |
| 85 is_privileged_ = is_privileged; |
| 86 } |
| OLD | NEW |