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

Side by Side Diff: chrome/browser/shell_integration_linux.cc

Issue 10910209: Add new PathService paths for Windows' All Users Desktop and Quick Launch folders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust links to pass presubmit Created 8 years, 3 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 | Annotate | Revision Log
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/shell_integration_linux.h" 5 #include "chrome/browser/shell_integration_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <glib.h> 8 #include <glib.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 14 matching lines...) Expand all
25 #include "base/path_service.h" 25 #include "base/path_service.h"
26 #include "base/process_util.h" 26 #include "base/process_util.h"
27 #include "base/scoped_temp_dir.h" 27 #include "base/scoped_temp_dir.h"
28 #include "base/string_number_conversions.h" 28 #include "base/string_number_conversions.h"
29 #include "base/string_tokenizer.h" 29 #include "base/string_tokenizer.h"
30 #include "base/threading/thread.h" 30 #include "base/threading/thread.h"
31 #include "base/utf_string_conversions.h" 31 #include "base/utf_string_conversions.h"
32 #include "build/build_config.h" 32 #include "build/build_config.h"
33 #include "chrome/browser/web_applications/web_app.h" 33 #include "chrome/browser/web_applications/web_app.h"
34 #include "chrome/common/chrome_constants.h" 34 #include "chrome/common/chrome_constants.h"
35 #include "chrome/common/chrome_paths.h"
36 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
37 #include "googleurl/src/gurl.h" 36 #include "googleurl/src/gurl.h"
38 #include "ui/gfx/codec/png_codec.h" 37 #include "ui/gfx/codec/png_codec.h"
39 38
40 using content::BrowserThread; 39 using content::BrowserThread;
41 40
42 namespace { 41 namespace {
43 42
44 // Helper to launch xdg scripts. We don't want them to ask any questions on the 43 // Helper to launch xdg scripts. We don't want them to ask any questions on the
45 // terminal etc. The function returns true if the utility launches and exits 44 // terminal etc. The function returns true if the utility launches and exits
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 LaunchXdgUtility(argv, &exit_code); 111 LaunchXdgUtility(argv, &exit_code);
113 return icon_name; 112 return icon_name;
114 } 113 }
115 114
116 bool CreateShortcutOnDesktop(const FilePath& shortcut_filename, 115 bool CreateShortcutOnDesktop(const FilePath& shortcut_filename,
117 const std::string& contents) { 116 const std::string& contents) {
118 // Make sure that we will later call openat in a secure way. 117 // Make sure that we will later call openat in a secure way.
119 DCHECK_EQ(shortcut_filename.BaseName().value(), shortcut_filename.value()); 118 DCHECK_EQ(shortcut_filename.BaseName().value(), shortcut_filename.value());
120 119
121 FilePath desktop_path; 120 FilePath desktop_path;
122 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) 121 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_path))
123 return false; 122 return false;
124 123
125 int desktop_fd = open(desktop_path.value().c_str(), O_RDONLY | O_DIRECTORY); 124 int desktop_fd = open(desktop_path.value().c_str(), O_RDONLY | O_DIRECTORY);
126 if (desktop_fd < 0) 125 if (desktop_fd < 0)
127 return false; 126 return false;
128 127
129 int fd = openat(desktop_fd, shortcut_filename.value().c_str(), 128 int fd = openat(desktop_fd, shortcut_filename.value().c_str(),
130 O_CREAT | O_EXCL | O_WRONLY, 129 O_CREAT | O_EXCL | O_WRONLY,
131 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); 130 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
132 if (fd < 0) { 131 if (fd < 0) {
(...skipping 16 matching lines...) Expand all
149 } 148 }
150 149
151 if (HANDLE_EINTR(close(desktop_fd)) < 0) 150 if (HANDLE_EINTR(close(desktop_fd)) < 0)
152 PLOG(ERROR) << "close"; 151 PLOG(ERROR) << "close";
153 152
154 return true; 153 return true;
155 } 154 }
156 155
157 void DeleteShortcutOnDesktop(const FilePath& shortcut_filename) { 156 void DeleteShortcutOnDesktop(const FilePath& shortcut_filename) {
158 FilePath desktop_path; 157 FilePath desktop_path;
159 if (PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) 158 if (PathService::Get(base::DIR_USER_DESKTOP, &desktop_path))
160 file_util::Delete(desktop_path.Append(shortcut_filename), false); 159 file_util::Delete(desktop_path.Append(shortcut_filename), false);
161 } 160 }
162 161
163 bool CreateShortcutInApplicationsMenu(const FilePath& shortcut_filename, 162 bool CreateShortcutInApplicationsMenu(const FilePath& shortcut_filename,
164 const std::string& contents) { 163 const std::string& contents) {
165 ScopedTempDir temp_dir; 164 ScopedTempDir temp_dir;
166 if (!temp_dir.CreateUniqueTempDir()) 165 if (!temp_dir.CreateUniqueTempDir())
167 return false; 166 return false;
168 167
169 FilePath temp_file_path = temp_dir.path().Append(shortcut_filename); 168 FilePath temp_file_path = temp_dir.path().Append(shortcut_filename);
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 return false; 476 return false;
478 } 477 }
479 478
480 FilePath GetWebShortcutFilename(const GURL& url) { 479 FilePath GetWebShortcutFilename(const GURL& url) {
481 // Use a prefix, because xdg-desktop-menu requires it. 480 // Use a prefix, because xdg-desktop-menu requires it.
482 std::string filename = 481 std::string filename =
483 std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec(); 482 std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec();
484 file_util::ReplaceIllegalCharactersInPath(&filename, '_'); 483 file_util::ReplaceIllegalCharactersInPath(&filename, '_');
485 484
486 FilePath desktop_path; 485 FilePath desktop_path;
487 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) 486 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_path))
488 return FilePath(); 487 return FilePath();
489 488
490 FilePath filepath = desktop_path.Append(filename); 489 FilePath filepath = desktop_path.Append(filename);
491 FilePath alternative_filepath(filepath.value() + ".desktop"); 490 FilePath alternative_filepath(filepath.value() + ".desktop");
492 for (size_t i = 1; i < 100; ++i) { 491 for (size_t i = 1; i < 100; ++i) {
493 if (file_util::PathExists(FilePath(alternative_filepath))) { 492 if (file_util::PathExists(FilePath(alternative_filepath))) {
494 alternative_filepath = FilePath( 493 alternative_filepath = FilePath(
495 filepath.value() + "_" + base::IntToString(i) + ".desktop"); 494 filepath.value() + "_" + base::IntToString(i) + ".desktop");
496 } else { 495 } else {
497 return FilePath(alternative_filepath).BaseName(); 496 return FilePath(alternative_filepath).BaseName();
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 679
681 FilePath shortcut_filename = GetExtensionShortcutFilename( 680 FilePath shortcut_filename = GetExtensionShortcutFilename(
682 profile_path, extension_id); 681 profile_path, extension_id);
683 DCHECK(!shortcut_filename.empty()); 682 DCHECK(!shortcut_filename.empty());
684 683
685 DeleteShortcutOnDesktop(shortcut_filename); 684 DeleteShortcutOnDesktop(shortcut_filename);
686 DeleteShortcutInApplicationsMenu(shortcut_filename); 685 DeleteShortcutInApplicationsMenu(shortcut_filename);
687 } 686 }
688 687
689 } // namespace ShellIntegrationLinux 688 } // namespace ShellIntegrationLinux
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc ('k') | chrome/browser/shell_integration_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698