123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- // Copyright 2020 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.
- #ifndef WEBLAYER_BROWSER_BROWSER_CONTROLS_NAVIGATION_STATE_HANDLER_H_
- #define WEBLAYER_BROWSER_BROWSER_CONTROLS_NAVIGATION_STATE_HANDLER_H_
- #include "base/memory/raw_ptr.h"
- #include "base/timer/timer.h"
- #include "cc/input/browser_controls_state.h"
- #include "content/public/browser/web_contents_observer.h"
- namespace weblayer {
- class BrowserControlsNavigationStateHandlerDelegate;
- // BrowserControlsNavigationStateHandler is responsible for the tracking the
- // value of cc::BrowserControlsState as related to navigation state and
- // notifying the delegate when the state changes.
- //
- // This class is roughly a combination of TopControlsSliderControllerChromeOS
- // and TabStateBrowserControlsVisibilityDelegate.
- class BrowserControlsNavigationStateHandler
- : public content::WebContentsObserver {
- public:
- BrowserControlsNavigationStateHandler(
- content::WebContents* web_contents,
- BrowserControlsNavigationStateHandlerDelegate* delegate);
- BrowserControlsNavigationStateHandler(
- const BrowserControlsNavigationStateHandler&) = delete;
- BrowserControlsNavigationStateHandler& operator=(
- const BrowserControlsNavigationStateHandler&) = delete;
- ~BrowserControlsNavigationStateHandler() override;
- // Returns true if the renderer is responsible for controlling the offsets.
- // This is normally true, but if the renderer is unresponsive (hung and/or
- // crashed), then the renderer won't be able to drive the offsets.
- bool IsRendererControllingOffsets();
- // content::WebContentsObserver:
- void DidStartNavigation(
- content::NavigationHandle* navigation_handle) override;
- void DidFinishNavigation(
- content::NavigationHandle* navigation_handle) override;
- void DidFinishLoad(content::RenderFrameHost* render_frame_host,
- const GURL& validated_url) override;
- void DidFailLoad(content::RenderFrameHost* render_frame_host,
- const GURL& validated_url,
- int error_code) override;
- void DidChangeVisibleSecurityState() override;
- void PrimaryMainFrameRenderProcessGone(
- base::TerminationStatus status) override;
- void OnRendererUnresponsive(
- content::RenderProcessHost* render_process_host) override;
- void OnRendererResponsive(
- content::RenderProcessHost* render_process_host) override;
- private:
- // Sets the value of |force_show_during_load_|. Calls to UpdateState() if
- // the value changed.
- void SetForceShowDuringLoad(bool value);
- // Schedules a timer to set |force_show_during_load_| to false.
- void ScheduleStopDelayedForceShow();
- // Checks the current state, and if it has changed notifies the delegate.
- void UpdateState();
- // Calculates whether the renderer is available to control the browser
- // controls.
- cc::BrowserControlsState CalculateStateForReasonRendererAvailability();
- // Calculates the value of the ControlsVisibilityReason::kOther state.
- cc::BrowserControlsState CalculateStateForReasonOther();
- bool IsRendererHungOrCrashed();
- raw_ptr<BrowserControlsNavigationStateHandlerDelegate> delegate_;
- // The controls are forced visible when a navigation starts, and allowed to
- // hide a short amount of time after done.
- bool force_show_during_load_ = false;
- // Timer used to set |force_show_during_load_| to false.
- base::OneShotTimer forced_show_during_load_timer_;
- // Last values supplied to the delegate.
- cc::BrowserControlsState last_renderer_availability_state_ =
- cc::BrowserControlsState::kBoth;
- cc::BrowserControlsState last_other_state_ = cc::BrowserControlsState::kBoth;
- // This is cached as WebContents::IsCrashed() does not always return the
- // right thing.
- bool is_crashed_ = false;
- };
- } // namespace weblayer
- #endif // WEBLAYER_BROWSER_BROWSER_CONTROLS_NAVIGATION_STATE_HANDLER_H_
|