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