Chromium Code Reviews| 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..7676828c80c06c3f4f47ae1e9c88006957479291 |
| --- /dev/null |
| +++ b/chrome/browser/content_settings/mixed_content_settings.cc |
| @@ -0,0 +1,73 @@ |
| +// 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), |
| + insecure_content_allowed_running_(false), |
| + insecure_content_allowed_displaying_(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. |
| + 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_; |
| + insecure_content_allowed_displaying_ = |
| + opener_settings->insecure_content_allowed_displaying_; |
| + } |
| + } |
| +} |
| + |
| +MixedContentSettings::~MixedContentSettings() {} |
| + |
| +void MixedContentSettings::AllowDisplayingOfInsecureContent() { |
| + 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_displaying_ = true; |
| +} |
| + |
| +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(); |
| + // Note: whenever running is allowed, so is displaying. |
| + insecure_content_allowed_running_ = true; |
| + insecure_content_allowed_displaying_ = true; |
| +} |
| + |
| +void MixedContentSettings::DidFinishNavigation( |
| + content::NavigationHandle* navigation_handle) { |
|
carlosk
2016/07/18 14:37:13
I'm not sure of when is the correct moment to rese
|
| + if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) |
| + return; |
| + |
| + // Resets mixed-content settings on a successful navigation of the main frame |
| + // to a new site instance. |
| + 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; |
| + insecure_content_allowed_displaying_ = false; |
| + } |
| +} |