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

Side by Side 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: Overall code cleanup to request reviewers to PTAL. Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 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/content_settings/mixed_content_settings.h"
6
7 #include "content/public/browser/browser_thread.h"
8 #include "content/public/browser/navigation_handle.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/site_instance.h"
11
12 using content::BrowserThread;
13 using content::WebContents;
14
15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MixedContentSettings);
16
17 MixedContentSettings::MixedContentSettings(WebContents* tab)
18 : content::WebContentsObserver(tab),
19 insecure_content_site_instance_(nullptr),
20 insecure_content_allowed_running_(false),
21 insecure_content_allowed_displaying_(false) {
22 if (tab->HasOpener()) {
23 // Note: using the opener WebContents to override these settings only works
24 // because Chrome controls them at the tab level instead of at the frame
25 // level as Blink does.
26 MixedContentSettings* opener_settings =
27 MixedContentSettings::FromWebContents(tab->GetOpener());
28 if (opener_settings) {
29 insecure_content_site_instance_ =
30 opener_settings->insecure_content_site_instance_;
31 insecure_content_allowed_running_ =
32 opener_settings->insecure_content_allowed_running_;
33 insecure_content_allowed_displaying_ =
34 opener_settings->insecure_content_allowed_displaying_;
35 }
36 }
37 }
38
39 MixedContentSettings::~MixedContentSettings() {}
40
41 void MixedContentSettings::AllowDisplayingOfInsecureContent() {
42 DCHECK_CURRENTLY_ON(BrowserThread::UI);
43 DCHECK(!insecure_content_site_instance_ ||
44 insecure_content_site_instance_ == web_contents()->GetSiteInstance());
45 insecure_content_site_instance_ = web_contents()->GetSiteInstance();
46 insecure_content_allowed_displaying_ = true;
47 }
48
49 void MixedContentSettings::AllowRunningOfInsecureContent() {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
51 DCHECK(!insecure_content_site_instance_ ||
52 insecure_content_site_instance_ == web_contents()->GetSiteInstance());
53 insecure_content_site_instance_ = web_contents()->GetSiteInstance();
54 // Note: whenever running is allowed, so is displaying.
55 insecure_content_allowed_running_ = true;
56 insecure_content_allowed_displaying_ = true;
57 }
58
59 void MixedContentSettings::DidFinishNavigation(
60 content::NavigationHandle* navigation_handle) {
carlosk 2016/07/18 14:37:13 I'm not sure of when is the correct moment to rese
61 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted())
62 return;
63
64 // Resets mixed-content settings on a successful navigation of the main frame
65 // to a new site instance.
66 content::SiteInstance* new_site =
67 navigation_handle->GetRenderFrameHost()->GetSiteInstance();
68 if (new_site != insecure_content_site_instance_) {
69 insecure_content_site_instance_ = nullptr;
70 insecure_content_allowed_running_ = false;
71 insecure_content_allowed_displaying_ = false;
72 }
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698