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

Side by Side Diff: chrome/browser/chromeos/file_manager/open_util.cc

Issue 910613002: Do not open a downloaded file with generic file handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use auto and for-range loop. Created 5 years, 10 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
« no previous file with comments | « no previous file | no next file » | 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) 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/chromeos/file_manager/open_util.h" 5 #include "chrome/browser/chromeos/file_manager/open_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 file_urls.push_back(url); 96 file_urls.push_back(url);
97 97
98 std::vector<file_tasks::FullTaskDescriptor> tasks; 98 std::vector<file_tasks::FullTaskDescriptor> tasks;
99 file_tasks::FindAllTypesOfTasks( 99 file_tasks::FindAllTypesOfTasks(
100 profile, 100 profile,
101 drive::util::GetDriveAppRegistryByProfile(profile), 101 drive::util::GetDriveAppRegistryByProfile(profile),
102 path_mime_set, 102 path_mime_set,
103 file_urls, 103 file_urls,
104 &tasks); 104 &tasks);
105 105
106 if (tasks.empty()) { 106 // Select a default handler. If a default handler is not available, select
107 callback.Run(false); 107 // a non-generic file handler.
108 return; 108 const file_tasks::FullTaskDescriptor* chosen_task = nullptr;
109 } 109 for (const auto& task : tasks) {
110 110 if (!task.is_generic_file_handler()) {
111 const file_tasks::FullTaskDescriptor* chosen_task = &tasks[0]; 111 chosen_task = &task;
112 for (size_t i = 0; i < tasks.size(); ++i) { 112 if (task.is_default())
113 if (tasks[i].is_default()) { 113 break;
114 chosen_task = &tasks[i];
115 break;
116 } 114 }
117 } 115 }
118 116
119 ExecuteFileTaskForUrl(profile, chosen_task->task_descriptor(), url); 117 if (chosen_task != nullptr) {
120 callback.Run(true); 118 ExecuteFileTaskForUrl(profile, chosen_task->task_descriptor(), url);
119 callback.Run(true);
120 } else {
121 callback.Run(false);
122 }
121 } 123 }
122 124
123 // Opens the file specified by |url| by finding and executing a file task for 125 // Opens the file specified by |url| by finding and executing a file task for
124 // the file. In case of success, calls |callback| with true. Otherwise the 126 // the file. In case of success, calls |callback| with true. Otherwise the
125 // returned value is false. 127 // returned value is false.
126 void OpenFile(Profile* profile, 128 void OpenFile(Profile* profile,
127 const base::FilePath& path, 129 const base::FilePath& path,
128 const GURL& url, 130 const GURL& url,
129 const base::Callback<void(bool)>& callback) { 131 const base::Callback<void(bool)>& callback) {
130 extensions::app_file_handler_util::GetMimeTypeForLocalPath( 132 extensions::app_file_handler_util::GetMimeTypeForLocalPath(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 GURL url; 206 GURL url;
205 if (!ConvertPath(profile, file_path, &url)) 207 if (!ConvertPath(profile, file_path, &url))
206 return; 208 return;
207 209
208 // This action changes the selection so we do not reuse existing tabs. 210 // This action changes the selection so we do not reuse existing tabs.
209 OpenFileManagerWithInternalActionId(profile, url, "select"); 211 OpenFileManagerWithInternalActionId(profile, url, "select");
210 } 212 }
211 213
212 } // namespace util 214 } // namespace util
213 } // namespace file_manager 215 } // namespace file_manager
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698