Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Unified Diff: chrome/browser/download/trusted_sources_manager_win.cc

Issue 2943763002: Add a new group policy to disable safe browsing for files downloaded from trusted sources. (Closed)
Patch Set: D'Ho! Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/trusted_sources_manager_win.cc
diff --git a/chrome/browser/download/trusted_sources_manager_win.cc b/chrome/browser/download/trusted_sources_manager_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ae150f224a104b9a6e637935afa3317138efe22a
--- /dev/null
+++ b/chrome/browser/download/trusted_sources_manager_win.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/download/trusted_sources_manager.h"
+
+#include <urlmon.h>
+
+#include "base/logging.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/win/scoped_comptr.h"
+#include "url/gurl.h"
+
+class TrustedSourcesManagerWin : public TrustedSourcesManager {
+ public:
+ TrustedSourcesManagerWin();
+ ~TrustedSourcesManagerWin() override;
+
+ // TrustedSourcesManager methods:
+ bool IsFromTrustedSource(const GURL& url) const override;
+};
+
+TrustedSourcesManagerWin::TrustedSourcesManagerWin() {}
+TrustedSourcesManagerWin::~TrustedSourcesManagerWin() {}
+
+bool TrustedSourcesManagerWin::IsFromTrustedSource(const GURL& url) const {
+ if (TrustedSourcesManager::IsFromTrustedSource(url))
+ return true;
+
+ base::win::ScopedComPtr<IInternetSecurityManager> security_manager_;
Roger Tawa OOO till Jul 10th 2017/06/19 18:51:29 No trailing underscore.
MAD 2017/06/19 19:33:48 D'Ho! Of course... Copied this code too quickly...
+ HRESULT hr = ::CoInternetCreateSecurityManager(
+ NULL, security_manager_.GetAddressOf(), NULL);
+ // URLZONE_LOCAL_MACHINE 0
+ // URLZONE_INTRANET 1
+ // URLZONE_TRUSTED 2
+ // URLZONE_INTERNET 3
+ // URLZONE_UNTRUSTED 4
+ DWORD zone = 0;
+ base::string16 url16 = base::ASCIIToUTF16(url.spec());
+ hr = security_manager_->MapUrlToZone(url16.c_str(), &zone, 0);
+ if (FAILED(hr)) {
+ LOG(ERROR) << "security_manager_->MapUrlToZone failed with hr: " << std::hex
+ << hr;
+ return false;
+ }
+ return zone <= static_cast<DWORD>(URLZONE_TRUSTED);
+}
+
+// static
+TrustedSourcesManager* TrustedSourcesManager::Create() {
+ return new TrustedSourcesManagerWin;
+}

Powered by Google App Engine
This is Rietveld 408576698