Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
|
nasko
2017/01/23 22:32:38
nit: no "(c)".
carlosk
2017/02/08 02:59:02
Done.
| |
| 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_tab_helper.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(MixedContentSettingsTabHelper); | |
| 16 | |
| 17 MixedContentSettingsTabHelper::MixedContentSettingsTabHelper(WebContents* tab) | |
| 18 : content::WebContentsObserver(tab) { | |
| 19 if (tab->HasOpener()) { | |
|
nasko
2017/01/23 22:32:37
nit: if (!tab->HasOpener()) return; will yield a b
carlosk
2017/02/08 02:59:02
Done.
| |
| 20 // Note: using the opener WebContents to override these values only works | |
| 21 // because in Chrome these settings are maintained at the tab level instead | |
| 22 // of at the frame level as Blink does. | |
| 23 MixedContentSettingsTabHelper* opener_settings = | |
| 24 MixedContentSettingsTabHelper::FromWebContents(tab->GetOpener()); | |
| 25 if (opener_settings) { | |
| 26 insecure_content_site_instance_ = | |
| 27 opener_settings->insecure_content_site_instance_; | |
| 28 is_running_insecure_content_allowed_ = | |
| 29 opener_settings->is_running_insecure_content_allowed_; | |
| 30 } | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 MixedContentSettingsTabHelper::~MixedContentSettingsTabHelper() {} | |
| 35 | |
| 36 void MixedContentSettingsTabHelper::AllowRunningOfInsecureContent() { | |
| 37 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 38 DCHECK(!insecure_content_site_instance_ || | |
| 39 insecure_content_site_instance_ == web_contents()->GetSiteInstance()); | |
| 40 insecure_content_site_instance_ = web_contents()->GetSiteInstance(); | |
| 41 is_running_insecure_content_allowed_ = true; | |
| 42 } | |
| 43 | |
| 44 void MixedContentSettingsTabHelper::DidFinishNavigation( | |
| 45 content::NavigationHandle* navigation_handle) { | |
| 46 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) | |
| 47 return; | |
| 48 | |
| 49 // Resets mixed content settings on a successful navigation of the main frame | |
| 50 // to a different SiteInstance. This follows the renderer side behavior which | |
| 51 // is reset whenever a cross-site navigation takes place: a new main | |
| 52 // RenderFrame is created along with a new ContentSettingsObserver, causing | |
| 53 // the effective reset of the mixed content running permission. | |
| 54 // Note: even though on the renderer this setting exists on a per frame basis, | |
| 55 // it has always been controlled at the WebContents level. Its value is always | |
| 56 // inherited from the parent frame and when changed the whole tree is updated. | |
| 57 content::SiteInstance* new_site = | |
| 58 navigation_handle->GetRenderFrameHost()->GetSiteInstance(); | |
| 59 if (new_site != insecure_content_site_instance_) { | |
| 60 insecure_content_site_instance_ = nullptr; | |
| 61 is_running_insecure_content_allowed_ = false; | |
| 62 } | |
| 63 } | |
| OLD | NEW |