1 // Copyright 2013 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.
4 
5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_PICKER_H_
6 #define CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_PICKER_H_
7 
8 #include <memory>
9 #include <string>
10 #include <utility>
11 
12 #include "base/callback_forward.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/optional.h"
16 #include "base/strings/string16.h"
17 #include "content/public/browser/desktop_media_id.h"
18 #include "content/public/browser/web_contents_observer.h"
19 #include "ui/base/ui_base_types.h"
20 #include "ui/gfx/native_widget_types.h"
21 
22 class DesktopMediaList;
23 
24 namespace content {
25 class WebContents;
26 }
27 
28 // Abstract interface for desktop media picker UI. It's used by Desktop Media
29 // API and by ARC to let user choose a desktop media source.
30 //
31 // TODO(crbug.com/987001): Rename this class.
32 class DesktopMediaPicker {
33  public:
34   using DoneCallback = base::OnceCallback<void(content::DesktopMediaID id)>;
35 
36   struct Params {
37     Params();
38     Params(const Params&);
39     Params& operator=(const Params&);
40     ~Params();
41 
42     // WebContents this picker is relative to, can be null.
43     content::WebContents* web_contents = nullptr;
44     // The context whose root window is used for dialog placement, cannot be
45     // null for Aura.
46     gfx::NativeWindow context = nullptr;
47     // Parent window the dialog is relative to, only used on Mac.
48     gfx::NativeWindow parent = nullptr;
49     // The modality used for showing the dialog.
50     ui::ModalType modality = ui::ModalType::MODAL_TYPE_CHILD;
51     // The name used in the dialog for what is requesting the picker to be
52     // shown.
53     base::string16 app_name;
54     // Can be the same as target_name. If it is not then this is used in the
55     // dialog for what is specific target within the app_name is requesting the
56     // picker.
57     base::string16 target_name;
58     // Whether audio capture should be shown as an option in the picker.
59     bool request_audio = false;
60     // Whether audio capture option should be approved by default if shown.
61     bool approve_audio_by_default = true;
62     // This flag controls the behvior in the case where the picker is invoked to
63     // select a screen and there is only one screen available.  If true, the
64     // dialog is bypassed entirely and the screen is automatically selected.
65     // This behavior is disabled by default because in addition to letting the
66     // user select a desktop, the desktop picker also serves to prevent the
67     // screen screen from being shared without the user's explicit consent.
68     bool select_only_screen = false;
69   };
70 
71   // Creates default implementation of DesktopMediaPicker for the current
72   // platform.
73   static std::unique_ptr<DesktopMediaPicker> Create();
74 
DesktopMediaPicker()75   DesktopMediaPicker() {}
~DesktopMediaPicker()76   virtual ~DesktopMediaPicker() {}
77 
78   // Shows dialog with list of desktop media sources (screens, windows, tabs)
79   // provided by |sources_lists|.
80   // Dialog window will call |done_callback| when user chooses one of the
81   // sources or closes the dialog.
82   virtual void Show(const Params& params,
83                     std::vector<std::unique_ptr<DesktopMediaList>> source_lists,
84                     DoneCallback done_callback) = 0;
85 
86  private:
87   DISALLOW_COPY_AND_ASSIGN(DesktopMediaPicker);
88 };
89 
90 #endif  // CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_PICKER_H_
91