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 "base/json/json_writer.h" | 5 #include "base/json/json_writer.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/extension_file_browser_private_api.h" | 10 #include "chrome/browser/extensions/extension_file_browser_private_api.h" |
| 11 #include "chrome/browser/metrics/user_metrics.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_dialogs.h" | 14 #include "chrome/browser/ui/browser_dialogs.h" |
14 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
15 #include "chrome/browser/ui/shell_dialogs.h" | 16 #include "chrome/browser/ui/shell_dialogs.h" |
16 #include "chrome/browser/ui/views/html_dialog_view.h" | 17 #include "chrome/browser/ui/views/html_dialog_view.h" |
17 #include "chrome/browser/ui/views/window.h" | 18 #include "chrome/browser/ui/views/window.h" |
18 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 19 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
19 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "third_party/libjingle/source/talk/base/urlencode.h" | 22 #include "third_party/libjingle/source/talk/base/urlencode.h" |
22 #include "views/window/window.h" | 23 #include "views/window/window.h" |
23 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
24 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
25 | 26 |
26 // Shows a dialog box for selecting a file or a folder. | 27 // Shows a dialog box for selecting a file or a folder. |
27 class FileManagerDialog | 28 class FileManagerDialog |
28 : public SelectFileDialog, | 29 : public SelectFileDialog, |
29 public HtmlDialogUIDelegate { | 30 public HtmlDialogUIDelegate { |
30 | 31 |
31 public: | 32 public: |
32 explicit FileManagerDialog(Listener* listener); | 33 explicit FileManagerDialog(Listener* listener); |
33 | 34 |
34 // Helper to convert numeric dialog type to a string. | 35 // Helper to convert numeric dialog type to a string. |
35 static std::string GetDialogTypeAsString(Type dialog_type); | 36 static std::string GetDialogTypeAsString(Type dialog_type); |
36 | 37 |
| 38 static void ShowFullTabUrl(Profile* profile, |
| 39 const FilePath& default_path); |
| 40 |
37 // Help to convert potential dialog arguments into json. | 41 // Help to convert potential dialog arguments into json. |
38 static std::string GetArgumentsJson( | 42 static std::string GetArgumentsJson( |
39 Type type, | 43 Type type, |
40 const string16& title, | 44 const string16& title, |
41 const FilePath& default_path, | 45 const FilePath& default_path, |
42 const FileTypeInfo* file_types, | 46 const FileTypeInfo* file_types, |
43 int file_type_index, | 47 int file_type_index, |
44 const FilePath::StringType& default_extension); | 48 const FilePath::StringType& default_extension); |
45 | 49 |
46 void CreateHtmlDialogView(Profile* profile, void* params) { | 50 void CreateHtmlDialogView(Profile* profile, void* params) { |
(...skipping 12 matching lines...) Expand all Loading... |
59 virtual bool IsRunning(gfx::NativeWindow owner_window) const { | 63 virtual bool IsRunning(gfx::NativeWindow owner_window) const { |
60 return owner_window_ == owner_window; | 64 return owner_window_ == owner_window; |
61 } | 65 } |
62 | 66 |
63 virtual void ListenerDestroyed() { | 67 virtual void ListenerDestroyed() { |
64 listener_ = NULL; | 68 listener_ = NULL; |
65 FileDialogFunction::Callback::Remove(tab_id_); | 69 FileDialogFunction::Callback::Remove(tab_id_); |
66 } | 70 } |
67 | 71 |
68 // SelectFileDialog implementation. | 72 // SelectFileDialog implementation. |
69 | |
70 virtual void SelectFile(Type type, | 73 virtual void SelectFile(Type type, |
71 const string16& title, | 74 const string16& title, |
72 const FilePath& default_path, | 75 const FilePath& default_path, |
73 const FileTypeInfo* file_types, | 76 const FileTypeInfo* file_types, |
74 int file_type_index, | 77 int file_type_index, |
75 const FilePath::StringType& default_extension, | 78 const FilePath::StringType& default_extension, |
76 gfx::NativeWindow owning_window, | 79 gfx::NativeWindow owning_window, |
77 void* params); | 80 void* params); |
78 | 81 |
79 virtual void set_browser_mode(bool value) { | 82 virtual void set_browser_mode(bool value) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 std::string FileManagerDialog::s_extension_base_url_ = | 173 std::string FileManagerDialog::s_extension_base_url_ = |
171 "chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/main.html"; | 174 "chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/main.html"; |
172 | 175 |
173 FileManagerDialog::FileManagerDialog(Listener* listener) | 176 FileManagerDialog::FileManagerDialog(Listener* listener) |
174 : tab_id_(0), | 177 : tab_id_(0), |
175 browser_mode_(true), | 178 browser_mode_(true), |
176 owner_window_(0) { | 179 owner_window_(0) { |
177 listener_ = listener; | 180 listener_ = listener; |
178 } | 181 } |
179 | 182 |
| 183 void FileManagerDialog::ShowFullTabUrl(Profile* profile, |
| 184 const FilePath& default_path) { |
| 185 std::string json = GetArgumentsJson(SELECT_NONE, string16(), default_path, |
| 186 NULL, 0, FilePath::StringType()); |
| 187 GURL url(s_extension_base_url_ + "?" + |
| 188 UrlEncodeStringWithoutEncodingSpaceAsPlus(json)); |
| 189 Browser* browser = BrowserList::GetLastActive(); |
| 190 if (!browser) |
| 191 return; |
| 192 |
| 193 UserMetrics::RecordAction(UserMetricsAction("ShowFileBrowserFullTab"), |
| 194 profile); |
| 195 browser->ShowSingletonTab(GURL(url)); |
| 196 } |
| 197 |
180 void FileManagerDialog::SelectFile( | 198 void FileManagerDialog::SelectFile( |
181 Type type, | 199 Type type, |
182 const string16& title, | 200 const string16& title, |
183 const FilePath& default_path, | 201 const FilePath& default_path, |
184 const FileTypeInfo* file_types, | 202 const FileTypeInfo* file_types, |
185 int file_type_index, | 203 int file_type_index, |
186 const FilePath::StringType& default_extension, | 204 const FilePath::StringType& default_extension, |
187 gfx::NativeWindow owner_window, | 205 gfx::NativeWindow owner_window, |
188 void* params) { | 206 void* params) { |
189 | 207 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 std::string FileManagerDialog::GetArgumentsJson( | 270 std::string FileManagerDialog::GetArgumentsJson( |
253 Type type, | 271 Type type, |
254 const string16& title, | 272 const string16& title, |
255 const FilePath& default_path, | 273 const FilePath& default_path, |
256 const FileTypeInfo* file_types, | 274 const FileTypeInfo* file_types, |
257 int file_type_index, | 275 int file_type_index, |
258 const FilePath::StringType& default_extension) { | 276 const FilePath::StringType& default_extension) { |
259 DictionaryValue arg_value; | 277 DictionaryValue arg_value; |
260 arg_value.SetString("type", GetDialogTypeAsString(type)); | 278 arg_value.SetString("type", GetDialogTypeAsString(type)); |
261 arg_value.SetString("title", title); | 279 arg_value.SetString("title", title); |
| 280 // TODO(zelidrag): Convert local system path into virtual path for File API. |
262 arg_value.SetString("defaultPath", default_path.value()); | 281 arg_value.SetString("defaultPath", default_path.value()); |
263 arg_value.SetString("defaultExtension", default_extension); | 282 arg_value.SetString("defaultExtension", default_extension); |
264 | 283 |
265 ListValue* types_list = new ListValue(); | 284 ListValue* types_list = new ListValue(); |
266 | 285 |
267 if (file_types) { | 286 if (file_types) { |
268 for (size_t i = 0; i < file_types->extensions.size(); ++i) { | 287 for (size_t i = 0; i < file_types->extensions.size(); ++i) { |
269 ListValue* extensions_list = new ListValue(); | 288 ListValue* extensions_list = new ListValue(); |
270 for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { | 289 for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { |
271 extensions_list->Set( | 290 extensions_list->Set( |
(...skipping 13 matching lines...) Expand all Loading... |
285 | 304 |
286 types_list->Set(i, dict); | 305 types_list->Set(i, dict); |
287 } | 306 } |
288 } | 307 } |
289 | 308 |
290 std::string rv; | 309 std::string rv; |
291 base::JSONWriter::Write(&arg_value, false, &rv); | 310 base::JSONWriter::Write(&arg_value, false, &rv); |
292 | 311 |
293 return rv; | 312 return rv; |
294 } | 313 } |
OLD | NEW |