| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ | 6 #define CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 | 10 |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/public/browser/web_contents_media_capture_id.h" |
| 12 | 13 |
| 13 #if defined(USE_AURA) | 14 #if defined(USE_AURA) |
| 14 namespace aura { | 15 namespace aura { |
| 15 class Window; | 16 class Window; |
| 16 } // namespace aura | 17 } // namespace aura |
| 17 #endif // defined(USE_AURA) | 18 #endif // defined(USE_AURA) |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 // Type used to identify desktop media sources. It's converted to string and | 22 // Type used to identify desktop media sources. It's converted to string and |
| 22 // stored in MediaStreamRequest::requested_video_device_id. | 23 // stored in MediaStreamRequest::requested_video_device_id. |
| 23 struct CONTENT_EXPORT DesktopMediaID { | 24 struct CONTENT_EXPORT DesktopMediaID { |
| 24 public: | 25 public: |
| 25 enum Type { | 26 enum Type { TYPE_NONE, TYPE_SCREEN, TYPE_WINDOW, TYPE_WEB_CONTENTS }; |
| 26 TYPE_NONE, | |
| 27 TYPE_SCREEN, | |
| 28 TYPE_WINDOW, | |
| 29 }; | |
| 30 | 27 |
| 31 typedef intptr_t Id; | 28 typedef intptr_t Id; |
| 32 | 29 |
| 33 // Represents an "unset" value for either |id| or |aura_id|. | 30 // Represents an "unset" value for either |id| or |aura_id|. |
| 34 static const Id kNullId = 0; | 31 static const Id kNullId = 0; |
| 35 | 32 |
| 36 #if defined(USE_AURA) | 33 #if defined(USE_AURA) |
| 37 // Assigns integer identifier to the |window| and returns its DesktopMediaID. | 34 // Assigns integer identifier to the |window| and returns its DesktopMediaID. |
| 38 static DesktopMediaID RegisterAuraWindow(Type type, aura::Window* window); | 35 static DesktopMediaID RegisterAuraWindow(Type type, aura::Window* window); |
| 39 | 36 |
| 40 // Returns the Window that was previously registered using | 37 // Returns the Window that was previously registered using |
| 41 // RegisterAuraWindow(), else nullptr. | 38 // RegisterAuraWindow(), else nullptr. |
| 42 static aura::Window* GetAuraWindowById(const DesktopMediaID& id); | 39 static aura::Window* GetAuraWindowById(const DesktopMediaID& id); |
| 43 #endif // defined(USE_AURA) | 40 #endif // defined(USE_AURA) |
| 44 | 41 |
| 45 static DesktopMediaID Parse(const std::string& str); | |
| 46 | |
| 47 DesktopMediaID() = default; | 42 DesktopMediaID() = default; |
| 48 | 43 |
| 49 DesktopMediaID(Type type, Id id) | 44 DesktopMediaID(Type type, Id id) : type(type), id(id) {} |
| 50 : type(type), | 45 |
| 51 id(id) { | 46 DesktopMediaID(Type type, Id id, WebContentsMediaCaptureId web_contents_id) |
| 52 } | 47 : type(type), id(id), web_contents_id(web_contents_id) {} |
| 53 | 48 |
| 54 // Operators so that DesktopMediaID can be used with STL containers. | 49 // Operators so that DesktopMediaID can be used with STL containers. |
| 55 bool operator<(const DesktopMediaID& other) const { | 50 bool operator<(const DesktopMediaID& other) const; |
| 56 #if defined(USE_AURA) | 51 bool operator==(const DesktopMediaID& other) const; |
| 57 return std::tie(type, id, aura_id) < | |
| 58 std::tie(other.type, other.id, other.aura_id); | |
| 59 #else | |
| 60 return std::tie(type, id) < std::tie(other.type, other.id); | |
| 61 #endif | |
| 62 } | |
| 63 bool operator==(const DesktopMediaID& other) const { | |
| 64 #if defined(USE_AURA) | |
| 65 return type == other.type && id == other.id && aura_id == other.aura_id; | |
| 66 #else | |
| 67 return type == other.type && id == other.id; | |
| 68 #endif | |
| 69 } | |
| 70 | 52 |
| 71 bool is_null() { return type == TYPE_NONE; } | 53 bool is_null() const { return type == TYPE_NONE; } |
| 72 | 54 std::string ToString() const; |
| 73 std::string ToString(); | 55 static DesktopMediaID Parse(const std::string& str); |
| 74 | 56 |
| 75 Type type = TYPE_NONE; | 57 Type type = TYPE_NONE; |
| 76 | 58 |
| 77 // The IDs referring to the target native screen or window. |id| will be | 59 // The IDs referring to the target native screen or window. |id| will be |
| 78 // non-null if and only if it refers to a native screen/window. |aura_id| | 60 // non-null if and only if it refers to a native screen/window. |aura_id| |
| 79 // will be non-null if and only if it refers to an Aura window. Note that is | 61 // will be non-null if and only if it refers to an Aura window. Note that is |
| 80 // it possible for both of these to be non-null, which means both IDs are | 62 // it possible for both of these to be non-null, which means both IDs are |
| 81 // referring to the same logical window. | 63 // referring to the same logical window. |
| 82 Id id = kNullId; | 64 Id id = kNullId; |
| 83 #if defined(USE_AURA) | 65 #if defined(USE_AURA) |
| 84 // TODO(miu): Make this an int, after clean-up for http://crbug.com/513490. | 66 // TODO(miu): Make this an int, after clean-up for http://crbug.com/513490. |
| 85 Id aura_id = kNullId; | 67 Id aura_id = kNullId; |
| 86 #endif | 68 #endif |
| 69 |
| 70 // This id contains information for WebContents capture. |
| 71 WebContentsMediaCaptureId web_contents_id; |
| 87 }; | 72 }; |
| 88 | 73 |
| 89 } // namespace content | 74 } // namespace content |
| 90 | 75 |
| 91 #endif // CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ | 76 #endif // CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ |
| OLD | NEW |