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

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

Issue 6680002: Pull the file picker code out of TabContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forgot the DISALLOW Created 9 years, 9 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) 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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/platform_util.h" 13 #include "chrome/browser/platform_util.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/render_messages.h"
15 #include "chrome/common/render_messages_params.h" 16 #include "chrome/common/render_messages_params.h"
16 #include "content/browser/renderer_host/render_view_host.h" 17 #include "content/browser/renderer_host/render_view_host.h"
17 #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"
18 #include "content/common/notification_details.h" 20 #include "content/common/notification_details.h"
19 #include "content/common/notification_source.h" 21 #include "content/common/notification_source.h"
20 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
21 #include "net/base/mime_util.h" 23 #include "net/base/mime_util.h"
22 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
23 25
24 FileSelectHelper::FileSelectHelper(Profile* profile) 26 FileSelectHelper::FileSelectHelper(Profile* profile)
25 : profile_(profile), 27 : profile_(profile),
26 render_view_host_(NULL), 28 render_view_host_(NULL),
27 select_file_dialog_(), 29 select_file_dialog_(),
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (description_id) { 187 if (description_id) {
186 file_type->extension_description_overrides.push_back( 188 file_type->extension_description_overrides.push_back(
187 l10n_util::GetStringUTF16(description_id)); 189 l10n_util::GetStringUTF16(description_id));
188 } 190 }
189 191
190 return file_type.release(); 192 return file_type.release();
191 } 193 }
192 194
193 void FileSelectHelper::RunFileChooser( 195 void FileSelectHelper::RunFileChooser(
194 RenderViewHost* render_view_host, 196 RenderViewHost* render_view_host,
195 const ViewHostMsg_RunFileChooser_Params &params) { 197 const ViewHostMsg_RunFileChooser_Params& params) {
196 DCHECK(!render_view_host_); 198 DCHECK(!render_view_host_);
197 render_view_host_ = render_view_host; 199 render_view_host_ = render_view_host;
198 notification_registrar_.RemoveAll(); 200 notification_registrar_.RemoveAll();
199 notification_registrar_.Add(this, 201 notification_registrar_.Add(this,
200 NotificationType::RENDER_WIDGET_HOST_DESTROYED, 202 NotificationType::RENDER_WIDGET_HOST_DESTROYED,
201 Source<RenderViewHost>(render_view_host)); 203 Source<RenderViewHost>(render_view_host));
202 204
203 if (!select_file_dialog_.get()) 205 if (!select_file_dialog_.get())
204 select_file_dialog_ = SelectFileDialog::Create(this); 206 select_file_dialog_ = SelectFileDialog::Create(this);
205 207
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 NULL); 240 NULL);
239 } 241 }
240 242
241 void FileSelectHelper::Observe(NotificationType type, 243 void FileSelectHelper::Observe(NotificationType type,
242 const NotificationSource& source, 244 const NotificationSource& source,
243 const NotificationDetails& details) { 245 const NotificationDetails& details) {
244 DCHECK(type == NotificationType::RENDER_WIDGET_HOST_DESTROYED); 246 DCHECK(type == NotificationType::RENDER_WIDGET_HOST_DESTROYED);
245 DCHECK(Details<RenderViewHost>(details).ptr() == render_view_host_); 247 DCHECK(Details<RenderViewHost>(details).ptr() == render_view_host_);
246 render_view_host_ = NULL; 248 render_view_host_ = NULL;
247 } 249 }
250
251 FileSelectObserver::FileSelectObserver(TabContents* tab_contents)
252 : TabContentsObserver(tab_contents) {
253 }
254
255 FileSelectObserver::~FileSelectObserver() {
256 }
257
258 bool FileSelectObserver::OnMessageReceived(const IPC::Message& message) {
259 bool handled = true;
260 IPC_BEGIN_MESSAGE_MAP(FileSelectObserver, message)
261 IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser)
262 IPC_MESSAGE_UNHANDLED(handled = false)
263 IPC_END_MESSAGE_MAP()
264
265 return handled;
266 }
267
268 void FileSelectObserver::OnRunFileChooser(
269 const ViewHostMsg_RunFileChooser_Params& params) {
270 if (file_select_helper_.get() == NULL)
jam 2011/03/11 17:03:58 nit: usual style is to drop the "== NULL"
Avi (use Gerrit) 2011/03/11 17:24:41 Done.
271 file_select_helper_.reset(new FileSelectHelper(tab_contents()->profile()));
272 file_select_helper_->RunFileChooser(tab_contents()->render_view_host(),
273 params);
274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698