summaryrefslogtreecommitdiffstats
path: root/chrome/browser/process_singleton_modal_dialog_lock.cc
blob: 34011a7b620b520298d4f73729872a49dddcc135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/process_singleton_modal_dialog_lock.h"

#if defined(OS_WIN)
#include <Windows.h>
#endif

#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"

namespace {

#if !defined(OS_WIN) || defined(USE_AURA)
void DoSetForegroundWindow(gfx::NativeWindow /* target_window */) {
  NOTREACHED();
}
#else
void DoSetForegroundWindow(HWND target_window) {
  ::SetForegroundWindow(target_window);
}
#endif

}  // namespace

ProcessSingletonModalDialogLock::ProcessSingletonModalDialogLock(
    const ProcessSingleton::NotificationCallback& original_callback)
    : active_dialog_(NULL),
      original_callback_(original_callback),
      set_foreground_window_handler_(base::Bind(&DoSetForegroundWindow)) {}

ProcessSingletonModalDialogLock::ProcessSingletonModalDialogLock(
    const ProcessSingleton::NotificationCallback& original_callback,
    const SetForegroundWindowHandler& set_foreground_window_handler)
    : active_dialog_(NULL),
      original_callback_(original_callback),
      set_foreground_window_handler_(set_foreground_window_handler) {}

ProcessSingletonModalDialogLock::~ProcessSingletonModalDialogLock() {}

void ProcessSingletonModalDialogLock::SetActiveModalDialog(
    gfx::NativeWindow active_dialog) {
  active_dialog_ = active_dialog;
}

ProcessSingleton::NotificationCallback
ProcessSingletonModalDialogLock::AsNotificationCallback() {
  return base::Bind(&ProcessSingletonModalDialogLock::NotificationCallbackImpl,
                    base::Unretained(this));
}

bool ProcessSingletonModalDialogLock::NotificationCallbackImpl(
      const CommandLine& command_line,
      const base::FilePath& current_directory) {
  if (active_dialog_ != NULL) {
    set_foreground_window_handler_.Run(active_dialog_);
    return true;
  } else {
    return original_callback_.Run(command_line, current_directory);
  }
}