• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "config.h"
22 #include "Chrome.h"
23 
24 #include "ChromeClient.h"
25 #include "DNS.h"
26 #include "Document.h"
27 #include "FileList.h"
28 #include "FloatRect.h"
29 #include "Frame.h"
30 #include "FrameTree.h"
31 #include "Geolocation.h"
32 #include "HTMLFormElement.h"
33 #include "HTMLInputElement.h"
34 #include "HTMLNames.h"
35 #include "HitTestResult.h"
36 #include "InspectorController.h"
37 #include "Page.h"
38 #include "PageGroupLoadDeferrer.h"
39 #include "RenderObject.h"
40 #include "ResourceHandle.h"
41 #include "ScriptController.h"
42 #include "SecurityOrigin.h"
43 #include "Settings.h"
44 #include "WindowFeatures.h"
45 #include <wtf/PassRefPtr.h>
46 #include <wtf/RefPtr.h>
47 #include <wtf/Vector.h>
48 
49 #if ENABLE(DOM_STORAGE)
50 #include "StorageNamespace.h"
51 #endif
52 
53 namespace WebCore {
54 
55 using namespace HTMLNames;
56 using namespace std;
57 
Chrome(Page * page,ChromeClient * client)58 Chrome::Chrome(Page* page, ChromeClient* client)
59     : m_page(page)
60     , m_client(client)
61 {
62     ASSERT(m_client);
63 }
64 
~Chrome()65 Chrome::~Chrome()
66 {
67     m_client->chromeDestroyed();
68 }
69 
repaint(const IntRect & windowRect,bool contentChanged,bool immediate,bool repaintContentOnly)70 void Chrome::repaint(const IntRect& windowRect, bool contentChanged, bool immediate, bool repaintContentOnly)
71 {
72     m_client->repaint(windowRect, contentChanged, immediate, repaintContentOnly);
73 }
74 
scroll(const IntSize & scrollDelta,const IntRect & rectToScroll,const IntRect & clipRect)75 void Chrome::scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
76 {
77     m_client->scroll(scrollDelta, rectToScroll, clipRect);
78 }
79 
screenToWindow(const IntPoint & point) const80 IntPoint Chrome::screenToWindow(const IntPoint& point) const
81 {
82     return m_client->screenToWindow(point);
83 }
84 
windowToScreen(const IntRect & rect) const85 IntRect Chrome::windowToScreen(const IntRect& rect) const
86 {
87     return m_client->windowToScreen(rect);
88 }
89 
platformWindow() const90 PlatformWidget Chrome::platformWindow() const
91 {
92     return m_client->platformWindow();
93 }
94 
contentsSizeChanged(Frame * frame,const IntSize & size) const95 void Chrome::contentsSizeChanged(Frame* frame, const IntSize& size) const
96 {
97     m_client->contentsSizeChanged(frame, size);
98 }
99 
scrollRectIntoView(const IntRect & rect,const ScrollView * scrollView) const100 void Chrome::scrollRectIntoView(const IntRect& rect, const ScrollView* scrollView) const
101 {
102     m_client->scrollRectIntoView(rect, scrollView);
103 }
104 
setWindowRect(const FloatRect & rect) const105 void Chrome::setWindowRect(const FloatRect& rect) const
106 {
107     m_client->setWindowRect(rect);
108 }
109 
windowRect() const110 FloatRect Chrome::windowRect() const
111 {
112     return m_client->windowRect();
113 }
114 
pageRect() const115 FloatRect Chrome::pageRect() const
116 {
117     return m_client->pageRect();
118 }
119 
scaleFactor()120 float Chrome::scaleFactor()
121 {
122     return m_client->scaleFactor();
123 }
124 
focus() const125 void Chrome::focus() const
126 {
127     m_client->focus();
128 }
129 
unfocus() const130 void Chrome::unfocus() const
131 {
132     m_client->unfocus();
133 }
134 
canTakeFocus(FocusDirection direction) const135 bool Chrome::canTakeFocus(FocusDirection direction) const
136 {
137     return m_client->canTakeFocus(direction);
138 }
139 
takeFocus(FocusDirection direction) const140 void Chrome::takeFocus(FocusDirection direction) const
141 {
142     m_client->takeFocus(direction);
143 }
144 
createWindow(Frame * frame,const FrameLoadRequest & request,const WindowFeatures & features) const145 Page* Chrome::createWindow(Frame* frame, const FrameLoadRequest& request, const WindowFeatures& features) const
146 {
147     Page* newPage = m_client->createWindow(frame, request, features);
148 
149 #if ENABLE(DOM_STORAGE)
150     if (newPage) {
151         if (StorageNamespace* oldSessionStorage = m_page->sessionStorage(false))
152             newPage->setSessionStorage(oldSessionStorage->copy());
153     }
154 #endif
155 
156     return newPage;
157 }
158 
show() const159 void Chrome::show() const
160 {
161     m_client->show();
162 }
163 
canRunModal() const164 bool Chrome::canRunModal() const
165 {
166     return m_client->canRunModal();
167 }
168 
canRunModalNow() const169 bool Chrome::canRunModalNow() const
170 {
171     // If loads are blocked, we can't run modal because the contents
172     // of the modal dialog will never show up!
173     return canRunModal() && !ResourceHandle::loadsBlocked();
174 }
175 
runModal() const176 void Chrome::runModal() const
177 {
178     // Defer callbacks in all the other pages in this group, so we don't try to run JavaScript
179     // in a way that could interact with this view.
180     PageGroupLoadDeferrer deferrer(m_page, false);
181 
182     TimerBase::fireTimersInNestedEventLoop();
183     m_client->runModal();
184 }
185 
setToolbarsVisible(bool b) const186 void Chrome::setToolbarsVisible(bool b) const
187 {
188     m_client->setToolbarsVisible(b);
189 }
190 
toolbarsVisible() const191 bool Chrome::toolbarsVisible() const
192 {
193     return m_client->toolbarsVisible();
194 }
195 
setStatusbarVisible(bool b) const196 void Chrome::setStatusbarVisible(bool b) const
197 {
198     m_client->setStatusbarVisible(b);
199 }
200 
statusbarVisible() const201 bool Chrome::statusbarVisible() const
202 {
203     return m_client->statusbarVisible();
204 }
205 
setScrollbarsVisible(bool b) const206 void Chrome::setScrollbarsVisible(bool b) const
207 {
208     m_client->setScrollbarsVisible(b);
209 }
210 
scrollbarsVisible() const211 bool Chrome::scrollbarsVisible() const
212 {
213     return m_client->scrollbarsVisible();
214 }
215 
setMenubarVisible(bool b) const216 void Chrome::setMenubarVisible(bool b) const
217 {
218     m_client->setMenubarVisible(b);
219 }
220 
menubarVisible() const221 bool Chrome::menubarVisible() const
222 {
223     return m_client->menubarVisible();
224 }
225 
setResizable(bool b) const226 void Chrome::setResizable(bool b) const
227 {
228     m_client->setResizable(b);
229 }
230 
canRunBeforeUnloadConfirmPanel()231 bool Chrome::canRunBeforeUnloadConfirmPanel()
232 {
233     return m_client->canRunBeforeUnloadConfirmPanel();
234 }
235 
runBeforeUnloadConfirmPanel(const String & message,Frame * frame)236 bool Chrome::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
237 {
238     // Defer loads in case the client method runs a new event loop that would
239     // otherwise cause the load to continue while we're in the middle of executing JavaScript.
240     PageGroupLoadDeferrer deferrer(m_page, true);
241 
242     return m_client->runBeforeUnloadConfirmPanel(message, frame);
243 }
244 
closeWindowSoon()245 void Chrome::closeWindowSoon()
246 {
247     m_client->closeWindowSoon();
248 }
249 
runJavaScriptAlert(Frame * frame,const String & message)250 void Chrome::runJavaScriptAlert(Frame* frame, const String& message)
251 {
252     // Defer loads in case the client method runs a new event loop that would
253     // otherwise cause the load to continue while we're in the middle of executing JavaScript.
254     PageGroupLoadDeferrer deferrer(m_page, true);
255 
256     ASSERT(frame);
257     m_client->runJavaScriptAlert(frame, frame->displayStringModifiedByEncoding(message));
258 }
259 
runJavaScriptConfirm(Frame * frame,const String & message)260 bool Chrome::runJavaScriptConfirm(Frame* frame, const String& message)
261 {
262     // Defer loads in case the client method runs a new event loop that would
263     // otherwise cause the load to continue while we're in the middle of executing JavaScript.
264     PageGroupLoadDeferrer deferrer(m_page, true);
265 
266     ASSERT(frame);
267     return m_client->runJavaScriptConfirm(frame, frame->displayStringModifiedByEncoding(message));
268 }
269 
runJavaScriptPrompt(Frame * frame,const String & prompt,const String & defaultValue,String & result)270 bool Chrome::runJavaScriptPrompt(Frame* frame, const String& prompt, const String& defaultValue, String& result)
271 {
272     // Defer loads in case the client method runs a new event loop that would
273     // otherwise cause the load to continue while we're in the middle of executing JavaScript.
274     PageGroupLoadDeferrer deferrer(m_page, true);
275 
276     ASSERT(frame);
277     bool ok = m_client->runJavaScriptPrompt(frame, frame->displayStringModifiedByEncoding(prompt), frame->displayStringModifiedByEncoding(defaultValue), result);
278 
279     if (ok)
280         result = frame->displayStringModifiedByEncoding(result);
281 
282     return ok;
283 }
284 
setStatusbarText(Frame * frame,const String & status)285 void Chrome::setStatusbarText(Frame* frame, const String& status)
286 {
287     ASSERT(frame);
288     m_client->setStatusbarText(frame->displayStringModifiedByEncoding(status));
289 }
290 
shouldInterruptJavaScript()291 bool Chrome::shouldInterruptJavaScript()
292 {
293     // Defer loads in case the client method runs a new event loop that would
294     // otherwise cause the load to continue while we're in the middle of executing JavaScript.
295     PageGroupLoadDeferrer deferrer(m_page, true);
296 
297     return m_client->shouldInterruptJavaScript();
298 }
299 
windowResizerRect() const300 IntRect Chrome::windowResizerRect() const
301 {
302     return m_client->windowResizerRect();
303 }
304 
mouseDidMoveOverElement(const HitTestResult & result,unsigned modifierFlags)305 void Chrome::mouseDidMoveOverElement(const HitTestResult& result, unsigned modifierFlags)
306 {
307     if (result.innerNode()) {
308         Document* document = result.innerNode()->document();
309         if (document && document->isDNSPrefetchEnabled())
310             prefetchDNS(result.absoluteLinkURL().host());
311     }
312     m_client->mouseDidMoveOverElement(result, modifierFlags);
313 
314     if (InspectorController* inspector = m_page->inspectorController())
315         inspector->mouseDidMoveOverElement(result, modifierFlags);
316 }
317 
setToolTip(const HitTestResult & result)318 void Chrome::setToolTip(const HitTestResult& result)
319 {
320     // First priority is a potential toolTip representing a spelling or grammar error
321     TextDirection toolTipDirection;
322     String toolTip = result.spellingToolTip(toolTipDirection);
323 
324     // Next priority is a toolTip from a URL beneath the mouse (if preference is set to show those).
325     if (toolTip.isEmpty() && m_page->settings()->showsURLsInToolTips()) {
326         if (Node* node = result.innerNonSharedNode()) {
327             // Get tooltip representing form action, if relevant
328             if (node->hasTagName(inputTag)) {
329                 HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
330                 if (input->inputType() == HTMLInputElement::SUBMIT)
331                     if (HTMLFormElement* form = input->form()) {
332                         toolTip = form->action();
333                         if (form->renderer())
334                             toolTipDirection = form->renderer()->style()->direction();
335                         else
336                             toolTipDirection = LTR;
337                     }
338             }
339         }
340 
341         // Get tooltip representing link's URL
342         if (toolTip.isEmpty()) {
343             // FIXME: Need to pass this URL through userVisibleString once that's in WebCore
344             toolTip = result.absoluteLinkURL().string();
345             // URL always display as LTR.
346             toolTipDirection = LTR;
347         }
348     }
349 
350     // Next we'll consider a tooltip for element with "title" attribute
351     if (toolTip.isEmpty())
352         toolTip = result.title(toolTipDirection);
353 
354     // Lastly, for <input type="file"> that allow multiple files, we'll consider a tooltip for the selected filenames
355     if (toolTip.isEmpty()) {
356         if (Node* node = result.innerNonSharedNode()) {
357             if (node->hasTagName(inputTag)) {
358                 HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
359                 if (input->inputType() == HTMLInputElement::FILE) {
360                     FileList* files = input->files();
361                     unsigned listSize = files->length();
362                     if (files && listSize > 1) {
363                         Vector<UChar> names;
364                         for (size_t i = 0; i < listSize; ++i) {
365                             append(names, files->item(i)->fileName());
366                             if (i != listSize - 1)
367                                 names.append('\n');
368                         }
369                         toolTip = String::adopt(names);
370                         // filename always display as LTR.
371                         toolTipDirection = LTR;
372                     }
373                 }
374             }
375         }
376     }
377 
378     m_client->setToolTip(toolTip, toolTipDirection);
379 }
380 
print(Frame * frame)381 void Chrome::print(Frame* frame)
382 {
383     m_client->print(frame);
384 }
385 
requestGeolocationPermissionForFrame(Frame * frame,Geolocation * geolocation)386 void Chrome::requestGeolocationPermissionForFrame(Frame* frame, Geolocation* geolocation)
387 {
388     // Defer loads in case the client method runs a new event loop that would
389     // otherwise cause the load to continue while we're in the middle of executing JavaScript.
390     PageGroupLoadDeferrer deferrer(m_page, true);
391 
392     ASSERT(frame);
393     m_client->requestGeolocationPermissionForFrame(frame, geolocation);
394 }
395 
runOpenPanel(Frame * frame,PassRefPtr<FileChooser> fileChooser)396 void Chrome::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> fileChooser)
397 {
398     m_client->runOpenPanel(frame, fileChooser);
399 }
400 
setCursor(PlatformCursorHandle cursor)401 bool Chrome::setCursor(PlatformCursorHandle cursor)
402 {
403     return m_client->setCursor(cursor);
404 }
405 
406 // --------
407 
408 #if ENABLE(DASHBOARD_SUPPORT)
dashboardRegionsChanged()409 void ChromeClient::dashboardRegionsChanged()
410 {
411 }
412 #endif
413 
populateVisitedLinks()414 void ChromeClient::populateVisitedLinks()
415 {
416 }
417 
customHighlightRect(Node *,const AtomicString &,const FloatRect &)418 FloatRect ChromeClient::customHighlightRect(Node*, const AtomicString&, const FloatRect&)
419 {
420     return FloatRect();
421 }
422 
paintCustomHighlight(Node *,const AtomicString &,const FloatRect &,const FloatRect &,bool,bool)423 void ChromeClient::paintCustomHighlight(Node*, const AtomicString&, const FloatRect&, const FloatRect&, bool, bool)
424 {
425 }
426 
shouldReplaceWithGeneratedFileForUpload(const String &,String &)427 bool ChromeClient::shouldReplaceWithGeneratedFileForUpload(const String&, String&)
428 {
429     return false;
430 }
431 
generateReplacementFile(const String &)432 String ChromeClient::generateReplacementFile(const String&)
433 {
434     ASSERT_NOT_REACHED();
435     return String();
436 }
437 
paintCustomScrollbar(GraphicsContext *,const FloatRect &,ScrollbarControlSize,ScrollbarControlState,ScrollbarPart,bool,float,float,ScrollbarControlPartMask)438 bool ChromeClient::paintCustomScrollbar(GraphicsContext*, const FloatRect&, ScrollbarControlSize,
439                                         ScrollbarControlState, ScrollbarPart, bool,
440                                         float, float, ScrollbarControlPartMask)
441 {
442     return false;
443 }
444 
paintCustomScrollCorner(GraphicsContext *,const FloatRect &)445 bool ChromeClient::paintCustomScrollCorner(GraphicsContext*, const FloatRect&)
446 {
447     return false;
448 }
449 
450 
451 } // namespace WebCore
452