12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef WIN8_TEST_OPEN_WITH_DIALOG_CONTROLLER_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define WIN8_TEST_OPEN_WITH_DIALOG_CONTROLLER_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <windows.h> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector> 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/callback_forward.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/weak_ptr.h" 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string16.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace win8 { 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Asynchronously drives Windows 8's OpenWithDialog into making a given program 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the default handler for an URL protocol. 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class OpenWithDialogController { 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // A callback that is invoked upon completion of the OpenWithDialog 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // interaction. If the HRESULT indicates success, the interaction completed 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // successfully. Otherwise, the vector of strings may contain the list of 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // possible choices if the desired program could not be selected. 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) typedef base::Callback<void(HRESULT, std::vector<base::string16>)> 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetDefaultCallback; 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OpenWithDialogController(); 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ~OpenWithDialogController(); 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Starts the process of making |program| the default handler for 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |url_protocol|. |parent_window| may be NULL. |callback| will be invoked 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // upon completion. This instance may be deleted prior to |callback| being 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // invoked to cancel the operation. 37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Note: This will fail if |program| is already default for |url_protocol| 38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // since |program| will not show up verbatim in the dialog (e.g., in EN-US, it 39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // will be prefixed by "Keep using "). 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Begin(HWND parent_window, 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& url_protocol, 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& program, 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const SetDefaultCallback& callback); 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sychronously drives the dialog by running a message loop. Do not by any 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // means call this on a thread that already has a message loop. Returns S_OK 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // on success. Otherwise, |choices| may contain the list of possible choices 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // if the desired program could not be selected. 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) HRESULT RunSynchronously(HWND parent_window, 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& url_protocol, 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& program, 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16>* choices); 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) class Context; 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::WeakPtr<Context> context_; 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(OpenWithDialogController); 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace win8 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // WIN8_TEST_OPEN_WITH_DIALOG_CONTROLLER_H_ 65