Commit 092d3be7 authored by jam's avatar jam Committed by Commit bot

Fix content settings's cookie code to work with PlzNavigate.

There are two main fixes:
-use GetWebContentsGetter instead of the RPH/RFH IDs since the latter don't exist for browser side navigation
-switching TabSpecificContentSettings to use the new navigation callbacks. This is needed because with PlzNavigate, the old didstartprovisionalload callback (from the new renderer) would run after the cookie request (from the browser), and so we would wipe out the settings map. Using the new callbacks preserves the order of these callbacks with PlzNavigate.

This fixes the following browser tests with PlzNavigate:
ContentSettingsTest.RedirectCrossOrigin
ContentSettingsTest.RedirectLoopCookies

BUG=504347

Review-Url: https://codereview.chromium.org/2374443003
Cr-Commit-Position: refs/heads/master@{#421224}
parent 5b1519e7
...@@ -778,6 +778,12 @@ class ClearSiteDataObserver : public BrowsingDataRemover::Observer { ...@@ -778,6 +778,12 @@ class ClearSiteDataObserver : public BrowsingDataRemover::Observer {
int count_; int count_;
}; };
WebContents* GetWebContents(int render_process_id, int render_frame_id) {
RenderFrameHost* rfh =
RenderFrameHost::FromID(render_process_id, render_frame_id);
return WebContents::FromRenderFrameHost(rfh);
}
} // namespace } // namespace
ChromeContentBrowserClient::ChromeContentBrowserClient() ChromeContentBrowserClient::ChromeContentBrowserClient()
...@@ -1811,10 +1817,12 @@ bool ChromeContentBrowserClient::AllowGetCookie( ...@@ -1811,10 +1817,12 @@ bool ChromeContentBrowserClient::AllowGetCookie(
bool allow = io_data->GetCookieSettings()-> bool allow = io_data->GetCookieSettings()->
IsReadingCookieAllowed(url, first_party); IsReadingCookieAllowed(url, first_party);
base::Callback<content::WebContents*(void)> wc_getter =
base::Bind(&GetWebContents, render_process_id, render_frame_id);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, base::Bind(&TabSpecificContentSettings::CookiesRead, wc_getter, url,
render_frame_id, url, first_party, cookie_list, !allow)); first_party, cookie_list, !allow));
return allow; return allow;
} }
...@@ -1832,11 +1840,12 @@ bool ChromeContentBrowserClient::AllowSetCookie( ...@@ -1832,11 +1840,12 @@ bool ChromeContentBrowserClient::AllowSetCookie(
io_data->GetCookieSettings(); io_data->GetCookieSettings();
bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
base::Callback<content::WebContents*(void)> wc_getter =
base::Bind(&GetWebContents, render_process_id, render_frame_id);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, base::Bind(&TabSpecificContentSettings::CookieChanged, wc_getter, url,
render_frame_id, url, first_party, cookie_line, options, first_party, cookie_line, options, !allow));
!allow));
return allow; return allow;
} }
......
...@@ -21,7 +21,6 @@ namespace { ...@@ -21,7 +21,6 @@ namespace {
ContentSettingsUsagesState::CommittedDetails CreateDetailsWithURL( ContentSettingsUsagesState::CommittedDetails CreateDetailsWithURL(
const GURL& url) { const GURL& url) {
ContentSettingsUsagesState::CommittedDetails details; ContentSettingsUsagesState::CommittedDetails details;
details.current_url_valid = true;
details.current_url = url; details.current_url = url;
return details; return details;
} }
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
...@@ -53,22 +54,21 @@ using content::NavigationController; ...@@ -53,22 +54,21 @@ using content::NavigationController;
using content::NavigationEntry; using content::NavigationEntry;
using content::WebContents; using content::WebContents;
DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings);
namespace { namespace {
ContentSettingsUsagesState::CommittedDetails GetCommittedDetails( static TabSpecificContentSettings* GetForWCGetter(
const content::LoadCommittedDetails& details) { const base::Callback<content::WebContents*(void)>& wc_getter) {
ContentSettingsUsagesState::CommittedDetails committed_details; WebContents* web_contents = wc_getter.Run();
committed_details.current_url_valid = !!details.entry; if (!web_contents)
if (details.entry) return nullptr;
committed_details.current_url = details.entry->GetURL();
committed_details.previous_url = details.previous_url; return TabSpecificContentSettings::FromWebContents(web_contents);
return committed_details;
} }
} // namespace } // namespace
DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings);
TabSpecificContentSettings::SiteDataObserver::SiteDataObserver( TabSpecificContentSettings::SiteDataObserver::SiteDataObserver(
TabSpecificContentSettings* tab_specific_content_settings) TabSpecificContentSettings* tab_specific_content_settings)
: tab_specific_content_settings_(tab_specific_content_settings) { : tab_specific_content_settings_(tab_specific_content_settings) {
...@@ -133,15 +133,14 @@ TabSpecificContentSettings* TabSpecificContentSettings::GetForFrame( ...@@ -133,15 +133,14 @@ TabSpecificContentSettings* TabSpecificContentSettings::GetForFrame(
} }
// static // static
void TabSpecificContentSettings::CookiesRead(int render_process_id, void TabSpecificContentSettings::CookiesRead(
int render_frame_id, const base::Callback<content::WebContents*(void)>& wc_getter,
const GURL& url, const GURL& url,
const GURL& frame_url, const GURL& frame_url,
const net::CookieList& cookie_list, const net::CookieList& cookie_list,
bool blocked_by_policy) { bool blocked_by_policy) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
TabSpecificContentSettings* settings = TabSpecificContentSettings* settings = GetForWCGetter(wc_getter);
GetForFrame(render_process_id, render_frame_id);
if (settings) { if (settings) {
settings->OnCookiesRead(url, frame_url, cookie_list, settings->OnCookiesRead(url, frame_url, cookie_list,
blocked_by_policy); blocked_by_policy);
...@@ -150,16 +149,14 @@ void TabSpecificContentSettings::CookiesRead(int render_process_id, ...@@ -150,16 +149,14 @@ void TabSpecificContentSettings::CookiesRead(int render_process_id,
// static // static
void TabSpecificContentSettings::CookieChanged( void TabSpecificContentSettings::CookieChanged(
int render_process_id, const base::Callback<WebContents*(void)>& wc_getter,
int render_frame_id,
const GURL& url, const GURL& url,
const GURL& frame_url, const GURL& frame_url,
const std::string& cookie_line, const std::string& cookie_line,
const net::CookieOptions& options, const net::CookieOptions& options,
bool blocked_by_policy) { bool blocked_by_policy) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
TabSpecificContentSettings* settings = TabSpecificContentSettings* settings = GetForWCGetter(wc_getter);
GetForFrame(render_process_id, render_frame_id);
if (settings) if (settings)
settings->OnCookieChanged(url, frame_url, cookie_line, options, settings->OnCookieChanged(url, frame_url, cookie_line, options,
blocked_by_policy); blocked_by_policy);
...@@ -778,41 +775,48 @@ bool TabSpecificContentSettings::OnMessageReceived( ...@@ -778,41 +775,48 @@ bool TabSpecificContentSettings::OnMessageReceived(
return handled; return handled;
} }
void TabSpecificContentSettings::DidNavigateMainFrame( void TabSpecificContentSettings::DidStartNavigation(
const content::LoadCommittedDetails& details, content::NavigationHandle* navigation_handle) {
const content::FrameNavigateParams& params) { if (!navigation_handle->IsInMainFrame())
if (!details.is_in_page) {
// Clear "blocked" flags.
ClearBlockedContentSettingsExceptForCookies();
blocked_plugin_names_.clear();
GeolocationDidNavigate(details);
MidiDidNavigate(details);
if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) {
content_settings::RecordPluginsAction(
content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS);
}
}
}
void TabSpecificContentSettings::DidStartProvisionalLoadForFrame(
content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
bool is_error_page,
bool is_iframe_srcdoc) {
if (render_frame_host->GetParent())
return; return;
const content::NavigationController& controller =
web_contents()->GetController();
content::NavigationEntry* last_committed_entry =
controller.GetLastCommittedEntry();
if (last_committed_entry)
previous_url_ = last_committed_entry->GetURL();
// If we're displaying a network error page do not reset the content // If we're displaying a network error page do not reset the content
// settings delegate's cookies so the user has a chance to modify cookie // settings delegate's cookies so the user has a chance to modify cookie
// settings. // settings.
if (!is_error_page) if (!navigation_handle->IsErrorPage())
ClearCookieSpecificContentSettings(); ClearCookieSpecificContentSettings();
ClearGeolocationContentSettings(); ClearGeolocationContentSettings();
ClearMidiContentSettings(); ClearMidiContentSettings();
ClearPendingProtocolHandler(); ClearPendingProtocolHandler();
} }
void TabSpecificContentSettings::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
if (!navigation_handle->IsInMainFrame() ||
!navigation_handle->HasCommitted() ||
navigation_handle->IsSamePage()) {
return;
}
// Clear "blocked" flags.
ClearBlockedContentSettingsExceptForCookies();
blocked_plugin_names_.clear();
GeolocationDidNavigate(navigation_handle);
MidiDidNavigate(navigation_handle);
if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) {
content_settings::RecordPluginsAction(
content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS);
}
}
void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url, void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url,
bool blocked_by_policy) { bool blocked_by_policy) {
if (blocked_by_policy) { if (blocked_by_policy) {
...@@ -847,13 +851,20 @@ void TabSpecificContentSettings::ClearMidiContentSettings() { ...@@ -847,13 +851,20 @@ void TabSpecificContentSettings::ClearMidiContentSettings() {
} }
void TabSpecificContentSettings::GeolocationDidNavigate( void TabSpecificContentSettings::GeolocationDidNavigate(
const content::LoadCommittedDetails& details) { content::NavigationHandle* navigation_handle) {
geolocation_usages_state_.DidNavigate(GetCommittedDetails(details)); ContentSettingsUsagesState::CommittedDetails committed_details;
committed_details.current_url = navigation_handle->GetURL();
committed_details.previous_url = previous_url_;
geolocation_usages_state_.DidNavigate(committed_details);
} }
void TabSpecificContentSettings::MidiDidNavigate( void TabSpecificContentSettings::MidiDidNavigate(
const content::LoadCommittedDetails& details) { content::NavigationHandle* navigation_handle) {
midi_usages_state_.DidNavigate(GetCommittedDetails(details)); ContentSettingsUsagesState::CommittedDetails committed_details;
committed_details.current_url = navigation_handle->GetURL();
committed_details.previous_url = previous_url_;
midi_usages_state_.DidNavigate(committed_details);
} }
void TabSpecificContentSettings::BlockAllContentForTesting() { void TabSpecificContentSettings::BlockAllContentForTesting() {
......
...@@ -102,24 +102,24 @@ class TabSpecificContentSettings ...@@ -102,24 +102,24 @@ class TabSpecificContentSettings
// current page or while loading it. |blocked_by_policy| should be true, if // current page or while loading it. |blocked_by_policy| should be true, if
// reading cookies was blocked due to the user's content settings. In that // reading cookies was blocked due to the user's content settings. In that
// case, this function should invoke OnContentBlocked. // case, this function should invoke OnContentBlocked.
static void CookiesRead(int render_process_id, static void CookiesRead(
int render_frame_id, const base::Callback<content::WebContents*(void)>& wc_getter,
const GURL& url, const GURL& url,
const GURL& first_party_url, const GURL& first_party_url,
const net::CookieList& cookie_list, const net::CookieList& cookie_list,
bool blocked_by_policy); bool blocked_by_policy);
// Called when a specific cookie in the current page was changed. // Called when a specific cookie in the current page was changed.
// |blocked_by_policy| should be true, if the cookie was blocked due to the // |blocked_by_policy| should be true, if the cookie was blocked due to the
// user's content settings. In that case, this function should invoke // user's content settings. In that case, this function should invoke
// OnContentBlocked. // OnContentBlocked.
static void CookieChanged(int render_process_id, static void CookieChanged(
int render_frame_id, const base::Callback<content::WebContents*(void)>& wc_getter,
const GURL& url, const GURL& url,
const GURL& first_party_url, const GURL& first_party_url,
const std::string& cookie_line, const std::string& cookie_line,
const net::CookieOptions& options, const net::CookieOptions& options,
bool blocked_by_policy); bool blocked_by_policy);
// Called when a specific Web database in the current page was accessed. If // Called when a specific Web database in the current page was accessed. If
// access was blocked due to the user's content settings, // access was blocked due to the user's content settings,
...@@ -398,14 +398,10 @@ class TabSpecificContentSettings ...@@ -398,14 +398,10 @@ class TabSpecificContentSettings
content::RenderFrameHost* render_frame_host) override; content::RenderFrameHost* render_frame_host) override;
bool OnMessageReceived(const IPC::Message& message, bool OnMessageReceived(const IPC::Message& message,
content::RenderFrameHost* render_frame_host) override; content::RenderFrameHost* render_frame_host) override;
void DidNavigateMainFrame( void DidStartNavigation(
const content::LoadCommittedDetails& details, content::NavigationHandle* navigation_handle) override;
const content::FrameNavigateParams& params) override; void DidFinishNavigation(
void DidStartProvisionalLoadForFrame( content::NavigationHandle* navigation_handle) override;
content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
bool is_error_page,
bool is_iframe_srcdoc) override;
void AppCacheAccessed(const GURL& manifest_url, void AppCacheAccessed(const GURL& manifest_url,
bool blocked_by_policy) override; bool blocked_by_policy) override;
...@@ -425,11 +421,10 @@ class TabSpecificContentSettings ...@@ -425,11 +421,10 @@ class TabSpecificContentSettings
void ClearMidiContentSettings(); void ClearMidiContentSettings();
// Updates Geolocation settings on navigation. // Updates Geolocation settings on navigation.
void GeolocationDidNavigate( void GeolocationDidNavigate(content::NavigationHandle* navigation_handle);
const content::LoadCommittedDetails& details);
// Updates MIDI settings on navigation. // Updates MIDI settings on navigation.
void MidiDidNavigate(const content::LoadCommittedDetails& details); void MidiDidNavigate(content::NavigationHandle* navigation_handle);
// All currently registered |SiteDataObserver|s. // All currently registered |SiteDataObserver|s.
base::ObserverList<SiteDataObserver> observer_list_; base::ObserverList<SiteDataObserver> observer_list_;
...@@ -493,6 +488,9 @@ class TabSpecificContentSettings ...@@ -493,6 +488,9 @@ class TabSpecificContentSettings
bool subresource_filter_enabled_; bool subresource_filter_enabled_;
bool subresource_filter_blockage_indicated_; bool subresource_filter_blockage_indicated_;
// Holds the previous committed url during a navigation.
GURL previous_url_;
// Observer to watch for content settings changed. // Observer to watch for content settings changed.
ScopedObserver<HostContentSettingsMap, content_settings::Observer> observer_; ScopedObserver<HostContentSettingsMap, content_settings::Observer> observer_;
......
...@@ -427,14 +427,12 @@ bool ChromeNetworkDelegate::OnCanGetCookies( ...@@ -427,14 +427,12 @@ bool ChromeNetworkDelegate::OnCanGetCookies(
bool allow = cookie_settings_->IsReadingCookieAllowed( bool allow = cookie_settings_->IsReadingCookieAllowed(
request.url(), request.first_party_for_cookies()); request.url(), request.first_party_for_cookies());
int render_process_id = -1; const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
int render_frame_id = -1; if (info) {
if (content::ResourceRequestInfo::GetRenderFrameForRequest(
&request, &render_process_id, &render_frame_id)) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&TabSpecificContentSettings::CookiesRead, base::Bind(&TabSpecificContentSettings::CookiesRead,
render_process_id, render_frame_id, info->GetWebContentsGetterForRequest(),
request.url(), request.first_party_for_cookies(), request.url(), request.first_party_for_cookies(),
cookie_list, !allow)); cookie_list, !allow));
} }
...@@ -452,14 +450,12 @@ bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, ...@@ -452,14 +450,12 @@ bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
bool allow = cookie_settings_->IsSettingCookieAllowed( bool allow = cookie_settings_->IsSettingCookieAllowed(
request.url(), request.first_party_for_cookies()); request.url(), request.first_party_for_cookies());
int render_process_id = -1; const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
int render_frame_id = -1; if (info) {
if (content::ResourceRequestInfo::GetRenderFrameForRequest(
&request, &render_process_id, &render_frame_id)) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&TabSpecificContentSettings::CookieChanged, base::Bind(&TabSpecificContentSettings::CookieChanged,
render_process_id, render_frame_id, info->GetWebContentsGetterForRequest(),
request.url(), request.first_party_for_cookies(), request.url(), request.first_party_for_cookies(),
cookie_line, *options, !allow)); cookie_line, *options, !allow));
} }
......
...@@ -10,12 +10,6 @@ ...@@ -10,12 +10,6 @@
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/url_formatter/url_formatter.h" #include "components/url_formatter/url_formatter.h"
ContentSettingsUsagesState::CommittedDetails::CommittedDetails()
: current_url_valid(false) {
}
ContentSettingsUsagesState::CommittedDetails::~CommittedDetails() {}
ContentSettingsUsagesState::ContentSettingsUsagesState( ContentSettingsUsagesState::ContentSettingsUsagesState(
HostContentSettingsMap* host_content_settings_map, HostContentSettingsMap* host_content_settings_map,
ContentSettingsType type) ContentSettingsType type)
...@@ -33,12 +27,10 @@ void ContentSettingsUsagesState::OnPermissionSet( ...@@ -33,12 +27,10 @@ void ContentSettingsUsagesState::OnPermissionSet(
} }
void ContentSettingsUsagesState::DidNavigate(const CommittedDetails& details) { void ContentSettingsUsagesState::DidNavigate(const CommittedDetails& details) {
if (details.current_url_valid) embedder_url_ = details.current_url;
embedder_url_ = details.current_url;
if (state_map_.empty()) if (state_map_.empty())
return; return;
if (!details.current_url_valid || if (details.previous_url.GetOrigin() != details.current_url.GetOrigin()) {
details.previous_url.GetOrigin() != details.current_url.GetOrigin()) {
state_map_.clear(); state_map_.clear();
return; return;
} }
......
...@@ -22,10 +22,6 @@ class ContentSettingsUsagesState { ...@@ -22,10 +22,6 @@ class ContentSettingsUsagesState {
public: public:
// Information about navigation. // Information about navigation.
struct CommittedDetails { struct CommittedDetails {
CommittedDetails();
~CommittedDetails();
bool current_url_valid;
GURL current_url; GURL current_url;
GURL previous_url; GURL previous_url;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment