OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/views/file_manager_dialog.h" | 5 #include "chrome/browser/ui/views/file_manager_dialog.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "chrome/browser/extensions/extension_file_browser_private_api.h" | 9 #include "chrome/browser/extensions/extension_file_browser_private_api.h" |
10 #include "chrome/browser/extensions/file_manager_util.h" | 10 #include "chrome/browser/extensions/file_manager_util.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/browser/ui/views/extensions/extension_dialog.h" | 14 #include "chrome/browser/ui/views/extensions/extension_dialog.h" |
14 #include "chrome/browser/ui/views/window.h" | 15 #include "chrome/browser/ui/views/window.h" |
15 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
16 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
17 #include "views/window/window.h" | 18 #include "views/window/window.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const int kFileManagerWidth = 720; // pixels | 22 const int kFileManagerWidth = 720; // pixels |
22 const int kFileManagerHeight = 580; // pixels | 23 const int kFileManagerHeight = 580; // pixels |
23 | 24 |
| 25 // Returns the browser represented by |window| or NULL if not found. |
| 26 // TODO(jamescook): Move this to browser_list.h. |
| 27 Browser* FindBrowserWithWindow(gfx::NativeWindow window) { |
| 28 for (BrowserList::const_iterator it = BrowserList::begin(); |
| 29 it != BrowserList::end(); |
| 30 ++it) { |
| 31 Browser* browser = *it; |
| 32 if (browser->window() && browser->window()->GetNativeHandle() == window) |
| 33 return browser; |
| 34 } |
| 35 return NULL; |
24 } | 36 } |
25 | 37 |
| 38 } // namespace |
| 39 |
26 // Linking this implementation of SelectFileDialog::Create into the target | 40 // Linking this implementation of SelectFileDialog::Create into the target |
27 // selects FileManagerDialog as the dialog of choice. | 41 // selects FileManagerDialog as the dialog of choice. |
28 // static | 42 // static |
29 SelectFileDialog* SelectFileDialog::Create(Listener* listener) { | 43 SelectFileDialog* SelectFileDialog::Create(Listener* listener) { |
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
31 return new FileManagerDialog(listener); | 45 return new FileManagerDialog(listener); |
32 } | 46 } |
33 | 47 |
34 ///////////////////////////////////////////////////////////////////////////// | 48 ///////////////////////////////////////////////////////////////////////////// |
35 | 49 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 const FilePath& default_path, | 87 const FilePath& default_path, |
74 const FileTypeInfo* file_types, | 88 const FileTypeInfo* file_types, |
75 int file_type_index, | 89 int file_type_index, |
76 const FilePath::StringType& default_extension, | 90 const FilePath::StringType& default_extension, |
77 gfx::NativeWindow owner_window, | 91 gfx::NativeWindow owner_window, |
78 void* params) { | 92 void* params) { |
79 if (owner_window_) { | 93 if (owner_window_) { |
80 LOG(ERROR) << "File dialog already in use!"; | 94 LOG(ERROR) << "File dialog already in use!"; |
81 return; | 95 return; |
82 } | 96 } |
83 Browser* active_browser = BrowserList::GetLastActive(); | 97 Browser* owner_browser = FindBrowserWithWindow(owner_window); |
84 if (!active_browser) | 98 if (!owner_browser) { |
| 99 NOTREACHED() << "Can't find owning browser"; |
85 return; | 100 return; |
| 101 } |
86 | 102 |
87 GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams( | 103 GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams( |
88 type, title, default_path, file_types, file_type_index, | 104 type, title, default_path, file_types, file_type_index, |
89 default_extension); | 105 default_extension); |
90 extension_dialog_ = ExtensionDialog::Show(file_browser_url, | 106 extension_dialog_ = ExtensionDialog::Show(file_browser_url, |
91 active_browser, kFileManagerWidth, kFileManagerHeight, | 107 owner_browser, kFileManagerWidth, kFileManagerHeight, |
92 this /* ExtensionDialog::Observer */); | 108 this /* ExtensionDialog::Observer */); |
93 | 109 |
94 // Connect our listener to FileDialogFunction's per-tab callbacks. | 110 // Connect our listener to FileDialogFunction's per-tab callbacks. |
95 Browser* extension_browser = extension_dialog_->host()->view()->browser(); | 111 TabContents* contents = owner_browser->GetSelectedTabContents(); |
96 TabContents* contents = extension_browser->GetSelectedTabContents(); | |
97 int32 tab_id = (contents ? contents->controller().session_id().id() : 0); | 112 int32 tab_id = (contents ? contents->controller().session_id().id() : 0); |
98 FileDialogFunction::Callback::Add(tab_id, listener_, params); | 113 FileDialogFunction::Callback::Add(tab_id, listener_, params); |
99 | 114 |
100 tab_id_ = tab_id; | 115 tab_id_ = tab_id; |
101 owner_window_ = owner_window; | 116 owner_window_ = owner_window; |
102 } | 117 } |
OLD | NEW |