Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/ui/views/select_file_dialog_extension.cc

Issue 11222003: Remove TabContents creation from ShellWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const fix Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 12 #include "base/message_loop.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" 15 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h"
16 #include "chrome/browser/chromeos/extensions/file_manager_util.h" 16 #include "chrome/browser/chromeos/extensions/file_manager_util.h"
17 #include "chrome/browser/extensions/extension_host.h" 17 #include "chrome/browser/extensions/extension_host.h"
18 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/extensions/shell_window_registry.h" 19 #include "chrome/browser/extensions/shell_window_registry.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/sessions/session_tab_helper.h" 21 #include "chrome/browser/sessions/session_tab_helper.h"
22 #include "chrome/browser/ui/base_window.h" 22 #include "chrome/browser/ui/base_window.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_finder.h" 24 #include "chrome/browser/ui/browser_finder.h"
25 #include "chrome/browser/ui/browser_list.h" 25 #include "chrome/browser/ui/browser_list.h"
26 #include "chrome/browser/ui/browser_tabstrip.h" 26 #include "chrome/browser/ui/browser_tabstrip.h"
27 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/chrome_select_file_policy.h" 28 #include "chrome/browser/ui/chrome_select_file_policy.h"
29 #include "chrome/browser/ui/extensions/shell_window.h" 29 #include "chrome/browser/ui/extensions/shell_window.h"
30 #include "chrome/browser/ui/tab_contents/tab_contents.h"
31 #include "chrome/browser/ui/views/extensions/extension_dialog.h" 30 #include "chrome/browser/ui/views/extensions/extension_dialog.h"
32 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
33 #include "ui/base/dialogs/selected_file_info.h" 32 #include "ui/base/dialogs/selected_file_info.h"
34 33
35 using content::BrowserThread; 34 using content::BrowserThread;
36 35
37 namespace { 36 namespace {
38 37
39 const int kFileManagerWidth = 954; // pixels 38 const int kFileManagerWidth = 954; // pixels
40 const int kFileManagerHeight = 640; // pixels 39 const int kFileManagerHeight = 640; // pixels
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 gfx::NativeWindow owner_window, 248 gfx::NativeWindow owner_window,
250 void* params) { 249 void* params) {
251 if (owner_window_) { 250 if (owner_window_) {
252 LOG(ERROR) << "File dialog already in use!"; 251 LOG(ERROR) << "File dialog already in use!";
253 return; 252 return;
254 } 253 }
255 254
256 // The base window to associate the dialog with. 255 // The base window to associate the dialog with.
257 BaseWindow* base_window = NULL; 256 BaseWindow* base_window = NULL;
258 257
259 // The tab contents to associate the dialog with. 258 // The web contents to associate the dialog with.
260 const TabContents* tab = NULL; 259 content::WebContents* web_contents = NULL;
261 260
262 // First try to find a Browser using the supplied owner_window. If no owner 261 // First try to find a Browser using the supplied owner_window. If no owner
263 // window has been supplied, this is running from a background page and should 262 // window has been supplied, this is running from a background page and should
264 // be associated with the last active browser. 263 // be associated with the last active browser.
265 Browser* owner_browser = (owner_window ? 264 Browser* owner_browser = owner_window ?
266 browser::FindBrowserWithWindow(owner_window) : 265 browser::FindBrowserWithWindow(owner_window) :
267 BrowserList::GetLastActive()); 266 BrowserList::GetLastActive();
268 if (owner_browser) { 267 if (owner_browser) {
269 base_window = owner_browser->window(); 268 base_window = owner_browser->window();
270 tab = chrome::GetActiveTabContents(owner_browser); 269 web_contents = chrome::GetActiveWebContents(owner_browser);
271 profile_ = tab->profile(); 270 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext());
272 } else if (owner_window) { 271 } else if (owner_window) {
273 // If an owner_window was supplied but we couldn't find a browser, this 272 // If an owner_window was supplied but we couldn't find a browser, this
274 // could be for a shell window. 273 // could be for a shell window.
275 // TODO(benwells): Find a better way to get a shell window from a native 274 // TODO(benwells): Find a better way to get a shell window from a native
276 // window. 275 // window.
277 std::vector<Profile*> profiles = 276 std::vector<Profile*> profiles =
278 g_browser_process->profile_manager()->GetLoadedProfiles(); 277 g_browser_process->profile_manager()->GetLoadedProfiles();
279 for (std::vector<Profile*>::const_iterator i(profiles.begin()); 278 for (std::vector<Profile*>::const_iterator i(profiles.begin());
280 i < profiles.end(); ++i) { 279 i < profiles.end(); ++i) {
281 extensions::ShellWindowRegistry* registry = 280 extensions::ShellWindowRegistry* registry =
282 extensions::ShellWindowRegistry::Get(*i); 281 extensions::ShellWindowRegistry::Get(*i);
283 DCHECK(registry); 282 DCHECK(registry);
284 ShellWindow* shell_window = registry->GetShellWindowForNativeWindow( 283 ShellWindow* shell_window = registry->GetShellWindowForNativeWindow(
285 owner_window); 284 owner_window);
286 if (shell_window) { 285 if (shell_window) {
287 base_window = shell_window->GetBaseWindow(); 286 base_window = shell_window->GetBaseWindow();
288 tab = shell_window->tab_contents(); 287 web_contents = shell_window->web_contents();
289 profile_ = *i; 288 profile_ = *i;
290 break; 289 break;
291 } 290 }
292 } 291 }
293 } 292 }
294 293
295 if (!base_window) { 294 if (!base_window) {
296 NOTREACHED() << "Can't find owning window."; 295 NOTREACHED() << "Can't find owning window.";
297 return; 296 return;
298 } 297 }
299 DCHECK(profile_); 298 DCHECK(profile_);
300 299
301 // Check if we have another dialog opened in the tab. It's unlikely, but 300 // Check if we have another dialog opened for the contents. It's unlikely, but
302 // possible. If there is no tab contents use a tab_id of 0. A dialog without 301 // possible. If there is no web contents use a tab_id of -1. A dialog without
303 // an associated tab contents will be shown fully screen; only one at a time 302 // an associated web contents will be shown full-screen; only one at a time
304 // is allowed in this state. 303 // is allowed in this state.
305 int32 tab_id = tab ? SessionTabHelper::FromWebContents(tab->web_contents())-> 304 int32 tab_id = SessionID::IdForTab(web_contents);
306 session_id().id()
307 : 0;
308 if (PendingExists(tab_id)) { 305 if (PendingExists(tab_id)) {
309 DLOG(WARNING) << "Pending dialog exists with id " << tab_id; 306 DLOG(WARNING) << "Pending dialog exists with id " << tab_id;
310 return; 307 return;
311 } 308 }
312 309
313 FilePath default_dialog_path; 310 FilePath default_dialog_path;
314 311
315 const PrefService* pref_service = profile_->GetPrefs(); 312 const PrefService* pref_service = profile_->GetPrefs();
316 313
317 if (default_path.empty() && pref_service) { 314 if (default_path.empty() && pref_service) {
(...skipping 12 matching lines...) Expand all
330 } 327 }
331 328
332 has_multiple_file_type_choices_ = 329 has_multiple_file_type_choices_ =
333 file_types ? file_types->extensions.size() > 1 : true; 330 file_types ? file_types->extensions.size() > 1 : true;
334 331
335 GURL file_browser_url = file_manager_util::GetFileBrowserUrlWithParams( 332 GURL file_browser_url = file_manager_util::GetFileBrowserUrlWithParams(
336 type, title, virtual_path, file_types, file_type_index, 333 type, title, virtual_path, file_types, file_type_index,
337 default_extension); 334 default_extension);
338 335
339 ExtensionDialog* dialog = ExtensionDialog::Show(file_browser_url, 336 ExtensionDialog* dialog = ExtensionDialog::Show(file_browser_url,
340 base_window, profile_, tab->web_contents(), 337 base_window, profile_, web_contents,
341 kFileManagerWidth, kFileManagerHeight, 338 kFileManagerWidth, kFileManagerHeight,
342 #if defined(USE_AURA) 339 #if defined(USE_AURA)
343 file_manager_util::GetTitleFromType(type), 340 file_manager_util::GetTitleFromType(type),
344 #else 341 #else
345 // HTML-based header used. 342 // HTML-based header used.
346 string16(), 343 string16(),
347 #endif 344 #endif
348 this /* ExtensionDialog::Observer */); 345 this /* ExtensionDialog::Observer */);
349 if (!dialog) { 346 if (!dialog) {
350 LOG(ERROR) << "Unable to create extension dialog"; 347 LOG(ERROR) << "Unable to create extension dialog";
351 return; 348 return;
352 } 349 }
353 350
354 dialog->SetMinimumContentsSize(kFileManagerMinimumWidth, 351 dialog->SetMinimumContentsSize(kFileManagerMinimumWidth,
355 kFileManagerMinimumHeight); 352 kFileManagerMinimumHeight);
356 353
357 // Connect our listener to FileDialogFunction's per-tab callbacks. 354 // Connect our listener to FileDialogFunction's per-tab callbacks.
358 AddPending(tab_id); 355 AddPending(tab_id);
359 356
360 extension_dialog_ = dialog; 357 extension_dialog_ = dialog;
361 params_ = params; 358 params_ = params;
362 tab_id_ = tab_id; 359 tab_id_ = tab_id;
363 owner_window_ = owner_window; 360 owner_window_ = owner_window;
364 } 361 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698