2011-01-24 Anders Carlsson <andersca@apple.com>
[WebKit.git] / Source / WebKit2 / WebProcess / WebPage / WebPage.cpp
1 /*
2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "WebPage.h"
27
28 #include "Arguments.h"
29 #include "DataReference.h"
30 #include "DecoderAdapter.h"
31 #include "DrawingArea.h"
32 #include "InjectedBundle.h"
33 #include "InjectedBundleBackForwardList.h"
34 #include "MessageID.h"
35 #include "NetscapePlugin.h"
36 #include "PageOverlay.h"
37 #include "PluginProxy.h"
38 #include "PluginView.h"
39 #include "PrintInfo.h"
40 #include "RunLoop.h"
41 #include "SessionState.h"
42 #include "ShareableBitmap.h"
43 #include "WebBackForwardList.h"
44 #include "WebBackForwardListItem.h"
45 #include "WebBackForwardListProxy.h"
46 #include "WebChromeClient.h"
47 #include "WebContextMenu.h"
48 #include "WebContextMenuClient.h"
49 #include "WebContextMessages.h"
50 #include "WebCoreArgumentCoders.h"
51 #include "WebDragClient.h"
52 #include "WebEditorClient.h"
53 #include "WebEvent.h"
54 #include "WebEventConversion.h"
55 #include "WebFrame.h"
56 #include "WebGeolocationClient.h"
57 #include "WebImage.h"
58 #include "WebInspector.h"
59 #include "WebInspectorClient.h"
60 #include "WebOpenPanelResultListener.h"
61 #include "WebPageCreationParameters.h"
62 #include "WebPageGroupProxy.h"
63 #include "WebPageProxyMessages.h"
64 #include "WebPopupMenu.h"
65 #include "WebPreferencesStore.h"
66 #include "WebProcess.h"
67 #include "WebProcessProxyMessageKinds.h"
68 #include "WebProcessProxyMessages.h"
69 #include <WebCore/AbstractDatabase.h>
70 #include <WebCore/ArchiveResource.h>
71 #include <WebCore/Chrome.h>
72 #include <WebCore/ContextMenuController.h>
73 #include <WebCore/DocumentFragment.h>
74 #include <WebCore/DocumentLoader.h>
75 #include <WebCore/DocumentMarkerController.h>
76 #include <WebCore/DragController.h>
77 #include <WebCore/DragData.h>
78 #include <WebCore/EventHandler.h>
79 #include <WebCore/FocusController.h>
80 #include <WebCore/Frame.h>
81 #include <WebCore/FrameLoaderTypes.h>
82 #include <WebCore/FrameView.h>
83 #include <WebCore/HistoryItem.h>
84 #include <WebCore/KeyboardEvent.h>
85 #include <WebCore/Page.h>
86 #include <WebCore/PlatformKeyboardEvent.h>
87 #include <WebCore/PrintContext.h>
88 #include <WebCore/RenderTreeAsText.h>
89 #include <WebCore/RenderLayer.h>
90 #include <WebCore/RenderView.h>
91 #include <WebCore/ReplaceSelectionCommand.h>
92 #include <WebCore/ResourceRequest.h>
93 #include <WebCore/Settings.h>
94 #include <WebCore/SharedBuffer.h>
95 #include <WebCore/SubstituteData.h>
96 #include <WebCore/TextIterator.h>
97 #include <WebCore/markup.h>
98 #include <runtime/JSLock.h>
99 #include <runtime/JSValue.h>
100
101 #if PLATFORM(MAC) || PLATFORM(WIN)
102 #include <WebCore/LegacyWebArchive.h>
103 #endif
104
105 #if ENABLE(PLUGIN_PROCESS)
106 // FIXME: This is currently Mac-specific!
107 #include "MachPort.h"
108 #endif
109
110 #if PLATFORM(QT)
111 #include "HitTestResult.h"
112 #endif
113
114 #ifndef NDEBUG
115 #include <wtf/RefCountedLeakCounter.h>
116 #endif
117
118 using namespace JSC;
119 using namespace WebCore;
120
121 namespace WebKit {
122
123 #ifndef NDEBUG
124 static WTF::RefCountedLeakCounter webPageCounter("WebPage");
125 #endif
126
127 PassRefPtr<WebPage> WebPage::create(uint64_t pageID, const WebPageCreationParameters& parameters)
128 {
129     RefPtr<WebPage> page = adoptRef(new WebPage(pageID, parameters));
130
131     if (page->pageGroup()->isVisibleToInjectedBundle() && WebProcess::shared().injectedBundle())
132         WebProcess::shared().injectedBundle()->didCreatePage(page.get());
133
134     return page.release();
135 }
136
137 WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
138     : m_viewSize(parameters.viewSize)
139     , m_drawsBackground(true)
140     , m_drawsTransparentBackground(false)
141     , m_isInRedo(false)
142     , m_isClosed(false)
143     , m_tabToLinks(false)
144 #if PLATFORM(MAC)
145     , m_windowIsVisible(false)
146     , m_isSmartInsertDeleteEnabled(parameters.isSmartInsertDeleteEnabled)
147 #elif PLATFORM(WIN)
148     , m_nativeWindow(parameters.nativeWindow)
149 #endif
150     , m_findController(this)
151     , m_geolocationPermissionRequestManager(this)
152     , m_pageID(pageID)
153     , m_canRunModal(parameters.canRunModal)
154     , m_isRunningModal(false)
155 {
156     ASSERT(m_pageID);
157
158     Page::PageClients pageClients;
159     pageClients.chromeClient = new WebChromeClient(this);
160     pageClients.contextMenuClient = new WebContextMenuClient(this);
161     pageClients.editorClient = new WebEditorClient(this);
162     pageClients.dragClient = new WebDragClient(this);
163     pageClients.backForwardClient = WebBackForwardListProxy::create(this);
164 #if ENABLE(CLIENT_BASED_GEOLOCATION)
165     pageClients.geolocationClient = new WebGeolocationClient(this);
166 #endif
167 #if ENABLE(INSPECTOR)
168     pageClients.inspectorClient = new WebInspectorClient(this);
169 #endif
170     m_page = adoptPtr(new Page(pageClients));
171
172     // Qt does not yet call setIsInWindow. Until it does, just leave
173     // this line out so plug-ins and video will work. Eventually all platforms
174     // should call setIsInWindow and this comment and #if should be removed,
175     // leaving behind the setCanStartMedia call.
176 #if !PLATFORM(QT)
177     m_page->setCanStartMedia(false);
178 #endif
179
180     updatePreferences(parameters.store);
181
182     m_pageGroup = WebProcess::shared().webPageGroup(parameters.pageGroupData);
183     m_page->setGroupName(m_pageGroup->identifier());
184
185     platformInitialize();
186     Settings::setMinDOMTimerInterval(0.004);
187
188     m_drawingArea = DrawingArea::create(this, parameters);
189     m_mainFrame = WebFrame::createMainFrame(this);
190
191     setDrawsBackground(parameters.drawsBackground);
192     setDrawsTransparentBackground(parameters.drawsTransparentBackground);
193
194     setActive(parameters.isActive);
195     setFocused(parameters.isFocused);
196     setIsInWindow(parameters.isInWindow);
197
198     m_userAgent = parameters.userAgent;
199
200     WebBackForwardListProxy::setHighestItemIDFromUIProcess(parameters.highestUsedBackForwardItemID);
201     
202     if (!parameters.sessionState.isEmpty())
203         restoreSession(parameters.sessionState);
204
205 #ifndef NDEBUG
206     webPageCounter.increment();
207 #endif
208 }
209
210 WebPage::~WebPage()
211 {
212     if (m_backForwardList)
213         m_backForwardList->detach();
214
215     ASSERT(!m_page);
216
217     m_sandboxExtensionTracker.invalidate();
218
219 #if PLATFORM(MAC)
220     ASSERT(m_pluginViews.isEmpty());
221 #endif
222
223 #ifndef NDEBUG
224     webPageCounter.decrement();
225 #endif
226 }
227
228 void WebPage::dummy(bool&)
229 {
230 }
231
232 CoreIPC::Connection* WebPage::connection() const
233 {
234     return WebProcess::shared().connection();
235 }
236
237 void WebPage::initializeInjectedBundleContextMenuClient(WKBundlePageContextMenuClient* client)
238 {
239     m_contextMenuClient.initialize(client);
240 }
241
242 void WebPage::initializeInjectedBundleEditorClient(WKBundlePageEditorClient* client)
243 {
244     m_editorClient.initialize(client);
245 }
246
247 void WebPage::initializeInjectedBundleFormClient(WKBundlePageFormClient* client)
248 {
249     m_formClient.initialize(client);
250 }
251
252 void WebPage::initializeInjectedBundleLoaderClient(WKBundlePageLoaderClient* client)
253 {
254     m_loaderClient.initialize(client);
255 }
256
257 void WebPage::initializeInjectedBundleUIClient(WKBundlePageUIClient* client)
258 {
259     m_uiClient.initialize(client);
260 }
261
262 PassRefPtr<Plugin> WebPage::createPlugin(const Plugin::Parameters& parameters)
263 {
264     String pluginPath;
265
266     if (!WebProcess::shared().connection()->sendSync(
267             Messages::WebContext::GetPluginPath(parameters.mimeType, parameters.url.string()), 
268             Messages::WebContext::GetPluginPath::Reply(pluginPath), 0)) {
269         return 0;
270     }
271
272     if (pluginPath.isNull())
273         return 0;
274
275 #if ENABLE(PLUGIN_PROCESS)
276     return PluginProxy::create(pluginPath);
277 #else
278     return NetscapePlugin::create(NetscapePluginModule::getOrCreate(pluginPath));
279 #endif
280 }
281
282 String WebPage::renderTreeExternalRepresentation() const
283 {
284     return externalRepresentation(m_mainFrame->coreFrame(), RenderAsTextBehaviorNormal);
285 }
286
287 void WebPage::executeEditingCommand(const String& commandName, const String& argument)
288 {
289     Frame* frame = m_page->focusController()->focusedOrMainFrame();
290     if (!frame)
291         return;
292     frame->editor()->command(commandName).execute(argument);
293 }
294
295 bool WebPage::isEditingCommandEnabled(const String& commandName)
296 {
297     Frame* frame = m_page->focusController()->focusedOrMainFrame();
298     if (!frame)
299         return false;
300     
301     Editor::Command command = frame->editor()->command(commandName);
302     return command.isSupported() && command.isEnabled();
303 }
304     
305 void WebPage::clearMainFrameName()
306 {
307     mainFrame()->coreFrame()->tree()->clearName();
308 }
309
310 #if USE(ACCELERATED_COMPOSITING)
311 void WebPage::changeAcceleratedCompositingMode(WebCore::GraphicsLayer* layer)
312 {
313     if (m_isClosed)
314         return;
315
316     bool compositing = layer;
317     
318     // Tell the UI process that accelerated compositing changed. It may respond by changing
319     // drawing area types.
320     DrawingAreaInfo newDrawingAreaInfo;
321
322     if (!sendSync(Messages::WebPageProxy::DidChangeAcceleratedCompositing(compositing), Messages::WebPageProxy::DidChangeAcceleratedCompositing::Reply(newDrawingAreaInfo)))
323         return;
324     
325     if (newDrawingAreaInfo.type != drawingArea()->info().type) {
326         m_drawingArea = 0;
327         if (newDrawingAreaInfo.type != DrawingAreaInfo::None) {
328             WebPageCreationParameters parameters;
329             parameters.drawingAreaInfo = newDrawingAreaInfo;
330             m_drawingArea = DrawingArea::create(this, parameters);
331             m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), m_viewSize));
332         }
333     }
334 }
335
336 void WebPage::enterAcceleratedCompositingMode(GraphicsLayer* layer)
337 {
338     changeAcceleratedCompositingMode(layer);
339     m_drawingArea->setRootCompositingLayer(layer);
340 }
341
342 void WebPage::exitAcceleratedCompositingMode()
343 {
344     changeAcceleratedCompositingMode(0);
345 }
346 #endif
347
348 void WebPage::close()
349 {
350     if (m_isClosed)
351         return;
352
353     m_isClosed = true;
354
355     if (pageGroup()->isVisibleToInjectedBundle() && WebProcess::shared().injectedBundle())
356         WebProcess::shared().injectedBundle()->willDestroyPage(this);
357
358 #if ENABLE(INSPECTOR)
359     m_inspector = 0;
360 #endif
361
362     if (m_activePopupMenu) {
363         m_activePopupMenu->disconnectFromPage();
364         m_activePopupMenu = 0;
365     }
366
367     if (m_activeOpenPanelResultListener) {
368         m_activeOpenPanelResultListener->disconnectFromPage();
369         m_activeOpenPanelResultListener = 0;
370     }
371
372     m_sandboxExtensionTracker.invalidate();
373
374     m_printContext = nullptr;
375
376     m_mainFrame->coreFrame()->loader()->detachFromParent();
377     m_page.clear();
378
379     m_drawingArea->onPageClose();
380     m_drawingArea.clear();
381
382     WebProcess::shared().removeWebPage(m_pageID);
383
384     if (m_isRunningModal) {
385         m_isRunningModal = false;
386         WebProcess::shared().runLoop()->stop();
387     }
388 }
389
390 void WebPage::tryClose()
391 {
392     if (!m_mainFrame->coreFrame()->loader()->shouldClose())
393         return;
394
395     sendClose();
396 }
397
398 void WebPage::sendClose()
399 {
400     send(Messages::WebPageProxy::ClosePage());
401 }
402
403 void WebPage::loadURL(const String& url, const SandboxExtension::Handle& sandboxExtensionHandle)
404 {
405     loadURLRequest(ResourceRequest(KURL(KURL(), url)), sandboxExtensionHandle);
406 }
407
408 void WebPage::loadURLRequest(const ResourceRequest& request, const SandboxExtension::Handle& sandboxExtensionHandle)
409 {
410     m_sandboxExtensionTracker.beginLoad(m_mainFrame.get(), sandboxExtensionHandle);
411     m_mainFrame->coreFrame()->loader()->load(request, false);
412 }
413
414 void WebPage::loadData(PassRefPtr<SharedBuffer> sharedBuffer, const String& MIMEType, const String& encodingName, const KURL& baseURL, const KURL& unreachableURL)
415 {
416     ResourceRequest request(baseURL);
417     SubstituteData substituteData(sharedBuffer, MIMEType, encodingName, unreachableURL);
418     m_mainFrame->coreFrame()->loader()->load(request, substituteData, false);
419 }
420
421 void WebPage::loadHTMLString(const String& htmlString, const String& baseURLString)
422 {
423     RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(htmlString.characters()), htmlString.length() * sizeof(UChar));
424     KURL baseURL = baseURLString.isEmpty() ? blankURL() : KURL(KURL(), baseURLString);
425     loadData(sharedBuffer, "text/html", "utf-16", baseURL, KURL());
426 }
427
428 void WebPage::loadAlternateHTMLString(const String& htmlString, const String& baseURLString, const String& unreachableURLString)
429 {
430     RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(htmlString.characters()), htmlString.length() * sizeof(UChar));
431     KURL baseURL = baseURLString.isEmpty() ? blankURL() : KURL(KURL(), baseURLString);
432     KURL unreachableURL = unreachableURLString.isEmpty() ? KURL() : KURL(KURL(), unreachableURLString)  ;
433     loadData(sharedBuffer, "text/html", "utf-16", baseURL, unreachableURL);
434 }
435
436 void WebPage::loadPlainTextString(const String& string)
437 {
438     RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(string.characters()), string.length() * sizeof(UChar));
439     loadData(sharedBuffer, "text/plain", "utf-16", blankURL(), KURL());
440 }
441
442 void WebPage::stopLoadingFrame(uint64_t frameID)
443 {
444     WebFrame* frame = WebProcess::shared().webFrame(frameID);
445     if (!frame)
446         return;
447
448     frame->coreFrame()->loader()->stopForUserCancel();
449 }
450
451 void WebPage::stopLoading()
452 {
453     m_mainFrame->coreFrame()->loader()->stopForUserCancel();
454 }
455
456 void WebPage::setDefersLoading(bool defersLoading)
457 {
458     m_page->setDefersLoading(defersLoading);
459 }
460
461 void WebPage::reload(bool reloadFromOrigin)
462 {
463     m_mainFrame->coreFrame()->loader()->reload(reloadFromOrigin);
464 }
465
466 void WebPage::goForward(uint64_t backForwardItemID)
467 {
468     HistoryItem* item = WebBackForwardListProxy::itemForID(backForwardItemID);
469     m_page->goToItem(item, FrameLoadTypeForward);
470 }
471
472 void WebPage::goBack(uint64_t backForwardItemID)
473 {
474     HistoryItem* item = WebBackForwardListProxy::itemForID(backForwardItemID);
475     m_page->goToItem(item, FrameLoadTypeBack);
476 }
477
478 void WebPage::goToBackForwardItem(uint64_t backForwardItemID)
479 {
480     HistoryItem* item = WebBackForwardListProxy::itemForID(backForwardItemID);
481     m_page->goToItem(item, FrameLoadTypeIndexedBackForward);
482 }
483
484 void WebPage::layoutIfNeeded()
485 {
486     if (m_mainFrame->coreFrame()->view())
487         m_mainFrame->coreFrame()->view()->updateLayoutAndStyleIfNeededRecursive();
488 }
489
490 void WebPage::setSize(const WebCore::IntSize& viewSize)
491 {
492 #if ENABLE(TILED_BACKING_STORE)
493     // If we are resizing to content ignore external attempts.
494     if (!m_resizesToContentsLayoutSize.isEmpty())
495         return;
496 #endif
497
498     if (m_viewSize == viewSize)
499         return;
500
501     Frame* frame = m_page->mainFrame();
502     
503     frame->view()->resize(viewSize);
504     frame->view()->setNeedsLayout();
505     m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), viewSize));
506     
507     m_viewSize = viewSize;
508 }
509
510 #if ENABLE(TILED_BACKING_STORE)
511 void WebPage::setActualVisibleContentRect(const IntRect& rect)
512 {
513     Frame* frame = m_page->mainFrame();
514
515     frame->view()->setActualVisibleContentRect(rect);
516 }
517
518 void WebPage::setResizesToContentsUsingLayoutSize(const IntSize& targetLayoutSize)
519 {
520     if (m_resizesToContentsLayoutSize == targetLayoutSize)
521         return;
522
523     m_resizesToContentsLayoutSize = targetLayoutSize;
524
525     Frame* frame = m_page->mainFrame();
526     if (m_resizesToContentsLayoutSize.isEmpty()) {
527         frame->view()->setDelegatesScrolling(false);
528         frame->view()->setUseFixedLayout(false);
529         frame->view()->setPaintsEntireContents(false);
530     } else {
531         frame->view()->setDelegatesScrolling(true);
532         frame->view()->setUseFixedLayout(true);
533         frame->view()->setPaintsEntireContents(true);
534         frame->view()->setFixedLayoutSize(m_resizesToContentsLayoutSize);
535     }
536     frame->view()->forceLayout();
537 }
538
539 void WebPage::resizeToContentsIfNeeded()
540 {
541     if (m_resizesToContentsLayoutSize.isEmpty())
542         return;
543
544     Frame* frame = m_page->mainFrame();
545
546     IntSize contentSize = frame->view()->contentsSize();
547     if (contentSize == m_viewSize)
548         return;
549
550     m_viewSize = contentSize;
551     frame->view()->resize(m_viewSize);
552     frame->view()->setNeedsLayout();
553 }
554 #endif
555
556 void WebPage::drawRect(GraphicsContext& graphicsContext, const IntRect& rect)
557 {
558     graphicsContext.save();
559     graphicsContext.clip(rect);
560     m_mainFrame->coreFrame()->view()->paint(&graphicsContext, rect);
561     graphicsContext.restore();
562
563     if (m_pageOverlay) {
564         graphicsContext.save();
565         graphicsContext.clip(rect);
566         m_pageOverlay->drawRect(graphicsContext, rect);
567         graphicsContext.restore();
568     }
569 }
570
571 double WebPage::textZoomFactor() const
572 {
573     Frame* frame = m_mainFrame->coreFrame();
574     if (!frame)
575         return 1;
576     return frame->textZoomFactor();
577 }
578
579 void WebPage::setTextZoomFactor(double zoomFactor)
580 {
581     Frame* frame = m_mainFrame->coreFrame();
582     if (!frame)
583         return;
584     frame->setTextZoomFactor(static_cast<float>(zoomFactor));
585 }
586
587 double WebPage::pageZoomFactor() const
588 {
589     Frame* frame = m_mainFrame->coreFrame();
590     if (!frame)
591         return 1;
592     return frame->pageZoomFactor();
593 }
594
595 void WebPage::setPageZoomFactor(double zoomFactor)
596 {
597     Frame* frame = m_mainFrame->coreFrame();
598     if (!frame)
599         return;
600     frame->setPageZoomFactor(static_cast<float>(zoomFactor));
601 }
602
603 void WebPage::setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor)
604 {
605     Frame* frame = m_mainFrame->coreFrame();
606     if (!frame)
607         return;
608     return frame->setPageAndTextZoomFactors(static_cast<float>(pageZoomFactor), static_cast<float>(textZoomFactor));
609 }
610
611 void WebPage::scaleWebView(double scale, const IntPoint& origin)
612 {
613     Frame* frame = m_mainFrame->coreFrame();
614     if (!frame)
615         return;
616     frame->scalePage(scale, origin);
617
618     send(Messages::WebPageProxy::ViewScaleFactorDidChange(scale));
619 }
620
621 double WebPage::viewScaleFactor() const
622 {
623     Frame* frame = m_mainFrame->coreFrame();
624     if (!frame)
625         return 1;
626     return frame->pageScaleFactor();
627 }
628
629 void WebPage::setUseFixedLayout(bool fixed)
630 {
631     Frame* frame = m_mainFrame->coreFrame();
632     if (!frame)
633         return;
634
635     FrameView* view = frame->view();
636     if (!view)
637         return;
638
639     view->setUseFixedLayout(fixed);
640     if (!fixed)
641         view->setFixedLayoutSize(IntSize());
642 }
643
644 void WebPage::setFixedLayoutSize(const IntSize& size)
645 {
646     Frame* frame = m_mainFrame->coreFrame();
647     if (!frame)
648         return;
649     
650     FrameView* view = frame->view();
651     if (!view)
652         return;
653
654     view->setFixedLayoutSize(size);
655     view->forceLayout();
656 }
657
658 void WebPage::installPageOverlay(PassRefPtr<PageOverlay> pageOverlay)
659 {
660     if (m_pageOverlay)
661         pageOverlay->setPage(0);
662
663     m_pageOverlay = pageOverlay;
664     m_pageOverlay->setPage(this);
665     m_pageOverlay->setNeedsDisplay();
666 }
667
668 void WebPage::uninstallPageOverlay(PageOverlay* pageOverlay)
669 {
670     if (pageOverlay != m_pageOverlay)
671         return;
672
673     m_pageOverlay->setPage(0);
674     m_pageOverlay = nullptr;
675     m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), m_viewSize));
676 }
677
678 PassRefPtr<WebImage> WebPage::snapshotInViewCoordinates(const IntRect& rect, ImageOptions options)
679 {
680     FrameView* frameView = m_mainFrame->coreFrame()->view();
681     if (!frameView)
682         return 0;
683
684     frameView->updateLayoutAndStyleIfNeededRecursive();
685
686     PaintBehavior oldBehavior = frameView->paintBehavior();
687     frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
688
689     RefPtr<WebImage> snapshot = WebImage::create(rect.size(), options);
690     OwnPtr<WebCore::GraphicsContext> graphicsContext = snapshot->bitmap()->createGraphicsContext();
691
692     graphicsContext->save();
693     graphicsContext->translate(-rect.x(), -rect.y());
694     frameView->paint(graphicsContext.get(), rect);
695     graphicsContext->restore();
696
697     frameView->setPaintBehavior(oldBehavior);
698
699     return snapshot.release();
700 }
701
702 PassRefPtr<WebImage> WebPage::snapshotInDocumentCoordinates(const IntRect& rect, ImageOptions options)
703 {
704     FrameView* frameView = m_mainFrame->coreFrame()->view();
705     if (!frameView)
706         return 0;
707
708     frameView->updateLayoutAndStyleIfNeededRecursive();
709
710     PaintBehavior oldBehavior = frameView->paintBehavior();
711     frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
712
713     RefPtr<WebImage> snapshot = WebImage::create(rect.size(), options);
714     OwnPtr<WebCore::GraphicsContext> graphicsContext = snapshot->bitmap()->createGraphicsContext();
715
716     graphicsContext->save();
717     graphicsContext->translate(-rect.x(), -rect.y());
718     frameView->paintContents(graphicsContext.get(), rect);
719     graphicsContext->restore();
720
721     frameView->setPaintBehavior(oldBehavior);
722
723     return snapshot.release();
724 }
725
726 void WebPage::pageDidScroll()
727 {
728     // Hide the find indicator.
729     m_findController.hideFindIndicator();
730
731     m_uiClient.pageDidScroll(this);
732
733     send(Messages::WebPageProxy::PageDidScroll());
734 }
735
736 #if ENABLE(TILED_BACKING_STORE)
737 void WebPage::pageDidRequestScroll(const IntSize& delta)
738 {
739     send(Messages::WebPageProxy::PageDidRequestScroll(delta));
740 }
741 #endif
742
743 WebContextMenu* WebPage::contextMenu()
744 {
745     if (!m_contextMenu)
746         m_contextMenu = WebContextMenu::create(this);
747     return m_contextMenu.get();
748 }
749
750 void WebPage::getLocationAndLengthFromRange(Range* range, uint64_t& location, uint64_t& length)
751 {
752     location = notFound;
753     length = 0;
754
755     if (!range || !range->startContainer())
756         return;
757
758     Element* selectionRoot = range->ownerDocument()->frame()->selection()->rootEditableElement();
759     Element* scope = selectionRoot ? selectionRoot : range->ownerDocument()->documentElement();
760     
761     // Mouse events may cause TSM to attempt to create an NSRange for a portion of the view
762     // that is not inside the current editable region.  These checks ensure we don't produce
763     // potentially invalid data when responding to such requests.
764     if (range->startContainer() != scope && !range->startContainer()->isDescendantOf(scope))
765         return;
766     if (range->endContainer() != scope && !range->endContainer()->isDescendantOf(scope))
767         return;
768
769     RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
770     ASSERT(testRange->startContainer() == scope);
771     location = TextIterator::rangeLength(testRange.get());
772     
773     ExceptionCode ec;
774     testRange->setEnd(range->endContainer(), range->endOffset(), ec);
775     ASSERT(testRange->startContainer() == scope);
776     length = TextIterator::rangeLength(testRange.get()) - location;
777 }
778
779 // Events 
780
781 static const WebEvent* g_currentEvent = 0;
782
783 // FIXME: WebPage::currentEvent is used by the plug-in code to avoid having to convert from DOM events back to
784 // WebEvents. When we get the event handling sorted out, this should go away and the Widgets should get the correct
785 // platform events passed to the event handler code.
786 const WebEvent* WebPage::currentEvent()
787 {
788     return g_currentEvent;
789 }
790
791 class CurrentEvent {
792 public:
793     explicit CurrentEvent(const WebEvent& event)
794         : m_previousCurrentEvent(g_currentEvent)
795     {
796         g_currentEvent = &event;
797     }
798
799     ~CurrentEvent()
800     {
801         g_currentEvent = m_previousCurrentEvent;
802     }
803
804 private:
805     const WebEvent* m_previousCurrentEvent;
806 };
807
808 static bool isContextClick(const PlatformMouseEvent& event)
809 {
810     if (event.button() == WebCore::RightButton)
811         return true;
812
813 #if PLATFORM(MAC)
814     // FIXME: this really should be about OSX-style UI, not about the Mac port
815     if (event.button() == WebCore::LeftButton && event.ctrlKey())
816         return true;
817 #endif
818
819     return false;
820 }
821
822 static bool handleMouseEvent(const WebMouseEvent& mouseEvent, Page* page)
823 {
824     Frame* frame = page->mainFrame();
825     if (!frame->view())
826         return false;
827
828     PlatformMouseEvent platformMouseEvent = platform(mouseEvent);
829
830     switch (platformMouseEvent.eventType()) {
831         case WebCore::MouseEventPressed:
832         {
833             if (isContextClick(platformMouseEvent))
834                 page->contextMenuController()->clearContextMenu();
835             
836             bool handled = frame->eventHandler()->handleMousePressEvent(platformMouseEvent);
837             
838             if (isContextClick(platformMouseEvent)) {
839                 handled = frame->eventHandler()->sendContextMenuEvent(platformMouseEvent);
840                 if (handled)
841                     page->chrome()->showContextMenu();
842             }
843
844             return handled;
845         }
846         case WebCore::MouseEventReleased:
847             return frame->eventHandler()->handleMouseReleaseEvent(platformMouseEvent);
848         case WebCore::MouseEventMoved:
849             return frame->eventHandler()->mouseMoved(platformMouseEvent);
850
851         default:
852             ASSERT_NOT_REACHED();
853             return false;
854     }
855 }
856
857 void WebPage::mouseEvent(const WebMouseEvent& mouseEvent)
858 {
859     bool handled = false;
860     
861     if (m_pageOverlay) {
862         // Let the page overlay handle the event.
863         handled = m_pageOverlay->mouseEvent(mouseEvent);
864     }
865
866     if (!handled) {
867         CurrentEvent currentEvent(mouseEvent);
868
869         handled = handleMouseEvent(mouseEvent, m_page.get());
870     }
871
872     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(mouseEvent.type()), handled));
873 }
874
875 static bool handleWheelEvent(const WebWheelEvent& wheelEvent, Page* page)
876 {
877     Frame* frame = page->mainFrame();
878     if (!frame->view())
879         return false;
880
881     PlatformWheelEvent platformWheelEvent = platform(wheelEvent);
882     return frame->eventHandler()->handleWheelEvent(platformWheelEvent);
883 }
884
885 void WebPage::wheelEvent(const WebWheelEvent& wheelEvent)
886 {
887     CurrentEvent currentEvent(wheelEvent);
888
889     bool handled = handleWheelEvent(wheelEvent, m_page.get());
890     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(wheelEvent.type()), handled));
891 }
892
893 static bool handleKeyEvent(const WebKeyboardEvent& keyboardEvent, Page* page)
894 {
895     if (!page->mainFrame()->view())
896         return false;
897
898     if (keyboardEvent.type() == WebEvent::Char && keyboardEvent.isSystemKey())
899         return page->focusController()->focusedOrMainFrame()->eventHandler()->handleAccessKey(platform(keyboardEvent));
900     return page->focusController()->focusedOrMainFrame()->eventHandler()->keyEvent(platform(keyboardEvent));
901 }
902
903 void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
904 {
905     CurrentEvent currentEvent(keyboardEvent);
906
907     bool handled = handleKeyEvent(keyboardEvent, m_page.get());
908     if (!handled)
909         handled = performDefaultBehaviorForKeyEvent(keyboardEvent);
910
911     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(keyboardEvent.type()), handled));
912 }
913
914 void WebPage::validateMenuItem(const String& commandName)
915 {
916     bool isEnabled = false;
917     int32_t state = 0;
918     Frame* frame = m_page->focusController()->focusedOrMainFrame();
919     if (frame) {
920         Editor::Command command = frame->editor()->command(commandName);
921         state = command.state();
922         isEnabled = command.isSupported() && command.isEnabled();
923     }
924
925     send(Messages::WebPageProxy::DidValidateMenuItem(commandName, isEnabled, state));
926 }
927
928 void WebPage::executeEditCommand(const String& commandName)
929 {
930     executeEditingCommand(commandName, String());
931 }
932
933 uint64_t WebPage::restoreSession(const SessionState& sessionState)
934 {
935     const BackForwardListItemVector& list = sessionState.list();
936     size_t size = list.size();
937     uint64_t currentItemID = 0;
938     for (size_t i = 0; i < size; ++i) {
939         WebBackForwardListItem* webItem = list[i].get();
940         DecoderAdapter decoder(webItem->backForwardData().data(), webItem->backForwardData().size());
941         
942         RefPtr<HistoryItem> item = HistoryItem::decodeBackForwardTree(webItem->url(), webItem->title(), webItem->originalURL(), decoder);
943         if (!item) {
944             LOG_ERROR("Failed to decode a HistoryItem from session state data.");
945             return 0;
946         }
947         
948         if (i == sessionState.currentIndex())
949             currentItemID = webItem->itemID();
950         
951         WebBackForwardListProxy::addItemFromUIProcess(list[i]->itemID(), item.release());
952     }    
953     ASSERT(currentItemID);
954     return currentItemID;
955 }
956
957 void WebPage::restoreSessionAndNavigateToCurrentItem(const SessionState& sessionState)
958 {
959     if (uint64_t currentItemID = restoreSession(sessionState))
960         goToBackForwardItem(currentItemID);
961 }
962
963 #if ENABLE(TOUCH_EVENTS)
964 static bool handleTouchEvent(const WebTouchEvent& touchEvent, Page* page)
965 {
966     Frame* frame = page->mainFrame();
967     if (!frame->view())
968         return false;
969
970     return frame->eventHandler()->handleTouchEvent(platform(touchEvent));
971 }
972
973 void WebPage::touchEvent(const WebTouchEvent& touchEvent)
974 {
975     CurrentEvent currentEvent(touchEvent);
976
977     bool handled = handleTouchEvent(touchEvent, m_page.get());
978
979     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(touchEvent.type()), handled));
980 }
981 #endif
982
983 void WebPage::setActive(bool isActive)
984 {
985     m_page->focusController()->setActive(isActive);
986
987 #if PLATFORM(MAC)    
988     // Tell all our plug-in views that the window focus changed.
989     for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
990         (*it)->setWindowIsFocused(isActive);
991 #endif
992 }
993
994 void WebPage::setDrawsBackground(bool drawsBackground)
995 {
996     if (m_drawsBackground == drawsBackground)
997         return;
998
999     m_drawsBackground = drawsBackground;
1000
1001     for (Frame* coreFrame = m_mainFrame->coreFrame(); coreFrame; coreFrame = coreFrame->tree()->traverseNext()) {
1002         if (FrameView* view = coreFrame->view())
1003             view->setTransparent(!drawsBackground);
1004     }
1005
1006     m_drawingArea->pageBackgroundTransparencyChanged();
1007     m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), m_viewSize));
1008 }
1009
1010 void WebPage::setDrawsTransparentBackground(bool drawsTransparentBackground)
1011 {
1012     if (m_drawsTransparentBackground == drawsTransparentBackground)
1013         return;
1014
1015     m_drawsTransparentBackground = drawsTransparentBackground;
1016
1017     Color backgroundColor = drawsTransparentBackground ? Color::transparent : Color::white;
1018     for (Frame* coreFrame = m_mainFrame->coreFrame(); coreFrame; coreFrame = coreFrame->tree()->traverseNext()) {
1019         if (FrameView* view = coreFrame->view())
1020             view->setBaseBackgroundColor(backgroundColor);
1021     }
1022
1023     m_drawingArea->pageBackgroundTransparencyChanged();
1024     m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), m_viewSize));
1025 }
1026
1027 void WebPage::setFocused(bool isFocused)
1028 {
1029     m_page->focusController()->setFocused(isFocused);
1030 }
1031
1032 void WebPage::setInitialFocus(bool forward)
1033 {
1034     if (!m_page || !m_page->focusController())
1035         return;
1036
1037     Frame* frame = m_page->focusController()->focusedOrMainFrame();
1038     frame->document()->setFocusedNode(0);
1039     m_page->focusController()->setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, 0);
1040 }
1041
1042 void WebPage::setWindowResizerSize(const IntSize& windowResizerSize)
1043 {
1044     if (m_windowResizerSize == windowResizerSize)
1045         return;
1046
1047     m_windowResizerSize = windowResizerSize;
1048
1049     for (Frame* coreFrame = m_mainFrame->coreFrame(); coreFrame; coreFrame = coreFrame->tree()->traverseNext()) {
1050         FrameView* view = coreFrame->view();
1051         if (view)
1052             view->windowResizerRectChanged();
1053     }
1054 }
1055
1056 void WebPage::setIsInWindow(bool isInWindow)
1057 {
1058     if (!isInWindow) {
1059         m_page->setCanStartMedia(false);
1060         m_page->willMoveOffscreen();
1061     } else {
1062         m_page->setCanStartMedia(true);
1063         m_page->didMoveOnscreen();
1064     }
1065 }
1066
1067 void WebPage::didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t downloadID)
1068 {
1069     WebFrame* frame = WebProcess::shared().webFrame(frameID);
1070     if (!frame)
1071         return;
1072     frame->didReceivePolicyDecision(listenerID, static_cast<PolicyAction>(policyAction), downloadID);
1073 }
1074
1075 void WebPage::show()
1076 {
1077     send(Messages::WebPageProxy::ShowPage());
1078 }
1079
1080 void WebPage::setUserAgent(const String& userAgent)
1081 {
1082     m_userAgent = userAgent;
1083 }
1084
1085 IntRect WebPage::windowResizerRect() const
1086 {
1087     if (m_windowResizerSize.isEmpty())
1088         return IntRect();
1089
1090     IntSize frameViewSize;
1091     if (Frame* coreFrame = m_mainFrame->coreFrame()) {
1092         if (FrameView* view = coreFrame->view())
1093             frameViewSize = view->size();
1094     }
1095
1096     return IntRect(frameViewSize.width() - m_windowResizerSize.width(), frameViewSize.height() - m_windowResizerSize.height(), 
1097                    m_windowResizerSize.width(), m_windowResizerSize.height());
1098 }
1099
1100 void WebPage::runJavaScriptInMainFrame(const String& script, uint64_t callbackID)
1101 {
1102     // NOTE: We need to be careful when running scripts that the objects we depend on don't
1103     // disappear during script execution.
1104
1105     JSLock lock(SilenceAssertionsOnly);
1106     JSValue resultValue = m_mainFrame->coreFrame()->script()->executeScript(script, true).jsValue();
1107     String resultString;
1108     if (resultValue)
1109         resultString = ustringToString(resultValue.toString(m_mainFrame->coreFrame()->script()->globalObject(mainThreadNormalWorld())->globalExec()));
1110
1111     send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
1112 }
1113
1114 void WebPage::getContentsAsString(uint64_t callbackID)
1115 {
1116     String resultString = m_mainFrame->contentsAsString();
1117     send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
1118 }
1119
1120 void WebPage::getRenderTreeExternalRepresentation(uint64_t callbackID)
1121 {
1122     String resultString = renderTreeExternalRepresentation();
1123     send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
1124 }
1125
1126 void WebPage::getSelectionOrContentsAsString(uint64_t callbackID)
1127 {
1128     String resultString = m_mainFrame->selectionAsString();
1129     if (resultString.isEmpty())
1130         resultString = m_mainFrame->contentsAsString();
1131     send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
1132 }
1133
1134 void WebPage::getSourceForFrame(uint64_t frameID, uint64_t callbackID)
1135 {
1136     String resultString;
1137     if (WebFrame* frame = WebProcess::shared().webFrame(frameID))
1138        resultString = frame->source();
1139
1140     send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
1141 }
1142
1143 void WebPage::getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID)
1144 {
1145     CoreIPC::DataReference dataReference;
1146
1147     RefPtr<SharedBuffer> buffer;
1148     if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
1149         if (DocumentLoader* loader = frame->coreFrame()->loader()->documentLoader()) {
1150             if ((buffer = loader->mainResourceData()))
1151                 dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
1152         }
1153     }
1154
1155     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
1156 }
1157
1158 void WebPage::getResourceDataFromFrame(uint64_t frameID, const String& resourceURL, uint64_t callbackID)
1159 {
1160     CoreIPC::DataReference dataReference;
1161
1162     RefPtr<SharedBuffer> buffer;
1163     if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
1164         if (DocumentLoader* loader = frame->coreFrame()->loader()->documentLoader()) {
1165             if (RefPtr<ArchiveResource> subresource = loader->subresource(KURL(KURL(), resourceURL))) {
1166                 if ((buffer = subresource->data()))
1167                     dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
1168             }
1169         }
1170     }
1171
1172     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
1173 }
1174
1175 void WebPage::getWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID)
1176 {
1177     CoreIPC::DataReference dataReference;
1178
1179 #if PLATFORM(MAC) || PLATFORM(WIN)
1180     RetainPtr<CFDataRef> data;
1181     if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
1182         if (RefPtr<LegacyWebArchive> archive = LegacyWebArchive::create(frame->coreFrame())) {
1183             if ((data = archive->rawDataRepresentation()))
1184                 dataReference = CoreIPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
1185         }
1186     }
1187 #endif
1188
1189     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
1190 }
1191
1192 void WebPage::forceRepaint(uint64_t callbackID)
1193 {
1194     m_drawingArea->forceRepaint();
1195     send(Messages::WebPageProxy::VoidCallback(callbackID));
1196 }
1197     
1198 void WebPage::preferencesDidChange(const WebPreferencesStore& store)
1199 {
1200     WebPreferencesStore::removeTestRunnerOverrides();
1201     updatePreferences(store);
1202 }
1203
1204 void WebPage::updatePreferences(const WebPreferencesStore& store)
1205 {
1206     Settings* settings = m_page->settings();
1207
1208     m_tabToLinks = store.getBoolValueForKey(WebPreferencesKey::tabsToLinksKey());
1209
1210     // FIXME: This should be generated from macro expansion for all preferences,
1211     // but we currently don't match the naming of WebCore exactly so we are
1212     // handrolling the boolean and integer preferences until that is fixed.
1213
1214 #define INITIALIZE_SETTINGS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) settings->set##KeyUpper(store.get##TypeName##ValueForKey(WebPreferencesKey::KeyLower##Key()));
1215
1216     FOR_EACH_WEBKIT_STRING_PREFERENCE(INITIALIZE_SETTINGS)
1217
1218 #undef INITIALIZE_SETTINGS
1219
1220     settings->setJavaScriptEnabled(store.getBoolValueForKey(WebPreferencesKey::javaScriptEnabledKey()));
1221     settings->setLoadsImagesAutomatically(store.getBoolValueForKey(WebPreferencesKey::loadsImagesAutomaticallyKey()));
1222     settings->setPluginsEnabled(store.getBoolValueForKey(WebPreferencesKey::pluginsEnabledKey()));
1223     settings->setJavaEnabled(store.getBoolValueForKey(WebPreferencesKey::javaEnabledKey()));
1224     settings->setOfflineWebApplicationCacheEnabled(store.getBoolValueForKey(WebPreferencesKey::offlineWebApplicationCacheEnabledKey()));
1225     settings->setLocalStorageEnabled(store.getBoolValueForKey(WebPreferencesKey::localStorageEnabledKey()));
1226     settings->setXSSAuditorEnabled(store.getBoolValueForKey(WebPreferencesKey::xssAuditorEnabledKey()));
1227     settings->setFrameFlatteningEnabled(store.getBoolValueForKey(WebPreferencesKey::frameFlatteningEnabledKey()));
1228     settings->setPrivateBrowsingEnabled(store.getBoolValueForKey(WebPreferencesKey::privateBrowsingEnabledKey()));
1229     settings->setDeveloperExtrasEnabled(store.getBoolValueForKey(WebPreferencesKey::developerExtrasEnabledKey()));
1230     settings->setTextAreasAreResizable(store.getBoolValueForKey(WebPreferencesKey::textAreasAreResizableKey()));
1231     settings->setNeedsSiteSpecificQuirks(store.getBoolValueForKey(WebPreferencesKey::needsSiteSpecificQuirksKey()));
1232     settings->setJavaScriptCanOpenWindowsAutomatically(store.getBoolValueForKey(WebPreferencesKey::javaScriptCanOpenWindowsAutomaticallyKey()));
1233     settings->setForceFTPDirectoryListings(store.getBoolValueForKey(WebPreferencesKey::forceFTPDirectoryListingsKey()));
1234     settings->setDNSPrefetchingEnabled(store.getBoolValueForKey(WebPreferencesKey::dnsPrefetchingEnabledKey()));
1235     settings->setWebArchiveDebugModeEnabled(store.getBoolValueForKey(WebPreferencesKey::webArchiveDebugModeEnabledKey()));
1236     settings->setLocalFileContentSniffingEnabled(store.getBoolValueForKey(WebPreferencesKey::localFileContentSniffingEnabledKey()));
1237     settings->setUsesPageCache(store.getBoolValueForKey(WebPreferencesKey::usesPageCacheKey()));
1238     settings->setAuthorAndUserStylesEnabled(store.getBoolValueForKey(WebPreferencesKey::authorAndUserStylesEnabledKey()));
1239     settings->setPaginateDuringLayoutEnabled(store.getBoolValueForKey(WebPreferencesKey::paginateDuringLayoutEnabledKey()));
1240     settings->setDOMPasteAllowed(store.getBoolValueForKey(WebPreferencesKey::domPasteAllowedKey()));
1241     settings->setShouldPrintBackgrounds(store.getBoolValueForKey(WebPreferencesKey::shouldPrintBackgroundsKey()));
1242
1243     settings->setMinimumFontSize(store.getUInt32ValueForKey(WebPreferencesKey::minimumFontSizeKey()));
1244     settings->setMinimumLogicalFontSize(store.getUInt32ValueForKey(WebPreferencesKey::minimumLogicalFontSizeKey()));
1245     settings->setDefaultFontSize(store.getUInt32ValueForKey(WebPreferencesKey::defaultFontSizeKey()));
1246     settings->setDefaultFixedFontSize(store.getUInt32ValueForKey(WebPreferencesKey::defaultFixedFontSizeKey()));
1247
1248 #if PLATFORM(WIN)
1249     // Temporarily turn off accelerated compositing until we have a good solution for rendering it.
1250     settings->setAcceleratedCompositingEnabled(false);
1251 #else
1252     settings->setAcceleratedCompositingEnabled(store.getBoolValueForKey(WebPreferencesKey::acceleratedCompositingEnabledKey()));
1253 #endif
1254     settings->setShowDebugBorders(store.getBoolValueForKey(WebPreferencesKey::compositingBordersVisibleKey()));
1255     settings->setShowRepaintCounter(store.getBoolValueForKey(WebPreferencesKey::compositingRepaintCountersVisibleKey()));
1256
1257 #if ENABLE(DATABASE)
1258     AbstractDatabase::setIsAvailable(store.getBoolValueForKey(WebPreferencesKey::databasesEnabledKey()));
1259 #endif
1260
1261     platformPreferencesDidChange(store);
1262 }
1263
1264 #if ENABLE(INSPECTOR)
1265 WebInspector* WebPage::inspector()
1266 {
1267     if (m_isClosed)
1268         return 0;
1269     if (!m_inspector)
1270         m_inspector = adoptPtr(new WebInspector(this));
1271     return m_inspector.get();
1272 }
1273 #endif
1274
1275 #if !PLATFORM(MAC)
1276 bool WebPage::handleEditingKeyboardEvent(KeyboardEvent* evt)
1277 {
1278     Node* node = evt->target()->toNode();
1279     ASSERT(node);
1280     Frame* frame = node->document()->frame();
1281     ASSERT(frame);
1282
1283     const PlatformKeyboardEvent* keyEvent = evt->keyEvent();
1284     if (!keyEvent)
1285         return false;
1286
1287     Editor::Command command = frame->editor()->command(interpretKeyEvent(evt));
1288
1289     if (keyEvent->type() == PlatformKeyboardEvent::RawKeyDown) {
1290         // WebKit doesn't have enough information about mode to decide how commands that just insert text if executed via Editor should be treated,
1291         // so we leave it upon WebCore to either handle them immediately (e.g. Tab that changes focus) or let a keypress event be generated
1292         // (e.g. Tab that inserts a Tab character, or Enter).
1293         return !command.isTextInsertion() && command.execute(evt);
1294     }
1295
1296     if (command.execute(evt))
1297         return true;
1298
1299     // Don't insert null or control characters as they can result in unexpected behaviour
1300     if (evt->charCode() < ' ')
1301         return false;
1302
1303     return frame->editor()->insertText(evt->keyEvent()->text(), evt);
1304 }
1305 #endif
1306
1307 void WebPage::performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const String& dragStorageName, uint32_t flags)
1308 {
1309     if (!m_page) {
1310         send(Messages::WebPageProxy::DidPerformDragControllerAction(DragOperationNone));
1311         return;
1312     }
1313
1314     DragData dragData(dragStorageName, clientPosition, globalPosition, static_cast<DragOperation>(draggingSourceOperationMask), static_cast<DragApplicationFlags>(flags));
1315     switch (action) {
1316     case DragControllerActionEntered:
1317         send(Messages::WebPageProxy::DidPerformDragControllerAction(m_page->dragController()->dragEntered(&dragData)));
1318         break;
1319
1320     case DragControllerActionUpdated:
1321         send(Messages::WebPageProxy::DidPerformDragControllerAction(m_page->dragController()->dragUpdated(&dragData)));
1322         break;
1323         
1324     case DragControllerActionExited:
1325         m_page->dragController()->dragExited(&dragData);
1326         break;
1327         
1328     case DragControllerActionPerformDrag:
1329         m_page->dragController()->performDrag(&dragData);
1330         break;
1331         
1332     default:
1333         ASSERT_NOT_REACHED();
1334     }
1335 }
1336
1337 void WebPage::dragEnded(WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t operation)
1338 {
1339     IntPoint adjustedClientPosition(clientPosition.x() + m_page->dragController()->dragOffset().x(), clientPosition.y() + m_page->dragController()->dragOffset().y());
1340     IntPoint adjustedGlobalPosition(globalPosition.x() + m_page->dragController()->dragOffset().x(), globalPosition.y() + m_page->dragController()->dragOffset().y());
1341     
1342     m_page->dragController()->dragEnded();
1343     FrameView* view = m_page->mainFrame()->view();
1344     if (!view)
1345         return;
1346     // FIXME: These are fake modifier keys here, but they should be real ones instead.
1347     PlatformMouseEvent event(adjustedClientPosition, adjustedGlobalPosition, LeftButton, MouseEventMoved, 0, false, false, false, false, currentTime());
1348     m_page->mainFrame()->eventHandler()->dragSourceEndedAt(event, (DragOperation)operation);
1349 }
1350
1351 WebEditCommand* WebPage::webEditCommand(uint64_t commandID)
1352 {
1353     return m_editCommandMap.get(commandID).get();
1354 }
1355
1356 void WebPage::addWebEditCommand(uint64_t commandID, WebEditCommand* command)
1357 {
1358     m_editCommandMap.set(commandID, command);
1359 }
1360
1361 void WebPage::removeWebEditCommand(uint64_t commandID)
1362 {
1363     m_editCommandMap.remove(commandID);
1364 }
1365
1366 void WebPage::unapplyEditCommand(uint64_t commandID)
1367 {
1368     WebEditCommand* command = webEditCommand(commandID);
1369     if (!command)
1370         return;
1371
1372     command->command()->unapply();
1373 }
1374
1375 void WebPage::reapplyEditCommand(uint64_t commandID)
1376 {
1377     WebEditCommand* command = webEditCommand(commandID);
1378     if (!command)
1379         return;
1380
1381     m_isInRedo = true;
1382     command->command()->reapply();
1383     m_isInRedo = false;
1384 }
1385
1386 void WebPage::didRemoveEditCommand(uint64_t commandID)
1387 {
1388     removeWebEditCommand(commandID);
1389 }
1390
1391 void WebPage::setActivePopupMenu(WebPopupMenu* menu)
1392 {
1393     m_activePopupMenu = menu;
1394 }
1395
1396 void WebPage::setActiveOpenPanelResultListener(PassRefPtr<WebOpenPanelResultListener> openPanelResultListener)
1397 {
1398     m_activeOpenPanelResultListener = openPanelResultListener;
1399 }
1400
1401 bool WebPage::findStringFromInjectedBundle(const String& target, FindOptions options)
1402 {
1403     return m_page->findString(target, options);
1404 }
1405
1406 void WebPage::findString(const String& string, uint32_t options, uint32_t maxMatchCount)
1407 {
1408     m_findController.findString(string, static_cast<FindOptions>(options), maxMatchCount);
1409 }
1410
1411 void WebPage::hideFindUI()
1412 {
1413     m_findController.hideFindUI();
1414 }
1415
1416 void WebPage::countStringMatches(const String& string, uint32_t options, uint32_t maxMatchCount)
1417 {
1418     m_findController.countStringMatches(string, static_cast<FindOptions>(options), maxMatchCount);
1419 }
1420
1421 void WebPage::didChangeSelectedIndexForActivePopupMenu(int32_t newIndex)
1422 {
1423     if (!m_activePopupMenu)
1424         return;
1425
1426     m_activePopupMenu->didChangeSelectedIndex(newIndex);
1427     m_activePopupMenu = 0;
1428 }
1429
1430 void WebPage::didChooseFilesForOpenPanel(const Vector<String>& files)
1431 {
1432     if (!m_activeOpenPanelResultListener)
1433         return;
1434
1435     m_activeOpenPanelResultListener->didChooseFiles(files);
1436     m_activeOpenPanelResultListener = 0;
1437 }
1438
1439 void WebPage::didCancelForOpenPanel()
1440 {
1441     m_activeOpenPanelResultListener = 0;
1442 }
1443
1444 void WebPage::didReceiveGeolocationPermissionDecision(uint64_t geolocationID, bool allowed)
1445 {
1446     m_geolocationPermissionRequestManager.didReceiveGeolocationPermissionDecision(geolocationID, allowed);
1447 }
1448
1449 void WebPage::advanceToNextMisspelling(bool startBeforeSelection)
1450 {
1451     Frame* frame = m_page->focusController()->focusedOrMainFrame();
1452     frame->editor()->advanceToNextMisspelling(startBeforeSelection);
1453 }
1454
1455 void WebPage::changeSpellingToWord(const String& word)
1456 {
1457     replaceSelectionWithText(m_page->focusController()->focusedOrMainFrame(), word);
1458 }
1459
1460 void WebPage::unmarkAllMisspellings()
1461 {
1462     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1463         if (Document* document = frame->document())
1464             document->markers()->removeMarkers(DocumentMarker::Spelling);
1465     }
1466 }
1467
1468 void WebPage::unmarkAllBadGrammar()
1469 {
1470     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1471         if (Document* document = frame->document())
1472             document->markers()->removeMarkers(DocumentMarker::Grammar);
1473     }
1474 }
1475
1476 #if PLATFORM(MAC)
1477 void WebPage::uppercaseWord()
1478 {
1479     m_page->focusController()->focusedOrMainFrame()->editor()->uppercaseWord();
1480 }
1481
1482 void WebPage::lowercaseWord()
1483 {
1484     m_page->focusController()->focusedOrMainFrame()->editor()->lowercaseWord();
1485 }
1486
1487 void WebPage::capitalizeWord()
1488 {
1489     m_page->focusController()->focusedOrMainFrame()->editor()->capitalizeWord();
1490 }
1491 #endif
1492     
1493 void WebPage::setTextForActivePopupMenu(int32_t index)
1494 {
1495     if (!m_activePopupMenu)
1496         return;
1497
1498     m_activePopupMenu->setTextForIndex(index);
1499 }
1500
1501 void WebPage::didSelectItemFromActiveContextMenu(const WebContextMenuItemData& item)
1502 {
1503     ASSERT(m_contextMenu);
1504     m_contextMenu->itemSelected(item);
1505     m_contextMenu = 0;
1506 }
1507
1508 void WebPage::replaceSelectionWithText(Frame* frame, const String& text)
1509 {
1510     if (frame->selection()->isNone())
1511         return;
1512     
1513     RefPtr<DocumentFragment> textFragment = createFragmentFromText(frame->selection()->toNormalizedRange().get(), text);
1514     applyCommand(ReplaceSelectionCommand::create(frame->document(), textFragment.release(), true, false, true));
1515     frame->selection()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
1516 }
1517
1518 bool WebPage::mainFrameHasCustomRepresentation() const
1519 {
1520     return static_cast<WebFrameLoaderClient*>(mainFrame()->coreFrame()->loader()->client())->frameHasCustomRepresentation();
1521 }
1522
1523 #if PLATFORM(MAC)
1524
1525 void WebPage::addPluginView(PluginView* pluginView)
1526 {
1527     ASSERT(!m_pluginViews.contains(pluginView));
1528
1529     m_pluginViews.add(pluginView);
1530 }
1531
1532 void WebPage::removePluginView(PluginView* pluginView)
1533 {
1534     ASSERT(m_pluginViews.contains(pluginView));
1535
1536     m_pluginViews.remove(pluginView);
1537 }
1538
1539 void WebPage::setWindowIsVisible(bool windowIsVisible)
1540 {
1541     m_windowIsVisible = windowIsVisible;
1542
1543     // Tell all our plug-in views that the window visibility changed.
1544     for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
1545         (*it)->setWindowIsVisible(windowIsVisible);
1546 }
1547
1548 void WebPage::windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates, const WebCore::IntPoint& accessibilityViewCoordinates)
1549 {
1550     m_windowFrameInScreenCoordinates = windowFrameInScreenCoordinates;
1551     m_viewFrameInWindowCoordinates = viewFrameInWindowCoordinates;
1552     m_accessibilityPosition = accessibilityViewCoordinates;
1553     
1554     // Tell all our plug-in views that the window and view frames have changed.
1555     for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
1556         (*it)->windowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates);
1557 }
1558
1559 bool WebPage::windowIsFocused() const
1560 {
1561     return m_page->focusController()->isActive();
1562 }
1563
1564 #endif
1565
1566 void WebPage::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
1567 {
1568     if (messageID.is<CoreIPC::MessageClassDrawingAreaLegacy>()) {
1569         if (m_drawingArea)
1570             m_drawingArea->didReceiveMessage(connection, messageID, arguments);
1571         return;
1572     }
1573
1574 #ifdef __APPLE__
1575     if (messageID.is<CoreIPC::MessageClassDrawingArea>()) {
1576         if (m_drawingArea)
1577             m_drawingArea->didReceiveDrawingAreaMessage(connection, messageID, arguments);
1578         return;
1579     }
1580 #endif
1581     
1582 #if ENABLE(INSPECTOR)
1583     if (messageID.is<CoreIPC::MessageClassWebInspector>()) {
1584         if (WebInspector* inspector = this->inspector())
1585             inspector->didReceiveWebInspectorMessage(connection, messageID, arguments);
1586         return;
1587     }
1588 #endif
1589
1590     didReceiveWebPageMessage(connection, messageID, arguments);
1591 }
1592
1593 CoreIPC::SyncReplyMode WebPage::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply)
1594 {   
1595     return didReceiveSyncWebPageMessage(connection, messageID, arguments, reply);
1596 }
1597     
1598 InjectedBundleBackForwardList* WebPage::backForwardList()
1599 {
1600     if (!m_backForwardList)
1601         m_backForwardList = InjectedBundleBackForwardList::create(this);
1602     return m_backForwardList.get();
1603 }
1604
1605 #if PLATFORM(QT)
1606 void WebPage::findZoomableAreaForPoint(const WebCore::IntPoint& point)
1607 {
1608     const int minimumZoomTargetWidth = 100;
1609
1610     Frame* mainframe = m_mainFrame->coreFrame();
1611     HitTestResult result = mainframe->eventHandler()->hitTestResultAtPoint(mainframe->view()->windowToContents(point), /*allowShadowContent*/ false, /*ignoreClipping*/ true);
1612
1613     Node* node = result.innerNode();
1614     while (node && node->getRect().width() < minimumZoomTargetWidth)
1615         node = node->parentNode();
1616
1617     IntRect zoomableArea;
1618     if (node)
1619         zoomableArea = node->getRect();
1620     send(Messages::WebPageProxy::DidFindZoomableArea(zoomableArea));
1621 }
1622 #endif
1623
1624 WebPage::SandboxExtensionTracker::~SandboxExtensionTracker()
1625 {
1626     invalidate();
1627 }
1628
1629 void WebPage::SandboxExtensionTracker::invalidate()
1630 {
1631     if (m_pendingProvisionalSandboxExtension) {
1632         m_pendingProvisionalSandboxExtension->invalidate();
1633         m_pendingProvisionalSandboxExtension = 0;
1634     }
1635
1636     if (m_provisionalSandboxExtension) {
1637         m_provisionalSandboxExtension->invalidate();
1638         m_provisionalSandboxExtension = 0;
1639     }
1640
1641     if (m_committedSandboxExtension) {
1642         m_committedSandboxExtension->invalidate();
1643         m_committedSandboxExtension = 0;
1644     }
1645 }
1646
1647 void WebPage::SandboxExtensionTracker::beginLoad(WebFrame* frame, const SandboxExtension::Handle& handle)
1648 {
1649     ASSERT(frame->isMainFrame());
1650
1651     // If we get two beginLoad calls in succession, without a provisional load starting, then
1652     // m_pendingProvisionalSandboxExtension will be non-null. Invalidate and null out the extension if that is the case.
1653     if (m_pendingProvisionalSandboxExtension) {
1654         m_pendingProvisionalSandboxExtension->invalidate();
1655         m_pendingProvisionalSandboxExtension = nullptr;
1656     }
1657         
1658     m_pendingProvisionalSandboxExtension = SandboxExtension::create(handle);
1659 }
1660
1661 void WebPage::SandboxExtensionTracker::didStartProvisionalLoad(WebFrame* frame)
1662 {
1663     if (!frame->isMainFrame())
1664         return;
1665
1666     ASSERT(!m_provisionalSandboxExtension);
1667
1668     m_provisionalSandboxExtension = m_pendingProvisionalSandboxExtension.release();
1669     if (!m_provisionalSandboxExtension)
1670         return;
1671
1672     m_provisionalSandboxExtension->consume();
1673 }
1674
1675 void WebPage::SandboxExtensionTracker::didCommitProvisionalLoad(WebFrame* frame)
1676 {
1677     if (!frame->isMainFrame())
1678         return;
1679     
1680     ASSERT(!m_pendingProvisionalSandboxExtension);
1681
1682     // The provisional load has been committed. Invalidate the currently committed sandbox
1683     // extension and make the provisional sandbox extension the committed sandbox extension.
1684     if (m_committedSandboxExtension)
1685         m_committedSandboxExtension->invalidate();
1686
1687     m_committedSandboxExtension = m_provisionalSandboxExtension.release();
1688 }
1689
1690 void WebPage::SandboxExtensionTracker::didFailProvisionalLoad(WebFrame* frame)
1691 {
1692     if (!frame->isMainFrame())
1693         return;
1694
1695     ASSERT(!m_pendingProvisionalSandboxExtension);
1696     if (!m_provisionalSandboxExtension)
1697         return;
1698
1699     m_provisionalSandboxExtension->invalidate();
1700     m_provisionalSandboxExtension = nullptr;
1701 }
1702
1703 bool WebPage::hasLocalDataForURL(const KURL& url)
1704 {
1705     if (url.isLocalFile())
1706         return true;
1707
1708     FrameLoader* frameLoader = m_page->mainFrame()->loader();
1709     DocumentLoader* documentLoader = frameLoader ? frameLoader->documentLoader() : 0;
1710     if (documentLoader && documentLoader->subresource(url))
1711         return true;
1712
1713     return platformHasLocalDataForURL(url);
1714 }
1715
1716 void WebPage::setCustomTextEncodingName(const String& encoding)
1717 {
1718     m_page->mainFrame()->loader()->reloadWithOverrideEncoding(encoding);
1719 }
1720
1721 void WebPage::didRemoveBackForwardItem(uint64_t itemID)
1722 {
1723     WebBackForwardListProxy::removeItem(itemID);
1724 }
1725
1726 #if PLATFORM(MAC)
1727
1728 bool WebPage::isSpeaking()
1729 {
1730     bool result;
1731     return sendSync(Messages::WebPageProxy::GetIsSpeaking(), Messages::WebPageProxy::GetIsSpeaking::Reply(result)) && result;
1732 }
1733
1734 void WebPage::speak(const String& string)
1735 {
1736     send(Messages::WebPageProxy::Speak(string));
1737 }
1738
1739 void WebPage::stopSpeaking()
1740 {
1741     send(Messages::WebPageProxy::StopSpeaking());
1742 }
1743
1744 #endif
1745
1746 void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
1747 {
1748     WebFrame* frame = WebProcess::shared().webFrame(frameID);
1749     if (!frame)
1750         return;
1751
1752     Frame* coreFrame = frame->coreFrame();
1753     if (!coreFrame)
1754         return;
1755
1756     if (!m_printContext)
1757         m_printContext = adoptPtr(new PrintContext(coreFrame));
1758
1759     m_printContext->begin(printInfo.availablePaperWidth, printInfo.availablePaperHeight);
1760 }
1761
1762 void WebPage::endPrinting()
1763 {
1764     m_printContext = nullptr;
1765 }
1766
1767 void WebPage::computePagesForPrinting(uint64_t frameID, const PrintInfo& printInfo, Vector<IntRect>& resultPageRects, double& resultTotalScaleFactorForPrinting)
1768 {
1769     beginPrinting(frameID, printInfo);
1770
1771     WebFrame* frame = WebProcess::shared().webFrame(frameID);
1772     if (!frame)
1773         return;
1774
1775     float fullPageHeight;
1776     m_printContext->computePageRects(FloatRect(0, 0, printInfo.availablePaperWidth, printInfo.availablePaperHeight), 0, 0, printInfo.pageSetupScaleFactor, fullPageHeight, true);
1777
1778     resultTotalScaleFactorForPrinting = m_printContext->computeAutomaticScaleFactor(printInfo.availablePaperWidth) * printInfo.pageSetupScaleFactor;
1779     resultPageRects = m_printContext->pageRects();
1780
1781     // If we're asked to print, we should actually print at least a blank page.
1782     if (resultPageRects.isEmpty())
1783         resultPageRects.append(IntRect(0, 0, 1, 1));
1784 }
1785
1786 #if PLATFORM(MAC)
1787 // FIXME: Find a better place for Mac specific code.
1788 void WebPage::drawRectToPDF(uint64_t frameID, const WebCore::IntRect& rect, Vector<uint8_t>& pdfData)
1789 {
1790     WebFrame* frame = WebProcess::shared().webFrame(frameID);
1791     if (!frame)
1792         return;
1793
1794     Frame* coreFrame = frame->coreFrame();
1795     if (!coreFrame)
1796         return;
1797
1798     ASSERT(coreFrame->document()->printing());
1799
1800     RetainPtr<CFMutableDataRef> pdfPageData(AdoptCF, CFDataCreateMutable(0, 0));
1801
1802     // FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data.
1803     RetainPtr<CGDataConsumerRef> pdfDataConsumer(AdoptCF, CGDataConsumerCreateWithCFData(pdfPageData.get()));
1804
1805     CGRect mediaBox = CGRectMake(0, 0, frame->size().width(), frame->size().height());
1806     RetainPtr<CGContextRef> context(AdoptCF, CGPDFContextCreate(pdfDataConsumer.get(), &mediaBox, 0));
1807     RetainPtr<CFDictionaryRef> pageInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
1808     CGPDFContextBeginPage(context.get(), pageInfo.get());
1809
1810     GraphicsContext ctx(context.get());
1811     m_printContext->spoolRect(ctx, rect);
1812
1813     CGPDFContextEndPage(context.get());
1814     CGPDFContextClose(context.get());
1815
1816     pdfData.resize(CFDataGetLength(pdfPageData.get()));
1817     CFDataGetBytes(pdfPageData.get(), CFRangeMake(0, pdfData.size()), pdfData.data());
1818 }
1819 #endif
1820
1821 void WebPage::runModal()
1822 {
1823     if (m_isClosed)
1824         return;
1825     if (m_isRunningModal)
1826         return;
1827
1828     m_isRunningModal = true;
1829     send(Messages::WebPageProxy::RunModal());
1830     RunLoop::run();
1831     ASSERT(!m_isRunningModal);
1832 }
1833
1834 } // namespace WebKit