OLD | NEW |
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/web_applications/web_app_win.h" | 5 #include "chrome/browser/web_applications/web_app_win.h" |
6 | 6 |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 sizeof(base::MD5Digest)) != 0; | 101 sizeof(base::MD5Digest)) != 0; |
102 } | 102 } |
103 | 103 |
104 // Returns true if |shortcut_file_name| matches profile |profile_path|, and has | 104 // Returns true if |shortcut_file_name| matches profile |profile_path|, and has |
105 // an --app-id flag. | 105 // an --app-id flag. |
106 bool IsAppShortcutForProfile(const base::FilePath& shortcut_file_name, | 106 bool IsAppShortcutForProfile(const base::FilePath& shortcut_file_name, |
107 const base::FilePath& profile_path) { | 107 const base::FilePath& profile_path) { |
108 base::string16 cmd_line_string; | 108 base::string16 cmd_line_string; |
109 if (base::win::ResolveShortcut(shortcut_file_name, NULL, &cmd_line_string)) { | 109 if (base::win::ResolveShortcut(shortcut_file_name, NULL, &cmd_line_string)) { |
110 cmd_line_string = L"program " + cmd_line_string; | 110 cmd_line_string = L"program " + cmd_line_string; |
111 CommandLine shortcut_cmd_line = CommandLine::FromString(cmd_line_string); | 111 base::CommandLine shortcut_cmd_line = |
| 112 base::CommandLine::FromString(cmd_line_string); |
112 return shortcut_cmd_line.HasSwitch(switches::kProfileDirectory) && | 113 return shortcut_cmd_line.HasSwitch(switches::kProfileDirectory) && |
113 shortcut_cmd_line.GetSwitchValuePath(switches::kProfileDirectory) == | 114 shortcut_cmd_line.GetSwitchValuePath(switches::kProfileDirectory) == |
114 profile_path.BaseName() && | 115 profile_path.BaseName() && |
115 shortcut_cmd_line.HasSwitch(switches::kAppId); | 116 shortcut_cmd_line.HasSwitch(switches::kAppId); |
116 } | 117 } |
117 | 118 |
118 return false; | 119 return false; |
119 } | 120 } |
120 | 121 |
121 // Finds shortcuts in |shortcut_path| that match profile for |profile_path| and | 122 // Finds shortcuts in |shortcut_path| that match profile for |profile_path| and |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 189 |
189 base::FilePath chrome_exe; | 190 base::FilePath chrome_exe; |
190 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 191 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
191 NOTREACHED(); | 192 NOTREACHED(); |
192 return false; | 193 return false; |
193 } | 194 } |
194 | 195 |
195 // Working directory. | 196 // Working directory. |
196 base::FilePath working_dir(chrome_exe.DirName()); | 197 base::FilePath working_dir(chrome_exe.DirName()); |
197 | 198 |
198 CommandLine cmd_line(CommandLine::NO_PROGRAM); | 199 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM); |
199 cmd_line = ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, | 200 cmd_line = ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, |
200 shortcut_info.extension_id, shortcut_info.profile_path); | 201 shortcut_info.extension_id, shortcut_info.profile_path); |
201 | 202 |
202 // TODO(evan): we rely on the fact that command_line_string() is | 203 // TODO(evan): we rely on the fact that command_line_string() is |
203 // properly quoted for a Windows command line. The method on | 204 // properly quoted for a Windows command line. The method on |
204 // CommandLine should probably be renamed to better reflect that | 205 // base::CommandLine should probably be renamed to better reflect that |
205 // fact. | 206 // fact. |
206 base::string16 wide_switches(cmd_line.GetCommandLineString()); | 207 base::string16 wide_switches(cmd_line.GetCommandLineString()); |
207 | 208 |
208 // Sanitize description | 209 // Sanitize description |
209 base::string16 description = shortcut_info.description; | 210 base::string16 description = shortcut_info.description; |
210 if (description.length() >= MAX_PATH) | 211 if (description.length() >= MAX_PATH) |
211 description.resize(MAX_PATH - 1); | 212 description.resize(MAX_PATH - 1); |
212 | 213 |
213 // Generates app id from web app url and profile path. | 214 // Generates app id from web app url and profile path. |
214 std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info)); | 215 std::string app_name(web_app::GenerateApplicationNameFromInfo(shortcut_info)); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 332 } |
332 } | 333 } |
333 } | 334 } |
334 | 335 |
335 void CreateIconAndSetRelaunchDetails(const base::FilePath& web_app_path, | 336 void CreateIconAndSetRelaunchDetails(const base::FilePath& web_app_path, |
336 const base::FilePath& icon_file, | 337 const base::FilePath& icon_file, |
337 const web_app::ShortcutInfo& shortcut_info, | 338 const web_app::ShortcutInfo& shortcut_info, |
338 HWND hwnd) { | 339 HWND hwnd) { |
339 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 340 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
340 | 341 |
341 CommandLine command_line = | 342 base::CommandLine command_line = |
342 ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, | 343 ShellIntegration::CommandLineArgsForLauncher(shortcut_info.url, |
343 shortcut_info.extension_id, | 344 shortcut_info.extension_id, |
344 shortcut_info.profile_path); | 345 shortcut_info.profile_path); |
345 | 346 |
346 base::FilePath chrome_exe; | 347 base::FilePath chrome_exe; |
347 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 348 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
348 NOTREACHED(); | 349 NOTREACHED(); |
349 return; | 350 return; |
350 } | 351 } |
351 command_line.SetProgram(chrome_exe); | 352 command_line.SetProgram(chrome_exe); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 return true; | 409 return true; |
409 } | 410 } |
410 | 411 |
411 // Gets the full command line for calling the shim binary. This will include a | 412 // Gets the full command line for calling the shim binary. This will include a |
412 // placeholder "%1" argument, which Windows will substitute with the filename | 413 // placeholder "%1" argument, which Windows will substitute with the filename |
413 // chosen by the user. | 414 // chosen by the user. |
414 base::CommandLine GetAppShimCommandLine(const base::FilePath& app_shim_path, | 415 base::CommandLine GetAppShimCommandLine(const base::FilePath& app_shim_path, |
415 const std::string& extension_id, | 416 const std::string& extension_id, |
416 const base::FilePath& profile_path) { | 417 const base::FilePath& profile_path) { |
417 // Get the command-line to pass to the shim (e.g., "chrome.exe --app-id=..."). | 418 // Get the command-line to pass to the shim (e.g., "chrome.exe --app-id=..."). |
418 CommandLine chrome_cmd_line = ShellIntegration::CommandLineArgsForLauncher( | 419 base::CommandLine chrome_cmd_line = |
419 GURL(), extension_id, profile_path); | 420 ShellIntegration::CommandLineArgsForLauncher(GURL(), extension_id, |
| 421 profile_path); |
420 chrome_cmd_line.AppendArg("%1"); | 422 chrome_cmd_line.AppendArg("%1"); |
421 | 423 |
422 // Get the command-line for calling the shim (e.g., | 424 // Get the command-line for calling the shim (e.g., |
423 // "app_shim [--chrome-sxs] -- --app-id=..."). | 425 // "app_shim [--chrome-sxs] -- --app-id=..."). |
424 CommandLine shim_cmd_line(app_shim_path); | 426 base::CommandLine shim_cmd_line(app_shim_path); |
425 // If this is a canary build, launch the shim in canary mode. | 427 // If this is a canary build, launch the shim in canary mode. |
426 if (InstallUtil::IsChromeSxSProcess()) | 428 if (InstallUtil::IsChromeSxSProcess()) |
427 shim_cmd_line.AppendSwitch(installer::switches::kChromeSxS); | 429 shim_cmd_line.AppendSwitch(installer::switches::kChromeSxS); |
428 // Ensure all subsequent switches are treated as args to the shim. | 430 // Ensure all subsequent switches are treated as args to the shim. |
429 shim_cmd_line.AppendArg("--"); | 431 shim_cmd_line.AppendArg("--"); |
430 for (size_t i = 1; i < chrome_cmd_line.argv().size(); ++i) | 432 for (size_t i = 1; i < chrome_cmd_line.argv().size(); ++i) |
431 shim_cmd_line.AppendArgNative(chrome_cmd_line.argv()[i]); | 433 shim_cmd_line.AppendArgNative(chrome_cmd_line.argv()[i]); |
432 | 434 |
433 return shim_cmd_line; | 435 return shim_cmd_line; |
434 } | 436 } |
(...skipping 28 matching lines...) Expand all Loading... |
463 // will use for file associations with this application. | 465 // will use for file associations with this application. |
464 base::string16 progid_base = L"chrome-"; | 466 base::string16 progid_base = L"chrome-"; |
465 progid_base += base::UTF8ToUTF16(extension_id); | 467 progid_base += base::UTF8ToUTF16(extension_id); |
466 | 468 |
467 // Create the app shim binary (see CreateAppShimBinary for rationale). Get the | 469 // Create the app shim binary (see CreateAppShimBinary for rationale). Get the |
468 // command line for the shim. | 470 // command line for the shim. |
469 base::FilePath app_shim_path = web_app_path.Append(file_name); | 471 base::FilePath app_shim_path = web_app_path.Append(file_name); |
470 if (!CreateAppShimBinary(app_shim_path)) | 472 if (!CreateAppShimBinary(app_shim_path)) |
471 return false; | 473 return false; |
472 | 474 |
473 CommandLine shim_cmd_line( | 475 base::CommandLine shim_cmd_line( |
474 GetAppShimCommandLine(app_shim_path, extension_id, profile_path)); | 476 GetAppShimCommandLine(app_shim_path, extension_id, profile_path)); |
475 | 477 |
476 // TODO(mgiuca): Get the file type name from the manifest, or generate a | 478 // TODO(mgiuca): Get the file type name from the manifest, or generate a |
477 // default one. (If this is blank, Windows will generate one of the form | 479 // default one. (If this is blank, Windows will generate one of the form |
478 // '<EXT> file'.) | 480 // '<EXT> file'.) |
479 base::string16 file_type_name = L""; | 481 base::string16 file_type_name = L""; |
480 | 482 |
481 // TODO(mgiuca): Generate a new icon for this application's file associations | 483 // TODO(mgiuca): Generate a new icon for this application's file associations |
482 // that looks like a page with the application icon inside. | 484 // that looks like a page with the application icon inside. |
483 base::FilePath icon_file = | 485 base::FilePath icon_file = |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 | 763 |
762 } // namespace internals | 764 } // namespace internals |
763 | 765 |
764 void UpdateShortcutForTabContents(content::WebContents* web_contents) { | 766 void UpdateShortcutForTabContents(content::WebContents* web_contents) { |
765 // UpdateShortcutWorker will delete itself when it's done. | 767 // UpdateShortcutWorker will delete itself when it's done. |
766 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); | 768 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); |
767 worker->Run(); | 769 worker->Run(); |
768 } | 770 } |
769 | 771 |
770 } // namespace web_app | 772 } // namespace web_app |
OLD | NEW |