| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 base::string16 ExternalProtocolDialog::GetWindowTitle() const { | 68 base::string16 ExternalProtocolDialog::GetWindowTitle() const { |
| 69 return delegate_->GetTitleText(); | 69 return delegate_->GetTitleText(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ExternalProtocolDialog::DeleteDelegate() { | 72 void ExternalProtocolDialog::DeleteDelegate() { |
| 73 delete this; | 73 delete this; |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool ExternalProtocolDialog::Cancel() { | 76 bool ExternalProtocolDialog::Cancel() { |
| 77 // We also get called back here if the user closes the dialog or presses | |
| 78 // escape. In these cases it would be preferable to ignore the state of the | |
| 79 // check box but MessageBox doesn't distinguish this from pressing the cancel | |
| 80 // button. | |
| 81 delegate_->DoCancel(delegate_->url(), | 77 delegate_->DoCancel(delegate_->url(), |
| 82 message_box_view_->IsCheckBoxSelected()); | 78 message_box_view_->IsCheckBoxSelected()); |
| 83 | 79 |
| 84 ExternalProtocolHandler::RecordMetrics( | 80 ExternalProtocolHandler::RecordMetrics( |
| 85 message_box_view_->IsCheckBoxSelected()); | 81 message_box_view_->IsCheckBoxSelected()); |
| 86 | 82 |
| 87 // Returning true closes the dialog. | 83 // Returning true closes the dialog. |
| 88 return true; | 84 return true; |
| 89 } | 85 } |
| 90 | 86 |
| 91 bool ExternalProtocolDialog::Accept() { | 87 bool ExternalProtocolDialog::Accept() { |
| 92 // We record how long it takes the user to accept an external protocol. If | 88 // We record how long it takes the user to accept an external protocol. If |
| 93 // users start accepting these dialogs too quickly, we should worry about | 89 // users start accepting these dialogs too quickly, we should worry about |
| 94 // clickjacking. | 90 // clickjacking. |
| 95 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url", | 91 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url", |
| 96 base::TimeTicks::Now() - creation_time_); | 92 base::TimeTicks::Now() - creation_time_); |
| 97 | 93 |
| 98 ExternalProtocolHandler::RecordMetrics( | 94 ExternalProtocolHandler::RecordMetrics( |
| 99 message_box_view_->IsCheckBoxSelected()); | 95 message_box_view_->IsCheckBoxSelected()); |
| 100 | 96 |
| 101 delegate_->DoAccept(delegate_->url(), | 97 delegate_->DoAccept(delegate_->url(), |
| 102 message_box_view_->IsCheckBoxSelected()); | 98 message_box_view_->IsCheckBoxSelected()); |
| 103 | 99 |
| 104 // Returning true closes the dialog. | 100 // Returning true closes the dialog. |
| 105 return true; | 101 return true; |
| 106 } | 102 } |
| 107 | 103 |
| 104 bool ExternalProtocolDialog::Close() { |
| 105 // If the user dismisses the dialog without interacting with the buttons (e.g. |
| 106 // via pressing Esc or the X), act as though they cancelled the request, but |
| 107 // ignore the checkbox state. This ensures that if they check the checkbox but |
| 108 // dismiss the dialog, we don't stop prompting them forever. |
| 109 delegate_->DoCancel(delegate_->url(), false); |
| 110 return true; |
| 111 } |
| 112 |
| 108 views::View* ExternalProtocolDialog::GetContentsView() { | 113 views::View* ExternalProtocolDialog::GetContentsView() { |
| 109 return message_box_view_; | 114 return message_box_view_; |
| 110 } | 115 } |
| 111 | 116 |
| 112 views::Widget* ExternalProtocolDialog::GetWidget() { | 117 views::Widget* ExternalProtocolDialog::GetWidget() { |
| 113 return message_box_view_->GetWidget(); | 118 return message_box_view_->GetWidget(); |
| 114 } | 119 } |
| 115 | 120 |
| 116 const views::Widget* ExternalProtocolDialog::GetWidget() const { | 121 const views::Widget* ExternalProtocolDialog::GetWidget() const { |
| 117 return message_box_view_->GetWidget(); | 122 return message_box_view_->GetWidget(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 137 message_box_view_ = new views::MessageBoxView(params); | 142 message_box_view_ = new views::MessageBoxView(params); |
| 138 message_box_view_->SetCheckBoxLabel(delegate_->GetCheckboxText()); | 143 message_box_view_->SetCheckBoxLabel(delegate_->GetCheckboxText()); |
| 139 | 144 |
| 140 WebContents* web_contents = tab_util::GetWebContentsByID( | 145 WebContents* web_contents = tab_util::GetWebContentsByID( |
| 141 render_process_host_id_, routing_id_); | 146 render_process_host_id_, routing_id_); |
| 142 // Only launch the dialog if there is a web contents associated with the | 147 // Only launch the dialog if there is a web contents associated with the |
| 143 // request. | 148 // request. |
| 144 if (web_contents) | 149 if (web_contents) |
| 145 constrained_window::ShowWebModalDialogViews(this, web_contents); | 150 constrained_window::ShowWebModalDialogViews(this, web_contents); |
| 146 } | 151 } |
| OLD | NEW |