Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / tabs / tab_utils.h
blob3f1b1cdb8d6e1b649a25bbf5d5a670d46965217a
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_TABS_TAB_UTILS_H_
6 #define CHROME_BROWSER_UI_TABS_TAB_UTILS_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
13 #include "content/public/browser/web_contents_user_data.h"
15 class TabStripModel;
17 namespace content {
18 class WebContents;
19 } // namespace content
21 namespace gfx {
22 class Animation;
23 class Image;
24 } // namespace gfx
26 namespace ui {
27 class ThemeProvider;
30 // Media state for a tab. In reality, more than one of these may apply. See
31 // comments for GetTabMediaStateForContents() below.
32 enum TabMediaState {
33 TAB_MEDIA_STATE_NONE,
34 TAB_MEDIA_STATE_RECORDING, // Audio/Video being recorded, consumed by tab.
35 TAB_MEDIA_STATE_CAPTURING, // Tab contents being captured.
36 TAB_MEDIA_STATE_AUDIO_PLAYING, // Audible audio is playing from the tab.
37 TAB_MEDIA_STATE_AUDIO_MUTING, // Tab audio is being muted.
40 enum TabMutedReason {
41 TAB_MUTED_REASON_NONE, // The tab has never been muted or unmuted.
42 TAB_MUTED_REASON_CONTEXT_MENU, // Mute/Unmute chosen from tab context menu.
43 TAB_MUTED_REASON_AUDIO_INDICATOR, // Mute toggled via tab-strip audio icon.
44 TAB_MUTED_REASON_MEDIA_CAPTURE, // Media recording/capture was started.
45 TAB_MUTED_REASON_EXTENSION, // Mute state changed via extension API.
48 enum TabMutedResult {
49 TAB_MUTED_RESULT_SUCCESS,
50 TAB_MUTED_RESULT_FAIL_NOT_ENABLED,
51 TAB_MUTED_RESULT_FAIL_TABCAPTURE,
54 namespace chrome {
56 // Logic to determine which components (i.e., close button, favicon, and media
57 // indicator) of a tab should be shown, given current state. |capacity|
58 // specifies how many components can be shown, given available tab width.
60 // Precedence rules for deciding what to show when capacity is insufficient to
61 // show everything:
63 // Active tab: Always show the close button, then the media indicator, then
64 // the favicon.
65 // Inactive tab: Media indicator, then the favicon, then the close button.
66 // Pinned tab: Show only the media indicator, or only the favicon
67 // (TAB_MEDIA_STATE_NONE). Never show the close button.
68 bool ShouldTabShowFavicon(int capacity,
69 bool is_pinned_tab,
70 bool is_active_tab,
71 bool has_favicon,
72 TabMediaState media_state);
73 bool ShouldTabShowMediaIndicator(int capacity,
74 bool is_pinned_tab,
75 bool is_active_tab,
76 bool has_favicon,
77 TabMediaState media_state);
78 bool ShouldTabShowCloseButton(int capacity,
79 bool is_pinned_tab,
80 bool is_active_tab);
82 // Returns the media state to be shown by the tab's media indicator. When
83 // multiple states apply (e.g., tab capture with audio playback), the one most
84 // relevant to user privacy concerns is selected.
85 TabMediaState GetTabMediaStateForContents(content::WebContents* contents);
87 // Returns a cached image, to be shown by the media indicator for the given
88 // |media_state|. Uses the global ui::ResourceBundle shared instance.
89 gfx::Image GetTabMediaIndicatorImage(TabMediaState media_state,
90 const ui::ThemeProvider* tp);
92 // Returns the cached image, to be shown by the media indicator button for mouse
93 // hover/pressed, when the indicator is in the given |media_state|. Uses the
94 // global ui::ResourceBundle shared instance.
95 gfx::Image GetTabMediaIndicatorAffordanceImage(TabMediaState media_state,
96 const ui::ThemeProvider* tp);
98 // Returns a non-continuous Animation that performs a fade-in or fade-out
99 // appropriate for the given |next_media_state|. This is used by the tab media
100 // indicator to alert the user that recording, tab capture, or audio playback
101 // has started/stopped.
102 scoped_ptr<gfx::Animation> CreateTabMediaIndicatorFadeAnimation(
103 TabMediaState next_media_state);
105 // Returns the text to show in a tab's tooltip: The contents |title|, followed
106 // by a break, followed by a localized string describing the |media_state|.
107 base::string16 AssembleTabTooltipText(const base::string16& title,
108 TabMediaState media_state);
110 // Returns true if experimental audio mute controls (UI or extension API) are
111 // enabled. Currently, toggling mute from a tab's context menu is the only
112 // non-experimental control method.
113 bool AreExperimentalMuteControlsEnabled();
115 // Returns true if audio mute can be activated/deactivated for the given
116 // |contents|.
117 bool CanToggleAudioMute(content::WebContents* contents);
119 // Unmute a tab if it is currently muted at the request of the extension having
120 // the given |extension_id|.
121 void UnmuteIfMutedByExtension(content::WebContents* contents,
122 const std::string& extension_id);
124 // Sets whether all audio output from |contents| is muted, along with the
125 // |reason| it is to be muted/unmuted (via UI or extension API). When |reason|
126 // is TAB_MUTED_REASON_EXTENSION, |extension_id| must be provided; otherwise, it
127 // is ignored.
129 // If the |reason| is an experimental feature and the experiment is not enabled,
130 // this will have no effect and TAB_MUTED_RESULT_FAIL_NOT_ENABLED will be
131 // returned.
132 TabMutedResult SetTabAudioMuted(content::WebContents* contents,
133 bool mute,
134 TabMutedReason reason,
135 const std::string& extension_id);
137 // Returns the last reason a tab's mute state was changed.
138 TabMutedReason GetTabAudioMutedReason(content::WebContents* contents);
140 // If the last reason a tab's mute state was changed was due to use of the
141 // extension API, this returns the extension's ID string. Otherwise, the empty
142 // string is returned.
143 const std::string& GetExtensionIdForMutedTab(content::WebContents* contents);
145 // Returns true if the tabs at the |indices| in |tab_strip| are all muted.
146 bool AreAllTabsMuted(const TabStripModel& tab_strip,
147 const std::vector<int>& indices);
149 } // namespace chrome
151 #endif // CHROME_BROWSER_UI_TABS_TAB_UTILS_H_