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

Unified Diff: chrome/browser/content_settings/mixed_content_settings.cc

Issue 1905033002: PlzNavigate: Move navigation-level mixed content checks to the browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@console-security-message
Patch Set: Address jam@ comments; many minor code and comment updates. Created 3 years, 11 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/content_settings/mixed_content_settings.cc
diff --git a/chrome/browser/content_settings/mixed_content_settings.cc b/chrome/browser/content_settings/mixed_content_settings.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7d46ac344be9e019e217c3ec30d9aa199391806a
--- /dev/null
+++ b/chrome/browser/content_settings/mixed_content_settings.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2016 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/content_settings/mixed_content_settings.h"
+
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/site_instance.h"
+
+using content::BrowserThread;
+using content::WebContents;
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(MixedContentSettings);
+
+MixedContentSettings::MixedContentSettings(WebContents* tab)
+ : content::WebContentsObserver(tab),
+ insecure_content_site_instance_(nullptr),
nasko 2017/01/12 18:32:37 nit: You could initialize these in the header file
carlosk 2017/01/21 02:54:58 Done.
+ insecure_content_allowed_running_(false) {
+ if (tab->HasOpener()) {
+ // Note: using the opener WebContents to override these settings only works
+ // because Chrome controls them at the tab level instead of at the frame
+ // level as Blink does.
nasko 2017/01/12 18:32:37 Hmm, I think we now track openers at the frame lev
carlosk 2017/01/21 02:54:58 We want to keep frame granularity at tab-level as
nasko 2017/02/10 01:08:20 Acknowledged.
+ MixedContentSettings* opener_settings =
+ MixedContentSettings::FromWebContents(tab->GetOpener());
+ if (opener_settings) {
+ insecure_content_site_instance_ =
+ opener_settings->insecure_content_site_instance_;
+ insecure_content_allowed_running_ =
+ opener_settings->insecure_content_allowed_running_;
+ }
+ }
+}
+
+MixedContentSettings::~MixedContentSettings() {}
+
+void MixedContentSettings::AllowRunningOfInsecureContent() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(!insecure_content_site_instance_ ||
+ insecure_content_site_instance_ == web_contents()->GetSiteInstance());
+ insecure_content_site_instance_ = web_contents()->GetSiteInstance();
+ insecure_content_allowed_running_ = true;
+}
+
+void MixedContentSettings::DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) {
+ if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted())
nasko 2017/01/12 18:32:37 What happens if the commit was for an error page?
carlosk 2017/01/21 02:54:58 In PlzNavigate, the RenderFrame that would render
nasko 2017/01/23 22:32:37 Do we have a test that ensures that is the case an
carlosk 2017/02/08 02:59:02 To clarify: this specific check will control if mi
nasko 2017/02/10 01:08:20 Ok. Where would one find that list?
carlosk 2017/02/11 01:40:22 It's currently in a task in my Asana task tracker.
+ return;
+
+ // Resets mixed-content settings on a successful navigation of the main frame
+ // to a new site instance.
nasko 2017/01/12 18:32:37 nit: s/site instance/SiteInstance/
carlosk 2017/01/21 02:54:58 Done. This comment also grew considerably to expla
nasko 2017/01/23 22:32:37 Thanks! That makes it a lot more clear why.
+ content::SiteInstance* new_site =
+ navigation_handle->GetRenderFrameHost()->GetSiteInstance();
+ if (new_site != insecure_content_site_instance_) {
+ insecure_content_site_instance_ = nullptr;
+ insecure_content_allowed_running_ = false;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698