1 // Copyright (c) 2013 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 #ifndef WIN8_TEST_OPEN_WITH_DIALOG_CONTROLLER_H_
6 #define WIN8_TEST_OPEN_WITH_DIALOG_CONTROLLER_H_
12 #include "base/basictypes.h"
13 #include "base/callback_forward.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h"
19 // Asynchronously drives Windows 8's OpenWithDialog into making a given program
20 // the default handler for an URL protocol.
21 class OpenWithDialogController
{
23 // A callback that is invoked upon completion of the OpenWithDialog
24 // interaction. If the HRESULT indicates success, the interaction completed
25 // successfully. Otherwise, the vector of strings may contain the list of
26 // possible choices if the desired program could not be selected.
27 typedef base::Callback
<void(HRESULT
, std::vector
<base::string16
>)>
30 OpenWithDialogController();
31 ~OpenWithDialogController();
33 // Starts the process of making |program| the default handler for
34 // |url_protocol|. |parent_window| may be NULL. |callback| will be invoked
35 // upon completion. This instance may be deleted prior to |callback| being
36 // invoked to cancel the operation.
37 // Note: This will fail if |program| is already default for |url_protocol|
38 // since |program| will not show up verbatim in the dialog (e.g., in EN-US, it
39 // will be prefixed by "Keep using ").
40 void Begin(HWND parent_window
,
41 const base::string16
& url_protocol
,
42 const base::string16
& program
,
43 const SetDefaultCallback
& callback
);
45 // Sychronously drives the dialog by running a message loop. Do not by any
46 // means call this on a thread that already has a message loop. Returns S_OK
47 // on success. Otherwise, |choices| may contain the list of possible choices
48 // if the desired program could not be selected.
49 HRESULT
RunSynchronously(HWND parent_window
,
50 const base::string16
& url_protocol
,
51 const base::string16
& program
,
52 std::vector
<base::string16
>* choices
);
57 base::WeakPtr
<Context
> context_
;
59 DISALLOW_COPY_AND_ASSIGN(OpenWithDialogController
);
64 #endif // WIN8_TEST_OPEN_WITH_DIALOG_CONTROLLER_H_