darin@apple.com | 815d7b5 | 2009-01-05 18:24:12 +0000 | [diff] [blame] | 1 | /* |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 | * (C) 2001 Dirk Mueller (mueller@kde.org) |
ap | 0289d28 | 2006-11-20 18:59:12 +0000 | [diff] [blame] | 5 | * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
antti@apple.com | da4d9c51 | 2012-04-11 23:20:55 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved. |
staikos@webkit.org | 159f11f | 2009-05-18 23:48:30 +0000 | [diff] [blame] | 7 | * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
bbudge@chromium.org | 9b3a128 | 2012-08-20 18:11:22 +0000 | [diff] [blame] | 8 | * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
luiz@webkit.org | db0dd43 | 2010-11-22 21:02:27 +0000 | [diff] [blame] | 9 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 10 | * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 11 | * |
| 12 | * This library is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU Library General Public |
| 14 | * License as published by the Free Software Foundation; either |
| 15 | * version 2 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This library is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * Library General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Library General Public License |
| 23 | * along with this library; see the file COPYING.LIB. If not, write to |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 24 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 25 | * Boston, MA 02110-1301, USA. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | #include "Document.h" |
| 30 | |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 31 | #include "AXObjectCache.h" |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 32 | #include "AnimationController.h" |
darin@apple.com | 9a925fa | 2009-05-04 18:00:34 +0000 | [diff] [blame] | 33 | #include "Attr.h" |
weinig@apple.com | c360893 | 2010-05-19 17:48:06 +0000 | [diff] [blame] | 34 | #include "Attribute.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 35 | #include "CDATASection.h" |
mihnea@adobe.com | cda097f | 2012-03-05 23:31:50 +0000 | [diff] [blame] | 36 | #include "CSSParser.h" |
jamesr@google.com | 2b9efdf | 2012-02-21 21:35:38 +0000 | [diff] [blame] | 37 | #include "CSSStyleDeclaration.h" |
eseidel | b3f4213 | 2006-05-16 02:08:51 +0000 | [diff] [blame] | 38 | #include "CSSStyleSheet.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 39 | #include "CSSValueKeywords.h" |
weinig@apple.com | ba6e665 | 2008-05-09 20:52:15 +0000 | [diff] [blame] | 40 | #include "CachedCSSStyleSheet.h" |
tonyg@chromium.org | 987a93b | 2011-01-04 16:56:17 +0000 | [diff] [blame] | 41 | #include "CachedResourceLoader.h" |
aroben@apple.com | a7c639a | 2009-12-18 17:38:45 +0000 | [diff] [blame] | 42 | #include "Chrome.h" |
eric@webkit.org | a1d8965 | 2010-01-21 03:49:51 +0000 | [diff] [blame] | 43 | #include "ChromeClient.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 44 | #include "Comment.h" |
ap@webkit.org | e9b6b59 | 2008-11-19 17:42:39 +0000 | [diff] [blame] | 45 | #include "Console.h" |
abarth@webkit.org | f921dee | 2011-03-26 11:59:34 +0000 | [diff] [blame] | 46 | #include "ContentSecurityPolicy.h" |
morrita@google.com | ac74304 | 2012-06-13 08:05:43 +0000 | [diff] [blame] | 47 | #include "ContextFeatures.h" |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 48 | #include "CookieJar.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 49 | #include "DOMImplementation.h" |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 50 | #include "DOMNamedFlowCollection.h" |
shinyak@chromium.org | 4fd60ed | 2012-05-11 10:36:31 +0000 | [diff] [blame] | 51 | #include "DOMSelection.h" |
weinig@apple.com | ba6e665 | 2008-05-09 20:52:15 +0000 | [diff] [blame] | 52 | #include "DOMWindow.h" |
weinig@apple.com | 1a8cc9d | 2011-09-04 21:04:14 +0000 | [diff] [blame] | 53 | #include "DateComponents.h" |
kenneth@webkit.org | ae65fe3 | 2011-10-26 14:56:09 +0000 | [diff] [blame] | 54 | #include "DeviceMotionController.h" |
kenneth@webkit.org | ae65fe3 | 2011-10-26 14:56:09 +0000 | [diff] [blame] | 55 | #include "DeviceOrientationController.h" |
dgrogan@chromium.org | 65c22c8 | 2011-10-27 23:15:04 +0000 | [diff] [blame] | 56 | #include "DocumentEventQueue.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 57 | #include "DocumentFragment.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 58 | #include "DocumentLoader.h" |
tonyg@chromium.org | 987a93b | 2011-01-04 16:56:17 +0000 | [diff] [blame] | 59 | #include "DocumentMarkerController.h" |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 60 | #include "DocumentStyleSheetCollection.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 61 | #include "DocumentType.h" |
| 62 | #include "EditingText.h" |
andersca | f2ad1b5 | 2006-11-09 00:51:35 +0000 | [diff] [blame] | 63 | #include "Editor.h" |
aestes@apple.com | 6268382 | 2011-02-11 07:21:54 +0000 | [diff] [blame] | 64 | #include "Element.h" |
morrita@google.com | 948bd53 | 2012-05-07 06:05:42 +0000 | [diff] [blame] | 65 | #include "ElementShadow.h" |
eseidel | 6e4fe45 | 2006-05-15 23:53:33 +0000 | [diff] [blame] | 66 | #include "EntityReference.h" |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 67 | #include "Event.h" |
abarth@webkit.org | 08feba4 | 2011-10-20 04:50:14 +0000 | [diff] [blame] | 68 | #include "EventFactory.h" |
darin | 60e537f5 | 2006-11-15 01:29:46 +0000 | [diff] [blame] | 69 | #include "EventHandler.h" |
darin | 817909f | 2006-04-17 05:34:58 +0000 | [diff] [blame] | 70 | #include "EventListener.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 71 | #include "EventNames.h" |
| 72 | #include "ExceptionCode.h" |
mihnea@adobe.com | d030fcd | 2012-04-11 09:41:37 +0000 | [diff] [blame] | 73 | #include "FlowThreadController.h" |
ggaren | 7c5851a | 2006-12-12 22:11:18 +0000 | [diff] [blame] | 74 | #include "FocusController.h" |
tkent@chromium.org | 3455487 | 2012-06-08 09:53:52 +0000 | [diff] [blame] | 75 | #include "FormController.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 76 | #include "Frame.h" |
ggaren | b2497d8 | 2006-10-28 01:22:13 +0000 | [diff] [blame] | 77 | #include "FrameLoader.h" |
ap@apple.com | 43af8a8 | 2010-10-29 17:23:55 +0000 | [diff] [blame] | 78 | #include "FrameLoaderClient.h" |
rniwa@webkit.org | 78bbc94 | 2011-05-05 18:14:43 +0000 | [diff] [blame] | 79 | #include "FrameSelection.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 80 | #include "FrameTree.h" |
darin | 647be15 | 2006-11-05 22:02:23 +0000 | [diff] [blame] | 81 | #include "FrameView.h" |
kenneth@webkit.org | ae65fe3 | 2011-10-26 14:56:09 +0000 | [diff] [blame] | 82 | #include "GeolocationController.h" |
abarth@webkit.org | 08feba4 | 2011-10-20 04:50:14 +0000 | [diff] [blame] | 83 | #include "HashChangeEvent.h" |
commit-queue@webkit.org | bfdd472 | 2011-12-17 00:58:33 +0000 | [diff] [blame] | 84 | #include "HistogramSupport.h" |
commit-queue@webkit.org | 7a2b40f | 2012-02-23 03:05:55 +0000 | [diff] [blame] | 85 | #include "History.h" |
weinig@apple.com | 963305c | 2009-10-23 21:12:03 +0000 | [diff] [blame] | 86 | #include "HTMLAllCollection.h" |
darin@apple.com | 72b7bb5 | 2009-01-05 17:32:03 +0000 | [diff] [blame] | 87 | #include "HTMLAnchorElement.h" |
eseidel | 409f430 | 2006-05-12 22:56:41 +0000 | [diff] [blame] | 88 | #include "HTMLBodyElement.h" |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 89 | #include "HTMLCanvasElement.h" |
darin@apple.com | 9a925fa | 2009-05-04 18:00:34 +0000 | [diff] [blame] | 90 | #include "HTMLCollection.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 91 | #include "HTMLDocument.h" |
| 92 | #include "HTMLElementFactory.h" |
darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 93 | #include "HTMLFrameOwnerElement.h" |
darin | a6a0caf | 2007-01-25 00:16:44 +0000 | [diff] [blame] | 94 | #include "HTMLHeadElement.h" |
dimich@chromium.org | 451eabb | 2010-01-27 00:22:37 +0000 | [diff] [blame] | 95 | #include "HTMLIFrameElement.h" |
eseidel | 1bdb6f5 | 2006-05-12 20:44:25 +0000 | [diff] [blame] | 96 | #include "HTMLLinkElement.h" |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 97 | #include "HTMLMapElement.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 98 | #include "HTMLNameCollection.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 99 | #include "HTMLNames.h" |
darin@apple.com | 7b7981b | 2010-10-01 00:04:02 +0000 | [diff] [blame] | 100 | #include "HTMLParserIdioms.h" |
eseidel | 1bdb6f5 | 2006-05-12 20:44:25 +0000 | [diff] [blame] | 101 | #include "HTMLStyleElement.h" |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 102 | #include "HTMLTitleElement.h" |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 103 | #include "HTTPParsers.h" |
weinig | e791808 | 2007-07-18 19:56:40 +0000 | [diff] [blame] | 104 | #include "HitTestRequest.h" |
| 105 | #include "HitTestResult.h" |
zimmermann@webkit.org | 953b744 | 2008-09-20 20:19:45 +0000 | [diff] [blame] | 106 | #include "ImageLoader.h" |
yurys@chromium.org | 793b08e | 2012-02-17 08:33:30 +0000 | [diff] [blame] | 107 | #include "InspectorCounters.h" |
commit-queue@webkit.org | 4c49a66 | 2011-01-02 22:27:10 +0000 | [diff] [blame] | 108 | #include "InspectorInstrumentation.h" |
tkent@chromium.org | aff3c93 | 2012-09-14 12:40:27 +0000 | [diff] [blame] | 109 | #include "Language.h" |
| 110 | #include "Localizer.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 111 | #include "Logging.h" |
loislo@chromium.org | c10e098 | 2012-09-26 14:10:50 +0000 | [diff] [blame] | 112 | #include "MediaCanStartListener.h" |
luiz@webkit.org | db0dd43 | 2010-11-22 21:02:27 +0000 | [diff] [blame] | 113 | #include "MediaQueryList.h" |
| 114 | #include "MediaQueryMatcher.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 115 | #include "MouseEventWithHitTestResults.h" |
| 116 | #include "NameNodeList.h" |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 117 | #include "NamedFlowCollection.h" |
commit-queue@webkit.org | b7b2b52 | 2011-02-02 00:22:52 +0000 | [diff] [blame] | 118 | #include "NestingLevelIncrementer.h" |
jpfau@apple.com | e854e5d | 2011-07-08 19:31:34 +0000 | [diff] [blame] | 119 | #include "NewXMLDocumentParser.h" |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 120 | #include "NodeFilter.h" |
| 121 | #include "NodeIterator.h" |
rniwa@webkit.org | fdcdadf | 2012-06-14 22:38:41 +0000 | [diff] [blame] | 122 | #include "NodeRareData.h" |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 123 | #include "NodeWithIndex.h" |
oliver | f8f0779 | 2007-05-11 21:54:12 +0000 | [diff] [blame] | 124 | #include "Page.h" |
hyatt@apple.com | 63e0ac2 | 2009-09-09 21:12:10 +0000 | [diff] [blame] | 125 | #include "PageGroup.h" |
ap@apple.com | 383dde5 | 2009-08-27 17:46:39 +0000 | [diff] [blame] | 126 | #include "PageTransitionEvent.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 127 | #include "PlatformKeyboardEvent.h" |
jpu@apple.com | dfd2ce6 | 2012-04-16 03:05:06 +0000 | [diff] [blame] | 128 | #include "PluginDocument.h" |
scheib@chromium.org | 6ed0176 | 2012-06-12 03:02:16 +0000 | [diff] [blame] | 129 | #include "PointerLockController.h" |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 130 | #include "PopStateEvent.h" |
eseidel | 6e4fe45 | 2006-05-15 23:53:33 +0000 | [diff] [blame] | 131 | #include "ProcessingInstruction.h" |
kling@webkit.org | ca1e2d4 | 2012-09-24 00:57:54 +0000 | [diff] [blame] | 132 | #include "QualifiedName.h" |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 133 | #include "RegisteredEventListener.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 134 | #include "RenderArena.h" |
hyatt@apple.com | 04cdbe4 | 2012-03-28 22:15:31 +0000 | [diff] [blame] | 135 | #include "RenderNamedFlowThread.h" |
hyatt@apple.com | e6dedc0 | 2009-02-13 19:18:36 +0000 | [diff] [blame] | 136 | #include "RenderTextControl.h" |
hyatt | d804834 | 2006-05-31 01:48:18 +0000 | [diff] [blame] | 137 | #include "RenderView.h" |
eseidel | 409f430 | 2006-05-12 22:56:41 +0000 | [diff] [blame] | 138 | #include "RenderWidget.h" |
tkent@chromium.org | aff3c93 | 2012-09-14 12:40:27 +0000 | [diff] [blame] | 139 | #include "RuntimeEnabledFeatures.h" |
jberlin@webkit.org | da2af49 | 2011-11-07 18:16:33 +0000 | [diff] [blame] | 140 | #include "SchemeRegistry.h" |
abarth@webkit.org | 90a3ca6 | 2011-04-14 19:54:30 +0000 | [diff] [blame] | 141 | #include "ScopedEventQueue.h" |
yurys@chromium.org | c8a06eb | 2011-01-20 09:28:54 +0000 | [diff] [blame] | 142 | #include "ScriptCallStack.h" |
abarth@webkit.org | 24d63ef | 2008-12-10 06:48:36 +0000 | [diff] [blame] | 143 | #include "ScriptController.h" |
mitz@apple.com | 73169a1 | 2009-04-20 04:20:08 +0000 | [diff] [blame] | 144 | #include "ScriptElement.h" |
darin@apple.com | 3a3edd4 | 2009-08-19 00:17:59 +0000 | [diff] [blame] | 145 | #include "ScriptEventListener.h" |
simonjam@chromium.org | 5871a05 | 2011-03-16 00:00:09 +0000 | [diff] [blame] | 146 | #include "ScriptRunner.h" |
jamesr@google.com | 0abe006 | 2012-02-18 00:23:16 +0000 | [diff] [blame] | 147 | #include "ScrollingCoordinator.h" |
weinig | e06430a | 2007-10-19 20:53:22 +0000 | [diff] [blame] | 148 | #include "SecurityOrigin.h" |
abarth@webkit.org | eea9066 | 2011-11-09 07:58:49 +0000 | [diff] [blame] | 149 | #include "SecurityPolicy.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 150 | #include "SegmentedString.h" |
haraken@chromium.org | 3981f52 | 2012-06-02 19:23:25 +0000 | [diff] [blame] | 151 | #include "SelectorQuery.h" |
ggaren | 6ad6e76 | 2007-05-25 09:13:32 +0000 | [diff] [blame] | 152 | #include "Settings.h" |
rolandsteiner@chromium.org | 6d944b8 | 2011-04-21 17:44:14 +0000 | [diff] [blame] | 153 | #include "ShadowRoot.h" |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 154 | #include "StaticHashSetNodeList.h" |
alexis.menard@openbossa.org | e6db2f6 | 2012-04-25 15:49:08 +0000 | [diff] [blame] | 155 | #include "StyleResolver.h" |
antti@apple.com | 069713a | 2012-05-24 08:54:22 +0000 | [diff] [blame] | 156 | #include "StyleSheetContents.h" |
eseidel | b3f4213 | 2006-05-16 02:08:51 +0000 | [diff] [blame] | 157 | #include "StyleSheetList.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 158 | #include "TextResourceDecoder.h" |
ap@webkit.org | a3f2d9f | 2008-12-04 07:20:45 +0000 | [diff] [blame] | 159 | #include "Timer.h" |
hausmann@webkit.org | 06b7e55 | 2009-09-28 20:11:36 +0000 | [diff] [blame] | 160 | #include "TransformSource.h" |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 161 | #include "TreeWalker.h" |
commit-queue@webkit.org | 5deb749 | 2012-06-09 09:05:22 +0000 | [diff] [blame] | 162 | #include "UndoManager.h" |
hyatt@apple.com | 5d1c0e7 | 2009-09-30 00:32:38 +0000 | [diff] [blame] | 163 | #include "UserContentURLPattern.h" |
loislo@chromium.org | c438912 | 2012-09-07 15:36:43 +0000 | [diff] [blame] | 164 | #include "WebCoreMemoryInstrumentation.h" |
mihnea@adobe.com | 88a6cdd | 2011-12-08 14:23:10 +0000 | [diff] [blame] | 165 | #include "WebKitNamedFlow.h" |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 166 | #include "XMLDocumentParser.h" |
weinig | 62f94be | 2007-07-18 20:37:20 +0000 | [diff] [blame] | 167 | #include "XMLHttpRequest.h" |
ap@apple.com | 38221c6 | 2010-01-18 22:05:55 +0000 | [diff] [blame] | 168 | #include "XMLNSNames.h" |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 169 | #include "XMLNames.h" |
abarth@webkit.org | 32638ce | 2011-10-18 17:21:28 +0000 | [diff] [blame] | 170 | #include "XPathEvaluator.h" |
| 171 | #include "XPathExpression.h" |
| 172 | #include "XPathNSResolver.h" |
| 173 | #include "XPathResult.h" |
weinig@apple.com | 628cb2c | 2009-09-08 22:02:41 +0000 | [diff] [blame] | 174 | #include "htmlediting.h" |
ap@webkit.org | c01ff49 | 2009-01-11 08:14:58 +0000 | [diff] [blame] | 175 | #include <wtf/CurrentTime.h> |
dsmith@webkit.org | 69601f9 | 2009-01-03 00:25:59 +0000 | [diff] [blame] | 176 | #include <wtf/HashFunctions.h> |
ap@webkit.org | a3f2d9f | 2008-12-04 07:20:45 +0000 | [diff] [blame] | 177 | #include <wtf/MainThread.h> |
yurys@chromium.org | 9c99016 | 2012-10-01 14:46:25 +0000 | [diff] [blame] | 178 | #include <wtf/MemoryInstrumentationHashMap.h> |
loislo@chromium.org | c10e098 | 2012-09-26 14:10:50 +0000 | [diff] [blame] | 179 | #include <wtf/MemoryInstrumentationHashSet.h> |
loislo@chromium.org | 8373693 | 2012-09-25 07:54:44 +0000 | [diff] [blame] | 180 | #include <wtf/MemoryInstrumentationVector.h> |
ap@webkit.org | a3f2d9f | 2008-12-04 07:20:45 +0000 | [diff] [blame] | 181 | #include <wtf/PassRefPtr.h> |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 182 | #include <wtf/StdLibExtras.h> |
barraclough@apple.com | bbb3cd4 | 2010-08-10 17:45:41 +0000 | [diff] [blame] | 183 | #include <wtf/text/StringBuffer.h> |
darin | b448382 | 2006-06-02 06:30:49 +0000 | [diff] [blame] | 184 | |
weinig@apple.com | 628cb2c | 2009-09-08 22:02:41 +0000 | [diff] [blame] | 185 | #if ENABLE(SHARED_WORKERS) |
| 186 | #include "SharedWorkerRepository.h" |
| 187 | #endif |
| 188 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 189 | #if ENABLE(XSLT) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 190 | #include "XSLTProcessor.h" |
| 191 | #endif |
| 192 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 193 | #if ENABLE(SVG) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 194 | #include "SVGDocumentExtensions.h" |
| 195 | #include "SVGElementFactory.h" |
krit@webkit.org | 5e3479c | 2009-08-24 06:00:03 +0000 | [diff] [blame] | 196 | #include "SVGNames.h" |
zimmermann@webkit.org | 3d2114c | 2012-02-08 10:21:49 +0000 | [diff] [blame] | 197 | #include "SVGSVGElement.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 198 | #include "SVGStyleElement.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 199 | #endif |
| 200 | |
eric@webkit.org | e0e1420 | 2010-01-14 10:03:34 +0000 | [diff] [blame] | 201 | #if ENABLE(TOUCH_EVENTS) |
tonyg@chromium.org | 8d183cb | 2011-05-10 08:19:52 +0000 | [diff] [blame] | 202 | #include "TouchList.h" |
eric@webkit.org | e0e1420 | 2010-01-14 10:03:34 +0000 | [diff] [blame] | 203 | #endif |
| 204 | |
eric@webkit.org | 8af95f3 | 2009-09-19 18:02:33 +0000 | [diff] [blame] | 205 | #if ENABLE(MATHML) |
| 206 | #include "MathMLElement.h" |
| 207 | #include "MathMLElementFactory.h" |
| 208 | #include "MathMLNames.h" |
| 209 | #endif |
| 210 | |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 211 | #if ENABLE(FULLSCREEN_API) |
| 212 | #include "RenderFullScreen.h" |
| 213 | #endif |
| 214 | |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 215 | #if ENABLE(REQUEST_ANIMATION_FRAME) |
| 216 | #include "RequestAnimationFrameCallback.h" |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 217 | #include "ScriptedAnimationController.h" |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 218 | #endif |
| 219 | |
rniwa@webkit.org | 43f105f | 2011-10-14 16:13:01 +0000 | [diff] [blame] | 220 | #if ENABLE(MICRODATA) |
| 221 | #include "MicroDataItemList.h" |
| 222 | #include "NodeRareData.h" |
| 223 | #endif |
| 224 | |
gavinp@chromium.org | af445b9 | 2012-05-15 04:42:52 +0000 | [diff] [blame] | 225 | #if ENABLE(LINK_PRERENDER) |
| 226 | #include "Prerenderer.h" |
| 227 | #endif |
| 228 | |
commit-queue@webkit.org | 85cce8f | 2012-07-04 17:43:12 +0000 | [diff] [blame] | 229 | #if ENABLE(TEXT_AUTOSIZING) |
| 230 | #include "TextAutosizer.h" |
| 231 | #endif |
| 232 | |
commit-queue@webkit.org | 05199e5 | 2012-07-26 09:49:52 +0000 | [diff] [blame] | 233 | #if ENABLE(CSP_NEXT) |
| 234 | #include "DOMSecurityPolicy.h" |
| 235 | #endif |
| 236 | |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 237 | using namespace std; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 238 | using namespace WTF; |
| 239 | using namespace Unicode; |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 240 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 241 | namespace WebCore { |
| 242 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 243 | using namespace HTMLNames; |
| 244 | |
| 245 | // #define INSTRUMENT_LAYOUT_SCHEDULING 1 |
| 246 | |
commit-queue@webkit.org | b7b2b52 | 2011-02-02 00:22:52 +0000 | [diff] [blame] | 247 | static const unsigned cMaxWriteRecursionDepth = 21; |
| 248 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 249 | // This amount of time must have elapsed before we will even consider scheduling a layout without a delay. |
| 250 | // FIXME: For faster machines this value can really be lowered to 200. 250 is adequate, but a little high |
| 251 | // for dual G5s. :) |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 252 | static const int cLayoutScheduleThreshold = 250; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 253 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 254 | // DOM Level 2 says (letters added): |
| 255 | // |
| 256 | // a) Name start characters must have one of the categories Ll, Lu, Lo, Lt, Nl. |
| 257 | // b) Name characters other than Name-start characters must have one of the categories Mc, Me, Mn, Lm, or Nd. |
| 258 | // c) Characters in the compatibility area (i.e. with character code greater than #xF900 and less than #xFFFE) are not allowed in XML names. |
| 259 | // d) Characters which have a font or compatibility decomposition (i.e. those with a "compatibility formatting tag" in field 5 of the database -- marked by field 5 beginning with a "<") are not allowed. |
| 260 | // e) The following characters are treated as name-start characters rather than name characters, because the property file classifies them as Alphabetic: [#x02BB-#x02C1], #x0559, #x06E5, #x06E6. |
| 261 | // f) Characters #x20DD-#x20E0 are excluded (in accordance with Unicode, section 5.14). |
| 262 | // g) Character #x00B7 is classified as an extender, because the property list so identifies it. |
| 263 | // h) Character #x0387 is added as a name character, because #x00B7 is its canonical equivalent. |
| 264 | // i) Characters ':' and '_' are allowed as name-start characters. |
| 265 | // j) Characters '-' and '.' are allowed as name characters. |
| 266 | // |
| 267 | // It also contains complete tables. If we decide it's better, we could include those instead of the following code. |
| 268 | |
| 269 | static inline bool isValidNameStart(UChar32 c) |
| 270 | { |
| 271 | // rule (e) above |
| 272 | if ((c >= 0x02BB && c <= 0x02C1) || c == 0x559 || c == 0x6E5 || c == 0x6E6) |
| 273 | return true; |
| 274 | |
| 275 | // rule (i) above |
| 276 | if (c == ':' || c == '_') |
| 277 | return true; |
| 278 | |
| 279 | // rules (a) and (f) above |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 280 | const uint32_t nameStartMask = Letter_Lowercase | Letter_Uppercase | Letter_Other | Letter_Titlecase | Number_Letter; |
| 281 | if (!(Unicode::category(c) & nameStartMask)) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 282 | return false; |
| 283 | |
| 284 | // rule (c) above |
| 285 | if (c >= 0xF900 && c < 0xFFFE) |
| 286 | return false; |
| 287 | |
| 288 | // rule (d) above |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 289 | DecompositionType decompType = decompositionType(c); |
| 290 | if (decompType == DecompositionFont || decompType == DecompositionCompat) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 291 | return false; |
| 292 | |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | static inline bool isValidNamePart(UChar32 c) |
| 297 | { |
| 298 | // rules (a), (e), and (i) above |
| 299 | if (isValidNameStart(c)) |
| 300 | return true; |
| 301 | |
| 302 | // rules (g) and (h) above |
| 303 | if (c == 0x00B7 || c == 0x0387) |
| 304 | return true; |
| 305 | |
| 306 | // rule (j) above |
| 307 | if (c == '-' || c == '.') |
| 308 | return true; |
| 309 | |
| 310 | // rules (b) and (f) above |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 311 | const uint32_t otherNamePartMask = Mark_NonSpacing | Mark_Enclosing | Mark_SpacingCombining | Letter_Modifier | Number_DecimalDigit; |
| 312 | if (!(Unicode::category(c) & otherNamePartMask)) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 313 | return false; |
| 314 | |
| 315 | // rule (c) above |
| 316 | if (c >= 0xF900 && c < 0xFFFE) |
| 317 | return false; |
| 318 | |
| 319 | // rule (d) above |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 320 | DecompositionType decompType = decompositionType(c); |
| 321 | if (decompType == DecompositionFont || decompType == DecompositionCompat) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 322 | return false; |
| 323 | |
| 324 | return true; |
| 325 | } |
| 326 | |
abarth@webkit.org | d8cd61a | 2011-11-14 19:33:02 +0000 | [diff] [blame] | 327 | static bool shouldInheritSecurityOriginFromOwner(const KURL& url) |
| 328 | { |
| 329 | // http://www.whatwg.org/specs/web-apps/current-work/#origin-0 |
| 330 | // |
| 331 | // If a Document has the address "about:blank" |
| 332 | // The origin of the Document is the origin it was assigned when its browsing context was created. |
| 333 | // |
commit-queue@webkit.org | a9b0818 | 2012-05-06 22:57:29 +0000 | [diff] [blame] | 334 | // Note: We generalize this to all "blank" URLs and invalid URLs because we |
abarth@webkit.org | d8cd61a | 2011-11-14 19:33:02 +0000 | [diff] [blame] | 335 | // treat all of these URLs as about:blank. |
| 336 | // |
commit-queue@webkit.org | a9b0818 | 2012-05-06 22:57:29 +0000 | [diff] [blame] | 337 | return !url.isValid() || url.isBlankURL(); |
abarth@webkit.org | d8cd61a | 2011-11-14 19:33:02 +0000 | [diff] [blame] | 338 | } |
| 339 | |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 340 | static Widget* widgetForNode(Node* focusedNode) |
darin@apple.com | 8a1c16e | 2008-03-19 04:23:21 +0000 | [diff] [blame] | 341 | { |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 342 | if (!focusedNode) |
| 343 | return 0; |
| 344 | RenderObject* renderer = focusedNode->renderer(); |
| 345 | if (!renderer || !renderer->isWidget()) |
| 346 | return 0; |
darin@apple.com | 9c96275 | 2009-07-30 18:44:42 +0000 | [diff] [blame] | 347 | return toRenderWidget(renderer)->widget(); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 348 | } |
| 349 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 350 | static bool acceptsEditingFocus(Node* node) |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 351 | { |
ggaren | f9f32ae | 2007-03-26 20:08:53 +0000 | [diff] [blame] | 352 | ASSERT(node); |
commit-queue@webkit.org | 595681f | 2011-03-25 16:21:30 +0000 | [diff] [blame] | 353 | ASSERT(node->rendererIsEditable()); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 354 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 355 | Node* root = node->rootEditableElement(); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 356 | Frame* frame = node->document()->frame(); |
| 357 | if (!frame || !root) |
| 358 | return false; |
| 359 | |
| 360 | return frame->editor()->shouldBeginEditing(rangeOfContents(root).get()); |
| 361 | } |
| 362 | |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 363 | static bool canAccessAncestor(const SecurityOrigin* activeSecurityOrigin, Frame* targetFrame) |
| 364 | { |
| 365 | // targetFrame can be 0 when we're trying to navigate a top-level frame |
| 366 | // that has a 0 opener. |
| 367 | if (!targetFrame) |
| 368 | return false; |
| 369 | |
| 370 | const bool isLocalActiveOrigin = activeSecurityOrigin->isLocal(); |
| 371 | for (Frame* ancestorFrame = targetFrame; ancestorFrame; ancestorFrame = ancestorFrame->tree()->parent()) { |
| 372 | Document* ancestorDocument = ancestorFrame->document(); |
| 373 | // FIXME: Should be an ASSERT? Frames should alway have documents. |
| 374 | if (!ancestorDocument) |
| 375 | return true; |
| 376 | |
| 377 | const SecurityOrigin* ancestorSecurityOrigin = ancestorDocument->securityOrigin(); |
| 378 | if (activeSecurityOrigin->canAccess(ancestorSecurityOrigin)) |
| 379 | return true; |
| 380 | |
| 381 | // Allow file URL descendant navigation even when allowFileAccessFromFileURLs is false. |
| 382 | // FIXME: It's a bit strange to special-case local origins here. Should we be doing |
| 383 | // something more general instead? |
| 384 | if (isLocalActiveOrigin && ancestorSecurityOrigin->isLocal()) |
| 385 | return true; |
| 386 | } |
| 387 | |
| 388 | return false; |
| 389 | } |
| 390 | |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 391 | static void printNavigationErrorMessage(Frame* frame, const KURL& activeURL) |
| 392 | { |
| 393 | // FIXME: this error message should contain more specifics of why the navigation change is not allowed. |
| 394 | String message = "Unsafe JavaScript attempt to initiate a navigation change for frame with URL " + |
| 395 | frame->document()->url().string() + " from frame with URL " + activeURL.string() + ".\n"; |
| 396 | |
| 397 | // FIXME: should we print to the console of the document performing the navigation instead? |
abarth@webkit.org | b7c6116 | 2012-08-14 22:34:01 +0000 | [diff] [blame] | 398 | frame->document()->domWindow()->printErrorMessage(message); |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 399 | } |
| 400 | |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 401 | static HashSet<Document*>* documentsThatNeedStyleRecalc = 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 402 | |
levin@chromium.org | e24a9ba | 2011-03-20 23:30:26 +0000 | [diff] [blame] | 403 | class DocumentWeakReference : public ThreadSafeRefCounted<DocumentWeakReference> { |
dimich@chromium.org | c252d6d | 2010-01-20 21:56:08 +0000 | [diff] [blame] | 404 | public: |
| 405 | static PassRefPtr<DocumentWeakReference> create(Document* document) |
| 406 | { |
| 407 | return adoptRef(new DocumentWeakReference(document)); |
| 408 | } |
| 409 | |
| 410 | Document* document() |
| 411 | { |
| 412 | ASSERT(isMainThread()); |
| 413 | return m_document; |
| 414 | } |
| 415 | |
| 416 | void clear() |
| 417 | { |
| 418 | ASSERT(isMainThread()); |
| 419 | m_document = 0; |
| 420 | } |
| 421 | |
| 422 | private: |
| 423 | DocumentWeakReference(Document* document) |
| 424 | : m_document(document) |
| 425 | { |
| 426 | ASSERT(isMainThread()); |
| 427 | } |
| 428 | |
| 429 | Document* m_document; |
| 430 | }; |
| 431 | |
eae@chromium.org | a01dd60 | 2011-03-11 01:46:48 +0000 | [diff] [blame] | 432 | uint64_t Document::s_globalTreeVersion = 0; |
| 433 | |
aestes@apple.com | 10c51ec | 2011-02-11 06:35:18 +0000 | [diff] [blame] | 434 | Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML) |
adamk@chromium.org | 575ab2b | 2012-03-08 22:47:44 +0000 | [diff] [blame] | 435 | : ContainerNode(0, CreateDocument) |
commit-queue@webkit.org | c4534e1 | 2012-07-24 00:53:24 +0000 | [diff] [blame] | 436 | , TreeScope(this) |
rolandsteiner@chromium.org | dafa610 | 2011-04-06 23:52:52 +0000 | [diff] [blame] | 437 | , m_guardRefCount(0) |
morrita@google.com | ac74304 | 2012-06-13 08:05:43 +0000 | [diff] [blame] | 438 | , m_contextFeatures(ContextFeatures::defaultSwitch()) |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 439 | , m_compatibilityMode(NoQuirksMode) |
| 440 | , m_compatibilityModeLocked(false) |
eae@chromium.org | a01dd60 | 2011-03-11 01:46:48 +0000 | [diff] [blame] | 441 | , m_domTreeVersion(++s_globalTreeVersion) |
adamk@chromium.org | f32db17 | 2011-11-08 18:29:54 +0000 | [diff] [blame] | 442 | #if ENABLE(MUTATION_OBSERVERS) |
adamk@chromium.org | c3168fb | 2011-12-16 00:59:39 +0000 | [diff] [blame] | 443 | , m_mutationObserverTypes(0) |
adamk@chromium.org | f32db17 | 2011-11-08 18:29:54 +0000 | [diff] [blame] | 444 | #endif |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 445 | , m_styleSheetCollection(adoptPtr(new DocumentStyleSheetCollection(this))) |
tonyg@chromium.org | d299d8a7 | 2010-09-06 18:32:48 +0000 | [diff] [blame] | 446 | , m_readyState(Complete) |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 447 | , m_styleRecalcTimer(this, &Document::styleRecalcTimerFired) |
hyatt@apple.com | 8dd0d93 | 2010-08-26 18:17:59 +0000 | [diff] [blame] | 448 | , m_pendingStyleRecalcShouldForce(false) |
darin@apple.com | 160d000 | 2009-01-02 09:27:08 +0000 | [diff] [blame] | 449 | , m_frameElementsShouldIgnoreScrolling(false) |
adele@apple.com | ddeabb8 | 2010-01-27 01:35:51 +0000 | [diff] [blame] | 450 | , m_containsValidityStyleRules(false) |
simon.fraser@apple.com | 9998eac | 2010-02-05 19:50:24 +0000 | [diff] [blame] | 451 | , m_updateFocusAppearanceRestoresSelection(false) |
tonyg@chromium.org | 8500eb8 | 2010-10-22 01:27:27 +0000 | [diff] [blame] | 452 | , m_ignoreDestructiveWriteCount(0) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 453 | , m_titleSetExplicitly(false) |
darin | 438e627 | 2007-08-16 16:29:48 +0000 | [diff] [blame] | 454 | , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFired) |
japhet@chromium.org | 4fdf46f | 2011-07-06 17:59:59 +0000 | [diff] [blame] | 455 | , m_loadEventFinished(false) |
eric@webkit.org | ef242d8 | 2010-01-09 01:25:44 +0000 | [diff] [blame] | 456 | , m_startTime(currentTime()) |
| 457 | , m_overMinimumLayoutThreshold(false) |
simonjam@chromium.org | 5871a05 | 2011-03-16 00:00:09 +0000 | [diff] [blame] | 458 | , m_scriptRunner(ScriptRunner::create(this)) |
ap | 0289d28 | 2006-11-20 18:59:12 +0000 | [diff] [blame] | 459 | , m_xmlVersion("1.0") |
rwlbuis@webkit.org | ac5a7ef | 2012-04-13 00:58:30 +0000 | [diff] [blame] | 460 | , m_xmlStandalone(StandaloneUnspecified) |
| 461 | , m_hasXMLDeclaration(0) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 462 | , m_savedRenderer(0) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 463 | , m_designMode(inherit) |
jianli@chromium.org | f66b581 | 2012-08-02 00:14:28 +0000 | [diff] [blame] | 464 | #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 465 | , m_hasDashboardRegions(false) |
| 466 | , m_dashboardRegionsDirty(false) |
ddkilzer@apple.com | 8fe6586 | 2008-04-29 21:31:09 +0000 | [diff] [blame] | 467 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 468 | , m_createRenderers(true) |
| 469 | , m_inPageCache(false) |
rolandsteiner@chromium.org | a8fbd63 | 2011-05-03 23:08:21 +0000 | [diff] [blame] | 470 | , m_accessKeyMapValid(false) |
beidson | c030e97 | 2007-05-12 21:22:08 +0000 | [diff] [blame] | 471 | , m_useSecureKeyboardEntryWhenActive(false) |
mrowe@apple.com | 46633d3 | 2007-12-17 01:26:46 +0000 | [diff] [blame] | 472 | , m_isXHTML(isXHTML) |
mjs@apple.com | 1232111 | 2010-01-20 02:25:21 +0000 | [diff] [blame] | 473 | , m_isHTML(isHTML) |
japhet@chromium.org | 0d6b1de | 2011-05-25 18:51:27 +0000 | [diff] [blame] | 474 | , m_isViewSource(false) |
pfeldman@chromium.org | 81b45e5 | 2011-02-28 15:26:44 +0000 | [diff] [blame] | 475 | , m_sawElementsInKnownNamespaces(false) |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 476 | , m_isSrcdocDocument(false) |
haraken@chromium.org | abf5d02 | 2012-06-28 06:29:27 +0000 | [diff] [blame] | 477 | , m_documentRareData(0) |
dgrogan@chromium.org | 65c22c8 | 2011-10-27 23:15:04 +0000 | [diff] [blame] | 478 | , m_eventQueue(DocumentEventQueue::create(this)) |
dimich@chromium.org | 948b9a3 | 2010-01-15 21:47:15 +0000 | [diff] [blame] | 479 | , m_weakReference(DocumentWeakReference::create(this)) |
darin@apple.com | f5247d1 | 2010-06-13 17:29:10 +0000 | [diff] [blame] | 480 | , m_idAttributeName(idAttr) |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 481 | #if ENABLE(FULLSCREEN_API) |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 482 | , m_areKeysEnabledInFullScreen(0) |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 483 | , m_fullScreenRenderer(0) |
| 484 | , m_fullScreenChangeDelayTimer(this, &Document::fullScreenChangeDelayTimerFired) |
jer.noble@apple.com | fed7d93 | 2011-05-23 22:22:27 +0000 | [diff] [blame] | 485 | , m_isAnimatingFullScreen(false) |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 486 | #endif |
eric.carlson@apple.com | 9c7fc72 | 2010-08-26 16:45:43 +0000 | [diff] [blame] | 487 | , m_loadEventDelayCount(0) |
jschuh@chromium.org | 47fb2f5 | 2010-10-04 22:25:43 +0000 | [diff] [blame] | 488 | , m_loadEventDelayTimer(this, &Document::loadEventDelayTimerFired) |
gavinp@chromium.org | 4b82056 | 2012-04-23 12:53:24 +0000 | [diff] [blame] | 489 | , m_referrerPolicy(ReferrerPolicyDefault) |
hyatt@apple.com | 3b5d20f0 | 2010-10-26 18:32:57 +0000 | [diff] [blame] | 490 | , m_directionSetOnDocumentElement(false) |
| 491 | , m_writingModeSetOnDocumentElement(false) |
commit-queue@webkit.org | b7b2b52 | 2011-02-02 00:22:52 +0000 | [diff] [blame] | 492 | , m_writeRecursionIsTooDeep(false) |
| 493 | , m_writeRecursionDepth(0) |
jonlee@apple.com | 8d90918 | 2011-05-16 17:25:02 +0000 | [diff] [blame] | 494 | , m_wheelEventHandlerCount(0) |
pierre.rossi@gmail.com | 81b0596 | 2012-07-23 18:31:14 +0000 | [diff] [blame] | 495 | #if ENABLE(TOUCH_EVENTS) |
commit-queue@webkit.org | 7c44a68 | 2012-02-15 20:21:15 +0000 | [diff] [blame] | 496 | , m_touchEventHandlerCount(0) |
pierre.rossi@gmail.com | 81b0596 | 2012-07-23 18:31:14 +0000 | [diff] [blame] | 497 | #endif |
commit-queue@webkit.org | 5deb749 | 2012-06-09 09:05:22 +0000 | [diff] [blame] | 498 | #if ENABLE(UNDO_MANAGER) |
| 499 | , m_undoManager(0) |
| 500 | #endif |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 501 | , m_pendingTasksTimer(this, &Document::pendingTasksTimerFired) |
beidson@apple.com | b1bc1b7 | 2012-04-20 21:29:00 +0000 | [diff] [blame] | 502 | , m_scheduledTasksAreSuspended(false) |
aestes@apple.com | 4544ec1 | 2012-04-24 07:43:40 +0000 | [diff] [blame] | 503 | , m_visualUpdatesAllowed(true) |
| 504 | , m_visualUpdatesSuppressionTimer(this, &Document::visualUpdatesSuppressionTimerFired) |
commit-queue@webkit.org | 7adcbd8 | 2012-05-02 13:00:47 +0000 | [diff] [blame] | 505 | #ifndef NDEBUG |
| 506 | , m_didDispatchViewportPropertiesChanged(false) |
| 507 | #endif |
ojan@chromium.org | 32aefb5 | 2011-11-11 19:14:25 +0000 | [diff] [blame] | 508 | { |
commit-queue@webkit.org | c4534e1 | 2012-07-24 00:53:24 +0000 | [diff] [blame] | 509 | m_document = this; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 510 | |
| 511 | m_printing = false; |
hyatt@apple.com | 16a3600 | 2010-08-11 19:48:07 +0000 | [diff] [blame] | 512 | m_paginatedForScreen = false; |
| 513 | |
adele@apple.com | b68cb86 | 2008-06-17 18:45:06 +0000 | [diff] [blame] | 514 | m_ignoreAutofocus = false; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 515 | |
mjs | 22f8a1a | 2007-04-29 07:33:46 +0000 | [diff] [blame] | 516 | m_frame = frame; |
morrita@google.com | ac74304 | 2012-06-13 08:05:43 +0000 | [diff] [blame] | 517 | if (m_frame) |
| 518 | provideContextFeaturesToDocumentFrom(this, m_frame->page()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 519 | |
japhet@chromium.org | b254c9b | 2011-01-26 19:14:26 +0000 | [diff] [blame] | 520 | // We depend on the url getting immediately set in subframes, but we |
| 521 | // also depend on the url NOT getting immediately set in opened windows. |
| 522 | // See fast/dom/early-frame-url.html |
| 523 | // and fast/dom/location-new-window-no-crash.html, respectively. |
| 524 | // FIXME: Can/should we unify this behavior? |
| 525 | if ((frame && frame->ownerElement()) || !url.isEmpty()) |
japhet@chromium.org | 6a088ce | 2010-06-25 17:17:45 +0000 | [diff] [blame] | 526 | setURL(url); |
| 527 | |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 528 | m_axObjectCache = 0; |
dbates@webkit.org | 858331b | 2010-08-22 21:41:37 +0000 | [diff] [blame] | 529 | |
levin@chromium.org | 5af8b19 | 2011-04-26 17:16:27 +0000 | [diff] [blame] | 530 | m_markers = adoptPtr(new DocumentMarkerController); |
dbates@webkit.org | 858331b | 2010-08-22 21:41:37 +0000 | [diff] [blame] | 531 | |
levin@chromium.org | 5af8b19 | 2011-04-26 17:16:27 +0000 | [diff] [blame] | 532 | m_cachedResourceLoader = adoptPtr(new CachedResourceLoader(this)); |
gavinp@chromium.org | af445b9 | 2012-05-15 04:42:52 +0000 | [diff] [blame] | 533 | #if ENABLE(LINK_PRERENDER) |
| 534 | m_prerenderer = Prerenderer::create(this); |
| 535 | #endif |
commit-queue@webkit.org | 85cce8f | 2012-07-04 17:43:12 +0000 | [diff] [blame] | 536 | #if ENABLE(TEXT_AUTOSIZING) |
| 537 | m_textAutosizer = TextAutosizer::create(this); |
| 538 | #endif |
hyatt@apple.com | 0880de1 | 2010-01-28 17:47:30 +0000 | [diff] [blame] | 539 | m_visuallyOrdered = false; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 540 | m_bParsing = false; |
ap | 2cb6b94 | 2006-11-20 19:56:38 +0000 | [diff] [blame] | 541 | m_wellFormed = false; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 542 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 543 | m_textColor = Color::black; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 544 | m_listenerTypes = 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 545 | m_inStyleRecalc = false; |
| 546 | m_closeAfterStyleRecalc = false; |
hyatt@apple.com | a67f96a | 2009-07-15 17:02:30 +0000 | [diff] [blame] | 547 | |
thatcher | 398012b | 2007-07-24 00:04:32 +0000 | [diff] [blame] | 548 | m_gotoAnchorNeededAfterStylesheetsLoad = false; |
abarth@webkit.org | 90a3ca6 | 2011-04-14 19:54:30 +0000 | [diff] [blame] | 549 | |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 550 | m_didCalculateStyleResolver = false; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 551 | m_ignorePendingStylesheets = false; |
morrita@google.com | cc735a7 | 2012-08-20 02:56:18 +0000 | [diff] [blame] | 552 | m_needsNotifyRemoveAllPendingStylesheet = false; |
antti | fa58db35 | 2007-08-29 22:46:41 +0000 | [diff] [blame] | 553 | m_hasNodesWithPlaceholderStyle = false; |
hyatt | a9c6a34 | 2006-09-02 01:43:36 +0000 | [diff] [blame] | 554 | m_pendingSheetLayout = NoLayoutWithPendingSheets; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 555 | |
| 556 | m_cssTarget = 0; |
| 557 | |
| 558 | resetLinkColor(); |
| 559 | resetVisitedLinkColor(); |
| 560 | resetActiveLinkColor(); |
| 561 | |
| 562 | m_processingLoadEvent = false; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 563 | |
abarth@webkit.org | 51aed8c | 2008-06-12 06:41:36 +0000 | [diff] [blame] | 564 | initSecurityContext(); |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 565 | initDNSPrefetch(); |
weinig | 343b6ff | 2007-08-07 03:08:53 +0000 | [diff] [blame] | 566 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 567 | static int docID = 0; |
| 568 | m_docID = docID++; |
rniwa@webkit.org | fc3b7b7 | 2012-07-12 20:31:09 +0000 | [diff] [blame] | 569 | |
| 570 | for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); i++) |
| 571 | m_nodeListCounts[i] = 0; |
| 572 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 573 | for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_collections); i++) |
| 574 | m_collections[i] = 0; |
| 575 | |
yurys@chromium.org | 793b08e | 2012-02-17 08:33:30 +0000 | [diff] [blame] | 576 | InspectorCounters::incrementCounter(InspectorCounters::DocumentCounter); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 577 | } |
| 578 | |
commit-queue@webkit.org | 2206b55 | 2011-11-15 01:23:35 +0000 | [diff] [blame] | 579 | static void histogramMutationEventUsage(const unsigned short& listenerTypes) |
| 580 | { |
commit-queue@webkit.org | bfdd472 | 2011-12-17 00:58:33 +0000 | [diff] [blame] | 581 | HistogramSupport::histogramEnumeration("DOMAPI.PerDocumentMutationEventUsage.DOMSubtreeModified", static_cast<bool>(listenerTypes & Document::DOMSUBTREEMODIFIED_LISTENER), 2); |
| 582 | HistogramSupport::histogramEnumeration("DOMAPI.PerDocumentMutationEventUsage.DOMNodeInserted", static_cast<bool>(listenerTypes & Document::DOMNODEINSERTED_LISTENER), 2); |
| 583 | HistogramSupport::histogramEnumeration("DOMAPI.PerDocumentMutationEventUsage.DOMNodeRemoved", static_cast<bool>(listenerTypes & Document::DOMNODEREMOVED_LISTENER), 2); |
| 584 | HistogramSupport::histogramEnumeration("DOMAPI.PerDocumentMutationEventUsage.DOMNodeRemovedFromDocument", static_cast<bool>(listenerTypes & Document::DOMNODEREMOVEDFROMDOCUMENT_LISTENER), 2); |
| 585 | HistogramSupport::histogramEnumeration("DOMAPI.PerDocumentMutationEventUsage.DOMNodeInsertedIntoDocument", static_cast<bool>(listenerTypes & Document::DOMNODEINSERTEDINTODOCUMENT_LISTENER), 2); |
| 586 | HistogramSupport::histogramEnumeration("DOMAPI.PerDocumentMutationEventUsage.DOMCharacterDataModified", static_cast<bool>(listenerTypes & Document::DOMCHARACTERDATAMODIFIED_LISTENER), 2); |
commit-queue@webkit.org | 2206b55 | 2011-11-15 01:23:35 +0000 | [diff] [blame] | 587 | } |
commit-queue@webkit.org | 2206b55 | 2011-11-15 01:23:35 +0000 | [diff] [blame] | 588 | |
scheib@chromium.org | e0e6003 | 2012-07-18 20:06:12 +0000 | [diff] [blame] | 589 | #if ENABLE(FULLSCREEN_API) |
| 590 | static bool isAttributeOnAllOwners(const WebCore::QualifiedName& attribute, const HTMLFrameOwnerElement* owner) |
| 591 | { |
| 592 | if (!owner) |
| 593 | return true; |
| 594 | do { |
| 595 | if (!owner->hasAttribute(attribute)) |
| 596 | return false; |
| 597 | } while ((owner = owner->document()->ownerElement())); |
| 598 | return true; |
| 599 | } |
| 600 | #endif |
| 601 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 602 | Document::~Document() |
| 603 | { |
beidson | ddbaead | 2006-12-13 23:34:09 +0000 | [diff] [blame] | 604 | ASSERT(!renderer()); |
| 605 | ASSERT(!m_inPageCache); |
| 606 | ASSERT(!m_savedRenderer); |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 607 | ASSERT(m_ranges.isEmpty()); |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 608 | ASSERT(!m_styleRecalcTimer.isActive()); |
rolandsteiner@chromium.org | 05d9423 | 2011-04-08 22:37:39 +0000 | [diff] [blame] | 609 | ASSERT(!m_parentTreeScope); |
rolandsteiner@chromium.org | d905546 | 2011-04-20 17:25:33 +0000 | [diff] [blame] | 610 | ASSERT(!m_guardRefCount); |
beidson | ddbaead | 2006-12-13 23:34:09 +0000 | [diff] [blame] | 611 | |
abarth@webkit.org | 7d4cb04 | 2012-08-17 00:29:35 +0000 | [diff] [blame] | 612 | // FIXME: Should we reset m_domWindow when we detach from the Frame? |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 613 | if (m_domWindow) |
abarth@webkit.org | 7d4cb04 | 2012-08-17 00:29:35 +0000 | [diff] [blame] | 614 | m_domWindow->resetUnlessSuspendedForPageCache(); |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 615 | |
simonjam@chromium.org | 5871a05 | 2011-03-16 00:00:09 +0000 | [diff] [blame] | 616 | m_scriptRunner.clear(); |
mitz@apple.com | 73169a1 | 2009-04-20 04:20:08 +0000 | [diff] [blame] | 617 | |
commit-queue@webkit.org | 2206b55 | 2011-11-15 01:23:35 +0000 | [diff] [blame] | 618 | histogramMutationEventUsage(m_listenerTypes); |
commit-queue@webkit.org | 2206b55 | 2011-11-15 01:23:35 +0000 | [diff] [blame] | 619 | |
beidson | ddbaead | 2006-12-13 23:34:09 +0000 | [diff] [blame] | 620 | removeAllEventListeners(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 621 | |
eric@webkit.org | 0cea84c | 2010-08-19 19:32:02 +0000 | [diff] [blame] | 622 | // Currently we believe that Document can never outlive the parser. |
| 623 | // Although the Document may be replaced synchronously, DocumentParsers |
| 624 | // generally keep at least one reference to an Element which would in turn |
| 625 | // has a reference to the Document. If you hit this ASSERT, then that |
| 626 | // assumption is wrong. DocumentParser::detach() should ensure that even |
| 627 | // if the DocumentParser outlives the Document it won't cause badness. |
| 628 | ASSERT(!m_parser || m_parser->refCount() == 1); |
| 629 | detachParser(); |
abarth@webkit.org | e5cb28e | 2009-12-04 05:28:33 +0000 | [diff] [blame] | 630 | |
abarth@webkit.org | 3e03535 | 2009-12-04 05:54:58 +0000 | [diff] [blame] | 631 | m_renderArena.clear(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 632 | |
harrison@apple.com | 7954df2 | 2008-03-12 16:16:40 +0000 | [diff] [blame] | 633 | clearAXObjectCache(); |
| 634 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 635 | m_decoder = 0; |
paroga@webkit.org | a91ac21 | 2010-11-23 00:55:59 +0000 | [diff] [blame] | 636 | |
antti@apple.com | 8a2e6f0 | 2012-09-25 04:25:35 +0000 | [diff] [blame] | 637 | if (m_styleSheetList) |
| 638 | m_styleSheetList->detachFromDocument(); |
| 639 | |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 640 | m_styleSheetCollection.clear(); |
dimich@chromium.org | 948b9a3 | 2010-01-15 21:47:15 +0000 | [diff] [blame] | 641 | |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 642 | if (m_namedFlows) |
| 643 | m_namedFlows->documentDestroyed(); |
| 644 | |
ap@apple.com | 1fe9089 | 2010-11-10 21:12:39 +0000 | [diff] [blame] | 645 | if (m_elemSheet) |
| 646 | m_elemSheet->clearOwnerNode(); |
ap@apple.com | 1fe9089 | 2010-11-10 21:12:39 +0000 | [diff] [blame] | 647 | |
commit-queue@webkit.org | def1a49 | 2012-09-07 22:58:56 +0000 | [diff] [blame] | 648 | deleteCustomFonts(); |
| 649 | |
dimich@chromium.org | 948b9a3 | 2010-01-15 21:47:15 +0000 | [diff] [blame] | 650 | m_weakReference->clear(); |
luiz@webkit.org | db0dd43 | 2010-11-22 21:02:27 +0000 | [diff] [blame] | 651 | |
| 652 | if (m_mediaQueryMatcher) |
| 653 | m_mediaQueryMatcher->documentDestroyed(); |
hayato@chromium.org | 81596e4 | 2012-02-02 04:21:29 +0000 | [diff] [blame] | 654 | |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 655 | clearStyleResolver(); // We need to destory CSSFontSelector before destroying m_cachedResourceLoader. |
rniwa@webkit.org | 1c7df64 | 2012-02-10 03:34:21 +0000 | [diff] [blame] | 656 | m_cachedResourceLoader.clear(); |
| 657 | |
hayato@chromium.org | 81596e4 | 2012-02-02 04:21:29 +0000 | [diff] [blame] | 658 | // We must call clearRareData() here since a Document class inherits TreeScope |
| 659 | // as well as Node. See a comment on TreeScope.h for the reason. |
| 660 | if (hasRareData()) |
| 661 | clearRareData(); |
yurys@chromium.org | 793b08e | 2012-02-17 08:33:30 +0000 | [diff] [blame] | 662 | |
rniwa@webkit.org | fc3b7b7 | 2012-07-12 20:31:09 +0000 | [diff] [blame] | 663 | ASSERT(!m_listsInvalidatedAtDocument.size()); |
| 664 | |
| 665 | for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); i++) |
| 666 | ASSERT(!m_nodeListCounts[i]); |
| 667 | |
| 668 | for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_collections); i++) |
| 669 | ASSERT(!m_collections[i]); |
| 670 | |
commit-queue@webkit.org | c4534e1 | 2012-07-24 00:53:24 +0000 | [diff] [blame] | 671 | m_document = 0; |
haraken@chromium.org | abf5d02 | 2012-06-28 06:29:27 +0000 | [diff] [blame] | 672 | |
yurys@chromium.org | 793b08e | 2012-02-17 08:33:30 +0000 | [diff] [blame] | 673 | InspectorCounters::decrementCounter(InspectorCounters::DocumentCounter); |
luiz@webkit.org | db0dd43 | 2010-11-22 21:02:27 +0000 | [diff] [blame] | 674 | } |
| 675 | |
rolandsteiner@chromium.org | dafa610 | 2011-04-06 23:52:52 +0000 | [diff] [blame] | 676 | void Document::removedLastRef() |
| 677 | { |
haraken@chromium.org | 971871a | 2012-06-08 09:19:39 +0000 | [diff] [blame] | 678 | ASSERT(!m_deletionHasBegun); |
rolandsteiner@chromium.org | dafa610 | 2011-04-06 23:52:52 +0000 | [diff] [blame] | 679 | if (m_guardRefCount) { |
| 680 | // If removing a child removes the last self-only ref, we don't |
| 681 | // want the scope to be destructed until after |
| 682 | // removeAllChildren returns, so we guard ourselves with an |
| 683 | // extra self-only ref. |
| 684 | guardRef(); |
| 685 | |
| 686 | // We must make sure not to be retaining any of our children through |
| 687 | // these extra pointers or we will create a reference cycle. |
| 688 | m_docType = 0; |
| 689 | m_focusedNode = 0; |
| 690 | m_hoverNode = 0; |
| 691 | m_activeNode = 0; |
| 692 | m_titleElement = 0; |
| 693 | m_documentElement = 0; |
morrita@google.com | ac74304 | 2012-06-13 08:05:43 +0000 | [diff] [blame] | 694 | m_contextFeatures = ContextFeatures::defaultSwitch(); |
rolandsteiner@chromium.org | dafa610 | 2011-04-06 23:52:52 +0000 | [diff] [blame] | 695 | #if ENABLE(FULLSCREEN_API) |
| 696 | m_fullScreenElement = 0; |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 697 | m_fullScreenElementStack.clear(); |
rolandsteiner@chromium.org | dafa610 | 2011-04-06 23:52:52 +0000 | [diff] [blame] | 698 | #endif |
| 699 | |
jpfau@apple.com | b601f18 | 2012-06-04 23:38:33 +0000 | [diff] [blame] | 700 | detachParser(); |
| 701 | |
rolandsteiner@chromium.org | dafa610 | 2011-04-06 23:52:52 +0000 | [diff] [blame] | 702 | // removeAllChildren() doesn't always unregister IDs, |
| 703 | // so tear down scope information upfront to avoid having stale references in the map. |
| 704 | destroyTreeScopeData(); |
| 705 | removeAllChildren(); |
| 706 | |
| 707 | m_markers->detach(); |
| 708 | |
rolandsteiner@chromium.org | dafa610 | 2011-04-06 23:52:52 +0000 | [diff] [blame] | 709 | m_cssCanvasElements.clear(); |
| 710 | |
| 711 | #if ENABLE(REQUEST_ANIMATION_FRAME) |
| 712 | // FIXME: consider using ActiveDOMObject. |
jamesr@google.com | a5d3c9e | 2011-12-09 01:33:41 +0000 | [diff] [blame] | 713 | if (m_scriptedAnimationController) |
| 714 | m_scriptedAnimationController->clearDocumentPointer(); |
| 715 | m_scriptedAnimationController.clear(); |
rolandsteiner@chromium.org | dafa610 | 2011-04-06 23:52:52 +0000 | [diff] [blame] | 716 | #endif |
| 717 | |
| 718 | #ifndef NDEBUG |
| 719 | m_inRemovedLastRefFunction = false; |
| 720 | #endif |
| 721 | |
| 722 | guardDeref(); |
| 723 | } else { |
haraken@chromium.org | 971871a | 2012-06-08 09:19:39 +0000 | [diff] [blame] | 724 | #ifndef NDEBUG |
| 725 | m_deletionHasBegun = true; |
| 726 | #endif |
rolandsteiner@chromium.org | dafa610 | 2011-04-06 23:52:52 +0000 | [diff] [blame] | 727 | delete this; |
| 728 | } |
| 729 | } |
| 730 | |
rolandsteiner@chromium.org | a3cbe77 | 2011-04-04 22:25:18 +0000 | [diff] [blame] | 731 | Element* Document::getElementById(const AtomicString& id) const |
| 732 | { |
| 733 | return TreeScope::getElementById(id); |
| 734 | } |
| 735 | |
rolandsteiner@chromium.org | a8fbd63 | 2011-05-03 23:08:21 +0000 | [diff] [blame] | 736 | Element* Document::getElementByAccessKey(const String& key) |
| 737 | { |
| 738 | if (key.isEmpty()) |
| 739 | return 0; |
| 740 | if (!m_accessKeyMapValid) { |
| 741 | buildAccessKeyMap(this); |
| 742 | m_accessKeyMapValid = true; |
| 743 | } |
| 744 | return m_elementsByAccessKey.get(key.impl()); |
| 745 | } |
| 746 | |
hayato@chromium.org | 81596e4 | 2012-02-02 04:21:29 +0000 | [diff] [blame] | 747 | void Document::buildAccessKeyMap(TreeScope* scope) |
rolandsteiner@chromium.org | a8fbd63 | 2011-05-03 23:08:21 +0000 | [diff] [blame] | 748 | { |
hayato@chromium.org | 81596e4 | 2012-02-02 04:21:29 +0000 | [diff] [blame] | 749 | ASSERT(scope); |
| 750 | Node* rootNode = scope->rootNode(); |
| 751 | for (Node* node = rootNode; node; node = node->traverseNextNode(rootNode)) { |
| 752 | if (!node->isElementNode()) |
rolandsteiner@chromium.org | a8fbd63 | 2011-05-03 23:08:21 +0000 | [diff] [blame] | 753 | continue; |
hayato@chromium.org | 81596e4 | 2012-02-02 04:21:29 +0000 | [diff] [blame] | 754 | Element* element = static_cast<Element*>(node); |
commit-queue@webkit.org | 03477c8 | 2011-09-02 17:07:51 +0000 | [diff] [blame] | 755 | const AtomicString& accessKey = element->getAttribute(accesskeyAttr); |
rolandsteiner@chromium.org | a8fbd63 | 2011-05-03 23:08:21 +0000 | [diff] [blame] | 756 | if (!accessKey.isEmpty()) |
| 757 | m_elementsByAccessKey.set(accessKey.impl(), element); |
commit-queue@webkit.org | 3676218 | 2012-02-14 12:48:24 +0000 | [diff] [blame] | 758 | |
morrita@google.com | e200421 | 2012-05-21 16:59:02 +0000 | [diff] [blame] | 759 | for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->olderShadowRoot()) |
| 760 | buildAccessKeyMap(root); |
rolandsteiner@chromium.org | a8fbd63 | 2011-05-03 23:08:21 +0000 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | |
| 764 | void Document::invalidateAccessKeyMap() |
| 765 | { |
| 766 | m_accessKeyMapValid = false; |
| 767 | m_elementsByAccessKey.clear(); |
| 768 | } |
| 769 | |
haraken@chromium.org | 3981f52 | 2012-06-02 19:23:25 +0000 | [diff] [blame] | 770 | SelectorQueryCache* Document::selectorQueryCache() |
| 771 | { |
| 772 | if (!m_selectorQueryCache) |
| 773 | m_selectorQueryCache = adoptPtr(new SelectorQueryCache()); |
| 774 | return m_selectorQueryCache.get(); |
| 775 | } |
| 776 | |
luiz@webkit.org | db0dd43 | 2010-11-22 21:02:27 +0000 | [diff] [blame] | 777 | MediaQueryMatcher* Document::mediaQueryMatcher() |
| 778 | { |
| 779 | if (!m_mediaQueryMatcher) |
| 780 | m_mediaQueryMatcher = MediaQueryMatcher::create(this); |
| 781 | return m_mediaQueryMatcher.get(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 782 | } |
| 783 | |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 784 | void Document::setCompatibilityMode(CompatibilityMode mode) |
| 785 | { |
| 786 | if (m_compatibilityModeLocked || mode == m_compatibilityMode) |
| 787 | return; |
antti@apple.com | 8a2e6f0 | 2012-09-25 04:25:35 +0000 | [diff] [blame] | 788 | ASSERT(m_styleSheetCollection->authorStyleSheets().isEmpty()); |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 789 | bool wasInQuirksMode = inQuirksMode(); |
| 790 | m_compatibilityMode = mode; |
haraken@chromium.org | 3981f52 | 2012-06-02 19:23:25 +0000 | [diff] [blame] | 791 | selectorQueryCache()->invalidate(); |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 792 | if (inQuirksMode() != wasInQuirksMode) { |
| 793 | // All user stylesheets have to reparse using the different mode. |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 794 | m_styleSheetCollection->clearPageUserSheet(); |
| 795 | m_styleSheetCollection->clearPageGroupUserSheets(); |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
abarth@webkit.org | d33c937 | 2010-09-14 23:27:19 +0000 | [diff] [blame] | 799 | String Document::compatMode() const |
| 800 | { |
| 801 | return inQuirksMode() ? "BackCompat" : "CSS1Compat"; |
| 802 | } |
| 803 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 804 | void Document::resetLinkColor() |
| 805 | { |
| 806 | m_linkColor = Color(0, 0, 238); |
| 807 | } |
| 808 | |
| 809 | void Document::resetVisitedLinkColor() |
| 810 | { |
| 811 | m_visitedLinkColor = Color(85, 26, 139); |
| 812 | } |
| 813 | |
| 814 | void Document::resetActiveLinkColor() |
| 815 | { |
eseidel | cff0a72 | 2006-03-22 22:27:45 +0000 | [diff] [blame] | 816 | m_activeLinkColor.setNamedColor("red"); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | void Document::setDocType(PassRefPtr<DocumentType> docType) |
| 820 | { |
hyatt@apple.com | 4258307 | 2008-02-20 22:47:57 +0000 | [diff] [blame] | 821 | // This should never be called more than once. |
hyatt@apple.com | 4258307 | 2008-02-20 22:47:57 +0000 | [diff] [blame] | 822 | ASSERT(!m_docType || !docType); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 823 | m_docType = docType; |
commit-queue@webkit.org | 7736e17 | 2012-05-09 23:10:21 +0000 | [diff] [blame] | 824 | if (m_docType) { |
morrita@google.com | e08d15a | 2012-01-10 02:11:30 +0000 | [diff] [blame] | 825 | this->adoptIfNeeded(m_docType.get()); |
commit-queue@webkit.org | 38d6785 | 2012-06-05 03:01:18 +0000 | [diff] [blame] | 826 | #if ENABLE(LEGACY_VIEWPORT_ADAPTION) |
commit-queue@webkit.org | 7736e17 | 2012-05-09 23:10:21 +0000 | [diff] [blame] | 827 | if (m_docType->publicId().startsWith("-//wapforum//dtd xhtml mobile 1.", /* caseSensitive */ false)) |
commit-queue@webkit.org | 36e5ae1 | 2012-06-01 18:24:02 +0000 | [diff] [blame] | 828 | processViewport("width=device-width, height=device-height", ViewportArguments::XHTMLMobileProfile); |
commit-queue@webkit.org | 7736e17 | 2012-05-09 23:10:21 +0000 | [diff] [blame] | 829 | #endif |
| 830 | } |
antti@apple.com | 0a03deb | 2012-01-06 14:48:23 +0000 | [diff] [blame] | 831 | // Doctype affects the interpretation of the stylesheets. |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 832 | clearStyleResolver(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 833 | } |
| 834 | |
antonm@chromium.org | 305e54d | 2011-02-21 16:01:41 +0000 | [diff] [blame] | 835 | DOMImplementation* Document::implementation() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 836 | { |
weinig@apple.com | 3feb4c3 | 2008-06-15 21:53:29 +0000 | [diff] [blame] | 837 | if (!m_implementation) |
antonm@chromium.org | 305e54d | 2011-02-21 16:01:41 +0000 | [diff] [blame] | 838 | m_implementation = DOMImplementation::create(this); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 839 | return m_implementation.get(); |
| 840 | } |
| 841 | |
hyatt@apple.com | 86b942b | 2008-02-27 23:13:51 +0000 | [diff] [blame] | 842 | void Document::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) |
thatcher | e6e3e56 | 2006-07-09 07:56:54 +0000 | [diff] [blame] | 843 | { |
hayato@chromium.org | 81596e4 | 2012-02-02 04:21:29 +0000 | [diff] [blame] | 844 | ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); |
hyatt@apple.com | 86b942b | 2008-02-27 23:13:51 +0000 | [diff] [blame] | 845 | |
antti@apple.com | 70726ab | 2012-01-08 11:45:58 +0000 | [diff] [blame] | 846 | Element* newDocumentElement = firstElementChild(this); |
| 847 | if (newDocumentElement == m_documentElement) |
| 848 | return; |
| 849 | m_documentElement = newDocumentElement; |
| 850 | // The root style used for media query matching depends on the document element. |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 851 | clearStyleResolver(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 852 | } |
| 853 | |
mjs@apple.com | 773874c | 2008-03-30 04:58:08 +0000 | [diff] [blame] | 854 | PassRefPtr<Element> Document::createElement(const AtomicString& name, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 855 | { |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 856 | if (!isValidName(name)) { |
| 857 | ec = INVALID_CHARACTER_ERR; |
| 858 | return 0; |
| 859 | } |
kmccullo | c19b279 | 2007-08-08 17:14:42 +0000 | [diff] [blame] | 860 | |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 861 | if (m_isXHTML) |
jchaffraix@webkit.org | 6d04619 | 2008-11-24 19:29:39 +0000 | [diff] [blame] | 862 | return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, name, xhtmlNamespaceURI), this, 0, false); |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 863 | |
jchaffraix@webkit.org | 0ad36c3 | 2009-02-12 20:52:02 +0000 | [diff] [blame] | 864 | return createElement(QualifiedName(nullAtom, name, nullAtom), false); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | PassRefPtr<DocumentFragment> Document::createDocumentFragment() |
| 868 | { |
darin@apple.com | 7e131b6 | 2009-08-15 06:25:49 +0000 | [diff] [blame] | 869 | return DocumentFragment::create(document()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 870 | } |
| 871 | |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 872 | PassRefPtr<Text> Document::createTextNode(const String& data) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 873 | { |
darin@apple.com | 7e131b6 | 2009-08-15 06:25:49 +0000 | [diff] [blame] | 874 | return Text::create(this, data); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 875 | } |
| 876 | |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 877 | PassRefPtr<Comment> Document::createComment(const String& data) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 878 | { |
darin@apple.com | 7e131b6 | 2009-08-15 06:25:49 +0000 | [diff] [blame] | 879 | return Comment::create(this, data); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 880 | } |
| 881 | |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 882 | PassRefPtr<CDATASection> Document::createCDATASection(const String& data, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 883 | { |
| 884 | if (isHTMLDocument()) { |
| 885 | ec = NOT_SUPPORTED_ERR; |
| 886 | return 0; |
| 887 | } |
darin@apple.com | 7e131b6 | 2009-08-15 06:25:49 +0000 | [diff] [blame] | 888 | return CDATASection::create(this, data); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 889 | } |
| 890 | |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 891 | PassRefPtr<ProcessingInstruction> Document::createProcessingInstruction(const String& target, const String& data, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 892 | { |
| 893 | if (!isValidName(target)) { |
| 894 | ec = INVALID_CHARACTER_ERR; |
| 895 | return 0; |
| 896 | } |
| 897 | if (isHTMLDocument()) { |
| 898 | ec = NOT_SUPPORTED_ERR; |
| 899 | return 0; |
| 900 | } |
darin@apple.com | 7e131b6 | 2009-08-15 06:25:49 +0000 | [diff] [blame] | 901 | return ProcessingInstruction::create(this, target, data); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 902 | } |
| 903 | |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 904 | PassRefPtr<EntityReference> Document::createEntityReference(const String& name, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 905 | { |
| 906 | if (!isValidName(name)) { |
| 907 | ec = INVALID_CHARACTER_ERR; |
| 908 | return 0; |
| 909 | } |
| 910 | if (isHTMLDocument()) { |
| 911 | ec = NOT_SUPPORTED_ERR; |
| 912 | return 0; |
| 913 | } |
darin@apple.com | 7e131b6 | 2009-08-15 06:25:49 +0000 | [diff] [blame] | 914 | return EntityReference::create(this, name); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 915 | } |
| 916 | |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 917 | PassRefPtr<EditingText> Document::createEditingTextNode(const String& text) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 918 | { |
darin@apple.com | 7e131b6 | 2009-08-15 06:25:49 +0000 | [diff] [blame] | 919 | return EditingText::create(this, text); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | PassRefPtr<CSSStyleDeclaration> Document::createCSSStyleDeclaration() |
| 923 | { |
antti@apple.com | e89e04d | 2012-02-03 19:46:48 +0000 | [diff] [blame] | 924 | return StylePropertySet::create()->ensureCSSStyleDeclaration(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionCode& ec) |
| 928 | { |
| 929 | ec = 0; |
ggaren | 59d1d76 | 2006-04-22 07:33:04 +0000 | [diff] [blame] | 930 | |
timothy_horton@apple.com | 6973661 | 2012-02-24 19:39:01 +0000 | [diff] [blame] | 931 | if (!importedNode) { |
ggaren | 59d1d76 | 2006-04-22 07:33:04 +0000 | [diff] [blame] | 932 | ec = NOT_SUPPORTED_ERR; |
| 933 | return 0; |
| 934 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 935 | |
| 936 | switch (importedNode->nodeType()) { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 937 | case TEXT_NODE: |
| 938 | return createTextNode(importedNode->nodeValue()); |
| 939 | case CDATA_SECTION_NODE: |
| 940 | return createCDATASection(importedNode->nodeValue(), ec); |
| 941 | case ENTITY_REFERENCE_NODE: |
| 942 | return createEntityReference(importedNode->nodeName(), ec); |
| 943 | case PROCESSING_INSTRUCTION_NODE: |
| 944 | return createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue(), ec); |
| 945 | case COMMENT_NODE: |
| 946 | return createComment(importedNode->nodeValue()); |
| 947 | case ELEMENT_NODE: { |
| 948 | Element* oldElement = static_cast<Element*>(importedNode); |
tkent@chromium.org | 02045fa | 2012-01-06 08:47:18 +0000 | [diff] [blame] | 949 | // FIXME: The following check might be unnecessary. Is it possible that |
| 950 | // oldElement has mismatched prefix/namespace? |
abarth@webkit.org | 427e9f1 | 2012-01-19 08:31:13 +0000 | [diff] [blame] | 951 | if (!hasValidNamespaceForElements(oldElement->tagQName())) { |
tkent@chromium.org | 02045fa | 2012-01-06 08:47:18 +0000 | [diff] [blame] | 952 | ec = NAMESPACE_ERR; |
| 953 | return 0; |
| 954 | } |
| 955 | RefPtr<Element> newElement = createElement(oldElement->tagQName(), ec); |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 956 | if (ec) |
| 957 | return 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 958 | |
kling@webkit.org | c4ff976 | 2012-05-16 19:31:40 +0000 | [diff] [blame] | 959 | newElement->cloneDataFromElement(*oldElement); |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 960 | |
| 961 | if (deep) { |
| 962 | for (Node* oldChild = oldElement->firstChild(); oldChild; oldChild = oldChild->nextSibling()) { |
| 963 | RefPtr<Node> newChild = importNode(oldChild, true, ec); |
| 964 | if (ec) |
| 965 | return 0; |
| 966 | newElement->appendChild(newChild.release(), ec); |
| 967 | if (ec) |
| 968 | return 0; |
ap | 4af4d7f | 2007-10-25 18:31:32 +0000 | [diff] [blame] | 969 | } |
ap | 4af4d7f | 2007-10-25 18:31:32 +0000 | [diff] [blame] | 970 | } |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 971 | |
| 972 | return newElement.release(); |
| 973 | } |
| 974 | case ATTRIBUTE_NODE: |
kling@webkit.org | e3f8e9d | 2012-04-23 05:40:02 +0000 | [diff] [blame] | 975 | return Attr::create(this, QualifiedName(nullAtom, static_cast<Attr*>(importedNode)->name(), nullAtom), static_cast<Attr*>(importedNode)->value()); |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 976 | case DOCUMENT_FRAGMENT_NODE: { |
hayato@chromium.org | 14993e0 | 2012-02-14 11:32:12 +0000 | [diff] [blame] | 977 | if (importedNode->isShadowRoot()) { |
| 978 | // ShadowRoot nodes should not be explicitly importable. |
| 979 | // Either they are imported along with their host node, or created implicitly. |
| 980 | break; |
| 981 | } |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 982 | DocumentFragment* oldFragment = static_cast<DocumentFragment*>(importedNode); |
| 983 | RefPtr<DocumentFragment> newFragment = createDocumentFragment(); |
| 984 | if (deep) { |
| 985 | for (Node* oldChild = oldFragment->firstChild(); oldChild; oldChild = oldChild->nextSibling()) { |
| 986 | RefPtr<Node> newChild = importNode(oldChild, true, ec); |
| 987 | if (ec) |
| 988 | return 0; |
| 989 | newFragment->appendChild(newChild.release(), ec); |
| 990 | if (ec) |
| 991 | return 0; |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | return newFragment.release(); |
| 996 | } |
| 997 | case ENTITY_NODE: |
| 998 | case NOTATION_NODE: |
| 999 | // FIXME: It should be possible to import these node types, however in DOM3 the DocumentType is readonly, so there isn't much sense in doing that. |
| 1000 | // Ability to add these imported nodes to a DocumentType will be considered for addition to a future release of the DOM. |
| 1001 | case DOCUMENT_NODE: |
| 1002 | case DOCUMENT_TYPE_NODE: |
| 1003 | case XPATH_NAMESPACE_NODE: |
| 1004 | break; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1005 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1006 | ec = NOT_SUPPORTED_ERR; |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | PassRefPtr<Node> Document::adoptNode(PassRefPtr<Node> source, ExceptionCode& ec) |
| 1012 | { |
ggaren | 59d1d76 | 2006-04-22 07:33:04 +0000 | [diff] [blame] | 1013 | if (!source) { |
| 1014 | ec = NOT_SUPPORTED_ERR; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1015 | return 0; |
ggaren | 59d1d76 | 2006-04-22 07:33:04 +0000 | [diff] [blame] | 1016 | } |
eric@webkit.org | 62f0c4a | 2008-02-08 09:04:22 +0000 | [diff] [blame] | 1017 | |
| 1018 | if (source->isReadOnlyNode()) { |
| 1019 | ec = NO_MODIFICATION_ALLOWED_ERR; |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
ojan@chromium.org | 5570e70 | 2011-03-04 06:20:57 +0000 | [diff] [blame] | 1023 | EventQueueScope scope; |
| 1024 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1025 | switch (source->nodeType()) { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 1026 | case ENTITY_NODE: |
| 1027 | case NOTATION_NODE: |
| 1028 | case DOCUMENT_NODE: |
| 1029 | case DOCUMENT_TYPE_NODE: |
| 1030 | case XPATH_NAMESPACE_NODE: |
| 1031 | ec = NOT_SUPPORTED_ERR; |
| 1032 | return 0; |
| 1033 | case ATTRIBUTE_NODE: { |
| 1034 | Attr* attr = static_cast<Attr*>(source.get()); |
| 1035 | if (attr->ownerElement()) |
| 1036 | attr->ownerElement()->removeAttributeNode(attr, ec); |
| 1037 | attr->setSpecified(true); |
| 1038 | break; |
| 1039 | } |
| 1040 | default: |
morrita@google.com | 7379856 | 2012-04-18 04:52:47 +0000 | [diff] [blame] | 1041 | if (source->isShadowRoot()) { |
| 1042 | // ShadowRoot cannot disconnect itself from the host node. |
| 1043 | ec = HIERARCHY_REQUEST_ERR; |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
abarth@webkit.org | 8c9fac6 | 2012-03-20 05:58:36 +0000 | [diff] [blame] | 1047 | // FIXME: What about <frame> and <object>? |
rniwa@webkit.org | a89a67a | 2011-01-08 00:49:52 +0000 | [diff] [blame] | 1048 | if (source->hasTagName(iframeTag)) { |
| 1049 | HTMLIFrameElement* iframe = static_cast<HTMLIFrameElement*>(source.get()); |
rniwa@webkit.org | a80cad0 | 2011-01-08 02:42:44 +0000 | [diff] [blame] | 1050 | if (frame() && frame()->tree()->isDescendantOf(iframe->contentFrame())) { |
rniwa@webkit.org | a89a67a | 2011-01-08 00:49:52 +0000 | [diff] [blame] | 1051 | ec = HIERARCHY_REQUEST_ERR; |
| 1052 | return 0; |
| 1053 | } |
rniwa@webkit.org | a89a67a | 2011-01-08 00:49:52 +0000 | [diff] [blame] | 1054 | } |
morrita@google.com | 790f7e6 | 2012-09-25 08:01:17 +0000 | [diff] [blame] | 1055 | if (source->parentNode()) { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 1056 | source->parentNode()->removeChild(source.get(), ec); |
morrita@google.com | 790f7e6 | 2012-09-25 08:01:17 +0000 | [diff] [blame] | 1057 | if (ec) |
| 1058 | return 0; |
| 1059 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1060 | } |
dglazkov@chromium.org | dbe9110 | 2011-01-13 23:38:32 +0000 | [diff] [blame] | 1061 | |
morrita@google.com | e08d15a | 2012-01-10 02:11:30 +0000 | [diff] [blame] | 1062 | this->adoptIfNeeded(source.get()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1063 | |
| 1064 | return source; |
| 1065 | } |
| 1066 | |
abarth@webkit.org | 427e9f1 | 2012-01-19 08:31:13 +0000 | [diff] [blame] | 1067 | bool Document::hasValidNamespaceForElements(const QualifiedName& qName) |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 1068 | { |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 1069 | // These checks are from DOM Core Level 2, createElementNS |
| 1070 | // http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrElNS |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 1071 | if (!qName.prefix().isEmpty() && qName.namespaceURI().isNull()) // createElementNS(null, "html:div") |
abarth@webkit.org | 427e9f1 | 2012-01-19 08:31:13 +0000 | [diff] [blame] | 1072 | return false; |
ap@apple.com | 38221c6 | 2010-01-18 22:05:55 +0000 | [diff] [blame] | 1073 | if (qName.prefix() == xmlAtom && qName.namespaceURI() != XMLNames::xmlNamespaceURI) // createElementNS("http://www.example.com", "xml:lang") |
abarth@webkit.org | 427e9f1 | 2012-01-19 08:31:13 +0000 | [diff] [blame] | 1074 | return false; |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 1075 | |
| 1076 | // Required by DOM Level 3 Core and unspecified by DOM Level 2 Core: |
| 1077 | // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS |
| 1078 | // createElementNS("http://www.w3.org/2000/xmlns/", "foo:bar"), createElementNS(null, "xmlns:bar") |
ap@apple.com | 38221c6 | 2010-01-18 22:05:55 +0000 | [diff] [blame] | 1079 | if ((qName.prefix() == xmlnsAtom && qName.namespaceURI() != XMLNSNames::xmlnsNamespaceURI) || (qName.prefix() != xmlnsAtom && qName.namespaceURI() == XMLNSNames::xmlnsNamespaceURI)) |
abarth@webkit.org | 427e9f1 | 2012-01-19 08:31:13 +0000 | [diff] [blame] | 1080 | return false; |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 1081 | |
abarth@webkit.org | 427e9f1 | 2012-01-19 08:31:13 +0000 | [diff] [blame] | 1082 | return true; |
| 1083 | } |
| 1084 | |
| 1085 | bool Document::hasValidNamespaceForAttributes(const QualifiedName& qName) |
| 1086 | { |
| 1087 | // Spec: DOM Level 2 Core: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElSetAttrNS |
| 1088 | if (qName.prefix().isEmpty() && qName.localName() == xmlnsAtom) { |
| 1089 | // Note: The case of an "xmlns" qualified name with a namespace of |
| 1090 | // xmlnsNamespaceURI is specifically allowed (See <http://www.w3.org/2000/xmlns/>). |
| 1091 | return qName.namespaceURI() == XMLNSNames::xmlnsNamespaceURI; |
| 1092 | } |
| 1093 | return hasValidNamespaceForElements(qName); |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
andersca | ddd3542 | 2007-01-29 22:42:59 +0000 | [diff] [blame] | 1096 | // FIXME: This should really be in a possible ElementFactory class |
jchaffraix@webkit.org | 0ad36c3 | 2009-02-12 20:52:02 +0000 | [diff] [blame] | 1097 | PassRefPtr<Element> Document::createElement(const QualifiedName& qName, bool createdByParser) |
andersca | ddd3542 | 2007-01-29 22:42:59 +0000 | [diff] [blame] | 1098 | { |
| 1099 | RefPtr<Element> e; |
| 1100 | |
| 1101 | // FIXME: Use registered namespaces and look up in a hash to find the right factory. |
| 1102 | if (qName.namespaceURI() == xhtmlNamespaceURI) |
jchaffraix@webkit.org | 6d04619 | 2008-11-24 19:29:39 +0000 | [diff] [blame] | 1103 | e = HTMLElementFactory::createHTMLElement(qName, this, 0, createdByParser); |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 1104 | #if ENABLE(SVG) |
andersca | ddd3542 | 2007-01-29 22:42:59 +0000 | [diff] [blame] | 1105 | else if (qName.namespaceURI() == SVGNames::svgNamespaceURI) |
| 1106 | e = SVGElementFactory::createSVGElement(qName, this, createdByParser); |
| 1107 | #endif |
eric@webkit.org | 8af95f3 | 2009-09-19 18:02:33 +0000 | [diff] [blame] | 1108 | #if ENABLE(MATHML) |
| 1109 | else if (qName.namespaceURI() == MathMLNames::mathmlNamespaceURI) |
| 1110 | e = MathMLElementFactory::createMathMLElement(qName, this, createdByParser); |
| 1111 | #endif |
darin@apple.com | f5247d1 | 2010-06-13 17:29:10 +0000 | [diff] [blame] | 1112 | |
pfeldman@chromium.org | 81b45e5 | 2011-02-28 15:26:44 +0000 | [diff] [blame] | 1113 | if (e) |
| 1114 | m_sawElementsInKnownNamespaces = true; |
| 1115 | else |
darin@apple.com | cf9dd0f | 2009-08-23 06:55:57 +0000 | [diff] [blame] | 1116 | e = Element::create(qName, document()); |
jchaffraix@webkit.org | 0ad36c3 | 2009-02-12 20:52:02 +0000 | [diff] [blame] | 1117 | |
| 1118 | // <image> uses imgTag so we need a special rule. |
| 1119 | ASSERT((qName.matches(imageTag) && e->tagQName().matches(imgTag) && e->tagQName().prefix() == qName.prefix()) || qName == e->tagQName()); |
| 1120 | |
andersca | ddd3542 | 2007-01-29 22:42:59 +0000 | [diff] [blame] | 1121 | return e.release(); |
| 1122 | } |
| 1123 | |
hyatt@apple.com | 6c8a73ab | 2012-03-16 19:55:25 +0000 | [diff] [blame] | 1124 | bool Document::regionBasedColumnsEnabled() const |
| 1125 | { |
| 1126 | return settings() && settings()->regionBasedColumnsEnabled(); |
| 1127 | } |
| 1128 | |
ojan@chromium.org | 52498d7 | 2012-09-14 22:49:38 +0000 | [diff] [blame] | 1129 | bool Document::cssStickyPositionEnabled() const |
| 1130 | { |
| 1131 | return settings() && settings()->cssStickyPositionEnabled(); |
| 1132 | } |
| 1133 | |
mihnea@adobe.com | 83fafcd | 2012-02-17 20:44:00 +0000 | [diff] [blame] | 1134 | bool Document::cssRegionsEnabled() const |
| 1135 | { |
| 1136 | return settings() && settings()->cssRegionsEnabled(); |
| 1137 | } |
| 1138 | |
tony@chromium.org | 6a48fa0 | 2012-05-18 19:23:14 +0000 | [diff] [blame] | 1139 | bool Document::cssGridLayoutEnabled() const |
| 1140 | { |
| 1141 | return settings() && settings()->cssGridLayoutEnabled(); |
| 1142 | } |
| 1143 | |
timothy_horton@apple.com | 3f03ac1 | 2012-05-25 06:53:27 +0000 | [diff] [blame] | 1144 | #if ENABLE(CSS_REGIONS) |
| 1145 | |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 1146 | PassRefPtr<DOMNamedFlowCollection> Document::webkitGetNamedFlows() |
| 1147 | { |
| 1148 | if (!cssRegionsEnabled() || !renderer()) |
| 1149 | return 0; |
| 1150 | |
| 1151 | updateStyleIfNeeded(); |
| 1152 | |
| 1153 | return namedFlows()->createCSSOMSnapshot(); |
| 1154 | } |
| 1155 | |
timothy_horton@apple.com | 3f03ac1 | 2012-05-25 06:53:27 +0000 | [diff] [blame] | 1156 | #endif |
| 1157 | |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 1158 | NamedFlowCollection* Document::namedFlows() |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 1159 | { |
| 1160 | if (!m_namedFlows) |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 1161 | m_namedFlows = NamedFlowCollection::create(this); |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 1162 | |
| 1163 | return m_namedFlows.get(); |
| 1164 | } |
| 1165 | |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 1166 | PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1167 | { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1168 | String prefix, localName; |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 1169 | if (!parseQualifiedName(qualifiedName, prefix, localName, ec)) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1170 | return 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1171 | |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 1172 | QualifiedName qName(prefix, localName, namespaceURI); |
abarth@webkit.org | 427e9f1 | 2012-01-19 08:31:13 +0000 | [diff] [blame] | 1173 | if (!hasValidNamespaceForElements(qName)) { |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 1174 | ec = NAMESPACE_ERR; |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
jchaffraix@webkit.org | 0ad36c3 | 2009-02-12 20:52:02 +0000 | [diff] [blame] | 1178 | return createElement(qName, false); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
darin | 4a24479 | 2006-05-05 15:22:33 +0000 | [diff] [blame] | 1181 | String Document::readyState() const |
mjs | 9d8e695 | 2006-04-05 22:26:43 +0000 | [diff] [blame] | 1182 | { |
abarth@webkit.org | b1e7d63 | 2012-08-29 23:04:26 +0000 | [diff] [blame] | 1183 | DEFINE_STATIC_LOCAL(const String, loading, (ASCIILiteral("loading"))); |
| 1184 | DEFINE_STATIC_LOCAL(const String, interactive, (ASCIILiteral("interactive"))); |
| 1185 | DEFINE_STATIC_LOCAL(const String, complete, (ASCIILiteral("complete"))); |
tonyg@chromium.org | d299d8a7 | 2010-09-06 18:32:48 +0000 | [diff] [blame] | 1186 | |
| 1187 | switch (m_readyState) { |
| 1188 | case Loading: |
| 1189 | return loading; |
| 1190 | case Interactive: |
| 1191 | return interactive; |
| 1192 | case Complete: |
| 1193 | return complete; |
mjs | 9d8e695 | 2006-04-05 22:26:43 +0000 | [diff] [blame] | 1194 | } |
tonyg@chromium.org | d299d8a7 | 2010-09-06 18:32:48 +0000 | [diff] [blame] | 1195 | |
| 1196 | ASSERT_NOT_REACHED(); |
mjs | 9d8e695 | 2006-04-05 22:26:43 +0000 | [diff] [blame] | 1197 | return String(); |
| 1198 | } |
| 1199 | |
tonyg@chromium.org | d299d8a7 | 2010-09-06 18:32:48 +0000 | [diff] [blame] | 1200 | void Document::setReadyState(ReadyState readyState) |
| 1201 | { |
commit-queue@webkit.org | 53b27b5 | 2010-10-13 23:10:56 +0000 | [diff] [blame] | 1202 | if (readyState == m_readyState) |
| 1203 | return; |
commit-queue@webkit.org | d63bb0a | 2010-11-04 08:36:17 +0000 | [diff] [blame] | 1204 | |
| 1205 | switch (readyState) { |
| 1206 | case Loading: |
| 1207 | if (!m_documentTiming.domLoading) |
simonjam@chromium.org | dfab5cf | 2011-12-15 18:45:29 +0000 | [diff] [blame] | 1208 | m_documentTiming.domLoading = monotonicallyIncreasingTime(); |
commit-queue@webkit.org | d63bb0a | 2010-11-04 08:36:17 +0000 | [diff] [blame] | 1209 | break; |
| 1210 | case Interactive: |
| 1211 | if (!m_documentTiming.domInteractive) |
simonjam@chromium.org | dfab5cf | 2011-12-15 18:45:29 +0000 | [diff] [blame] | 1212 | m_documentTiming.domInteractive = monotonicallyIncreasingTime(); |
commit-queue@webkit.org | d63bb0a | 2010-11-04 08:36:17 +0000 | [diff] [blame] | 1213 | break; |
| 1214 | case Complete: |
| 1215 | if (!m_documentTiming.domComplete) |
simonjam@chromium.org | dfab5cf | 2011-12-15 18:45:29 +0000 | [diff] [blame] | 1216 | m_documentTiming.domComplete = monotonicallyIncreasingTime(); |
commit-queue@webkit.org | d63bb0a | 2010-11-04 08:36:17 +0000 | [diff] [blame] | 1217 | break; |
| 1218 | } |
| 1219 | |
tonyg@chromium.org | d299d8a7 | 2010-09-06 18:32:48 +0000 | [diff] [blame] | 1220 | m_readyState = readyState; |
commit-queue@webkit.org | 53b27b5 | 2010-10-13 23:10:56 +0000 | [diff] [blame] | 1221 | dispatchEvent(Event::create(eventNames().readystatechangeEvent, false, false)); |
aestes@apple.com | 4544ec1 | 2012-04-24 07:43:40 +0000 | [diff] [blame] | 1222 | |
| 1223 | if (settings() && settings()->suppressesIncrementalRendering()) |
| 1224 | setVisualUpdatesAllowed(readyState); |
| 1225 | } |
| 1226 | |
| 1227 | void Document::setVisualUpdatesAllowed(ReadyState readyState) |
| 1228 | { |
| 1229 | ASSERT(settings() && settings()->suppressesIncrementalRendering()); |
| 1230 | switch (readyState) { |
| 1231 | case Loading: |
| 1232 | ASSERT(!m_visualUpdatesSuppressionTimer.isActive()); |
| 1233 | ASSERT(m_visualUpdatesAllowed); |
| 1234 | m_visualUpdatesSuppressionTimer.startOneShot(settings()->incrementalRenderingSuppressionTimeoutInSeconds()); |
| 1235 | setVisualUpdatesAllowed(false); |
| 1236 | break; |
| 1237 | case Interactive: |
| 1238 | ASSERT(m_visualUpdatesSuppressionTimer.isActive() || m_visualUpdatesAllowed); |
| 1239 | break; |
| 1240 | case Complete: |
| 1241 | if (m_visualUpdatesSuppressionTimer.isActive()) { |
| 1242 | ASSERT(!m_visualUpdatesAllowed); |
| 1243 | m_visualUpdatesSuppressionTimer.stop(); |
| 1244 | setVisualUpdatesAllowed(true); |
| 1245 | } else |
| 1246 | ASSERT(m_visualUpdatesAllowed); |
| 1247 | break; |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | void Document::setVisualUpdatesAllowed(bool visualUpdatesAllowed) |
| 1252 | { |
| 1253 | if (m_visualUpdatesAllowed == visualUpdatesAllowed) |
| 1254 | return; |
| 1255 | |
| 1256 | m_visualUpdatesAllowed = visualUpdatesAllowed; |
| 1257 | |
| 1258 | if (!visualUpdatesAllowed) |
| 1259 | return; |
| 1260 | |
| 1261 | #if USE(ACCELERATED_COMPOSITING) |
| 1262 | if (view()) |
| 1263 | view()->updateCompositingLayersAfterLayout(); |
| 1264 | #endif |
| 1265 | |
| 1266 | if (renderer()) |
| 1267 | renderer()->repaint(); |
| 1268 | } |
| 1269 | |
| 1270 | void Document::visualUpdatesSuppressionTimerFired(Timer<Document>*) |
| 1271 | { |
| 1272 | ASSERT(!m_visualUpdatesAllowed); |
| 1273 | setVisualUpdatesAllowed(true); |
tonyg@chromium.org | d299d8a7 | 2010-09-06 18:32:48 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
dimich@chromium.org | e1c0392 | 2009-03-06 21:21:06 +0000 | [diff] [blame] | 1276 | String Document::encoding() const |
mjs | 9d8e695 | 2006-04-05 22:26:43 +0000 | [diff] [blame] | 1277 | { |
darin | 5b2cbe1 | 2006-10-30 00:57:20 +0000 | [diff] [blame] | 1278 | if (TextResourceDecoder* d = decoder()) |
eric@webkit.org | 19fc198 | 2009-05-06 05:37:54 +0000 | [diff] [blame] | 1279 | return d->encoding().domName(); |
mjs | 9d8e695 | 2006-04-05 22:26:43 +0000 | [diff] [blame] | 1280 | return String(); |
| 1281 | } |
| 1282 | |
darin | 4a24479 | 2006-05-05 15:22:33 +0000 | [diff] [blame] | 1283 | String Document::defaultCharset() const |
mjs | 9d8e695 | 2006-04-05 22:26:43 +0000 | [diff] [blame] | 1284 | { |
ggaren | 6ad6e76 | 2007-05-25 09:13:32 +0000 | [diff] [blame] | 1285 | if (Settings* settings = this->settings()) |
| 1286 | return settings->defaultTextEncodingName(); |
mjs | 9d8e695 | 2006-04-05 22:26:43 +0000 | [diff] [blame] | 1287 | return String(); |
| 1288 | } |
| 1289 | |
| 1290 | void Document::setCharset(const String& charset) |
| 1291 | { |
| 1292 | if (!decoder()) |
| 1293 | return; |
darin | 5b2cbe1 | 2006-10-30 00:57:20 +0000 | [diff] [blame] | 1294 | decoder()->setEncoding(charset, TextResourceDecoder::UserChosenEncoding); |
mjs | 9d8e695 | 2006-04-05 22:26:43 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
commit-queue@webkit.org | 335d75e | 2012-02-03 07:30:20 +0000 | [diff] [blame] | 1297 | void Document::setContentLanguage(const String& language) |
| 1298 | { |
| 1299 | if (m_contentLanguage == language) |
| 1300 | return; |
| 1301 | m_contentLanguage = language; |
| 1302 | |
| 1303 | // Recalculate style so language is used when selecting the initial font. |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 1304 | styleResolverChanged(DeferRecalcStyle); |
commit-queue@webkit.org | 335d75e | 2012-02-03 07:30:20 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
ap | 0289d28 | 2006-11-20 18:59:12 +0000 | [diff] [blame] | 1307 | void Document::setXMLVersion(const String& version, ExceptionCode& ec) |
| 1308 | { |
ap | 0289d28 | 2006-11-20 18:59:12 +0000 | [diff] [blame] | 1309 | if (!implementation()->hasFeature("XML", String())) { |
| 1310 | ec = NOT_SUPPORTED_ERR; |
| 1311 | return; |
| 1312 | } |
andreas.kling@nokia.com | 38277de | 2010-08-24 08:55:29 +0000 | [diff] [blame] | 1313 | |
| 1314 | if (!XMLDocumentParser::supportsXMLVersion(version)) { |
| 1315 | ec = NOT_SUPPORTED_ERR; |
| 1316 | return; |
| 1317 | } |
darin@apple.com | a3c493e | 2008-03-18 13:47:47 +0000 | [diff] [blame] | 1318 | |
ap | 0289d28 | 2006-11-20 18:59:12 +0000 | [diff] [blame] | 1319 | m_xmlVersion = version; |
| 1320 | } |
| 1321 | |
| 1322 | void Document::setXMLStandalone(bool standalone, ExceptionCode& ec) |
| 1323 | { |
| 1324 | if (!implementation()->hasFeature("XML", String())) { |
| 1325 | ec = NOT_SUPPORTED_ERR; |
| 1326 | return; |
| 1327 | } |
| 1328 | |
rwlbuis@webkit.org | ac5a7ef | 2012-04-13 00:58:30 +0000 | [diff] [blame] | 1329 | m_xmlStandalone = standalone ? Standalone : NotStandalone; |
ap | 0289d28 | 2006-11-20 18:59:12 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
darin@apple.com | 640fa30 | 2008-02-15 05:03:55 +0000 | [diff] [blame] | 1332 | void Document::setDocumentURI(const String& uri) |
rwlbuis | 8643f1f | 2007-03-07 21:25:16 +0000 | [diff] [blame] | 1333 | { |
commit-queue@webkit.org | 4ef9053 | 2012-06-12 18:02:56 +0000 | [diff] [blame] | 1334 | // This property is read-only from JavaScript, but writable from Objective-C. |
abarth@webkit.org | 761e100 | 2008-06-16 04:43:06 +0000 | [diff] [blame] | 1335 | m_documentURI = uri; |
| 1336 | updateBaseURL(); |
rwlbuis | 8643f1f | 2007-03-07 21:25:16 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
darin@apple.com | 640fa30 | 2008-02-15 05:03:55 +0000 | [diff] [blame] | 1339 | KURL Document::baseURI() const |
rwlbuis | 8643f1f | 2007-03-07 21:25:16 +0000 | [diff] [blame] | 1340 | { |
darin@apple.com | 640fa30 | 2008-02-15 05:03:55 +0000 | [diff] [blame] | 1341 | return m_baseURL; |
rwlbuis | 8643f1f | 2007-03-07 21:25:16 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
paroga@webkit.org | db65784 | 2011-01-12 01:26:04 +0000 | [diff] [blame] | 1344 | void Document::setContent(const String& content) |
| 1345 | { |
paroga@webkit.org | db65784 | 2011-01-12 01:26:04 +0000 | [diff] [blame] | 1346 | open(); |
| 1347 | m_parser->append(content); |
abarth@webkit.org | 3a0207f | 2011-02-16 00:36:28 +0000 | [diff] [blame] | 1348 | close(); |
paroga@webkit.org | db65784 | 2011-01-12 01:26:04 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
abarth@webkit.org | a6659fd | 2011-04-28 22:03:09 +0000 | [diff] [blame] | 1351 | String Document::suggestedMIMEType() const |
| 1352 | { |
commit-queue@webkit.org | c4534e1 | 2012-07-24 00:53:24 +0000 | [diff] [blame] | 1353 | if (m_document->isXHTMLDocument()) |
abarth@webkit.org | a6659fd | 2011-04-28 22:03:09 +0000 | [diff] [blame] | 1354 | return "application/xhtml+xml"; |
commit-queue@webkit.org | c4534e1 | 2012-07-24 00:53:24 +0000 | [diff] [blame] | 1355 | if (m_document->isSVGDocument()) |
abarth@webkit.org | a6659fd | 2011-04-28 22:03:09 +0000 | [diff] [blame] | 1356 | return "image/svg+xml"; |
commit-queue@webkit.org | c4534e1 | 2012-07-24 00:53:24 +0000 | [diff] [blame] | 1357 | if (m_document->xmlStandalone()) |
abarth@webkit.org | a6659fd | 2011-04-28 22:03:09 +0000 | [diff] [blame] | 1358 | return "text/xml"; |
commit-queue@webkit.org | c4534e1 | 2012-07-24 00:53:24 +0000 | [diff] [blame] | 1359 | if (m_document->isHTMLDocument()) |
abarth@webkit.org | a6659fd | 2011-04-28 22:03:09 +0000 | [diff] [blame] | 1360 | return "text/html"; |
| 1361 | |
beidson@apple.com | 197fbd3 | 2011-05-31 22:13:06 +0000 | [diff] [blame] | 1362 | if (DocumentLoader* documentLoader = loader()) |
| 1363 | return documentLoader->responseMIMEType(); |
| 1364 | return String(); |
abarth@webkit.org | a6659fd | 2011-04-28 22:03:09 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 1367 | // FIXME: We need to discuss the DOM API here at some point. Ideas: |
| 1368 | // * making it receive a rect as parameter, i.e. nodesFromRect(x, y, w, h); |
| 1369 | // * making it receive the expading size of each direction separately, |
| 1370 | // i.e. nodesFromRect(x, y, topSize, rightSize, bottomSize, leftSize); |
jchaffraix@webkit.org | 5083f63 | 2012-09-15 01:24:30 +0000 | [diff] [blame] | 1371 | PassRefPtr<NodeList> Document::nodesFromRect(int centerX, int centerY, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent) const |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 1372 | { |
| 1373 | // FIXME: Share code between this, elementFromPoint and caretRangeFromPoint. |
| 1374 | if (!renderer()) |
| 1375 | return 0; |
| 1376 | Frame* frame = this->frame(); |
| 1377 | if (!frame) |
| 1378 | return 0; |
| 1379 | FrameView* frameView = frame->view(); |
| 1380 | if (!frameView) |
| 1381 | return 0; |
| 1382 | |
darin@apple.com | 0f442a7 | 2010-09-18 00:32:24 +0000 | [diff] [blame] | 1383 | float zoomFactor = frame->pageZoomFactor(); |
leviw@chromium.org | 3af1706 | 2011-08-18 00:36:48 +0000 | [diff] [blame] | 1384 | LayoutPoint point = roundedLayoutPoint(FloatPoint(centerX * zoomFactor + view()->scrollX(), centerY * zoomFactor + view()->scrollY())); |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 1385 | |
commit-queue@webkit.org | 3f2c009 | 2012-09-13 05:09:58 +0000 | [diff] [blame] | 1386 | int type = HitTestRequest::ReadOnly | HitTestRequest::Active; |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 1387 | |
| 1388 | // When ignoreClipping is false, this method returns null for coordinates outside of the viewport. |
commit-queue@webkit.org | 3f2c009 | 2012-09-13 05:09:58 +0000 | [diff] [blame] | 1389 | if (ignoreClipping) |
| 1390 | type |= HitTestRequest::IgnoreClipping; |
| 1391 | else if (!frameView->visibleContentRect().intersects(HitTestResult::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding))) |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 1392 | return 0; |
commit-queue@webkit.org | 3f2c009 | 2012-09-13 05:09:58 +0000 | [diff] [blame] | 1393 | if (allowShadowContent) |
| 1394 | type |= HitTestRequest::AllowShadowContent; |
commit-queue@webkit.org | 3f2c009 | 2012-09-13 05:09:58 +0000 | [diff] [blame] | 1395 | |
| 1396 | HitTestRequest request(type); |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 1397 | |
| 1398 | // Passing a zero padding will trigger a rect hit test, however for the purposes of nodesFromRect, |
| 1399 | // we special handle this case in order to return a valid NodeList. |
tonikitoo@webkit.org | 6e7483d | 2010-09-28 02:28:25 +0000 | [diff] [blame] | 1400 | if (!topPadding && !rightPadding && !bottomPadding && !leftPadding) { |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 1401 | HitTestResult result(point); |
| 1402 | return handleZeroPadding(request, result); |
| 1403 | } |
| 1404 | |
allan.jensen@nokia.com | 4c7e352 | 2012-09-03 14:41:42 +0000 | [diff] [blame] | 1405 | HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding); |
jchaffraix@webkit.org | 9dbf6d1 | 2012-04-12 16:02:25 +0000 | [diff] [blame] | 1406 | renderView()->hitTest(request, result); |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 1407 | |
| 1408 | return StaticHashSetNodeList::adopt(result.rectBasedTestResult()); |
| 1409 | } |
| 1410 | |
| 1411 | PassRefPtr<NodeList> Document::handleZeroPadding(const HitTestRequest& request, HitTestResult& result) const |
| 1412 | { |
jchaffraix@webkit.org | 9dbf6d1 | 2012-04-12 16:02:25 +0000 | [diff] [blame] | 1413 | renderView()->hitTest(request, result); |
tonikitoo@webkit.org | 81c027d | 2010-07-29 13:19:43 +0000 | [diff] [blame] | 1414 | |
| 1415 | Node* node = result.innerNode(); |
| 1416 | if (!node) |
| 1417 | return 0; |
| 1418 | |
| 1419 | node = node->shadowAncestorNode(); |
| 1420 | ListHashSet<RefPtr<Node> > list; |
| 1421 | list.add(node); |
| 1422 | return StaticHashSetNodeList::adopt(list); |
| 1423 | } |
| 1424 | |
leviw@chromium.org | 3af1706 | 2011-08-18 00:36:48 +0000 | [diff] [blame] | 1425 | static Node* nodeFromPoint(Frame* frame, RenderView* renderView, int x, int y, LayoutPoint* localPoint = 0) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1426 | { |
weinig@apple.com | d242796 | 2009-09-12 19:11:55 +0000 | [diff] [blame] | 1427 | if (!frame) |
| 1428 | return 0; |
| 1429 | FrameView* frameView = frame->view(); |
| 1430 | if (!frameView) |
| 1431 | return 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1432 | |
darin@apple.com | 0f442a7 | 2010-09-18 00:32:24 +0000 | [diff] [blame] | 1433 | float zoomFactor = frame->pageZoomFactor(); |
eae@chromium.org | b469de3 | 2011-02-24 12:31:15 +0000 | [diff] [blame] | 1434 | IntPoint point = roundedIntPoint(FloatPoint(x * zoomFactor + frameView->scrollX(), y * zoomFactor + frameView->scrollY())); |
simon.fraser@apple.com | 154f13a | 2009-03-23 18:56:35 +0000 | [diff] [blame] | 1435 | |
mrowe@apple.com | bc93926 | 2009-09-15 18:40:11 +0000 | [diff] [blame] | 1436 | if (!frameView->visibleContentRect().contains(point)) |
weinig@apple.com | d242796 | 2009-09-12 19:11:55 +0000 | [diff] [blame] | 1437 | return 0; |
simon.fraser@apple.com | 154f13a | 2009-03-23 18:56:35 +0000 | [diff] [blame] | 1438 | |
weinig@apple.com | d242796 | 2009-09-12 19:11:55 +0000 | [diff] [blame] | 1439 | HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); |
| 1440 | HitTestResult result(point); |
jchaffraix@webkit.org | 9dbf6d1 | 2012-04-12 16:02:25 +0000 | [diff] [blame] | 1441 | renderView->hitTest(request, result); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1442 | |
eae@chromium.org | b469de3 | 2011-02-24 12:31:15 +0000 | [diff] [blame] | 1443 | if (localPoint) |
| 1444 | *localPoint = result.localPoint(); |
| 1445 | |
| 1446 | return result.innerNode(); |
| 1447 | } |
| 1448 | |
| 1449 | Element* Document::elementFromPoint(int x, int y) const |
| 1450 | { |
| 1451 | if (!renderer()) |
| 1452 | return 0; |
| 1453 | Node* node = nodeFromPoint(frame(), renderView(), x, y); |
| 1454 | while (node && !node->isElementNode()) |
| 1455 | node = node->parentNode(); |
| 1456 | if (node) |
shinyak@chromium.org | 42d59fc | 2012-05-24 03:59:41 +0000 | [diff] [blame] | 1457 | node = ancestorInThisScope(node); |
eae@chromium.org | b469de3 | 2011-02-24 12:31:15 +0000 | [diff] [blame] | 1458 | return static_cast<Element*>(node); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
weinig@apple.com | 628cb2c | 2009-09-08 22:02:41 +0000 | [diff] [blame] | 1461 | PassRefPtr<Range> Document::caretRangeFromPoint(int x, int y) |
| 1462 | { |
| 1463 | if (!renderer()) |
| 1464 | return 0; |
leviw@chromium.org | 3af1706 | 2011-08-18 00:36:48 +0000 | [diff] [blame] | 1465 | LayoutPoint localPoint; |
eae@chromium.org | b469de3 | 2011-02-24 12:31:15 +0000 | [diff] [blame] | 1466 | Node* node = nodeFromPoint(frame(), renderView(), x, y, &localPoint); |
weinig@apple.com | 628cb2c | 2009-09-08 22:02:41 +0000 | [diff] [blame] | 1467 | if (!node) |
| 1468 | return 0; |
| 1469 | |
shinyak@chromium.org | 1bc322a | 2012-05-24 03:45:18 +0000 | [diff] [blame] | 1470 | Node* shadowAncestorNode = ancestorInThisScope(node); |
weinig@apple.com | 628cb2c | 2009-09-08 22:02:41 +0000 | [diff] [blame] | 1471 | if (shadowAncestorNode != node) { |
| 1472 | unsigned offset = shadowAncestorNode->nodeIndex(); |
darin@apple.com | 601d44b | 2010-10-15 18:30:37 +0000 | [diff] [blame] | 1473 | ContainerNode* container = shadowAncestorNode->parentNode(); |
weinig@apple.com | 628cb2c | 2009-09-08 22:02:41 +0000 | [diff] [blame] | 1474 | return Range::create(this, container, offset, container, offset); |
| 1475 | } |
| 1476 | |
| 1477 | RenderObject* renderer = node->renderer(); |
| 1478 | if (!renderer) |
| 1479 | return 0; |
eae@chromium.org | b469de3 | 2011-02-24 12:31:15 +0000 | [diff] [blame] | 1480 | VisiblePosition visiblePosition = renderer->positionForPoint(localPoint); |
weinig@apple.com | 628cb2c | 2009-09-08 22:02:41 +0000 | [diff] [blame] | 1481 | if (visiblePosition.isNull()) |
| 1482 | return 0; |
| 1483 | |
commit-queue@webkit.org | c56f5de | 2011-01-19 09:32:09 +0000 | [diff] [blame] | 1484 | Position rangeCompliantPosition = visiblePosition.deepEquivalent().parentAnchoredEquivalent(); |
weinig@apple.com | 628cb2c | 2009-09-08 22:02:41 +0000 | [diff] [blame] | 1485 | return Range::create(this, rangeCompliantPosition, rangeCompliantPosition); |
| 1486 | } |
| 1487 | |
eric@webkit.org | 0e91742 | 2010-01-07 21:32:13 +0000 | [diff] [blame] | 1488 | /* |
| 1489 | * Performs three operations: |
| 1490 | * 1. Convert control characters to spaces |
| 1491 | * 2. Trim leading and trailing spaces |
| 1492 | * 3. Collapse internal whitespace. |
| 1493 | */ |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1494 | static inline StringWithDirection canonicalizedTitle(Document* document, const StringWithDirection& titleWithDirection) |
eric@webkit.org | 0e91742 | 2010-01-07 21:32:13 +0000 | [diff] [blame] | 1495 | { |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1496 | const String& title = titleWithDirection.string(); |
eric@webkit.org | 0e91742 | 2010-01-07 21:32:13 +0000 | [diff] [blame] | 1497 | const UChar* characters = title.characters(); |
| 1498 | unsigned length = title.length(); |
| 1499 | unsigned i; |
| 1500 | |
msaboff@apple.com | b81ffeb | 2011-11-16 22:46:31 +0000 | [diff] [blame] | 1501 | StringBuffer<UChar> buffer(length); |
eric@webkit.org | 0e91742 | 2010-01-07 21:32:13 +0000 | [diff] [blame] | 1502 | unsigned builderIndex = 0; |
| 1503 | |
| 1504 | // Skip leading spaces and leading characters that would convert to spaces |
| 1505 | for (i = 0; i < length; ++i) { |
| 1506 | UChar c = characters[i]; |
| 1507 | if (!(c <= 0x20 || c == 0x7F)) |
| 1508 | break; |
| 1509 | } |
| 1510 | |
| 1511 | if (i == length) |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1512 | return StringWithDirection(); |
eric@webkit.org | 0e91742 | 2010-01-07 21:32:13 +0000 | [diff] [blame] | 1513 | |
| 1514 | // Replace control characters with spaces, and backslashes with currency symbols, and collapse whitespace. |
| 1515 | bool previousCharWasWS = false; |
| 1516 | for (; i < length; ++i) { |
| 1517 | UChar c = characters[i]; |
| 1518 | if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode::Separator_Line | WTF::Unicode::Separator_Paragraph))) { |
| 1519 | if (previousCharWasWS) |
| 1520 | continue; |
| 1521 | buffer[builderIndex++] = ' '; |
| 1522 | previousCharWasWS = true; |
| 1523 | } else { |
| 1524 | buffer[builderIndex++] = c; |
| 1525 | previousCharWasWS = false; |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | // Strip trailing spaces |
| 1530 | while (builderIndex > 0) { |
| 1531 | --builderIndex; |
| 1532 | if (buffer[builderIndex] != ' ') |
| 1533 | break; |
| 1534 | } |
| 1535 | |
| 1536 | if (!builderIndex && buffer[builderIndex] == ' ') |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1537 | return StringWithDirection(); |
eric@webkit.org | 0e91742 | 2010-01-07 21:32:13 +0000 | [diff] [blame] | 1538 | |
| 1539 | buffer.shrink(builderIndex + 1); |
| 1540 | |
| 1541 | // Replace the backslashes with currency symbols if the encoding requires it. |
| 1542 | document->displayBufferModifiedByEncoding(buffer.characters(), buffer.length()); |
| 1543 | |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1544 | return StringWithDirection(String::adopt(buffer), titleWithDirection.direction()); |
eric@webkit.org | 0e91742 | 2010-01-07 21:32:13 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1547 | void Document::updateTitle(const StringWithDirection& title) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1548 | { |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1549 | if (m_rawTitle == title) |
| 1550 | return; |
| 1551 | |
| 1552 | m_rawTitle = title; |
eric@webkit.org | 0e91742 | 2010-01-07 21:32:13 +0000 | [diff] [blame] | 1553 | m_title = canonicalizedTitle(this, m_rawTitle); |
darin | 4a24479 | 2006-05-05 15:22:33 +0000 | [diff] [blame] | 1554 | if (Frame* f = frame()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1555 | f->loader()->setTitle(m_title); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1558 | void Document::setTitle(const String& title) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1559 | { |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1560 | // Title set by JavaScript -- overrides any title elements. |
| 1561 | m_titleSetExplicitly = true; |
commit-queue@webkit.org | 017a7d3 | 2011-09-13 03:50:01 +0000 | [diff] [blame] | 1562 | if (!isHTMLDocument() && !isXHTMLDocument()) |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1563 | m_titleElement = 0; |
| 1564 | else if (!m_titleElement) { |
| 1565 | if (HTMLElement* headElement = head()) { |
| 1566 | m_titleElement = createElement(titleTag, false); |
| 1567 | ExceptionCode ec = 0; |
| 1568 | headElement->appendChild(m_titleElement, ec); |
| 1569 | ASSERT(!ec); |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 1570 | } |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1573 | // The DOM API has no method of specifying direction, so assume LTR. |
| 1574 | updateTitle(StringWithDirection(title, LTR)); |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1575 | |
evan@chromium.org | 28970be | 2011-03-30 12:55:45 +0000 | [diff] [blame] | 1576 | if (m_titleElement) { |
| 1577 | ASSERT(m_titleElement->hasTagName(titleTag)); |
| 1578 | if (m_titleElement->hasTagName(titleTag)) |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1579 | static_cast<HTMLTitleElement*>(m_titleElement.get())->setText(title); |
evan@chromium.org | 28970be | 2011-03-30 12:55:45 +0000 | [diff] [blame] | 1580 | } |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1583 | void Document::setTitleElement(const StringWithDirection& title, Element* titleElement) |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1584 | { |
| 1585 | if (titleElement != m_titleElement) { |
bdash | fa8c5ec | 2007-01-23 04:00:54 +0000 | [diff] [blame] | 1586 | if (m_titleElement || m_titleSetExplicitly) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1587 | // Only allow the first title element to change the title -- others have no effect. |
| 1588 | return; |
| 1589 | m_titleElement = titleElement; |
| 1590 | } |
| 1591 | |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1592 | updateTitle(title); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 1595 | void Document::removeTitle(Element* titleElement) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1596 | { |
| 1597 | if (m_titleElement != titleElement) |
| 1598 | return; |
| 1599 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1600 | m_titleElement = 0; |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 1601 | m_titleSetExplicitly = false; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1602 | |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 1603 | // Update title based on first title element in the head, if one exists. |
| 1604 | if (HTMLElement* headElement = head()) { |
| 1605 | for (Node* e = headElement->firstChild(); e; e = e->nextSibling()) |
| 1606 | if (e->hasTagName(titleTag)) { |
| 1607 | HTMLTitleElement* titleElement = static_cast<HTMLTitleElement*>(e); |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1608 | setTitleElement(titleElement->textWithDirection(), titleElement); |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 1609 | break; |
| 1610 | } |
| 1611 | } |
| 1612 | |
evan@chromium.org | 50b7afc | 2011-03-30 11:21:53 +0000 | [diff] [blame] | 1613 | if (!m_titleElement) |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1614 | updateTitle(StringWithDirection()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
commit-queue@webkit.org | 084ff96 | 2011-05-09 11:00:47 +0000 | [diff] [blame] | 1617 | #if ENABLE(PAGE_VISIBILITY_API) |
| 1618 | PageVisibilityState Document::visibilityState() const |
| 1619 | { |
| 1620 | // The visibility of the document is inherited from the visibility of the |
| 1621 | // page. If there is no page associated with the document, we will assume |
| 1622 | // that the page is visible i.e. invisibility has to be explicitly |
| 1623 | // specified by the embedder. |
| 1624 | if (!m_frame || !m_frame->page()) |
| 1625 | return PageVisibilityStateVisible; |
| 1626 | return m_frame->page()->visibilityState(); |
| 1627 | } |
| 1628 | |
| 1629 | String Document::webkitVisibilityState() const |
| 1630 | { |
tonyg@chromium.org | 245b864 | 2011-05-09 18:18:54 +0000 | [diff] [blame] | 1631 | return pageVisibilityStateString(visibilityState()); |
commit-queue@webkit.org | 084ff96 | 2011-05-09 11:00:47 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
commit-queue@webkit.org | dcc6741 | 2011-06-01 14:11:23 +0000 | [diff] [blame] | 1634 | bool Document::webkitHidden() const |
commit-queue@webkit.org | 084ff96 | 2011-05-09 11:00:47 +0000 | [diff] [blame] | 1635 | { |
commit-queue@webkit.org | dcc6741 | 2011-06-01 14:11:23 +0000 | [diff] [blame] | 1636 | return visibilityState() != PageVisibilityStateVisible; |
commit-queue@webkit.org | 084ff96 | 2011-05-09 11:00:47 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | void Document::dispatchVisibilityStateChangeEvent() |
| 1640 | { |
commit-queue@webkit.org | dcc6741 | 2011-06-01 14:11:23 +0000 | [diff] [blame] | 1641 | dispatchEvent(Event::create(eventNames().webkitvisibilitychangeEvent, false, false)); |
commit-queue@webkit.org | 084ff96 | 2011-05-09 11:00:47 +0000 | [diff] [blame] | 1642 | } |
| 1643 | #endif |
| 1644 | |
commit-queue@webkit.org | 05199e5 | 2012-07-26 09:49:52 +0000 | [diff] [blame] | 1645 | #if ENABLE(CSP_NEXT) |
| 1646 | DOMSecurityPolicy* Document::securityPolicy() |
| 1647 | { |
| 1648 | if (!m_domSecurityPolicy) |
| 1649 | m_domSecurityPolicy = DOMSecurityPolicy::create(this); |
| 1650 | return m_domSecurityPolicy.get(); |
| 1651 | } |
| 1652 | #endif |
| 1653 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1654 | String Document::nodeName() const |
| 1655 | { |
| 1656 | return "#document"; |
| 1657 | } |
| 1658 | |
| 1659 | Node::NodeType Document::nodeType() const |
| 1660 | { |
| 1661 | return DOCUMENT_NODE; |
| 1662 | } |
| 1663 | |
tkent@chromium.org | 3455487 | 2012-06-08 09:53:52 +0000 | [diff] [blame] | 1664 | FormController* Document::formController() |
| 1665 | { |
| 1666 | if (!m_formController) |
| 1667 | m_formController = FormController::create(); |
| 1668 | return m_formController.get(); |
| 1669 | } |
| 1670 | |
| 1671 | Vector<String> Document::formElementsState() const |
| 1672 | { |
| 1673 | if (!m_formController) |
| 1674 | return Vector<String>(); |
| 1675 | return m_formController->formElementsState(); |
| 1676 | } |
| 1677 | |
| 1678 | void Document::setStateForNewFormElements(const Vector<String>& stateVector) |
| 1679 | { |
| 1680 | if (!stateVector.size() && !m_formController) |
| 1681 | return; |
| 1682 | formController()->setStateForNewFormElements(stateVector); |
| 1683 | } |
| 1684 | |
ggaren | 7c5851a | 2006-12-12 22:11:18 +0000 | [diff] [blame] | 1685 | FrameView* Document::view() const |
| 1686 | { |
mjs | 22f8a1a | 2007-04-29 07:33:46 +0000 | [diff] [blame] | 1687 | return m_frame ? m_frame->view() : 0; |
ggaren | 7c5851a | 2006-12-12 22:11:18 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
ggaren | 7c5851a | 2006-12-12 22:11:18 +0000 | [diff] [blame] | 1690 | Page* Document::page() const |
| 1691 | { |
ggaren | 6ad6e76 | 2007-05-25 09:13:32 +0000 | [diff] [blame] | 1692 | return m_frame ? m_frame->page() : 0; |
| 1693 | } |
| 1694 | |
| 1695 | Settings* Document::settings() const |
| 1696 | { |
| 1697 | return m_frame ? m_frame->settings() : 0; |
ggaren | 7c5851a | 2006-12-12 22:11:18 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1700 | PassRefPtr<Range> Document::createRange() |
| 1701 | { |
darin@apple.com | b7bf13a | 2008-03-11 23:43:12 +0000 | [diff] [blame] | 1702 | return Range::create(this); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatToShow, |
darin@apple.com | e4f9a66 | 2008-02-08 10:35:20 +0000 | [diff] [blame] | 1706 | PassRefPtr<NodeFilter> filter, bool expandEntityReferences, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1707 | { |
| 1708 | if (!root) { |
| 1709 | ec = NOT_SUPPORTED_ERR; |
| 1710 | return 0; |
| 1711 | } |
andersca@apple.com | 0f509b1 | 2008-06-04 21:12:16 +0000 | [diff] [blame] | 1712 | return NodeIterator::create(root, whatToShow, filter, expandEntityReferences); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 1715 | PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToShow, |
darin@apple.com | e4f9a66 | 2008-02-08 10:35:20 +0000 | [diff] [blame] | 1716 | PassRefPtr<NodeFilter> filter, bool expandEntityReferences, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1717 | { |
| 1718 | if (!root) { |
| 1719 | ec = NOT_SUPPORTED_ERR; |
| 1720 | return 0; |
| 1721 | } |
andersca@apple.com | 0f509b1 | 2008-06-04 21:12:16 +0000 | [diff] [blame] | 1722 | return TreeWalker::create(root, whatToShow, filter, expandEntityReferences); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
hyatt@apple.com | 9e92428 | 2010-08-26 19:33:40 +0000 | [diff] [blame] | 1725 | void Document::scheduleForcedStyleRecalc() |
| 1726 | { |
| 1727 | m_pendingStyleRecalcShouldForce = true; |
| 1728 | scheduleStyleRecalc(); |
| 1729 | } |
| 1730 | |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1731 | void Document::scheduleStyleRecalc() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1732 | { |
eric@webkit.org | 7e897f7 | 2012-05-24 01:07:22 +0000 | [diff] [blame] | 1733 | if (shouldDisplaySeamlesslyWithParent()) { |
| 1734 | // When we're seamless, our parent document manages our style recalcs. |
| 1735 | ownerElement()->setNeedsStyleRecalc(); |
| 1736 | ownerElement()->document()->scheduleStyleRecalc(); |
| 1737 | return; |
| 1738 | } |
eric@webkit.org | 981501e | 2012-05-10 22:11:57 +0000 | [diff] [blame] | 1739 | |
hyatt@apple.com | 094f41b | 2009-04-13 17:14:44 +0000 | [diff] [blame] | 1740 | if (m_styleRecalcTimer.isActive() || inPageCache()) |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1741 | return; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1742 | |
hyatt@apple.com | 8dd0d93 | 2010-08-26 18:17:59 +0000 | [diff] [blame] | 1743 | ASSERT(childNeedsStyleRecalc() || m_pendingStyleRecalcShouldForce); |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 1744 | |
| 1745 | if (!documentsThatNeedStyleRecalc) |
| 1746 | documentsThatNeedStyleRecalc = new HashSet<Document*>; |
| 1747 | documentsThatNeedStyleRecalc->add(this); |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1748 | |
| 1749 | // FIXME: Why on earth is this here? This is clearly misplaced. |
rolandsteiner@chromium.org | a3cbe77 | 2011-04-04 22:25:18 +0000 | [diff] [blame] | 1750 | invalidateAccessKeyMap(); |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1751 | |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 1752 | m_styleRecalcTimer.startOneShot(0); |
vsevik@chromium.org | d0f79f1 | 2011-07-28 15:13:34 +0000 | [diff] [blame] | 1753 | |
| 1754 | InspectorInstrumentation::didScheduleStyleRecalculation(this); |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void Document::unscheduleStyleRecalc() |
| 1758 | { |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 1759 | ASSERT(!childNeedsStyleRecalc()); |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1760 | |
| 1761 | if (documentsThatNeedStyleRecalc) |
| 1762 | documentsThatNeedStyleRecalc->remove(this); |
| 1763 | |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 1764 | m_styleRecalcTimer.stop(); |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 1765 | m_pendingStyleRecalcShouldForce = false; |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
antti@apple.com | 52bdb21 | 2012-09-28 03:51:25 +0000 | [diff] [blame] | 1768 | bool Document::hasPendingStyleRecalc() const |
mitz@apple.com | 543c300 | 2010-11-16 22:08:26 +0000 | [diff] [blame] | 1769 | { |
| 1770 | return m_styleRecalcTimer.isActive() && !m_inStyleRecalc; |
| 1771 | } |
| 1772 | |
antti@apple.com | 52bdb21 | 2012-09-28 03:51:25 +0000 | [diff] [blame] | 1773 | bool Document::hasPendingForcedStyleRecalc() const |
| 1774 | { |
| 1775 | return m_styleRecalcTimer.isActive() && m_pendingStyleRecalcShouldForce; |
| 1776 | } |
| 1777 | |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 1778 | void Document::styleRecalcTimerFired(Timer<Document>*) |
| 1779 | { |
| 1780 | updateStyleIfNeeded(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1781 | } |
| 1782 | |
ojan@chromium.org | e4d44e1 | 2009-07-27 22:45:37 +0000 | [diff] [blame] | 1783 | bool Document::childNeedsAndNotInStyleRecalc() |
| 1784 | { |
| 1785 | return childNeedsStyleRecalc() && !m_inStyleRecalc; |
| 1786 | } |
| 1787 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1788 | void Document::recalcStyle(StyleChange change) |
| 1789 | { |
antti | 6e917c3 | 2007-08-06 02:05:15 +0000 | [diff] [blame] | 1790 | // we should not enter style recalc while painting |
rafael.lobo@openbossa.org | 4687db8 | 2012-08-30 03:48:29 +0000 | [diff] [blame] | 1791 | ASSERT(!view() || !view()->isPainting()); |
| 1792 | if (view() && view()->isPainting()) |
antti | 6e917c3 | 2007-08-06 02:05:15 +0000 | [diff] [blame] | 1793 | return; |
antti | 6e917c3 | 2007-08-06 02:05:15 +0000 | [diff] [blame] | 1794 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1795 | if (m_inStyleRecalc) |
| 1796 | return; // Guard against re-entrancy. -dwh |
eric@webkit.org | 981501e | 2012-05-10 22:11:57 +0000 | [diff] [blame] | 1797 | |
eric@webkit.org | 7e897f7 | 2012-05-24 01:07:22 +0000 | [diff] [blame] | 1798 | // FIXME: We should update style on our ancestor chain before proceeding (especially for seamless), |
| 1799 | // however doing so currently causes several tests to crash, as Frame::setDocument calls Document::attach |
| 1800 | // before setting the DOMWindow on the Frame, or the SecurityOrigin on the document. The attach, in turn |
| 1801 | // resolves style (here) and then when we resolve style on the parent chain, we may end up |
| 1802 | // re-attaching our containing iframe, which when asked HTMLFrameElementBase::isURLAllowed |
| 1803 | // hits a null-dereference due to security code always assuming the document has a SecurityOrigin. |
eric@webkit.org | 981501e | 2012-05-10 22:11:57 +0000 | [diff] [blame] | 1804 | |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 1805 | if (m_styleSheetCollection->needsUpdateActiveStylesheetsOnStyleRecalc()) |
| 1806 | m_styleSheetCollection->updateActiveStyleSheets(DocumentStyleSheetCollection::FullUpdate); |
commit-queue@webkit.org | 4c49a66 | 2011-01-02 22:27:10 +0000 | [diff] [blame] | 1807 | |
podivilov@chromium.org | b6cd025 | 2010-10-07 09:43:02 +0000 | [diff] [blame] | 1808 | InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRecalculateStyle(this); |
eric@webkit.org | 80bd7d6 | 2009-09-08 17:55:32 +0000 | [diff] [blame] | 1809 | |
antti@apple.com | 384e66f | 2012-05-23 17:17:43 +0000 | [diff] [blame] | 1810 | if (m_elemSheet && m_elemSheet->contents()->usesRemUnits()) |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 1811 | m_styleSheetCollection->setUsesRemUnit(true); |
antti@apple.com | 87bb183 | 2012-04-13 21:23:13 +0000 | [diff] [blame] | 1812 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1813 | m_inStyleRecalc = true; |
mitz@apple.com | 8476cbd | 2007-11-23 06:04:36 +0000 | [diff] [blame] | 1814 | suspendPostAttachCallbacks(); |
rniwa@webkit.org | 04ec298 | 2012-09-24 20:34:35 +0000 | [diff] [blame] | 1815 | { |
| 1816 | WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; |
| 1817 | |
| 1818 | RefPtr<FrameView> frameView = view(); |
| 1819 | if (frameView) { |
| 1820 | frameView->pauseScheduledEvents(); |
| 1821 | frameView->beginDeferredRepaints(); |
| 1822 | } |
| 1823 | |
| 1824 | ASSERT(!renderer() || renderArena()); |
| 1825 | if (!renderer() || !renderArena()) |
| 1826 | goto bailOut; |
| 1827 | |
| 1828 | if (m_pendingStyleRecalcShouldForce) |
| 1829 | change = Force; |
| 1830 | |
| 1831 | // Recalculating the root style (on the document) is not needed in the common case. |
| 1832 | if ((change == Force) || (shouldDisplaySeamlesslyWithParent() && (change >= Inherit))) { |
| 1833 | // style selector may set this again during recalc |
| 1834 | m_hasNodesWithPlaceholderStyle = false; |
| 1835 | |
| 1836 | RefPtr<RenderStyle> documentStyle = StyleResolver::styleForDocument(this, m_styleResolver ? m_styleResolver->fontSelector() : 0); |
| 1837 | StyleChange ch = Node::diff(documentStyle.get(), renderer()->style(), this); |
| 1838 | if (ch != NoChange) |
| 1839 | renderer()->setStyle(documentStyle.release()); |
| 1840 | } |
| 1841 | |
| 1842 | for (Node* n = firstChild(); n; n = n->nextSibling()) { |
| 1843 | if (!n->isElementNode()) |
| 1844 | continue; |
| 1845 | Element* element = static_cast<Element*>(n); |
| 1846 | if (change >= Inherit || element->childNeedsStyleRecalc() || element->needsStyleRecalc()) |
| 1847 | element->recalcStyle(change); |
| 1848 | } |
| 1849 | |
| 1850 | #if USE(ACCELERATED_COMPOSITING) |
| 1851 | if (view()) { |
| 1852 | bool layoutPending = view()->layoutPending() || renderer()->needsLayout(); |
| 1853 | // If we didn't update compositing layers because of layout(), we need to do so here. |
| 1854 | if (!layoutPending) |
| 1855 | view()->updateCompositingLayersAfterStyleChange(); |
| 1856 | } |
| 1857 | #endif |
| 1858 | |
| 1859 | bailOut: |
| 1860 | clearNeedsStyleRecalc(); |
| 1861 | clearChildNeedsStyleRecalc(); |
| 1862 | unscheduleStyleRecalc(); |
| 1863 | |
| 1864 | m_inStyleRecalc = false; |
| 1865 | |
| 1866 | // Pseudo element removal and similar may only work with these flags still set. Reset them after the style recalc. |
| 1867 | if (m_styleResolver) |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 1868 | m_styleSheetCollection->resetCSSFeatureFlags(); |
rniwa@webkit.org | 04ec298 | 2012-09-24 20:34:35 +0000 | [diff] [blame] | 1869 | |
| 1870 | if (frameView) { |
| 1871 | frameView->resumeScheduledEvents(); |
| 1872 | frameView->endDeferredRepaints(); |
| 1873 | } |
antti@apple.com | 587e9cf | 2011-04-05 22:29:33 +0000 | [diff] [blame] | 1874 | } |
mitz@apple.com | 8476cbd | 2007-11-23 06:04:36 +0000 | [diff] [blame] | 1875 | resumePostAttachCallbacks(); |
mitz@apple.com | 8a089a4 | 2009-03-01 19:02:08 +0000 | [diff] [blame] | 1876 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 1877 | // If we wanted to call implicitClose() during recalcStyle, do so now that we're finished. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1878 | if (m_closeAfterStyleRecalc) { |
| 1879 | m_closeAfterStyleRecalc = false; |
| 1880 | implicitClose(); |
| 1881 | } |
commit-queue@webkit.org | 4c49a66 | 2011-01-02 22:27:10 +0000 | [diff] [blame] | 1882 | |
podivilov@chromium.org | c5dc5a7 | 2010-10-08 16:39:57 +0000 | [diff] [blame] | 1883 | InspectorInstrumentation::didRecalculateStyle(cookie); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1886 | void Document::updateStyleIfNeeded() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1887 | { |
rniwa@webkit.org | cf0fea9 | 2010-11-05 22:47:59 +0000 | [diff] [blame] | 1888 | ASSERT(isMainThread()); |
simon.fraser@apple.com | 64487f9 | 2010-08-19 17:19:40 +0000 | [diff] [blame] | 1889 | ASSERT(!view() || (!view()->isInLayout() && !view()->isPainting())); |
| 1890 | |
hyatt@apple.com | 8dd0d93 | 2010-08-26 18:17:59 +0000 | [diff] [blame] | 1891 | if ((!m_pendingStyleRecalcShouldForce && !childNeedsStyleRecalc()) || inPageCache()) |
cmarrin@apple.com | 3ec14ff | 2009-01-24 15:10:06 +0000 | [diff] [blame] | 1892 | return; |
hyatt@apple.com | 8dd0d93 | 2010-08-26 18:17:59 +0000 | [diff] [blame] | 1893 | |
simon.fraser@apple.com | dbb8087 | 2012-05-22 21:17:44 +0000 | [diff] [blame] | 1894 | AnimationUpdateBlock animationUpdateBlock(m_frame ? m_frame->animation() : 0); |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 1895 | recalcStyle(NoChange); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1898 | void Document::updateStyleForAllDocuments() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1899 | { |
rniwa@webkit.org | cf0fea9 | 2010-11-05 22:47:59 +0000 | [diff] [blame] | 1900 | ASSERT(isMainThread()); |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1901 | if (!documentsThatNeedStyleRecalc) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1902 | return; |
| 1903 | |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1904 | while (documentsThatNeedStyleRecalc->size()) { |
| 1905 | HashSet<Document*>::iterator it = documentsThatNeedStyleRecalc->begin(); |
andersca@apple.com | f1fef13 | 2008-06-23 16:24:24 +0000 | [diff] [blame] | 1906 | Document* doc = *it; |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 1907 | documentsThatNeedStyleRecalc->remove(doc); |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1908 | doc->updateStyleIfNeeded(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | void Document::updateLayout() |
| 1913 | { |
rniwa@webkit.org | cf0fea9 | 2010-11-05 22:47:59 +0000 | [diff] [blame] | 1914 | ASSERT(isMainThread()); |
darin | 52c80798 | 2007-04-19 00:33:29 +0000 | [diff] [blame] | 1915 | if (Element* oe = ownerElement()) |
| 1916 | oe->document()->updateLayout(); |
| 1917 | |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 1918 | updateStyleIfNeeded(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1919 | |
slewis@apple.com | 9b67c99 | 2010-01-08 01:56:08 +0000 | [diff] [blame] | 1920 | // Only do a layout if changes have occurred that make it necessary. |
mjs | 22f8a1a | 2007-04-29 07:33:46 +0000 | [diff] [blame] | 1921 | FrameView* v = view(); |
slewis@apple.com | 9b67c99 | 2010-01-08 01:56:08 +0000 | [diff] [blame] | 1922 | if (v && renderer() && (v->layoutPending() || renderer()->needsLayout())) |
mjs | 22f8a1a | 2007-04-29 07:33:46 +0000 | [diff] [blame] | 1923 | v->layout(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | // FIXME: This is a bad idea and needs to be removed eventually. |
| 1927 | // Other browsers load stylesheets before they continue parsing the web page. |
| 1928 | // Since we don't, we can run JavaScript code that needs answers before the |
| 1929 | // stylesheets are loaded. Doing a layout ignoring the pending stylesheets |
| 1930 | // lets us get reasonable answers. The long term solution to this problem is |
| 1931 | // to instead suspend JavaScript execution. |
| 1932 | void Document::updateLayoutIgnorePendingStylesheets() |
| 1933 | { |
| 1934 | bool oldIgnore = m_ignorePendingStylesheets; |
| 1935 | |
| 1936 | if (!haveStylesheetsLoaded()) { |
| 1937 | m_ignorePendingStylesheets = true; |
hyatt | a9c6a34 | 2006-09-02 01:43:36 +0000 | [diff] [blame] | 1938 | // FIXME: We are willing to attempt to suppress painting with outdated style info only once. Our assumption is that it would be |
| 1939 | // dangerous to try to stop it a second time, after page content has already been loaded and displayed |
| 1940 | // with accurate style information. (Our suppression involves blanking the whole page at the |
| 1941 | // moment. If it were more refined, we might be able to do something better.) |
| 1942 | // It's worth noting though that this entire method is a hack, since what we really want to do is |
| 1943 | // suspend JS instead of doing a layout with inaccurate information. |
kling@webkit.org | 156604c | 2011-12-16 08:51:18 +0000 | [diff] [blame] | 1944 | HTMLElement* bodyElement = body(); |
| 1945 | if (bodyElement && !bodyElement->renderer() && m_pendingSheetLayout == NoLayoutWithPendingSheets) { |
hyatt | a9c6a34 | 2006-09-02 01:43:36 +0000 | [diff] [blame] | 1946 | m_pendingSheetLayout = DidLayoutWithPendingSheets; |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 1947 | styleResolverChanged(RecalcStyleImmediately); |
antti | fa58db35 | 2007-08-29 22:46:41 +0000 | [diff] [blame] | 1948 | } else if (m_hasNodesWithPlaceholderStyle) |
| 1949 | // If new nodes have been added or style recalc has been done with style sheets still pending, some nodes |
| 1950 | // may not have had their real style calculated yet. Normally this gets cleaned when style sheets arrive |
dbates@webkit.org | ef42d38 | 2010-01-25 19:20:06 +0000 | [diff] [blame] | 1951 | // but here we need up-to-date style immediately. |
antti | fa58db35 | 2007-08-29 22:46:41 +0000 | [diff] [blame] | 1952 | recalcStyle(Force); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | updateLayout(); |
| 1956 | |
| 1957 | m_ignorePendingStylesheets = oldIgnore; |
| 1958 | } |
| 1959 | |
mitz@apple.com | cd786b2 | 2010-02-19 00:19:48 +0000 | [diff] [blame] | 1960 | PassRefPtr<RenderStyle> Document::styleForElementIgnoringPendingStylesheets(Element* element) |
| 1961 | { |
| 1962 | ASSERT_ARG(element, element->document() == this); |
| 1963 | |
| 1964 | bool oldIgnore = m_ignorePendingStylesheets; |
| 1965 | m_ignorePendingStylesheets = true; |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 1966 | RefPtr<RenderStyle> style = styleResolver()->styleForElement(element, element->parentNode() ? element->parentNode()->computedStyle() : 0); |
mitz@apple.com | cd786b2 | 2010-02-19 00:19:48 +0000 | [diff] [blame] | 1967 | m_ignorePendingStylesheets = oldIgnore; |
| 1968 | return style.release(); |
| 1969 | } |
| 1970 | |
yuzo@google.com | b1f14f8 | 2010-06-16 03:23:12 +0000 | [diff] [blame] | 1971 | PassRefPtr<RenderStyle> Document::styleForPage(int pageIndex) |
| 1972 | { |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 1973 | RefPtr<RenderStyle> style = styleResolver()->styleForPage(pageIndex); |
yuzo@google.com | b1f14f8 | 2010-06-16 03:23:12 +0000 | [diff] [blame] | 1974 | return style.release(); |
| 1975 | } |
| 1976 | |
schenney@chromium.org | fc27bcb | 2012-10-02 13:03:18 +0000 | [diff] [blame^] | 1977 | void Document::registerCustomFont(PassRefPtr<FontData> fontData) |
commit-queue@webkit.org | def1a49 | 2012-09-07 22:58:56 +0000 | [diff] [blame] | 1978 | { |
| 1979 | m_customFonts.append(fontData); |
| 1980 | } |
| 1981 | |
| 1982 | void Document::deleteCustomFonts() |
| 1983 | { |
| 1984 | size_t size = m_customFonts.size(); |
| 1985 | for (size_t i = 0; i < size; ++i) |
| 1986 | GlyphPageTreeNode::pruneTreeCustomFontData(m_customFonts[i].get()); |
| 1987 | |
| 1988 | m_customFonts.clear(); |
| 1989 | } |
| 1990 | |
yuzo@google.com | 164cf38 | 2010-06-23 07:30:04 +0000 | [diff] [blame] | 1991 | bool Document::isPageBoxVisible(int pageIndex) |
| 1992 | { |
| 1993 | RefPtr<RenderStyle> style = styleForPage(pageIndex); |
| 1994 | return style->visibility() != HIDDEN; // display property doesn't apply to @page. |
| 1995 | } |
| 1996 | |
yuzo@google.com | 0170f20 | 2010-06-28 01:59:51 +0000 | [diff] [blame] | 1997 | void Document::pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft) |
yuzo@google.com | 164cf38 | 2010-06-23 07:30:04 +0000 | [diff] [blame] | 1998 | { |
| 1999 | RefPtr<RenderStyle> style = styleForPage(pageIndex); |
commit-queue@webkit.org | c558b51 | 2012-03-27 19:19:59 +0000 | [diff] [blame] | 2000 | RenderView* view = renderView(); |
yuzo@google.com | 164cf38 | 2010-06-23 07:30:04 +0000 | [diff] [blame] | 2001 | |
yuzo@google.com | 0170f20 | 2010-06-28 01:59:51 +0000 | [diff] [blame] | 2002 | int width = pageSize.width(); |
| 2003 | int height = pageSize.height(); |
| 2004 | switch (style->pageSizeType()) { |
| 2005 | case PAGE_SIZE_AUTO: |
| 2006 | break; |
| 2007 | case PAGE_SIZE_AUTO_LANDSCAPE: |
| 2008 | if (width < height) |
| 2009 | std::swap(width, height); |
| 2010 | break; |
| 2011 | case PAGE_SIZE_AUTO_PORTRAIT: |
| 2012 | if (width > height) |
| 2013 | std::swap(width, height); |
| 2014 | break; |
| 2015 | case PAGE_SIZE_RESOLVED: { |
| 2016 | LengthSize size = style->pageSize(); |
| 2017 | ASSERT(size.width().isFixed()); |
| 2018 | ASSERT(size.height().isFixed()); |
commit-queue@webkit.org | c558b51 | 2012-03-27 19:19:59 +0000 | [diff] [blame] | 2019 | width = valueForLength(size.width(), 0, view); |
| 2020 | height = valueForLength(size.height(), 0, view); |
yuzo@google.com | 0170f20 | 2010-06-28 01:59:51 +0000 | [diff] [blame] | 2021 | break; |
| 2022 | } |
| 2023 | default: |
| 2024 | ASSERT_NOT_REACHED(); |
| 2025 | } |
| 2026 | pageSize = IntSize(width, height); |
yuzo@google.com | 164cf38 | 2010-06-23 07:30:04 +0000 | [diff] [blame] | 2027 | |
yuzo@google.com | 0170f20 | 2010-06-28 01:59:51 +0000 | [diff] [blame] | 2028 | // The percentage is calculated with respect to the width even for margin top and bottom. |
| 2029 | // http://www.w3.org/TR/CSS2/box.html#margin-properties |
leviw@chromium.org | f5ba187 | 2012-04-13 04:19:42 +0000 | [diff] [blame] | 2030 | marginTop = style->marginTop().isAuto() ? marginTop : intValueForLength(style->marginTop(), width, view); |
| 2031 | marginRight = style->marginRight().isAuto() ? marginRight : intValueForLength(style->marginRight(), width, view); |
| 2032 | marginBottom = style->marginBottom().isAuto() ? marginBottom : intValueForLength(style->marginBottom(), width, view); |
| 2033 | marginLeft = style->marginLeft().isAuto() ? marginLeft : intValueForLength(style->marginLeft(), width, view); |
yuzo@google.com | 164cf38 | 2010-06-23 07:30:04 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
haraken@chromium.org | abf5d02 | 2012-06-28 06:29:27 +0000 | [diff] [blame] | 2036 | void Document::setDocumentRareData(NodeRareData* rareData) |
| 2037 | { |
| 2038 | m_documentRareData = rareData; |
| 2039 | } |
| 2040 | |
japhet@chromium.org | 0d6b1de | 2011-05-25 18:51:27 +0000 | [diff] [blame] | 2041 | void Document::setIsViewSource(bool isViewSource) |
| 2042 | { |
| 2043 | m_isViewSource = isViewSource; |
| 2044 | if (!m_isViewSource) |
| 2045 | return; |
| 2046 | |
abarth@webkit.org | 435c759 | 2011-11-18 04:58:44 +0000 | [diff] [blame] | 2047 | setSecurityOrigin(SecurityOrigin::createUnique()); |
abarth@webkit.org | d19503e | 2012-08-09 23:59:52 +0000 | [diff] [blame] | 2048 | didUpdateSecurityOrigin(); |
japhet@chromium.org | 0d6b1de | 2011-05-25 18:51:27 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 2051 | void Document::createStyleResolver() |
hyatt@apple.com | 0880de1 | 2010-01-28 17:47:30 +0000 | [diff] [blame] | 2052 | { |
| 2053 | bool matchAuthorAndUserStyles = true; |
| 2054 | if (Settings* docSettings = settings()) |
| 2055 | matchAuthorAndUserStyles = docSettings->authorAndUserStylesEnabled(); |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 2056 | m_styleResolver = adoptPtr(new StyleResolver(this, matchAuthorAndUserStyles)); |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 2057 | m_styleSheetCollection->combineCSSFeatureFlags(); |
hyatt@apple.com | 0880de1 | 2010-01-28 17:47:30 +0000 | [diff] [blame] | 2058 | } |
antti@apple.com | 846f7b3 | 2012-03-27 12:40:38 +0000 | [diff] [blame] | 2059 | |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 2060 | void Document::clearStyleResolver() |
antti@apple.com | 3f4f37b | 2012-01-09 14:59:57 +0000 | [diff] [blame] | 2061 | { |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 2062 | m_styleResolver.clear(); |
antti@apple.com | 3f4f37b | 2012-01-09 14:59:57 +0000 | [diff] [blame] | 2063 | } |
hyatt@apple.com | 0880de1 | 2010-01-28 17:47:30 +0000 | [diff] [blame] | 2064 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2065 | void Document::attach() |
| 2066 | { |
ggaren | f9f32ae | 2007-03-26 20:08:53 +0000 | [diff] [blame] | 2067 | ASSERT(!attached()); |
| 2068 | ASSERT(!m_inPageCache); |
commit-queue@webkit.org | e45033b | 2011-09-27 17:29:46 +0000 | [diff] [blame] | 2069 | ASSERT(!m_axObjectCache || this != topDocument()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2070 | |
| 2071 | if (!m_renderArena) |
levin@chromium.org | 5af8b19 | 2011-04-26 17:16:27 +0000 | [diff] [blame] | 2072 | m_renderArena = adoptPtr(new RenderArena); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2073 | |
| 2074 | // Create the rendering tree |
abarth@webkit.org | 3e03535 | 2009-12-04 05:54:58 +0000 | [diff] [blame] | 2075 | setRenderer(new (m_renderArena.get()) RenderView(this, view())); |
simon.fraser@apple.com | 8f9c77b | 2009-02-06 17:05:07 +0000 | [diff] [blame] | 2076 | #if USE(ACCELERATED_COMPOSITING) |
| 2077 | renderView()->didMoveOnscreen(); |
| 2078 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2079 | |
| 2080 | recalcStyle(Force); |
| 2081 | |
| 2082 | RenderObject* render = renderer(); |
| 2083 | setRenderer(0); |
| 2084 | |
hayato@chromium.org | 81596e4 | 2012-02-02 04:21:29 +0000 | [diff] [blame] | 2085 | ContainerNode::attach(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2086 | |
| 2087 | setRenderer(render); |
| 2088 | } |
| 2089 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2090 | void Document::detach() |
| 2091 | { |
darin | 4782910 | 2007-09-06 19:39:32 +0000 | [diff] [blame] | 2092 | ASSERT(attached()); |
| 2093 | ASSERT(!m_inPageCache); |
| 2094 | |
scheib@chromium.org | fd0b8a9 | 2012-07-13 20:37:50 +0000 | [diff] [blame] | 2095 | #if ENABLE(POINTER_LOCK) |
| 2096 | if (page()) |
| 2097 | page()->pointerLockController()->documentDetached(this); |
| 2098 | #endif |
| 2099 | |
commit-queue@webkit.org | e45033b | 2011-09-27 17:29:46 +0000 | [diff] [blame] | 2100 | if (this == topDocument()) |
| 2101 | clearAXObjectCache(); |
| 2102 | |
oliver@apple.com | 9440806 | 2008-12-11 02:14:04 +0000 | [diff] [blame] | 2103 | stopActiveDOMObjects(); |
dimich@chromium.org | 34a3c44 | 2011-08-30 17:35:52 +0000 | [diff] [blame] | 2104 | m_eventQueue->close(); |
commit-queue@webkit.org | 49314b9 | 2011-09-20 00:19:02 +0000 | [diff] [blame] | 2105 | #if ENABLE(FULLSCREEN_API) |
| 2106 | m_fullScreenChangeEventTargetQueue.clear(); |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 2107 | m_fullScreenErrorEventTargetQueue.clear(); |
commit-queue@webkit.org | 49314b9 | 2011-09-20 00:19:02 +0000 | [diff] [blame] | 2108 | #endif |
zmo@google.com | 83f778b | 2011-03-17 23:26:27 +0000 | [diff] [blame] | 2109 | |
| 2110 | #if ENABLE(REQUEST_ANIMATION_FRAME) |
| 2111 | // FIXME: consider using ActiveDOMObject. |
jamesr@google.com | a5d3c9e | 2011-12-09 01:33:41 +0000 | [diff] [blame] | 2112 | if (m_scriptedAnimationController) |
| 2113 | m_scriptedAnimationController->clearDocumentPointer(); |
| 2114 | m_scriptedAnimationController.clear(); |
zmo@google.com | 83f778b | 2011-03-17 23:26:27 +0000 | [diff] [blame] | 2115 | #endif |
| 2116 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2117 | RenderObject* render = renderer(); |
| 2118 | |
simon.fraser@apple.com | bd618dd | 2009-02-19 19:20:33 +0000 | [diff] [blame] | 2119 | documentWillBecomeInactive(); |
atwilson@chromium.org | e57cf26 | 2009-08-12 01:05:22 +0000 | [diff] [blame] | 2120 | |
| 2121 | #if ENABLE(SHARED_WORKERS) |
| 2122 | SharedWorkerRepository::documentDetached(this); |
| 2123 | #endif |
| 2124 | |
levin@chromium.org | b742833 | 2009-06-22 17:20:03 +0000 | [diff] [blame] | 2125 | if (m_frame) { |
| 2126 | FrameView* view = m_frame->view(); |
| 2127 | if (view) |
| 2128 | view->detachCustomScrollbars(); |
eric@webkit.org | 19e68c5 | 2010-01-29 17:56:44 +0000 | [diff] [blame] | 2129 | |
levin@chromium.org | b742833 | 2009-06-22 17:20:03 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2132 | // indicate destruction mode, i.e. attached() but renderer == 0 |
| 2133 | setRenderer(0); |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 2134 | |
| 2135 | #if ENABLE(FULLSCREEN_API) |
| 2136 | if (m_fullScreenRenderer) |
| 2137 | setFullScreenRenderer(0); |
| 2138 | #endif |
darin@apple.com | c4dab5d | 2009-03-17 17:02:19 +0000 | [diff] [blame] | 2139 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2140 | m_hoverNode = 0; |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 2141 | m_focusedNode = 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2142 | m_activeNode = 0; |
| 2143 | |
hayato@chromium.org | 81596e4 | 2012-02-02 04:21:29 +0000 | [diff] [blame] | 2144 | ContainerNode::detach(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2145 | |
hyatt@apple.com | dcf3633 | 2009-04-10 03:15:05 +0000 | [diff] [blame] | 2146 | unscheduleStyleRecalc(); |
| 2147 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2148 | if (render) |
| 2149 | render->destroy(); |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 2150 | |
eric@webkit.org | e0a5162 | 2008-06-26 22:45:47 +0000 | [diff] [blame] | 2151 | // This is required, as our Frame might delete itself as soon as it detaches |
dbates@webkit.org | ef42d38 | 2010-01-25 19:20:06 +0000 | [diff] [blame] | 2152 | // us. However, this violates Node::detach() semantics, as it's never |
darin@apple.com | 4cd1b24 | 2009-03-27 23:37:46 +0000 | [diff] [blame] | 2153 | // possible to re-attach. Eventually Document::detach() should be renamed, |
| 2154 | // or this setting of the frame to 0 could be made explicit in each of the |
| 2155 | // callers of Document::detach(). |
| 2156 | m_frame = 0; |
abarth@webkit.org | 3e03535 | 2009-12-04 05:54:58 +0000 | [diff] [blame] | 2157 | m_renderArena.clear(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
jberlin@webkit.org | a4facf2 | 2012-05-10 02:00:38 +0000 | [diff] [blame] | 2160 | void Document::prepareForDestruction() |
| 2161 | { |
morrita@google.com | 1b44b4d | 2012-05-10 11:37:09 +0000 | [diff] [blame] | 2162 | disconnectDescendantFrames(); |
jberlin@webkit.org | a4facf2 | 2012-05-10 02:00:38 +0000 | [diff] [blame] | 2163 | if (DOMWindow* window = this->domWindow()) |
| 2164 | window->willDetachDocumentFromFrame(); |
| 2165 | detach(); |
| 2166 | } |
| 2167 | |
ggaren@apple.com | bc6ef28 | 2009-04-13 19:43:47 +0000 | [diff] [blame] | 2168 | void Document::removeAllEventListeners() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2169 | { |
ggaren@apple.com | 521f64b | 2009-09-24 05:53:23 +0000 | [diff] [blame] | 2170 | EventTarget::removeAllEventListeners(); |
| 2171 | |
ggaren@apple.com | bc6ef28 | 2009-04-13 19:43:47 +0000 | [diff] [blame] | 2172 | if (DOMWindow* domWindow = this->domWindow()) |
| 2173 | domWindow->removeAllEventListeners(); |
ggaren@apple.com | 521f64b | 2009-09-24 05:53:23 +0000 | [diff] [blame] | 2174 | for (Node* node = firstChild(); node; node = node->traverseNextNode()) |
weinig@apple.com | b9d2ac2 | 2009-02-05 20:35:53 +0000 | [diff] [blame] | 2175 | node->removeAllEventListeners(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
kenneth@webkit.org | ae65fe3 | 2011-10-26 14:56:09 +0000 | [diff] [blame] | 2178 | void Document::suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension why) |
| 2179 | { |
| 2180 | ScriptExecutionContext::suspendActiveDOMObjects(why); |
| 2181 | |
| 2182 | #if ENABLE(DEVICE_ORIENTATION) |
| 2183 | if (!page()) |
| 2184 | return; |
| 2185 | |
commit-queue@webkit.org | 335a9d8 | 2012-02-13 01:18:28 +0000 | [diff] [blame] | 2186 | if (DeviceMotionController* controller = DeviceMotionController::from(page())) |
| 2187 | controller->suspendEventsForAllListeners(domWindow()); |
| 2188 | if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) |
| 2189 | controller->suspendEventsForAllListeners(domWindow()); |
| 2190 | |
kenneth@webkit.org | ae65fe3 | 2011-10-26 14:56:09 +0000 | [diff] [blame] | 2191 | #endif |
| 2192 | } |
| 2193 | |
| 2194 | void Document::resumeActiveDOMObjects() |
| 2195 | { |
| 2196 | ScriptExecutionContext::resumeActiveDOMObjects(); |
| 2197 | |
| 2198 | #if ENABLE(DEVICE_ORIENTATION) |
| 2199 | if (!page()) |
| 2200 | return; |
| 2201 | |
commit-queue@webkit.org | 335a9d8 | 2012-02-13 01:18:28 +0000 | [diff] [blame] | 2202 | if (DeviceMotionController* controller = DeviceMotionController::from(page())) |
| 2203 | controller->resumeEventsForAllListeners(domWindow()); |
| 2204 | if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) |
| 2205 | controller->resumeEventsForAllListeners(domWindow()); |
kenneth@webkit.org | ae65fe3 | 2011-10-26 14:56:09 +0000 | [diff] [blame] | 2206 | #endif |
| 2207 | } |
| 2208 | |
hyatt@apple.com | ee16394 | 2009-01-23 21:25:32 +0000 | [diff] [blame] | 2209 | RenderView* Document::renderView() const |
| 2210 | { |
weinig@apple.com | e2da629 | 2009-01-30 21:57:37 +0000 | [diff] [blame] | 2211 | return toRenderView(renderer()); |
hyatt@apple.com | ee16394 | 2009-01-23 21:25:32 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
harrison@apple.com | 7954df2 | 2008-03-12 16:16:40 +0000 | [diff] [blame] | 2214 | void Document::clearAXObjectCache() |
| 2215 | { |
| 2216 | // clear cache in top document |
| 2217 | if (m_axObjectCache) { |
inferno@chromium.org | 22417bf | 2010-11-30 23:21:15 +0000 | [diff] [blame] | 2218 | // Clear the cache member variable before calling delete because attempts |
| 2219 | // are made to access it during destruction. |
| 2220 | AXObjectCache* axObjectCache = m_axObjectCache; |
harrison@apple.com | 7954df2 | 2008-03-12 16:16:40 +0000 | [diff] [blame] | 2221 | m_axObjectCache = 0; |
inferno@chromium.org | 22417bf | 2010-11-30 23:21:15 +0000 | [diff] [blame] | 2222 | delete axObjectCache; |
harrison@apple.com | 7954df2 | 2008-03-12 16:16:40 +0000 | [diff] [blame] | 2223 | return; |
| 2224 | } |
| 2225 | |
| 2226 | // ask the top-level document to clear its cache |
| 2227 | Document* doc = topDocument(); |
| 2228 | if (doc != this) |
| 2229 | doc->clearAXObjectCache(); |
| 2230 | } |
| 2231 | |
cfleizach@apple.com | c6d72ec | 2010-09-28 17:59:32 +0000 | [diff] [blame] | 2232 | bool Document::axObjectCacheExists() const |
| 2233 | { |
| 2234 | if (m_axObjectCache) |
| 2235 | return true; |
| 2236 | |
| 2237 | Document* doc = topDocument(); |
| 2238 | if (doc != this) |
| 2239 | return doc->axObjectCacheExists(); |
| 2240 | |
| 2241 | return false; |
| 2242 | } |
| 2243 | |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 2244 | AXObjectCache* Document::axObjectCache() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2245 | { |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 2246 | // The only document that actually has a AXObjectCache is the top-level |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2247 | // document. This is because we need to be able to get from any WebCoreAXObject |
| 2248 | // to any other WebCoreAXObject on the same page. Using a single cache allows |
| 2249 | // lookups across nested webareas (i.e. multiple documents). |
| 2250 | |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 2251 | if (m_axObjectCache) { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2252 | // return already known top-level cache |
| 2253 | if (!ownerElement()) |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 2254 | return m_axObjectCache; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2255 | |
| 2256 | // In some pages with frames, the cache is created before the sub-webarea is |
| 2257 | // inserted into the tree. Here, we catch that case and just toss the old |
| 2258 | // cache and start over. |
harrison@apple.com | 7954df2 | 2008-03-12 16:16:40 +0000 | [diff] [blame] | 2259 | // NOTE: This recovery may no longer be needed. I have been unable to trigger |
| 2260 | // it again. See rdar://5794454 |
| 2261 | // FIXME: Can this be fixed when inserting the subframe instead of now? |
| 2262 | // FIXME: If this function was called to get the cache in order to remove |
| 2263 | // an AXObject, we are now deleting the cache as a whole and returning a |
| 2264 | // new empty cache that does not contain the AXObject! That should actually |
| 2265 | // be OK. I am concerned about other cases like this where accessing the |
| 2266 | // cache blows away the AXObject being operated on. |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 2267 | delete m_axObjectCache; |
| 2268 | m_axObjectCache = 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | // ask the top-level document for its cache |
darin | 4e217c0 | 2006-03-24 07:07:34 +0000 | [diff] [blame] | 2272 | Document* doc = topDocument(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2273 | if (doc != this) |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 2274 | return doc->axObjectCache(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2275 | |
| 2276 | // this is the top-level document, so install a new cache |
cfleizach@apple.com | aa50410 | 2011-01-05 01:07:44 +0000 | [diff] [blame] | 2277 | m_axObjectCache = new AXObjectCache(this); |
darin | e775cf7 | 2006-07-09 22:48:56 +0000 | [diff] [blame] | 2278 | return m_axObjectCache; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | void Document::setVisuallyOrdered() |
| 2282 | { |
hyatt@apple.com | 0880de1 | 2010-01-28 17:47:30 +0000 | [diff] [blame] | 2283 | m_visuallyOrdered = true; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2284 | if (renderer()) |
macpherson@chromium.org | 258babf | 2011-06-10 06:20:58 +0000 | [diff] [blame] | 2285 | renderer()->style()->setRTLOrdering(VisualOrder); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2286 | } |
| 2287 | |
eric@webkit.org | 0cea84c | 2010-08-19 19:32:02 +0000 | [diff] [blame] | 2288 | PassRefPtr<DocumentParser> Document::createParser() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2289 | { |
mjs | 22f8a1a | 2007-04-29 07:33:46 +0000 | [diff] [blame] | 2290 | // FIXME: this should probably pass the frame instead |
jpfau@apple.com | e854e5d | 2011-07-08 19:31:34 +0000 | [diff] [blame] | 2291 | #if ENABLE(NEW_XML) |
| 2292 | return NewXMLDocumentParser::create(this); |
| 2293 | #else |
eric@webkit.org | 0cea84c | 2010-08-19 19:32:02 +0000 | [diff] [blame] | 2294 | return XMLDocumentParser::create(this, view()); |
jpfau@apple.com | e854e5d | 2011-07-08 19:31:34 +0000 | [diff] [blame] | 2295 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
eric@webkit.org | e37f595 | 2010-06-28 07:56:10 +0000 | [diff] [blame] | 2298 | ScriptableDocumentParser* Document::scriptableDocumentParser() const |
| 2299 | { |
| 2300 | return parser() ? parser()->asScriptableDocumentParser() : 0; |
| 2301 | } |
| 2302 | |
abarth@webkit.org | bf2c13a | 2008-06-12 06:41:53 +0000 | [diff] [blame] | 2303 | void Document::open(Document* ownerDocument) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2304 | { |
abarth@webkit.org | bf2c13a | 2008-06-12 06:41:53 +0000 | [diff] [blame] | 2305 | if (ownerDocument) { |
| 2306 | setURL(ownerDocument->url()); |
abarth@webkit.org | bf2c13a | 2008-06-12 06:41:53 +0000 | [diff] [blame] | 2307 | m_cookieURL = ownerDocument->cookieURL(); |
abarth@webkit.org | 51ad70c | 2011-11-18 00:20:41 +0000 | [diff] [blame] | 2308 | setSecurityOrigin(ownerDocument->securityOrigin()); |
aliceli1 | 4bd0100 | 2006-08-28 20:43:36 +0000 | [diff] [blame] | 2309 | } |
aliceli1 | 4bd0100 | 2006-08-28 20:43:36 +0000 | [diff] [blame] | 2310 | |
andersca | 07ff221 | 2007-07-24 03:09:32 +0000 | [diff] [blame] | 2311 | if (m_frame) { |
tonyg@chromium.org | 9ccc4f3 | 2011-03-01 00:54:55 +0000 | [diff] [blame] | 2312 | if (ScriptableDocumentParser* parser = scriptableDocumentParser()) { |
| 2313 | if (parser->isParsing()) { |
| 2314 | // FIXME: HTML5 doesn't tell us to check this, it might not be correct. |
| 2315 | if (parser->isExecutingScript()) |
| 2316 | return; |
| 2317 | |
| 2318 | if (!parser->wasCreatedByScript() && parser->hasInsertionPoint()) |
| 2319 | return; |
| 2320 | } |
| 2321 | } |
eric@webkit.org | e37f595 | 2010-06-28 07:56:10 +0000 | [diff] [blame] | 2322 | |
andersca | 07ff221 | 2007-07-24 03:09:32 +0000 | [diff] [blame] | 2323 | if (m_frame->loader()->state() == FrameStateProvisional) |
| 2324 | m_frame->loader()->stopAllLoaders(); |
| 2325 | } |
abarth@webkit.org | 4c4bee0 | 2009-06-19 18:25:42 +0000 | [diff] [blame] | 2326 | |
commit-queue@webkit.org | 53b27b5 | 2010-10-13 23:10:56 +0000 | [diff] [blame] | 2327 | removeAllEventListeners(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2328 | implicitOpen(); |
abarth@webkit.org | 01e4cc0 | 2011-02-09 23:07:45 +0000 | [diff] [blame] | 2329 | if (ScriptableDocumentParser* parser = scriptableDocumentParser()) |
| 2330 | parser->setWasCreatedByScript(true); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2331 | |
eric@webkit.org | 871c3a7 | 2009-10-13 20:27:04 +0000 | [diff] [blame] | 2332 | if (DOMWindow* domWindow = this->domWindow()) |
| 2333 | domWindow->removeAllEventListeners(); |
| 2334 | |
ap@webkit.org | a0a1987 | 2008-02-05 09:34:18 +0000 | [diff] [blame] | 2335 | if (m_frame) |
| 2336 | m_frame->loader()->didExplicitOpen(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
eric@webkit.org | 0cea84c | 2010-08-19 19:32:02 +0000 | [diff] [blame] | 2339 | void Document::detachParser() |
| 2340 | { |
| 2341 | if (!m_parser) |
| 2342 | return; |
| 2343 | m_parser->detach(); |
| 2344 | m_parser.clear(); |
| 2345 | } |
| 2346 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2347 | void Document::cancelParsing() |
| 2348 | { |
abarth@webkit.org | 01e4cc0 | 2011-02-09 23:07:45 +0000 | [diff] [blame] | 2349 | if (!m_parser) |
| 2350 | return; |
| 2351 | |
| 2352 | // We have to clear the parser to avoid possibly triggering |
| 2353 | // the onload handler when closing as a side effect of a cancel-style |
| 2354 | // change, such as opening a new document or closing the window while |
| 2355 | // still parsing |
| 2356 | detachParser(); |
| 2357 | explicitClose(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | void Document::implicitOpen() |
| 2361 | { |
| 2362 | cancelParsing(); |
| 2363 | |
eric@webkit.org | 871c3a7 | 2009-10-13 20:27:04 +0000 | [diff] [blame] | 2364 | removeChildren(); |
| 2365 | |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 2366 | setCompatibilityMode(NoQuirksMode); |
| 2367 | |
abarth@webkit.org | 5d72ad2 | 2010-06-14 04:40:20 +0000 | [diff] [blame] | 2368 | m_parser = createParser(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2369 | setParsing(true); |
tonyg@chromium.org | d299d8a7 | 2010-09-06 18:32:48 +0000 | [diff] [blame] | 2370 | setReadyState(Loading); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2371 | } |
| 2372 | |
zecke@webkit.org | 6c03d34 | 2009-01-31 03:51:37 +0000 | [diff] [blame] | 2373 | HTMLElement* Document::body() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2374 | { |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 2375 | Node* de = documentElement(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2376 | if (!de) |
| 2377 | return 0; |
| 2378 | |
| 2379 | // try to prefer a FRAMESET element over BODY |
| 2380 | Node* body = 0; |
| 2381 | for (Node* i = de->firstChild(); i; i = i->nextSibling()) { |
| 2382 | if (i->hasTagName(framesetTag)) |
yael.aharon@nokia.com | 3be82c1 | 2011-02-09 23:13:27 +0000 | [diff] [blame] | 2383 | return toHTMLElement(i); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2384 | |
hyatt@apple.com | bf26cc0 | 2008-10-14 20:35:36 +0000 | [diff] [blame] | 2385 | if (i->hasTagName(bodyTag) && !body) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2386 | body = i; |
| 2387 | } |
yael.aharon@nokia.com | 3be82c1 | 2011-02-09 23:13:27 +0000 | [diff] [blame] | 2388 | return toHTMLElement(body); |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 2389 | } |
| 2390 | |
andersca@apple.com | d645ac6 | 2011-06-20 20:21:56 +0000 | [diff] [blame] | 2391 | void Document::setBody(PassRefPtr<HTMLElement> prpNewBody, ExceptionCode& ec) |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 2392 | { |
andersca@apple.com | d645ac6 | 2011-06-20 20:21:56 +0000 | [diff] [blame] | 2393 | RefPtr<HTMLElement> newBody = prpNewBody; |
| 2394 | |
inferno@chromium.org | e2b8e39 | 2011-06-01 23:13:53 +0000 | [diff] [blame] | 2395 | if (!newBody || !documentElement() || !newBody->hasTagName(bodyTag)) { |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 2396 | ec = HIERARCHY_REQUEST_ERR; |
| 2397 | return; |
| 2398 | } |
| 2399 | |
inferno@chromium.org | e2b8e39 | 2011-06-01 23:13:53 +0000 | [diff] [blame] | 2400 | if (newBody->document() && newBody->document() != this) { |
inferno@chromium.org | 06e516e | 2011-06-02 02:49:37 +0000 | [diff] [blame] | 2401 | ec = 0; |
inferno@chromium.org | e2b8e39 | 2011-06-01 23:13:53 +0000 | [diff] [blame] | 2402 | RefPtr<Node> node = importNode(newBody.get(), true, ec); |
| 2403 | if (ec) |
| 2404 | return; |
| 2405 | |
| 2406 | newBody = toHTMLElement(node.get()); |
| 2407 | } |
| 2408 | |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 2409 | HTMLElement* b = body(); |
| 2410 | if (!b) |
andersca@apple.com | d645ac6 | 2011-06-20 20:21:56 +0000 | [diff] [blame] | 2411 | documentElement()->appendChild(newBody.release(), ec); |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 2412 | else |
andersca@apple.com | d645ac6 | 2011-06-20 20:21:56 +0000 | [diff] [blame] | 2413 | documentElement()->replaceChild(newBody.release(), b, ec); |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
darin | a6a0caf | 2007-01-25 00:16:44 +0000 | [diff] [blame] | 2416 | HTMLHeadElement* Document::head() |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 2417 | { |
| 2418 | Node* de = documentElement(); |
| 2419 | if (!de) |
| 2420 | return 0; |
| 2421 | |
| 2422 | for (Node* e = de->firstChild(); e; e = e->nextSibling()) |
| 2423 | if (e->hasTagName(headTag)) |
darin | a6a0caf | 2007-01-25 00:16:44 +0000 | [diff] [blame] | 2424 | return static_cast<HTMLHeadElement*>(e); |
bdash | f45c4e3 | 2007-01-24 03:44:47 +0000 | [diff] [blame] | 2425 | |
| 2426 | return 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | void Document::close() |
| 2430 | { |
abarth@webkit.org | 01e4cc0 | 2011-02-09 23:07:45 +0000 | [diff] [blame] | 2431 | // FIXME: We should follow the specification more closely: |
| 2432 | // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-close |
| 2433 | |
tonyg@chromium.org | 517fd46 | 2011-05-05 22:38:09 +0000 | [diff] [blame] | 2434 | if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedByScript() || !scriptableDocumentParser()->isParsing()) |
abarth@webkit.org | 01e4cc0 | 2011-02-09 23:07:45 +0000 | [diff] [blame] | 2435 | return; |
| 2436 | |
| 2437 | explicitClose(); |
| 2438 | } |
| 2439 | |
| 2440 | void Document::explicitClose() |
| 2441 | { |
abarth@webkit.org | 14a3bdf | 2011-06-11 00:56:13 +0000 | [diff] [blame] | 2442 | if (m_parser) |
| 2443 | m_parser->finish(); |
| 2444 | |
abarth@webkit.org | 01e4cc0 | 2011-02-09 23:07:45 +0000 | [diff] [blame] | 2445 | if (!m_frame) { |
ggaren | d9f8cfd | 2007-07-10 16:25:40 +0000 | [diff] [blame] | 2446 | // Because we have no frame, we don't know if all loading has completed, |
| 2447 | // so we just call implicitClose() immediately. FIXME: This might fire |
| 2448 | // the load event prematurely <http://bugs.webkit.org/show_bug.cgi?id=14568>. |
| 2449 | implicitClose(); |
abarth@webkit.org | 01e4cc0 | 2011-02-09 23:07:45 +0000 | [diff] [blame] | 2450 | return; |
ggaren | d9f8cfd | 2007-07-10 16:25:40 +0000 | [diff] [blame] | 2451 | } |
abarth@webkit.org | 01e4cc0 | 2011-02-09 23:07:45 +0000 | [diff] [blame] | 2452 | |
abarth@webkit.org | 14a3bdf | 2011-06-11 00:56:13 +0000 | [diff] [blame] | 2453 | m_frame->loader()->checkCompleted(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | void Document::implicitClose() |
| 2457 | { |
| 2458 | // If we're in the middle of recalcStyle, we need to defer the close until the style information is accurate and all elements are re-attached. |
| 2459 | if (m_inStyleRecalc) { |
| 2460 | m_closeAfterStyleRecalc = true; |
| 2461 | return; |
| 2462 | } |
| 2463 | |
abarth@webkit.org | 88b4e6b | 2010-10-04 22:09:57 +0000 | [diff] [blame] | 2464 | bool wasLocationChangePending = frame() && frame()->navigationScheduler()->locationChangePending(); |
abarth@webkit.org | 5d72ad2 | 2010-06-14 04:40:20 +0000 | [diff] [blame] | 2465 | bool doload = !parsing() && m_parser && !m_processingLoadEvent && !wasLocationChangePending; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2466 | |
| 2467 | if (!doload) |
| 2468 | return; |
| 2469 | |
| 2470 | m_processingLoadEvent = true; |
| 2471 | |
eric@webkit.org | e37f595 | 2010-06-28 07:56:10 +0000 | [diff] [blame] | 2472 | ScriptableDocumentParser* parser = scriptableDocumentParser(); |
| 2473 | m_wellFormed = parser && parser->wellFormed(); |
ap | 2cb6b94 | 2006-11-20 19:56:38 +0000 | [diff] [blame] | 2474 | |
abarth@webkit.org | 5d72ad2 | 2010-06-14 04:40:20 +0000 | [diff] [blame] | 2475 | // We have to clear the parser, in case someone document.write()s from the |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2476 | // onLoad event handler, as in Radar 3206524. |
eric@webkit.org | 0cea84c | 2010-08-19 19:32:02 +0000 | [diff] [blame] | 2477 | detachParser(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2478 | |
antti@apple.com | 6c76e54 | 2008-03-13 21:20:31 +0000 | [diff] [blame] | 2479 | // Parser should have picked up all preloads by now |
abarth@webkit.org | 17d66c6 | 2010-09-08 10:26:02 +0000 | [diff] [blame] | 2480 | m_cachedResourceLoader->clearPreloads(); |
antti@apple.com | 6c76e54 | 2008-03-13 21:20:31 +0000 | [diff] [blame] | 2481 | |
beidson@apple.com | 2626514 | 2008-04-23 00:13:31 +0000 | [diff] [blame] | 2482 | // FIXME: We kick off the icon loader when the Document is done parsing. |
| 2483 | // There are earlier opportunities we could start it: |
| 2484 | // -When the <head> finishes parsing |
| 2485 | // -When any new HTMLLinkElement is inserted into the document |
| 2486 | // But those add a dynamic component to the favicon that has UI |
| 2487 | // ramifications, and we need to decide what is the Right Thing To Do(tm) |
| 2488 | Frame* f = frame(); |
abarth@webkit.org | 4e00997 | 2011-06-13 20:36:03 +0000 | [diff] [blame] | 2489 | if (f) { |
| 2490 | f->loader()->icon()->startLoader(); |
cmarrin@apple.com | e6a2700 | 2010-11-05 21:45:37 +0000 | [diff] [blame] | 2491 | f->animation()->resumeAnimationsForDocument(this); |
abarth@webkit.org | 4e00997 | 2011-06-13 20:36:03 +0000 | [diff] [blame] | 2492 | } |
dino@apple.com | 6b8acf7 | 2008-08-08 20:44:14 +0000 | [diff] [blame] | 2493 | |
ap@apple.com | 66e61bd | 2009-12-14 21:47:04 +0000 | [diff] [blame] | 2494 | ImageLoader::dispatchPendingBeforeLoadEvents(); |
| 2495 | ImageLoader::dispatchPendingLoadEvents(); |
abarth@webkit.org | 71def43 | 2012-03-27 01:59:06 +0000 | [diff] [blame] | 2496 | ImageLoader::dispatchPendingErrorEvents(); |
zimmermann@webkit.org | 3d2114c | 2012-02-08 10:21:49 +0000 | [diff] [blame] | 2497 | |
dbates@webkit.org | 03278c1 | 2012-02-24 16:50:55 +0000 | [diff] [blame] | 2498 | HTMLLinkElement::dispatchPendingLoadEvents(); |
| 2499 | HTMLStyleElement::dispatchPendingLoadEvents(); |
| 2500 | |
zimmermann@webkit.org | 3d2114c | 2012-02-08 10:21:49 +0000 | [diff] [blame] | 2501 | #if ENABLE(SVG) |
| 2502 | // To align the HTML load event and the SVGLoad event for the outermost <svg> element, fire it from |
| 2503 | // here, instead of doing it from SVGElement::finishedParsingChildren (if externalResourcesRequired="false", |
| 2504 | // which is the default, for ='true' its fired at a later time, once all external resources finished loading). |
| 2505 | if (svgExtensions()) |
| 2506 | accessSVGExtensions()->dispatchSVGLoadEventToOutermostSVGElements(); |
| 2507 | #endif |
| 2508 | |
ggaren@apple.com | 521f64b | 2009-09-24 05:53:23 +0000 | [diff] [blame] | 2509 | dispatchWindowLoadEvent(); |
beidson@apple.com | 43a414c | 2010-03-19 18:25:21 +0000 | [diff] [blame] | 2510 | enqueuePageshowEvent(PageshowEventNotPersisted); |
commit-queue@webkit.org | 7235406 | 2010-09-02 01:00:51 +0000 | [diff] [blame] | 2511 | enqueuePopstateEvent(m_pendingStateObject ? m_pendingStateObject.release() : SerializedScriptValue::nullValue()); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 2512 | |
beidson@apple.com | 2626514 | 2008-04-23 00:13:31 +0000 | [diff] [blame] | 2513 | if (f) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2514 | f->loader()->handledOnloadEvents(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2515 | #ifdef INSTRUMENT_LAYOUT_SCHEDULING |
| 2516 | if (!ownerElement()) |
| 2517 | printf("onload fired at %d\n", elapsedTime()); |
| 2518 | #endif |
| 2519 | |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 2520 | // An event handler may have removed the frame |
commit-queue@webkit.org | 2b7d692 | 2012-04-05 04:22:50 +0000 | [diff] [blame] | 2521 | if (!frame()) { |
| 2522 | m_processingLoadEvent = false; |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 2523 | return; |
commit-queue@webkit.org | 2b7d692 | 2012-04-05 04:22:50 +0000 | [diff] [blame] | 2524 | } |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 2525 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2526 | // Make sure both the initial layout and reflow happen after the onload |
| 2527 | // fires. This will improve onload scores, and other browsers do it. |
| 2528 | // If they wanna cheat, we can too. -dwh |
| 2529 | |
abarth@webkit.org | 88b4e6b | 2010-10-04 22:09:57 +0000 | [diff] [blame] | 2530 | if (frame()->navigationScheduler()->locationChangePending() && elapsedTime() < cLayoutScheduleThreshold) { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2531 | // Just bail out. Before or during the onload we were shifted to another page. |
| 2532 | // The old i-Bench suite does this. When this happens don't bother painting or laying out. |
commit-queue@webkit.org | 2b7d692 | 2012-04-05 04:22:50 +0000 | [diff] [blame] | 2533 | m_processingLoadEvent = false; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2534 | view()->unscheduleRelayout(); |
| 2535 | return; |
| 2536 | } |
| 2537 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 2538 | frame()->loader()->checkCallImplicitClose(); |
cfleizach@apple.com | 21657b6 | 2009-07-07 19:05:45 +0000 | [diff] [blame] | 2539 | RenderObject* renderObject = renderer(); |
| 2540 | |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 2541 | // We used to force a synchronous display and flush here. This really isn't |
| 2542 | // necessary and can in fact be actively harmful if pages are loading at a rate of > 60fps |
| 2543 | // (if your platform is syncing flushes and limiting them to 60fps). |
| 2544 | m_overMinimumLayoutThreshold = true; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2545 | if (!ownerElement() || (ownerElement()->renderer() && !ownerElement()->renderer()->needsLayout())) { |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 2546 | updateStyleIfNeeded(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2547 | |
| 2548 | // Always do a layout after loading if needed. |
cfleizach@apple.com | 21657b6 | 2009-07-07 19:05:45 +0000 | [diff] [blame] | 2549 | if (view() && renderObject && (!renderObject->firstChild() || renderObject->needsLayout())) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2550 | view()->layout(); |
| 2551 | } |
hyatt | 72907f4 | 2006-10-17 08:52:26 +0000 | [diff] [blame] | 2552 | |
commit-queue@webkit.org | 2b7d692 | 2012-04-05 04:22:50 +0000 | [diff] [blame] | 2553 | m_processingLoadEvent = false; |
| 2554 | |
commit-queue@webkit.org | 666227b | 2010-09-24 07:51:48 +0000 | [diff] [blame] | 2555 | #if PLATFORM(MAC) || PLATFORM(CHROMIUM) |
pkasting@chromium.org | 0921df4 | 2011-11-18 01:28:56 +0000 | [diff] [blame] | 2556 | if (f && renderObject && AXObjectCache::accessibilityEnabled()) { |
cfleizach@apple.com | 21657b6 | 2009-07-07 19:05:45 +0000 | [diff] [blame] | 2557 | // The AX cache may have been cleared at this point, but we need to make sure it contains an |
| 2558 | // AX object to send the notification to. getOrCreate will make sure that an valid AX object |
| 2559 | // exists in the cache (we ignore the return value because we don't need it here). This is |
| 2560 | // only safe to call when a layout is not in progress, so it can not be used in postNotification. |
| 2561 | axObjectCache()->getOrCreate(renderObject); |
pkasting@chromium.org | 0921df4 | 2011-11-18 01:28:56 +0000 | [diff] [blame] | 2562 | if (this == topDocument()) |
| 2563 | axObjectCache()->postNotification(renderObject, AXObjectCache::AXLoadComplete, true); |
| 2564 | else { |
| 2565 | // AXLoadComplete can only be posted on the top document, so if it's a document |
dmazzoni@google.com | 709c0b0 | 2011-12-15 04:40:50 +0000 | [diff] [blame] | 2566 | // in an iframe that just finished loading, post AXLayoutComplete instead. |
| 2567 | axObjectCache()->postNotification(renderObject, AXObjectCache::AXLayoutComplete, true); |
pkasting@chromium.org | 0921df4 | 2011-11-18 01:28:56 +0000 | [diff] [blame] | 2568 | } |
cfleizach@apple.com | 4c5c29c | 2009-07-24 00:35:28 +0000 | [diff] [blame] | 2569 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2570 | #endif |
| 2571 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 2572 | #if ENABLE(SVG) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2573 | if (svgExtensions()) |
eseidel | 4e52462 | 2006-05-31 17:25:30 +0000 | [diff] [blame] | 2574 | accessSVGExtensions()->startAnimations(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2575 | #endif |
| 2576 | } |
| 2577 | |
| 2578 | void Document::setParsing(bool b) |
| 2579 | { |
| 2580 | m_bParsing = b; |
| 2581 | if (!m_bParsing && view()) |
| 2582 | view()->scheduleRelayout(); |
| 2583 | |
| 2584 | #ifdef INSTRUMENT_LAYOUT_SCHEDULING |
| 2585 | if (!ownerElement() && !m_bParsing) |
| 2586 | printf("Parsing finished at %d\n", elapsedTime()); |
| 2587 | #endif |
| 2588 | } |
| 2589 | |
| 2590 | bool Document::shouldScheduleLayout() |
| 2591 | { |
darin@apple.com | 8bf1fe0 | 2008-11-10 17:06:04 +0000 | [diff] [blame] | 2592 | // This function will only be called when FrameView thinks a layout is needed. |
| 2593 | // This enforces a couple extra rules. |
| 2594 | // |
| 2595 | // (a) Only schedule a layout once the stylesheets are loaded. |
| 2596 | // (b) Only schedule layout once we have a body element. |
| 2597 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 2598 | return (haveStylesheetsLoaded() && body()) |
| 2599 | || (documentElement() && !documentElement()->hasTagName(htmlTag)); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2600 | } |
tonyg@chromium.org | 991ea59 | 2011-02-26 11:20:11 +0000 | [diff] [blame] | 2601 | |
| 2602 | bool Document::isLayoutTimerActive() |
| 2603 | { |
steveblock@google.com | e1919eb | 2011-09-01 12:37:04 +0000 | [diff] [blame] | 2604 | return view() && view()->layoutPending() && !minimumLayoutDelay(); |
tonyg@chromium.org | 991ea59 | 2011-02-26 11:20:11 +0000 | [diff] [blame] | 2605 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2606 | |
| 2607 | int Document::minimumLayoutDelay() |
| 2608 | { |
| 2609 | if (m_overMinimumLayoutThreshold) |
steveblock@google.com | e1919eb | 2011-09-01 12:37:04 +0000 | [diff] [blame] | 2610 | return 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2611 | |
| 2612 | int elapsed = elapsedTime(); |
| 2613 | m_overMinimumLayoutThreshold = elapsed > cLayoutScheduleThreshold; |
| 2614 | |
| 2615 | // We'll want to schedule the timer to fire at the minimum layout threshold. |
steveblock@google.com | e1919eb | 2011-09-01 12:37:04 +0000 | [diff] [blame] | 2616 | return max(0, cLayoutScheduleThreshold - elapsed); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | int Document::elapsedTime() const |
| 2620 | { |
| 2621 | return static_cast<int>((currentTime() - m_startTime) * 1000); |
| 2622 | } |
| 2623 | |
treat@webkit.org | 2155329 | 2009-02-13 21:01:31 +0000 | [diff] [blame] | 2624 | void Document::write(const SegmentedString& text, Document* ownerDocument) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2625 | { |
commit-queue@webkit.org | b7b2b52 | 2011-02-02 00:22:52 +0000 | [diff] [blame] | 2626 | NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth); |
| 2627 | |
| 2628 | m_writeRecursionIsTooDeep = (m_writeRecursionDepth > 1) && m_writeRecursionIsTooDeep; |
| 2629 | m_writeRecursionIsTooDeep = (m_writeRecursionDepth > cMaxWriteRecursionDepth) || m_writeRecursionIsTooDeep; |
| 2630 | |
| 2631 | if (m_writeRecursionIsTooDeep) |
| 2632 | return; |
| 2633 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2634 | #ifdef INSTRUMENT_LAYOUT_SCHEDULING |
| 2635 | if (!ownerElement()) |
| 2636 | printf("Beginning a document.write at %d\n", elapsedTime()); |
| 2637 | #endif |
darin@apple.com | eeec127 | 2009-02-13 16:20:16 +0000 | [diff] [blame] | 2638 | |
abarth@webkit.org | 8a828c1 | 2010-07-23 22:14:02 +0000 | [diff] [blame] | 2639 | bool hasInsertionPoint = m_parser && m_parser->hasInsertionPoint(); |
tonyg@chromium.org | 8500eb8 | 2010-10-22 01:27:27 +0000 | [diff] [blame] | 2640 | if (!hasInsertionPoint && m_ignoreDestructiveWriteCount) |
abarth@webkit.org | 8a828c1 | 2010-07-23 22:14:02 +0000 | [diff] [blame] | 2641 | return; |
| 2642 | |
| 2643 | if (!hasInsertionPoint) |
treat@webkit.org | 2155329 | 2009-02-13 21:01:31 +0000 | [diff] [blame] | 2644 | open(ownerDocument); |
treat@webkit.org | 2155329 | 2009-02-13 21:01:31 +0000 | [diff] [blame] | 2645 | |
abarth@webkit.org | 5d72ad2 | 2010-06-14 04:40:20 +0000 | [diff] [blame] | 2646 | ASSERT(m_parser); |
eric@webkit.org | 5cfd556 | 2010-06-25 21:37:08 +0000 | [diff] [blame] | 2647 | m_parser->insert(text); |
ap@apple.com | 97b0fe7 | 2010-05-14 20:32:08 +0000 | [diff] [blame] | 2648 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2649 | #ifdef INSTRUMENT_LAYOUT_SCHEDULING |
| 2650 | if (!ownerElement()) |
| 2651 | printf("Ending a document.write at %d\n", elapsedTime()); |
ap@webkit.org | a0a1987 | 2008-02-05 09:34:18 +0000 | [diff] [blame] | 2652 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2653 | } |
| 2654 | |
treat@webkit.org | 2155329 | 2009-02-13 21:01:31 +0000 | [diff] [blame] | 2655 | void Document::write(const String& text, Document* ownerDocument) |
| 2656 | { |
| 2657 | write(SegmentedString(text), ownerDocument); |
| 2658 | } |
| 2659 | |
abarth@webkit.org | bf2c13a | 2008-06-12 06:41:53 +0000 | [diff] [blame] | 2660 | void Document::writeln(const String& text, Document* ownerDocument) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2661 | { |
abarth@webkit.org | bf2c13a | 2008-06-12 06:41:53 +0000 | [diff] [blame] | 2662 | write(text, ownerDocument); |
| 2663 | write("\n", ownerDocument); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
ap@webkit.org | be35d51 | 2008-10-31 09:44:03 +0000 | [diff] [blame] | 2666 | const KURL& Document::virtualURL() const |
| 2667 | { |
| 2668 | return m_url; |
| 2669 | } |
| 2670 | |
jchaffraix@webkit.org | 715c47a | 2008-12-23 19:01:12 +0000 | [diff] [blame] | 2671 | KURL Document::virtualCompleteURL(const String& url) const |
| 2672 | { |
| 2673 | return completeURL(url); |
| 2674 | } |
| 2675 | |
kbr@google.com | 7bf42ee | 2011-02-15 22:53:44 +0000 | [diff] [blame] | 2676 | double Document::minimumTimerInterval() const |
| 2677 | { |
| 2678 | Page* p = page(); |
| 2679 | if (!p) |
| 2680 | return ScriptExecutionContext::minimumTimerInterval(); |
| 2681 | return p->settings()->minDOMTimerInterval(); |
| 2682 | } |
| 2683 | |
yurys@chromium.org | c8a06eb | 2011-01-20 09:28:54 +0000 | [diff] [blame] | 2684 | EventTarget* Document::errorEventTarget() |
| 2685 | { |
| 2686 | return domWindow(); |
| 2687 | } |
| 2688 | |
vsevik@chromium.org | 0c3bdd9 | 2012-01-12 10:56:52 +0000 | [diff] [blame] | 2689 | void Document::logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, PassRefPtr<ScriptCallStack> callStack) |
yurys@chromium.org | c8a06eb | 2011-01-20 09:28:54 +0000 | [diff] [blame] | 2690 | { |
vsevik@chromium.org | 0c3bdd9 | 2012-01-12 10:56:52 +0000 | [diff] [blame] | 2691 | addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, errorMessage, sourceURL, lineNumber, callStack); |
yurys@chromium.org | c8a06eb | 2011-01-20 09:28:54 +0000 | [diff] [blame] | 2692 | } |
| 2693 | |
darin@apple.com | 640fa30 | 2008-02-15 05:03:55 +0000 | [diff] [blame] | 2694 | void Document::setURL(const KURL& url) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2695 | { |
abarth@webkit.org | 86d0445 | 2008-06-16 04:42:51 +0000 | [diff] [blame] | 2696 | const KURL& newURL = url.isEmpty() ? blankURL() : url; |
| 2697 | if (newURL == m_url) |
kmccullo | adfd67d | 2007-03-03 02:18:43 +0000 | [diff] [blame] | 2698 | return; |
| 2699 | |
abarth@webkit.org | 86d0445 | 2008-06-16 04:42:51 +0000 | [diff] [blame] | 2700 | m_url = newURL; |
abarth@webkit.org | 761e100 | 2008-06-16 04:43:06 +0000 | [diff] [blame] | 2701 | m_documentURI = m_url.string(); |
abarth@webkit.org | 86d0445 | 2008-06-16 04:42:51 +0000 | [diff] [blame] | 2702 | updateBaseURL(); |
morrita@google.com | 71ae039 | 2012-07-09 08:53:48 +0000 | [diff] [blame] | 2703 | contextFeatures()->urlDidChange(this); |
abarth@webkit.org | 86d0445 | 2008-06-16 04:42:51 +0000 | [diff] [blame] | 2704 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2705 | |
abarth@webkit.org | 86d0445 | 2008-06-16 04:42:51 +0000 | [diff] [blame] | 2706 | void Document::updateBaseURL() |
| 2707 | { |
antti@apple.com | f89be04 | 2011-12-12 18:56:20 +0000 | [diff] [blame] | 2708 | KURL oldBaseURL = m_baseURL; |
ap@webkit.org | 3db1ca1 | 2009-01-26 06:42:30 +0000 | [diff] [blame] | 2709 | // DOM 3 Core: When the Document supports the feature "HTML" [DOM Level 2 HTML], the base URI is computed using |
| 2710 | // first the value of the href attribute of the HTML BASE element if any, and the value of the documentURI attribute |
| 2711 | // from the Document interface otherwise. |
jcivelli@chromium.org | 5de7131 | 2011-11-17 03:08:21 +0000 | [diff] [blame] | 2712 | if (!m_baseElementURL.isEmpty()) |
| 2713 | m_baseURL = m_baseElementURL; |
| 2714 | else if (!m_baseURLOverride.isEmpty()) |
| 2715 | m_baseURL = m_baseURLOverride; |
| 2716 | else { |
commit-queue@webkit.org | 4ef9053 | 2012-06-12 18:02:56 +0000 | [diff] [blame] | 2717 | // The documentURI attribute is read-only from JavaScript, but writable from Objective C, so we need to retain |
| 2718 | // this fallback behavior. We use a null base URL, since the documentURI attribute is an arbitrary string |
| 2719 | // and DOM 3 Core does not specify how it should be resolved. |
ap@webkit.org | 3db1ca1 | 2009-01-26 06:42:30 +0000 | [diff] [blame] | 2720 | m_baseURL = KURL(KURL(), documentURI()); |
jcivelli@chromium.org | 5de7131 | 2011-11-17 03:08:21 +0000 | [diff] [blame] | 2721 | } |
haraken@chromium.org | 3981f52 | 2012-06-02 19:23:25 +0000 | [diff] [blame] | 2722 | selectorQueryCache()->invalidate(); |
jcivelli@chromium.org | 5de7131 | 2011-11-17 03:08:21 +0000 | [diff] [blame] | 2723 | |
abarth@webkit.org | 761e100 | 2008-06-16 04:43:06 +0000 | [diff] [blame] | 2724 | if (!m_baseURL.isValid()) |
| 2725 | m_baseURL = KURL(); |
abarth@webkit.org | 86d0445 | 2008-06-16 04:42:51 +0000 | [diff] [blame] | 2726 | |
antti@apple.com | fe126eb | 2012-04-25 22:42:47 +0000 | [diff] [blame] | 2727 | if (m_elemSheet) { |
| 2728 | // Element sheet is silly. It never contains anything. |
antti@apple.com | 384e66f | 2012-05-23 17:17:43 +0000 | [diff] [blame] | 2729 | ASSERT(!m_elemSheet->contents()->ruleCount()); |
| 2730 | bool usesRemUnits = m_elemSheet->contents()->usesRemUnits(); |
antti@apple.com | fe126eb | 2012-04-25 22:42:47 +0000 | [diff] [blame] | 2731 | m_elemSheet = CSSStyleSheet::createInline(this, m_baseURL); |
| 2732 | // FIXME: So we are not really the parser. The right fix is to eliminate the element sheet completely. |
antti@apple.com | 384e66f | 2012-05-23 17:17:43 +0000 | [diff] [blame] | 2733 | m_elemSheet->contents()->parserSetUsesRemUnits(usesRemUnits); |
antti@apple.com | fe126eb | 2012-04-25 22:42:47 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
antti@apple.com | f89be04 | 2011-12-12 18:56:20 +0000 | [diff] [blame] | 2736 | if (!equalIgnoringFragmentIdentifier(oldBaseURL, m_baseURL)) { |
| 2737 | // Base URL change changes any relative visited links. |
| 2738 | // FIXME: There are other URLs in the tree that would need to be re-evaluated on dynamic base URL change. Style should be invalidated too. |
| 2739 | for (Node* node = firstChild(); node; node = node->traverseNextNode()) { |
| 2740 | if (node->hasTagName(aTag)) |
| 2741 | static_cast<HTMLAnchorElement*>(node)->invalidateCachedVisitedLinkHash(); |
| 2742 | } |
| 2743 | } |
weinig | d1f53f0 | 2007-02-20 01:22:06 +0000 | [diff] [blame] | 2744 | } |
| 2745 | |
jcivelli@chromium.org | 5de7131 | 2011-11-17 03:08:21 +0000 | [diff] [blame] | 2746 | void Document::setBaseURLOverride(const KURL& url) |
| 2747 | { |
| 2748 | m_baseURLOverride = url; |
| 2749 | updateBaseURL(); |
| 2750 | } |
| 2751 | |
darin@apple.com | 17c2d2c | 2010-08-29 05:48:44 +0000 | [diff] [blame] | 2752 | void Document::processBaseElement() |
| 2753 | { |
| 2754 | // Find the first href attribute in a base element and the first target attribute in a base element. |
| 2755 | const AtomicString* href = 0; |
| 2756 | const AtomicString* target = 0; |
| 2757 | for (Node* node = document()->firstChild(); node && (!href || !target); node = node->traverseNextNode()) { |
| 2758 | if (node->hasTagName(baseTag)) { |
| 2759 | if (!href) { |
| 2760 | const AtomicString& value = static_cast<Element*>(node)->fastGetAttribute(hrefAttr); |
| 2761 | if (!value.isNull()) |
| 2762 | href = &value; |
| 2763 | } |
| 2764 | if (!target) { |
| 2765 | const AtomicString& value = static_cast<Element*>(node)->fastGetAttribute(targetAttr); |
| 2766 | if (!value.isNull()) |
| 2767 | target = &value; |
| 2768 | } |
| 2769 | } |
| 2770 | } |
| 2771 | |
| 2772 | // FIXME: Since this doesn't share code with completeURL it may not handle encodings correctly. |
| 2773 | KURL baseElementURL; |
| 2774 | if (href) { |
darin@apple.com | 7b7981b | 2010-10-01 00:04:02 +0000 | [diff] [blame] | 2775 | String strippedHref = stripLeadingAndTrailingHTMLSpaces(*href); |
abarth@webkit.org | fb50fc9 | 2011-02-05 22:55:14 +0000 | [diff] [blame] | 2776 | if (!strippedHref.isEmpty()) |
darin@apple.com | 17c2d2c | 2010-08-29 05:48:44 +0000 | [diff] [blame] | 2777 | baseElementURL = KURL(url(), strippedHref); |
| 2778 | } |
| 2779 | if (m_baseElementURL != baseElementURL) { |
| 2780 | m_baseElementURL = baseElementURL; |
| 2781 | updateBaseURL(); |
| 2782 | } |
| 2783 | |
| 2784 | m_baseTarget = target ? *target : nullAtom; |
| 2785 | } |
| 2786 | |
dimich@chromium.org | 5f1b3fe | 2009-02-20 07:23:00 +0000 | [diff] [blame] | 2787 | String Document::userAgent(const KURL& url) const |
| 2788 | { |
| 2789 | return frame() ? frame()->loader()->userAgent(url) : String(); |
| 2790 | } |
| 2791 | |
commit-queue@webkit.org | 7415e10 | 2012-09-14 23:33:20 +0000 | [diff] [blame] | 2792 | void Document::disableEval(const String& errorMessage) |
weinig@apple.com | 76f3d93 | 2011-10-05 00:52:50 +0000 | [diff] [blame] | 2793 | { |
| 2794 | if (!frame()) |
| 2795 | return; |
| 2796 | |
commit-queue@webkit.org | 7415e10 | 2012-09-14 23:33:20 +0000 | [diff] [blame] | 2797 | frame()->script()->disableEval(errorMessage); |
weinig@apple.com | 76f3d93 | 2011-10-05 00:52:50 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2800 | bool Document::canNavigate(Frame* targetFrame) |
| 2801 | { |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2802 | if (!m_frame) |
| 2803 | return false; |
| 2804 | |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 2805 | // FIXME: We shouldn't call this function without a target frame, but |
| 2806 | // fast/forms/submit-to-blank-multiple-times.html depends on this function |
| 2807 | // returning true when supplied with a 0 targetFrame. |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2808 | if (!targetFrame) |
| 2809 | return true; |
| 2810 | |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 2811 | // Frame-busting is generally allowed (unless we're sandboxed and prevent from frame-busting). |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2812 | if (!isSandboxed(SandboxTopNavigation) && targetFrame == m_frame->tree()->top()) |
| 2813 | return true; |
| 2814 | |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 2815 | if (isSandboxed(SandboxNavigation)) { |
| 2816 | if (targetFrame->tree()->isDescendantOf(m_frame)) |
| 2817 | return true; |
| 2818 | |
| 2819 | printNavigationErrorMessage(targetFrame, url()); |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2820 | return false; |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 2821 | } |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2822 | |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 2823 | // This is the normal case. A document can navigate its decendant frames, |
| 2824 | // or, more generally, a document can navigate a frame if the document is |
| 2825 | // in the same origin as any of that frame's ancestors (in the frame |
| 2826 | // hierarchy). |
| 2827 | // |
| 2828 | // See http://www.adambarth.com/papers/2008/barth-jackson-mitchell.pdf for |
| 2829 | // historical information about this security check. |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2830 | if (canAccessAncestor(securityOrigin(), targetFrame)) |
| 2831 | return true; |
| 2832 | |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 2833 | // Top-level frames are easier to navigate than other frames because they |
| 2834 | // display their URLs in the address bar (in most browsers). However, there |
| 2835 | // are still some restrictions on navigation to avoid nuisance attacks. |
| 2836 | // Specifically, a document can navigate a top-level frame if that frame |
| 2837 | // opened the document or if the document is the same-origin with any of |
| 2838 | // the top-level frame's opener's ancestors (in the frame hierarchy). |
| 2839 | // |
| 2840 | // In both of these cases, the document performing the navigation is in |
| 2841 | // some way related to the frame being navigate (e.g., by the "opener" |
| 2842 | // and/or "parent" relation). Requiring some sort of relation prevents a |
| 2843 | // document from navigating arbitrary, unrelated top-level frames. |
| 2844 | if (!targetFrame->tree()->parent()) { |
| 2845 | if (targetFrame == m_frame->loader()->opener()) |
| 2846 | return true; |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2847 | |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 2848 | if (canAccessAncestor(securityOrigin(), targetFrame->loader()->opener())) |
| 2849 | return true; |
| 2850 | } |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2851 | |
abarth@webkit.org | 0f97abe | 2012-04-02 02:43:17 +0000 | [diff] [blame] | 2852 | printNavigationErrorMessage(targetFrame, url()); |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 2853 | return false; |
| 2854 | } |
| 2855 | |
tsepez@chromium.org | 8d3c2c1 | 2012-04-17 19:03:42 +0000 | [diff] [blame] | 2856 | Frame* Document::findUnsafeParentScrollPropagationBoundary() |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 2857 | { |
tsepez@chromium.org | 8d3c2c1 | 2012-04-17 19:03:42 +0000 | [diff] [blame] | 2858 | Frame* currentFrame = m_frame; |
| 2859 | Frame* ancestorFrame = currentFrame->tree()->parent(); |
| 2860 | |
| 2861 | while (ancestorFrame) { |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 2862 | if (!ancestorFrame->document()->securityOrigin()->canAccess(securityOrigin())) |
tsepez@chromium.org | 8d3c2c1 | 2012-04-17 19:03:42 +0000 | [diff] [blame] | 2863 | return currentFrame; |
| 2864 | currentFrame = ancestorFrame; |
| 2865 | ancestorFrame = ancestorFrame->tree()->parent(); |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 2866 | } |
tsepez@chromium.org | 8d3c2c1 | 2012-04-17 19:03:42 +0000 | [diff] [blame] | 2867 | return 0; |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
mihaip@chromium.org | 5605116 | 2011-07-27 18:34:07 +0000 | [diff] [blame] | 2870 | |
eric@webkit.org | 876b40e | 2012-05-09 00:52:08 +0000 | [diff] [blame] | 2871 | void Document::seamlessParentUpdatedStylesheets() |
| 2872 | { |
| 2873 | styleResolverChanged(RecalcStyleImmediately); |
| 2874 | } |
| 2875 | |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 2876 | void Document::didRemoveAllPendingStylesheet() |
| 2877 | { |
| 2878 | m_needsNotifyRemoveAllPendingStylesheet = false; |
| 2879 | |
| 2880 | styleResolverChanged(RecalcStyleIfNeeded); |
| 2881 | |
| 2882 | if (ScriptableDocumentParser* parser = scriptableDocumentParser()) |
| 2883 | parser->executeScriptsWaitingForStylesheets(); |
| 2884 | |
| 2885 | if (m_gotoAnchorNeededAfterStylesheetsLoad && view()) |
| 2886 | view()->scrollToFragment(m_url); |
| 2887 | } |
| 2888 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2889 | CSSStyleSheet* Document::elementSheet() |
| 2890 | { |
| 2891 | if (!m_elemSheet) |
antti@apple.com | fe126eb | 2012-04-25 22:42:47 +0000 | [diff] [blame] | 2892 | m_elemSheet = CSSStyleSheet::createInline(this, m_baseURL); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2893 | return m_elemSheet.get(); |
| 2894 | } |
| 2895 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2896 | int Document::nodeAbsIndex(Node *node) |
| 2897 | { |
ggaren | f9f32ae | 2007-03-26 20:08:53 +0000 | [diff] [blame] | 2898 | ASSERT(node->document() == this); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2899 | |
| 2900 | int absIndex = 0; |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 2901 | for (Node* n = node; n && n != this; n = n->traversePreviousNode()) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2902 | absIndex++; |
| 2903 | return absIndex; |
| 2904 | } |
| 2905 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 2906 | Node* Document::nodeWithAbsIndex(int absIndex) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2907 | { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 2908 | Node* n = this; |
| 2909 | for (int i = 0; n && (i < absIndex); i++) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2910 | n = n->traverseNextNode(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2911 | return n; |
| 2912 | } |
| 2913 | |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 2914 | void Document::processHttpEquiv(const String& equiv, const String& content) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2915 | { |
ggaren | f9f32ae | 2007-03-26 20:08:53 +0000 | [diff] [blame] | 2916 | ASSERT(!equiv.isNull() && !content.isNull()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2917 | |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 2918 | Frame* frame = this->frame(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2919 | |
| 2920 | if (equalIgnoringCase(equiv, "default-style")) { |
| 2921 | // The preferred style set has been overridden as per section |
| 2922 | // 14.3.2 of the HTML4.0 specification. We need to update the |
| 2923 | // sheet used variable and then update our style selector. |
| 2924 | // For more info, see the test at: |
| 2925 | // http://www.hixie.ch/tests/evil/css/import/main/preferred.html |
| 2926 | // -dwh |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 2927 | m_styleSheetCollection->setSelectedStylesheetSetName(content); |
| 2928 | m_styleSheetCollection->setPreferredStylesheetSetName(content); |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 2929 | styleResolverChanged(DeferRecalcStyle); |
eseidel | cff0a72 | 2006-03-22 22:27:45 +0000 | [diff] [blame] | 2930 | } else if (equalIgnoringCase(equiv, "refresh")) { |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 2931 | double delay; |
| 2932 | String url; |
ap | e74d7f9 | 2007-02-18 12:48:44 +0000 | [diff] [blame] | 2933 | if (frame && parseHTTPRefresh(content, true, delay, url)) { |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 2934 | if (url.isEmpty()) |
japhet@chromium.org | 5a15274 | 2011-01-28 01:22:16 +0000 | [diff] [blame] | 2935 | url = m_url.string(); |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 2936 | else |
darin@apple.com | 640fa30 | 2008-02-15 05:03:55 +0000 | [diff] [blame] | 2937 | url = completeURL(url).string(); |
abarth@webkit.org | 88b4e6b | 2010-10-04 22:09:57 +0000 | [diff] [blame] | 2938 | frame->navigationScheduler()->scheduleRedirect(delay, url); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2939 | } |
eseidel | cff0a72 | 2006-03-22 22:27:45 +0000 | [diff] [blame] | 2940 | } else if (equalIgnoringCase(equiv, "set-cookie")) { |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2941 | // FIXME: make setCookie work on XML documents too; e.g. in case of <html:meta .....> |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 2942 | if (isHTMLDocument()) { |
| 2943 | ExceptionCode ec; // Exception (for sandboxed documents) ignored. |
| 2944 | static_cast<HTMLDocument*>(this)->setCookie(content, ec); |
| 2945 | } |
eric@webkit.org | 1658b66 | 2008-01-09 09:23:16 +0000 | [diff] [blame] | 2946 | } else if (equalIgnoringCase(equiv, "content-language")) |
| 2947 | setContentLanguage(content); |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 2948 | else if (equalIgnoringCase(equiv, "x-dns-prefetch-control")) |
| 2949 | parseDNSPrefetchControlHeader(content); |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 2950 | else if (equalIgnoringCase(equiv, "x-frame-options")) { |
tonyg@chromium.org | 254d90f | 2010-09-16 16:12:23 +0000 | [diff] [blame] | 2951 | if (frame) { |
| 2952 | FrameLoader* frameLoader = frame->loader(); |
| 2953 | if (frameLoader->shouldInterruptLoadForXFrameOptions(content, url())) { |
| 2954 | frameLoader->stopAllLoaders(); |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 2955 | frame->navigationScheduler()->scheduleLocationChange(securityOrigin(), blankURL(), String()); |
eric@webkit.org | c3ee4d0 | 2010-05-15 09:10:44 +0000 | [diff] [blame] | 2956 | |
abarth@webkit.org | f6d1b8c | 2012-08-29 07:38:10 +0000 | [diff] [blame] | 2957 | DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to display document because display forbidden by X-Frame-Options.\n"))); |
abarth@webkit.org | 0ed3277 | 2011-11-08 00:57:10 +0000 | [diff] [blame] | 2958 | addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, consoleMessage); |
tonyg@chromium.org | 254d90f | 2010-09-16 16:12:23 +0000 | [diff] [blame] | 2959 | } |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 2960 | } |
abarth@webkit.org | 3285b43b | 2011-04-07 10:04:22 +0000 | [diff] [blame] | 2961 | } else if (equalIgnoringCase(equiv, "x-webkit-csp")) |
abarth@webkit.org | bd0c775 | 2011-05-07 02:13:06 +0000 | [diff] [blame] | 2962 | contentSecurityPolicy()->didReceiveHeader(content, ContentSecurityPolicy::EnforcePolicy); |
| 2963 | else if (equalIgnoringCase(equiv, "x-webkit-csp-report-only")) |
| 2964 | contentSecurityPolicy()->didReceiveHeader(content, ContentSecurityPolicy::ReportOnly); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
dbates@webkit.org | f6460f9 | 2010-04-17 04:40:14 +0000 | [diff] [blame] | 2967 | // Though isspace() considers \t and \v to be whitespace, Win IE doesn't. |
| 2968 | static bool isSeparator(UChar c) |
| 2969 | { |
| 2970 | return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '=' || c == ',' || c == '\0'; |
| 2971 | } |
| 2972 | |
| 2973 | void Document::processArguments(const String& features, void* data, ArgumentsCallback callback) |
| 2974 | { |
| 2975 | // Tread lightly in this code -- it was specifically designed to mimic Win IE's parsing behavior. |
| 2976 | int keyBegin, keyEnd; |
| 2977 | int valueBegin, valueEnd; |
| 2978 | |
| 2979 | int i = 0; |
| 2980 | int length = features.length(); |
| 2981 | String buffer = features.lower(); |
| 2982 | while (i < length) { |
| 2983 | // skip to first non-separator, but don't skip past the end of the string |
| 2984 | while (isSeparator(buffer[i])) { |
| 2985 | if (i >= length) |
| 2986 | break; |
| 2987 | i++; |
| 2988 | } |
| 2989 | keyBegin = i; |
| 2990 | |
| 2991 | // skip to first separator |
| 2992 | while (!isSeparator(buffer[i])) |
| 2993 | i++; |
| 2994 | keyEnd = i; |
| 2995 | |
| 2996 | // skip to first '=', but don't skip past a ',' or the end of the string |
| 2997 | while (buffer[i] != '=') { |
| 2998 | if (buffer[i] == ',' || i >= length) |
| 2999 | break; |
| 3000 | i++; |
| 3001 | } |
| 3002 | |
| 3003 | // skip to first non-separator, but don't skip past a ',' or the end of the string |
| 3004 | while (isSeparator(buffer[i])) { |
| 3005 | if (buffer[i] == ',' || i >= length) |
| 3006 | break; |
| 3007 | i++; |
| 3008 | } |
| 3009 | valueBegin = i; |
| 3010 | |
| 3011 | // skip to first separator |
| 3012 | while (!isSeparator(buffer[i])) |
| 3013 | i++; |
| 3014 | valueEnd = i; |
| 3015 | |
| 3016 | ASSERT(i <= length); |
| 3017 | |
| 3018 | String keyString = buffer.substring(keyBegin, keyEnd - keyBegin); |
| 3019 | String valueString = buffer.substring(valueBegin, valueEnd - valueBegin); |
| 3020 | callback(keyString, valueString, this, data); |
| 3021 | } |
| 3022 | } |
| 3023 | |
commit-queue@webkit.org | 36e5ae1 | 2012-06-01 18:24:02 +0000 | [diff] [blame] | 3024 | void Document::processViewport(const String& features, ViewportArguments::Type origin) |
dbates@webkit.org | f6460f9 | 2010-04-17 04:40:14 +0000 | [diff] [blame] | 3025 | { |
| 3026 | ASSERT(!features.isNull()); |
| 3027 | |
commit-queue@webkit.org | 36e5ae1 | 2012-06-01 18:24:02 +0000 | [diff] [blame] | 3028 | if (origin < m_viewportArguments.type) |
| 3029 | return; |
| 3030 | |
| 3031 | m_viewportArguments = ViewportArguments(origin); |
luiz@webkit.org | e0514c5 | 2010-09-24 21:54:25 +0000 | [diff] [blame] | 3032 | processArguments(features, (void*)&m_viewportArguments, &setViewportFeature); |
| 3033 | |
wangxianzhu@chromium.org | 8a6966f | 2012-02-07 04:16:50 +0000 | [diff] [blame] | 3034 | updateViewportArguments(); |
| 3035 | } |
dbates@webkit.org | f6460f9 | 2010-04-17 04:40:14 +0000 | [diff] [blame] | 3036 | |
wangxianzhu@chromium.org | 8a6966f | 2012-02-07 04:16:50 +0000 | [diff] [blame] | 3037 | void Document::updateViewportArguments() |
| 3038 | { |
commit-queue@webkit.org | 7adcbd8 | 2012-05-02 13:00:47 +0000 | [diff] [blame] | 3039 | if (page() && page()->mainFrame() == frame()) { |
| 3040 | #ifndef NDEBUG |
| 3041 | m_didDispatchViewportPropertiesChanged = true; |
| 3042 | #endif |
wangxianzhu@chromium.org | 8a6966f | 2012-02-07 04:16:50 +0000 | [diff] [blame] | 3043 | page()->chrome()->dispatchViewportPropertiesDidChange(m_viewportArguments); |
commit-queue@webkit.org | 7adcbd8 | 2012-05-02 13:00:47 +0000 | [diff] [blame] | 3044 | } |
dbates@webkit.org | f6460f9 | 2010-04-17 04:40:14 +0000 | [diff] [blame] | 3045 | } |
| 3046 | |
jochen@chromium.org | 4761ef5 | 2011-11-21 10:29:55 +0000 | [diff] [blame] | 3047 | void Document::processReferrerPolicy(const String& policy) |
| 3048 | { |
| 3049 | ASSERT(!policy.isNull()); |
| 3050 | |
gavinp@chromium.org | 4b82056 | 2012-04-23 12:53:24 +0000 | [diff] [blame] | 3051 | m_referrerPolicy = ReferrerPolicyDefault; |
jochen@chromium.org | 4761ef5 | 2011-11-21 10:29:55 +0000 | [diff] [blame] | 3052 | |
| 3053 | if (equalIgnoringCase(policy, "never")) |
gavinp@chromium.org | 4b82056 | 2012-04-23 12:53:24 +0000 | [diff] [blame] | 3054 | m_referrerPolicy = ReferrerPolicyNever; |
jochen@chromium.org | 4761ef5 | 2011-11-21 10:29:55 +0000 | [diff] [blame] | 3055 | else if (equalIgnoringCase(policy, "always")) |
gavinp@chromium.org | 4b82056 | 2012-04-23 12:53:24 +0000 | [diff] [blame] | 3056 | m_referrerPolicy = ReferrerPolicyAlways; |
jochen@chromium.org | 4761ef5 | 2011-11-21 10:29:55 +0000 | [diff] [blame] | 3057 | else if (equalIgnoringCase(policy, "origin")) |
gavinp@chromium.org | 4b82056 | 2012-04-23 12:53:24 +0000 | [diff] [blame] | 3058 | m_referrerPolicy = ReferrerPolicyOrigin; |
jochen@chromium.org | 4761ef5 | 2011-11-21 10:29:55 +0000 | [diff] [blame] | 3059 | } |
| 3060 | |
leviw@chromium.org | 3af1706 | 2011-08-18 00:36:48 +0000 | [diff] [blame] | 3061 | MouseEventWithHitTestResults Document::prepareMouseEvent(const HitTestRequest& request, const LayoutPoint& documentPoint, const PlatformMouseEvent& event) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3062 | { |
ggaren | a523f08 | 2006-12-19 08:04:48 +0000 | [diff] [blame] | 3063 | ASSERT(!renderer() || renderer()->isRenderView()); |
| 3064 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3065 | if (!renderer()) |
leviw@chromium.org | 3af1706 | 2011-08-18 00:36:48 +0000 | [diff] [blame] | 3066 | return MouseEventWithHitTestResults(event, HitTestResult(LayoutPoint())); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3067 | |
ggaren | a523f08 | 2006-12-19 08:04:48 +0000 | [diff] [blame] | 3068 | HitTestResult result(documentPoint); |
jchaffraix@webkit.org | 9dbf6d1 | 2012-04-12 16:02:25 +0000 | [diff] [blame] | 3069 | renderView()->hitTest(request, result); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3070 | |
treat@webkit.org | 16eda3f | 2009-02-02 20:46:48 +0000 | [diff] [blame] | 3071 | if (!request.readOnly()) |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 3072 | updateStyleIfNeeded(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3073 | |
aroben | 3e7723d | 2007-07-05 02:59:41 +0000 | [diff] [blame] | 3074 | return MouseEventWithHitTestResults(event, result); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | // DOM Section 1.1.1 |
rolandsteiner@chromium.org | 6642a95 | 2011-04-14 05:44:29 +0000 | [diff] [blame] | 3078 | bool Document::childTypeAllowed(NodeType type) const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3079 | { |
| 3080 | switch (type) { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 3081 | case ATTRIBUTE_NODE: |
| 3082 | case CDATA_SECTION_NODE: |
| 3083 | case DOCUMENT_FRAGMENT_NODE: |
| 3084 | case DOCUMENT_NODE: |
| 3085 | case ENTITY_NODE: |
| 3086 | case ENTITY_REFERENCE_NODE: |
| 3087 | case NOTATION_NODE: |
| 3088 | case TEXT_NODE: |
| 3089 | case XPATH_NAMESPACE_NODE: |
| 3090 | return false; |
| 3091 | case COMMENT_NODE: |
| 3092 | case PROCESSING_INSTRUCTION_NODE: |
| 3093 | return true; |
| 3094 | case DOCUMENT_TYPE_NODE: |
| 3095 | case ELEMENT_NODE: |
| 3096 | // Documents may contain no more than one of each of these. |
| 3097 | // (One Element and one DocumentType.) |
| 3098 | for (Node* c = firstChild(); c; c = c->nextSibling()) |
| 3099 | if (c->nodeType() == type) |
| 3100 | return false; |
| 3101 | return true; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3102 | } |
darin | 2b8671c | 2006-05-17 06:33:59 +0000 | [diff] [blame] | 3103 | return false; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
andersca | 229761c | 2007-02-12 23:24:15 +0000 | [diff] [blame] | 3106 | bool Document::canReplaceChild(Node* newChild, Node* oldChild) |
| 3107 | { |
mitz@apple.com | 4e34eca | 2007-12-03 18:09:34 +0000 | [diff] [blame] | 3108 | if (!oldChild) |
| 3109 | // ContainerNode::replaceChild will raise a NOT_FOUND_ERR. |
| 3110 | return true; |
| 3111 | |
andersca | 229761c | 2007-02-12 23:24:15 +0000 | [diff] [blame] | 3112 | if (oldChild->nodeType() == newChild->nodeType()) |
| 3113 | return true; |
| 3114 | |
| 3115 | int numDoctypes = 0; |
| 3116 | int numElements = 0; |
| 3117 | |
| 3118 | // First, check how many doctypes and elements we have, not counting |
| 3119 | // the child we're about to remove. |
| 3120 | for (Node* c = firstChild(); c; c = c->nextSibling()) { |
| 3121 | if (c == oldChild) |
| 3122 | continue; |
| 3123 | |
| 3124 | switch (c->nodeType()) { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 3125 | case DOCUMENT_TYPE_NODE: |
| 3126 | numDoctypes++; |
| 3127 | break; |
| 3128 | case ELEMENT_NODE: |
| 3129 | numElements++; |
| 3130 | break; |
| 3131 | default: |
| 3132 | break; |
andersca | 229761c | 2007-02-12 23:24:15 +0000 | [diff] [blame] | 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | // Then, see how many doctypes and elements might be added by the new child. |
| 3137 | if (newChild->nodeType() == DOCUMENT_FRAGMENT_NODE) { |
commit-queue@webkit.org | 0249dc8 | 2012-06-12 04:10:42 +0000 | [diff] [blame] | 3138 | for (Node* c = newChild->firstChild(); c; c = c->nextSibling()) { |
andersca | 229761c | 2007-02-12 23:24:15 +0000 | [diff] [blame] | 3139 | switch (c->nodeType()) { |
andersca | 229761c | 2007-02-12 23:24:15 +0000 | [diff] [blame] | 3140 | case ATTRIBUTE_NODE: |
| 3141 | case CDATA_SECTION_NODE: |
| 3142 | case DOCUMENT_FRAGMENT_NODE: |
| 3143 | case DOCUMENT_NODE: |
| 3144 | case ENTITY_NODE: |
| 3145 | case ENTITY_REFERENCE_NODE: |
| 3146 | case NOTATION_NODE: |
| 3147 | case TEXT_NODE: |
| 3148 | case XPATH_NAMESPACE_NODE: |
| 3149 | return false; |
| 3150 | case COMMENT_NODE: |
| 3151 | case PROCESSING_INSTRUCTION_NODE: |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 3152 | break; |
andersca | 229761c | 2007-02-12 23:24:15 +0000 | [diff] [blame] | 3153 | case DOCUMENT_TYPE_NODE: |
| 3154 | numDoctypes++; |
| 3155 | break; |
| 3156 | case ELEMENT_NODE: |
| 3157 | numElements++; |
| 3158 | break; |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | } else { |
| 3162 | switch (newChild->nodeType()) { |
| 3163 | case ATTRIBUTE_NODE: |
| 3164 | case CDATA_SECTION_NODE: |
| 3165 | case DOCUMENT_FRAGMENT_NODE: |
| 3166 | case DOCUMENT_NODE: |
| 3167 | case ENTITY_NODE: |
| 3168 | case ENTITY_REFERENCE_NODE: |
| 3169 | case NOTATION_NODE: |
| 3170 | case TEXT_NODE: |
| 3171 | case XPATH_NAMESPACE_NODE: |
| 3172 | return false; |
| 3173 | case COMMENT_NODE: |
| 3174 | case PROCESSING_INSTRUCTION_NODE: |
| 3175 | return true; |
| 3176 | case DOCUMENT_TYPE_NODE: |
| 3177 | numDoctypes++; |
| 3178 | break; |
| 3179 | case ELEMENT_NODE: |
| 3180 | numElements++; |
| 3181 | break; |
andersca | 229761c | 2007-02-12 23:24:15 +0000 | [diff] [blame] | 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | if (numElements > 1 || numDoctypes > 1) |
| 3186 | return false; |
| 3187 | |
| 3188 | return true; |
| 3189 | } |
| 3190 | |
morrita@google.com | 8728882 | 2012-08-31 04:27:31 +0000 | [diff] [blame] | 3191 | PassRefPtr<Node> Document::cloneNode(bool /*deep*/) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3192 | { |
| 3193 | // Spec says cloning Document nodes is "implementation dependent" |
| 3194 | // so we do not support it... |
| 3195 | return 0; |
| 3196 | } |
| 3197 | |
| 3198 | StyleSheetList* Document::styleSheets() |
| 3199 | { |
antti@apple.com | 8a2e6f0 | 2012-09-25 04:25:35 +0000 | [diff] [blame] | 3200 | if (!m_styleSheetList) |
| 3201 | m_styleSheetList = StyleSheetList::create(this); |
| 3202 | return m_styleSheetList.get(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
darin | 4a24479 | 2006-05-05 15:22:33 +0000 | [diff] [blame] | 3205 | String Document::preferredStylesheetSet() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3206 | { |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 3207 | return m_styleSheetCollection->preferredStylesheetSetName(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
darin | 4a24479 | 2006-05-05 15:22:33 +0000 | [diff] [blame] | 3210 | String Document::selectedStylesheetSet() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3211 | { |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 3212 | return m_styleSheetCollection->selectedStylesheetSetName(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | void Document::setSelectedStylesheetSet(const String& aString) |
| 3216 | { |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 3217 | m_styleSheetCollection->setSelectedStylesheetSetName(aString); |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 3218 | styleResolverChanged(DeferRecalcStyle); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
antti@apple.com | ef75e9e | 2012-04-18 18:34:42 +0000 | [diff] [blame] | 3221 | void Document::evaluateMediaQueryList() |
| 3222 | { |
| 3223 | if (m_mediaQueryMatcher) |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 3224 | m_mediaQueryMatcher->styleResolverChanged(); |
antti@apple.com | ef75e9e | 2012-04-18 18:34:42 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 3227 | void Document::styleResolverChanged(StyleResolverUpdateFlag updateFlag) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3228 | { |
ddkilzer | 27a28d4 | 2007-05-24 01:46:31 +0000 | [diff] [blame] | 3229 | // Don't bother updating, since we haven't loaded all our style info yet |
| 3230 | // and haven't calculated the style selector for the first time. |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 3231 | if (!attached() || (!m_didCalculateStyleResolver && !haveStylesheetsLoaded())) { |
| 3232 | m_styleResolver.clear(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3233 | return; |
antti@apple.com | 0396227 | 2012-01-12 20:21:51 +0000 | [diff] [blame] | 3234 | } |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 3235 | m_didCalculateStyleResolver = true; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3236 | |
| 3237 | #ifdef INSTRUMENT_LAYOUT_SCHEDULING |
| 3238 | if (!ownerElement()) |
| 3239 | printf("Beginning update of style selector at time %d.\n", elapsedTime()); |
| 3240 | #endif |
| 3241 | |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 3242 | DocumentStyleSheetCollection::UpdateFlag styleSheetUpdate = (updateFlag == RecalcStyleIfNeeded) |
| 3243 | ? DocumentStyleSheetCollection::OptimizedUpdate |
| 3244 | : DocumentStyleSheetCollection::FullUpdate; |
| 3245 | bool stylesheetChangeRequiresStyleRecalc = m_styleSheetCollection->updateActiveStyleSheets(styleSheetUpdate); |
antti@apple.com | 8f4b2d6 | 2012-01-04 20:03:35 +0000 | [diff] [blame] | 3246 | |
hyatt@apple.com | 8dd0d93 | 2010-08-26 18:17:59 +0000 | [diff] [blame] | 3247 | if (updateFlag == DeferRecalcStyle) { |
hyatt@apple.com | 9e92428 | 2010-08-26 19:33:40 +0000 | [diff] [blame] | 3248 | scheduleForcedStyleRecalc(); |
hyatt@apple.com | 8dd0d93 | 2010-08-26 18:17:59 +0000 | [diff] [blame] | 3249 | return; |
| 3250 | } |
antti@apple.com | 1b3067c | 2012-03-02 10:46:55 +0000 | [diff] [blame] | 3251 | |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 3252 | if (didLayoutWithPendingStylesheets() && !m_styleSheetCollection->hasPendingSheets()) { |
hyatt@apple.com | 8dd0d93 | 2010-08-26 18:17:59 +0000 | [diff] [blame] | 3253 | m_pendingSheetLayout = IgnoreLayoutWithPendingSheets; |
| 3254 | if (renderer()) |
| 3255 | renderer()->repaint(); |
| 3256 | } |
| 3257 | |
antti@apple.com | 1b3067c | 2012-03-02 10:46:55 +0000 | [diff] [blame] | 3258 | if (!stylesheetChangeRequiresStyleRecalc) |
| 3259 | return; |
| 3260 | |
cmarrin@apple.com | d0121bc | 2010-04-10 01:00:18 +0000 | [diff] [blame] | 3261 | // This recalcStyle initiates a new recalc cycle. We need to bracket it to |
| 3262 | // make sure animations get the correct update time |
simon.fraser@apple.com | dbb8087 | 2012-05-22 21:17:44 +0000 | [diff] [blame] | 3263 | { |
| 3264 | AnimationUpdateBlock animationUpdateBlock(m_frame ? m_frame->animation() : 0); |
| 3265 | recalcStyle(Force); |
| 3266 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3267 | |
| 3268 | #ifdef INSTRUMENT_LAYOUT_SCHEDULING |
| 3269 | if (!ownerElement()) |
| 3270 | printf("Finished update of style selector at time %d\n", elapsedTime()); |
| 3271 | #endif |
| 3272 | |
| 3273 | if (renderer()) { |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 3274 | renderer()->setNeedsLayoutAndPrefWidthsRecalc(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3275 | if (view()) |
| 3276 | view()->scheduleRelayout(); |
| 3277 | } |
luiz@webkit.org | db0dd43 | 2010-11-22 21:02:27 +0000 | [diff] [blame] | 3278 | |
antti@apple.com | ef75e9e | 2012-04-18 18:34:42 +0000 | [diff] [blame] | 3279 | evaluateMediaQueryList(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
eric@webkit.org | 876b40e | 2012-05-09 00:52:08 +0000 | [diff] [blame] | 3282 | void Document::notifySeamlessChildDocumentsOfStylesheetUpdate() const |
| 3283 | { |
| 3284 | // If we're not in a frame yet any potential child documents won't have a StyleResolver to update. |
| 3285 | if (!frame()) |
| 3286 | return; |
| 3287 | |
| 3288 | // Seamless child frames are expected to notify their seamless children recursively, so we only do direct children. |
| 3289 | for (Frame* child = frame()->tree()->firstChild(); child; child = child->tree()->nextSibling()) { |
| 3290 | Document* childDocument = child->document(); |
| 3291 | if (childDocument->shouldDisplaySeamlesslyWithParent()) { |
| 3292 | ASSERT(childDocument->seamlessParentIFrame()->document() == this); |
| 3293 | childDocument->seamlessParentUpdatedStylesheets(); |
| 3294 | } |
| 3295 | } |
| 3296 | } |
| 3297 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3298 | void Document::setHoverNode(PassRefPtr<Node> newHoverNode) |
| 3299 | { |
| 3300 | m_hoverNode = newHoverNode; |
| 3301 | } |
| 3302 | |
| 3303 | void Document::setActiveNode(PassRefPtr<Node> newActiveNode) |
| 3304 | { |
| 3305 | m_activeNode = newActiveNode; |
| 3306 | } |
| 3307 | |
alice.liu@apple.com | d7e80fd | 2007-12-19 22:51:30 +0000 | [diff] [blame] | 3308 | void Document::focusedNodeRemoved() |
ggaren | 7c5851a | 2006-12-12 22:11:18 +0000 | [diff] [blame] | 3309 | { |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3310 | setFocusedNode(0); |
ggaren | 7c5851a | 2006-12-12 22:11:18 +0000 | [diff] [blame] | 3311 | } |
| 3312 | |
alice.liu@apple.com | d7e80fd | 2007-12-19 22:51:30 +0000 | [diff] [blame] | 3313 | void Document::removeFocusedNodeOfSubtree(Node* node, bool amongChildrenOnly) |
| 3314 | { |
| 3315 | if (!m_focusedNode || this->inPageCache()) // If the document is in the page cache, then we don't need to clear out the focused node. |
| 3316 | return; |
yosin@chromium.org | c58582b | 2012-09-25 03:26:31 +0000 | [diff] [blame] | 3317 | |
| 3318 | Node* focusedNode = node->treeScope()->focusedNode(); |
| 3319 | if (!focusedNode) |
| 3320 | return; |
| 3321 | |
alice.liu@apple.com | d7e80fd | 2007-12-19 22:51:30 +0000 | [diff] [blame] | 3322 | bool nodeInSubtree = false; |
| 3323 | if (amongChildrenOnly) |
yosin@chromium.org | c58582b | 2012-09-25 03:26:31 +0000 | [diff] [blame] | 3324 | nodeInSubtree = focusedNode->isDescendantOf(node); |
alice.liu@apple.com | d7e80fd | 2007-12-19 22:51:30 +0000 | [diff] [blame] | 3325 | else |
yosin@chromium.org | c58582b | 2012-09-25 03:26:31 +0000 | [diff] [blame] | 3326 | nodeInSubtree = (focusedNode == node) || focusedNode->isDescendantOf(node); |
alice.liu@apple.com | d7e80fd | 2007-12-19 22:51:30 +0000 | [diff] [blame] | 3327 | |
| 3328 | if (nodeInSubtree) |
| 3329 | document()->focusedNodeRemoved(); |
| 3330 | } |
| 3331 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3332 | void Document::hoveredNodeDetached(Node* node) |
| 3333 | { |
dglazkov@chromium.org | c2dd528 | 2010-11-29 21:27:45 +0000 | [diff] [blame] | 3334 | if (!m_hoverNode || (node != m_hoverNode && (!m_hoverNode->isTextNode() || node != m_hoverNode->parentNode()))) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3335 | return; |
| 3336 | |
dglazkov@chromium.org | c2dd528 | 2010-11-29 21:27:45 +0000 | [diff] [blame] | 3337 | m_hoverNode = node->parentNode(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3338 | while (m_hoverNode && !m_hoverNode->renderer()) |
dglazkov@chromium.org | c2dd528 | 2010-11-29 21:27:45 +0000 | [diff] [blame] | 3339 | m_hoverNode = m_hoverNode->parentNode(); |
darin | 60e537f5 | 2006-11-15 01:29:46 +0000 | [diff] [blame] | 3340 | if (frame()) |
| 3341 | frame()->eventHandler()->scheduleHoverStateUpdate(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | void Document::activeChainNodeDetached(Node* node) |
| 3345 | { |
dglazkov@chromium.org | c2dd528 | 2010-11-29 21:27:45 +0000 | [diff] [blame] | 3346 | if (!m_activeNode || (node != m_activeNode && (!m_activeNode->isTextNode() || node != m_activeNode->parentNode()))) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3347 | return; |
| 3348 | |
dglazkov@chromium.org | c2dd528 | 2010-11-29 21:27:45 +0000 | [diff] [blame] | 3349 | m_activeNode = node->parentNode(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3350 | while (m_activeNode && !m_activeNode->renderer()) |
dglazkov@chromium.org | c2dd528 | 2010-11-29 21:27:45 +0000 | [diff] [blame] | 3351 | m_activeNode = m_activeNode->parentNode(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3352 | } |
| 3353 | |
jianli@chromium.org | f66b581 | 2012-08-02 00:14:28 +0000 | [diff] [blame] | 3354 | #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION) |
darin | be6eb6b | 2006-09-06 16:23:32 +0000 | [diff] [blame] | 3355 | const Vector<DashboardRegionValue>& Document::dashboardRegions() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3356 | { |
| 3357 | return m_dashboardRegions; |
| 3358 | } |
| 3359 | |
darin | be6eb6b | 2006-09-06 16:23:32 +0000 | [diff] [blame] | 3360 | void Document::setDashboardRegions(const Vector<DashboardRegionValue>& regions) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3361 | { |
| 3362 | m_dashboardRegions = regions; |
darin | be6eb6b | 2006-09-06 16:23:32 +0000 | [diff] [blame] | 3363 | setDashboardRegionsDirty(false); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3364 | } |
ddkilzer@apple.com | 8fe6586 | 2008-04-29 21:31:09 +0000 | [diff] [blame] | 3365 | #endif |
darin | a6a0caf | 2007-01-25 00:16:44 +0000 | [diff] [blame] | 3366 | |
andersca@apple.com | d645ac6 | 2011-06-20 20:21:56 +0000 | [diff] [blame] | 3367 | bool Document::setFocusedNode(PassRefPtr<Node> prpNewFocusedNode) |
| 3368 | { |
| 3369 | RefPtr<Node> newFocusedNode = prpNewFocusedNode; |
| 3370 | |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3371 | // Make sure newFocusedNode is actually in this document |
| 3372 | if (newFocusedNode && (newFocusedNode->document() != this)) |
| 3373 | return true; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3374 | |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3375 | if (m_focusedNode == newFocusedNode) |
| 3376 | return true; |
mitz@apple.com | 85e88e4 | 2008-01-21 02:01:26 +0000 | [diff] [blame] | 3377 | |
| 3378 | if (m_inPageCache) |
| 3379 | return false; |
| 3380 | |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3381 | bool focusChangeBlocked = false; |
| 3382 | RefPtr<Node> oldFocusedNode = m_focusedNode; |
tkent@chromium.org | 4a11c2f | 2011-10-05 06:07:51 +0000 | [diff] [blame] | 3383 | m_focusedNode = 0; |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3384 | |
| 3385 | // Remove focus from the existing focus node (if any) |
morrita@google.com | 1d498e7 | 2012-05-10 14:43:27 +0000 | [diff] [blame] | 3386 | if (oldFocusedNode) { |
morrita@google.com | edbd61e | 2012-05-14 07:49:59 +0000 | [diff] [blame] | 3387 | ASSERT(!oldFocusedNode->inDetach()); |
| 3388 | |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3389 | if (oldFocusedNode->active()) |
| 3390 | oldFocusedNode->setActive(false); |
| 3391 | |
| 3392 | oldFocusedNode->setFocus(false); |
timothy@apple.com | 7157c6d | 2009-12-02 18:34:33 +0000 | [diff] [blame] | 3393 | |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3394 | // Dispatch a change event for text fields or textareas that have been edited |
commit-queue@webkit.org | 5f06da0 | 2011-03-05 08:09:39 +0000 | [diff] [blame] | 3395 | if (oldFocusedNode->isElementNode()) { |
| 3396 | Element* element = static_cast<Element*>(oldFocusedNode.get()); |
| 3397 | if (element->wasChangedSinceLastFormControlChangeEvent()) |
| 3398 | element->dispatchFormControlChangeEvent(); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | // Dispatch the blur event and let the node do any other blur related activities (important for text fields) |
hayato@chromium.org | 91ac134 | 2011-08-18 02:41:10 +0000 | [diff] [blame] | 3402 | oldFocusedNode->dispatchBlurEvent(newFocusedNode); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3403 | |
| 3404 | if (m_focusedNode) { |
| 3405 | // handler shifted focus |
| 3406 | focusChangeBlocked = true; |
| 3407 | newFocusedNode = 0; |
| 3408 | } |
hyatt@apple.com | 25d28d1 | 2010-03-23 17:53:00 +0000 | [diff] [blame] | 3409 | |
hayato@chromium.org | 3854c5c | 2011-08-15 11:02:10 +0000 | [diff] [blame] | 3410 | oldFocusedNode->dispatchFocusOutEvent(eventNames().focusoutEvent, newFocusedNode); // DOM level 3 name for the bubbling blur event. |
enrica@apple.com | bd9026c | 2010-10-01 20:50:41 +0000 | [diff] [blame] | 3411 | // FIXME: We should remove firing DOMFocusOutEvent event when we are sure no content depends |
| 3412 | // on it, probably when <rdar://problem/8503958> is resolved. |
hayato@chromium.org | 3854c5c | 2011-08-15 11:02:10 +0000 | [diff] [blame] | 3413 | oldFocusedNode->dispatchFocusOutEvent(eventNames().DOMFocusOutEvent, newFocusedNode); // DOM level 2 name for compatibility. |
hyatt@apple.com | 25d28d1 | 2010-03-23 17:53:00 +0000 | [diff] [blame] | 3414 | |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3415 | if (m_focusedNode) { |
| 3416 | // handler shifted focus |
| 3417 | focusChangeBlocked = true; |
| 3418 | newFocusedNode = 0; |
| 3419 | } |
darin@apple.com | 6f6b5be | 2009-08-17 17:03:58 +0000 | [diff] [blame] | 3420 | if (oldFocusedNode == this && oldFocusedNode->hasOneRef()) |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3421 | return true; |
| 3422 | |
commit-queue@webkit.org | 5f40293 | 2012-05-11 20:09:13 +0000 | [diff] [blame] | 3423 | if (oldFocusedNode->isRootEditableElement()) |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3424 | frame()->editor()->didEndEditing(); |
eric@webkit.org | 754029e | 2010-05-05 16:22:05 +0000 | [diff] [blame] | 3425 | |
| 3426 | if (view()) { |
| 3427 | Widget* oldWidget = widgetForNode(oldFocusedNode.get()); |
| 3428 | if (oldWidget) |
| 3429 | oldWidget->setFocus(false); |
| 3430 | else |
| 3431 | view()->setFocus(false); |
| 3432 | } |
tkent@chromium.org | 4a11c2f | 2011-10-05 06:07:51 +0000 | [diff] [blame] | 3433 | } |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3434 | |
| 3435 | if (newFocusedNode) { |
commit-queue@webkit.org | 5f40293 | 2012-05-11 20:09:13 +0000 | [diff] [blame] | 3436 | if (newFocusedNode->isRootEditableElement() && !acceptsEditingFocus(newFocusedNode.get())) { |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3437 | // delegate blocks focus change |
| 3438 | focusChangeBlocked = true; |
| 3439 | goto SetFocusedNodeDone; |
| 3440 | } |
| 3441 | // Set focus on the new node |
andersca@apple.com | d645ac6 | 2011-06-20 20:21:56 +0000 | [diff] [blame] | 3442 | m_focusedNode = newFocusedNode; |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3443 | |
| 3444 | // Dispatch the focus event and let the node do any other focus related activities (important for text fields) |
hayato@chromium.org | 91ac134 | 2011-08-18 02:41:10 +0000 | [diff] [blame] | 3445 | m_focusedNode->dispatchFocusEvent(oldFocusedNode); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3446 | |
| 3447 | if (m_focusedNode != newFocusedNode) { |
| 3448 | // handler shifted focus |
| 3449 | focusChangeBlocked = true; |
| 3450 | goto SetFocusedNodeDone; |
| 3451 | } |
hyatt@apple.com | 25d28d1 | 2010-03-23 17:53:00 +0000 | [diff] [blame] | 3452 | |
hayato@chromium.org | 3854c5c | 2011-08-15 11:02:10 +0000 | [diff] [blame] | 3453 | m_focusedNode->dispatchFocusInEvent(eventNames().focusinEvent, oldFocusedNode); // DOM level 3 bubbling focus event. |
hayato@chromium.org | 0159d53 | 2012-01-24 01:21:42 +0000 | [diff] [blame] | 3454 | |
| 3455 | if (m_focusedNode != newFocusedNode) { |
| 3456 | // handler shifted focus |
| 3457 | focusChangeBlocked = true; |
| 3458 | goto SetFocusedNodeDone; |
| 3459 | } |
| 3460 | |
enrica@apple.com | bd9026c | 2010-10-01 20:50:41 +0000 | [diff] [blame] | 3461 | // FIXME: We should remove firing DOMFocusInEvent event when we are sure no content depends |
hayato@chromium.org | 3854c5c | 2011-08-15 11:02:10 +0000 | [diff] [blame] | 3462 | // on it, probably when <rdar://problem/8503958> is m. |
| 3463 | m_focusedNode->dispatchFocusInEvent(eventNames().DOMFocusInEvent, oldFocusedNode); // DOM level 2 for compatibility. |
hyatt@apple.com | 25d28d1 | 2010-03-23 17:53:00 +0000 | [diff] [blame] | 3464 | |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3465 | if (m_focusedNode != newFocusedNode) { |
| 3466 | // handler shifted focus |
| 3467 | focusChangeBlocked = true; |
| 3468 | goto SetFocusedNodeDone; |
| 3469 | } |
eric@webkit.org | 754029e | 2010-05-05 16:22:05 +0000 | [diff] [blame] | 3470 | m_focusedNode->setFocus(true); |
hyatt | 5e94117 | 2007-02-13 04:49:26 +0000 | [diff] [blame] | 3471 | |
commit-queue@webkit.org | 5f40293 | 2012-05-11 20:09:13 +0000 | [diff] [blame] | 3472 | if (m_focusedNode->isRootEditableElement()) |
weinig | 28ce873 | 2007-04-19 14:47:21 +0000 | [diff] [blame] | 3473 | frame()->editor()->didBeginEditing(); |
| 3474 | |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3475 | // eww, I suck. set the qt focus correctly |
| 3476 | // ### find a better place in the code for this |
| 3477 | if (view()) { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 3478 | Widget* focusWidget = widgetForNode(m_focusedNode.get()); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3479 | if (focusWidget) { |
| 3480 | // Make sure a widget has the right size before giving it focus. |
| 3481 | // Otherwise, we are testing edge cases of the Widget code. |
| 3482 | // Specifically, in WebCore this does not work well for text fields. |
| 3483 | updateLayout(); |
| 3484 | // Re-get the widget in case updating the layout changed things. |
| 3485 | focusWidget = widgetForNode(m_focusedNode.get()); |
| 3486 | } |
| 3487 | if (focusWidget) |
eric@webkit.org | 754029e | 2010-05-05 16:22:05 +0000 | [diff] [blame] | 3488 | focusWidget->setFocus(true); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3489 | else |
eric@webkit.org | 754029e | 2010-05-05 16:22:05 +0000 | [diff] [blame] | 3490 | view()->setFocus(true); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3491 | } |
ddkilzer@apple.com | 9c4dacc | 2009-07-11 05:36:29 +0000 | [diff] [blame] | 3492 | } |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3493 | |
commit-queue@webkit.org | 666227b | 2010-09-24 07:51:48 +0000 | [diff] [blame] | 3494 | #if PLATFORM(MAC) || PLATFORM(WIN) || PLATFORM(GTK) || PLATFORM(CHROMIUM) |
dmazzoni@google.com | cfbd0dd | 2012-08-15 21:31:35 +0000 | [diff] [blame] | 3495 | if (!focusChangeBlocked && m_focusedNode && AXObjectCache::accessibilityEnabled()) |
| 3496 | axObjectCache()->handleFocusedUIElementChanged(oldFocusedNode.get(), newFocusedNode.get()); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3497 | #endif |
levin@chromium.org | ec60442 | 2009-10-30 20:59:46 +0000 | [diff] [blame] | 3498 | if (!focusChangeBlocked) |
| 3499 | page()->chrome()->focusedNodeChanged(m_focusedNode.get()); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3500 | |
| 3501 | SetFocusedNodeDone: |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 3502 | updateStyleIfNeeded(); |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3503 | return !focusChangeBlocked; |
adele@apple.com | 3b8816e | 2009-04-03 00:39:18 +0000 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | void Document::getFocusableNodes(Vector<RefPtr<Node> >& nodes) |
| 3507 | { |
| 3508 | updateLayout(); |
| 3509 | |
| 3510 | for (Node* node = firstChild(); node; node = node->traverseNextNode()) { |
| 3511 | if (node->isFocusable()) |
| 3512 | nodes.append(node); |
| 3513 | } |
| 3514 | } |
ggaren | 03a0f87 | 2006-12-15 03:43:51 +0000 | [diff] [blame] | 3515 | |
darin@apple.com | e8c3a2a | 2009-02-02 17:29:54 +0000 | [diff] [blame] | 3516 | void Document::setCSSTarget(Element* n) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3517 | { |
| 3518 | if (m_cssTarget) |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 3519 | m_cssTarget->setNeedsStyleRecalc(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3520 | m_cssTarget = n; |
| 3521 | if (n) |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 3522 | n->setNeedsStyleRecalc(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3523 | } |
| 3524 | |
rniwa@webkit.org | f57f8e0 | 2012-07-13 19:48:40 +0000 | [diff] [blame] | 3525 | void Document::registerNodeListCache(DynamicNodeListCacheBase* list) |
rniwa@webkit.org | fdcdadf | 2012-06-14 22:38:41 +0000 | [diff] [blame] | 3526 | { |
rniwa@webkit.org | 7f9d0ef | 2012-07-21 01:03:17 +0000 | [diff] [blame] | 3527 | if (list->type() != NodeListCollectionType) |
rniwa@webkit.org | f57f8e0 | 2012-07-13 19:48:40 +0000 | [diff] [blame] | 3528 | m_nodeListCounts[InvalidateOnIdNameAttrChange]++; |
| 3529 | m_nodeListCounts[list->invalidationType()]++; |
rniwa@webkit.org | 198f43c | 2012-07-13 22:44:46 +0000 | [diff] [blame] | 3530 | if (list->isRootedAtDocument()) |
rniwa@webkit.org | fc3b7b7 | 2012-07-12 20:31:09 +0000 | [diff] [blame] | 3531 | m_listsInvalidatedAtDocument.add(list); |
rniwa@webkit.org | fdcdadf | 2012-06-14 22:38:41 +0000 | [diff] [blame] | 3532 | } |
| 3533 | |
rniwa@webkit.org | f57f8e0 | 2012-07-13 19:48:40 +0000 | [diff] [blame] | 3534 | void Document::unregisterNodeListCache(DynamicNodeListCacheBase* list) |
rniwa@webkit.org | fdcdadf | 2012-06-14 22:38:41 +0000 | [diff] [blame] | 3535 | { |
rniwa@webkit.org | 7f9d0ef | 2012-07-21 01:03:17 +0000 | [diff] [blame] | 3536 | if (list->type() != NodeListCollectionType) |
rniwa@webkit.org | f57f8e0 | 2012-07-13 19:48:40 +0000 | [diff] [blame] | 3537 | m_nodeListCounts[InvalidateOnIdNameAttrChange]--; |
| 3538 | m_nodeListCounts[list->invalidationType()]--; |
rniwa@webkit.org | 198f43c | 2012-07-13 22:44:46 +0000 | [diff] [blame] | 3539 | if (list->isRootedAtDocument()) { |
rniwa@webkit.org | fc3b7b7 | 2012-07-12 20:31:09 +0000 | [diff] [blame] | 3540 | ASSERT(m_listsInvalidatedAtDocument.contains(list)); |
| 3541 | m_listsInvalidatedAtDocument.remove(list); |
| 3542 | } |
| 3543 | } |
| 3544 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 3545 | void Document::attachNodeIterator(NodeIterator* ni) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3546 | { |
andersca | 202e865 | 2006-11-18 05:57:13 +0000 | [diff] [blame] | 3547 | m_nodeIterators.add(ni); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 3550 | void Document::detachNodeIterator(NodeIterator* ni) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3551 | { |
ap@apple.com | 3f3f4a1 | 2010-09-23 21:09:17 +0000 | [diff] [blame] | 3552 | // The node iterator can be detached without having been attached if its root node didn't have a document |
| 3553 | // when the iterator was created, but has it now. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3554 | m_nodeIterators.remove(ni); |
| 3555 | } |
| 3556 | |
inferno@chromium.org | b0f943f | 2010-12-08 23:31:04 +0000 | [diff] [blame] | 3557 | void Document::moveNodeIteratorsToNewDocument(Node* node, Document* newDocument) |
| 3558 | { |
| 3559 | HashSet<NodeIterator*> nodeIteratorsList = m_nodeIterators; |
| 3560 | HashSet<NodeIterator*>::const_iterator nodeIteratorsEnd = nodeIteratorsList.end(); |
| 3561 | for (HashSet<NodeIterator*>::const_iterator it = nodeIteratorsList.begin(); it != nodeIteratorsEnd; ++it) { |
inferno@chromium.org | fd8e006 | 2010-12-09 17:51:07 +0000 | [diff] [blame] | 3562 | if ((*it)->root() == node) { |
inferno@chromium.org | b0f943f | 2010-12-08 23:31:04 +0000 | [diff] [blame] | 3563 | detachNodeIterator(*it); |
| 3564 | newDocument->attachNodeIterator(*it); |
| 3565 | } |
| 3566 | } |
| 3567 | } |
| 3568 | |
rniwa@webkit.org | 941f815 | 2011-12-09 05:26:58 +0000 | [diff] [blame] | 3569 | void Document::updateRangesAfterChildrenChanged(ContainerNode* container) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3570 | { |
eric@webkit.org | 7c63216 | 2012-06-29 07:15:44 +0000 | [diff] [blame] | 3571 | if (!m_ranges.isEmpty()) { |
justin.garcia@apple.com | 692743d | 2008-05-05 22:50:56 +0000 | [diff] [blame] | 3572 | HashSet<Range*>::const_iterator end = m_ranges.end(); |
| 3573 | for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it) |
| 3574 | (*it)->nodeChildrenChanged(container); |
| 3575 | } |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3576 | } |
andersca | 202e865 | 2006-11-18 05:57:13 +0000 | [diff] [blame] | 3577 | |
ap@apple.com | 748d522 | 2010-05-10 22:13:36 +0000 | [diff] [blame] | 3578 | void Document::nodeChildrenWillBeRemoved(ContainerNode* container) |
| 3579 | { |
eric@webkit.org | 7c63216 | 2012-06-29 07:15:44 +0000 | [diff] [blame] | 3580 | if (!m_ranges.isEmpty()) { |
ap@apple.com | 748d522 | 2010-05-10 22:13:36 +0000 | [diff] [blame] | 3581 | HashSet<Range*>::const_iterator end = m_ranges.end(); |
| 3582 | for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it) |
| 3583 | (*it)->nodeChildrenWillBeRemoved(container); |
| 3584 | } |
| 3585 | |
| 3586 | HashSet<NodeIterator*>::const_iterator nodeIteratorsEnd = m_nodeIterators.end(); |
| 3587 | for (HashSet<NodeIterator*>::const_iterator it = m_nodeIterators.begin(); it != nodeIteratorsEnd; ++it) { |
| 3588 | for (Node* n = container->firstChild(); n; n = n->nextSibling()) |
| 3589 | (*it)->nodeWillBeRemoved(n); |
| 3590 | } |
| 3591 | |
| 3592 | if (Frame* frame = this->frame()) { |
| 3593 | for (Node* n = container->firstChild(); n; n = n->nextSibling()) { |
rniwa@webkit.org | 91cc070 | 2011-05-13 21:35:06 +0000 | [diff] [blame] | 3594 | frame->eventHandler()->nodeWillBeRemoved(n); |
ap@apple.com | 748d522 | 2010-05-10 22:13:36 +0000 | [diff] [blame] | 3595 | frame->selection()->nodeWillBeRemoved(n); |
darin@apple.com | b17ec2f | 2010-09-10 22:06:47 +0000 | [diff] [blame] | 3596 | frame->page()->dragCaretController()->nodeWillBeRemoved(n); |
ap@apple.com | 748d522 | 2010-05-10 22:13:36 +0000 | [diff] [blame] | 3597 | } |
| 3598 | } |
| 3599 | } |
| 3600 | |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3601 | void Document::nodeWillBeRemoved(Node* n) |
| 3602 | { |
| 3603 | HashSet<NodeIterator*>::const_iterator nodeIteratorsEnd = m_nodeIterators.end(); |
| 3604 | for (HashSet<NodeIterator*>::const_iterator it = m_nodeIterators.begin(); it != nodeIteratorsEnd; ++it) |
| 3605 | (*it)->nodeWillBeRemoved(n); |
| 3606 | |
eric@webkit.org | 7c63216 | 2012-06-29 07:15:44 +0000 | [diff] [blame] | 3607 | if (!m_ranges.isEmpty()) { |
justin.garcia@apple.com | 692743d | 2008-05-05 22:50:56 +0000 | [diff] [blame] | 3608 | HashSet<Range*>::const_iterator rangesEnd = m_ranges.end(); |
| 3609 | for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != rangesEnd; ++it) |
| 3610 | (*it)->nodeWillBeRemoved(n); |
| 3611 | } |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3612 | |
| 3613 | if (Frame* frame = this->frame()) { |
rniwa@webkit.org | 91cc070 | 2011-05-13 21:35:06 +0000 | [diff] [blame] | 3614 | frame->eventHandler()->nodeWillBeRemoved(n); |
darin@apple.com | 60d3e9f | 2008-06-16 06:13:02 +0000 | [diff] [blame] | 3615 | frame->selection()->nodeWillBeRemoved(n); |
darin@apple.com | b17ec2f | 2010-09-10 22:06:47 +0000 | [diff] [blame] | 3616 | frame->page()->dragCaretController()->nodeWillBeRemoved(n); |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3617 | } |
| 3618 | } |
| 3619 | |
| 3620 | void Document::textInserted(Node* text, unsigned offset, unsigned length) |
| 3621 | { |
eric@webkit.org | 7c63216 | 2012-06-29 07:15:44 +0000 | [diff] [blame] | 3622 | if (!m_ranges.isEmpty()) { |
justin.garcia@apple.com | 692743d | 2008-05-05 22:50:56 +0000 | [diff] [blame] | 3623 | HashSet<Range*>::const_iterator end = m_ranges.end(); |
| 3624 | for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it) |
| 3625 | (*it)->textInserted(text, offset, length); |
| 3626 | } |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3627 | |
| 3628 | // Update the markers for spelling and grammar checking. |
dbates@webkit.org | 858331b | 2010-08-22 21:41:37 +0000 | [diff] [blame] | 3629 | m_markers->shiftMarkers(text, offset, length); |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3630 | } |
| 3631 | |
| 3632 | void Document::textRemoved(Node* text, unsigned offset, unsigned length) |
| 3633 | { |
eric@webkit.org | 7c63216 | 2012-06-29 07:15:44 +0000 | [diff] [blame] | 3634 | if (!m_ranges.isEmpty()) { |
justin.garcia@apple.com | 692743d | 2008-05-05 22:50:56 +0000 | [diff] [blame] | 3635 | HashSet<Range*>::const_iterator end = m_ranges.end(); |
| 3636 | for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it) |
| 3637 | (*it)->textRemoved(text, offset, length); |
| 3638 | } |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3639 | |
| 3640 | // Update the markers for spelling and grammar checking. |
dbates@webkit.org | 858331b | 2010-08-22 21:41:37 +0000 | [diff] [blame] | 3641 | m_markers->removeMarkers(text, offset, length); |
| 3642 | m_markers->shiftMarkers(text, offset + length, 0 - length); |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | void Document::textNodesMerged(Text* oldNode, unsigned offset) |
| 3646 | { |
eric@webkit.org | 7c63216 | 2012-06-29 07:15:44 +0000 | [diff] [blame] | 3647 | if (!m_ranges.isEmpty()) { |
justin.garcia@apple.com | 692743d | 2008-05-05 22:50:56 +0000 | [diff] [blame] | 3648 | NodeWithIndex oldNodeWithIndex(oldNode); |
| 3649 | HashSet<Range*>::const_iterator end = m_ranges.end(); |
| 3650 | for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it) |
| 3651 | (*it)->textNodesMerged(oldNodeWithIndex, offset); |
| 3652 | } |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3653 | |
| 3654 | // FIXME: This should update markers for spelling and grammar checking. |
| 3655 | } |
| 3656 | |
| 3657 | void Document::textNodeSplit(Text* oldNode) |
| 3658 | { |
eric@webkit.org | 7c63216 | 2012-06-29 07:15:44 +0000 | [diff] [blame] | 3659 | if (!m_ranges.isEmpty()) { |
justin.garcia@apple.com | 692743d | 2008-05-05 22:50:56 +0000 | [diff] [blame] | 3660 | HashSet<Range*>::const_iterator end = m_ranges.end(); |
| 3661 | for (HashSet<Range*>::const_iterator it = m_ranges.begin(); it != end; ++it) |
| 3662 | (*it)->textNodeSplit(oldNode); |
| 3663 | } |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3664 | |
| 3665 | // FIXME: This should update markers for spelling and grammar checking. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3666 | } |
| 3667 | |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 3668 | void Document::createDOMWindow() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3669 | { |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 3670 | ASSERT(m_frame); |
| 3671 | ASSERT(!m_domWindow); |
ap@webkit.org | 142736a | 2009-05-19 18:14:51 +0000 | [diff] [blame] | 3672 | |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 3673 | m_domWindow = DOMWindow::create(this); |
ap@webkit.org | 142736a | 2009-05-19 18:14:51 +0000 | [diff] [blame] | 3674 | |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 3675 | ASSERT(m_domWindow->document() == this); |
| 3676 | ASSERT(m_domWindow->frame() == m_frame); |
| 3677 | } |
| 3678 | |
| 3679 | void Document::takeDOMWindowFrom(Document* document) |
| 3680 | { |
| 3681 | ASSERT(m_frame); |
| 3682 | ASSERT(!m_domWindow); |
| 3683 | ASSERT(document->domWindow()); |
| 3684 | |
| 3685 | m_domWindow = document->m_domWindow.release(); |
| 3686 | m_domWindow->didSecureTransitionTo(this); |
| 3687 | |
| 3688 | ASSERT(m_domWindow->document() == this); |
| 3689 | ASSERT(m_domWindow->frame() == m_frame); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3690 | } |
| 3691 | |
weinig@apple.com | f23f771 | 2009-04-27 23:33:57 +0000 | [diff] [blame] | 3692 | void Document::setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener) |
| 3693 | { |
| 3694 | DOMWindow* domWindow = this->domWindow(); |
| 3695 | if (!domWindow) |
| 3696 | return; |
| 3697 | domWindow->setAttributeEventListener(eventType, listener); |
| 3698 | } |
| 3699 | |
weinig@apple.com | 0ce8f4e | 2009-06-22 18:32:08 +0000 | [diff] [blame] | 3700 | EventListener* Document::getWindowAttributeEventListener(const AtomicString& eventType) |
| 3701 | { |
| 3702 | DOMWindow* domWindow = this->domWindow(); |
| 3703 | if (!domWindow) |
| 3704 | return 0; |
| 3705 | return domWindow->getAttributeEventListener(eventType); |
| 3706 | } |
| 3707 | |
ggaren@apple.com | 521f64b | 2009-09-24 05:53:23 +0000 | [diff] [blame] | 3708 | void Document::dispatchWindowEvent(PassRefPtr<Event> event, PassRefPtr<EventTarget> target) |
weinig@apple.com | 6dfb60c | 2009-05-31 00:58:06 +0000 | [diff] [blame] | 3709 | { |
rniwa@webkit.org | 61322a1 | 2012-10-01 22:24:20 +0000 | [diff] [blame] | 3710 | ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); |
weinig@apple.com | 6dfb60c | 2009-05-31 00:58:06 +0000 | [diff] [blame] | 3711 | DOMWindow* domWindow = this->domWindow(); |
| 3712 | if (!domWindow) |
| 3713 | return; |
ggaren@apple.com | 521f64b | 2009-09-24 05:53:23 +0000 | [diff] [blame] | 3714 | domWindow->dispatchEvent(event, target); |
weinig@apple.com | 6dfb60c | 2009-05-31 00:58:06 +0000 | [diff] [blame] | 3715 | } |
| 3716 | |
ggaren@apple.com | 521f64b | 2009-09-24 05:53:23 +0000 | [diff] [blame] | 3717 | void Document::dispatchWindowLoadEvent() |
weinig@apple.com | f23f771 | 2009-04-27 23:33:57 +0000 | [diff] [blame] | 3718 | { |
rniwa@webkit.org | 61322a1 | 2012-10-01 22:24:20 +0000 | [diff] [blame] | 3719 | ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); |
weinig@apple.com | f23f771 | 2009-04-27 23:33:57 +0000 | [diff] [blame] | 3720 | DOMWindow* domWindow = this->domWindow(); |
| 3721 | if (!domWindow) |
| 3722 | return; |
| 3723 | domWindow->dispatchLoadEvent(); |
japhet@chromium.org | 4fdf46f | 2011-07-06 17:59:59 +0000 | [diff] [blame] | 3724 | m_loadEventFinished = true; |
weinig@apple.com | f23f771 | 2009-04-27 23:33:57 +0000 | [diff] [blame] | 3725 | } |
| 3726 | |
mihaip@chromium.org | b042a70 | 2010-12-14 22:52:24 +0000 | [diff] [blame] | 3727 | void Document::enqueueWindowEvent(PassRefPtr<Event> event) |
jorlow@chromium.org | ee1d476 | 2010-01-26 06:23:35 +0000 | [diff] [blame] | 3728 | { |
mihaip@chromium.org | b042a70 | 2010-12-14 22:52:24 +0000 | [diff] [blame] | 3729 | event->setTarget(domWindow()); |
| 3730 | m_eventQueue->enqueueEvent(event); |
jorlow@chromium.org | ee1d476 | 2010-01-26 06:23:35 +0000 | [diff] [blame] | 3731 | } |
| 3732 | |
rniwa@webkit.org | 6d5a87e | 2011-02-21 11:24:41 +0000 | [diff] [blame] | 3733 | void Document::enqueueDocumentEvent(PassRefPtr<Event> event) |
| 3734 | { |
| 3735 | event->setTarget(this); |
| 3736 | m_eventQueue->enqueueEvent(event); |
| 3737 | } |
| 3738 | |
weinig@apple.com | 4e70ed3 | 2008-02-18 00:22:21 +0000 | [diff] [blame] | 3739 | PassRefPtr<Event> Document::createEvent(const String& eventType, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3740 | { |
abarth@webkit.org | 08feba4 | 2011-10-20 04:50:14 +0000 | [diff] [blame] | 3741 | RefPtr<Event> event = EventFactory::create(eventType); |
abarth@webkit.org | b4fefb8 | 2010-04-03 07:05:55 +0000 | [diff] [blame] | 3742 | if (event) |
abarth@webkit.org | 0e7ddb4 | 2009-10-20 01:19:01 +0000 | [diff] [blame] | 3743 | return event.release(); |
abarth@webkit.org | b4fefb8 | 2010-04-03 07:05:55 +0000 | [diff] [blame] | 3744 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3745 | ec = NOT_SUPPORTED_ERR; |
| 3746 | return 0; |
| 3747 | } |
| 3748 | |
adamk@chromium.org | fdf6346 | 2012-08-21 01:14:51 +0000 | [diff] [blame] | 3749 | void Document::addMutationEventListenerTypeIfEnabled(ListenerType listenerType) |
| 3750 | { |
| 3751 | if (ContextFeatures::mutationEventsEnabled(this)) |
| 3752 | addListenerType(listenerType); |
| 3753 | } |
| 3754 | |
zimmermann@webkit.org | 97c7108 | 2008-09-24 00:23:28 +0000 | [diff] [blame] | 3755 | void Document::addListenerTypeIfNeeded(const AtomicString& eventType) |
| 3756 | { |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3757 | if (eventType == eventNames().DOMSubtreeModifiedEvent) |
adamk@chromium.org | fdf6346 | 2012-08-21 01:14:51 +0000 | [diff] [blame] | 3758 | addMutationEventListenerTypeIfEnabled(DOMSUBTREEMODIFIED_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3759 | else if (eventType == eventNames().DOMNodeInsertedEvent) |
adamk@chromium.org | fdf6346 | 2012-08-21 01:14:51 +0000 | [diff] [blame] | 3760 | addMutationEventListenerTypeIfEnabled(DOMNODEINSERTED_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3761 | else if (eventType == eventNames().DOMNodeRemovedEvent) |
adamk@chromium.org | fdf6346 | 2012-08-21 01:14:51 +0000 | [diff] [blame] | 3762 | addMutationEventListenerTypeIfEnabled(DOMNODEREMOVED_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3763 | else if (eventType == eventNames().DOMNodeRemovedFromDocumentEvent) |
adamk@chromium.org | fdf6346 | 2012-08-21 01:14:51 +0000 | [diff] [blame] | 3764 | addMutationEventListenerTypeIfEnabled(DOMNODEREMOVEDFROMDOCUMENT_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3765 | else if (eventType == eventNames().DOMNodeInsertedIntoDocumentEvent) |
adamk@chromium.org | fdf6346 | 2012-08-21 01:14:51 +0000 | [diff] [blame] | 3766 | addMutationEventListenerTypeIfEnabled(DOMNODEINSERTEDINTODOCUMENT_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3767 | else if (eventType == eventNames().DOMCharacterDataModifiedEvent) |
adamk@chromium.org | fdf6346 | 2012-08-21 01:14:51 +0000 | [diff] [blame] | 3768 | addMutationEventListenerTypeIfEnabled(DOMCHARACTERDATAMODIFIED_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3769 | else if (eventType == eventNames().overflowchangedEvent) |
zimmermann@webkit.org | 97c7108 | 2008-09-24 00:23:28 +0000 | [diff] [blame] | 3770 | addListenerType(OVERFLOWCHANGED_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3771 | else if (eventType == eventNames().webkitAnimationStartEvent) |
zimmermann@webkit.org | 97c7108 | 2008-09-24 00:23:28 +0000 | [diff] [blame] | 3772 | addListenerType(ANIMATIONSTART_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3773 | else if (eventType == eventNames().webkitAnimationEndEvent) |
zimmermann@webkit.org | 97c7108 | 2008-09-24 00:23:28 +0000 | [diff] [blame] | 3774 | addListenerType(ANIMATIONEND_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3775 | else if (eventType == eventNames().webkitAnimationIterationEvent) |
zimmermann@webkit.org | 97c7108 | 2008-09-24 00:23:28 +0000 | [diff] [blame] | 3776 | addListenerType(ANIMATIONITERATION_LISTENER); |
ap@webkit.org | c5e3f1b | 2008-11-04 10:46:13 +0000 | [diff] [blame] | 3777 | else if (eventType == eventNames().webkitTransitionEndEvent) |
zimmermann@webkit.org | 97c7108 | 2008-09-24 00:23:28 +0000 | [diff] [blame] | 3778 | addListenerType(TRANSITIONEND_LISTENER); |
hyatt@apple.com | f10dc6b | 2009-10-09 17:03:48 +0000 | [diff] [blame] | 3779 | else if (eventType == eventNames().beforeloadEvent) |
| 3780 | addListenerType(BEFORELOAD_LISTENER); |
simon.fraser@apple.com | 5e4454c | 2011-06-15 23:02:48 +0000 | [diff] [blame] | 3781 | else if (eventType == eventNames().scrollEvent) |
| 3782 | addListenerType(SCROLL_LISTENER); |
zimmermann@webkit.org | 97c7108 | 2008-09-24 00:23:28 +0000 | [diff] [blame] | 3783 | } |
| 3784 | |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3785 | CSSStyleDeclaration* Document::getOverrideStyle(Element*, const String&) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3786 | { |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 3787 | return 0; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
simon.fraser@apple.com | bab14a9 | 2010-07-07 20:04:32 +0000 | [diff] [blame] | 3790 | HTMLFrameOwnerElement* Document::ownerElement() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3791 | { |
| 3792 | if (!frame()) |
| 3793 | return 0; |
| 3794 | return frame()->ownerElement(); |
| 3795 | } |
| 3796 | |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3797 | String Document::cookie(ExceptionCode& ec) const |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 3798 | { |
commit-queue@webkit.org | c8870db | 2012-06-20 23:49:53 +0000 | [diff] [blame] | 3799 | if (page() && !page()->settings()->cookieEnabled()) |
mitz@apple.com | b7f8848 | 2008-10-31 23:35:00 +0000 | [diff] [blame] | 3800 | return String(); |
| 3801 | |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3802 | // FIXME: The HTML5 DOM spec states that this attribute can raise an |
| 3803 | // INVALID_STATE_ERR exception on getting if the Document has no |
| 3804 | // browsing context. |
| 3805 | |
abarth@webkit.org | 907caeb | 2010-01-10 08:10:00 +0000 | [diff] [blame] | 3806 | if (!securityOrigin()->canAccessCookies()) { |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3807 | ec = SECURITY_ERR; |
| 3808 | return String(); |
| 3809 | } |
| 3810 | |
adele@apple.com | d4ac299 | 2008-12-29 21:42:33 +0000 | [diff] [blame] | 3811 | KURL cookieURL = this->cookieURL(); |
| 3812 | if (cookieURL.isEmpty()) |
| 3813 | return String(); |
| 3814 | |
| 3815 | return cookies(this, cookieURL); |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3818 | void Document::setCookie(const String& value, ExceptionCode& ec) |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 3819 | { |
commit-queue@webkit.org | c8870db | 2012-06-20 23:49:53 +0000 | [diff] [blame] | 3820 | if (page() && !page()->settings()->cookieEnabled()) |
mitz@apple.com | b7f8848 | 2008-10-31 23:35:00 +0000 | [diff] [blame] | 3821 | return; |
| 3822 | |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3823 | // FIXME: The HTML5 DOM spec states that this attribute can raise an |
| 3824 | // INVALID_STATE_ERR exception on setting if the Document has no |
| 3825 | // browsing context. |
| 3826 | |
abarth@webkit.org | 907caeb | 2010-01-10 08:10:00 +0000 | [diff] [blame] | 3827 | if (!securityOrigin()->canAccessCookies()) { |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3828 | ec = SECURITY_ERR; |
| 3829 | return; |
| 3830 | } |
| 3831 | |
adele@apple.com | d4ac299 | 2008-12-29 21:42:33 +0000 | [diff] [blame] | 3832 | KURL cookieURL = this->cookieURL(); |
| 3833 | if (cookieURL.isEmpty()) |
| 3834 | return; |
| 3835 | |
abarth@webkit.org | 6764679 | 2009-05-22 16:45:32 +0000 | [diff] [blame] | 3836 | setCookies(this, cookieURL, value); |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 3837 | } |
| 3838 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3839 | String Document::referrer() const |
| 3840 | { |
| 3841 | if (frame()) |
ggaren | b2497d8 | 2006-10-28 01:22:13 +0000 | [diff] [blame] | 3842 | return frame()->loader()->referrer(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3843 | return String(); |
| 3844 | } |
| 3845 | |
| 3846 | String Document::domain() const |
| 3847 | { |
ap@webkit.org | 0497fce | 2008-12-02 08:49:06 +0000 | [diff] [blame] | 3848 | return securityOrigin()->domain(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
eric@webkit.org | e13621e | 2009-09-25 17:53:43 +0000 | [diff] [blame] | 3851 | void Document::setDomain(const String& newDomain, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3852 | { |
abarth@webkit.org | 8e056b0 | 2011-11-08 01:37:47 +0000 | [diff] [blame] | 3853 | if (SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(securityOrigin()->protocol())) { |
aroben@apple.com | 9ca1e9e | 2010-01-18 21:26:39 +0000 | [diff] [blame] | 3854 | ec = SECURITY_ERR; |
| 3855 | return; |
| 3856 | } |
| 3857 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3858 | // Both NS and IE specify that changing the domain is only allowed when |
| 3859 | // the new domain is a suffix of the old domain. |
weinig | c1cac71 | 2007-07-30 18:29:29 +0000 | [diff] [blame] | 3860 | |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3861 | // FIXME: We should add logging indicating why a domain was not allowed. |
| 3862 | |
| 3863 | // If the new domain is the same as the old domain, still call |
ap@webkit.org | 0497fce | 2008-12-02 08:49:06 +0000 | [diff] [blame] | 3864 | // securityOrigin()->setDomainForDOM. This will change the |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3865 | // security check behavior. For example, if a page loaded on port 8000 |
| 3866 | // assigns its current domain using document.domain, the page will |
| 3867 | // allow other pages loaded on different ports in the same domain that |
| 3868 | // have also assigned to access this page. |
weinig@apple.com | 6432161 | 2007-12-20 22:39:51 +0000 | [diff] [blame] | 3869 | if (equalIgnoringCase(domain(), newDomain)) { |
ap@webkit.org | 0497fce | 2008-12-02 08:49:06 +0000 | [diff] [blame] | 3870 | securityOrigin()->setDomainFromDOM(newDomain); |
abarth@webkit.org | 24d63ef | 2008-12-10 06:48:36 +0000 | [diff] [blame] | 3871 | if (m_frame) |
| 3872 | m_frame->script()->updateSecurityOrigin(); |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3873 | return; |
| 3874 | } |
weinig | c1cac71 | 2007-07-30 18:29:29 +0000 | [diff] [blame] | 3875 | |
weinig@apple.com | 6432161 | 2007-12-20 22:39:51 +0000 | [diff] [blame] | 3876 | int oldLength = domain().length(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3877 | int newLength = newDomain.length(); |
weinig@apple.com | 6432161 | 2007-12-20 22:39:51 +0000 | [diff] [blame] | 3878 | // e.g. newDomain = webkit.org (10) and domain() = www.webkit.org (14) |
eric@webkit.org | e13621e | 2009-09-25 17:53:43 +0000 | [diff] [blame] | 3879 | if (newLength >= oldLength) { |
| 3880 | ec = SECURITY_ERR; |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3881 | return; |
eric@webkit.org | e13621e | 2009-09-25 17:53:43 +0000 | [diff] [blame] | 3882 | } |
weinig | e06430a | 2007-10-19 20:53:22 +0000 | [diff] [blame] | 3883 | |
darin@apple.com | 4db8bb1 | 2008-01-13 19:19:41 +0000 | [diff] [blame] | 3884 | String test = domain(); |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3885 | // Check that it's a subdomain, not e.g. "ebkit.org" |
eric@webkit.org | e13621e | 2009-09-25 17:53:43 +0000 | [diff] [blame] | 3886 | if (test[oldLength - newLength - 1] != '.') { |
| 3887 | ec = SECURITY_ERR; |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3888 | return; |
eric@webkit.org | e13621e | 2009-09-25 17:53:43 +0000 | [diff] [blame] | 3889 | } |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3890 | |
weinig@apple.com | 6432161 | 2007-12-20 22:39:51 +0000 | [diff] [blame] | 3891 | // Now test is "webkit.org" from domain() |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3892 | // and we check that it's the same thing as newDomain |
| 3893 | test.remove(0, oldLength - newLength); |
eric@webkit.org | e13621e | 2009-09-25 17:53:43 +0000 | [diff] [blame] | 3894 | if (test != newDomain) { |
| 3895 | ec = SECURITY_ERR; |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3896 | return; |
eric@webkit.org | e13621e | 2009-09-25 17:53:43 +0000 | [diff] [blame] | 3897 | } |
weinig@apple.com | d878868 | 2007-11-27 01:52:43 +0000 | [diff] [blame] | 3898 | |
ap@webkit.org | 0497fce | 2008-12-02 08:49:06 +0000 | [diff] [blame] | 3899 | securityOrigin()->setDomainFromDOM(newDomain); |
abarth@webkit.org | 24d63ef | 2008-12-10 06:48:36 +0000 | [diff] [blame] | 3900 | if (m_frame) |
| 3901 | m_frame->script()->updateSecurityOrigin(); |
weinig | c1cac71 | 2007-07-30 18:29:29 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
abarth@webkit.org | 6dbb21c | 2010-09-14 23:29:38 +0000 | [diff] [blame] | 3904 | // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-lastmodified |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 3905 | String Document::lastModified() const |
| 3906 | { |
abarth@webkit.org | 6dbb21c | 2010-09-14 23:29:38 +0000 | [diff] [blame] | 3907 | DateComponents date; |
| 3908 | bool foundDate = false; |
| 3909 | if (m_frame) { |
beidson@apple.com | 197fbd3 | 2011-05-31 22:13:06 +0000 | [diff] [blame] | 3910 | String httpLastModified; |
| 3911 | if (DocumentLoader* documentLoader = loader()) |
| 3912 | httpLastModified = documentLoader->response().httpHeaderField("Last-Modified"); |
abarth@webkit.org | 6dbb21c | 2010-09-14 23:29:38 +0000 | [diff] [blame] | 3913 | if (!httpLastModified.isEmpty()) { |
| 3914 | date.setMillisecondsSinceEpochForDateTime(parseDate(httpLastModified)); |
| 3915 | foundDate = true; |
| 3916 | } |
| 3917 | } |
| 3918 | // FIXME: If this document came from the file system, the HTML5 |
| 3919 | // specificiation tells us to read the last modification date from the file |
| 3920 | // system. |
| 3921 | if (!foundDate) |
| 3922 | date.setMillisecondsSinceEpochForDateTime(currentTimeMS()); |
| 3923 | return String::format("%02d/%02d/%04d %02d:%02d:%02d", date.month() + 1, date.monthDay(), date.fullYear(), date.hour(), date.minute(), date.second()); |
oliver | 9119a9c | 2007-10-12 15:13:16 +0000 | [diff] [blame] | 3924 | } |
| 3925 | |
darin@apple.com | a4fc32d | 2008-03-25 03:26:02 +0000 | [diff] [blame] | 3926 | static bool isValidNameNonASCII(const UChar* characters, unsigned length) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3927 | { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3928 | unsigned i = 0; |
| 3929 | |
| 3930 | UChar32 c; |
darin@apple.com | a4fc32d | 2008-03-25 03:26:02 +0000 | [diff] [blame] | 3931 | U16_NEXT(characters, i, length, c) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3932 | if (!isValidNameStart(c)) |
| 3933 | return false; |
| 3934 | |
| 3935 | while (i < length) { |
darin@apple.com | a4fc32d | 2008-03-25 03:26:02 +0000 | [diff] [blame] | 3936 | U16_NEXT(characters, i, length, c) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3937 | if (!isValidNamePart(c)) |
| 3938 | return false; |
| 3939 | } |
| 3940 | |
| 3941 | return true; |
| 3942 | } |
| 3943 | |
commit-queue@webkit.org | 44da644 | 2011-12-19 08:11:24 +0000 | [diff] [blame] | 3944 | template<typename CharType> |
| 3945 | static inline bool isValidNameASCII(const CharType* characters, unsigned length) |
darin@apple.com | a4fc32d | 2008-03-25 03:26:02 +0000 | [diff] [blame] | 3946 | { |
commit-queue@webkit.org | 44da644 | 2011-12-19 08:11:24 +0000 | [diff] [blame] | 3947 | CharType c = characters[0]; |
darin@apple.com | a4fc32d | 2008-03-25 03:26:02 +0000 | [diff] [blame] | 3948 | if (!(isASCIIAlpha(c) || c == ':' || c == '_')) |
| 3949 | return false; |
| 3950 | |
| 3951 | for (unsigned i = 1; i < length; ++i) { |
| 3952 | c = characters[i]; |
| 3953 | if (!(isASCIIAlphanumeric(c) || c == ':' || c == '_' || c == '-' || c == '.')) |
| 3954 | return false; |
| 3955 | } |
| 3956 | |
| 3957 | return true; |
| 3958 | } |
| 3959 | |
| 3960 | bool Document::isValidName(const String& name) |
| 3961 | { |
| 3962 | unsigned length = name.length(); |
| 3963 | if (!length) |
| 3964 | return false; |
| 3965 | |
commit-queue@webkit.org | 44da644 | 2011-12-19 08:11:24 +0000 | [diff] [blame] | 3966 | const UChar* characters; |
| 3967 | if (name.is8Bit()) { |
| 3968 | if (isValidNameASCII(name.characters8(), length)) |
| 3969 | return true; |
| 3970 | characters = name.characters(); |
| 3971 | } else { |
| 3972 | characters = name.characters16(); |
| 3973 | if (isValidNameASCII(characters, length)) |
| 3974 | return true; |
| 3975 | } |
| 3976 | return isValidNameNonASCII(characters, length); |
darin@apple.com | a4fc32d | 2008-03-25 03:26:02 +0000 | [diff] [blame] | 3977 | } |
| 3978 | |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 3979 | bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode& ec) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3980 | { |
| 3981 | unsigned length = qualifiedName.length(); |
| 3982 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 3983 | if (!length) { |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 3984 | ec = INVALID_CHARACTER_ERR; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3985 | return false; |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 3986 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3987 | |
| 3988 | bool nameStart = true; |
| 3989 | bool sawColon = false; |
| 3990 | int colonPos = 0; |
| 3991 | |
eric@webkit.org | 87d855b | 2008-03-10 22:06:44 +0000 | [diff] [blame] | 3992 | const UChar* s = qualifiedName.characters(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3993 | for (unsigned i = 0; i < length;) { |
| 3994 | UChar32 c; |
| 3995 | U16_NEXT(s, i, length, c) |
| 3996 | if (c == ':') { |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 3997 | if (sawColon) { |
| 3998 | ec = NAMESPACE_ERR; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 3999 | return false; // multiple colons: not allowed |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 4000 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4001 | nameStart = true; |
| 4002 | sawColon = true; |
| 4003 | colonPos = i - 1; |
| 4004 | } else if (nameStart) { |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 4005 | if (!isValidNameStart(c)) { |
| 4006 | ec = INVALID_CHARACTER_ERR; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4007 | return false; |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 4008 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4009 | nameStart = false; |
| 4010 | } else { |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 4011 | if (!isValidNamePart(c)) { |
| 4012 | ec = INVALID_CHARACTER_ERR; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4013 | return false; |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 4014 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4015 | } |
| 4016 | } |
| 4017 | |
| 4018 | if (!sawColon) { |
| 4019 | prefix = String(); |
darin@apple.com | 4db8bb1 | 2008-01-13 19:19:41 +0000 | [diff] [blame] | 4020 | localName = qualifiedName; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4021 | } else { |
| 4022 | prefix = qualifiedName.substring(0, colonPos); |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 4023 | if (prefix.isEmpty()) { |
| 4024 | ec = NAMESPACE_ERR; |
| 4025 | return false; |
| 4026 | } |
darin@apple.com | 4db8bb1 | 2008-01-13 19:19:41 +0000 | [diff] [blame] | 4027 | localName = qualifiedName.substring(colonPos + 1); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4028 | } |
| 4029 | |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 4030 | if (localName.isEmpty()) { |
| 4031 | ec = NAMESPACE_ERR; |
| 4032 | return false; |
| 4033 | } |
| 4034 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4035 | return true; |
| 4036 | } |
| 4037 | |
darin@apple.com | 642f500 | 2008-06-07 22:51:37 +0000 | [diff] [blame] | 4038 | void Document::setDecoder(PassRefPtr<TextResourceDecoder> decoder) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4039 | { |
| 4040 | m_decoder = decoder; |
| 4041 | } |
| 4042 | |
abarth@webkit.org | e18d059 | 2012-02-01 04:07:52 +0000 | [diff] [blame] | 4043 | KURL Document::completeURL(const String& url, const KURL& baseURLOverride) const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4044 | { |
darin@apple.com | 640fa30 | 2008-02-15 05:03:55 +0000 | [diff] [blame] | 4045 | // Always return a null URL when passed a null string. |
| 4046 | // FIXME: Should we change the KURL constructor to have this behavior? |
ddkilzer@apple.com | e9a5504 | 2008-12-23 00:00:14 +0000 | [diff] [blame] | 4047 | // See also [CSS]StyleSheet::completeURL(const String&) |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 4048 | if (url.isNull()) |
darin@apple.com | 640fa30 | 2008-02-15 05:03:55 +0000 | [diff] [blame] | 4049 | return KURL(); |
abarth@webkit.org | e18d059 | 2012-02-01 04:07:52 +0000 | [diff] [blame] | 4050 | const KURL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == blankURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride; |
darin@apple.com | 640fa30 | 2008-02-15 05:03:55 +0000 | [diff] [blame] | 4051 | if (!m_decoder) |
ddkilzer@apple.com | a6df999 | 2009-03-24 21:40:24 +0000 | [diff] [blame] | 4052 | return KURL(baseURL, url); |
| 4053 | return KURL(baseURL, url, m_decoder->encoding()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4054 | } |
| 4055 | |
abarth@webkit.org | e18d059 | 2012-02-01 04:07:52 +0000 | [diff] [blame] | 4056 | KURL Document::completeURL(const String& url) const |
| 4057 | { |
| 4058 | return completeURL(url, m_baseURL); |
| 4059 | } |
| 4060 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4061 | void Document::setInPageCache(bool flag) |
| 4062 | { |
| 4063 | if (m_inPageCache == flag) |
| 4064 | return; |
| 4065 | |
| 4066 | m_inPageCache = flag; |
bdakin@apple.com | c7a8e42 | 2011-05-10 22:37:15 +0000 | [diff] [blame] | 4067 | |
| 4068 | FrameView* v = view(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4069 | if (flag) { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 4070 | ASSERT(!m_savedRenderer); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4071 | m_savedRenderer = renderer(); |
bdakin@apple.com | c7a8e42 | 2011-05-10 22:37:15 +0000 | [diff] [blame] | 4072 | if (v) { |
bdakin@apple.com | d1b045c | 2011-04-22 22:10:21 +0000 | [diff] [blame] | 4073 | v->cacheCurrentScrollPosition(); |
| 4074 | if (page() && page()->mainFrame() == m_frame) |
| 4075 | v->resetScrollbarsAndClearContentsSize(); |
| 4076 | else |
| 4077 | v->resetScrollbars(); |
| 4078 | } |
hyatt@apple.com | 8dd0d93 | 2010-08-26 18:17:59 +0000 | [diff] [blame] | 4079 | m_styleRecalcTimer.stop(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4080 | } else { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 4081 | ASSERT(!renderer() || renderer() == m_savedRenderer); |
eseidel | fe32643 | 2006-04-25 05:00:39 +0000 | [diff] [blame] | 4082 | ASSERT(m_renderArena); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4083 | setRenderer(m_savedRenderer); |
| 4084 | m_savedRenderer = 0; |
luiz@webkit.org | e0514c5 | 2010-09-24 21:54:25 +0000 | [diff] [blame] | 4085 | |
hyatt@apple.com | 094f41b | 2009-04-13 17:14:44 +0000 | [diff] [blame] | 4086 | if (childNeedsStyleRecalc()) |
| 4087 | scheduleStyleRecalc(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4088 | } |
| 4089 | } |
| 4090 | |
beidson@apple.com | a675a9d | 2011-12-17 00:32:40 +0000 | [diff] [blame] | 4091 | void Document::documentWillBecomeInactive() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4092 | { |
simon.fraser@apple.com | 8f9c77b | 2009-02-06 17:05:07 +0000 | [diff] [blame] | 4093 | #if USE(ACCELERATED_COMPOSITING) |
| 4094 | if (renderer()) |
| 4095 | renderView()->willMoveOffscreen(); |
| 4096 | #endif |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4097 | } |
| 4098 | |
beidson@apple.com | a675a9d | 2011-12-17 00:32:40 +0000 | [diff] [blame] | 4099 | void Document::documentWillSuspendForPageCache() |
| 4100 | { |
| 4101 | documentWillBecomeInactive(); |
| 4102 | |
| 4103 | HashSet<Element*>::iterator end = m_documentSuspensionCallbackElements.end(); |
| 4104 | for (HashSet<Element*>::iterator i = m_documentSuspensionCallbackElements.begin(); i != end; ++i) |
| 4105 | (*i)->documentWillSuspendForPageCache(); |
commit-queue@webkit.org | 7adcbd8 | 2012-05-02 13:00:47 +0000 | [diff] [blame] | 4106 | |
| 4107 | #ifndef NDEBUG |
| 4108 | // Clear the update flag to be able to check if the viewport arguments update |
| 4109 | // is dispatched, after the document is restored from the page cache. |
| 4110 | m_didDispatchViewportPropertiesChanged = false; |
| 4111 | #endif |
beidson@apple.com | a675a9d | 2011-12-17 00:32:40 +0000 | [diff] [blame] | 4112 | } |
| 4113 | |
| 4114 | void Document::documentDidResumeFromPageCache() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4115 | { |
beidson@apple.com | 343e49b | 2011-12-12 22:00:31 +0000 | [diff] [blame] | 4116 | Vector<Element*> elements; |
beidson@apple.com | a675a9d | 2011-12-17 00:32:40 +0000 | [diff] [blame] | 4117 | copyToVector(m_documentSuspensionCallbackElements, elements); |
beidson@apple.com | 343e49b | 2011-12-12 22:00:31 +0000 | [diff] [blame] | 4118 | Vector<Element*>::iterator end = elements.end(); |
| 4119 | for (Vector<Element*>::iterator i = elements.begin(); i != end; ++i) |
beidson@apple.com | a675a9d | 2011-12-17 00:32:40 +0000 | [diff] [blame] | 4120 | (*i)->documentDidResumeFromPageCache(); |
simon.fraser@apple.com | 8f9c77b | 2009-02-06 17:05:07 +0000 | [diff] [blame] | 4121 | |
| 4122 | #if USE(ACCELERATED_COMPOSITING) |
| 4123 | if (renderer()) |
| 4124 | renderView()->didMoveOnscreen(); |
| 4125 | #endif |
ap@apple.com | 43af8a8 | 2010-10-29 17:23:55 +0000 | [diff] [blame] | 4126 | |
bdakin@apple.com | 8a57afc | 2011-06-15 23:13:23 +0000 | [diff] [blame] | 4127 | if (FrameView* frameView = view()) |
| 4128 | frameView->setAnimatorsAreActive(); |
| 4129 | |
ap@apple.com | 43af8a8 | 2010-10-29 17:23:55 +0000 | [diff] [blame] | 4130 | ASSERT(m_frame); |
| 4131 | m_frame->loader()->client()->dispatchDidBecomeFrameset(isFrameSet()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4132 | } |
| 4133 | |
beidson@apple.com | a675a9d | 2011-12-17 00:32:40 +0000 | [diff] [blame] | 4134 | void Document::registerForPageCacheSuspensionCallbacks(Element* e) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4135 | { |
beidson@apple.com | a675a9d | 2011-12-17 00:32:40 +0000 | [diff] [blame] | 4136 | m_documentSuspensionCallbackElements.add(e); |
antti | 76787a8 | 2007-10-31 01:03:35 +0000 | [diff] [blame] | 4137 | } |
| 4138 | |
beidson@apple.com | a675a9d | 2011-12-17 00:32:40 +0000 | [diff] [blame] | 4139 | void Document::unregisterForPageCacheSuspensionCallbacks(Element* e) |
antti | 76787a8 | 2007-10-31 01:03:35 +0000 | [diff] [blame] | 4140 | { |
beidson@apple.com | a675a9d | 2011-12-17 00:32:40 +0000 | [diff] [blame] | 4141 | m_documentSuspensionCallbackElements.remove(e); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4142 | } |
| 4143 | |
mitz@apple.com | 44d57d4 | 2008-11-11 22:45:16 +0000 | [diff] [blame] | 4144 | void Document::mediaVolumeDidChange() |
| 4145 | { |
| 4146 | HashSet<Element*>::iterator end = m_mediaVolumeCallbackElements.end(); |
| 4147 | for (HashSet<Element*>::iterator i = m_mediaVolumeCallbackElements.begin(); i != end; ++i) |
| 4148 | (*i)->mediaVolumeDidChange(); |
| 4149 | } |
| 4150 | |
| 4151 | void Document::registerForMediaVolumeCallbacks(Element* e) |
| 4152 | { |
| 4153 | m_mediaVolumeCallbackElements.add(e); |
| 4154 | } |
| 4155 | |
| 4156 | void Document::unregisterForMediaVolumeCallbacks(Element* e) |
| 4157 | { |
| 4158 | m_mediaVolumeCallbackElements.remove(e); |
| 4159 | } |
| 4160 | |
jpfau@apple.com | aaef731 | 2012-09-14 21:30:42 +0000 | [diff] [blame] | 4161 | void Document::storageBlockingStateDidChange() |
| 4162 | { |
| 4163 | if (Settings* settings = this->settings()) |
| 4164 | securityOrigin()->setStorageBlockingPolicy(settings->storageBlockingPolicy()); |
| 4165 | } |
| 4166 | |
eric.carlson@apple.com | 98deeaa | 2011-03-01 20:54:37 +0000 | [diff] [blame] | 4167 | void Document::privateBrowsingStateDidChange() |
| 4168 | { |
| 4169 | HashSet<Element*>::iterator end = m_privateBrowsingStateChangedElements.end(); |
| 4170 | for (HashSet<Element*>::iterator it = m_privateBrowsingStateChangedElements.begin(); it != end; ++it) |
| 4171 | (*it)->privateBrowsingStateDidChange(); |
| 4172 | } |
| 4173 | |
| 4174 | void Document::registerForPrivateBrowsingStateChangedCallbacks(Element* e) |
| 4175 | { |
| 4176 | m_privateBrowsingStateChangedElements.add(e); |
| 4177 | } |
| 4178 | |
| 4179 | void Document::unregisterForPrivateBrowsingStateChangedCallbacks(Element* e) |
| 4180 | { |
| 4181 | m_privateBrowsingStateChangedElements.remove(e); |
| 4182 | } |
| 4183 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4184 | void Document::setShouldCreateRenderers(bool f) |
| 4185 | { |
| 4186 | m_createRenderers = f; |
| 4187 | } |
| 4188 | |
| 4189 | bool Document::shouldCreateRenderers() |
| 4190 | { |
| 4191 | return m_createRenderers; |
| 4192 | } |
| 4193 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4194 | // Support for Javascript execCommand, and related methods |
| 4195 | |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4196 | static Editor::Command command(Document* document, const String& commandName, bool userInterface = false) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4197 | { |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4198 | Frame* frame = document->frame(); |
| 4199 | if (!frame || frame->document() != document) |
| 4200 | return Editor::Command(); |
simon.fraser@apple.com | 64487f9 | 2010-08-19 17:19:40 +0000 | [diff] [blame] | 4201 | |
| 4202 | document->updateStyleIfNeeded(); |
| 4203 | |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4204 | return frame->editor()->command(commandName, |
| 4205 | userInterface ? CommandFromDOMWithUserInterface : CommandFromDOM); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4206 | } |
| 4207 | |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4208 | bool Document::execCommand(const String& commandName, bool userInterface, const String& value) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4209 | { |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4210 | return command(this, commandName, userInterface).execute(value); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4211 | } |
| 4212 | |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4213 | bool Document::queryCommandEnabled(const String& commandName) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4214 | { |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4215 | return command(this, commandName).isEnabled(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4216 | } |
| 4217 | |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4218 | bool Document::queryCommandIndeterm(const String& commandName) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4219 | { |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4220 | return command(this, commandName).state() == MixedTriState; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4223 | bool Document::queryCommandState(const String& commandName) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4224 | { |
rniwa@webkit.org | 5c713d9 | 2010-09-27 21:10:54 +0000 | [diff] [blame] | 4225 | return command(this, commandName).state() == TrueTriState; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4226 | } |
| 4227 | |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4228 | bool Document::queryCommandSupported(const String& commandName) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4229 | { |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4230 | return command(this, commandName).isSupported(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4231 | } |
| 4232 | |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4233 | String Document::queryCommandValue(const String& commandName) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4234 | { |
darin@apple.com | 5377d7d | 2007-12-11 20:26:56 +0000 | [diff] [blame] | 4235 | return command(this, commandName).value(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4236 | } |
| 4237 | |
abarth@webkit.org | d403605 | 2011-06-23 00:39:10 +0000 | [diff] [blame] | 4238 | KURL Document::openSearchDescriptionURL() |
| 4239 | { |
| 4240 | static const char* const openSearchMIMEType = "application/opensearchdescription+xml"; |
| 4241 | static const char* const openSearchRelation = "search"; |
| 4242 | |
| 4243 | // FIXME: Why do only top-level frames have openSearchDescriptionURLs? |
| 4244 | if (!frame() || frame()->tree()->parent()) |
| 4245 | return KURL(); |
| 4246 | |
| 4247 | // FIXME: Why do we need to wait for FrameStateComplete? |
| 4248 | if (frame()->loader()->state() != FrameStateComplete) |
| 4249 | return KURL(); |
| 4250 | |
| 4251 | if (!head()) |
| 4252 | return KURL(); |
| 4253 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4254 | RefPtr<HTMLCollection> children = head()->children(); |
rniwa@webkit.org | d50a665 | 2012-06-26 06:29:58 +0000 | [diff] [blame] | 4255 | for (unsigned i = 0; Node* child = children->item(i); i++) { |
darin@apple.com | fa0136f | 2011-10-15 07:59:24 +0000 | [diff] [blame] | 4256 | if (!child->hasTagName(linkTag)) |
abarth@webkit.org | d403605 | 2011-06-23 00:39:10 +0000 | [diff] [blame] | 4257 | continue; |
| 4258 | HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(child); |
| 4259 | if (!equalIgnoringCase(linkElement->type(), openSearchMIMEType) || !equalIgnoringCase(linkElement->rel(), openSearchRelation)) |
| 4260 | continue; |
| 4261 | if (linkElement->href().isEmpty()) |
| 4262 | continue; |
| 4263 | return linkElement->href(); |
| 4264 | } |
| 4265 | |
| 4266 | return KURL(); |
| 4267 | } |
| 4268 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 4269 | #if ENABLE(XSLT) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4270 | |
| 4271 | void Document::applyXSLTransform(ProcessingInstruction* pi) |
| 4272 | { |
andersca@apple.com | c442c15 | 2008-02-20 01:55:42 +0000 | [diff] [blame] | 4273 | RefPtr<XSLTProcessor> processor = XSLTProcessor::create(); |
darin@apple.com | 3aa8927 | 2008-06-15 04:32:16 +0000 | [diff] [blame] | 4274 | processor->setXSLStyleSheet(static_cast<XSLStyleSheet*>(pi->sheet())); |
ap | 276970c | 2007-10-29 17:02:51 +0000 | [diff] [blame] | 4275 | String resultMIMEType; |
| 4276 | String newSource; |
| 4277 | String resultEncoding; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4278 | if (!processor->transformToString(this, resultMIMEType, newSource, resultEncoding)) |
| 4279 | return; |
| 4280 | // FIXME: If the transform failed we should probably report an error (like Mozilla does). |
mjs | 22f8a1a | 2007-04-29 07:33:46 +0000 | [diff] [blame] | 4281 | processor->createDocumentFromSource(newSource, resultEncoding, resultMIMEType, this, frame()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4282 | } |
| 4283 | |
hausmann@webkit.org | 06b7e55 | 2009-09-28 20:11:36 +0000 | [diff] [blame] | 4284 | void Document::setTransformSource(PassOwnPtr<TransformSource> source) |
bdash | c4bd53a | 2007-07-12 14:01:41 +0000 | [diff] [blame] | 4285 | { |
hausmann@webkit.org | 06b7e55 | 2009-09-28 20:11:36 +0000 | [diff] [blame] | 4286 | m_transformSource = source; |
bdash | c4bd53a | 2007-07-12 14:01:41 +0000 | [diff] [blame] | 4287 | } |
| 4288 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4289 | #endif |
| 4290 | |
| 4291 | void Document::setDesignMode(InheritedBool value) |
| 4292 | { |
| 4293 | m_designMode = value; |
commit-queue@webkit.org | 713aea4 | 2011-04-29 00:10:34 +0000 | [diff] [blame] | 4294 | for (Frame* frame = m_frame; frame && frame->document(); frame = frame->tree()->traverseNext(m_frame)) |
| 4295 | frame->document()->scheduleForcedStyleRecalc(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | Document::InheritedBool Document::getDesignMode() const |
| 4299 | { |
| 4300 | return m_designMode; |
| 4301 | } |
| 4302 | |
| 4303 | bool Document::inDesignMode() const |
| 4304 | { |
| 4305 | for (const Document* d = this; d; d = d->parentDocument()) { |
| 4306 | if (d->m_designMode != inherit) |
justing | 1c9170e | 2006-07-25 21:06:25 +0000 | [diff] [blame] | 4307 | return d->m_designMode; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4308 | } |
| 4309 | return false; |
| 4310 | } |
| 4311 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 4312 | Document* Document::parentDocument() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4313 | { |
abarth@webkit.org | 345dd26 | 2010-09-10 22:08:41 +0000 | [diff] [blame] | 4314 | if (!m_frame) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4315 | return 0; |
abarth@webkit.org | 345dd26 | 2010-09-10 22:08:41 +0000 | [diff] [blame] | 4316 | Frame* parent = m_frame->tree()->parent(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4317 | if (!parent) |
| 4318 | return 0; |
| 4319 | return parent->document(); |
| 4320 | } |
| 4321 | |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 4322 | Document* Document::topDocument() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4323 | { |
abarth@webkit.org | f77ca5c | 2010-08-07 01:30:16 +0000 | [diff] [blame] | 4324 | Document* doc = const_cast<Document *>(this); |
| 4325 | Element* element; |
beidson | ddbaead | 2006-12-13 23:34:09 +0000 | [diff] [blame] | 4326 | while ((element = doc->ownerElement())) |
ggaren | aa01dc0 | 2006-03-29 00:21:31 +0000 | [diff] [blame] | 4327 | doc = element->document(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4328 | |
| 4329 | return doc; |
| 4330 | } |
| 4331 | |
darin@apple.com | 9a925fa | 2009-05-04 18:00:34 +0000 | [diff] [blame] | 4332 | PassRefPtr<Attr> Document::createAttribute(const String& name, ExceptionCode& ec) |
| 4333 | { |
| 4334 | return createAttributeNS(String(), name, ec, true); |
| 4335 | } |
| 4336 | |
jchaffraix@webkit.org | 17b7c90 | 2008-06-02 19:51:32 +0000 | [diff] [blame] | 4337 | PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec, bool shouldIgnoreNamespaceChecks) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4338 | { |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 4339 | String prefix, localName; |
eric@webkit.org | dc1386a | 2008-03-22 09:50:54 +0000 | [diff] [blame] | 4340 | if (!parseQualifiedName(qualifiedName, prefix, localName, ec)) |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 4341 | return 0; |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 4342 | |
| 4343 | QualifiedName qName(prefix, localName, namespaceURI); |
kmccullough@apple.com | 9aa2a5b | 2008-02-06 22:03:08 +0000 | [diff] [blame] | 4344 | |
abarth@webkit.org | 427e9f1 | 2012-01-19 08:31:13 +0000 | [diff] [blame] | 4345 | if (!shouldIgnoreNamespaceChecks && !hasValidNamespaceForAttributes(qName)) { |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 4346 | ec = NAMESPACE_ERR; |
eric@webkit.org | 63d461e | 2008-02-03 23:46:58 +0000 | [diff] [blame] | 4347 | return 0; |
| 4348 | } |
eric@webkit.org | 4e5ae83 | 2008-03-22 09:49:58 +0000 | [diff] [blame] | 4349 | |
kling@webkit.org | e3f8e9d | 2012-04-23 05:40:02 +0000 | [diff] [blame] | 4350 | return Attr::create(this, qName, emptyString()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4351 | } |
| 4352 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 4353 | #if ENABLE(SVG) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4354 | const SVGDocumentExtensions* Document::svgExtensions() |
| 4355 | { |
zecke@webkit.org | f383449 | 2008-09-20 14:23:55 +0000 | [diff] [blame] | 4356 | return m_svgExtensions.get(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | SVGDocumentExtensions* Document::accessSVGExtensions() |
| 4360 | { |
| 4361 | if (!m_svgExtensions) |
darin@apple.com | 69b3ef4 | 2010-08-31 17:08:40 +0000 | [diff] [blame] | 4362 | m_svgExtensions = adoptPtr(new SVGDocumentExtensions(this)); |
zecke@webkit.org | f383449 | 2008-09-20 14:23:55 +0000 | [diff] [blame] | 4363 | return m_svgExtensions.get(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4364 | } |
commit-queue@webkit.org | 3c4e124 | 2010-09-23 21:36:18 +0000 | [diff] [blame] | 4365 | |
| 4366 | bool Document::hasSVGRootNode() const |
| 4367 | { |
| 4368 | return documentElement() && documentElement()->hasTagName(SVGNames::svgTag); |
| 4369 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4370 | #endif |
| 4371 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4372 | // FIXME: This caching mechanism should be merged that of DynamicNodeList in NodeRareData. |
| 4373 | PassRefPtr<HTMLCollection> Document::cachedCollection(CollectionType type) |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4374 | { |
kling@webkit.org | 66299d6 | 2011-12-16 23:45:29 +0000 | [diff] [blame] | 4375 | ASSERT(static_cast<unsigned>(type) < NumUnnamedDocumentCachedTypes); |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4376 | if (m_collections[type]) |
| 4377 | return m_collections[type]; |
| 4378 | |
| 4379 | RefPtr<HTMLCollection> collection; |
| 4380 | if (type == DocAll) |
| 4381 | collection = HTMLAllCollection::create(this); |
| 4382 | else |
| 4383 | collection = HTMLCollection::create(this, type); |
| 4384 | m_collections[type] = collection.get(); |
| 4385 | |
| 4386 | return collection.release(); |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4387 | } |
| 4388 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4389 | void Document::removeCachedHTMLCollection(HTMLCollection* collection, CollectionType type) |
| 4390 | { |
| 4391 | ASSERT_UNUSED(collection, m_collections[type] == collection); |
| 4392 | m_collections[type] = 0; |
| 4393 | } |
| 4394 | |
| 4395 | PassRefPtr<HTMLCollection> Document::images() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4396 | { |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4397 | return cachedCollection(DocImages); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4398 | } |
| 4399 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4400 | PassRefPtr<HTMLCollection> Document::applets() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4401 | { |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4402 | return cachedCollection(DocApplets); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4403 | } |
| 4404 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4405 | PassRefPtr<HTMLCollection> Document::embeds() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4406 | { |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4407 | return cachedCollection(DocEmbeds); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4408 | } |
| 4409 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4410 | PassRefPtr<HTMLCollection> Document::plugins() |
weinig | 661a37f | 2007-05-23 23:00:20 +0000 | [diff] [blame] | 4411 | { |
| 4412 | // This is an alias for embeds() required for the JS DOM bindings. |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4413 | return cachedCollection(DocEmbeds); |
weinig | 661a37f | 2007-05-23 23:00:20 +0000 | [diff] [blame] | 4414 | } |
| 4415 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4416 | PassRefPtr<HTMLCollection> Document::objects() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4417 | { |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4418 | return cachedCollection(DocObjects); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4421 | PassRefPtr<HTMLCollection> Document::scripts() |
andersca | 1d0b377 | 2006-05-24 19:26:09 +0000 | [diff] [blame] | 4422 | { |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4423 | return cachedCollection(DocScripts); |
andersca | 1d0b377 | 2006-05-24 19:26:09 +0000 | [diff] [blame] | 4424 | } |
| 4425 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4426 | PassRefPtr<HTMLCollection> Document::links() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4427 | { |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4428 | return cachedCollection(DocLinks); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4429 | } |
| 4430 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4431 | PassRefPtr<HTMLCollection> Document::forms() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4432 | { |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4433 | return cachedCollection(DocForms); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4434 | } |
| 4435 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4436 | PassRefPtr<HTMLCollection> Document::anchors() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4437 | { |
kling@webkit.org | 3e527e9 | 2011-12-16 23:11:11 +0000 | [diff] [blame] | 4438 | return cachedCollection(DocAnchors); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4439 | } |
| 4440 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4441 | PassRefPtr<HTMLCollection> Document::all() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4442 | { |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4443 | return cachedCollection(DocAll); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4444 | } |
| 4445 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4446 | PassRefPtr<HTMLCollection> Document::windowNamedItems(const AtomicString& name) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4447 | { |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4448 | NamedCollectionMap::AddResult result = m_windowNamedItemCollections.add(name, 0); |
| 4449 | if (!result.isNewEntry) |
commit-queue@webkit.org | fa6afbc | 2012-08-28 20:54:45 +0000 | [diff] [blame] | 4450 | return result.iterator->second; |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4451 | |
| 4452 | RefPtr<HTMLNameCollection> collection = HTMLNameCollection::create(this, WindowNamedItems, name); |
commit-queue@webkit.org | fa6afbc | 2012-08-28 20:54:45 +0000 | [diff] [blame] | 4453 | result.iterator->second = collection.get(); |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4454 | return collection.release(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4455 | } |
| 4456 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4457 | PassRefPtr<HTMLCollection> Document::documentNamedItems(const AtomicString& name) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4458 | { |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4459 | NamedCollectionMap::AddResult result = m_documentNamedItemCollections.add(name, 0); |
| 4460 | if (!result.isNewEntry) |
commit-queue@webkit.org | fa6afbc | 2012-08-28 20:54:45 +0000 | [diff] [blame] | 4461 | return result.iterator->second; |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4462 | |
| 4463 | RefPtr<HTMLNameCollection> collection = HTMLNameCollection::create(this, DocumentNamedItems, name); |
commit-queue@webkit.org | fa6afbc | 2012-08-28 20:54:45 +0000 | [diff] [blame] | 4464 | result.iterator->second = collection.get(); |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 4465 | return collection.release(); |
| 4466 | } |
| 4467 | |
| 4468 | // FIXME: This caching mechanism should be merged that of DynamicNodeList in NodeRareData. |
| 4469 | void Document::removeWindowNamedItemCache(HTMLCollection* collection, const AtomicString& name) |
| 4470 | { |
| 4471 | ASSERT_UNUSED(collection, m_windowNamedItemCollections.get(name) == collection); |
| 4472 | m_windowNamedItemCollections.remove(name); |
| 4473 | } |
| 4474 | |
| 4475 | void Document::removeDocumentNamedItemCache(HTMLCollection* collection, const AtomicString& name) |
| 4476 | { |
| 4477 | ASSERT_UNUSED(collection, m_documentNamedItemCollections.get(name) == collection); |
| 4478 | m_documentNamedItemCollections.remove(name); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4479 | } |
| 4480 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4481 | void Document::finishedParsing() |
| 4482 | { |
tonyg@chromium.org | d299d8a7 | 2010-09-06 18:32:48 +0000 | [diff] [blame] | 4483 | ASSERT(!scriptableDocumentParser() || !m_parser->isParsing()); |
| 4484 | ASSERT(!scriptableDocumentParser() || m_readyState != Loading); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4485 | setParsing(false); |
tonyg@chromium.org | 64d18d9 | 2010-12-18 09:23:56 +0000 | [diff] [blame] | 4486 | if (!m_documentTiming.domContentLoadedEventStart) |
simonjam@chromium.org | dfab5cf | 2011-12-15 18:45:29 +0000 | [diff] [blame] | 4487 | m_documentTiming.domContentLoadedEventStart = monotonicallyIncreasingTime(); |
ggaren@apple.com | 521f64b | 2009-09-24 05:53:23 +0000 | [diff] [blame] | 4488 | dispatchEvent(Event::create(eventNames().DOMContentLoadedEvent, true, false)); |
tonyg@chromium.org | 64d18d9 | 2010-12-18 09:23:56 +0000 | [diff] [blame] | 4489 | if (!m_documentTiming.domContentLoadedEventEnd) |
simonjam@chromium.org | dfab5cf | 2011-12-15 18:45:29 +0000 | [diff] [blame] | 4490 | m_documentTiming.domContentLoadedEventEnd = monotonicallyIncreasingTime(); |
jamesr@google.com | ee0be31 | 2010-04-06 03:08:45 +0000 | [diff] [blame] | 4491 | |
inferno@chromium.org | a2e1c25 | 2011-06-16 21:27:30 +0000 | [diff] [blame] | 4492 | if (RefPtr<Frame> f = frame()) { |
jamesr@google.com | ee0be31 | 2010-04-06 03:08:45 +0000 | [diff] [blame] | 4493 | // FrameLoader::finishedParsing() might end up calling Document::implicitClose() if all |
| 4494 | // resource loads are complete. HTMLObjectElements can start loading their resources from |
| 4495 | // post attach callbacks triggered by recalcStyle(). This means if we parse out an <object> |
| 4496 | // tag and then reach the end of the document without updating styles, we might not have yet |
| 4497 | // started the resource load and might fire the window load event too early. To avoid this |
| 4498 | // we force the styles to be up to date before calling FrameLoader::finishedParsing(). |
| 4499 | // See https://bugs.webkit.org/show_bug.cgi?id=36864 starting around comment 35. |
| 4500 | updateStyleIfNeeded(); |
| 4501 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 4502 | f->loader()->finishedParsing(); |
bweinstein@apple.com | 1c773e2 | 2009-10-02 20:01:46 +0000 | [diff] [blame] | 4503 | |
vsevik@chromium.org | 29510e2 | 2011-09-23 10:46:54 +0000 | [diff] [blame] | 4504 | InspectorInstrumentation::domContentLoadedEventFired(f.get()); |
eric@webkit.org | f3d9422 | 2009-10-11 22:34:05 +0000 | [diff] [blame] | 4505 | } |
kling@webkit.org | 7c57578 | 2012-09-04 02:19:26 +0000 | [diff] [blame] | 4506 | |
| 4507 | // The ElementAttributeData sharing cache is only used during parsing since |
| 4508 | // that's when the majority of immutable attribute data will be created. |
| 4509 | m_immutableAttributeDataCache.clear(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4510 | } |
| 4511 | |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 4512 | PassRefPtr<XPathExpression> Document::createExpression(const String& expression, |
| 4513 | XPathNSResolver* resolver, |
| 4514 | ExceptionCode& ec) |
| 4515 | { |
| 4516 | if (!m_xpathEvaluator) |
andersca@apple.com | c442c15 | 2008-02-20 01:55:42 +0000 | [diff] [blame] | 4517 | m_xpathEvaluator = XPathEvaluator::create(); |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 4518 | return m_xpathEvaluator->createExpression(expression, resolver, ec); |
| 4519 | } |
| 4520 | |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 4521 | PassRefPtr<XPathNSResolver> Document::createNSResolver(Node* nodeResolver) |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 4522 | { |
| 4523 | if (!m_xpathEvaluator) |
andersca@apple.com | c442c15 | 2008-02-20 01:55:42 +0000 | [diff] [blame] | 4524 | m_xpathEvaluator = XPathEvaluator::create(); |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 4525 | return m_xpathEvaluator->createNSResolver(nodeResolver); |
| 4526 | } |
| 4527 | |
| 4528 | PassRefPtr<XPathResult> Document::evaluate(const String& expression, |
| 4529 | Node* contextNode, |
| 4530 | XPathNSResolver* resolver, |
| 4531 | unsigned short type, |
| 4532 | XPathResult* result, |
| 4533 | ExceptionCode& ec) |
| 4534 | { |
| 4535 | if (!m_xpathEvaluator) |
andersca@apple.com | c442c15 | 2008-02-20 01:55:42 +0000 | [diff] [blame] | 4536 | m_xpathEvaluator = XPathEvaluator::create(); |
andersca | 75fd42c | 2006-05-08 21:27:25 +0000 | [diff] [blame] | 4537 | return m_xpathEvaluator->evaluate(expression, contextNode, resolver, type, result, ec); |
| 4538 | } |
| 4539 | |
commit-queue@webkit.org | 466dbd4 | 2012-07-17 04:37:29 +0000 | [diff] [blame] | 4540 | const Vector<IconURL>& Document::iconURLs() |
beidson | b4e0ceb | 2006-09-19 02:21:52 +0000 | [diff] [blame] | 4541 | { |
commit-queue@webkit.org | 466dbd4 | 2012-07-17 04:37:29 +0000 | [diff] [blame] | 4542 | m_iconURLs.clear(); |
| 4543 | |
| 4544 | if (!head() || !(head()->children())) |
| 4545 | return m_iconURLs; |
| 4546 | |
| 4547 | // Include any icons where type = link, rel = "shortcut icon". |
| 4548 | RefPtr<HTMLCollection> children = head()->children(); |
| 4549 | unsigned int length = children->length(); |
| 4550 | for (unsigned int i = 0; i < length; ++i) { |
| 4551 | Node* child = children->item(i); |
| 4552 | if (!child->hasTagName(linkTag)) |
| 4553 | continue; |
| 4554 | HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(child); |
| 4555 | if (linkElement->iconType() != Favicon) |
| 4556 | continue; |
| 4557 | if (linkElement->href().isEmpty()) |
| 4558 | continue; |
| 4559 | |
| 4560 | // Put it at the front to ensure that icons seen later take precedence as required by the spec. |
| 4561 | IconURL newURL(linkElement->href(), linkElement->iconSizes(), linkElement->type(), linkElement->iconType()); |
| 4562 | m_iconURLs.prepend(newURL); |
| 4563 | } |
| 4564 | |
commit-queue@webkit.org | 343b8a6 | 2011-09-21 01:49:03 +0000 | [diff] [blame] | 4565 | return m_iconURLs; |
commit-queue@webkit.org | e46967d | 2011-05-04 21:02:54 +0000 | [diff] [blame] | 4566 | } |
| 4567 | |
commit-queue@webkit.org | 343b8a6 | 2011-09-21 01:49:03 +0000 | [diff] [blame] | 4568 | void Document::addIconURL(const String& url, const String& mimeType, const String& sizes, IconType iconType) |
commit-queue@webkit.org | e46967d | 2011-05-04 21:02:54 +0000 | [diff] [blame] | 4569 | { |
commit-queue@webkit.org | 343b8a6 | 2011-09-21 01:49:03 +0000 | [diff] [blame] | 4570 | if (url.isEmpty()) |
| 4571 | return; |
| 4572 | |
commit-queue@webkit.org | e46967d | 2011-05-04 21:02:54 +0000 | [diff] [blame] | 4573 | // FIXME - <rdar://problem/4727645> - At some point in the future, we might actually honor the "mimeType" |
commit-queue@webkit.org | 343b8a6 | 2011-09-21 01:49:03 +0000 | [diff] [blame] | 4574 | IconURL newURL(KURL(ParsedURLString, url), sizes, mimeType, iconType); |
commit-queue@webkit.org | e46967d | 2011-05-04 21:02:54 +0000 | [diff] [blame] | 4575 | |
commit-queue@webkit.org | 343b8a6 | 2011-09-21 01:49:03 +0000 | [diff] [blame] | 4576 | if (Frame* f = frame()) { |
| 4577 | IconURL iconURL = f->loader()->icon()->iconURL(iconType); |
| 4578 | if (iconURL == newURL) |
| 4579 | f->loader()->didChangeIcons(iconType); |
| 4580 | } |
beidson | b4e0ceb | 2006-09-19 02:21:52 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
beidson | c030e97 | 2007-05-12 21:22:08 +0000 | [diff] [blame] | 4583 | void Document::setUseSecureKeyboardEntryWhenActive(bool usesSecureKeyboard) |
| 4584 | { |
| 4585 | if (m_useSecureKeyboardEntryWhenActive == usesSecureKeyboard) |
| 4586 | return; |
commit-queue@webkit.org | 466dbd4 | 2012-07-17 04:37:29 +0000 | [diff] [blame] | 4587 | |
beidson | c030e97 | 2007-05-12 21:22:08 +0000 | [diff] [blame] | 4588 | m_useSecureKeyboardEntryWhenActive = usesSecureKeyboard; |
eric@webkit.org | 0425329 | 2010-03-08 19:22:44 +0000 | [diff] [blame] | 4589 | m_frame->selection()->updateSecureKeyboardEntryIfActive(); |
beidson | c030e97 | 2007-05-12 21:22:08 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | bool Document::useSecureKeyboardEntryWhenActive() const |
| 4593 | { |
| 4594 | return m_useSecureKeyboardEntryWhenActive; |
| 4595 | } |
| 4596 | |
eric@webkit.org | 591bb23 | 2012-05-02 01:09:53 +0000 | [diff] [blame] | 4597 | static bool isEligibleForSeamless(Document* parent, Document* child) |
| 4598 | { |
| 4599 | // It should not matter what we return for the top-most document. |
| 4600 | if (!parent) |
| 4601 | return false; |
| 4602 | if (parent->isSandboxed(SandboxSeamlessIframes)) |
| 4603 | return false; |
| 4604 | if (child->isSrcdocDocument()) |
| 4605 | return true; |
| 4606 | if (parent->securityOrigin()->canAccess(child->securityOrigin())) |
| 4607 | return true; |
| 4608 | return parent->securityOrigin()->canRequest(child->url()); |
| 4609 | } |
| 4610 | |
abarth@webkit.org | 51aed8c | 2008-06-12 06:41:36 +0000 | [diff] [blame] | 4611 | void Document::initSecurityContext() |
weinig | 343b6ff | 2007-08-07 03:08:53 +0000 | [diff] [blame] | 4612 | { |
abarth@webkit.org | cd948f1 | 2011-11-14 10:26:49 +0000 | [diff] [blame] | 4613 | if (haveInitializedSecurityOrigin()) { |
| 4614 | ASSERT(securityOrigin()); |
| 4615 | return; |
| 4616 | } |
weinig@apple.com | 6b00e24 | 2008-01-08 01:30:27 +0000 | [diff] [blame] | 4617 | |
abarth@webkit.org | 51aed8c | 2008-06-12 06:41:36 +0000 | [diff] [blame] | 4618 | if (!m_frame) { |
| 4619 | // No source for a security context. |
| 4620 | // This can occur via document.implementation.createDocument(). |
benjamin@webkit.org | 512c7f5 | 2011-12-06 01:51:27 +0000 | [diff] [blame] | 4621 | m_cookieURL = KURL(ParsedURLString, emptyString()); |
abarth@webkit.org | 51ad70c | 2011-11-18 00:20:41 +0000 | [diff] [blame] | 4622 | setSecurityOrigin(SecurityOrigin::createUnique()); |
| 4623 | setContentSecurityPolicy(ContentSecurityPolicy::create(this)); |
abarth@webkit.org | 51aed8c | 2008-06-12 06:41:36 +0000 | [diff] [blame] | 4624 | return; |
| 4625 | } |
| 4626 | |
| 4627 | // In the common case, create the security context from the currently |
abarth@webkit.org | d27ac26 | 2011-02-24 12:52:29 +0000 | [diff] [blame] | 4628 | // loading URL with a fresh content security policy. |
japhet@chromium.org | 6a088ce | 2010-06-25 17:17:45 +0000 | [diff] [blame] | 4629 | m_cookieURL = m_url; |
abarth@webkit.org | 51ad70c | 2011-11-18 00:20:41 +0000 | [diff] [blame] | 4630 | enforceSandboxFlags(m_frame->loader()->effectiveSandboxFlags()); |
abarth@webkit.org | 435c759 | 2011-11-18 04:58:44 +0000 | [diff] [blame] | 4631 | setSecurityOrigin(isSandboxed(SandboxOrigin) ? SecurityOrigin::createUnique() : SecurityOrigin::create(m_url)); |
abarth@webkit.org | 51ad70c | 2011-11-18 00:20:41 +0000 | [diff] [blame] | 4632 | setContentSecurityPolicy(ContentSecurityPolicy::create(this)); |
abarth@webkit.org | 51aed8c | 2008-06-12 06:41:36 +0000 | [diff] [blame] | 4633 | |
abarth@webkit.org | eea9066 | 2011-11-09 07:58:49 +0000 | [diff] [blame] | 4634 | if (SecurityPolicy::allowSubstituteDataAccessToLocal()) { |
abarth@webkit.org | aea97a0 | 2008-09-02 04:26:15 +0000 | [diff] [blame] | 4635 | // If this document was loaded with substituteData, then the document can |
| 4636 | // load local resources. See https://bugs.webkit.org/show_bug.cgi?id=16756 |
| 4637 | // and https://bugs.webkit.org/show_bug.cgi?id=19760 for further |
| 4638 | // discussion. |
beidson@apple.com | 197fbd3 | 2011-05-31 22:13:06 +0000 | [diff] [blame] | 4639 | |
| 4640 | DocumentLoader* documentLoader = loader(); |
| 4641 | if (documentLoader && documentLoader->substituteData().isValid()) |
ap@webkit.org | 0497fce | 2008-12-02 08:49:06 +0000 | [diff] [blame] | 4642 | securityOrigin()->grantLoadLocalResources(); |
abarth@webkit.org | aea97a0 | 2008-09-02 04:26:15 +0000 | [diff] [blame] | 4643 | } |
abarth@webkit.org | 82988b5 | 2008-06-24 03:00:21 +0000 | [diff] [blame] | 4644 | |
abarth@webkit.org | 083c72e | 2009-02-27 20:52:55 +0000 | [diff] [blame] | 4645 | if (Settings* settings = this->settings()) { |
| 4646 | if (!settings->isWebSecurityEnabled()) { |
ap@apple.com | d8f6ae0 | 2012-05-24 18:42:58 +0000 | [diff] [blame] | 4647 | // Web security is turned off. We should let this document access every other document. This is used primary by testing |
| 4648 | // harnesses for web sites. |
jonlee@apple.com | d4ac1bd | 2012-03-21 00:34:59 +0000 | [diff] [blame] | 4649 | securityOrigin()->grantUniversalAccess(); |
ap@apple.com | d8f6ae0 | 2012-05-24 18:42:58 +0000 | [diff] [blame] | 4650 | } else if (securityOrigin()->isLocal()) { |
| 4651 | if (settings->allowUniversalAccessFromFileURLs() || m_frame->loader()->client()->shouldForceUniversalAccessFromLocalURL(m_url)) { |
| 4652 | // Some clients want local URLs to have universal access, but that setting is dangerous for other clients. |
| 4653 | securityOrigin()->grantUniversalAccess(); |
| 4654 | } else if (!settings->allowFileAccessFromFileURLs()) { |
| 4655 | // Some clients want local URLs to have even tighter restrictions by default, and not be able to access other local files. |
| 4656 | // FIXME 81578: The naming of this is confusing. Files with restricted access to other local files |
| 4657 | // still can have other privileges that can be remembered, thereby not making them unique origins. |
| 4658 | securityOrigin()->enforceFilePathSeparation(); |
| 4659 | } |
abarth@webkit.org | 083c72e | 2009-02-27 20:52:55 +0000 | [diff] [blame] | 4660 | } |
jpfau@apple.com | d5a0fa0 | 2012-09-08 02:05:36 +0000 | [diff] [blame] | 4661 | securityOrigin()->setStorageBlockingPolicy(settings->storageBlockingPolicy()); |
abarth@webkit.org | af47798 | 2009-01-31 08:42:29 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
eric@webkit.org | 591bb23 | 2012-05-02 01:09:53 +0000 | [diff] [blame] | 4664 | Document* parentDocument = ownerElement() ? ownerElement()->document() : 0; |
| 4665 | if (parentDocument && m_frame->loader()->shouldTreatURLAsSrcdocDocument(url())) { |
| 4666 | m_isSrcdocDocument = true; |
| 4667 | setBaseURLOverride(parentDocument->baseURL()); |
| 4668 | } |
| 4669 | |
| 4670 | // FIXME: What happens if we inherit the security origin? This check may need to be later. |
| 4671 | // <iframe seamless src="about:blank"> likely won't work as-is. |
| 4672 | m_mayDisplaySeamlessWithParent = isEligibleForSeamless(parentDocument, this); |
| 4673 | |
abarth@webkit.org | d8cd61a | 2011-11-14 19:33:02 +0000 | [diff] [blame] | 4674 | if (!shouldInheritSecurityOriginFromOwner(m_url)) |
abarth@webkit.org | 51aed8c | 2008-06-12 06:41:36 +0000 | [diff] [blame] | 4675 | return; |
| 4676 | |
| 4677 | // If we do not obtain a meaningful origin from the URL, then we try to |
| 4678 | // find one via the frame hierarchy. |
| 4679 | |
| 4680 | Frame* ownerFrame = m_frame->tree()->parent(); |
| 4681 | if (!ownerFrame) |
| 4682 | ownerFrame = m_frame->loader()->opener(); |
| 4683 | |
abarth@webkit.org | cd948f1 | 2011-11-14 10:26:49 +0000 | [diff] [blame] | 4684 | if (!ownerFrame) { |
| 4685 | didFailToInitializeSecurityOrigin(); |
abarth@webkit.org | e313e7b | 2011-11-14 07:57:10 +0000 | [diff] [blame] | 4686 | return; |
abarth@webkit.org | cd948f1 | 2011-11-14 10:26:49 +0000 | [diff] [blame] | 4687 | } |
abarth@webkit.org | e313e7b | 2011-11-14 07:57:10 +0000 | [diff] [blame] | 4688 | |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 4689 | if (isSandboxed(SandboxOrigin)) { |
| 4690 | // If we're supposed to inherit our security origin from our owner, |
| 4691 | // but we're also sandboxed, the only thing we inherit is the ability |
| 4692 | // to load local resources. This lets about:blank iframes in file:// |
| 4693 | // URL documents load images and other resources from the file system. |
| 4694 | if (ownerFrame->document()->securityOrigin()->canLoadLocalResources()) |
| 4695 | securityOrigin()->grantLoadLocalResources(); |
| 4696 | return; |
| 4697 | } |
| 4698 | |
abarth@webkit.org | e313e7b | 2011-11-14 07:57:10 +0000 | [diff] [blame] | 4699 | m_cookieURL = ownerFrame->document()->cookieURL(); |
| 4700 | // We alias the SecurityOrigins to match Firefox, see Bug 15313 |
| 4701 | // https://bugs.webkit.org/show_bug.cgi?id=15313 |
abarth@webkit.org | 51ad70c | 2011-11-18 00:20:41 +0000 | [diff] [blame] | 4702 | setSecurityOrigin(ownerFrame->document()->securityOrigin()); |
abarth@webkit.org | 6038332 | 2012-05-04 03:45:06 +0000 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | void Document::initContentSecurityPolicy() |
| 4706 | { |
commit-queue@webkit.org | 46fa215 | 2012-08-01 21:34:13 +0000 | [diff] [blame] | 4707 | if (!m_frame->tree()->parent() || (!shouldInheritSecurityOriginFromOwner(m_url) && !isPluginDocument())) |
abarth@webkit.org | 6038332 | 2012-05-04 03:45:06 +0000 | [diff] [blame] | 4708 | return; |
commit-queue@webkit.org | 46fa215 | 2012-08-01 21:34:13 +0000 | [diff] [blame] | 4709 | |
abarth@webkit.org | 6038332 | 2012-05-04 03:45:06 +0000 | [diff] [blame] | 4710 | contentSecurityPolicy()->copyStateFrom(m_frame->tree()->parent()->document()->contentSecurityPolicy()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 4711 | } |
weinig | 343b6ff | 2007-08-07 03:08:53 +0000 | [diff] [blame] | 4712 | |
abarth@webkit.org | 23d614a | 2012-06-01 09:26:27 +0000 | [diff] [blame] | 4713 | void Document::didUpdateSecurityOrigin() |
weinig@apple.com | 8fb8fd2 | 2008-01-30 21:56:26 +0000 | [diff] [blame] | 4714 | { |
abarth@webkit.org | 23d614a | 2012-06-01 09:26:27 +0000 | [diff] [blame] | 4715 | if (!m_frame) |
| 4716 | return; |
abarth@webkit.org | 23d614a | 2012-06-01 09:26:27 +0000 | [diff] [blame] | 4717 | m_frame->script()->updateSecurityOrigin(); |
weinig@apple.com | 8fb8fd2 | 2008-01-30 21:56:26 +0000 | [diff] [blame] | 4718 | } |
| 4719 | |
eric@webkit.org | a1d8965 | 2010-01-21 03:49:51 +0000 | [diff] [blame] | 4720 | bool Document::isContextThread() const |
| 4721 | { |
| 4722 | return isMainThread(); |
| 4723 | } |
| 4724 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 4725 | void Document::updateURLForPushOrReplaceState(const KURL& url) |
| 4726 | { |
| 4727 | Frame* f = frame(); |
| 4728 | if (!f) |
| 4729 | return; |
| 4730 | |
| 4731 | setURL(url); |
japhet@chromium.org | b254c9b | 2011-01-26 19:14:26 +0000 | [diff] [blame] | 4732 | f->loader()->setOutgoingReferrer(url); |
beidson@apple.com | 197fbd3 | 2011-05-31 22:13:06 +0000 | [diff] [blame] | 4733 | |
| 4734 | if (DocumentLoader* documentLoader = loader()) |
| 4735 | documentLoader->replaceRequestURLForSameDocumentNavigation(url); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
jsbell@chromium.org | 2ba7991 | 2012-05-17 01:36:11 +0000 | [diff] [blame] | 4738 | void Document::statePopped(PassRefPtr<SerializedScriptValue> stateObject) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 4739 | { |
mihaip@chromium.org | d801651 | 2010-10-09 00:01:57 +0000 | [diff] [blame] | 4740 | if (!frame()) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 4741 | return; |
| 4742 | |
mihaip@chromium.org | d801651 | 2010-10-09 00:01:57 +0000 | [diff] [blame] | 4743 | // Per step 11 of section 6.5.9 (history traversal) of the HTML5 spec, we |
| 4744 | // defer firing of popstate until we're in the complete state. |
| 4745 | if (m_readyState == Complete) |
beidson@apple.com | 43a414c | 2010-03-19 18:25:21 +0000 | [diff] [blame] | 4746 | enqueuePopstateEvent(stateObject); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 4747 | else |
| 4748 | m_pendingStateObject = stateObject; |
| 4749 | } |
| 4750 | |
simon.fraser@apple.com | 9998eac | 2010-02-05 19:50:24 +0000 | [diff] [blame] | 4751 | void Document::updateFocusAppearanceSoon(bool restorePreviousSelection) |
darin | 438e627 | 2007-08-16 16:29:48 +0000 | [diff] [blame] | 4752 | { |
simon.fraser@apple.com | 9998eac | 2010-02-05 19:50:24 +0000 | [diff] [blame] | 4753 | m_updateFocusAppearanceRestoresSelection = restorePreviousSelection; |
darin | 438e627 | 2007-08-16 16:29:48 +0000 | [diff] [blame] | 4754 | if (!m_updateFocusAppearanceTimer.isActive()) |
| 4755 | m_updateFocusAppearanceTimer.startOneShot(0); |
| 4756 | } |
| 4757 | |
| 4758 | void Document::cancelFocusAppearanceUpdate() |
| 4759 | { |
| 4760 | m_updateFocusAppearanceTimer.stop(); |
| 4761 | } |
| 4762 | |
| 4763 | void Document::updateFocusAppearanceTimerFired(Timer<Document>*) |
| 4764 | { |
| 4765 | Node* node = focusedNode(); |
| 4766 | if (!node) |
| 4767 | return; |
| 4768 | if (!node->isElementNode()) |
| 4769 | return; |
| 4770 | |
| 4771 | updateLayout(); |
| 4772 | |
| 4773 | Element* element = static_cast<Element*>(node); |
| 4774 | if (element->isFocusable()) |
simon.fraser@apple.com | 9998eac | 2010-02-05 19:50:24 +0000 | [diff] [blame] | 4775 | element->updateFocusAppearance(m_updateFocusAppearanceRestoresSelection); |
darin | 438e627 | 2007-08-16 16:29:48 +0000 | [diff] [blame] | 4776 | } |
| 4777 | |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 4778 | void Document::attachRange(Range* range) |
| 4779 | { |
| 4780 | ASSERT(!m_ranges.contains(range)); |
| 4781 | m_ranges.add(range); |
| 4782 | } |
| 4783 | |
| 4784 | void Document::detachRange(Range* range) |
| 4785 | { |
eric@webkit.org | 11875df | 2009-06-11 21:20:01 +0000 | [diff] [blame] | 4786 | // We don't ASSERT m_ranges.contains(range) to allow us to call this |
| 4787 | // unconditionally to fix: https://bugs.webkit.org/show_bug.cgi?id=26044 |
darin@apple.com | f28fa1b | 2008-03-15 17:26:28 +0000 | [diff] [blame] | 4788 | m_ranges.remove(range); |
| 4789 | } |
| 4790 | |
cmarrin@apple.com | f493aa2 | 2009-08-25 18:45:56 +0000 | [diff] [blame] | 4791 | CanvasRenderingContext* Document::getCSSCanvasContext(const String& type, const String& name, int width, int height) |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 4792 | { |
darin@apple.com | a132a51 | 2011-12-25 19:03:16 +0000 | [diff] [blame] | 4793 | HTMLCanvasElement* element = getCSSCanvasElement(name); |
| 4794 | if (!element) |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 4795 | return 0; |
darin@apple.com | a132a51 | 2011-12-25 19:03:16 +0000 | [diff] [blame] | 4796 | element->setSize(IntSize(width, height)); |
| 4797 | return element->getContext(type); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | HTMLCanvasElement* Document::getCSSCanvasElement(const String& name) |
| 4801 | { |
commit-queue@webkit.org | fa6afbc | 2012-08-28 20:54:45 +0000 | [diff] [blame] | 4802 | RefPtr<HTMLCanvasElement>& element = m_cssCanvasElements.add(name, 0).iterator->second; |
darin@apple.com | a132a51 | 2011-12-25 19:03:16 +0000 | [diff] [blame] | 4803 | if (!element) |
| 4804 | element = HTMLCanvasElement::create(this); |
| 4805 | return element.get(); |
hyatt@apple.com | 6838215 | 2008-04-17 04:13:36 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 4808 | void Document::initDNSPrefetch() |
| 4809 | { |
timothy@apple.com | 217852f | 2010-07-01 19:32:15 +0000 | [diff] [blame] | 4810 | Settings* settings = this->settings(); |
| 4811 | |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 4812 | m_haveExplicitlyDisabledDNSPrefetch = false; |
timothy@apple.com | 217852f | 2010-07-01 19:32:15 +0000 | [diff] [blame] | 4813 | m_isDNSPrefetchEnabled = settings && settings->dnsPrefetchingEnabled() && securityOrigin()->protocol() == "http"; |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 4814 | |
| 4815 | // Inherit DNS prefetch opt-out from parent frame |
| 4816 | if (Document* parent = parentDocument()) { |
| 4817 | if (!parent->isDNSPrefetchEnabled()) |
| 4818 | m_isDNSPrefetchEnabled = false; |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | void Document::parseDNSPrefetchControlHeader(const String& dnsPrefetchControl) |
| 4823 | { |
| 4824 | if (equalIgnoringCase(dnsPrefetchControl, "on") && !m_haveExplicitlyDisabledDNSPrefetch) { |
| 4825 | m_isDNSPrefetchEnabled = true; |
| 4826 | return; |
| 4827 | } |
| 4828 | |
| 4829 | m_isDNSPrefetchEnabled = false; |
| 4830 | m_haveExplicitlyDisabledDNSPrefetch = true; |
| 4831 | } |
| 4832 | |
vsevik@chromium.org | 0c3bdd9 | 2012-01-12 10:56:52 +0000 | [diff] [blame] | 4833 | void Document::addMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, PassRefPtr<ScriptCallStack> callStack) |
eric@webkit.org | b571be3 | 2010-04-07 16:18:38 +0000 | [diff] [blame] | 4834 | { |
commit-queue@webkit.org | e5a8ade | 2011-11-04 22:24:17 +0000 | [diff] [blame] | 4835 | if (!isContextThread()) { |
| 4836 | postTask(AddConsoleMessageTask::create(source, type, level, message)); |
| 4837 | return; |
| 4838 | } |
| 4839 | |
ap@webkit.org | e9b6b59 | 2008-11-19 17:42:39 +0000 | [diff] [blame] | 4840 | if (DOMWindow* window = domWindow()) |
vsevik@chromium.org | 0c3bdd9 | 2012-01-12 10:56:52 +0000 | [diff] [blame] | 4841 | window->console()->addMessage(source, type, level, message, sourceURL, lineNumber, callStack); |
oliver@apple.com | 991c37e | 2009-03-10 09:44:30 +0000 | [diff] [blame] | 4842 | } |
| 4843 | |
ossy@webkit.org | 95c1bc4 | 2011-01-20 16:30:54 +0000 | [diff] [blame] | 4844 | struct PerformTaskContext { |
| 4845 | WTF_MAKE_NONCOPYABLE(PerformTaskContext); WTF_MAKE_FAST_ALLOCATED; |
| 4846 | public: |
dimich@chromium.org | 948b9a3 | 2010-01-15 21:47:15 +0000 | [diff] [blame] | 4847 | PerformTaskContext(PassRefPtr<DocumentWeakReference> documentReference, PassOwnPtr<ScriptExecutionContext::Task> task) |
| 4848 | : documentReference(documentReference) |
dimich@chromium.org | 301cf2b | 2009-11-18 20:25:52 +0000 | [diff] [blame] | 4849 | , task(task) |
| 4850 | { |
| 4851 | } |
| 4852 | |
dimich@chromium.org | 948b9a3 | 2010-01-15 21:47:15 +0000 | [diff] [blame] | 4853 | RefPtr<DocumentWeakReference> documentReference; |
dimich@chromium.org | 301cf2b | 2009-11-18 20:25:52 +0000 | [diff] [blame] | 4854 | OwnPtr<ScriptExecutionContext::Task> task; |
| 4855 | }; |
| 4856 | |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4857 | void Document::didReceiveTask(void* untypedContext) |
dimich@chromium.org | 301cf2b | 2009-11-18 20:25:52 +0000 | [diff] [blame] | 4858 | { |
dimich@chromium.org | 948b9a3 | 2010-01-15 21:47:15 +0000 | [diff] [blame] | 4859 | ASSERT(isMainThread()); |
| 4860 | |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4861 | OwnPtr<PerformTaskContext> context = adoptPtr(static_cast<PerformTaskContext*>(untypedContext)); |
dimich@chromium.org | 948b9a3 | 2010-01-15 21:47:15 +0000 | [diff] [blame] | 4862 | ASSERT(context); |
| 4863 | |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4864 | Document* document = context->documentReference->document(); |
| 4865 | if (!document) |
| 4866 | return; |
dimich@chromium.org | 948b9a3 | 2010-01-15 21:47:15 +0000 | [diff] [blame] | 4867 | |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4868 | Page* page = document->page(); |
| 4869 | if ((page && page->defersLoading()) || !document->m_pendingTasks.isEmpty()) { |
| 4870 | document->m_pendingTasks.append(context->task.release()); |
| 4871 | return; |
| 4872 | } |
| 4873 | |
| 4874 | context->task->performTask(document); |
dimich@chromium.org | 301cf2b | 2009-11-18 20:25:52 +0000 | [diff] [blame] | 4875 | } |
| 4876 | |
dimich@chromium.org | 142155a | 2009-11-02 21:31:22 +0000 | [diff] [blame] | 4877 | void Document::postTask(PassOwnPtr<Task> task) |
ap@webkit.org | a3f2d9f | 2008-12-04 07:20:45 +0000 | [diff] [blame] | 4878 | { |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4879 | callOnMainThread(didReceiveTask, new PerformTaskContext(m_weakReference, task)); |
| 4880 | } |
| 4881 | |
| 4882 | void Document::pendingTasksTimerFired(Timer<Document>*) |
| 4883 | { |
| 4884 | while (!m_pendingTasks.isEmpty()) { |
| 4885 | OwnPtr<Task> task = m_pendingTasks[0].release(); |
| 4886 | m_pendingTasks.remove(0); |
| 4887 | task->performTask(this); |
| 4888 | } |
| 4889 | } |
| 4890 | |
beidson@apple.com | b1bc1b7 | 2012-04-20 21:29:00 +0000 | [diff] [blame] | 4891 | void Document::suspendScheduledTasks(ActiveDOMObject::ReasonForSuspension reason) |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4892 | { |
beidson@apple.com | b1bc1b7 | 2012-04-20 21:29:00 +0000 | [diff] [blame] | 4893 | ASSERT(!m_scheduledTasksAreSuspended); |
| 4894 | |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4895 | suspendScriptedAnimationControllerCallbacks(); |
beidson@apple.com | b1bc1b7 | 2012-04-20 21:29:00 +0000 | [diff] [blame] | 4896 | suspendActiveDOMObjects(reason); |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4897 | scriptRunner()->suspend(); |
| 4898 | m_pendingTasksTimer.stop(); |
| 4899 | if (m_parser) |
| 4900 | m_parser->suspendScheduledTasks(); |
beidson@apple.com | b1bc1b7 | 2012-04-20 21:29:00 +0000 | [diff] [blame] | 4901 | |
| 4902 | m_scheduledTasksAreSuspended = true; |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | void Document::resumeScheduledTasks() |
| 4906 | { |
beidson@apple.com | b1bc1b7 | 2012-04-20 21:29:00 +0000 | [diff] [blame] | 4907 | ASSERT(m_scheduledTasksAreSuspended); |
| 4908 | |
commit-queue@webkit.org | 160529f | 2011-12-07 23:41:21 +0000 | [diff] [blame] | 4909 | if (m_parser) |
| 4910 | m_parser->resumeScheduledTasks(); |
| 4911 | if (!m_pendingTasks.isEmpty()) |
| 4912 | m_pendingTasksTimer.startOneShot(0); |
| 4913 | scriptRunner()->resume(); |
| 4914 | resumeActiveDOMObjects(); |
| 4915 | resumeScriptedAnimationControllerCallbacks(); |
beidson@apple.com | b1bc1b7 | 2012-04-20 21:29:00 +0000 | [diff] [blame] | 4916 | |
| 4917 | m_scheduledTasksAreSuspended = false; |
ap@webkit.org | a3f2d9f | 2008-12-04 07:20:45 +0000 | [diff] [blame] | 4918 | } |
| 4919 | |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 4920 | void Document::suspendScriptedAnimationControllerCallbacks() |
| 4921 | { |
| 4922 | #if ENABLE(REQUEST_ANIMATION_FRAME) |
| 4923 | if (m_scriptedAnimationController) |
| 4924 | m_scriptedAnimationController->suspend(); |
| 4925 | #endif |
| 4926 | } |
| 4927 | |
| 4928 | void Document::resumeScriptedAnimationControllerCallbacks() |
| 4929 | { |
| 4930 | #if ENABLE(REQUEST_ANIMATION_FRAME) |
| 4931 | if (m_scriptedAnimationController) |
| 4932 | m_scriptedAnimationController->resume(); |
| 4933 | #endif |
| 4934 | } |
| 4935 | |
cmarrin@apple.com | 4386e02 | 2011-10-13 21:59:25 +0000 | [diff] [blame] | 4936 | void Document::windowScreenDidChange(PlatformDisplayID displayID) |
| 4937 | { |
| 4938 | #if ENABLE(REQUEST_ANIMATION_FRAME) |
| 4939 | if (m_scriptedAnimationController) |
| 4940 | m_scriptedAnimationController->windowScreenDidChange(displayID); |
commit-queue@webkit.org | 11b6e67 | 2012-01-16 11:09:00 +0000 | [diff] [blame] | 4941 | #else |
| 4942 | UNUSED_PARAM(displayID); |
cmarrin@apple.com | 4386e02 | 2011-10-13 21:59:25 +0000 | [diff] [blame] | 4943 | #endif |
| 4944 | } |
| 4945 | |
| 4946 | |
ap@webkit.org | 7803088 | 2009-02-28 08:06:32 +0000 | [diff] [blame] | 4947 | String Document::displayStringModifiedByEncoding(const String& str) const |
| 4948 | { |
| 4949 | if (m_decoder) |
| 4950 | return m_decoder->encoding().displayString(str.impl()); |
| 4951 | return str; |
| 4952 | } |
| 4953 | |
| 4954 | PassRefPtr<StringImpl> Document::displayStringModifiedByEncoding(PassRefPtr<StringImpl> str) const |
| 4955 | { |
| 4956 | if (m_decoder) |
| 4957 | return m_decoder->encoding().displayString(str); |
| 4958 | return str; |
| 4959 | } |
| 4960 | |
| 4961 | void Document::displayBufferModifiedByEncoding(UChar* buffer, unsigned len) const |
| 4962 | { |
| 4963 | if (m_decoder) |
| 4964 | m_decoder->encoding().displayBuffer(buffer, len); |
| 4965 | } |
| 4966 | |
beidson@apple.com | 43a414c | 2010-03-19 18:25:21 +0000 | [diff] [blame] | 4967 | void Document::enqueuePageshowEvent(PageshowEventPersistence persisted) |
| 4968 | { |
| 4969 | // FIXME: https://bugs.webkit.org/show_bug.cgi?id=36334 Pageshow event needs to fire asynchronously. |
| 4970 | dispatchWindowEvent(PageTransitionEvent::create(eventNames().pageshowEvent, persisted), this); |
| 4971 | } |
| 4972 | |
mihaip@chromium.org | 6b40a77 | 2010-09-21 00:22:13 +0000 | [diff] [blame] | 4973 | void Document::enqueueHashchangeEvent(const String& oldURL, const String& newURL) |
beidson@apple.com | 43a414c | 2010-03-19 18:25:21 +0000 | [diff] [blame] | 4974 | { |
mihaip@chromium.org | b042a70 | 2010-12-14 22:52:24 +0000 | [diff] [blame] | 4975 | enqueueWindowEvent(HashChangeEvent::create(oldURL, newURL)); |
beidson@apple.com | 43a414c | 2010-03-19 18:25:21 +0000 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | void Document::enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObject) |
| 4979 | { |
| 4980 | // FIXME: https://bugs.webkit.org/show_bug.cgi?id=36202 Popstate event needs to fire asynchronously |
commit-queue@webkit.org | 7a2b40f | 2012-02-23 03:05:55 +0000 | [diff] [blame] | 4981 | dispatchWindowEvent(PopStateEvent::create(stateObject, domWindow() ? domWindow()->history() : 0)); |
beidson@apple.com | 43a414c | 2010-03-19 18:25:21 +0000 | [diff] [blame] | 4982 | } |
| 4983 | |
darin@apple.com | cfc5f06 | 2010-05-12 00:35:38 +0000 | [diff] [blame] | 4984 | void Document::addMediaCanStartListener(MediaCanStartListener* listener) |
| 4985 | { |
bdakin@apple.com | bc39dc8 | 2010-05-12 16:52:45 +0000 | [diff] [blame] | 4986 | ASSERT(!m_mediaCanStartListeners.contains(listener)); |
| 4987 | m_mediaCanStartListeners.add(listener); |
darin@apple.com | cfc5f06 | 2010-05-12 00:35:38 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | void Document::removeMediaCanStartListener(MediaCanStartListener* listener) |
| 4991 | { |
bdakin@apple.com | bc39dc8 | 2010-05-12 16:52:45 +0000 | [diff] [blame] | 4992 | ASSERT(m_mediaCanStartListeners.contains(listener)); |
| 4993 | m_mediaCanStartListeners.remove(listener); |
| 4994 | } |
| 4995 | |
| 4996 | MediaCanStartListener* Document::takeAnyMediaCanStartListener() |
| 4997 | { |
| 4998 | HashSet<MediaCanStartListener*>::iterator slot = m_mediaCanStartListeners.begin(); |
| 4999 | if (slot == m_mediaCanStartListeners.end()) |
| 5000 | return 0; |
| 5001 | MediaCanStartListener* listener = *slot; |
| 5002 | m_mediaCanStartListeners.remove(slot); |
| 5003 | return listener; |
darin@apple.com | cfc5f06 | 2010-05-12 00:35:38 +0000 | [diff] [blame] | 5004 | } |
| 5005 | |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5006 | #if ENABLE(FULLSCREEN_API) |
jer.noble@apple.com | 67f9c90 | 2011-03-14 17:52:31 +0000 | [diff] [blame] | 5007 | bool Document::fullScreenIsAllowedForElement(Element* element) const |
| 5008 | { |
| 5009 | ASSERT(element); |
scheib@chromium.org | e0e6003 | 2012-07-18 20:06:12 +0000 | [diff] [blame] | 5010 | return isAttributeOnAllOwners(webkitallowfullscreenAttr, element->document()->ownerElement()); |
jer.noble@apple.com | 67f9c90 | 2011-03-14 17:52:31 +0000 | [diff] [blame] | 5011 | } |
| 5012 | |
jer.noble@apple.com | 009a1cb | 2011-05-25 21:38:31 +0000 | [diff] [blame] | 5013 | void Document::requestFullScreenForElement(Element* element, unsigned short flags, FullScreenCheckType checkType) |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5014 | { |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5015 | // The Mozilla Full Screen API <https://wiki.mozilla.org/Gecko:FullScreenAPI> has different requirements |
| 5016 | // for full screen mode, and do not have the concept of a full screen element stack. |
| 5017 | bool inLegacyMozillaMode = (flags & Element::LEGACY_MOZILLA_REQUEST); |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5018 | |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5019 | do { |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5020 | if (!element) |
| 5021 | element = documentElement(); |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5022 | |
| 5023 | // 1. If any of the following conditions are true, terminate these steps and queue a task to fire |
| 5024 | // an event named fullscreenerror with its bubbles attribute set to true on the context object's |
| 5025 | // node document: |
| 5026 | |
| 5027 | // The context object is not in a document. |
| 5028 | if (!element->inDocument()) |
| 5029 | break; |
| 5030 | |
| 5031 | // The context object's node document, or an ancestor browsing context's document does not have |
| 5032 | // the fullscreen enabled flag set. |
scheib@chromium.org | 23765bb | 2012-07-17 00:52:57 +0000 | [diff] [blame] | 5033 | if (checkType == EnforceIFrameAllowFullScreenRequirement && !fullScreenIsAllowedForElement(element)) |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5034 | break; |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5035 | |
| 5036 | // The context object's node document fullscreen element stack is not empty and its top element |
| 5037 | // is not an ancestor of the context object. (NOTE: Ignore this requirement if the request was |
| 5038 | // made via the legacy Mozilla-style API.) |
| 5039 | if (!m_fullScreenElementStack.isEmpty() && !m_fullScreenElementStack.first()->contains(element) && !inLegacyMozillaMode) |
| 5040 | break; |
| 5041 | |
| 5042 | // A descendant browsing context's document has a non-empty fullscreen element stack. |
| 5043 | bool descendentHasNonEmptyStack = false; |
| 5044 | for (Frame* descendant = frame() ? frame()->tree()->traverseNext() : 0; descendant; descendant = descendant->tree()->traverseNext()) { |
| 5045 | if (descendant->document()->webkitFullscreenElement()) { |
| 5046 | descendentHasNonEmptyStack = true; |
| 5047 | break; |
| 5048 | } |
| 5049 | } |
| 5050 | if (descendentHasNonEmptyStack && !inLegacyMozillaMode) |
| 5051 | break; |
| 5052 | |
scheib@chromium.org | b779c1d | 2012-05-02 04:28:14 +0000 | [diff] [blame] | 5053 | // This algorithm is not allowed to show a pop-up: |
| 5054 | // An algorithm is allowed to show a pop-up if, in the task in which the algorithm is running, either: |
| 5055 | // - an activation behavior is currently being processed whose click event was trusted, or |
| 5056 | // - the event listener for a trusted click event is being handled. |
| 5057 | if (!ScriptController::processingUserGesture()) |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5058 | break; |
| 5059 | |
| 5060 | // There is a previously-established user preference, security risk, or platform limitation. |
| 5061 | if (!page() || !page()->settings()->fullScreenEnabled()) |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5062 | break; |
| 5063 | |
| 5064 | if (!page()->chrome()->client()->supportsFullScreenForElement(element, flags & Element::ALLOW_KEYBOARD_INPUT)) |
| 5065 | break; |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5066 | |
| 5067 | // 2. Let doc be element's node document. (i.e. "this") |
| 5068 | Document* currentDoc = this; |
| 5069 | |
| 5070 | // 3. Let docs be all doc's ancestor browsing context's documents (if any) and doc. |
| 5071 | Deque<Document*> docs; |
| 5072 | |
| 5073 | do { |
| 5074 | docs.prepend(currentDoc); |
| 5075 | currentDoc = currentDoc->ownerElement() ? currentDoc->ownerElement()->document() : 0; |
| 5076 | } while (currentDoc); |
| 5077 | |
| 5078 | // 4. For each document in docs, run these substeps: |
| 5079 | Deque<Document*>::iterator current = docs.begin(), following = docs.begin(); |
| 5080 | |
| 5081 | do { |
| 5082 | ++following; |
| 5083 | |
| 5084 | // 1. Let following document be the document after document in docs, or null if there is no |
| 5085 | // such document. |
| 5086 | Document* currentDoc = *current; |
| 5087 | Document* followingDoc = following != docs.end() ? *following : 0; |
| 5088 | |
| 5089 | // 2. If following document is null, push context object on document's fullscreen element |
| 5090 | // stack, and queue a task to fire an event named fullscreenchange with its bubbles attribute |
| 5091 | // set to true on the document. |
| 5092 | if (!followingDoc) { |
| 5093 | currentDoc->pushFullscreenElementStack(element); |
| 5094 | addDocumentToFullScreenChangeEventQueue(currentDoc); |
| 5095 | continue; |
| 5096 | } |
| 5097 | |
| 5098 | // 3. Otherwise, if document's fullscreen element stack is either empty or its top element |
| 5099 | // is not following document's browsing context container, |
| 5100 | Element* topElement = currentDoc->webkitFullscreenElement(); |
| 5101 | if (!topElement || topElement != followingDoc->ownerElement()) { |
| 5102 | // ...push following document's browsing context container on document's fullscreen element |
| 5103 | // stack, and queue a task to fire an event named fullscreenchange with its bubbles attribute |
| 5104 | // set to true on document. |
| 5105 | currentDoc->pushFullscreenElementStack(followingDoc->ownerElement()); |
| 5106 | addDocumentToFullScreenChangeEventQueue(currentDoc); |
| 5107 | continue; |
| 5108 | } |
| 5109 | |
| 5110 | // 4. Otherwise, do nothing for this document. It stays the same. |
| 5111 | } while (++current != docs.end()); |
| 5112 | |
| 5113 | // 5. Return, and run the remaining steps asynchronously. |
| 5114 | // 6. Optionally, perform some animation. |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5115 | m_areKeysEnabledInFullScreen = flags & Element::ALLOW_KEYBOARD_INPUT; |
| 5116 | page()->chrome()->client()->enterFullScreenForElement(element); |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5117 | |
| 5118 | // 7. Optionally, display a message indicating how the user can exit displaying the context object fullscreen. |
jer.noble@apple.com | 67f9c90 | 2011-03-14 17:52:31 +0000 | [diff] [blame] | 5119 | return; |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5120 | } while (0); |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5121 | |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5122 | m_fullScreenErrorEventTargetQueue.append(element ? element : documentElement()); |
| 5123 | m_fullScreenChangeDelayTimer.startOneShot(0); |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5124 | } |
| 5125 | |
| 5126 | void Document::webkitCancelFullScreen() |
| 5127 | { |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5128 | // The Mozilla "cancelFullScreen()" API behaves like the W3C "fully exit fullscreen" behavior, which |
| 5129 | // is defined as: |
| 5130 | // "To fully exit fullscreen act as if the exitFullscreen() method was invoked on the top-level browsing |
| 5131 | // context's document and subsequently empty that document's fullscreen element stack." |
| 5132 | if (!topDocument()->webkitFullscreenElement()) |
| 5133 | return; |
| 5134 | |
| 5135 | // To achieve that aim, remove all the elements from the top document's stack except for the first before |
| 5136 | // calling webkitExitFullscreen(): |
| 5137 | Deque<RefPtr<Element> > replacementFullscreenElementStack; |
| 5138 | replacementFullscreenElementStack.prepend(topDocument()->webkitFullscreenElement()); |
| 5139 | topDocument()->m_fullScreenElementStack.swap(replacementFullscreenElementStack); |
| 5140 | |
| 5141 | topDocument()->webkitExitFullscreen(); |
| 5142 | } |
| 5143 | |
| 5144 | void Document::webkitExitFullscreen() |
| 5145 | { |
| 5146 | // The exitFullscreen() method must run these steps: |
| 5147 | |
| 5148 | // 1. Let doc be the context object. (i.e. "this") |
| 5149 | Document* currentDoc = this; |
| 5150 | |
| 5151 | // 2. If doc's fullscreen element stack is empty, terminate these steps. |
| 5152 | if (m_fullScreenElementStack.isEmpty()) |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5153 | return; |
| 5154 | |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5155 | // 3. Let descendants be all the doc's descendant browsing context's documents with a non-empty fullscreen |
| 5156 | // element stack (if any), ordered so that the child of the doc is last and the document furthest |
| 5157 | // away from the doc is first. |
| 5158 | Deque<RefPtr<Document> > descendants; |
| 5159 | for (Frame* descendant = frame() ? frame()->tree()->traverseNext() : 0; descendant; descendant = descendant->tree()->traverseNext()) { |
| 5160 | if (descendant->document()->webkitFullscreenElement()) |
| 5161 | descendants.prepend(descendant->document()); |
| 5162 | } |
| 5163 | |
| 5164 | // 4. For each descendant in descendants, empty descendant's fullscreen element stack, and queue a |
| 5165 | // task to fire an event named fullscreenchange with its bubbles attribute set to true on descendant. |
| 5166 | for (Deque<RefPtr<Document> >::iterator i = descendants.begin(); i != descendants.end(); ++i) { |
| 5167 | (*i)->clearFullscreenElementStack(); |
| 5168 | addDocumentToFullScreenChangeEventQueue(i->get()); |
| 5169 | } |
| 5170 | |
| 5171 | // 5. While doc is not null, run these substeps: |
| 5172 | Element* newTop = 0; |
| 5173 | while (currentDoc) { |
| 5174 | // 1. Pop the top element of doc's fullscreen element stack. |
| 5175 | currentDoc->popFullscreenElementStack(); |
| 5176 | |
| 5177 | // If doc's fullscreen element stack is non-empty and the element now at the top is either |
| 5178 | // not in a document or its node document is not doc, repeat this substep. |
| 5179 | newTop = currentDoc->webkitFullscreenElement(); |
| 5180 | if (newTop && (!newTop->inDocument() || newTop->document() != currentDoc)) |
| 5181 | continue; |
| 5182 | |
| 5183 | // 2. Queue a task to fire an event named fullscreenchange with its bubbles attribute set to true |
| 5184 | // on doc. |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5185 | addDocumentToFullScreenChangeEventQueue(currentDoc); |
| 5186 | |
| 5187 | // 3. If doc's fullscreen element stack is empty and doc's browsing context has a browsing context |
| 5188 | // container, set doc to that browsing context container's node document. |
bbudge@chromium.org | 9b3a128 | 2012-08-20 18:11:22 +0000 | [diff] [blame] | 5189 | if (!newTop && currentDoc->ownerElement()) { |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5190 | currentDoc = currentDoc->ownerElement()->document(); |
bbudge@chromium.org | 9b3a128 | 2012-08-20 18:11:22 +0000 | [diff] [blame] | 5191 | continue; |
| 5192 | } |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5193 | |
| 5194 | // 4. Otherwise, set doc to null. |
| 5195 | currentDoc = 0; |
| 5196 | } |
| 5197 | |
| 5198 | // 6. Return, and run the remaining steps asynchronously. |
| 5199 | // 7. Optionally, perform some animation. |
| 5200 | |
| 5201 | // Only exit out of full screen window mode if there are no remaining elements in the |
| 5202 | // full screen stack. |
| 5203 | if (!newTop) { |
| 5204 | page()->chrome()->client()->exitFullScreenForElement(m_fullScreenElement.get()); |
| 5205 | return; |
| 5206 | } |
| 5207 | |
| 5208 | // Otherwise, notify the chrome of the new full screen element. |
| 5209 | page()->chrome()->client()->enterFullScreenForElement(newTop); |
| 5210 | } |
| 5211 | |
| 5212 | bool Document::webkitFullscreenEnabled() const |
| 5213 | { |
| 5214 | // 4. The fullscreenEnabled attribute must return true if the context object and all ancestor |
| 5215 | // browsing context's documents have their fullscreen enabled flag set, or false otherwise. |
| 5216 | |
| 5217 | // Top-level browsing contexts are implied to have their allowFullScreen attribute set. |
scheib@chromium.org | e0e6003 | 2012-07-18 20:06:12 +0000 | [diff] [blame] | 5218 | return isAttributeOnAllOwners(webkitallowfullscreenAttr, ownerElement()); |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5219 | } |
jer.noble@apple.com | e886485 | 2011-04-22 23:52:44 +0000 | [diff] [blame] | 5220 | |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5221 | void Document::webkitWillEnterFullScreenForElement(Element* element) |
| 5222 | { |
jer.noble@apple.com | 40284f3 | 2012-04-04 21:11:14 +0000 | [diff] [blame] | 5223 | if (!attached() || inPageCache()) |
| 5224 | return; |
| 5225 | |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5226 | ASSERT(element); |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5227 | |
| 5228 | // Protect against being called after the document has been removed from the page. |
| 5229 | if (!page()) |
| 5230 | return; |
| 5231 | |
| 5232 | ASSERT(page()->settings()->fullScreenEnabled()); |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5233 | |
koz@chromium.org | 24394b4 | 2011-09-17 06:07:42 +0000 | [diff] [blame] | 5234 | if (m_fullScreenRenderer) |
| 5235 | m_fullScreenRenderer->unwrapRenderer(); |
| 5236 | |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5237 | m_fullScreenElement = element; |
jer.noble@apple.com | 5346d01 | 2011-06-03 18:48:15 +0000 | [diff] [blame] | 5238 | |
commit-queue@webkit.org | 13bbf8c | 2012-05-02 00:39:31 +0000 | [diff] [blame] | 5239 | #if USE(NATIVE_FULLSCREEN_VIDEO) |
| 5240 | if (element && element->isMediaElement()) |
| 5241 | return; |
| 5242 | #endif |
| 5243 | |
jer.noble@apple.com | 5346d01 | 2011-06-03 18:48:15 +0000 | [diff] [blame] | 5244 | // Create a placeholder block for a the full-screen element, to keep the page from reflowing |
| 5245 | // when the element is removed from the normal flow. Only do this for a RenderBox, as only |
| 5246 | // a box will have a frameRect. The placeholder will be created in setFullScreenRenderer() |
| 5247 | // during layout. |
| 5248 | RenderObject* renderer = m_fullScreenElement->renderer(); |
jer.noble@apple.com | 0c78841 | 2011-06-11 03:36:15 +0000 | [diff] [blame] | 5249 | bool shouldCreatePlaceholder = renderer && renderer->isBox(); |
jer.noble@apple.com | 5346d01 | 2011-06-03 18:48:15 +0000 | [diff] [blame] | 5250 | if (shouldCreatePlaceholder) { |
| 5251 | m_savedPlaceholderFrameRect = toRenderBox(renderer)->frameRect(); |
| 5252 | m_savedPlaceholderRenderStyle = RenderStyle::clone(renderer->style()); |
| 5253 | } |
| 5254 | |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5255 | if (m_fullScreenElement != documentElement()) |
inferno@chromium.org | ad473f5 | 2012-08-02 20:44:31 +0000 | [diff] [blame] | 5256 | RenderFullScreen::wrapRenderer(renderer, renderer ? renderer->parent() : 0, this); |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5257 | |
jer.noble@apple.com | 548e336 | 2011-06-18 20:34:57 +0000 | [diff] [blame] | 5258 | m_fullScreenElement->setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(true); |
jer.noble@apple.com | e886485 | 2011-04-22 23:52:44 +0000 | [diff] [blame] | 5259 | |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5260 | recalcStyle(Force); |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5261 | } |
commit-queue@webkit.org | 13bbf8c | 2012-05-02 00:39:31 +0000 | [diff] [blame] | 5262 | |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5263 | void Document::webkitDidEnterFullScreenForElement(Element*) |
| 5264 | { |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5265 | if (!m_fullScreenElement) |
| 5266 | return; |
jer.noble@apple.com | 40284f3 | 2012-04-04 21:11:14 +0000 | [diff] [blame] | 5267 | |
| 5268 | if (!attached() || inPageCache()) |
| 5269 | return; |
| 5270 | |
mitz@apple.com | 571ae7c | 2011-05-30 00:19:51 +0000 | [diff] [blame] | 5271 | m_fullScreenElement->didBecomeFullscreenElement(); |
jer.noble@apple.com | fed7d93 | 2011-05-23 22:22:27 +0000 | [diff] [blame] | 5272 | |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5273 | m_fullScreenChangeDelayTimer.startOneShot(0); |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | void Document::webkitWillExitFullScreenForElement(Element*) |
| 5277 | { |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5278 | if (!m_fullScreenElement) |
| 5279 | return; |
| 5280 | |
jer.noble@apple.com | 40284f3 | 2012-04-04 21:11:14 +0000 | [diff] [blame] | 5281 | if (!attached() || inPageCache()) |
| 5282 | return; |
| 5283 | |
mitz@apple.com | 571ae7c | 2011-05-30 00:19:51 +0000 | [diff] [blame] | 5284 | m_fullScreenElement->willStopBeingFullscreenElement(); |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5285 | } |
| 5286 | |
jer.noble@apple.com | 08429c9 | 2011-01-07 23:09:25 +0000 | [diff] [blame] | 5287 | void Document::webkitDidExitFullScreenForElement(Element*) |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5288 | { |
jer.noble@apple.com | 53465aa | 2012-04-20 22:33:46 +0000 | [diff] [blame] | 5289 | if (!m_fullScreenElement) |
| 5290 | return; |
| 5291 | |
jer.noble@apple.com | 40284f3 | 2012-04-04 21:11:14 +0000 | [diff] [blame] | 5292 | if (!attached() || inPageCache()) |
| 5293 | return; |
| 5294 | |
jer.noble@apple.com | 53465aa | 2012-04-20 22:33:46 +0000 | [diff] [blame] | 5295 | m_fullScreenElement->setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(false); |
| 5296 | |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5297 | m_areKeysEnabledInFullScreen = false; |
koz@chromium.org | cceed2e | 2011-09-05 06:43:32 +0000 | [diff] [blame] | 5298 | |
koz@chromium.org | 24394b4 | 2011-09-17 06:07:42 +0000 | [diff] [blame] | 5299 | if (m_fullScreenRenderer) |
| 5300 | m_fullScreenRenderer->unwrapRenderer(); |
scherkus@chromium.org | 17b740a | 2011-04-18 19:27:35 +0000 | [diff] [blame] | 5301 | |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5302 | m_fullScreenElement = 0; |
jer.noble@apple.com | fed7d93 | 2011-05-23 22:22:27 +0000 | [diff] [blame] | 5303 | scheduleForcedStyleRecalc(); |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5304 | |
bbudge@chromium.org | 9b3a128 | 2012-08-20 18:11:22 +0000 | [diff] [blame] | 5305 | // When webkitCancelFullScreen is called, we call webkitExitFullScreen on the topDocument(). That |
| 5306 | // means that the events will be queued there. So if we have no events here, start the timer on |
| 5307 | // the exiting document. |
| 5308 | Document* exitingDocument = this; |
| 5309 | if (m_fullScreenChangeEventTargetQueue.isEmpty() && m_fullScreenErrorEventTargetQueue.isEmpty()) |
| 5310 | exitingDocument = topDocument(); |
| 5311 | exitingDocument->m_fullScreenChangeDelayTimer.startOneShot(0); |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | void Document::setFullScreenRenderer(RenderFullScreen* renderer) |
| 5315 | { |
jer.noble@apple.com | 2596abb | 2011-03-16 23:48:44 +0000 | [diff] [blame] | 5316 | if (renderer == m_fullScreenRenderer) |
| 5317 | return; |
| 5318 | |
jer.noble@apple.com | 5346d01 | 2011-06-03 18:48:15 +0000 | [diff] [blame] | 5319 | if (renderer && m_savedPlaceholderRenderStyle) |
| 5320 | renderer->createPlaceholder(m_savedPlaceholderRenderStyle.release(), m_savedPlaceholderFrameRect); |
| 5321 | else if (renderer && m_fullScreenRenderer && m_fullScreenRenderer->placeholder()) { |
| 5322 | RenderBlock* placeholder = m_fullScreenRenderer->placeholder(); |
| 5323 | renderer->createPlaceholder(RenderStyle::clone(placeholder->style()), placeholder->frameRect()); |
| 5324 | } |
| 5325 | |
jer.noble@apple.com | 2596abb | 2011-03-16 23:48:44 +0000 | [diff] [blame] | 5326 | if (m_fullScreenRenderer) |
| 5327 | m_fullScreenRenderer->destroy(); |
jer.noble@apple.com | 961d45b | 2011-05-26 19:30:48 +0000 | [diff] [blame] | 5328 | ASSERT(!m_fullScreenRenderer); |
| 5329 | |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5330 | m_fullScreenRenderer = renderer; |
| 5331 | |
| 5332 | // This notification can come in after the page has been destroyed. |
| 5333 | if (page()) |
| 5334 | page()->chrome()->client()->fullScreenRendererChanged(m_fullScreenRenderer); |
| 5335 | } |
jer.noble@apple.com | 961d45b | 2011-05-26 19:30:48 +0000 | [diff] [blame] | 5336 | |
| 5337 | void Document::fullScreenRendererDestroyed() |
| 5338 | { |
| 5339 | m_fullScreenRenderer = 0; |
| 5340 | |
| 5341 | if (page()) |
| 5342 | page()->chrome()->client()->fullScreenRendererChanged(0); |
| 5343 | } |
| 5344 | |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5345 | void Document::setFullScreenRendererSize(const IntSize& size) |
| 5346 | { |
| 5347 | ASSERT(m_fullScreenRenderer); |
| 5348 | if (!m_fullScreenRenderer) |
| 5349 | return; |
| 5350 | |
| 5351 | if (m_fullScreenRenderer) { |
| 5352 | RefPtr<RenderStyle> newStyle = RenderStyle::clone(m_fullScreenRenderer->style()); |
| 5353 | newStyle->setWidth(Length(size.width(), WebCore::Fixed)); |
| 5354 | newStyle->setHeight(Length(size.height(), WebCore::Fixed)); |
| 5355 | newStyle->setTop(Length(0, WebCore::Fixed)); |
| 5356 | newStyle->setLeft(Length(0, WebCore::Fixed)); |
| 5357 | m_fullScreenRenderer->setStyle(newStyle); |
jer.noble@apple.com | 65e744e | 2011-03-12 05:28:40 +0000 | [diff] [blame] | 5358 | updateLayout(); |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | void Document::setFullScreenRendererBackgroundColor(Color backgroundColor) |
| 5363 | { |
| 5364 | if (!m_fullScreenRenderer) |
| 5365 | return; |
| 5366 | |
| 5367 | RefPtr<RenderStyle> newStyle = RenderStyle::clone(m_fullScreenRenderer->style()); |
| 5368 | newStyle->setBackgroundColor(backgroundColor); |
| 5369 | m_fullScreenRenderer->setStyle(newStyle); |
| 5370 | } |
| 5371 | |
| 5372 | void Document::fullScreenChangeDelayTimerFired(Timer<Document>*) |
| 5373 | { |
commit-queue@webkit.org | 921569d | 2012-09-21 23:20:08 +0000 | [diff] [blame] | 5374 | // Since we dispatch events in this function, it's possible that the |
| 5375 | // document will be detached and GC'd. We protect it here to make sure we |
| 5376 | // can finish the function successfully. |
| 5377 | RefPtr<Document> protectDocument(this); |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5378 | Deque<RefPtr<Node> > changeQueue; |
| 5379 | m_fullScreenChangeEventTargetQueue.swap(changeQueue); |
| 5380 | |
| 5381 | while (!changeQueue.isEmpty()) { |
| 5382 | RefPtr<Node> node = changeQueue.takeFirst(); |
| 5383 | if (!node) |
| 5384 | node = documentElement(); |
commit-queue@webkit.org | 921569d | 2012-09-21 23:20:08 +0000 | [diff] [blame] | 5385 | // The dispatchEvent below may have blown away our documentElement. |
| 5386 | if (!node) |
| 5387 | continue; |
jer.noble@apple.com | 7a362df | 2011-05-18 06:12:12 +0000 | [diff] [blame] | 5388 | |
bbudge@chromium.org | 9b3a128 | 2012-08-20 18:11:22 +0000 | [diff] [blame] | 5389 | // If the element was removed from our tree, also message the documentElement. Since we may |
| 5390 | // have a document hierarchy, check that node isn't in another document. |
| 5391 | if (!contains(node.get()) && !node->inDocument()) |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5392 | changeQueue.append(documentElement()); |
jer.noble@apple.com | b6054d3 | 2011-05-21 22:30:01 +0000 | [diff] [blame] | 5393 | |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5394 | node->dispatchEvent(Event::create(eventNames().webkitfullscreenchangeEvent, true, false)); |
jer.noble@apple.com | 5a4d18e | 2011-05-14 17:29:14 +0000 | [diff] [blame] | 5395 | } |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5396 | |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5397 | Deque<RefPtr<Node> > errorQueue; |
| 5398 | m_fullScreenErrorEventTargetQueue.swap(errorQueue); |
| 5399 | |
| 5400 | while (!errorQueue.isEmpty()) { |
| 5401 | RefPtr<Node> node = errorQueue.takeFirst(); |
| 5402 | if (!node) |
| 5403 | node = documentElement(); |
commit-queue@webkit.org | 921569d | 2012-09-21 23:20:08 +0000 | [diff] [blame] | 5404 | // The dispatchEvent below may have blown away our documentElement. |
| 5405 | if (!node) |
| 5406 | continue; |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5407 | |
bbudge@chromium.org | 9b3a128 | 2012-08-20 18:11:22 +0000 | [diff] [blame] | 5408 | // If the element was removed from our tree, also message the documentElement. Since we may |
| 5409 | // have a document hierarchy, check that node isn't in another document. |
| 5410 | if (!contains(node.get()) && !node->inDocument()) |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5411 | errorQueue.append(documentElement()); |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5412 | |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5413 | node->dispatchEvent(Event::create(eventNames().webkitfullscreenerrorEvent, true, false)); |
jer.noble@apple.com | d20c464 | 2012-01-12 19:15:27 +0000 | [diff] [blame] | 5414 | } |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5415 | } |
jer.noble@apple.com | d9d59ff | 2011-01-07 22:45:47 +0000 | [diff] [blame] | 5416 | |
jer.noble@apple.com | 43d325a | 2011-05-10 22:38:52 +0000 | [diff] [blame] | 5417 | void Document::fullScreenElementRemoved() |
| 5418 | { |
jer.noble@apple.com | 548e336 | 2011-06-18 20:34:57 +0000 | [diff] [blame] | 5419 | m_fullScreenElement->setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(false); |
jer.noble@apple.com | 7a362df | 2011-05-18 06:12:12 +0000 | [diff] [blame] | 5420 | webkitCancelFullScreen(); |
jer.noble@apple.com | 43d325a | 2011-05-10 22:38:52 +0000 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | void Document::removeFullScreenElementOfSubtree(Node* node, bool amongChildrenOnly) |
| 5424 | { |
| 5425 | if (!m_fullScreenElement) |
| 5426 | return; |
| 5427 | |
| 5428 | bool elementInSubtree = false; |
| 5429 | if (amongChildrenOnly) |
| 5430 | elementInSubtree = m_fullScreenElement->isDescendantOf(node); |
| 5431 | else |
| 5432 | elementInSubtree = (m_fullScreenElement == node) || m_fullScreenElement->isDescendantOf(node); |
| 5433 | |
| 5434 | if (elementInSubtree) |
| 5435 | fullScreenElementRemoved(); |
| 5436 | } |
jer.noble@apple.com | fed7d93 | 2011-05-23 22:22:27 +0000 | [diff] [blame] | 5437 | |
| 5438 | bool Document::isAnimatingFullScreen() const |
| 5439 | { |
| 5440 | return m_isAnimatingFullScreen; |
| 5441 | } |
| 5442 | |
| 5443 | void Document::setAnimatingFullScreen(bool flag) |
| 5444 | { |
| 5445 | if (m_isAnimatingFullScreen == flag) |
| 5446 | return; |
| 5447 | m_isAnimatingFullScreen = flag; |
| 5448 | |
jer.noble@apple.com | 961d45b | 2011-05-26 19:30:48 +0000 | [diff] [blame] | 5449 | if (m_fullScreenElement && m_fullScreenElement->isDescendantOf(this)) { |
jer.noble@apple.com | fed7d93 | 2011-05-23 22:22:27 +0000 | [diff] [blame] | 5450 | m_fullScreenElement->setNeedsStyleRecalc(); |
darin@apple.com | 1628ed9 | 2011-05-29 20:12:01 +0000 | [diff] [blame] | 5451 | scheduleForcedStyleRecalc(); |
jer.noble@apple.com | fed7d93 | 2011-05-23 22:22:27 +0000 | [diff] [blame] | 5452 | } |
jer.noble@apple.com | fed7d93 | 2011-05-23 22:22:27 +0000 | [diff] [blame] | 5453 | } |
jer.noble@apple.com | 26cf870 | 2012-03-16 18:12:14 +0000 | [diff] [blame] | 5454 | |
| 5455 | void Document::clearFullscreenElementStack() |
| 5456 | { |
| 5457 | m_fullScreenElementStack.clear(); |
| 5458 | } |
| 5459 | |
| 5460 | void Document::popFullscreenElementStack() |
| 5461 | { |
| 5462 | if (m_fullScreenElementStack.isEmpty()) |
| 5463 | return; |
| 5464 | |
| 5465 | m_fullScreenElementStack.removeFirst(); |
| 5466 | } |
| 5467 | |
| 5468 | void Document::pushFullscreenElementStack(Element* element) |
| 5469 | { |
| 5470 | m_fullScreenElementStack.prepend(element); |
| 5471 | } |
| 5472 | |
| 5473 | void Document::addDocumentToFullScreenChangeEventQueue(Document* doc) |
| 5474 | { |
| 5475 | ASSERT(doc); |
| 5476 | Node* target = doc->webkitFullscreenElement(); |
| 5477 | if (!target) |
| 5478 | target = doc->webkitCurrentFullScreenElement(); |
| 5479 | if (!target) |
| 5480 | target = doc; |
| 5481 | m_fullScreenChangeEventTargetQueue.append(target); |
| 5482 | } |
jer.noble@apple.com | c5584f3 | 2010-08-27 20:49:02 +0000 | [diff] [blame] | 5483 | #endif |
beidson@apple.com | 992d69a | 2009-11-03 21:06:09 +0000 | [diff] [blame] | 5484 | |
scheib@chromium.org | 6ed0176 | 2012-06-12 03:02:16 +0000 | [diff] [blame] | 5485 | #if ENABLE(POINTER_LOCK) |
scheib@chromium.org | ebbfecc | 2012-06-15 19:53:27 +0000 | [diff] [blame] | 5486 | void Document::webkitExitPointerLock() |
| 5487 | { |
scheib@chromium.org | f4b6c5c | 2012-08-01 05:10:30 +0000 | [diff] [blame] | 5488 | if (!page()) |
| 5489 | return; |
| 5490 | if (Element* target = page()->pointerLockController()->element()) { |
| 5491 | if (target->document() != this) |
| 5492 | return; |
| 5493 | } |
| 5494 | page()->pointerLockController()->requestPointerUnlock(); |
scheib@chromium.org | ebbfecc | 2012-06-15 19:53:27 +0000 | [diff] [blame] | 5495 | } |
| 5496 | |
scheib@chromium.org | 6ed0176 | 2012-06-12 03:02:16 +0000 | [diff] [blame] | 5497 | Element* Document::webkitPointerLockElement() const |
| 5498 | { |
scheib@chromium.org | 575ba7c | 2012-09-05 17:31:32 +0000 | [diff] [blame] | 5499 | if (!page() || page()->pointerLockController()->lockPending()) |
scheib@chromium.org | e31007f | 2012-07-23 15:50:29 +0000 | [diff] [blame] | 5500 | return 0; |
| 5501 | if (Element* element = page()->pointerLockController()->element()) { |
| 5502 | if (element->document() == this) |
| 5503 | return element; |
| 5504 | } |
| 5505 | return 0; |
scheib@chromium.org | 6ed0176 | 2012-06-12 03:02:16 +0000 | [diff] [blame] | 5506 | } |
| 5507 | #endif |
| 5508 | |
eric.carlson@apple.com | 9c7fc72 | 2010-08-26 16:45:43 +0000 | [diff] [blame] | 5509 | void Document::decrementLoadEventDelayCount() |
| 5510 | { |
| 5511 | ASSERT(m_loadEventDelayCount); |
| 5512 | --m_loadEventDelayCount; |
| 5513 | |
jschuh@chromium.org | 47fb2f5 | 2010-10-04 22:25:43 +0000 | [diff] [blame] | 5514 | if (frame() && !m_loadEventDelayCount && !m_loadEventDelayTimer.isActive()) |
| 5515 | m_loadEventDelayTimer.startOneShot(0); |
| 5516 | } |
| 5517 | |
| 5518 | void Document::loadEventDelayTimerFired(Timer<Document>*) |
| 5519 | { |
| 5520 | if (frame()) |
eric.carlson@apple.com | 9c7fc72 | 2010-08-26 16:45:43 +0000 | [diff] [blame] | 5521 | frame()->loader()->checkCompleted(); |
| 5522 | } |
| 5523 | |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 5524 | #if ENABLE(REQUEST_ANIMATION_FRAME) |
commit-queue@webkit.org | 9fb90af | 2012-04-09 11:42:18 +0000 | [diff] [blame] | 5525 | int Document::webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback> callback) |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 5526 | { |
jamesr@google.com | 72acb83 | 2012-03-15 05:07:20 +0000 | [diff] [blame] | 5527 | if (!m_scriptedAnimationController) { |
| 5528 | #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
dino@apple.com | 78a8b47 | 2012-04-05 21:29:38 +0000 | [diff] [blame] | 5529 | m_scriptedAnimationController = ScriptedAnimationController::create(this, page() ? page()->displayID() : 0); |
jamesr@google.com | 72acb83 | 2012-03-15 05:07:20 +0000 | [diff] [blame] | 5530 | #else |
| 5531 | m_scriptedAnimationController = ScriptedAnimationController::create(this, 0); |
| 5532 | #endif |
dino@apple.com | 78a8b47 | 2012-04-05 21:29:38 +0000 | [diff] [blame] | 5533 | // It's possible that the Page may have suspended scripted animations before |
| 5534 | // we were created. We need to make sure that we don't start up the animation |
| 5535 | // controller on a background tab, for example. |
| 5536 | if (!page() || page()->scriptedAnimationsSuspended()) |
| 5537 | m_scriptedAnimationController->suspend(); |
jamesr@google.com | 72acb83 | 2012-03-15 05:07:20 +0000 | [diff] [blame] | 5538 | } |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 5539 | |
commit-queue@webkit.org | 9fb90af | 2012-04-09 11:42:18 +0000 | [diff] [blame] | 5540 | return m_scriptedAnimationController->registerCallback(callback); |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 5541 | } |
| 5542 | |
commit-queue@webkit.org | cd5d11d | 2011-12-12 20:58:15 +0000 | [diff] [blame] | 5543 | void Document::webkitCancelAnimationFrame(int id) |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 5544 | { |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 5545 | if (!m_scriptedAnimationController) |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 5546 | return; |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 5547 | m_scriptedAnimationController->cancelCallback(id); |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 5548 | } |
| 5549 | |
nduca@chromium.org | f98045a | 2012-05-07 17:37:30 +0000 | [diff] [blame] | 5550 | void Document::serviceScriptedAnimations(DOMTimeStamp time) |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 5551 | { |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 5552 | if (!m_scriptedAnimationController) |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 5553 | return; |
nduca@chromium.org | f98045a | 2012-05-07 17:37:30 +0000 | [diff] [blame] | 5554 | m_scriptedAnimationController->serviceScriptedAnimations(time); |
jamesr@google.com | 0ea9e5f | 2011-01-20 21:50:34 +0000 | [diff] [blame] | 5555 | } |
| 5556 | #endif |
| 5557 | |
benm@google.com | b08424c | 2010-10-19 11:50:02 +0000 | [diff] [blame] | 5558 | #if ENABLE(TOUCH_EVENTS) |
commit-queue@webkit.org | 20bf23d | 2011-06-19 04:13:49 +0000 | [diff] [blame] | 5559 | PassRefPtr<Touch> Document::createTouch(DOMWindow* window, EventTarget* target, int identifier, int pageX, int pageY, int screenX, int screenY, int radiusX, int radiusY, float rotationAngle, float force, ExceptionCode&) const |
benm@google.com | b08424c | 2010-10-19 11:50:02 +0000 | [diff] [blame] | 5560 | { |
| 5561 | // FIXME: It's not clear from the documentation at |
| 5562 | // http://developer.apple.com/library/safari/#documentation/UserExperience/Reference/DocumentAdditionsReference/DocumentAdditions/DocumentAdditions.html |
| 5563 | // when this method should throw and nor is it by inspection of iOS behavior. It would be nice to verify any cases where it throws under iOS |
| 5564 | // and implement them here. See https://bugs.webkit.org/show_bug.cgi?id=47819 |
benm@google.com | b08424c | 2010-10-19 11:50:02 +0000 | [diff] [blame] | 5565 | Frame* frame = window ? window->frame() : this->frame(); |
commit-queue@webkit.org | 20bf23d | 2011-06-19 04:13:49 +0000 | [diff] [blame] | 5566 | return Touch::create(frame, target, identifier, screenX, screenY, pageX, pageY, radiusX, radiusY, rotationAngle, force); |
benm@google.com | b08424c | 2010-10-19 11:50:02 +0000 | [diff] [blame] | 5567 | } |
benm@google.com | b08424c | 2010-10-19 11:50:02 +0000 | [diff] [blame] | 5568 | #endif |
| 5569 | |
andersca@apple.com | 4ef1087 | 2012-02-06 00:43:19 +0000 | [diff] [blame] | 5570 | static void wheelEventHandlerCountChanged(Document* document) |
| 5571 | { |
andersca@apple.com | 4ef1087 | 2012-02-06 00:43:19 +0000 | [diff] [blame] | 5572 | Page* page = document->page(); |
| 5573 | if (!page) |
| 5574 | return; |
| 5575 | |
| 5576 | ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator(); |
| 5577 | if (!scrollingCoordinator) |
| 5578 | return; |
| 5579 | |
| 5580 | FrameView* frameView = document->view(); |
| 5581 | if (!frameView) |
| 5582 | return; |
| 5583 | |
| 5584 | scrollingCoordinator->frameViewWheelEventHandlerCountChanged(frameView); |
andersca@apple.com | 4ef1087 | 2012-02-06 00:43:19 +0000 | [diff] [blame] | 5585 | } |
| 5586 | |
jonlee@apple.com | 8d90918 | 2011-05-16 17:25:02 +0000 | [diff] [blame] | 5587 | void Document::didAddWheelEventHandler() |
| 5588 | { |
| 5589 | ++m_wheelEventHandlerCount; |
| 5590 | Frame* mainFrame = page() ? page()->mainFrame() : 0; |
| 5591 | if (mainFrame) |
| 5592 | mainFrame->notifyChromeClientWheelEventHandlerCountChanged(); |
andersca@apple.com | 4ef1087 | 2012-02-06 00:43:19 +0000 | [diff] [blame] | 5593 | |
| 5594 | wheelEventHandlerCountChanged(this); |
jonlee@apple.com | 8d90918 | 2011-05-16 17:25:02 +0000 | [diff] [blame] | 5595 | } |
| 5596 | |
| 5597 | void Document::didRemoveWheelEventHandler() |
| 5598 | { |
| 5599 | ASSERT(m_wheelEventHandlerCount > 0); |
| 5600 | --m_wheelEventHandlerCount; |
| 5601 | Frame* mainFrame = page() ? page()->mainFrame() : 0; |
| 5602 | if (mainFrame) |
| 5603 | mainFrame->notifyChromeClientWheelEventHandlerCountChanged(); |
andersca@apple.com | 4ef1087 | 2012-02-06 00:43:19 +0000 | [diff] [blame] | 5604 | |
| 5605 | wheelEventHandlerCountChanged(this); |
jonlee@apple.com | 8d90918 | 2011-05-16 17:25:02 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
commit-queue@webkit.org | 7c44a68 | 2012-02-15 20:21:15 +0000 | [diff] [blame] | 5608 | void Document::didAddTouchEventHandler() |
| 5609 | { |
pierre.rossi@gmail.com | 81b0596 | 2012-07-23 18:31:14 +0000 | [diff] [blame] | 5610 | #if ENABLE(TOUCH_EVENTS) |
commit-queue@webkit.org | 7c44a68 | 2012-02-15 20:21:15 +0000 | [diff] [blame] | 5611 | ++m_touchEventHandlerCount; |
pierre.rossi@gmail.com | 81b0596 | 2012-07-23 18:31:14 +0000 | [diff] [blame] | 5612 | if (m_touchEventHandlerCount > 1) |
| 5613 | return; |
| 5614 | if (Page* page = this->page()) |
| 5615 | page->chrome()->client()->needTouchEvents(true); |
| 5616 | #endif |
commit-queue@webkit.org | 7c44a68 | 2012-02-15 20:21:15 +0000 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | void Document::didRemoveTouchEventHandler() |
| 5620 | { |
pierre.rossi@gmail.com | 81b0596 | 2012-07-23 18:31:14 +0000 | [diff] [blame] | 5621 | #if ENABLE(TOUCH_EVENTS) |
| 5622 | ASSERT(m_touchEventHandlerCount); |
commit-queue@webkit.org | 7c44a68 | 2012-02-15 20:21:15 +0000 | [diff] [blame] | 5623 | --m_touchEventHandlerCount; |
pierre.rossi@gmail.com | 81b0596 | 2012-07-23 18:31:14 +0000 | [diff] [blame] | 5624 | if (m_touchEventHandlerCount) |
| 5625 | return; |
| 5626 | |
pierre.rossi@gmail.com | 81b0596 | 2012-07-23 18:31:14 +0000 | [diff] [blame] | 5627 | Page* page = this->page(); |
| 5628 | if (!page) |
| 5629 | return; |
| 5630 | for (const Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) { |
| 5631 | if (frame->document() && frame->document()->touchEventHandlerCount()) |
| 5632 | return; |
| 5633 | } |
| 5634 | page->chrome()->client()->needTouchEvents(false); |
| 5635 | #endif |
commit-queue@webkit.org | 7c44a68 | 2012-02-15 20:21:15 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
eric@webkit.org | 591bb23 | 2012-05-02 01:09:53 +0000 | [diff] [blame] | 5638 | HTMLIFrameElement* Document::seamlessParentIFrame() const |
| 5639 | { |
| 5640 | if (!shouldDisplaySeamlesslyWithParent()) |
| 5641 | return 0; |
| 5642 | |
| 5643 | HTMLFrameOwnerElement* ownerElement = this->ownerElement(); |
| 5644 | ASSERT(ownerElement->hasTagName(iframeTag)); |
| 5645 | return static_cast<HTMLIFrameElement*>(ownerElement); |
| 5646 | } |
| 5647 | |
| 5648 | bool Document::shouldDisplaySeamlesslyWithParent() const |
| 5649 | { |
eric@webkit.org | a1a6e12 | 2012-05-07 22:02:47 +0000 | [diff] [blame] | 5650 | #if ENABLE(IFRAME_SEAMLESS) |
eric@webkit.org | 591bb23 | 2012-05-02 01:09:53 +0000 | [diff] [blame] | 5651 | HTMLFrameOwnerElement* ownerElement = this->ownerElement(); |
| 5652 | if (!ownerElement) |
| 5653 | return false; |
| 5654 | return m_mayDisplaySeamlessWithParent && ownerElement->hasTagName(iframeTag) && ownerElement->fastHasAttribute(seamlessAttr); |
eric@webkit.org | a1a6e12 | 2012-05-07 22:02:47 +0000 | [diff] [blame] | 5655 | #else |
| 5656 | return false; |
| 5657 | #endif |
eric@webkit.org | 591bb23 | 2012-05-02 01:09:53 +0000 | [diff] [blame] | 5658 | } |
| 5659 | |
beidson@apple.com | 197fbd3 | 2011-05-31 22:13:06 +0000 | [diff] [blame] | 5660 | DocumentLoader* Document::loader() const |
| 5661 | { |
| 5662 | if (!m_frame) |
| 5663 | return 0; |
| 5664 | |
jschuh@chromium.org | 2a6986e | 2011-11-08 17:42:29 +0000 | [diff] [blame] | 5665 | DocumentLoader* loader = m_frame->loader()->documentLoader(); |
beidson@apple.com | 197fbd3 | 2011-05-31 22:13:06 +0000 | [diff] [blame] | 5666 | if (!loader) |
| 5667 | return 0; |
| 5668 | |
| 5669 | if (m_frame->document() != this) |
| 5670 | return 0; |
| 5671 | |
| 5672 | return loader; |
| 5673 | } |
| 5674 | |
rniwa@webkit.org | 43f105f | 2011-10-14 16:13:01 +0000 | [diff] [blame] | 5675 | #if ENABLE(MICRODATA) |
| 5676 | PassRefPtr<NodeList> Document::getItems(const String& typeNames) |
| 5677 | { |
rniwa@webkit.org | 43f105f | 2011-10-14 16:13:01 +0000 | [diff] [blame] | 5678 | // Since documet.getItem() is allowed for microdata, typeNames will be null string. |
arko@motorola.com | a89cb25 | 2012-08-06 10:29:39 +0000 | [diff] [blame] | 5679 | // In this case we need to create an empty string identifier to map such request in the cache. |
arko@motorola.com | c2218d7 | 2012-06-25 12:09:33 +0000 | [diff] [blame] | 5680 | String localTypeNames = typeNames.isNull() ? MicroDataItemList::undefinedItemType() : typeNames; |
rniwa@webkit.org | 43f105f | 2011-10-14 16:13:01 +0000 | [diff] [blame] | 5681 | |
rniwa@webkit.org | fc3b7b7 | 2012-07-12 20:31:09 +0000 | [diff] [blame] | 5682 | return ensureRareData()->ensureNodeLists()->addCacheWithName<MicroDataItemList>(this, DynamicNodeList::MicroDataItemListType, localTypeNames); |
rniwa@webkit.org | 43f105f | 2011-10-14 16:13:01 +0000 | [diff] [blame] | 5683 | } |
| 5684 | #endif |
| 5685 | |
commit-queue@webkit.org | c558b51 | 2012-03-27 19:19:59 +0000 | [diff] [blame] | 5686 | IntSize Document::viewportSize() const |
| 5687 | { |
| 5688 | if (!view()) |
| 5689 | return IntSize(); |
| 5690 | return view()->visibleContentRect(/* includeScrollbars */ true).size(); |
| 5691 | } |
| 5692 | |
jpu@apple.com | dfd2ce6 | 2012-04-16 03:05:06 +0000 | [diff] [blame] | 5693 | Node* eventTargetNodeForDocument(Document* doc) |
| 5694 | { |
| 5695 | if (!doc) |
| 5696 | return 0; |
| 5697 | Node* node = doc->focusedNode(); |
| 5698 | if (!node && doc->isPluginDocument()) { |
| 5699 | PluginDocument* pluginDocument = static_cast<PluginDocument*>(doc); |
| 5700 | node = pluginDocument->pluginNode(); |
| 5701 | } |
| 5702 | if (!node && doc->isHTMLDocument()) |
| 5703 | node = doc->body(); |
| 5704 | if (!node) |
| 5705 | node = doc->documentElement(); |
| 5706 | return node; |
| 5707 | } |
| 5708 | |
wangxianzhu@chromium.org | 254f322 | 2012-06-07 06:57:19 +0000 | [diff] [blame] | 5709 | void Document::adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(Vector<FloatQuad>& quads, RenderObject* renderer) |
| 5710 | { |
| 5711 | if (!view()) |
| 5712 | return; |
| 5713 | |
| 5714 | float inverseFrameScale = 1; |
| 5715 | if (frame()) |
| 5716 | inverseFrameScale = 1 / frame()->frameScaleFactor(); |
| 5717 | |
| 5718 | LayoutRect visibleContentRect = view()->visibleContentRect(); |
| 5719 | for (size_t i = 0; i < quads.size(); ++i) { |
| 5720 | quads[i].move(-visibleContentRect.x(), -visibleContentRect.y()); |
| 5721 | adjustFloatQuadForAbsoluteZoom(quads[i], renderer); |
| 5722 | if (inverseFrameScale != 1) |
| 5723 | quads[i].scale(inverseFrameScale, inverseFrameScale); |
| 5724 | } |
| 5725 | } |
| 5726 | |
| 5727 | void Document::adjustFloatRectForScrollAndAbsoluteZoomAndFrameScale(FloatRect& rect, RenderObject* renderer) |
| 5728 | { |
| 5729 | if (!view()) |
| 5730 | return; |
| 5731 | |
| 5732 | float inverseFrameScale = 1; |
| 5733 | if (frame()) |
| 5734 | inverseFrameScale = 1 / frame()->frameScaleFactor(); |
| 5735 | |
| 5736 | LayoutRect visibleContentRect = view()->visibleContentRect(); |
| 5737 | rect.move(-visibleContentRect.x(), -visibleContentRect.y()); |
| 5738 | adjustFloatRectForAbsoluteZoom(rect, renderer); |
| 5739 | if (inverseFrameScale != 1) |
| 5740 | rect.scale(inverseFrameScale); |
| 5741 | } |
| 5742 | |
morrita@google.com | ac74304 | 2012-06-13 08:05:43 +0000 | [diff] [blame] | 5743 | void Document::setContextFeatures(PassRefPtr<ContextFeatures> features) |
| 5744 | { |
| 5745 | m_contextFeatures = features; |
| 5746 | } |
| 5747 | |
allan.jensen@nokia.com | 236eff2 | 2012-09-13 15:22:37 +0000 | [diff] [blame] | 5748 | static RenderObject* nearestCommonHoverAncestor(RenderObject* obj1, RenderObject* obj2) |
| 5749 | { |
| 5750 | if (!obj1 || !obj2) |
| 5751 | return 0; |
| 5752 | |
| 5753 | for (RenderObject* currObj1 = obj1; currObj1; currObj1 = currObj1->hoverAncestor()) { |
| 5754 | for (RenderObject* currObj2 = obj2; currObj2; currObj2 = currObj2->hoverAncestor()) { |
| 5755 | if (currObj1 == currObj2) |
| 5756 | return currObj1; |
| 5757 | } |
| 5758 | } |
| 5759 | |
| 5760 | return 0; |
| 5761 | } |
| 5762 | |
| 5763 | void Document::updateHoverActiveState(const HitTestRequest& request, HitTestResult& result) |
| 5764 | { |
| 5765 | // We don't update :hover/:active state when the result is marked as readOnly. |
| 5766 | if (request.readOnly()) |
| 5767 | return; |
| 5768 | |
| 5769 | Node* innerNodeInDocument = result.innerNode(); |
allan.jensen@nokia.com | 82fb305 | 2012-09-18 10:28:02 +0000 | [diff] [blame] | 5770 | ASSERT(!innerNodeInDocument || innerNodeInDocument->document() == this); |
allan.jensen@nokia.com | 236eff2 | 2012-09-13 15:22:37 +0000 | [diff] [blame] | 5771 | |
| 5772 | Node* oldActiveNode = activeNode(); |
| 5773 | if (oldActiveNode && !request.active()) { |
| 5774 | // We are clearing the :active chain because the mouse has been released. |
| 5775 | for (RenderObject* curr = oldActiveNode->renderer(); curr; curr = curr->parent()) { |
| 5776 | if (curr->node() && !curr->isText()) { |
| 5777 | curr->node()->setActive(false); |
| 5778 | curr->node()->clearInActiveChain(); |
| 5779 | } |
| 5780 | } |
| 5781 | setActiveNode(0); |
| 5782 | } else { |
| 5783 | Node* newActiveNode = innerNodeInDocument; |
| 5784 | if (!oldActiveNode && newActiveNode && request.active() && !request.touchMove()) { |
| 5785 | // We are setting the :active chain and freezing it. If future moves happen, they |
| 5786 | // will need to reference this chain. |
| 5787 | for (RenderObject* curr = newActiveNode->renderer(); curr; curr = curr->parent()) { |
| 5788 | if (curr->node() && !curr->isText()) |
| 5789 | curr->node()->setInActiveChain(); |
| 5790 | } |
| 5791 | setActiveNode(newActiveNode); |
| 5792 | } |
| 5793 | } |
| 5794 | // If the mouse has just been pressed, set :active on the chain. Those (and only those) |
| 5795 | // nodes should remain :active until the mouse is released. |
| 5796 | bool allowActiveChanges = !oldActiveNode && activeNode(); |
| 5797 | |
| 5798 | // If the mouse is down and if this is a mouse move event, we want to restrict changes in |
| 5799 | // :hover/:active to only apply to elements that are in the :active chain that we froze |
| 5800 | // at the time the mouse went down. |
| 5801 | bool mustBeInActiveChain = request.active() && request.move(); |
| 5802 | |
| 5803 | RefPtr<Node> oldHoverNode = hoverNode(); |
| 5804 | // Clear the :hover chain when the touch gesture is over. |
| 5805 | if (request.touchRelease()) { |
| 5806 | if (oldHoverNode) { |
| 5807 | for (RenderObject* curr = oldHoverNode->renderer(); curr; curr = curr->hoverAncestor()) { |
| 5808 | if (curr->node() && !curr->isText()) |
| 5809 | curr->node()->setHovered(false); |
| 5810 | } |
| 5811 | setHoverNode(0); |
| 5812 | } |
| 5813 | // A touch release can not set new hover or active target. |
| 5814 | return; |
| 5815 | } |
| 5816 | |
| 5817 | // Check to see if the hovered node has changed. |
| 5818 | // If it hasn't, we do not need to do anything. |
| 5819 | Node* newHoverNode = innerNodeInDocument; |
| 5820 | while (newHoverNode && !newHoverNode->renderer()) |
| 5821 | newHoverNode = newHoverNode->parentOrHostNode(); |
| 5822 | |
| 5823 | // Update our current hover node. |
| 5824 | setHoverNode(newHoverNode); |
| 5825 | |
| 5826 | // We have two different objects. Fetch their renderers. |
| 5827 | RenderObject* oldHoverObj = oldHoverNode ? oldHoverNode->renderer() : 0; |
| 5828 | RenderObject* newHoverObj = newHoverNode ? newHoverNode->renderer() : 0; |
| 5829 | |
| 5830 | // Locate the common ancestor render object for the two renderers. |
| 5831 | RenderObject* ancestor = nearestCommonHoverAncestor(oldHoverObj, newHoverObj); |
| 5832 | |
| 5833 | Vector<RefPtr<Node>, 32> nodesToRemoveFromChain; |
| 5834 | Vector<RefPtr<Node>, 32> nodesToAddToChain; |
| 5835 | |
| 5836 | if (oldHoverObj != newHoverObj) { |
| 5837 | // The old hover path only needs to be cleared up to (and not including) the common ancestor; |
| 5838 | for (RenderObject* curr = oldHoverObj; curr && curr != ancestor; curr = curr->hoverAncestor()) { |
| 5839 | if (curr->node() && !curr->isText() && (!mustBeInActiveChain || curr->node()->inActiveChain())) |
| 5840 | nodesToRemoveFromChain.append(curr->node()); |
| 5841 | } |
| 5842 | } |
| 5843 | |
| 5844 | // Now set the hover state for our new object up to the root. |
| 5845 | for (RenderObject* curr = newHoverObj; curr; curr = curr->hoverAncestor()) { |
| 5846 | if (curr->node() && !curr->isText() && (!mustBeInActiveChain || curr->node()->inActiveChain())) |
| 5847 | nodesToAddToChain.append(curr->node()); |
| 5848 | } |
| 5849 | |
| 5850 | size_t removeCount = nodesToRemoveFromChain.size(); |
| 5851 | for (size_t i = 0; i < removeCount; ++i) |
| 5852 | nodesToRemoveFromChain[i]->setHovered(false); |
| 5853 | |
| 5854 | size_t addCount = nodesToAddToChain.size(); |
| 5855 | for (size_t i = 0; i < addCount; ++i) { |
| 5856 | if (allowActiveChanges) |
| 5857 | nodesToAddToChain[i]->setActive(true); |
| 5858 | nodesToAddToChain[i]->setHovered(true); |
| 5859 | } |
| 5860 | } |
| 5861 | |
yurys@chromium.org | 1a722c5 | 2012-07-06 11:25:28 +0000 | [diff] [blame] | 5862 | void Document::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| 5863 | { |
loislo@chromium.org | 53b3ffd | 2012-09-05 15:11:06 +0000 | [diff] [blame] | 5864 | MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); |
loislo@chromium.org | 24454d9 | 2012-08-03 16:44:40 +0000 | [diff] [blame] | 5865 | ContainerNode::reportMemoryUsage(memoryObjectInfo); |
loislo@chromium.org | c10e098 | 2012-09-26 14:10:50 +0000 | [diff] [blame] | 5866 | info.addMember(m_styleResolver); |
loislo@chromium.org | 8373693 | 2012-09-25 07:54:44 +0000 | [diff] [blame] | 5867 | info.addMember(m_customFonts); |
loislo@chromium.org | 61a7dd6 | 2012-09-17 15:12:21 +0000 | [diff] [blame] | 5868 | info.addMember(m_url); |
| 5869 | info.addMember(m_baseURL); |
| 5870 | info.addMember(m_baseURLOverride); |
| 5871 | info.addMember(m_baseElementURL); |
| 5872 | info.addMember(m_cookieURL); |
| 5873 | info.addMember(m_firstPartyForCookies); |
| 5874 | info.addMember(m_documentURI); |
| 5875 | info.addMember(m_baseTarget); |
loislo@chromium.org | c10e098 | 2012-09-26 14:10:50 +0000 | [diff] [blame] | 5876 | info.addMember(m_docType); |
| 5877 | info.addMember(m_implementation); |
| 5878 | info.addMember(m_elemSheet); |
loislo@chromium.org | 61a7dd6 | 2012-09-17 15:12:21 +0000 | [diff] [blame] | 5879 | info.addMember(m_frame); |
| 5880 | info.addMember(m_cachedResourceLoader); |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 5881 | info.addMember(m_styleSheetCollection); |
loislo@chromium.org | c10e098 | 2012-09-26 14:10:50 +0000 | [diff] [blame] | 5882 | info.addMember(m_styleSheetList); |
| 5883 | info.addMember(m_formController); |
| 5884 | info.addMember(m_nodeIterators); |
| 5885 | info.addMember(m_ranges); |
loislo@chromium.org | 61a7dd6 | 2012-09-17 15:12:21 +0000 | [diff] [blame] | 5886 | info.addMember(m_title.string()); |
| 5887 | info.addMember(m_rawTitle.string()); |
| 5888 | info.addMember(m_xmlEncoding); |
| 5889 | info.addMember(m_xmlVersion); |
| 5890 | info.addMember(m_contentLanguage); |
yurys@chromium.org | 9c99016 | 2012-10-01 14:46:25 +0000 | [diff] [blame] | 5891 | info.addMember(m_documentNamedItemCollections); |
| 5892 | info.addMember(m_windowNamedItemCollections); |
yurys@chromium.org | 1a722c5 | 2012-07-06 11:25:28 +0000 | [diff] [blame] | 5893 | #if ENABLE(DASHBOARD_SUPPORT) |
loislo@chromium.org | 8373693 | 2012-09-25 07:54:44 +0000 | [diff] [blame] | 5894 | info.addMember(m_dashboardRegions); |
yurys@chromium.org | 1a722c5 | 2012-07-06 11:25:28 +0000 | [diff] [blame] | 5895 | #endif |
yurys@chromium.org | 9c99016 | 2012-10-01 14:46:25 +0000 | [diff] [blame] | 5896 | info.addMember(m_cssCanvasElements); |
loislo@chromium.org | 8373693 | 2012-09-25 07:54:44 +0000 | [diff] [blame] | 5897 | info.addMember(m_iconURLs); |
loislo@chromium.org | c10e098 | 2012-09-26 14:10:50 +0000 | [diff] [blame] | 5898 | info.addMember(m_documentSuspensionCallbackElements); |
| 5899 | info.addMember(m_mediaVolumeCallbackElements); |
| 5900 | info.addMember(m_privateBrowsingStateChangedElements); |
yurys@chromium.org | 9c99016 | 2012-10-01 14:46:25 +0000 | [diff] [blame] | 5901 | info.addMember(m_elementsByAccessKey); |
loislo@chromium.org | 61a7dd6 | 2012-09-17 15:12:21 +0000 | [diff] [blame] | 5902 | info.addMember(m_eventQueue); |
loislo@chromium.org | c10e098 | 2012-09-26 14:10:50 +0000 | [diff] [blame] | 5903 | info.addMember(m_mediaCanStartListeners); |
loislo@chromium.org | 8373693 | 2012-09-25 07:54:44 +0000 | [diff] [blame] | 5904 | info.addMember(m_pendingTasks); |
yurys@chromium.org | 1a722c5 | 2012-07-06 11:25:28 +0000 | [diff] [blame] | 5905 | } |
| 5906 | |
commit-queue@webkit.org | 5deb749 | 2012-06-09 09:05:22 +0000 | [diff] [blame] | 5907 | #if ENABLE(UNDO_MANAGER) |
| 5908 | PassRefPtr<UndoManager> Document::undoManager() |
| 5909 | { |
| 5910 | if (!m_undoManager) |
commit-queue@webkit.org | 290528b | 2012-08-22 01:42:43 +0000 | [diff] [blame] | 5911 | m_undoManager = UndoManager::create(this); |
commit-queue@webkit.org | 5deb749 | 2012-06-09 09:05:22 +0000 | [diff] [blame] | 5912 | return m_undoManager; |
| 5913 | } |
| 5914 | #endif |
| 5915 | |
kling@webkit.org | 7c57578 | 2012-09-04 02:19:26 +0000 | [diff] [blame] | 5916 | class ImmutableAttributeDataCacheKey { |
| 5917 | public: |
kling@webkit.org | ca1e2d4 | 2012-09-24 00:57:54 +0000 | [diff] [blame] | 5918 | ImmutableAttributeDataCacheKey(const QualifiedName& tagName, const Attribute* attributes, unsigned attributeCount) |
| 5919 | : m_tagQName(tagName) |
kling@webkit.org | 7c57578 | 2012-09-04 02:19:26 +0000 | [diff] [blame] | 5920 | , m_attributes(attributes) |
| 5921 | , m_attributeCount(attributeCount) |
| 5922 | { } |
| 5923 | |
| 5924 | bool operator!=(const ImmutableAttributeDataCacheKey& other) const |
| 5925 | { |
kling@webkit.org | ca1e2d4 | 2012-09-24 00:57:54 +0000 | [diff] [blame] | 5926 | if (m_tagQName != other.m_tagQName) |
kling@webkit.org | 7c57578 | 2012-09-04 02:19:26 +0000 | [diff] [blame] | 5927 | return true; |
| 5928 | if (m_attributeCount != other.m_attributeCount) |
| 5929 | return true; |
| 5930 | return memcmp(m_attributes, other.m_attributes, sizeof(Attribute) * m_attributeCount); |
| 5931 | } |
| 5932 | |
| 5933 | unsigned hash() const |
| 5934 | { |
| 5935 | unsigned attributeHash = StringHasher::hashMemory(m_attributes, m_attributeCount * sizeof(Attribute)); |
kling@webkit.org | ca1e2d4 | 2012-09-24 00:57:54 +0000 | [diff] [blame] | 5936 | return WTF::pairIntHash(m_tagQName.localName().impl()->existingHash(), attributeHash); |
kling@webkit.org | 7c57578 | 2012-09-04 02:19:26 +0000 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | private: |
kling@webkit.org | ca1e2d4 | 2012-09-24 00:57:54 +0000 | [diff] [blame] | 5940 | QualifiedName m_tagQName; |
kling@webkit.org | 7c57578 | 2012-09-04 02:19:26 +0000 | [diff] [blame] | 5941 | const Attribute* m_attributes; |
| 5942 | unsigned m_attributeCount; |
| 5943 | }; |
| 5944 | |
| 5945 | struct ImmutableAttributeDataCacheEntry { |
kling@webkit.org | ca1e2d4 | 2012-09-24 00:57:54 +0000 | [diff] [blame] | 5946 | ImmutableAttributeDataCacheEntry(const ImmutableAttributeDataCacheKey& k, PassRefPtr<ElementAttributeData> v) |
| 5947 | : key(k) |
| 5948 | , value(v) |
| 5949 | { } |
| 5950 | |
kling@webkit.org | 7c57578 | 2012-09-04 02:19:26 +0000 | [diff] [blame] | 5951 | ImmutableAttributeDataCacheKey key; |
| 5952 | RefPtr<ElementAttributeData> value; |
| 5953 | }; |
| 5954 | |
| 5955 | PassRefPtr<ElementAttributeData> Document::cachedImmutableAttributeData(const Element* element, const Vector<Attribute>& attributes) |
| 5956 | { |
| 5957 | ASSERT(!attributes.isEmpty()); |
| 5958 | |
kling@webkit.org | ca1e2d4 | 2012-09-24 00:57:54 +0000 | [diff] [blame] | 5959 | ImmutableAttributeDataCacheKey cacheKey(element->tagQName(), attributes.data(), attributes.size()); |
kling@webkit.org | 7c57578 | 2012-09-04 02:19:26 +0000 | [diff] [blame] | 5960 | unsigned cacheHash = cacheKey.hash(); |
| 5961 | |
| 5962 | ImmutableAttributeDataCache::iterator cacheIterator = m_immutableAttributeDataCache.add(cacheHash, nullptr).iterator; |
| 5963 | if (cacheIterator->second && cacheIterator->second->key != cacheKey) |
| 5964 | cacheHash = 0; |
| 5965 | |
| 5966 | RefPtr<ElementAttributeData> attributeData; |
| 5967 | if (cacheHash && cacheIterator->second) |
| 5968 | attributeData = cacheIterator->second->value; |
| 5969 | else |
| 5970 | attributeData = ElementAttributeData::createImmutable(attributes); |
| 5971 | |
| 5972 | if (!cacheHash || cacheIterator->second) |
| 5973 | return attributeData.release(); |
| 5974 | |
kling@webkit.org | ca1e2d4 | 2012-09-24 00:57:54 +0000 | [diff] [blame] | 5975 | cacheIterator->second = adoptPtr(new ImmutableAttributeDataCacheEntry(ImmutableAttributeDataCacheKey(element->tagQName(), attributeData->immutableAttributeArray(), attributeData->length()), attributeData)); |
kling@webkit.org | 7c57578 | 2012-09-04 02:19:26 +0000 | [diff] [blame] | 5976 | |
| 5977 | return attributeData.release(); |
| 5978 | } |
| 5979 | |
antti@apple.com | e5a88a7 | 2012-09-24 22:14:47 +0000 | [diff] [blame] | 5980 | bool Document::haveStylesheetsLoaded() const |
| 5981 | { |
| 5982 | return !m_styleSheetCollection->hasPendingSheets() || m_ignorePendingStylesheets; |
| 5983 | } |
| 5984 | |
tkent@chromium.org | 24b1fce | 2012-09-28 15:51:52 +0000 | [diff] [blame] | 5985 | Localizer& Document::getCachedLocalizer(const AtomicString& locale) |
tkent@chromium.org | aff3c93 | 2012-09-14 12:40:27 +0000 | [diff] [blame] | 5986 | { |
| 5987 | AtomicString localeKey = locale; |
| 5988 | if (locale.isEmpty() || !RuntimeEnabledFeatures::langAttributeAwareFormControlUIEnabled()) |
| 5989 | localeKey = defaultLanguage(); |
| 5990 | LocaleToLocalizerMap::AddResult result = m_localizerCache.add(localeKey, nullptr); |
| 5991 | if (result.isNewEntry) |
| 5992 | result.iterator->second = Localizer::create(localeKey); |
| 5993 | return *(result.iterator->second); |
| 5994 | } |
| 5995 | |
weinig | 343b6ff | 2007-08-07 03:08:53 +0000 | [diff] [blame] | 5996 | } // namespace WebCore |