OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/select_file_dialog_extension.h" | 5 #include "chrome/browser/ui/views/select_file_dialog_extension.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "chrome/browser/app_mode/app_mode_utils.h" | 14 #include "chrome/browser/app_mode/app_mode_utils.h" |
15 #include "chrome/browser/chromeos/file_manager/app_id.h" | 15 #include "chrome/browser/chromeos/file_manager/app_id.h" |
16 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 16 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
17 #include "chrome/browser/chromeos/file_manager/select_file_dialog_util.h" | 17 #include "chrome/browser/chromeos/file_manager/select_file_dialog_util.h" |
18 #include "chrome/browser/chromeos/file_manager/url_util.h" | 18 #include "chrome/browser/chromeos/file_manager/url_util.h" |
19 #include "chrome/browser/chromeos/login/ui/login_web_dialog.h" | 19 #include "chrome/browser/chromeos/login/ui/login_web_dialog.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/extension_view_host.h" | 21 #include "chrome/browser/extensions/extension_view_host.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/sessions/session_tab_helper.h" | 23 #include "chrome/browser/sessions/session_tab_helper.h" |
24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
26 #include "chrome/browser/ui/browser_list.h" | |
27 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
28 #include "chrome/browser/ui/chrome_select_file_policy.h" | 27 #include "chrome/browser/ui/chrome_select_file_policy.h" |
29 #include "chrome/browser/ui/host_desktop.h" | 28 #include "chrome/browser/ui/host_desktop.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
31 #include "chrome/browser/ui/views/extensions/extension_dialog.h" | 30 #include "chrome/browser/ui/views/extensions/extension_dialog.h" |
32 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
33 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
34 #include "extensions/browser/app_window/app_window.h" | 33 #include "extensions/browser/app_window/app_window.h" |
35 #include "extensions/browser/app_window/app_window_registry.h" | 34 #include "extensions/browser/app_window/app_window_registry.h" |
36 #include "extensions/browser/app_window/native_app_window.h" | 35 #include "extensions/browser/app_window/native_app_window.h" |
37 #include "extensions/browser/extension_system.h" | 36 #include "extensions/browser/extension_system.h" |
38 #include "ui/base/base_window.h" | 37 #include "ui/base/base_window.h" |
39 #include "ui/shell_dialogs/selected_file_info.h" | 38 #include "ui/shell_dialogs/selected_file_info.h" |
40 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
41 | 40 |
| 41 #if defined(USE_ATHENA) |
| 42 #include "chrome/browser/ui/views/athena/athena_util.h" |
| 43 #endif // USE_ATHENA |
| 44 |
42 using extensions::AppWindow; | 45 using extensions::AppWindow; |
43 using content::BrowserThread; | 46 using content::BrowserThread; |
44 | 47 |
45 namespace { | 48 namespace { |
46 | 49 |
47 const int kFileManagerWidth = 972; // pixels | 50 const int kFileManagerWidth = 972; // pixels |
48 const int kFileManagerHeight = 640; // pixels | 51 const int kFileManagerHeight = 640; // pixels |
49 const int kFileManagerMinimumWidth = 640; // pixels | 52 const int kFileManagerMinimumWidth = 640; // pixels |
50 const int kFileManagerMinimumHeight = 240; // pixels | 53 const int kFileManagerMinimumHeight = 240; // pixels |
51 | 54 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 89 } |
87 | 90 |
88 scoped_refptr<SelectFileDialogExtension> PendingDialog::Find( | 91 scoped_refptr<SelectFileDialogExtension> PendingDialog::Find( |
89 SelectFileDialogExtension::RoutingID id) { | 92 SelectFileDialogExtension::RoutingID id) { |
90 Map::const_iterator it = map_.find(id); | 93 Map::const_iterator it = map_.find(id); |
91 if (it == map_.end()) | 94 if (it == map_.end()) |
92 return NULL; | 95 return NULL; |
93 return it->second; | 96 return it->second; |
94 } | 97 } |
95 | 98 |
96 | 99 #if defined(USE_ATHENA) |
| 100 void FindRuntimeContext(gfx::NativeWindow owner_window, |
| 101 ui::BaseWindow** base_window, |
| 102 content::WebContents** web_contents) { |
| 103 *base_window = NULL; |
| 104 *web_contents = GetWebContentsForWindow(owner_window); |
| 105 } |
| 106 #else // USE_ATHENA |
97 // Given |owner_window| finds corresponding |base_window|, it's associated | 107 // Given |owner_window| finds corresponding |base_window|, it's associated |
98 // |web_contents| and |profile|. | 108 // |web_contents| and |profile|. |
99 void FindRuntimeContext( | 109 void FindRuntimeContext(gfx::NativeWindow owner_window, |
100 gfx::NativeWindow owner_window, | 110 ui::BaseWindow** base_window, |
101 ui::BaseWindow** base_window, | 111 content::WebContents** web_contents) { |
102 content::WebContents** web_contents, | |
103 Profile** profile) { | |
104 *base_window = NULL; | 112 *base_window = NULL; |
105 *web_contents = NULL; | 113 *web_contents = NULL; |
106 *profile = NULL; | 114 // To get the base_window and web contents, either a Browser or AppWindow is |
107 // To get the base_window and profile, either a Browser or AppWindow is | |
108 // needed. | 115 // needed. |
109 Browser* owner_browser = NULL; | 116 Browser* owner_browser = NULL; |
110 AppWindow* app_window = NULL; | 117 AppWindow* app_window = NULL; |
111 | 118 |
112 // If owner_window is supplied, use that to find a browser or a app window. | 119 // If owner_window is supplied, use that to find a browser or a app window. |
113 if (owner_window) { | 120 if (owner_window) { |
114 owner_browser = chrome::FindBrowserWithWindow(owner_window); | 121 owner_browser = chrome::FindBrowserWithWindow(owner_window); |
115 if (!owner_browser) { | 122 if (!owner_browser) { |
116 // If an owner_window was supplied but we couldn't find a browser, this | 123 // If an owner_window was supplied but we couldn't find a browser, this |
117 // could be for a app window. | 124 // could be for a app window. |
(...skipping 20 matching lines...) Expand all Loading... |
138 } | 145 } |
139 } | 146 } |
140 | 147 |
141 // In ChromeOS kiosk launch mode, we can still show file picker for | 148 // In ChromeOS kiosk launch mode, we can still show file picker for |
142 // certificate manager dialog. There are no browser or webapp window | 149 // certificate manager dialog. There are no browser or webapp window |
143 // instances present in this case. | 150 // instances present in this case. |
144 if (chrome::IsRunningInForcedAppMode() && !(*web_contents)) | 151 if (chrome::IsRunningInForcedAppMode() && !(*web_contents)) |
145 *web_contents = chromeos::LoginWebDialog::GetCurrentWebContents(); | 152 *web_contents = chromeos::LoginWebDialog::GetCurrentWebContents(); |
146 | 153 |
147 CHECK(web_contents); | 154 CHECK(web_contents); |
148 *profile = Profile::FromBrowserContext((*web_contents)->GetBrowserContext()); | |
149 } | 155 } |
| 156 #endif // USE_ATHENA |
150 | 157 |
151 } // namespace | 158 } // namespace |
152 | 159 |
153 ///////////////////////////////////////////////////////////////////////////// | 160 ///////////////////////////////////////////////////////////////////////////// |
154 | 161 |
155 // static | 162 // static |
156 SelectFileDialogExtension::RoutingID | 163 SelectFileDialogExtension::RoutingID |
157 SelectFileDialogExtension::GetRoutingIDFromWebContents( | 164 SelectFileDialogExtension::GetRoutingIDFromWebContents( |
158 const content::WebContents* web_contents) { | 165 const content::WebContents* web_contents) { |
159 // Use the raw pointer value as the identifier. Previously we have used the | 166 // Use the raw pointer value as the identifier. Previously we have used the |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 if (owner_window_) { | 335 if (owner_window_) { |
329 LOG(ERROR) << "File dialog already in use!"; | 336 LOG(ERROR) << "File dialog already in use!"; |
330 return; | 337 return; |
331 } | 338 } |
332 | 339 |
333 // The base window to associate the dialog with. | 340 // The base window to associate the dialog with. |
334 ui::BaseWindow* base_window = NULL; | 341 ui::BaseWindow* base_window = NULL; |
335 | 342 |
336 // The web contents to associate the dialog with. | 343 // The web contents to associate the dialog with. |
337 content::WebContents* web_contents = NULL; | 344 content::WebContents* web_contents = NULL; |
338 | 345 FindRuntimeContext(owner_window, &base_window, &web_contents); |
339 FindRuntimeContext(owner_window, &base_window, &web_contents, &profile_); | 346 CHECK(web_contents); |
| 347 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
340 CHECK(profile_); | 348 CHECK(profile_); |
341 | 349 |
342 // Check if we have another dialog opened for the contents. It's unlikely, but | 350 // Check if we have another dialog opened for the contents. It's unlikely, but |
343 // possible. In such situation, discard this request. | 351 // possible. In such situation, discard this request. |
344 RoutingID routing_id = GetRoutingIDFromWebContents(web_contents); | 352 RoutingID routing_id = GetRoutingIDFromWebContents(web_contents); |
345 if (PendingExists(routing_id)) | 353 if (PendingExists(routing_id)) |
346 return; | 354 return; |
347 | 355 |
348 const PrefService* pref_service = profile_->GetPrefs(); | 356 const PrefService* pref_service = profile_->GetPrefs(); |
349 DCHECK(pref_service); | 357 DCHECK(pref_service); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 } | 434 } |
427 | 435 |
428 // Connect our listener to FileDialogFunction's per-tab callbacks. | 436 // Connect our listener to FileDialogFunction's per-tab callbacks. |
429 AddPending(routing_id); | 437 AddPending(routing_id); |
430 | 438 |
431 extension_dialog_ = dialog; | 439 extension_dialog_ = dialog; |
432 params_ = params; | 440 params_ = params; |
433 routing_id_ = routing_id; | 441 routing_id_ = routing_id; |
434 owner_window_ = owner_window; | 442 owner_window_ = owner_window; |
435 } | 443 } |
OLD | NEW |