OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_with_browser.h" | 5 #include "chrome/browser/chromeos/file_manager/open_with_browser.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 14 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" |
14 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" | 15 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
15 #include "chrome/browser/drive/drive_api_util.h" | 16 #include "chrome/browser/drive/drive_api_util.h" |
16 #include "chrome/browser/plugins/plugin_prefs.h" | 17 #include "chrome/browser/plugins/plugin_prefs.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 19 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_tabstrip.h" | 21 #include "chrome/browser/ui/browser_tabstrip.h" |
21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 23 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // Note that an alternate url is a URL to open a hosted document. | 123 // Note that an alternate url is a URL to open a hosted document. |
123 GURL ReadUrlFromGDocOnBlockingPool(const base::FilePath& file_path) { | 124 GURL ReadUrlFromGDocOnBlockingPool(const base::FilePath& file_path) { |
124 GURL url = drive::util::ReadUrlFromGDocFile(file_path); | 125 GURL url = drive::util::ReadUrlFromGDocFile(file_path); |
125 if (url.is_empty()) | 126 if (url.is_empty()) |
126 url = net::FilePathToFileURL(file_path); | 127 url = net::FilePathToFileURL(file_path); |
127 return url; | 128 return url; |
128 } | 129 } |
129 | 130 |
130 } // namespace | 131 } // namespace |
131 | 132 |
132 bool OpenFileWithBrowser(Profile* profile, const base::FilePath& file_path) { | 133 bool OpenFileWithBrowser(Profile* profile, |
| 134 const storage::FileSystemURL& file_system_url) { |
133 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
134 DCHECK(profile); | 136 DCHECK(profile); |
135 | 137 |
| 138 const base::FilePath file_path = file_system_url.path(); |
| 139 |
136 // For things supported natively by the browser, we should open it | 140 // For things supported natively by the browser, we should open it |
137 // in a tab. | 141 // in a tab. |
138 if (IsViewableInBrowser(file_path) || | 142 if (IsViewableInBrowser(file_path) || |
139 ShouldBeOpenedWithPlugin(profile, file_path.Extension())) { | 143 ShouldBeOpenedWithPlugin(profile, file_path.Extension())) { |
140 GURL page_url = net::FilePathToFileURL(file_path); | 144 // Use external file URL if it is provided for the file system. |
141 // Override drive resource to point to internal handler instead of file URL. | 145 GURL page_url = chromeos::FileSystemURLToExternalFileURL(file_system_url); |
142 if (drive::util::IsUnderDriveMountPoint(file_path)) { | 146 if (page_url.is_empty()) |
143 page_url = chromeos::FilePathToExternalFileURL( | 147 page_url = net::FilePathToFileURL(file_path); |
144 drive::util::ExtractDrivePath(file_path)); | 148 |
145 } | |
146 OpenNewTab(profile, page_url); | 149 OpenNewTab(profile, page_url); |
147 return true; | 150 return true; |
148 } | 151 } |
149 | 152 |
150 if (drive::util::HasHostedDocumentExtension(file_path)) { | 153 if (drive::util::HasHostedDocumentExtension(file_path)) { |
151 if (drive::util::IsUnderDriveMountPoint(file_path)) { | 154 if (file_manager::util::IsUnderNonNativeLocalPath(profile, file_path)) { |
152 // The file is on Google Docs. Open with drive URL. | 155 // The file is on a non-native volume. Use external file URL. If the file |
153 GURL url = chromeos::FilePathToExternalFileURL( | 156 // is on the drive volume, ExternalFileURLRequestJob redirects the URL to |
154 drive::util::ExtractDrivePath(file_path)); | 157 // drive's web interface. Otherwise (e.g. MTP, FSP), the file is just |
| 158 // downloaded in a browser tab. |
| 159 const GURL url = |
| 160 chromeos::FileSystemURLToExternalFileURL(file_system_url); |
| 161 DCHECK(!url.is_empty()); |
155 OpenNewTab(profile, url); | 162 OpenNewTab(profile, url); |
156 } else { | 163 } else { |
157 // The file is local (downloaded from an attachment or otherwise copied). | 164 // The file is local (downloaded from an attachment or otherwise copied). |
158 // Parse the file to extract the Docs url and open this url. | 165 // Parse the file to extract the Docs url and open this url. |
159 base::PostTaskAndReplyWithResult( | 166 base::PostTaskAndReplyWithResult( |
160 BrowserThread::GetBlockingPool(), | 167 BrowserThread::GetBlockingPool(), |
161 FROM_HERE, | 168 FROM_HERE, |
162 base::Bind(&ReadUrlFromGDocOnBlockingPool, file_path), | 169 base::Bind(&ReadUrlFromGDocOnBlockingPool, file_path), |
163 base::Bind(&OpenNewTab, profile)); | 170 base::Bind(&OpenNewTab, profile)); |
164 } | 171 } |
(...skipping 15 matching lines...) Expand all Loading... |
180 base::FilePath::FromUTF8Unsafe("dummy").AddExtension(file_extension); | 187 base::FilePath::FromUTF8Unsafe("dummy").AddExtension(file_extension); |
181 if (file_path.MatchesExtension(kPdfExtension)) | 188 if (file_path.MatchesExtension(kPdfExtension)) |
182 return IsPdfPluginEnabled(profile); | 189 return IsPdfPluginEnabled(profile); |
183 if (file_path.MatchesExtension(kSwfExtension)) | 190 if (file_path.MatchesExtension(kSwfExtension)) |
184 return IsFlashPluginEnabled(profile); | 191 return IsFlashPluginEnabled(profile); |
185 return false; | 192 return false; |
186 } | 193 } |
187 | 194 |
188 } // namespace util | 195 } // namespace util |
189 } // namespace file_manager | 196 } // namespace file_manager |
OLD | NEW |