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