Chromium Code Reviews| 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. | |
|
achuithb
2011/06/10 22:09:40
Add a TODO to move this code to browser_list.h whi
| |
| 26 Browser* FindBrowserWithWindow(gfx::NativeWindow window) { | |
| 27 for (BrowserList::const_iterator it = BrowserList::begin(); | |
| 28 it != BrowserList::end(); | |
| 29 ++it) { | |
| 30 Browser* browser = *it; | |
| 31 if (browser->window() && browser->window()->GetNativeHandle() == window) | |
| 32 return browser; | |
| 33 } | |
| 34 return NULL; | |
| 24 } | 35 } |
| 25 | 36 |
| 37 } // namespace | |
| 38 | |
| 26 // Linking this implementation of SelectFileDialog::Create into the target | 39 // Linking this implementation of SelectFileDialog::Create into the target |
| 27 // selects FileManagerDialog as the dialog of choice. | 40 // selects FileManagerDialog as the dialog of choice. |
| 28 // static | 41 // static |
| 29 SelectFileDialog* SelectFileDialog::Create(Listener* listener) { | 42 SelectFileDialog* SelectFileDialog::Create(Listener* listener) { |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 31 return new FileManagerDialog(listener); | 44 return new FileManagerDialog(listener); |
| 32 } | 45 } |
| 33 | 46 |
| 34 ///////////////////////////////////////////////////////////////////////////// | 47 ///////////////////////////////////////////////////////////////////////////// |
| 35 | 48 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 const FilePath& default_path, | 86 const FilePath& default_path, |
| 74 const FileTypeInfo* file_types, | 87 const FileTypeInfo* file_types, |
| 75 int file_type_index, | 88 int file_type_index, |
| 76 const FilePath::StringType& default_extension, | 89 const FilePath::StringType& default_extension, |
| 77 gfx::NativeWindow owner_window, | 90 gfx::NativeWindow owner_window, |
| 78 void* params) { | 91 void* params) { |
| 79 if (owner_window_) { | 92 if (owner_window_) { |
| 80 LOG(ERROR) << "File dialog already in use!"; | 93 LOG(ERROR) << "File dialog already in use!"; |
| 81 return; | 94 return; |
| 82 } | 95 } |
| 83 Browser* active_browser = BrowserList::GetLastActive(); | 96 Browser* owner_browser = FindBrowserWithWindow(owner_window); |
| 84 if (!active_browser) | 97 if (!owner_browser) { |
|
achuithb
2011/06/10 22:09:40
A DCHECK is probably appropriate here.
| |
| 98 LOG(WARNING) << "Can't find owning browser"; | |
| 85 return; | 99 return; |
| 100 } | |
| 86 | 101 |
| 87 GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams( | 102 GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams( |
| 88 type, title, default_path, file_types, file_type_index, | 103 type, title, default_path, file_types, file_type_index, |
| 89 default_extension); | 104 default_extension); |
| 90 extension_dialog_ = ExtensionDialog::Show(file_browser_url, | 105 extension_dialog_ = ExtensionDialog::Show(file_browser_url, |
| 91 active_browser, kFileManagerWidth, kFileManagerHeight, | 106 owner_browser, kFileManagerWidth, kFileManagerHeight, |
| 92 this /* ExtensionDialog::Observer */); | 107 this /* ExtensionDialog::Observer */); |
| 93 | 108 |
| 94 // Connect our listener to FileDialogFunction's per-tab callbacks. | 109 // Connect our listener to FileDialogFunction's per-tab callbacks. |
| 95 Browser* extension_browser = extension_dialog_->host()->view()->browser(); | 110 TabContents* contents = owner_browser->GetSelectedTabContents(); |
| 96 TabContents* contents = extension_browser->GetSelectedTabContents(); | |
| 97 int32 tab_id = (contents ? contents->controller().session_id().id() : 0); | 111 int32 tab_id = (contents ? contents->controller().session_id().id() : 0); |
| 98 FileDialogFunction::Callback::Add(tab_id, listener_, params); | 112 FileDialogFunction::Callback::Add(tab_id, listener_, params); |
| 99 | 113 |
| 100 tab_id_ = tab_id; | 114 tab_id_ = tab_id; |
| 101 owner_window_ = owner_window; | 115 owner_window_ = owner_window; |
| 102 } | 116 } |
| OLD | NEW |