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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
// Copyright 2015 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_BOOKMARKS_BOOKMARK_UTILS_DESKTOP_H_
#define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_DESKTOP_H_
#include <vector>
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/bookmarks/bookmark_editor.h"
#include "chrome/browser/ui/bookmarks/bookmark_stats.h"
#include "components/page_load_metrics/browser/navigation_handle_user_data.h"
#include "components/tab_groups/tab_group_id.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/native_window_types.h"
class Browser;
struct NavigateParams;
class TabGroup;
namespace content {
class BrowserContext;
class NavigationHandle;
} // namespace content
namespace tab_groups {
class TabGroupSyncService;
} // namespace tab_groups
namespace bookmarks {
class BookmarkNode;
enum OpenAllBookmarksContext {
kNone = 0, // Open all bookmarks as separate tabs.
kInGroup = 1, // Open all bookmarks in a tab group.
kInSplit = 2, // Open all bookmarks in a split tab.
kMaxValue = kInSplit,
};
// Wraps bookmark navigations to support view testing.
class BookmarkNavigationWrapper {
public:
virtual ~BookmarkNavigationWrapper() = default;
// Wraps browser_navigator::Navigate.
virtual base::WeakPtr<content::NavigationHandle> NavigateTo(
NavigateParams* params);
// Provide an instance for use in testing.
static void SetInstanceForTesting(BookmarkNavigationWrapper* instance);
};
// Set whether to override connected group to skip UI for testing.
void SetOverrideConnectedGroupForTesting(bool value);
using TabGroupData =
std::pair<std::optional<tab_groups::TabGroupId>, std::u16string>;
// Number of bookmarks we'll open before prompting the user to see if they
// really want to open all.
//
// NOTE: treat this as a const. It is not const so unit tests can change the
// value.
extern size_t kNumBookmarkUrlsBeforePrompting;
// Tries to open all bookmarks in `nodes`. If there are many, prompts
// the user first. Returns immediately, opening the bookmarks
// asynchronously if prompting the user. `browser` is the browser from
// which the bookmarks were opened. Its window is used as the anchor for
// the dialog (if shown). `context` can optionally open the bookmarks into a
// tab group or split view.
// `launch_action` represents the location and time of the bookmark launch
// action for callsites that support it.
// TODO(crbug.com/40914589): This should be made non-optional once all callsites
// have all the information needed to correctly construct the `launch_action`.
void OpenAllIfAllowed(
Browser* browser,
const std::vector<
raw_ptr<const bookmarks::BookmarkNode, VectorExperimental>>& nodes,
WindowOpenDisposition initial_disposition,
bookmarks::OpenAllBookmarksContext context =
bookmarks::OpenAllBookmarksContext::kNone,
page_load_metrics::NavigationHandleUserData::InitiatorLocation
navigation_type = page_load_metrics::NavigationHandleUserData::
InitiatorLocation::kOther,
std::optional<BookmarkLaunchAction> launch_action = std::nullopt);
// Returns the count of bookmarks that would be opened by OpenAll. If
// |incognito_context| is set, the function will use it to check if the URLs
// can be opened in incognito mode, which may affect the count.
int OpenCount(gfx::NativeWindow parent,
const std::vector<raw_ptr<const bookmarks::BookmarkNode,
VectorExperimental>>& nodes,
content::BrowserContext* incognito_context = nullptr);
// Convenience for OpenCount() with a single BookmarkNode.
int OpenCount(gfx::NativeWindow parent,
const bookmarks::BookmarkNode* node,
content::BrowserContext* incognito_context = nullptr);
// Asks the user before deleting a non-empty bookmark folder.
bool ConfirmDeleteBookmarkNode(gfx::NativeWindow window,
const bookmarks::BookmarkNode* node);
// Shows the bookmark all tabs dialog.
void ShowBookmarkAllTabsDialog(Browser* browser);
// Shows the bookmark tab group dialog.
void ShowBookmarkTabGroupDialog(
Browser* browser,
const TabGroup& tab_group,
base::OnceCallback<void(Browser*, const tab_groups::TabGroupId&)>
on_save_callback = base::DoNothing());
// Returns true if OpenAll() can open at least one bookmark of type url
// in |selection|.
bool HasBookmarkURLs(const std::vector<raw_ptr<const bookmarks::BookmarkNode,
VectorExperimental>>& selection);
// Returns true if OpenAll() can open at least one bookmark of type url
// in |selection| with incognito mode.
bool HasBookmarkURLsAllowedInIncognitoMode(
const std::vector<
raw_ptr<const bookmarks::BookmarkNode, VectorExperimental>>& selection);
// Populates |folder_data| with all tab items and sub-folders for any open tab
// groups.
void GetURLsAndFoldersForTabEntries(
std::vector<BookmarkEditor::EditDetails::BookmarkData>* folder_data,
std::vector<std::pair<GURL, std::u16string>> tab_entries,
base::flat_map<int, TabGroupData> groups_by_index);
// Populates |folder_data| with all tabs from the tab group.
void GetURLsAndFoldersForTabGroup(
const Browser* browser,
const TabGroup& tab_group,
std::vector<BookmarkEditor::EditDetails::BookmarkData>* folder_data);
// Suggest a unique name for tab group based on the bookmark folder's name.
std::u16string SuggestUniqueTabGroupName(
std::u16string folder_title,
const tab_groups::TabGroupSyncService* tab_group_sync_service);
} // namespace bookmarks
#endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_DESKTOP_H_
|