OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/javascript_dialogs/javascript_dialog_tab_helper.h" | 5 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "chrome/browser/engagement/site_engagement_service.h" | 11 #include "chrome/browser/engagement/site_engagement_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
15 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 15 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/common/chrome_features.h" | 17 #include "chrome/common/chrome_features.h" |
| 18 #include "components/app_modal/javascript_dialog_extensions_client.h" |
18 #include "components/app_modal/javascript_dialog_manager.h" | 19 #include "components/app_modal/javascript_dialog_manager.h" |
19 #include "content/public/browser/navigation_handle.h" | 20 #include "content/public/browser/navigation_handle.h" |
20 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
21 #include "ui/gfx/text_elider.h" | 22 #include "ui/gfx/text_elider.h" |
22 | 23 |
23 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); | 24 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 bool IsEnabled() { | 28 bool IsEnabled() { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 kMessageTextMaxCols, false, | 165 kMessageTextMaxCols, false, |
165 &truncated_message_text); | 166 &truncated_message_text); |
166 base::string16 truncated_default_prompt_text; | 167 base::string16 truncated_default_prompt_text; |
167 gfx::ElideString(default_prompt_text, kDefaultPromptMaxSize, | 168 gfx::ElideString(default_prompt_text, kDefaultPromptMaxSize, |
168 &truncated_default_prompt_text); | 169 &truncated_default_prompt_text); |
169 | 170 |
170 base::string16 title = | 171 base::string16 title = |
171 AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url); | 172 AppModalDialogManager()->GetTitle(alerting_web_contents, origin_url); |
172 dialog_callback_ = callback; | 173 dialog_callback_ = callback; |
173 dialog_type_ = dialog_type; | 174 dialog_type_ = dialog_type; |
| 175 alerting_web_contents_ = alerting_web_contents; |
| 176 AppModalDialogManager()->GetExtensionsClient()->OnDialogOpened( |
| 177 alerting_web_contents); |
174 dialog_ = JavaScriptDialog::Create( | 178 dialog_ = JavaScriptDialog::Create( |
175 parent_web_contents, alerting_web_contents, title, dialog_type, | 179 parent_web_contents, alerting_web_contents, title, dialog_type, |
176 truncated_message_text, truncated_default_prompt_text, | 180 truncated_message_text, truncated_default_prompt_text, |
177 base::Bind(&JavaScriptDialogTabHelper::OnDialogClosed, | 181 base::Bind(&JavaScriptDialogTabHelper::OnDialogClosed, |
178 base::Unretained(this), callback)); | 182 base::Unretained(this), callback)); |
179 | 183 |
180 BrowserList::AddObserver(this); | 184 BrowserList::AddObserver(this); |
181 | 185 |
182 // Message suppression is something that we don't give the user a checkbox | 186 // Message suppression is something that we don't give the user a checkbox |
183 // for any more. It was useful back in the day when dialogs were app-modal | 187 // for any more. It was useful back in the day when dialogs were app-modal |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 break; | 327 break; |
324 } | 328 } |
325 } | 329 } |
326 | 330 |
327 void JavaScriptDialogTabHelper::OnDialogClosed( | 331 void JavaScriptDialogTabHelper::OnDialogClosed( |
328 DialogClosedCallback callback, | 332 DialogClosedCallback callback, |
329 bool success, | 333 bool success, |
330 const base::string16& user_input) { | 334 const base::string16& user_input) { |
331 LogDialogDismissalCause(DismissalCause::DIALOG_BUTTON_CLICKED); | 335 LogDialogDismissalCause(DismissalCause::DIALOG_BUTTON_CLICKED); |
332 callback.Run(success, user_input); | 336 callback.Run(success, user_input); |
| 337 AppModalDialogManager()->GetExtensionsClient()->OnDialogClosed( |
| 338 alerting_web_contents_); |
333 | 339 |
334 ClearDialogInfo(); | 340 ClearDialogInfo(); |
335 } | 341 } |
336 | 342 |
337 void JavaScriptDialogTabHelper::CloseDialog(bool success, | 343 void JavaScriptDialogTabHelper::CloseDialog(bool success, |
338 const base::string16& user_input, | 344 const base::string16& user_input, |
339 DismissalCause cause) { | 345 DismissalCause cause) { |
340 DCHECK(dialog_); | 346 DCHECK(dialog_); |
341 LogDialogDismissalCause(cause); | 347 LogDialogDismissalCause(cause); |
342 | 348 |
343 dialog_->CloseDialogWithoutCallback(); | 349 dialog_->CloseDialogWithoutCallback(); |
344 dialog_callback_.Run(success, user_input); | 350 dialog_callback_.Run(success, user_input); |
| 351 AppModalDialogManager()->GetExtensionsClient()->OnDialogClosed( |
| 352 alerting_web_contents_); |
345 | 353 |
346 ClearDialogInfo(); | 354 ClearDialogInfo(); |
347 } | 355 } |
348 | 356 |
349 void JavaScriptDialogTabHelper::ClearDialogInfo() { | 357 void JavaScriptDialogTabHelper::ClearDialogInfo() { |
350 dialog_.reset(); | 358 dialog_.reset(); |
351 dialog_callback_.Reset(); | 359 dialog_callback_.Reset(); |
| 360 alerting_web_contents_ = nullptr; |
352 BrowserList::RemoveObserver(this); | 361 BrowserList::RemoveObserver(this); |
353 } | 362 } |
OLD | NEW |