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

Side by Side Diff: chrome/browser/file_select_helper.cc

Issue 8622005: Get rid of view_messages.h include from chrome since TabContentsDelegate used a struct from it (V... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/file_select_helper.h ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_select_helper.h" 5 #include "chrome/browser/file_select_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/platform_file.h" 11 #include "base/platform_file.h"
12 #include "base/string_split.h" 12 #include "base/string_split.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/platform_util.h" 15 #include "chrome/browser/platform_util.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "content/browser/renderer_host/render_view_host.h" 17 #include "content/browser/renderer_host/render_view_host.h"
18 #include "content/browser/renderer_host/render_widget_host_view.h" 18 #include "content/browser/renderer_host/render_widget_host_view.h"
19 #include "content/browser/tab_contents/tab_contents.h" 19 #include "content/browser/tab_contents/tab_contents.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
22 #include "content/common/view_messages.h"
23 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
25 #include "content/public/browser/notification_types.h" 24 #include "content/public/browser/notification_types.h"
25 #include "content/public/common/file_chooser_params.h"
26 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 #include "net/base/mime_util.h" 27 #include "net/base/mime_util.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 31
32 namespace { 32 namespace {
33 33
34 // There is only one file-selection happening at any given time, 34 // There is only one file-selection happening at any given time,
35 // so we allocate an enumeration ID for that purpose. All IDs from 35 // so we allocate an enumeration ID for that purpose. All IDs from
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 file_type->extension_description_overrides.push_back( 257 file_type->extension_description_overrides.push_back(
258 l10n_util::GetStringUTF16(description_id)); 258 l10n_util::GetStringUTF16(description_id));
259 } 259 }
260 260
261 return file_type.release(); 261 return file_type.release();
262 } 262 }
263 263
264 void FileSelectHelper::RunFileChooser( 264 void FileSelectHelper::RunFileChooser(
265 RenderViewHost* render_view_host, 265 RenderViewHost* render_view_host,
266 TabContents* tab_contents, 266 TabContents* tab_contents,
267 const ViewHostMsg_RunFileChooser_Params& params) { 267 const content::FileChooserParams& params) {
268 DCHECK(!render_view_host_); 268 DCHECK(!render_view_host_);
269 DCHECK(!tab_contents_); 269 DCHECK(!tab_contents_);
270 render_view_host_ = render_view_host; 270 render_view_host_ = render_view_host;
271 tab_contents_ = tab_contents; 271 tab_contents_ = tab_contents;
272 notification_registrar_.RemoveAll(); 272 notification_registrar_.RemoveAll();
273 notification_registrar_.Add( 273 notification_registrar_.Add(
274 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 274 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
275 content::Source<RenderWidgetHost>(render_view_host_)); 275 content::Source<RenderWidgetHost>(render_view_host_));
276 notification_registrar_.Add( 276 notification_registrar_.Add(
277 this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, 277 this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
278 content::Source<TabContents>(tab_contents_)); 278 content::Source<TabContents>(tab_contents_));
279 279
280 BrowserThread::PostTask( 280 BrowserThread::PostTask(
281 BrowserThread::FILE, FROM_HERE, 281 BrowserThread::FILE, FROM_HERE,
282 base::Bind(&FileSelectHelper::RunFileChooserOnFileThread, this, params)); 282 base::Bind(&FileSelectHelper::RunFileChooserOnFileThread, this, params));
283 283
284 // Because this class returns notifications to the RenderViewHost, it is 284 // Because this class returns notifications to the RenderViewHost, it is
285 // difficult for callers to know how long to keep a reference to this 285 // difficult for callers to know how long to keep a reference to this
286 // instance. We AddRef() here to keep the instance alive after we return 286 // instance. We AddRef() here to keep the instance alive after we return
287 // to the caller, until the last callback is received from the file dialog. 287 // to the caller, until the last callback is received from the file dialog.
288 // At that point, we must call RunFileChooserEnd(). 288 // At that point, we must call RunFileChooserEnd().
289 AddRef(); 289 AddRef();
290 } 290 }
291 291
292 void FileSelectHelper::RunFileChooserOnFileThread( 292 void FileSelectHelper::RunFileChooserOnFileThread(
293 const ViewHostMsg_RunFileChooser_Params& params) { 293 const content::FileChooserParams& params) {
294 select_file_types_.reset( 294 select_file_types_.reset(
295 GetFileTypesFromAcceptType(params.accept_types)); 295 GetFileTypesFromAcceptType(params.accept_types));
296 296
297 BrowserThread::PostTask( 297 BrowserThread::PostTask(
298 BrowserThread::UI, FROM_HERE, 298 BrowserThread::UI, FROM_HERE,
299 base::Bind(&FileSelectHelper::RunFileChooserOnUIThread, this, params)); 299 base::Bind(&FileSelectHelper::RunFileChooserOnUIThread, this, params));
300 } 300 }
301 301
302 void FileSelectHelper::RunFileChooserOnUIThread( 302 void FileSelectHelper::RunFileChooserOnUIThread(
303 const ViewHostMsg_RunFileChooser_Params& params) { 303 const content::FileChooserParams& params) {
304 if (!render_view_host_ || !tab_contents_) 304 if (!render_view_host_ || !tab_contents_)
305 return; 305 return;
306 306
307 if (!select_file_dialog_.get()) 307 if (!select_file_dialog_.get())
308 select_file_dialog_ = SelectFileDialog::Create(this); 308 select_file_dialog_ = SelectFileDialog::Create(this);
309 309
310 switch (params.mode) { 310 switch (params.mode) {
311 case ViewHostMsg_RunFileChooser_Mode::Open: 311 case content::FileChooserParams::Open:
312 dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; 312 dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE;
313 break; 313 break;
314 case ViewHostMsg_RunFileChooser_Mode::OpenMultiple: 314 case content::FileChooserParams::OpenMultiple:
315 dialog_type_ = SelectFileDialog::SELECT_OPEN_MULTI_FILE; 315 dialog_type_ = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
316 break; 316 break;
317 case ViewHostMsg_RunFileChooser_Mode::OpenFolder: 317 case content::FileChooserParams::OpenFolder:
318 dialog_type_ = SelectFileDialog::SELECT_FOLDER; 318 dialog_type_ = SelectFileDialog::SELECT_FOLDER;
319 break; 319 break;
320 case ViewHostMsg_RunFileChooser_Mode::Save: 320 case content::FileChooserParams::Save:
321 dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; 321 dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE;
322 break; 322 break;
323 default: 323 default:
324 dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning. 324 dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning.
325 NOTREACHED(); 325 NOTREACHED();
326 } 326 }
327 FilePath default_file_name = params.default_file_name; 327 FilePath default_file_name = params.default_file_name;
328 if (default_file_name.empty()) 328 if (default_file_name.empty())
329 default_file_name = profile_->last_selected_directory(); 329 default_file_name = profile_->last_selected_directory();
330 330
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 DCHECK(content::Source<TabContents>(source).ptr() == tab_contents_); 390 DCHECK(content::Source<TabContents>(source).ptr() == tab_contents_);
391 tab_contents_ = NULL; 391 tab_contents_ = NULL;
392 break; 392 break;
393 } 393 }
394 394
395 default: 395 default:
396 NOTREACHED(); 396 NOTREACHED();
397 } 397 }
398 } 398 }
399 399
OLDNEW
« no previous file with comments | « chrome/browser/file_select_helper.h ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698