File: bookmark_utils_desktop.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (122 lines) | stat: -rw-r--r-- 4,911 bytes parent folder | download | duplicates (3)
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
// 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_widget_types.h"

class Browser;
struct NavigateParams;

namespace content {
class BrowserContext;
class NavigationHandle;
}  // namespace content

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);
};

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);

// 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);

}  // namespace bookmarks

#endif  // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_DESKTOP_H_