Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / renderer_host / pepper / monitor_finder_mac.mm
blob31f6cfd41060fa300ad3ff54ee71f0592094e430
1 // Copyright 2014 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 #include "chrome/browser/renderer_host/pepper/monitor_finder_mac.h"
7 #import <Cocoa/Cocoa.h>
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_frame_host.h"
12 namespace chrome {
14 MonitorFinder::MonitorFinder(int process_id, int render_frame_id)
15     : process_id_(process_id),
16       render_frame_id_(render_frame_id),
17       request_sent_(false),
18       display_id_(kCGNullDirectDisplay) {}
20 MonitorFinder::~MonitorFinder() {}
22 int64_t MonitorFinder::GetMonitor() {
23   {
24     // The plugin may call this method several times, so avoid spamming the UI
25     // thread with requests by only allowing one outstanding request at a time.
26     base::AutoLock lock(mutex_);
27     if (request_sent_)
28       return display_id_;
29     request_sent_ = true;
30   }
32   content::BrowserThread::PostTask(
33       content::BrowserThread::UI,
34       FROM_HERE,
35       base::Bind(&MonitorFinder::FetchMonitorFromWidget, this));
36   return display_id_;
39 // static
40 bool MonitorFinder::IsMonitorBuiltIn(int64_t display_id) {
41   return CGDisplayIsBuiltin(display_id);
44 void MonitorFinder::FetchMonitorFromWidget() {
45   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
46   content::RenderFrameHost* rfh =
47       content::RenderFrameHost::FromID(process_id_, render_frame_id_);
48   if (!rfh)
49     return;
51   gfx::NativeView native_view = rfh->GetNativeView();
52   NSWindow* window = [native_view window];
53   NSScreen* screen = [window screen];
54   CGDirectDisplayID display_id =
55       [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
57   base::AutoLock lock(mutex_);
58   request_sent_ = false;
59   display_id_ = display_id;
62 }  // namespace chrome