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 #include "content/public/browser/desktop_media_id.h" | 5 #include "content/public/browser/desktop_media_id.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 id_to_window_map_[id] = window; | 42 id_to_window_map_[id] = window; |
43 window->AddObserver(this); | 43 window->AddObserver(this); |
44 return id; | 44 return id; |
45 } | 45 } |
46 | 46 |
47 aura::Window* GetWindowById(int id) { | 47 aura::Window* GetWindowById(int id) { |
48 std::map<int, aura::Window*>::iterator it = id_to_window_map_.find(id); | 48 std::map<int, aura::Window*>::iterator it = id_to_window_map_.find(id); |
49 return (it != id_to_window_map_.end()) ? it->second : nullptr; | 49 return (it != id_to_window_map_.end()) ? it->second : nullptr; |
50 } | 50 } |
51 | 51 |
| 52 void RegisterVirtualScreenWindow(aura::Window* window) { |
| 53 DCHECK(!virtual_screen_window_); |
| 54 virtual_screen_window_ = window; |
| 55 window->AddObserver(this); |
| 56 } |
| 57 |
| 58 aura::Window* GetVirtualScreenWindow() { return virtual_screen_window_; } |
| 59 |
52 private: | 60 private: |
53 friend struct DefaultSingletonTraits<AuraWindowRegistry>; | 61 friend struct DefaultSingletonTraits<AuraWindowRegistry>; |
54 | 62 |
55 AuraWindowRegistry() | 63 AuraWindowRegistry() |
56 : next_id_(1) { | 64 : next_id_(1), |
| 65 virtual_screen_window_(nullptr) { |
57 } | 66 } |
58 ~AuraWindowRegistry() override {} | 67 ~AuraWindowRegistry() override {} |
59 | 68 |
60 // WindowObserver overrides. | 69 // WindowObserver overrides. |
61 void OnWindowDestroying(aura::Window* window) override { | 70 void OnWindowDestroying(aura::Window* window) override { |
| 71 if (window == virtual_screen_window_) { |
| 72 virtual_screen_window_ = nullptr; |
| 73 return; |
| 74 } |
62 std::map<aura::Window*, int>::iterator it = window_to_id_map_.find(window); | 75 std::map<aura::Window*, int>::iterator it = window_to_id_map_.find(window); |
63 DCHECK(it != window_to_id_map_.end()); | 76 DCHECK(it != window_to_id_map_.end()); |
64 id_to_window_map_.erase(it->second); | 77 id_to_window_map_.erase(it->second); |
65 window_to_id_map_.erase(it); | 78 window_to_id_map_.erase(it); |
66 } | 79 } |
67 | 80 |
68 int next_id_; | 81 int next_id_; |
69 std::map<aura::Window*, int> window_to_id_map_; | 82 std::map<aura::Window*, int> window_to_id_map_; |
70 std::map<int, aura::Window*> id_to_window_map_; | 83 std::map<int, aura::Window*> id_to_window_map_; |
71 | 84 |
| 85 aura::Window* virtual_screen_window_; |
| 86 |
72 DISALLOW_COPY_AND_ASSIGN(AuraWindowRegistry); | 87 DISALLOW_COPY_AND_ASSIGN(AuraWindowRegistry); |
73 }; | 88 }; |
74 | 89 |
75 #endif // defined(USE_AURA) | 90 #endif // defined(USE_AURA) |
76 | 91 |
77 } // namespace | 92 } // namespace |
78 | 93 |
79 namespace content { | 94 namespace content { |
80 | 95 |
81 const char kScreenPrefix[] = "screen"; | 96 const char kScreenPrefix[] = "screen"; |
82 const char kWindowPrefix[] = "window"; | 97 const char kWindowPrefix[] = "window"; |
83 const char kAuraWindowPrefix[] = "aura_window"; | 98 const char kAuraWindowPrefix[] = "aura_window"; |
| 99 const char kAuraVirtualScreenPrefix[] = "aura_virtual_screen"; |
84 | 100 |
85 #if defined(USE_AURA) | 101 #if defined(USE_AURA) |
86 | 102 |
87 // static | 103 // static |
88 DesktopMediaID DesktopMediaID::RegisterAuraWindow(aura::Window* window) { | 104 DesktopMediaID DesktopMediaID::RegisterAuraWindow(aura::Window* window) { |
89 return DesktopMediaID( | 105 return DesktopMediaID( |
90 TYPE_AURA_WINDOW, | 106 TYPE_AURA_WINDOW, |
91 AuraWindowRegistry::GetInstance()->RegisterWindow(window)); | 107 AuraWindowRegistry::GetInstance()->RegisterWindow(window)); |
92 } | 108 } |
93 | 109 |
94 // static | 110 // static |
| 111 void DesktopMediaID::RegisterVirtualScreenAuraWindow(aura::Window* window) { |
| 112 AuraWindowRegistry::GetInstance()->RegisterVirtualScreenWindow(window); |
| 113 } |
| 114 |
| 115 // static |
95 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) { | 116 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) { |
| 117 if (id.type == TYPE_AURA_VIRTUAL_SCREEN) |
| 118 return AuraWindowRegistry::GetInstance()->GetVirtualScreenWindow(); |
| 119 |
96 DCHECK_EQ(id.type, TYPE_AURA_WINDOW); | 120 DCHECK_EQ(id.type, TYPE_AURA_WINDOW); |
97 return AuraWindowRegistry::GetInstance()->GetWindowById(id.id); | 121 return AuraWindowRegistry::GetInstance()->GetWindowById(id.id); |
98 } | 122 } |
99 | 123 |
100 #endif // defined(USE_AURA) | 124 #endif // defined(USE_AURA) |
101 | 125 |
102 // static | 126 // static |
103 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { | 127 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { |
104 std::vector<std::string> parts; | 128 std::vector<std::string> parts; |
105 base::SplitString(str, ':', &parts); | 129 base::SplitString(str, ':', &parts); |
106 | 130 |
107 if (parts.size() != 2) | 131 if (parts.size() != 2) |
108 return DesktopMediaID(TYPE_NONE, 0); | 132 return DesktopMediaID(TYPE_NONE, 0); |
109 | 133 |
110 Type type = TYPE_NONE; | 134 Type type = TYPE_NONE; |
111 if (parts[0] == kScreenPrefix) { | 135 if (parts[0] == kScreenPrefix) { |
112 type = TYPE_SCREEN; | 136 type = TYPE_SCREEN; |
113 } else if (parts[0] == kWindowPrefix) { | 137 } else if (parts[0] == kWindowPrefix) { |
114 type = TYPE_WINDOW; | 138 type = TYPE_WINDOW; |
115 } else if (parts[0] == kAuraWindowPrefix) { | 139 } else if (parts[0] == kAuraWindowPrefix) { |
116 type = TYPE_AURA_WINDOW; | 140 type = TYPE_AURA_WINDOW; |
| 141 } else if (parts[0] == kAuraVirtualScreenPrefix) { |
| 142 type = TYPE_AURA_VIRTUAL_SCREEN; |
117 } else { | 143 } else { |
118 return DesktopMediaID(TYPE_NONE, 0); | 144 return DesktopMediaID(TYPE_NONE, 0); |
119 } | 145 } |
120 | 146 |
121 int64 id; | 147 int64 id; |
122 if (!base::StringToInt64(parts[1], &id)) | 148 if (!base::StringToInt64(parts[1], &id)) |
123 return DesktopMediaID(TYPE_NONE, 0); | 149 return DesktopMediaID(TYPE_NONE, 0); |
124 | 150 |
125 return DesktopMediaID(type, id); | 151 return DesktopMediaID(type, id); |
126 } | 152 } |
127 | 153 |
128 std::string DesktopMediaID::ToString() { | 154 std::string DesktopMediaID::ToString() { |
129 std::string prefix; | 155 std::string prefix; |
130 switch (type) { | 156 switch (type) { |
131 case TYPE_NONE: | 157 case TYPE_NONE: |
132 NOTREACHED(); | 158 NOTREACHED(); |
133 return std::string(); | 159 return std::string(); |
134 case TYPE_SCREEN: | 160 case TYPE_SCREEN: |
135 prefix = kScreenPrefix; | 161 prefix = kScreenPrefix; |
136 break; | 162 break; |
137 case TYPE_WINDOW: | 163 case TYPE_WINDOW: |
138 prefix = kWindowPrefix; | 164 prefix = kWindowPrefix; |
139 break; | 165 break; |
140 case TYPE_AURA_WINDOW: | 166 case TYPE_AURA_WINDOW: |
141 prefix = kAuraWindowPrefix; | 167 prefix = kAuraWindowPrefix; |
142 break; | 168 break; |
| 169 case TYPE_AURA_VIRTUAL_SCREEN: |
| 170 prefix = kAuraVirtualScreenPrefix; |
| 171 break; |
143 } | 172 } |
144 DCHECK(!prefix.empty()); | 173 DCHECK(!prefix.empty()); |
145 | 174 |
146 prefix.append(":"); | 175 prefix.append(":"); |
147 prefix.append(base::Int64ToString(id)); | 176 prefix.append(base::Int64ToString(id)); |
148 | 177 |
149 return prefix; | 178 return prefix; |
150 } | 179 } |
151 | 180 |
152 } // namespace content | 181 } // namespace content |
OLD | NEW |