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

Side by Side Diff: chrome/common/win_util.cc

Issue 18699: Fix a bug when saving web pages that have a period in their title (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
« no previous file with comments | « chrome/common/win_util.h ('k') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/common/win_util.h" 5 #include "chrome/common/win_util.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlapp.h> 8 #include <atlapp.h>
9 #include <commdlg.h> 9 #include <commdlg.h>
10 #include <dwmapi.h> 10 #include <dwmapi.h>
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 380
381 bool SaveFileAs(HWND owner, 381 bool SaveFileAs(HWND owner,
382 const std::wstring& suggested_name, 382 const std::wstring& suggested_name,
383 std::wstring* final_name) { 383 std::wstring* final_name) {
384 std::wstring filter = GetFileFilterFromPath(suggested_name); 384 std::wstring filter = GetFileFilterFromPath(suggested_name);
385 unsigned index = 1; 385 unsigned index = 1;
386 return SaveFileAsWithFilter(owner, 386 return SaveFileAsWithFilter(owner,
387 suggested_name, 387 suggested_name,
388 filter, 388 filter,
389 L"", 389 L"",
390 false,
390 &index, 391 &index,
391 final_name); 392 final_name);
392 } 393 }
393 394
394 bool SaveFileAsWithFilter(HWND owner, 395 bool SaveFileAsWithFilter(HWND owner,
395 const std::wstring& suggested_name, 396 const std::wstring& suggested_name,
396 const std::wstring& filter, 397 const std::wstring& filter,
397 const std::wstring& def_ext, 398 const std::wstring& def_ext,
399 bool ignore_suggested_ext,
398 unsigned* index, 400 unsigned* index,
399 std::wstring* final_name) { 401 std::wstring* final_name) {
400 DCHECK(final_name); 402 DCHECK(final_name);
401 // Having an empty filter makes for a bad user experience. We should always 403 // Having an empty filter makes for a bad user experience. We should always
402 // specify a filter when saving. 404 // specify a filter when saving.
403 DCHECK(!filter.empty()); 405 DCHECK(!filter.empty());
404 std::wstring file_part = file_util::GetFilenameFromPath(suggested_name); 406 std::wstring file_part = file_util::GetFilenameFromPath(suggested_name);
405 407
406 // The size of the in/out buffer in number of characters we pass to win32 408 // The size of the in/out buffer in number of characters we pass to win32
407 // GetSaveFileName. From MSDN "The buffer must be large enough to store the 409 // GetSaveFileName. From MSDN "The buffer must be large enough to store the
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 // the example above, if the first index was selected we need to skip 1 467 // the example above, if the first index was selected we need to skip 1
466 // instance of null to get to "*.jpg". 468 // instance of null to get to "*.jpg".
467 std::vector<std::wstring> filters; 469 std::vector<std::wstring> filters;
468 if (!filter.empty() && save_as.nFilterIndex > 0) 470 if (!filter.empty() && save_as.nFilterIndex > 0)
469 SplitString(filter, '\0', &filters); 471 SplitString(filter, '\0', &filters);
470 std::wstring filter_selected; 472 std::wstring filter_selected;
471 if (!filters.empty()) 473 if (!filters.empty())
472 filter_selected = filters[(2 * (save_as.nFilterIndex - 1)) + 1]; 474 filter_selected = filters[(2 * (save_as.nFilterIndex - 1)) + 1];
473 475
474 // Get the extension that was suggested to the user (when the Save As dialog 476 // Get the extension that was suggested to the user (when the Save As dialog
475 // was opened). 477 // was opened). For saving web pages, we skip this step since there may be
476 std::wstring suggested_ext = 478 // 'extension characters' in the title of the web page.
477 file_util::GetFileExtensionFromPath(suggested_name); 479 std::wstring suggested_ext;
480 if (!ignore_suggested_ext)
481 suggested_ext = file_util::GetFileExtensionFromPath(suggested_name);
482
478 // If we can't get the extension from the suggested_name, we use the default 483 // If we can't get the extension from the suggested_name, we use the default
479 // extension passed in. This is to cover cases like when saving a web page, 484 // extension passed in. This is to cover cases like when saving a web page,
480 // where we get passed in a name without an extension and a default extension 485 // where we get passed in a name without an extension and a default extension
481 // along with it. 486 // along with it.
482 if (suggested_ext.empty()) 487 if (suggested_ext.empty())
483 suggested_ext = def_ext; 488 suggested_ext = def_ext;
484 489
485 *final_name = 490 *final_name =
486 AppendExtensionIfNeeded(*final_name, filter_selected, suggested_ext); 491 AppendExtensionIfNeeded(*final_name, filter_selected, suggested_ext);
487 return true; 492 return true;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 } 897 }
893 898
894 ChromeFont GetWindowTitleFont() { 899 ChromeFont GetWindowTitleFont() {
895 NONCLIENTMETRICS ncm; 900 NONCLIENTMETRICS ncm;
896 win_util::GetNonClientMetrics(&ncm); 901 win_util::GetNonClientMetrics(&ncm);
897 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); 902 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
898 return ChromeFont::CreateFont(caption_font); 903 return ChromeFont::CreateFont(caption_font);
899 } 904 }
900 905
901 } // namespace win_util 906 } // namespace win_util
OLDNEW
« no previous file with comments | « chrome/common/win_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698