blob: b7b71c54bcf839ff5f81d10389f63840aa3b5d88 [file] [log] [blame]
// Copyright 2017 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 "base/macros.h"
#include "components/signin/core/browser/signin_metrics.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
class NavigationHandle;
// Tab helper used for DICE to mark that sync should start after a web sign-in
// with a Google account.
class DiceTabHelper : public content::WebContentsUserData<DiceTabHelper>,
public content::WebContentsObserver {
~DiceTabHelper() override;
signin_metrics::AccessPoint signin_access_point() {
return signin_access_point_;
signin_metrics::PromoAction signin_promo_action() {
return signin_promo_action_;
signin_metrics::Reason signin_reason() { return signin_reason_; }
GURL redirect_url() { return redirect_url_; }
// Initializes the DiceTabHelper for a new signin flow. Must be called once
// per signin flow happening in the tab, when the signin URL is being loaded.
void InitializeSigninFlow(const GURL& signin_url,
signin_metrics::AccessPoint access_point,
signin_metrics::Reason reason,
signin_metrics::PromoAction promo_action,
const GURL& redirect_url);
// Returns true if this the tab is a re-usable chrome sign-in page (the signin
// page is loading or loaded in the tab).
// Returns false if the user or the page has navigated away from |signin_url|.
bool IsChromeSigninPage() const;
friend class content::WebContentsUserData<DiceTabHelper>;
explicit DiceTabHelper(content::WebContents* web_contents);
// content::WebContentsObserver:
void DidStartNavigation(
content::NavigationHandle* navigation_handle) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
// Returns true if this is a navigation to the signin URL.
bool IsSigninPageNavigation(
content::NavigationHandle* navigation_handle) const;
GURL redirect_url_;
GURL signin_url_;
signin_metrics::AccessPoint signin_access_point_ =
signin_metrics::PromoAction signin_promo_action_ =
signin_metrics::Reason signin_reason_ =
bool is_chrome_signin_page_ = false;
bool signin_page_load_recorded_ = false;