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

Side by Side Diff: chrome/browser/views/shell_dialogs_win.cc

Issue 3836005: Move pe_image and registry from base to base/win and use the namespace. It re... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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/browser/views/external_protocol_dialog.cc ('k') | chrome/common/chrome_plugin_lib.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_dialogs.h" 5 #include "chrome/browser/shell_dialogs.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <commdlg.h> 8 #include <commdlg.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <set> 12 #include <set>
13 13
14 #include "app/l10n_util.h" 14 #include "app/l10n_util.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/message_loop.h" 16 #include "base/message_loop.h"
17 #include "base/registry.h"
18 #include "base/scoped_comptr_win.h" 17 #include "base/scoped_comptr_win.h"
19 #include "base/string_split.h" 18 #include "base/string_split.h"
20 #include "base/thread.h" 19 #include "base/thread.h"
21 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "base/win/registry.h"
22 #include "base/win/windows_version.h" 22 #include "base/win/windows_version.h"
23 #include "chrome/browser/browser_thread.h" 23 #include "chrome/browser/browser_thread.h"
24 #include "gfx/font.h" 24 #include "gfx/font.h"
25 #include "grit/app_strings.h" 25 #include "grit/app_strings.h"
26 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 27
28 // This function takes the output of a SaveAs dialog: a filename, a filter and 28 // This function takes the output of a SaveAs dialog: a filename, a filter and
29 // the extension originally suggested to the user (shown in the dialog box) and 29 // the extension originally suggested to the user (shown in the dialog box) and
30 // returns back the filename with the appropriate extension tacked on. If the 30 // returns back the filename with the appropriate extension tacked on. If the
31 // user requests an unknown extension and is not using the 'All files' filter, 31 // user requests an unknown extension and is not using the 'All files' filter,
(...skipping 10 matching lines...) Expand all
42 std::wstring return_value = filename; 42 std::wstring return_value = filename;
43 43
44 // If we wanted a specific extension, but the user's filename deleted it or 44 // If we wanted a specific extension, but the user's filename deleted it or
45 // changed it to something that the system doesn't understand, re-append. 45 // changed it to something that the system doesn't understand, re-append.
46 // Careful: Checking net::GetMimeTypeFromExtension() will only find 46 // Careful: Checking net::GetMimeTypeFromExtension() will only find
47 // extensions with a known MIME type, which many "known" extensions on Windows 47 // extensions with a known MIME type, which many "known" extensions on Windows
48 // don't have. So we check directly for the "known extension" registry key. 48 // don't have. So we check directly for the "known extension" registry key.
49 std::wstring file_extension(file_util::GetFileExtensionFromPath(filename)); 49 std::wstring file_extension(file_util::GetFileExtensionFromPath(filename));
50 std::wstring key(L"." + file_extension); 50 std::wstring key(L"." + file_extension);
51 if (!(filter_selected.empty() || filter_selected == L"*.*") && 51 if (!(filter_selected.empty() || filter_selected == L"*.*") &&
52 !RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).Valid() && 52 !base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).Valid() &&
53 file_extension != suggested_ext) { 53 file_extension != suggested_ext) {
54 if (return_value[return_value.length() - 1] != L'.') 54 if (return_value[return_value.length() - 1] != L'.')
55 return_value.append(L"."); 55 return_value.append(L".");
56 return_value.append(suggested_ext); 56 return_value.append(suggested_ext);
57 } 57 }
58 58
59 // Strip any trailing dots, which Windows doesn't allow. 59 // Strip any trailing dots, which Windows doesn't allow.
60 size_t index = return_value.find_last_not_of(L'.'); 60 size_t index = return_value.find_last_not_of(L'.');
61 if (index < return_value.size() - 1) 61 if (index < return_value.size() - 1)
62 return_value.resize(index + 1); 62 return_value.resize(index + 1);
63 63
64 return return_value; 64 return return_value;
65 } 65 }
66 66
67 namespace { 67 namespace {
68 68
69 // Get the file type description from the registry. This will be "Text Document" 69 // Get the file type description from the registry. This will be "Text Document"
70 // for .txt files, "JPEG Image" for .jpg files, etc. If the registry doesn't 70 // for .txt files, "JPEG Image" for .jpg files, etc. If the registry doesn't
71 // have an entry for the file type, we return false, true if the description was 71 // have an entry for the file type, we return false, true if the description was
72 // found. 'file_ext' must be in form ".txt". 72 // found. 'file_ext' must be in form ".txt".
73 static bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext, 73 static bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext,
74 std::wstring* reg_description) { 74 std::wstring* reg_description) {
75 DCHECK(reg_description); 75 DCHECK(reg_description);
76 RegKey reg_ext(HKEY_CLASSES_ROOT, file_ext.c_str(), KEY_READ); 76 base::win::RegKey reg_ext(HKEY_CLASSES_ROOT, file_ext.c_str(), KEY_READ);
77 std::wstring reg_app; 77 std::wstring reg_app;
78 if (reg_ext.ReadValue(NULL, &reg_app) && !reg_app.empty()) { 78 if (reg_ext.ReadValue(NULL, &reg_app) && !reg_app.empty()) {
79 RegKey reg_link(HKEY_CLASSES_ROOT, reg_app.c_str(), KEY_READ); 79 base::win::RegKey reg_link(HKEY_CLASSES_ROOT, reg_app.c_str(), KEY_READ);
80 if (reg_link.ReadValue(NULL, reg_description)) 80 if (reg_link.ReadValue(NULL, reg_description))
81 return true; 81 return true;
82 } 82 }
83 return false; 83 return false;
84 } 84 }
85 85
86 // Set up a filter for a Save/Open dialog, which will consist of |file_ext| file 86 // Set up a filter for a Save/Open dialog, which will consist of |file_ext| file
87 // extensions (internally separated by semicolons), |ext_desc| as the text 87 // extensions (internally separated by semicolons), |ext_desc| as the text
88 // descriptions of the |file_ext| types (optional), and (optionally) the default 88 // descriptions of the |file_ext| types (optional), and (optionally) the default
89 // 'All Files' view. The purpose of the filter is to show only files of a 89 // 'All Files' view. The purpose of the filter is to show only files of a
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 void SelectFontDialogImpl::FontNotSelected(void* params, RunState run_state) { 1120 void SelectFontDialogImpl::FontNotSelected(void* params, RunState run_state) {
1121 if (listener_) 1121 if (listener_)
1122 listener_->FontSelectionCanceled(params); 1122 listener_->FontSelectionCanceled(params);
1123 EndRun(run_state); 1123 EndRun(run_state);
1124 } 1124 }
1125 1125
1126 // static 1126 // static
1127 SelectFontDialog* SelectFontDialog::Create(Listener* listener) { 1127 SelectFontDialog* SelectFontDialog::Create(Listener* listener) {
1128 return new SelectFontDialogImpl(listener); 1128 return new SelectFontDialogImpl(listener);
1129 } 1129 }
OLDNEW
« no previous file with comments | « chrome/browser/views/external_protocol_dialog.cc ('k') | chrome/common/chrome_plugin_lib.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698