| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/mac/foundation_util.h" | 13 #include "base/mac/foundation_util.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "third_party/zlib/google/zip.h" | 15 #include "third_party/zlib/google/zip.h" |
| 16 #include "ui/shell_dialogs/selected_file_info.h" | 16 #include "ui/shell_dialogs/selected_file_info.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Given the |path| of a package, returns the destination that the package | 20 // Given the |path| of a package, returns the destination that the package |
| 21 // should be zipped to. Returns an empty path on any errors. | 21 // should be zipped to. Returns an empty path on any errors. |
| 22 base::FilePath ZipDestination(const base::FilePath& path) { | 22 base::FilePath ZipDestination(const base::FilePath& path) { |
| 23 base::FilePath dest; | 23 NSMutableString* dest = |
| 24 [NSMutableString stringWithString:NSTemporaryDirectory()]; |
| 24 | 25 |
| 25 if (!base::GetTempDir(&dest)) { | 26 // Couldn't get the temporary directory. |
| 26 // Couldn't get the temporary directory. | 27 if (!dest) |
| 27 return base::FilePath(); | 28 return base::FilePath(); |
| 28 } | |
| 29 | 29 |
| 30 // TMPDIR/<bundleID>/zip_cache/<guid> | 30 [dest appendFormat:@"%@/zip_cache/%@", |
| 31 [[NSBundle mainBundle] bundleIdentifier], |
| 32 [[NSProcessInfo processInfo] globallyUniqueString]]; |
| 31 | 33 |
| 32 NSString* bundleID = [[NSBundle mainBundle] bundleIdentifier]; | 34 return base::mac::NSStringToFilePath(dest); |
| 33 dest = dest.Append([bundleID fileSystemRepresentation]); | |
| 34 | |
| 35 dest = dest.Append("zip_cache"); | |
| 36 | |
| 37 NSString* guid = [[NSProcessInfo processInfo] globallyUniqueString]; | |
| 38 dest = dest.Append([guid fileSystemRepresentation]); | |
| 39 | |
| 40 return dest; | |
| 41 } | 35 } |
| 42 | 36 |
| 43 // Returns the path of the package and its components relative to the package's | 37 // Returns the path of the package and its components relative to the package's |
| 44 // parent directory. | 38 // parent directory. |
| 45 std::vector<base::FilePath> RelativePathsForPackage( | 39 std::vector<base::FilePath> RelativePathsForPackage( |
| 46 const base::FilePath& package) { | 40 const base::FilePath& package) { |
| 47 // Get the base directory. | 41 // Get the base directory. |
| 48 base::FilePath base_dir = package.DirName(); | 42 base::FilePath base_dir = package.DirName(); |
| 49 | 43 |
| 50 // Add the package as the first relative path. | 44 // Add the package as the first relative path. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // need to be deleted now. | 131 // need to be deleted now. |
| 138 if (!web_contents_) { | 132 if (!web_contents_) { |
| 139 DeleteTemporaryFiles(); | 133 DeleteTemporaryFiles(); |
| 140 RunFileChooserEnd(); | 134 RunFileChooserEnd(); |
| 141 return; | 135 return; |
| 142 } | 136 } |
| 143 } | 137 } |
| 144 | 138 |
| 145 NotifyRenderFrameHostAndEnd(files); | 139 NotifyRenderFrameHostAndEnd(files); |
| 146 } | 140 } |
| OLD | NEW |