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

Unified Diff: Source/core/page/ChromeClient.cpp

Issue 1162263007: Cleanup: Move code common in ChromeClient JavaScript dialog functions to a function template. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/page/ChromeClient.h ('k') | Source/web/ChromeClientImpl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/page/ChromeClient.cpp
diff --git a/Source/core/page/ChromeClient.cpp b/Source/core/page/ChromeClient.cpp
index ee3ea49be7560f814f16c0a497556a5dab93e223..6498e76d8b4ca1a979e103e8ff0cfc8ac66debed 100644
--- a/Source/core/page/ChromeClient.cpp
+++ b/Source/core/page/ChromeClient.cpp
@@ -98,62 +98,51 @@ private:
InspectorInstrumentationCookie m_cookie;
};
-bool ChromeClient::runBeforeUnloadConfirmPanel(const String& message, LocalFrame* frame)
+template<typename ReturnType, typename... Params>
+ReturnType openJavaScriptDialog(
+ ChromeClient* chromeClient,
+ ReturnType(ChromeClient::*function)(LocalFrame*, const String& message, Params&...),
+ LocalFrame& frame,
+ const String& message,
+ Params&... parameters)
{
// Defer loads in case the client method runs a new event loop that would
- // otherwise cause the load to continue while we're in the middle of executing JavaScript.
+ // otherwise cause the load to continue while we're in the middle of
+ // executing JavaScript.
ScopedPageLoadDeferrer deferrer;
- ScopedJavaScriptDialogInstrumentation instrumentation(*frame, message);
- return runBeforeUnloadConfirmPanelInternal(message, frame);
+ chromeClient->notifyPopupOpeningObservers();
+ ScopedJavaScriptDialogInstrumentation instrumentation(frame, message);
+ return (chromeClient->*function)(&frame, message, parameters...);
+}
+
+bool ChromeClient::runBeforeUnloadConfirmPanel(const String& message, LocalFrame* frame)
+{
+ return openJavaScriptDialog(this, &ChromeClient::runBeforeUnloadConfirmPanelInternal, *frame, message);
}
void ChromeClient::runJavaScriptAlert(LocalFrame* frame, const String& message)
{
+ ASSERT(frame);
if (!canRunModalIfDuringPageDismissal(frame->tree().top(), ChromeClient::AlertDialog, message))
return;
-
- // Defer loads in case the client method runs a new event loop that would
- // otherwise cause the load to continue while we're in the middle of executing JavaScript.
- ScopedPageLoadDeferrer deferrer;
-
- ASSERT(frame);
- notifyPopupOpeningObservers();
-
- ScopedJavaScriptDialogInstrumentation instrumentation(*frame, message);
- runJavaScriptAlertInternal(frame, message);
+ openJavaScriptDialog(this, &ChromeClient::runJavaScriptAlertInternal, *frame, message);
}
bool ChromeClient::runJavaScriptConfirm(LocalFrame* frame, const String& message)
{
+ ASSERT(frame);
if (!canRunModalIfDuringPageDismissal(frame->tree().top(), ChromeClient::ConfirmDialog, message))
return false;
-
- // Defer loads in case the client method runs a new event loop that would
- // otherwise cause the load to continue while we're in the middle of executing JavaScript.
- ScopedPageLoadDeferrer deferrer;
-
- ASSERT(frame);
- notifyPopupOpeningObservers();
-
- ScopedJavaScriptDialogInstrumentation instrumentation(*frame, message);
- return runJavaScriptConfirmInternal(frame, message);
+ return openJavaScriptDialog(this, &ChromeClient::runJavaScriptConfirmInternal, *frame, message);
}
bool ChromeClient::runJavaScriptPrompt(LocalFrame* frame, const String& prompt, const String& defaultValue, String& result)
{
+ ASSERT(frame);
if (!canRunModalIfDuringPageDismissal(frame->tree().top(), ChromeClient::PromptDialog, prompt))
return false;
-
- // Defer loads in case the client method runs a new event loop that would
- // otherwise cause the load to continue while we're in the middle of executing JavaScript.
- ScopedPageLoadDeferrer deferrer;
-
- ASSERT(frame);
- notifyPopupOpeningObservers();
-
- ScopedJavaScriptDialogInstrumentation instrumentation(*frame, prompt);
- return runJavaScriptPromptInternal(frame, prompt, defaultValue, result);
+ return openJavaScriptDialog(this, &ChromeClient::runJavaScriptPromptInternal, *frame, prompt, defaultValue, result);
}
void ChromeClient::mouseDidMoveOverElement(const HitTestResult& result)
« no previous file with comments | « Source/core/page/ChromeClient.h ('k') | Source/web/ChromeClientImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698