OLD | NEW |
(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 if (tab->HasOpener()) { |
| 22 // Note: using the opener WebContents to override these settings only works |
| 23 // because Chrome controls them at the tab level instead of at the frame |
| 24 // level as Blink does. |
| 25 MixedContentSettings* opener_settings = |
| 26 MixedContentSettings::FromWebContents(tab->GetOpener()); |
| 27 if (opener_settings) { |
| 28 insecure_content_site_instance_ = |
| 29 opener_settings->insecure_content_site_instance_; |
| 30 insecure_content_allowed_running_ = |
| 31 opener_settings->insecure_content_allowed_running_; |
| 32 } |
| 33 } |
| 34 } |
| 35 |
| 36 MixedContentSettings::~MixedContentSettings() {} |
| 37 |
| 38 void MixedContentSettings::AllowRunningOfInsecureContent() { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 40 DCHECK(!insecure_content_site_instance_ || |
| 41 insecure_content_site_instance_ == web_contents()->GetSiteInstance()); |
| 42 insecure_content_site_instance_ = web_contents()->GetSiteInstance(); |
| 43 insecure_content_allowed_running_ = true; |
| 44 } |
| 45 |
| 46 void MixedContentSettings::DidFinishNavigation( |
| 47 content::NavigationHandle* navigation_handle) { |
| 48 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) |
| 49 return; |
| 50 |
| 51 // Resets mixed-content settings on a successful navigation of the main frame |
| 52 // to a new site instance. |
| 53 content::SiteInstance* new_site = |
| 54 navigation_handle->GetRenderFrameHost()->GetSiteInstance(); |
| 55 if (new_site != insecure_content_site_instance_) { |
| 56 insecure_content_site_instance_ = nullptr; |
| 57 insecure_content_allowed_running_ = false; |
| 58 } |
| 59 } |
OLD | NEW |