1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSIONS_TOOLBAR_CONTAINER_VIEW_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSIONS_TOOLBAR_CONTAINER_VIEW_CONTROLLER_H_
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
class ExtensionsToolbarContainer;
class ExtensionsToolbarContainerViewController final
: public TabStripModelObserver,
public ToolbarActionsModel::Observer,
public extensions::PermissionsManager::Observer {
public:
// Flex behavior precedence for the container's views.
static constexpr int kFlexOrderExtensionsButton = 1;
static constexpr int kFlexOrderRequestAccessButton = 2;
static constexpr int kFlexOrderActionView = 3;
// Returns a scope object to block launching the Extensions Zero State
// Promo IPH.
//
// In a live environment, the Extensions Zero State Promo IPH will only open
// after at least 10 minutes into the browsing session.
//
// When running InProcessBrowserTest, the IPH can trigger as soon as the
// browser is constructed. When the IPH is shown, it takes focus away from
// the browser, and causes tests to time out, as
// InProcessBrowserTest::PreRunTestOnMainThread waits for the browser to
// come to focus.
//
// This global variable allows the In Process Browser Tests that trigger
// the IPH to avoid this race condition, by suppressing the IPH until the
// browser initialization and set up steps are done.
//
// TODO(crbug.com/417543907) Move the Zero State Promo IPH trigger to a more
// appropriate location to avoid this race condition.
static base::AutoReset<bool> BlockZeroStatePromoForTesting();
ExtensionsToolbarContainerViewController(
Browser* browser,
ExtensionsToolbarContainer* extensions_container);
ExtensionsToolbarContainerViewController(
const ExtensionsToolbarContainerViewController&) = delete;
const ExtensionsToolbarContainerViewController& operator=(
const ExtensionsToolbarContainerViewController&) = delete;
~ExtensionsToolbarContainerViewController() override;
// Updates the flex layout rules for the extension toolbar container to have
// views::MinimumFlexSizeRule::kPreferred when WindowControlsOverlay (WCO) is
// toggled on for PWAs. Otherwise the extensions icon does not stay visible as
// it is not considered for during the calculation of the preferred size of
// it's parent (in the case of WCO PWAs, WebAppFrameToolbarView).
void WindowControlsOverlayEnabledChanged(bool enabled);
private:
// Maybe displays the In-Product-Help with a specific priority order.
void MaybeShowIPH();
// Updates the request access button in the toolbar.
void UpdateRequestAccessButton();
// TabStripModelObserver:
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
void TabChangedAt(content::WebContents* contents,
int index,
TabChangeType change_type) override;
// ToolbarActionsModel::Observer:
void OnToolbarActionAdded(
const ToolbarActionsModel::ActionId& action_id) override;
void OnToolbarActionRemoved(
const ToolbarActionsModel::ActionId& action_id) override;
void OnToolbarActionUpdated(
const ToolbarActionsModel::ActionId& action_id) override;
void OnToolbarModelInitialized() override;
void OnToolbarPinnedActionsChanged() override;
// PermissionsManager::Observer:
void OnUserPermissionsSettingsChanged(
const extensions::PermissionsManager::UserPermissionsSettings& settings)
override;
void OnShowAccessRequestsInToolbarChanged(
const extensions::ExtensionId& extension_id,
bool can_show_requests) override;
void OnHostAccessRequestAdded(const extensions::ExtensionId& extension_id,
int tab_id) override;
void OnHostAccessRequestUpdated(const extensions::ExtensionId& extension_id,
int tab_id) override;
void OnHostAccessRequestRemoved(const extensions::ExtensionId& extension_id,
int tab_id) override;
void OnHostAccessRequestsCleared(int tab_id) override;
void OnHostAccessRequestDismissedByUser(
const extensions::ExtensionId& extension_id,
const url::Origin& origin) override;
const raw_ptr<Browser> browser_;
raw_ptr<ExtensionsToolbarContainer> extensions_container_;
base::ScopedObservation<ToolbarActionsModel, ToolbarActionsModel::Observer>
model_observation_{this};
base::ScopedObservation<extensions::PermissionsManager,
extensions::PermissionsManager::Observer>
permissions_manager_observation_{this};
};
#endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSIONS_TOOLBAR_CONTAINER_VIEW_CONTROLLER_H_
|