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

Side by Side Diff: components/app_modal/javascript_dialog_manager.cc

Issue 2421943002: Make JavaScript dialogs auto-dismiss on tab switch. (Closed)
Patch Set: fix Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/app_modal/javascript_dialog_manager.h" 5 #include "components/app_modal/javascript_dialog_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 // Also log the time since a dialog was closed, but only if this is the first 144 // Also log the time since a dialog was closed, but only if this is the first
145 // dialog that was opened since the closing. 145 // dialog that was opened since the closing.
146 if (!last_close_time_.is_null()) { 146 if (!last_close_time_.is_null()) {
147 UMA_HISTOGRAM_MEDIUM_TIMES( 147 UMA_HISTOGRAM_MEDIUM_TIMES(
148 "JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated", 148 "JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated",
149 now - last_close_time_); 149 now - last_close_time_);
150 last_close_time_ = base::TimeTicks(); 150 last_close_time_ = base::TimeTicks();
151 } 151 }
152 152
153 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; 153 base::string16 dialog_title = GetTitle(web_contents, origin_url);
154 base::string16 dialog_title = GetTitle(web_contents, origin_url, is_alert);
155 154
156 extensions_client_->OnDialogOpened(web_contents); 155 extensions_client_->OnDialogOpened(web_contents);
157 156
158 LogUMAMessageLengthStats(message_text); 157 LogUMAMessageLengthStats(message_text);
159 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( 158 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
160 web_contents, 159 web_contents,
161 &javascript_dialog_extra_data_, 160 &javascript_dialog_extra_data_,
162 dialog_title, 161 dialog_title,
163 message_type, 162 message_type,
164 message_text, 163 message_text,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 dialog->SetOverridePromptText(*prompt_override); 235 dialog->SetOverridePromptText(*prompt_override);
237 dialog->native_dialog()->AcceptAppModalDialog(); 236 dialog->native_dialog()->AcceptAppModalDialog();
238 } else { 237 } else {
239 dialog->native_dialog()->CancelAppModalDialog(); 238 dialog->native_dialog()->CancelAppModalDialog();
240 } 239 }
241 return true; 240 return true;
242 } 241 }
243 242
244 base::string16 JavaScriptDialogManager::GetTitle( 243 base::string16 JavaScriptDialogManager::GetTitle(
245 content::WebContents* web_contents, 244 content::WebContents* web_contents,
246 const GURL& origin_url, 245 const GURL& origin_url) {
247 bool is_alert) {
248 // For extensions, show the extension name, but only if the origin of 246 // For extensions, show the extension name, but only if the origin of
249 // the alert matches the top-level WebContents. 247 // the alert matches the top-level WebContents.
250 std::string name; 248 std::string name;
251 if (extensions_client_->GetExtensionName(web_contents, origin_url, &name)) 249 if (extensions_client_->GetExtensionName(web_contents, origin_url, &name))
252 return base::UTF8ToUTF16(name); 250 return base::UTF8ToUTF16(name);
253 251
254 // Otherwise, return the formatted URL. For non-standard URLs such as |data:|, 252 // Otherwise, return the formatted URL. For non-standard URLs such as |data:|,
255 // just say "This page". 253 // just say "This page".
256 bool is_same_origin_as_main_frame = 254 bool is_same_origin_as_main_frame =
257 (web_contents->GetURL().GetOrigin() == origin_url.GetOrigin()); 255 (web_contents->GetURL().GetOrigin() == origin_url.GetOrigin());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // lazy background page after the dialog closes. (Dialogs are closed before 321 // lazy background page after the dialog closes. (Dialogs are closed before
324 // their WebContents is destroyed so |web_contents| is still valid here.) 322 // their WebContents is destroyed so |web_contents| is still valid here.)
325 extensions_client_->OnDialogClosed(web_contents); 323 extensions_client_->OnDialogClosed(web_contents);
326 324
327 last_close_time_ = base::TimeTicks::Now(); 325 last_close_time_ = base::TimeTicks::Now();
328 326
329 callback.Run(success, user_input); 327 callback.Run(success, user_input);
330 } 328 }
331 329
332 } // namespace app_modal 330 } // namespace app_modal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698