| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_BASE_SHELL_DIALOG_WIN_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_BASE_SHELL_DIALOG_WIN_H_ | |
| 7 | |
| 8 #include <shlobj.h> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "ui/base/dialogs/base_shell_dialog.h" | |
| 12 | |
| 13 namespace base { | |
| 14 class Thread; | |
| 15 } | |
| 16 | |
| 17 /////////////////////////////////////////////////////////////////////////////// | |
| 18 // A base class for all shell dialog implementations that handles showing a | |
| 19 // shell dialog modally on its own thread. | |
| 20 class BaseShellDialogImpl { | |
| 21 public: | |
| 22 BaseShellDialogImpl(); | |
| 23 virtual ~BaseShellDialogImpl(); | |
| 24 | |
| 25 protected: | |
| 26 // Represents a run of a dialog. | |
| 27 struct RunState { | |
| 28 // Owning HWND, may be null. | |
| 29 HWND owner; | |
| 30 | |
| 31 // Thread dialog is run on. | |
| 32 base::Thread* dialog_thread; | |
| 33 }; | |
| 34 | |
| 35 // Called at the beginning of a modal dialog run. Disables the owner window | |
| 36 // and tracks it. Returns the message loop of the thread that the dialog will | |
| 37 // be run on. | |
| 38 RunState BeginRun(HWND owner); | |
| 39 | |
| 40 // Cleans up after a dialog run. If the run_state has a valid HWND this makes | |
| 41 // sure that the window is enabled. This is essential because BeginRun | |
| 42 // aggressively guards against multiple modal dialogs per HWND. Must be called | |
| 43 // on the UI thread after the result of the dialog has been determined. | |
| 44 // | |
| 45 // In addition this deletes the Thread in RunState. | |
| 46 void EndRun(RunState run_state); | |
| 47 | |
| 48 // Returns true if a modal shell dialog is currently active for the specified | |
| 49 // owner. Must be called on the UI thread. | |
| 50 bool IsRunningDialogForOwner(HWND owner) const; | |
| 51 | |
| 52 // Disables the window |owner|. Can be run from either the ui or the dialog | |
| 53 // thread. Can be called on either the UI or the dialog thread. This function | |
| 54 // is called on the dialog thread after the modal Windows Common dialog | |
| 55 // functions return because Windows automatically re-enables the owning | |
| 56 // window when those functions return, but we don't actually want them to be | |
| 57 // re-enabled until the response of the dialog propagates back to the UI | |
| 58 // thread, so we disable the owner manually after the Common dialog function | |
| 59 // returns. | |
| 60 void DisableOwner(HWND owner); | |
| 61 | |
| 62 private: | |
| 63 typedef std::set<HWND> Owners; | |
| 64 | |
| 65 // Creates a thread to run a shell dialog on. Each dialog requires its own | |
| 66 // thread otherwise in some situations where a singleton owns a single | |
| 67 // instance of this object we can have a situation where a modal dialog in | |
| 68 // one window blocks the appearance of a modal dialog in another. | |
| 69 static base::Thread* CreateDialogThread(); | |
| 70 | |
| 71 // Enables the window |owner_|. Can only be run from the ui thread. | |
| 72 void EnableOwner(HWND owner); | |
| 73 | |
| 74 // A list of windows that currently own active shell dialogs for this | |
| 75 // instance. For example, if the DownloadManager owns an instance of this | |
| 76 // object and there are two browser windows open both with Save As dialog | |
| 77 // boxes active, this list will consist of the two browser windows' HWNDs. | |
| 78 // The derived class must call EndRun once the dialog is done showing to | |
| 79 // remove the owning HWND from this list. | |
| 80 // This object is static since it is maintained for all instances of this | |
| 81 // object - i.e. you can't have two file pickers open for the | |
| 82 // same owner, even though they might be represented by different instances | |
| 83 // of this object. | |
| 84 // This set only contains non-null HWNDs. NULL hwnds are not added to this | |
| 85 // list. | |
| 86 static Owners owners_; | |
| 87 static int instance_count_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(BaseShellDialogImpl); | |
| 90 }; | |
| 91 | |
| 92 #endif // CHROME_BROWSER_UI_VIEWS_BASE_SHELL_DIALOG_WIN_H_ | |
| OLD | NEW |