summaryrefslogtreecommitdiffstats
path: root/win8/test/open_with_dialog_controller.h
blob: 8c664fce1184fef0a0ef25e564b1077fc7fb9673 (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
// 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.

#ifndef WIN8_TEST_OPEN_WITH_DIALOG_CONTROLLER_H_
#define WIN8_TEST_OPEN_WITH_DIALOG_CONTROLLER_H_

#include <windows.h>

#include <vector>

#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "base/string16.h"

namespace win8 {

// Asynchronously drives Windows 8's OpenWithDialog into making a given program
// the default handler for an URL protocol.
class OpenWithDialogController {
 public:
  // A callback that is invoked upon completion of the OpenWithDialog
  // interaction. If the HRESULT indicates success, the interaction completed
  // successfully. Otherwise, the vector of strings may contain the list of
  // possible choices if the desired program could not be selected.
  typedef base::Callback<void(HRESULT,
                              std::vector<string16>)> SetDefaultCallback;

  OpenWithDialogController();
  ~OpenWithDialogController();

  // Starts the process of making |program| the default handler for
  // |url_protocol|. |parent_window| may be NULL.  |callback| will be invoked
  // upon completion. This instance may be deleted prior to |callback| being
  // invoked to cancel the operation.
  void Begin(HWND parent_window,
             const string16& url_protocol,
             const string16& program,
             const SetDefaultCallback& callback);

  // Sychronously drives the dialog by running a message loop. Do not by any
  // means call this on a thread that already has a message loop. Returns S_OK
  // on success. Otherwise, |choices| may contain the list of possible choices
  // if the desired program could not be selected.
  HRESULT RunSynchronously(HWND parent_window,
                           const string16& url_protocol,
                           const string16& program,
                           std::vector<string16>* choices);

 private:
  class Context;

  base::WeakPtr<Context> context_;

  DISALLOW_COPY_AND_ASSIGN(OpenWithDialogController);
};

}  // namespace win8

#endif // WIN8_TEST_OPEN_WITH_DIALOG_CONTROLLER_H_