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

Side by Side Diff: chrome/browser/tab_contents/tab_contents.cc

Issue 5631001: Stops javascript alerts and unload dialogs from showing during (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move to single method Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/tab_contents/tab_contents.h" 5 #include "chrome/browser/tab_contents/tab_contents.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 2736 matching lines...) Expand 10 before | Expand all | Expand 10 after
2747 const GURL& frame_url, 2747 const GURL& frame_url,
2748 const int flags, 2748 const int flags,
2749 IPC::Message* reply_msg, 2749 IPC::Message* reply_msg,
2750 bool* did_suppress_message) { 2750 bool* did_suppress_message) {
2751 // Suppress javascript messages when requested and when inside a constrained 2751 // Suppress javascript messages when requested and when inside a constrained
2752 // popup window (because that activates them and breaks them out of the 2752 // popup window (because that activates them and breaks them out of the
2753 // constrained window jail). 2753 // constrained window jail).
2754 // Also suppress messages when showing an interstitial. The interstitial is 2754 // Also suppress messages when showing an interstitial. The interstitial is
2755 // shown over the previous page, we don't want the hidden page dialogs to 2755 // shown over the previous page, we don't want the hidden page dialogs to
2756 // interfere with the interstitial. 2756 // interfere with the interstitial.
2757 bool suppress_this_message = suppress_javascript_messages_ || 2757 bool suppress_this_message =
2758 showing_interstitial_page(); 2758 suppress_javascript_messages_ ||
2759 showing_interstitial_page() ||
2760 (delegate() && delegate()->ShouldSuppressDialogs());
2759 if (delegate()) 2761 if (delegate())
2760 suppress_this_message |= 2762 suppress_this_message |=
2761 (delegate()->GetConstrainingContents(this) != this); 2763 (delegate()->GetConstrainingContents(this) != this);
2762 2764
2763 *did_suppress_message = suppress_this_message; 2765 *did_suppress_message = suppress_this_message;
2764 2766
2765 if (!suppress_this_message) { 2767 if (!suppress_this_message) {
2766 base::TimeDelta time_since_last_message( 2768 base::TimeDelta time_since_last_message(
2767 base::TimeTicks::Now() - last_javascript_message_dismissal_); 2769 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2768 bool show_suppress_checkbox = false; 2770 bool show_suppress_checkbox = false;
2769 // Show a checkbox offering to suppress further messages if this message is 2771 // Show a checkbox offering to suppress further messages if this message is
2770 // being displayed within kJavascriptMessageExpectedDelay of the last one. 2772 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2771 if (time_since_last_message < 2773 if (time_since_last_message <
2772 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay)) 2774 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2773 show_suppress_checkbox = true; 2775 show_suppress_checkbox = true;
2774 2776
2775 RunJavascriptMessageBox(profile(), this, frame_url, flags, message, 2777 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2776 default_prompt, show_suppress_checkbox, reply_msg); 2778 default_prompt, show_suppress_checkbox, reply_msg);
2777 } else { 2779 } else {
2778 // If we are suppressing messages, just reply as is if the user immediately 2780 // If we are suppressing messages, just reply as is if the user immediately
2779 // pressed "Cancel". 2781 // pressed "Cancel".
2780 OnMessageBoxClosed(reply_msg, false, std::wstring()); 2782 OnMessageBoxClosed(reply_msg, false, std::wstring());
2781 } 2783 }
2782 } 2784 }
2783 2785
2784 void TabContents::RunBeforeUnloadConfirm(const std::wstring& message, 2786 void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2785 IPC::Message* reply_msg) { 2787 IPC::Message* reply_msg) {
2788 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2789 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2790 std::wstring());
2791 return;
2792 }
2786 is_showing_before_unload_dialog_ = true; 2793 is_showing_before_unload_dialog_ = true;
2787 RunBeforeUnloadDialog(this, message, reply_msg); 2794 RunBeforeUnloadDialog(this, message, reply_msg);
2788 } 2795 }
2789 2796
2790 void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height, 2797 void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2791 const std::string& json_arguments, 2798 const std::string& json_arguments,
2792 IPC::Message* reply_msg) { 2799 IPC::Message* reply_msg) {
2793 if (delegate()) { 2800 if (delegate()) {
2794 HtmlDialogUIDelegate* dialog_delegate = 2801 HtmlDialogUIDelegate* dialog_delegate =
2795 new ModalHtmlDialogDelegate(url, width, height, json_arguments, 2802 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
3236 } 3243 }
3237 3244
3238 void TabContents::set_encoding(const std::string& encoding) { 3245 void TabContents::set_encoding(const std::string& encoding) {
3239 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); 3246 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3240 } 3247 }
3241 3248
3242 void TabContents::SetAppIcon(const SkBitmap& app_icon) { 3249 void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3243 app_icon_ = app_icon; 3250 app_icon_ = app_icon;
3244 NotifyNavigationStateChanged(INVALIDATE_TITLE); 3251 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3245 } 3252 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_loader.cc ('k') | chrome/browser/tab_contents/tab_contents_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698