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/ui/views/external_protocol_dialog.h" | 5 #include "chrome/browser/ui/views/external_protocol_dialog.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 const std::wstring& command) | 127 const std::wstring& command) |
128 : web_contents_(web_contents), | 128 : web_contents_(web_contents), |
129 url_(url), | 129 url_(url), |
130 creation_time_(base::TimeTicks::Now()) { | 130 creation_time_(base::TimeTicks::Now()) { |
131 const int kMaxUrlWithoutSchemeSize = 256; | 131 const int kMaxUrlWithoutSchemeSize = 256; |
132 const int kMaxCommandSize = 256; | 132 const int kMaxCommandSize = 256; |
133 string16 elided_url_without_scheme; | 133 string16 elided_url_without_scheme; |
134 string16 elided_command; | 134 string16 elided_command; |
135 ui::ElideString(ASCIIToUTF16(url.possibly_invalid_spec()), | 135 ui::ElideString(ASCIIToUTF16(url.possibly_invalid_spec()), |
136 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme); | 136 kMaxUrlWithoutSchemeSize, &elided_url_without_scheme); |
137 ui::ElideString(base::WideToUTF16Hack(command), kMaxCommandSize, | 137 ui::ElideString(WideToUTF16Hack(command), kMaxCommandSize, &elided_command); |
138 &elided_command); | |
139 | 138 |
140 string16 message_text = l10n_util::GetStringFUTF16( | 139 string16 message_text = l10n_util::GetStringFUTF16( |
141 IDS_EXTERNAL_PROTOCOL_INFORMATION, | 140 IDS_EXTERNAL_PROTOCOL_INFORMATION, |
142 ASCIIToUTF16(url.scheme() + ":"), | 141 ASCIIToUTF16(url.scheme() + ":"), |
143 elided_url_without_scheme) + ASCIIToUTF16("\n\n"); | 142 elided_url_without_scheme) + ASCIIToUTF16("\n\n"); |
144 | 143 |
145 message_text += l10n_util::GetStringFUTF16( | 144 message_text += l10n_util::GetStringFUTF16( |
146 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH, | 145 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH, |
147 elided_command) + ASCIIToUTF16("\n\n"); | 146 elided_command) + ASCIIToUTF16("\n\n"); |
148 | 147 |
(...skipping 16 matching lines...) Expand all Loading... |
165 views::Widget::CreateWindowWithParent(this, root_hwnd)->Show(); | 164 views::Widget::CreateWindowWithParent(this, root_hwnd)->Show(); |
166 } | 165 } |
167 | 166 |
168 // static | 167 // static |
169 std::wstring ExternalProtocolDialog::GetApplicationForProtocol( | 168 std::wstring ExternalProtocolDialog::GetApplicationForProtocol( |
170 const GURL& url) { | 169 const GURL& url) { |
171 // We shouldn't be accessing the registry from the UI thread, since it can go | 170 // We shouldn't be accessing the registry from the UI thread, since it can go |
172 // to disk. http://crbug.com/61996 | 171 // to disk. http://crbug.com/61996 |
173 base::ThreadRestrictions::ScopedAllowIO allow_io; | 172 base::ThreadRestrictions::ScopedAllowIO allow_io; |
174 | 173 |
175 std::wstring url_spec = base::ASCIIToWide(url.possibly_invalid_spec()); | 174 std::wstring url_spec = ASCIIToWide(url.possibly_invalid_spec()); |
176 std::wstring cmd_key_path = | 175 std::wstring cmd_key_path = |
177 base::ASCIIToWide(url.scheme() + "\\shell\\open\\command"); | 176 ASCIIToWide(url.scheme() + "\\shell\\open\\command"); |
178 base::win::RegKey cmd_key(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), KEY_READ); | 177 base::win::RegKey cmd_key(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), KEY_READ); |
179 size_t split_offset = url_spec.find(L':'); | 178 size_t split_offset = url_spec.find(L':'); |
180 if (split_offset == std::wstring::npos) | 179 if (split_offset == std::wstring::npos) |
181 return std::wstring(); | 180 return std::wstring(); |
182 std::wstring parameters = url_spec.substr(split_offset + 1, | 181 std::wstring parameters = url_spec.substr(split_offset + 1, |
183 url_spec.length() - 1); | 182 url_spec.length() - 1); |
184 std::wstring application_to_launch; | 183 std::wstring application_to_launch; |
185 if (cmd_key.ReadValue(NULL, &application_to_launch) == ERROR_SUCCESS) { | 184 if (cmd_key.ReadValue(NULL, &application_to_launch) == ERROR_SUCCESS) { |
186 ReplaceSubstringsAfterOffset(&application_to_launch, 0, L"%1", parameters); | 185 ReplaceSubstringsAfterOffset(&application_to_launch, 0, L"%1", parameters); |
187 return application_to_launch; | 186 return application_to_launch; |
188 } else { | 187 } else { |
189 return std::wstring(); | 188 return std::wstring(); |
190 } | 189 } |
191 } | 190 } |
OLD | NEW |