diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 17:59:23 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 17:59:23 +0000 |
commit | e5c75e4861b7b84ffd18149ecc11934aaa159f21 (patch) | |
tree | e8db0d59bf55d5b01e4465e1881a8c3cdc71559b /chrome | |
parent | 8a9adb85620f16df0c223992c8a51bc3d3537158 (diff) | |
download | chromium_src-e5c75e4861b7b84ffd18149ecc11934aaa159f21.zip chromium_src-e5c75e4861b7b84ffd18149ecc11934aaa159f21.tar.gz chromium_src-e5c75e4861b7b84ffd18149ecc11934aaa159f21.tar.bz2 |
Make JavaScript alerts reflect the URL of the frame they came from, not the
enclosing frame.
BUG=1686837
Review URL: http://codereview.chromium.org/39163
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rwxr-xr-x | chrome/browser/extensions/extension_view.cc | 1 | ||||
-rwxr-xr-x | chrome/browser/extensions/extension_view.h | 1 | ||||
-rwxr-xr-x | chrome/browser/extensions/extension_view_unittest.cc | 1 | ||||
-rw-r--r-- | chrome/browser/js_before_unload_handler.h | 1 | ||||
-rw-r--r-- | chrome/browser/js_before_unload_handler_win.cc | 19 | ||||
-rw-r--r-- | chrome/browser/js_before_unload_handler_win.h | 1 | ||||
-rw-r--r-- | chrome/browser/jsmessage_box_handler.h | 2 | ||||
-rw-r--r-- | chrome/browser/jsmessage_box_handler_win.cc | 27 | ||||
-rw-r--r-- | chrome/browser/jsmessage_box_handler_win.h | 6 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 9 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 4 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host_delegate.h | 4 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.cc | 10 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.h | 4 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 6 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 16 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 9 |
18 files changed, 79 insertions, 44 deletions
diff --git a/chrome/browser/extensions/extension_view.cc b/chrome/browser/extensions/extension_view.cc index 1647ecb..883ac3a 100755 --- a/chrome/browser/extensions/extension_view.cc +++ b/chrome/browser/extensions/extension_view.cc @@ -22,6 +22,7 @@ WebPreferences ExtensionView::GetWebkitPrefs() { void ExtensionView::RunJavaScriptMessage( const std::wstring& message, const std::wstring& default_prompt, + const GURL& frame_url, const int flags, IPC::Message* reply_msg, bool* did_suppress_message) { diff --git a/chrome/browser/extensions/extension_view.h b/chrome/browser/extensions/extension_view.h index 5eb869c..d95b745 100755 --- a/chrome/browser/extensions/extension_view.h +++ b/chrome/browser/extensions/extension_view.h @@ -35,6 +35,7 @@ class ExtensionView : public HWNDHtmlView, virtual void RunJavaScriptMessage( const std::wstring& message, const std::wstring& default_prompt, + const GURL& frame_url, const int flags, IPC::Message* reply_msg, bool* did_suppress_message); diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_view_unittest.cc index 61cd8de..43341ce 100755 --- a/chrome/browser/extensions/extension_view_unittest.cc +++ b/chrome/browser/extensions/extension_view_unittest.cc @@ -43,6 +43,7 @@ class MockExtensionView : public ExtensionView { virtual void RunJavaScriptMessage( const std::wstring& message, const std::wstring& default_prompt, + const GURL& frame_url, const int flags, IPC::Message* reply_msg, bool* did_suppress_message) { diff --git a/chrome/browser/js_before_unload_handler.h b/chrome/browser/js_before_unload_handler.h index 3d85a3c..0babdf0 100644 --- a/chrome/browser/js_before_unload_handler.h +++ b/chrome/browser/js_before_unload_handler.h @@ -10,6 +10,7 @@ // |message_text| between the header and footer. The users response is // returned to the renderer using |reply_msg|. void RunBeforeUnloadDialog(WebContents* web_contents, + const GURL& frame_url, const std::wstring& message_text, IPC::Message* reply_msg); diff --git a/chrome/browser/js_before_unload_handler_win.cc b/chrome/browser/js_before_unload_handler_win.cc index ac31b70..88a3eec 100644 --- a/chrome/browser/js_before_unload_handler_win.cc +++ b/chrome/browser/js_before_unload_handler_win.cc @@ -9,15 +9,16 @@ #include "chrome/views/message_box_view.h" #include "grit/generated_resources.h" -void RunBeforeUnloadDialog( - WebContents* web_contents, - const std::wstring& message_text, - IPC::Message* reply_msg) { +void RunBeforeUnloadDialog(WebContents* web_contents, + const GURL& frame_url, + const std::wstring& message_text, + IPC::Message* reply_msg) { std::wstring full_message = - message_text + L"\n\n" + - l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); + message_text + L"\n\n" + + l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); JavascriptBeforeUnloadHandler* handler = - new JavascriptBeforeUnloadHandler(web_contents, full_message, reply_msg); + new JavascriptBeforeUnloadHandler(web_contents, frame_url, full_message, + reply_msg); AppModalDialogQueue::AddDialog(handler); } @@ -25,12 +26,14 @@ void RunBeforeUnloadDialog( JavascriptBeforeUnloadHandler::JavascriptBeforeUnloadHandler( WebContents* web_contents, + const GURL& frame_url, const std::wstring& message_text, IPC::Message* reply_msg) : JavascriptMessageBoxHandler(web_contents, + frame_url, MessageBoxView::kIsJavascriptConfirm, message_text, - L"", + std::wstring(), false, reply_msg) { } diff --git a/chrome/browser/js_before_unload_handler_win.h b/chrome/browser/js_before_unload_handler_win.h index 4cd6067..7b3d9d8 100644 --- a/chrome/browser/js_before_unload_handler_win.h +++ b/chrome/browser/js_before_unload_handler_win.h @@ -13,6 +13,7 @@ class JavascriptBeforeUnloadHandler : public JavascriptMessageBoxHandler { public: // Cross-platform code should use RunBeforeUnloadDialog. JavascriptBeforeUnloadHandler(WebContents* web_contents, + const GURL& frame_url, const std::wstring& message_text, IPC::Message* reply_msg); virtual ~JavascriptBeforeUnloadHandler() {} diff --git a/chrome/browser/jsmessage_box_handler.h b/chrome/browser/jsmessage_box_handler.h index 0e33681..149bfd7 100644 --- a/chrome/browser/jsmessage_box_handler.h +++ b/chrome/browser/jsmessage_box_handler.h @@ -9,6 +9,7 @@ #include "chrome/common/ipc_message.h" +class GURL; class WebContents; // Creates and runs a Javascript Message Box dialog. @@ -18,6 +19,7 @@ class WebContents; // |default_prompt_text|. The result of the operation is returned using // |reply_msg|. void RunJavascriptMessageBox(WebContents* web_contents, + const GURL& frame_url, int dialog_flags, const std::wstring& message_text, const std::wstring& default_prompt_text, diff --git a/chrome/browser/jsmessage_box_handler_win.cc b/chrome/browser/jsmessage_box_handler_win.cc index 5026e8e..35eb683 100644 --- a/chrome/browser/jsmessage_box_handler_win.cc +++ b/chrome/browser/jsmessage_box_handler_win.cc @@ -20,13 +20,14 @@ #include "grit/generated_resources.h" void RunJavascriptMessageBox(WebContents* web_contents, + const GURL& frame_url, int dialog_flags, const std::wstring& message_text, const std::wstring& default_prompt_text, bool display_suppress_checkbox, IPC::Message* reply_msg) { JavascriptMessageBoxHandler* handler = - new JavascriptMessageBoxHandler(web_contents, dialog_flags, + new JavascriptMessageBoxHandler(web_contents, frame_url, dialog_flags, message_text, default_prompt_text, display_suppress_checkbox, reply_msg); AppModalDialogQueue::AddDialog(handler); @@ -34,18 +35,20 @@ void RunJavascriptMessageBox(WebContents* web_contents, JavascriptMessageBoxHandler::JavascriptMessageBoxHandler( WebContents* web_contents, + const GURL& frame_url, int dialog_flags, const std::wstring& message_text, const std::wstring& default_prompt_text, bool display_suppress_checkbox, IPC::Message* reply_msg) - : web_contents_(web_contents), - reply_msg_(reply_msg), - dialog_flags_(dialog_flags), - dialog_(NULL), - message_box_view_(new MessageBoxView( - dialog_flags | MessageBoxView::kAutoDetectAlignment, - message_text, default_prompt_text)) { + : web_contents_(web_contents), + frame_url_(frame_url), + reply_msg_(reply_msg), + dialog_flags_(dialog_flags), + dialog_(NULL), + message_box_view_(new MessageBoxView( + dialog_flags | MessageBoxView::kAutoDetectAlignment, + message_text, default_prompt_text)) { DCHECK(message_box_view_); DCHECK(reply_msg_); @@ -80,11 +83,7 @@ int JavascriptMessageBoxHandler::GetDialogButtons() const { } std::wstring JavascriptMessageBoxHandler::GetWindowTitle() const { - if (!web_contents_) - return std::wstring(); - - GURL url = web_contents_->GetURL(); - if (!url.has_host()) + if (!frame_url_.has_host()) return l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE); // We really only want the scheme, hostname, and port. @@ -94,7 +93,7 @@ std::wstring JavascriptMessageBoxHandler::GetWindowTitle() const { replacements.ClearPath(); replacements.ClearQuery(); replacements.ClearRef(); - GURL clean_url = url.ReplaceComponents(replacements); + GURL clean_url = frame_url_.ReplaceComponents(replacements); // TODO(brettw) it should be easier than this to do the correct language // handling without getting the accept language from the profile. diff --git a/chrome/browser/jsmessage_box_handler_win.h b/chrome/browser/jsmessage_box_handler_win.h index bac80dd..e8049d9 100644 --- a/chrome/browser/jsmessage_box_handler_win.h +++ b/chrome/browser/jsmessage_box_handler_win.h @@ -10,6 +10,7 @@ #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/views/app_modal_dialog_delegate.h" +#include "googleurl/src/gurl.h" class MessageBoxView; class WebContents; @@ -23,6 +24,7 @@ class JavascriptMessageBoxHandler public: // Cross-platform code should use RunJavaScriptMessageBox. JavascriptMessageBoxHandler(WebContents* web_contents, + const GURL& frame_url, int dialog_flags, const std::wstring& message_text, const std::wstring& default_prompt_text, @@ -64,6 +66,10 @@ class JavascriptMessageBoxHandler // The associated WebContents. Used to send IPC messages to the renderer. WebContents* web_contents_; + // The URL of the frame originating the dialog. It is important we display + // this so the user doesn't blame the enclosing site if a subframe alert()s. + GURL frame_url_; + // Stores flags defined in message_box_view.h which describe the dialog box. int dialog_flags_; diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 9f174fa..629a908 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -1088,21 +1088,24 @@ void RenderViewHost::OnMsgRunFileChooser(bool multiple_files, void RenderViewHost::OnMsgRunJavaScriptMessage( const std::wstring& message, const std::wstring& default_prompt, + const GURL& frame_url, const int flags, IPC::Message* reply_msg) { StopHangMonitorTimeout(); if (modal_dialog_count_++ == 0) modal_dialog_event_->Signal(); - delegate_->RunJavaScriptMessage(message, default_prompt, flags, reply_msg, + delegate_->RunJavaScriptMessage(message, default_prompt, frame_url, flags, + reply_msg, &are_javascript_messages_suppressed_); } -void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const std::wstring& message, +void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const GURL& frame_url, + const std::wstring& message, IPC::Message* reply_msg) { StopHangMonitorTimeout(); if (modal_dialog_count_++ == 0) modal_dialog_event_->Signal(); - delegate_->RunBeforeUnloadConfirm(message, reply_msg); + delegate_->RunBeforeUnloadConfirm(frame_url, message, reply_msg); } void RenderViewHost::OnMsgShowModalHTMLDialog( diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 7120a22..29ed8e4 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -498,9 +498,11 @@ class RenderViewHost : public RenderWidgetHost { const std::wstring& filter); void OnMsgRunJavaScriptMessage(const std::wstring& message, const std::wstring& default_prompt, + const GURL& frame_url, const int flags, IPC::Message* reply_msg); - void OnMsgRunBeforeUnloadConfirm(const std::wstring& message, + void OnMsgRunBeforeUnloadConfirm(const GURL& frame_url, + const std::wstring& message, IPC::Message* reply_msg); void OnMsgShowModalHTMLDialog(const GURL& url, int width, int height, const std::string& json_arguments, diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index cf78cf4..30870af 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -278,11 +278,13 @@ class RenderViewHostDelegate { // A javascript message, confirmation or prompt should be shown. virtual void RunJavaScriptMessage(const std::wstring& message, const std::wstring& default_prompt, + const GURL& frame_url, const int flags, IPC::Message* reply_msg, bool* did_suppress_message) { } - virtual void RunBeforeUnloadConfirm(const std::wstring& message, + virtual void RunBeforeUnloadConfirm(const GURL& frame_url, + const std::wstring& message, IPC::Message* reply_msg) { } // Display this RenderViewHost in a modal fashion. diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index 6ca0726..55c3180 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -1047,6 +1047,7 @@ void WebContents::RunFileChooser(bool multiple_files, void WebContents::RunJavaScriptMessage( const std::wstring& message, const std::wstring& default_prompt, + const GURL& frame_url, const int flags, IPC::Message* reply_msg, bool* did_suppress_message) { @@ -1070,18 +1071,19 @@ void WebContents::RunJavaScriptMessage( TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay)) show_suppress_checkbox = true; - RunJavascriptMessageBox(this, flags, message, default_prompt, + RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt, show_suppress_checkbox, reply_msg); } else { // If we are suppressing messages, just reply as is if the user immediately // pressed "Cancel". - OnJavaScriptMessageBoxClosed(reply_msg, false, L""); + OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring()); } } -void WebContents::RunBeforeUnloadConfirm(const std::wstring& message, +void WebContents::RunBeforeUnloadConfirm(const GURL& frame_url, + const std::wstring& message, IPC::Message* reply_msg) { - RunBeforeUnloadDialog(this, message, reply_msg); + RunBeforeUnloadDialog(this, frame_url, message, reply_msg); } void WebContents::ShowModalHTMLDialog(const GURL& url, int width, int height, diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index 110e923..e1d21de 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -344,10 +344,12 @@ class WebContents : public TabContents, const std::wstring& filter); virtual void RunJavaScriptMessage(const std::wstring& message, const std::wstring& default_prompt, + const GURL& frame_url, const int flags, IPC::Message* reply_msg, bool* did_suppress_message); - virtual void RunBeforeUnloadConfirm(const std::wstring& message, + virtual void RunBeforeUnloadConfirm(const GURL& frame_url, + const std::wstring& message, IPC::Message* reply_msg); virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, const std::string& json_arguments, diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 963afae..db71aa2 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -755,9 +755,10 @@ IPC_BEGIN_MESSAGES(ViewHost) IPC_MESSAGE_ROUTED1(ViewHostMsg_GoToEntryAtOffset, int /* offset (from current) of history item to get */) - IPC_SYNC_MESSAGE_ROUTED3_2(ViewHostMsg_RunJavaScriptMessage, + IPC_SYNC_MESSAGE_ROUTED4_2(ViewHostMsg_RunJavaScriptMessage, std::wstring /* in - alert message */, std::wstring /* in - default prompt */, + GURL /* in - originating page URL */, int /* in - dialog flags */, bool /* out - success */, std::wstring /* out - prompt field */) @@ -1032,7 +1033,8 @@ IPC_BEGIN_MESSAGES(ViewHost) // Displays a box to confirm that the user wants to navigate away from the // page. Replies true if yes, false otherwise, the reply string is ignored, // but is included so that we can use OnJavaScriptMessageBoxClosed. - IPC_SYNC_MESSAGE_ROUTED1_2(ViewHostMsg_RunBeforeUnloadConfirm, + IPC_SYNC_MESSAGE_ROUTED2_2(ViewHostMsg_RunBeforeUnloadConfirm, + GURL, /* in - originating frame URL */ std::wstring /* in - alert message */, bool /* out - success */, std::wstring /* out - This is ignored.*/) diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index a1727c8..d9b2477 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -427,6 +427,7 @@ bool IsPluginProcess() { //-------------------------------------------------------------------------- void RunJavascriptMessageBox(WebContents* web_contents, + const GURL& url, int dialog_flags, const std::wstring& message_text, const std::wstring& default_prompt_text, @@ -436,6 +437,7 @@ void RunJavascriptMessageBox(WebContents* web_contents, } void RunBeforeUnloadDialog(WebContents* web_contents, + const GURL& url, const std::wstring& message_text, IPC::Message* reply_msg) { NOTIMPLEMENTED(); diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index debff4dc..ac29d7e 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -1660,42 +1660,46 @@ class MessageBoxView { }; #endif -void RenderView::RunJavaScriptAlert(WebView* webview, +void RenderView::RunJavaScriptAlert(WebFrame* webframe, const std::wstring& message) { RunJavaScriptMessage(MessageBoxView::kIsJavascriptAlert, message, std::wstring(), + webframe->GetURL(), NULL); } -bool RenderView::RunJavaScriptConfirm(WebView* webview, +bool RenderView::RunJavaScriptConfirm(WebFrame* webframe, const std::wstring& message) { return RunJavaScriptMessage(MessageBoxView::kIsJavascriptConfirm, message, std::wstring(), + webframe->GetURL(), NULL); } -bool RenderView::RunJavaScriptPrompt(WebView* webview, +bool RenderView::RunJavaScriptPrompt(WebFrame* webframe, const std::wstring& message, const std::wstring& default_value, std::wstring* result) { return RunJavaScriptMessage(MessageBoxView::kIsJavascriptPrompt, message, default_value, + webframe->GetURL(), result); } bool RenderView::RunJavaScriptMessage(int type, const std::wstring& message, const std::wstring& default_value, + const GURL& frame_url, std::wstring* result) { bool success = false; std::wstring result_temp; if (!result) result = &result_temp; IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage( - routing_id_, message, default_value, type, &success, result); + routing_id_, message, default_value, frame_url, type, &success, result); msg->set_pump_messages_event(modal_dialog_event_.get()); Send(msg); @@ -1709,14 +1713,14 @@ void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) { autodetected)); } -bool RenderView::RunBeforeUnloadConfirm(WebView* webview, +bool RenderView::RunBeforeUnloadConfirm(WebFrame* webframe, const std::wstring& message) { bool success = false; // This is an ignored return value, but is included so we can accept the same // response as RunJavaScriptMessage. std::wstring ignored_result; IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm( - routing_id_, message, &success, &ignored_result); + routing_id_, webframe->GetURL(), message, &success, &ignored_result); msg->set_pump_messages_event(modal_dialog_event_.get()); Send(msg); diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 1c0078c..700faa9 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -142,15 +142,15 @@ class RenderView : public RenderWidget, virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, const std::string& json_arguments, std::string* json_retval); - virtual void RunJavaScriptAlert(WebView* webview, + virtual void RunJavaScriptAlert(WebFrame* webframe, const std::wstring& message); - virtual bool RunJavaScriptConfirm(WebView* webview, + virtual bool RunJavaScriptConfirm(WebFrame* webframe, const std::wstring& message); - virtual bool RunJavaScriptPrompt(WebView* webview, + virtual bool RunJavaScriptPrompt(WebFrame* webframe, const std::wstring& message, const std::wstring& default_value, std::wstring* result); - virtual bool RunBeforeUnloadConfirm(WebView* webview, + virtual bool RunBeforeUnloadConfirm(WebFrame* webframe, const std::wstring& message); virtual void EnableSuddenTermination(); virtual void DisableSuddenTermination(); @@ -430,6 +430,7 @@ class RenderView : public RenderWidget, bool RunJavaScriptMessage(int type, const std::wstring& message, const std::wstring& default_value, + const GURL& frame_url, std::wstring* result); // Adds search provider from the given OpenSearch description URL as a |