OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017 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/browser/download/trusted_sources_manager.h" |
| 6 |
| 7 #include <urlmon.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/win/scoped_comptr.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 class TrustedSourcesManagerWin : public TrustedSourcesManager { |
| 18 public: |
| 19 TrustedSourcesManagerWin(); |
| 20 ~TrustedSourcesManagerWin() override; |
| 21 |
| 22 // TrustedSourcesManager methods: |
| 23 bool IsFromTrustedSource(const GURL& url) const override; |
| 24 }; |
| 25 |
| 26 TrustedSourcesManagerWin::TrustedSourcesManagerWin() = default; |
| 27 TrustedSourcesManagerWin::~TrustedSourcesManagerWin() = default; |
| 28 |
| 29 bool TrustedSourcesManagerWin::IsFromTrustedSource(const GURL& url) const { |
| 30 base::win::ScopedComPtr<IInternetSecurityManager> security_manager; |
| 31 HRESULT hr = ::CoInternetCreateSecurityManager( |
| 32 NULL, security_manager.GetAddressOf(), NULL); |
| 33 // URLZONE_LOCAL_MACHINE 0 |
| 34 // URLZONE_INTRANET 1 |
| 35 // URLZONE_TRUSTED 2 |
| 36 // URLZONE_INTERNET 3 |
| 37 // URLZONE_UNTRUSTED 4 |
| 38 DWORD zone = 0; |
| 39 base::string16 url16 = base::ASCIIToUTF16(url.spec()); |
| 40 hr = security_manager->MapUrlToZone(url16.c_str(), &zone, 0); |
| 41 if (FAILED(hr)) { |
| 42 LOG(ERROR) << "security_manager->MapUrlToZone failed with hr: " << std::hex |
| 43 << hr; |
| 44 return false; |
| 45 } |
| 46 return zone <= static_cast<DWORD>(URLZONE_TRUSTED); |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 51 // static |
| 52 TrustedSourcesManager* TrustedSourcesManager::Create() { |
| 53 return new TrustedSourcesManagerWin; |
| 54 } |
OLD | NEW |