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

Side by Side Diff: chrome/browser/extensions/file_manager_util.cc

Issue 8457004: platform_util::OpenItem fixes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rdsmith feedback 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
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 #include "chrome/browser/extensions/file_manager_util.h" 4 #include "chrome/browser/extensions/file_manager_util.h"
5 5
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 28 matching lines...) Expand all
39 #define FILEBROWSER_URL(PATH) \ 39 #define FILEBROWSER_URL(PATH) \
40 ("chrome-extension://" FILEBROWSER_DOMAIN "/" PATH) 40 ("chrome-extension://" FILEBROWSER_DOMAIN "/" PATH)
41 // This is the "well known" url for the file manager extension from 41 // This is the "well known" url for the file manager extension from
42 // browser/resources/file_manager. In the future we may provide a way to swap 42 // browser/resources/file_manager. In the future we may provide a way to swap
43 // out this file manager for an aftermarket part, but not yet. 43 // out this file manager for an aftermarket part, but not yet.
44 const char kFileBrowserExtensionUrl[] = FILEBROWSER_URL(""); 44 const char kFileBrowserExtensionUrl[] = FILEBROWSER_URL("");
45 const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html"); 45 const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html");
46 const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html"); 46 const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html");
47 const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html"); 47 const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html");
48 #undef FILEBROWSER_URL 48 #undef FILEBROWSER_URL
49 #undef FILEBROWSER_DOMAIN
50
51 namespace {
49 52
50 const char kPdfExtension[] = ".pdf"; 53 const char kPdfExtension[] = ".pdf";
51 // List of file extension we can open in tab. 54 // List of file extension we can open in tab.
52 const char* kBrowserSupportedExtensions[] = { 55 const char* kBrowserSupportedExtensions[] = {
53 #if defined(GOOGLE_CHROME_BUILD) 56 #if defined(GOOGLE_CHROME_BUILD)
54 ".pdf", 57 ".pdf",
55 #endif 58 #endif
56 ".bmp", ".jpg", ".jpeg", ".png", ".webp", ".gif", ".txt", ".html", ".htm" 59 ".bmp", ".jpg", ".jpeg", ".png", ".webp", ".gif", ".txt", ".html", ".htm"
57 }; 60 };
58 // List of file extension that can be handled with the media player. 61 // List of file extension that can be handled with the media player.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) 113 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin))
111 return false; 114 return false;
112 115
113 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 116 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
114 if (!plugin_prefs) 117 if (!plugin_prefs)
115 return false; 118 return false;
116 119
117 return plugin_prefs->IsPluginEnabled(plugin); 120 return plugin_prefs->IsPluginEnabled(plugin);
118 } 121 }
119 122
120 // static
121 GURL FileManagerUtil::GetFileBrowserExtensionUrl() {
122 return GURL(kFileBrowserExtensionUrl);
123 }
124
125 // Returns index |ext| has in the |array|. If there is no |ext| in |array|, last 123 // Returns index |ext| has in the |array|. If there is no |ext| in |array|, last
126 // element's index is return (last element should have irrelevant value). 124 // element's index is return (last element should have irrelevant value).
127 int UMAExtensionIndex(const char *ext, 125 int UMAExtensionIndex(const char *ext,
128 const char** array, 126 const char** array,
129 size_t array_size) { 127 size_t array_size) {
130 for (size_t i = 0; i < array_size; i++) { 128 for (size_t i = 0; i < array_size; i++) {
131 if (base::strcasecmp(ext, array[i]) == 0) { 129 if (base::strcasecmp(ext, array[i]) == 0) {
132 return i; 130 return i;
133 } 131 }
134 } 132 }
135 return 0; 133 return 0;
136 } 134 }
137 135
136 } // namespace
137
138 // static
139 GURL FileManagerUtil::GetFileBrowserExtensionUrl() {
140 return GURL(kFileBrowserExtensionUrl);
141 }
142
138 // static 143 // static
139 GURL FileManagerUtil::GetFileBrowserUrl() { 144 GURL FileManagerUtil::GetFileBrowserUrl() {
140 return GURL(kBaseFileBrowserUrl); 145 return GURL(kBaseFileBrowserUrl);
141 } 146 }
142 147
143 // static 148 // static
144 GURL FileManagerUtil::GetMediaPlayerUrl() { 149 GURL FileManagerUtil::GetMediaPlayerUrl() {
145 return GURL(kMediaPlayerUrl); 150 return GURL(kMediaPlayerUrl);
146 } 151 }
147 152
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 228 }
224 229
225 std::string json_args; 230 std::string json_args;
226 base::JSONWriter::Write(&arg_value, false, &json_args); 231 base::JSONWriter::Write(&arg_value, false, &json_args);
227 232
228 // kChromeUIFileManagerURL could not be used since query parameters are not 233 // kChromeUIFileManagerURL could not be used since query parameters are not
229 // supported for it. 234 // supported for it.
230 std::string url = FileManagerUtil::GetFileBrowserUrl().spec() + 235 std::string url = FileManagerUtil::GetFileBrowserUrl().spec() +
231 '?' + EscapeUrlEncodedData(json_args, false); 236 '?' + EscapeUrlEncodedData(json_args, false);
232 return GURL(url); 237 return GURL(url);
233
234 } 238 }
235 239
236 // static 240 // static
237 void FileManagerUtil::ShowFullTabUrl(Profile*, 241 void FileManagerUtil::ViewFolder(const FilePath& dir) {
238 const FilePath& dir) {
239 Browser* browser = BrowserList::GetLastActive(); 242 Browser* browser = BrowserList::GetLastActive();
240 if (!browser) 243 if (!browser)
241 return; 244 return;
242 245
243 FilePath virtual_path; 246 FilePath virtual_path;
244 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(browser->profile(), 247 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(browser->profile(),
245 dir, 248 dir,
246 &virtual_path)) { 249 &virtual_path)) {
247 return; 250 return;
248 } 251 }
249 252
250 std::string url = chrome::kChromeUIFileManagerURL; 253 std::string url = chrome::kChromeUIFileManagerURL;
251 url += "#/" + EscapeUrlEncodedData(virtual_path.value(), false); 254 url += "#/" + EscapeUrlEncodedData(virtual_path.value(), false);
252 255
253 UserMetrics::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); 256 UserMetrics::RecordAction(UserMetricsAction("ShowFileBrowserFullTab"));
254 browser->ShowSingletonTabRespectRef(GURL(url)); 257 browser->ShowSingletonTabRespectRef(GURL(url));
255 } 258 }
256 259
260 // static
257 void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) { 261 void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) {
258 std::string ext = full_path.Extension(); 262 std::string ext = full_path.Extension();
259 // For things supported natively by the browser, we should open it 263 // For things supported natively by the browser, we should open it
260 // in a tab. 264 // in a tab.
261 if (IsSupportedBrowserExtension(ext.data()) || 265 if (IsSupportedBrowserExtension(ext.data()) ||
262 ShouldBeOpenedWithPdfPlugin(ext.data())) { 266 ShouldBeOpenedWithPdfPlugin(ext.data())) {
263 std::string path; 267 std::string path;
264 path = "file://"; 268 path = "file://";
265 path.append(EscapeUrlEncodedData(full_path.value(), false)); 269 path.append(EscapeUrlEncodedData(full_path.value(), false));
266 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 270 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 311
308 BrowserThread::PostTask( 312 BrowserThread::PostTask(
309 BrowserThread::UI, FROM_HERE, 313 BrowserThread::UI, FROM_HERE,
310 base::Bind( 314 base::Bind(
311 &browser::ShowErrorBox, 315 &browser::ShowErrorBox,
312 static_cast<gfx::NativeWindow>(NULL), 316 static_cast<gfx::NativeWindow>(NULL),
313 l10n_util::GetStringFUTF16( 317 l10n_util::GetStringFUTF16(
314 IDS_FILEBROWSER_ERROR_VIEWING_FILE_TITLE, 318 IDS_FILEBROWSER_ERROR_VIEWING_FILE_TITLE,
315 UTF8ToUTF16(full_path.BaseName().value())), 319 UTF8ToUTF16(full_path.BaseName().value())),
316 l10n_util::GetStringUTF16( 320 l10n_util::GetStringUTF16(
317 IDS_FILEBROWSER_ERROR_VIEWING_FILE) 321 IDS_FILEBROWSER_ERROR_VIEWING_FILE)));
318 ));
319 } 322 }
320 323
321 // static 324 // static
322 std::string FileManagerUtil::GetDialogTypeAsString( 325 std::string FileManagerUtil::GetDialogTypeAsString(
323 SelectFileDialog::Type dialog_type) { 326 SelectFileDialog::Type dialog_type) {
324 std::string type_str; 327 std::string type_str;
325 switch (dialog_type) { 328 switch (dialog_type) {
326 case SelectFileDialog::SELECT_NONE: 329 case SelectFileDialog::SELECT_NONE:
327 type_str = "full-page"; 330 type_str = "full-page";
328 break; 331 break;
(...skipping 13 matching lines...) Expand all
342 case SelectFileDialog::SELECT_OPEN_MULTI_FILE: 345 case SelectFileDialog::SELECT_OPEN_MULTI_FILE:
343 type_str = "open-multi-file"; 346 type_str = "open-multi-file";
344 break; 347 break;
345 348
346 default: 349 default:
347 NOTREACHED(); 350 NOTREACHED();
348 } 351 }
349 352
350 return type_str; 353 return type_str;
351 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698