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

Side by Side 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, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/page/ChromeClient.h ('k') | Source/web/ChromeClientImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2009, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2009, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2012, Samsung Electronics. All rights reserved. 4 * Copyright (C) 2012, Samsung Electronics. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 ~ScopedJavaScriptDialogInstrumentation() 92 ~ScopedJavaScriptDialogInstrumentation()
93 { 93 {
94 InspectorInstrumentation::didRunJavaScriptDialog(m_cookie); 94 InspectorInstrumentation::didRunJavaScriptDialog(m_cookie);
95 } 95 }
96 96
97 private: 97 private:
98 InspectorInstrumentationCookie m_cookie; 98 InspectorInstrumentationCookie m_cookie;
99 }; 99 };
100 100
101 template<typename ReturnType, typename... Params>
102 ReturnType openJavaScriptDialog(
103 ChromeClient* chromeClient,
104 ReturnType(ChromeClient::*function)(LocalFrame*, const String& message, Para ms&...),
105 LocalFrame& frame,
106 const String& message,
107 Params&... parameters)
108 {
109 // Defer loads in case the client method runs a new event loop that would
110 // otherwise cause the load to continue while we're in the middle of
111 // executing JavaScript.
112 ScopedPageLoadDeferrer deferrer;
113
114 chromeClient->notifyPopupOpeningObservers();
115 ScopedJavaScriptDialogInstrumentation instrumentation(frame, message);
116 return (chromeClient->*function)(&frame, message, parameters...);
117 }
118
101 bool ChromeClient::runBeforeUnloadConfirmPanel(const String& message, LocalFrame * frame) 119 bool ChromeClient::runBeforeUnloadConfirmPanel(const String& message, LocalFrame * frame)
102 { 120 {
103 // Defer loads in case the client method runs a new event loop that would 121 return openJavaScriptDialog(this, &ChromeClient::runBeforeUnloadConfirmPanel Internal, *frame, message);
104 // otherwise cause the load to continue while we're in the middle of executi ng JavaScript.
105 ScopedPageLoadDeferrer deferrer;
106
107 ScopedJavaScriptDialogInstrumentation instrumentation(*frame, message);
108 return runBeforeUnloadConfirmPanelInternal(message, frame);
109 } 122 }
110 123
111 void ChromeClient::runJavaScriptAlert(LocalFrame* frame, const String& message) 124 void ChromeClient::runJavaScriptAlert(LocalFrame* frame, const String& message)
112 { 125 {
126 ASSERT(frame);
113 if (!canRunModalIfDuringPageDismissal(frame->tree().top(), ChromeClient::Ale rtDialog, message)) 127 if (!canRunModalIfDuringPageDismissal(frame->tree().top(), ChromeClient::Ale rtDialog, message))
114 return; 128 return;
115 129 openJavaScriptDialog(this, &ChromeClient::runJavaScriptAlertInternal, *frame , message);
116 // Defer loads in case the client method runs a new event loop that would
117 // otherwise cause the load to continue while we're in the middle of executi ng JavaScript.
118 ScopedPageLoadDeferrer deferrer;
119
120 ASSERT(frame);
121 notifyPopupOpeningObservers();
122
123 ScopedJavaScriptDialogInstrumentation instrumentation(*frame, message);
124 runJavaScriptAlertInternal(frame, message);
125 } 130 }
126 131
127 bool ChromeClient::runJavaScriptConfirm(LocalFrame* frame, const String& message ) 132 bool ChromeClient::runJavaScriptConfirm(LocalFrame* frame, const String& message )
128 { 133 {
134 ASSERT(frame);
129 if (!canRunModalIfDuringPageDismissal(frame->tree().top(), ChromeClient::Con firmDialog, message)) 135 if (!canRunModalIfDuringPageDismissal(frame->tree().top(), ChromeClient::Con firmDialog, message))
130 return false; 136 return false;
131 137 return openJavaScriptDialog(this, &ChromeClient::runJavaScriptConfirmInterna l, *frame, message);
132 // Defer loads in case the client method runs a new event loop that would
133 // otherwise cause the load to continue while we're in the middle of executi ng JavaScript.
134 ScopedPageLoadDeferrer deferrer;
135
136 ASSERT(frame);
137 notifyPopupOpeningObservers();
138
139 ScopedJavaScriptDialogInstrumentation instrumentation(*frame, message);
140 return runJavaScriptConfirmInternal(frame, message);
141 } 138 }
142 139
143 bool ChromeClient::runJavaScriptPrompt(LocalFrame* frame, const String& prompt, const String& defaultValue, String& result) 140 bool ChromeClient::runJavaScriptPrompt(LocalFrame* frame, const String& prompt, const String& defaultValue, String& result)
144 { 141 {
142 ASSERT(frame);
145 if (!canRunModalIfDuringPageDismissal(frame->tree().top(), ChromeClient::Pro mptDialog, prompt)) 143 if (!canRunModalIfDuringPageDismissal(frame->tree().top(), ChromeClient::Pro mptDialog, prompt))
146 return false; 144 return false;
147 145 return openJavaScriptDialog(this, &ChromeClient::runJavaScriptPromptInternal , *frame, prompt, defaultValue, result);
148 // Defer loads in case the client method runs a new event loop that would
149 // otherwise cause the load to continue while we're in the middle of executi ng JavaScript.
150 ScopedPageLoadDeferrer deferrer;
151
152 ASSERT(frame);
153 notifyPopupOpeningObservers();
154
155 ScopedJavaScriptDialogInstrumentation instrumentation(*frame, prompt);
156 return runJavaScriptPromptInternal(frame, prompt, defaultValue, result);
157 } 146 }
158 147
159 void ChromeClient::mouseDidMoveOverElement(const HitTestResult& result) 148 void ChromeClient::mouseDidMoveOverElement(const HitTestResult& result)
160 { 149 {
161 if (result.innerNode()) { 150 if (result.innerNode()) {
162 if (result.innerNode()->document().isDNSPrefetchEnabled()) 151 if (result.innerNode()->document().isDNSPrefetchEnabled())
163 prefetchDNS(result.absoluteLinkURL().host()); 152 prefetchDNS(result.absoluteLinkURL().host());
164 } 153 }
165 showMouseOverURL(result); 154 showMouseOverURL(result);
166 155
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 252 }
264 253
265 void ChromeClient::notifyPopupOpeningObservers() const 254 void ChromeClient::notifyPopupOpeningObservers() const
266 { 255 {
267 const Vector<PopupOpeningObserver*> observers(m_popupOpeningObservers); 256 const Vector<PopupOpeningObserver*> observers(m_popupOpeningObservers);
268 for (size_t i = 0; i < observers.size(); ++i) 257 for (size_t i = 0; i < observers.size(); ++i)
269 observers[i]->willOpenPopup(); 258 observers[i]->willOpenPopup();
270 } 259 }
271 260
272 } // namespace blink 261 } // namespace blink
OLDNEW
« 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