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 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_controller.h" | 5 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_controller.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #import "base/mac/bundle_locations.h" | 11 #import "base/mac/bundle_locations.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "chrome/browser/media/combined_desktop_media_list.h" | 13 #include "chrome/browser/media/combined_desktop_media_list.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/browser_window.h" |
14 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 16 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
15 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_item.h" | 17 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_item.h" |
16 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
20 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
22 #include "grit/components_strings.h" | 24 #include "grit/components_strings.h" |
23 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 25 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 240 } |
239 | 241 |
240 - (void)reportResult:(content::DesktopMediaID)sourceID { | 242 - (void)reportResult:(content::DesktopMediaID)sourceID { |
241 if (doneCallback_.is_null()) { | 243 if (doneCallback_.is_null()) { |
242 return; | 244 return; |
243 } | 245 } |
244 | 246 |
245 sourceID.audio_share = [audioShareCheckbox_ isEnabled] && | 247 sourceID.audio_share = [audioShareCheckbox_ isEnabled] && |
246 [audioShareCheckbox_ state] == NSOnState; | 248 [audioShareCheckbox_ state] == NSOnState; |
247 | 249 |
248 // If the media source is an tab, activate it. | |
249 if (sourceID.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { | 250 if (sourceID.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) { |
| 251 // Activate the selected tab and bring the browser window for the selected |
| 252 // tab to the front. |
250 content::WebContents* tab = content::WebContents::FromRenderFrameHost( | 253 content::WebContents* tab = content::WebContents::FromRenderFrameHost( |
251 content::RenderFrameHost::FromID( | 254 content::RenderFrameHost::FromID( |
252 sourceID.web_contents_id.render_process_id, | 255 sourceID.web_contents_id.render_process_id, |
253 sourceID.web_contents_id.main_render_frame_id)); | 256 sourceID.web_contents_id.main_render_frame_id)); |
254 if (tab) | 257 if (tab) { |
255 tab->GetDelegate()->ActivateContents(tab); | 258 tab->GetDelegate()->ActivateContents(tab); |
| 259 Browser* browser = chrome::FindBrowserWithWebContents(tab); |
| 260 if (browser && browser->window()) |
| 261 browser->window()->Activate(); |
| 262 } |
256 } | 263 } |
257 | 264 |
258 // Notify the |callback_| asynchronously because it may release the | 265 // Notify the |callback_| asynchronously because it may release the |
259 // controller. | 266 // controller. |
260 content::BrowserThread::PostTask( | 267 content::BrowserThread::PostTask( |
261 content::BrowserThread::UI, FROM_HERE, | 268 content::BrowserThread::UI, FROM_HERE, |
262 base::Bind(doneCallback_, sourceID)); | 269 base::Bind(doneCallback_, sourceID)); |
263 doneCallback_.Reset(); | 270 doneCallback_.Reset(); |
264 } | 271 } |
265 | 272 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 - (void)sourceThumbnailChangedAtIndex:(int)index { | 440 - (void)sourceThumbnailChangedAtIndex:(int)index { |
434 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 441 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
435 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); | 442 NSImage* image = gfx::NSImageFromImageSkia(source.thumbnail); |
436 | 443 |
437 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; | 444 DesktopMediaPickerItem* item = [items_ objectAtIndex:index]; |
438 [item setImageRepresentation:image]; | 445 [item setImageRepresentation:image]; |
439 [sourceBrowser_ reloadData]; | 446 [sourceBrowser_ reloadData]; |
440 } | 447 } |
441 | 448 |
442 @end // @interface DesktopMediaPickerController | 449 @end // @interface DesktopMediaPickerController |
OLD | NEW |