| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 elided_command) + ASCIIToUTF16("\n\n"); | 147 elided_command) + ASCIIToUTF16("\n\n"); |
| 148 | 148 |
| 149 message_text += l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING); | 149 message_text += l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_WARNING); |
| 150 | 150 |
| 151 views::MessageBoxView::InitParams params(message_text); | 151 views::MessageBoxView::InitParams params(message_text); |
| 152 params.message_width = kMessageWidth; | 152 params.message_width = kMessageWidth; |
| 153 message_box_view_ = new views::MessageBoxView(params); | 153 message_box_view_ = new views::MessageBoxView(params); |
| 154 message_box_view_->SetCheckBoxLabel( | 154 message_box_view_->SetCheckBoxLabel( |
| 155 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT)); | 155 l10n_util::GetStringUTF16(IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT)); |
| 156 | 156 |
| 157 HWND root_hwnd; | 157 // Dialog is top level if we don't have a web_contents associated with us. |
| 158 HWND root_hwnd = NULL; |
| 158 if (web_contents_) { | 159 if (web_contents_) { |
| 159 root_hwnd = GetAncestor(web_contents_->GetView()->GetContentNativeView(), | 160 root_hwnd = GetAncestor(web_contents_->GetView()->GetContentNativeView(), |
| 160 GA_ROOT); | 161 GA_ROOT); |
| 161 } else { | |
| 162 // Dialog is top level if we don't have a web_contents associated with us. | |
| 163 root_hwnd = NULL; | |
| 164 } | 162 } |
| 165 | 163 |
| 166 views::Widget::CreateWindowWithParent(this, root_hwnd)->Show(); | 164 views::DialogDelegate::CreateDialogWidget(this, NULL, root_hwnd)->Show(); |
| 167 } | 165 } |
| 168 | 166 |
| 169 // static | 167 // static |
| 170 std::wstring ExternalProtocolDialog::GetApplicationForProtocol( | 168 std::wstring ExternalProtocolDialog::GetApplicationForProtocol( |
| 171 const GURL& url) { | 169 const GURL& url) { |
| 172 // 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 |
| 173 // to disk. http://crbug.com/61996 | 171 // to disk. http://crbug.com/61996 |
| 174 base::ThreadRestrictions::ScopedAllowIO allow_io; | 172 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 175 | 173 |
| 176 std::wstring url_spec = ASCIIToWide(url.possibly_invalid_spec()); | 174 std::wstring url_spec = ASCIIToWide(url.possibly_invalid_spec()); |
| 177 std::wstring cmd_key_path = | 175 std::wstring cmd_key_path = |
| 178 ASCIIToWide(url.scheme() + "\\shell\\open\\command"); | 176 ASCIIToWide(url.scheme() + "\\shell\\open\\command"); |
| 179 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); |
| 180 size_t split_offset = url_spec.find(L':'); | 178 size_t split_offset = url_spec.find(L':'); |
| 181 if (split_offset == std::wstring::npos) | 179 if (split_offset == std::wstring::npos) |
| 182 return std::wstring(); | 180 return std::wstring(); |
| 183 std::wstring parameters = url_spec.substr(split_offset + 1, | 181 std::wstring parameters = url_spec.substr(split_offset + 1, |
| 184 url_spec.length() - 1); | 182 url_spec.length() - 1); |
| 185 std::wstring application_to_launch; | 183 std::wstring application_to_launch; |
| 186 if (cmd_key.ReadValue(NULL, &application_to_launch) == ERROR_SUCCESS) { | 184 if (cmd_key.ReadValue(NULL, &application_to_launch) == ERROR_SUCCESS) { |
| 187 ReplaceSubstringsAfterOffset(&application_to_launch, 0, L"%1", parameters); | 185 ReplaceSubstringsAfterOffset(&application_to_launch, 0, L"%1", parameters); |
| 188 return application_to_launch; | 186 return application_to_launch; |
| 189 } else { | 187 } else { |
| 190 return std::wstring(); | 188 return std::wstring(); |
| 191 } | 189 } |
| 192 } | 190 } |
| OLD | NEW |