OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "core/page/FocusController.h" | 37 #include "core/page/FocusController.h" |
38 #include "core/page/Page.h" | 38 #include "core/page/Page.h" |
39 #include "core/page/WindowFeatures.h" | 39 #include "core/page/WindowFeatures.h" |
40 #include "platform/network/ResourceRequest.h" | 40 #include "platform/network/ResourceRequest.h" |
41 #include "platform/weborigin/KURL.h" | 41 #include "platform/weborigin/KURL.h" |
42 #include "platform/weborigin/SecurityOrigin.h" | 42 #include "platform/weborigin/SecurityOrigin.h" |
43 #include "platform/weborigin/SecurityPolicy.h" | 43 #include "platform/weborigin/SecurityPolicy.h" |
44 | 44 |
45 namespace WebCore { | 45 namespace WebCore { |
46 | 46 |
47 static LocalFrame* createWindow(LocalFrame* openerFrame, LocalFrame* lookupFrame
, const FrameLoadRequest& request, const WindowFeatures& features, NavigationPol
icy policy, ShouldSendReferrer shouldSendReferrer, bool& created) | 47 static LocalFrame* createWindow(LocalFrame& openerFrame, LocalFrame& lookupFrame
, const FrameLoadRequest& request, const WindowFeatures& features, NavigationPol
icy policy, ShouldSendReferrer shouldSendReferrer, bool& created) |
48 { | 48 { |
49 ASSERT(!features.dialog || request.frameName().isEmpty()); | 49 ASSERT(!features.dialog || request.frameName().isEmpty()); |
50 | 50 |
51 if (!request.frameName().isEmpty() && request.frameName() != "_blank" && pol
icy == NavigationPolicyIgnore) { | 51 if (!request.frameName().isEmpty() && request.frameName() != "_blank" && pol
icy == NavigationPolicyIgnore) { |
52 if (LocalFrame* frame = lookupFrame->loader().findFrameForNavigation(req
uest.frameName(), openerFrame->document())) { | 52 if (LocalFrame* frame = lookupFrame.loader().findFrameForNavigation(requ
est.frameName(), openerFrame.document())) { |
53 if (request.frameName() != "_self") | 53 if (request.frameName() != "_self") |
54 frame->page()->focusController().setFocusedFrame(frame); | 54 frame->page()->focusController().setFocusedFrame(frame); |
55 created = false; | 55 created = false; |
56 return frame; | 56 return frame; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 // Sandboxed frames cannot open new auxiliary browsing contexts. | 60 // Sandboxed frames cannot open new auxiliary browsing contexts. |
61 if (openerFrame->document()->isSandboxed(SandboxPopups)) { | 61 if (openerFrame.document()->isSandboxed(SandboxPopups)) { |
62 // FIXME: This message should be moved off the console once a solution t
o https://bugs.webkit.org/show_bug.cgi?id=103274 exists. | 62 // FIXME: This message should be moved off the console once a solution t
o https://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
63 openerFrame->document()->addConsoleMessage(SecurityMessageSource, ErrorM
essageLevel, "Blocked opening '" + request.resourceRequest().url().elidedString(
) + "' in a new window because the request was made in a sandboxed frame whose '
allow-popups' permission is not set."); | 63 openerFrame.document()->addConsoleMessage(SecurityMessageSource, ErrorMe
ssageLevel, "Blocked opening '" + request.resourceRequest().url().elidedString()
+ "' in a new window because the request was made in a sandboxed frame whose 'a
llow-popups' permission is not set."); |
64 return 0; | 64 return 0; |
65 } | 65 } |
66 | 66 |
67 if (openerFrame->settings() && !openerFrame->settings()->supportsMultipleWin
dows()) { | 67 if (openerFrame.settings() && !openerFrame.settings()->supportsMultipleWindo
ws()) { |
68 created = false; | 68 created = false; |
69 return openerFrame->tree().top(); | 69 return openerFrame.tree().top(); |
70 } | 70 } |
71 | 71 |
72 Page* oldPage = openerFrame->page(); | 72 Page* oldPage = openerFrame.page(); |
73 if (!oldPage) | 73 if (!oldPage) |
74 return 0; | 74 return 0; |
75 | 75 |
76 Page* page = oldPage->chrome().client().createWindow(openerFrame, request, f
eatures, policy, shouldSendReferrer); | 76 Page* page = oldPage->chrome().client().createWindow(&openerFrame, request,
features, policy, shouldSendReferrer); |
77 if (!page) | 77 if (!page) |
78 return 0; | 78 return 0; |
79 FrameHost* host = &page->frameHost(); | 79 FrameHost* host = &page->frameHost(); |
80 | 80 |
81 LocalFrame* frame = page->mainFrame(); | 81 ASSERT(page->mainFrame()); |
| 82 LocalFrame& frame = *page->mainFrame(); |
82 | 83 |
83 frame->loader().forceSandboxFlags(openerFrame->document()->sandboxFlags()); | 84 frame.loader().forceSandboxFlags(openerFrame.document()->sandboxFlags()); |
84 | 85 |
85 if (request.frameName() != "_blank") | 86 if (request.frameName() != "_blank") |
86 frame->tree().setName(request.frameName()); | 87 frame.tree().setName(request.frameName()); |
87 | 88 |
88 host->chrome().setWindowFeatures(features); | 89 host->chrome().setWindowFeatures(features); |
89 | 90 |
90 // 'x' and 'y' specify the location of the window, while 'width' and 'height
' | 91 // 'x' and 'y' specify the location of the window, while 'width' and 'height
' |
91 // specify the size of the viewport. We can only resize the window, so adjus
t | 92 // specify the size of the viewport. We can only resize the window, so adjus
t |
92 // for the difference between the window size and the viewport size. | 93 // for the difference between the window size and the viewport size. |
93 | 94 |
94 FloatRect windowRect = host->chrome().windowRect(); | 95 FloatRect windowRect = host->chrome().windowRect(); |
95 FloatSize viewportSize = host->chrome().pageRect().size(); | 96 FloatSize viewportSize = host->chrome().pageRect().size(); |
96 | 97 |
97 if (features.xSet) | 98 if (features.xSet) |
98 windowRect.setX(features.x); | 99 windowRect.setX(features.x); |
99 if (features.ySet) | 100 if (features.ySet) |
100 windowRect.setY(features.y); | 101 windowRect.setY(features.y); |
101 if (features.widthSet) | 102 if (features.widthSet) |
102 windowRect.setWidth(features.width + (windowRect.width() - viewportSize.
width())); | 103 windowRect.setWidth(features.width + (windowRect.width() - viewportSize.
width())); |
103 if (features.heightSet) | 104 if (features.heightSet) |
104 windowRect.setHeight(features.height + (windowRect.height() - viewportSi
ze.height())); | 105 windowRect.setHeight(features.height + (windowRect.height() - viewportSi
ze.height())); |
105 | 106 |
106 // Ensure non-NaN values, minimum size as well as being within valid screen
area. | 107 // Ensure non-NaN values, minimum size as well as being within valid screen
area. |
107 FloatRect newWindowRect = DOMWindow::adjustWindowRect(frame, windowRect); | 108 FloatRect newWindowRect = DOMWindow::adjustWindowRect(frame, windowRect); |
108 | 109 |
109 host->chrome().setWindowRect(newWindowRect); | 110 host->chrome().setWindowRect(newWindowRect); |
110 host->chrome().show(policy); | 111 host->chrome().show(policy); |
111 | 112 |
112 created = true; | 113 created = true; |
113 return frame; | 114 return &frame; |
114 } | 115 } |
115 | 116 |
116 LocalFrame* createWindow(const String& urlString, const AtomicString& frameName,
const WindowFeatures& windowFeatures, | 117 LocalFrame* createWindow(const String& urlString, const AtomicString& frameName,
const WindowFeatures& windowFeatures, |
117 DOMWindow* callingWindow, LocalFrame* firstFrame, LocalFrame* openerFrame) | 118 DOMWindow& callingWindow, LocalFrame& firstFrame, LocalFrame& openerFrame) |
118 { | 119 { |
119 LocalFrame* activeFrame = callingWindow->frame(); | 120 LocalFrame* activeFrame = callingWindow.frame(); |
| 121 ASSERT(activeFrame); |
120 | 122 |
121 KURL completedURL = urlString.isEmpty() ? KURL(ParsedURLString, emptyString(
)) : firstFrame->document()->completeURL(urlString); | 123 KURL completedURL = urlString.isEmpty() ? KURL(ParsedURLString, emptyString(
)) : firstFrame.document()->completeURL(urlString); |
122 if (!completedURL.isEmpty() && !completedURL.isValid()) { | 124 if (!completedURL.isEmpty() && !completedURL.isValid()) { |
123 // Don't expose client code to invalid URLs. | 125 // Don't expose client code to invalid URLs. |
124 callingWindow->printErrorMessage("Unable to open a window with invalid U
RL '" + completedURL.string() + "'.\n"); | 126 callingWindow.printErrorMessage("Unable to open a window with invalid UR
L '" + completedURL.string() + "'.\n"); |
125 return 0; | 127 return 0; |
126 } | 128 } |
127 | 129 |
128 // For whatever reason, Firefox uses the first frame to determine the outgoi
ngReferrer. We replicate that behavior here. | 130 // For whatever reason, Firefox uses the first frame to determine the outgoi
ngReferrer. We replicate that behavior here. |
129 Referrer referrer(SecurityPolicy::generateReferrerHeader(firstFrame->documen
t()->referrerPolicy(), completedURL, firstFrame->document()->outgoingReferrer())
, firstFrame->document()->referrerPolicy()); | 131 Referrer referrer(SecurityPolicy::generateReferrerHeader(firstFrame.document
()->referrerPolicy(), completedURL, firstFrame.document()->outgoingReferrer()),
firstFrame.document()->referrerPolicy()); |
130 | 132 |
131 ResourceRequest request(completedURL, referrer); | 133 ResourceRequest request(completedURL, referrer); |
132 FrameLoader::addHTTPOriginIfNeeded(request, AtomicString(firstFrame->documen
t()->outgoingOrigin())); | 134 FrameLoader::addHTTPOriginIfNeeded(request, AtomicString(firstFrame.document
()->outgoingOrigin())); |
133 FrameLoadRequest frameRequest(callingWindow->document(), request, frameName)
; | 135 FrameLoadRequest frameRequest(callingWindow.document(), request, frameName); |
134 | 136 |
135 // We pass the opener frame for the lookupFrame in case the active frame is
different from | 137 // We pass the opener frame for the lookupFrame in case the active frame is
different from |
136 // the opener frame, and the name references a frame relative to the opener
frame. | 138 // the opener frame, and the name references a frame relative to the opener
frame. |
137 bool created; | 139 bool created; |
138 LocalFrame* newFrame = createWindow(activeFrame, openerFrame, frameRequest,
windowFeatures, NavigationPolicyIgnore, MaybeSendReferrer, created); | 140 LocalFrame* newFrame = createWindow(*activeFrame, openerFrame, frameRequest,
windowFeatures, NavigationPolicyIgnore, MaybeSendReferrer, created); |
139 if (!newFrame) | 141 if (!newFrame) |
140 return 0; | 142 return 0; |
141 | 143 |
142 newFrame->loader().setOpener(openerFrame); | 144 newFrame->loader().setOpener(&openerFrame); |
143 newFrame->page()->setOpenedByDOM(); | 145 newFrame->page()->setOpenedByDOM(); |
144 | 146 |
145 if (newFrame->domWindow()->isInsecureScriptAccess(callingWindow, completedUR
L)) | 147 if (newFrame->domWindow()->isInsecureScriptAccess(callingWindow, completedUR
L)) |
146 return newFrame; | 148 return newFrame; |
147 | 149 |
148 if (created) { | 150 if (created) { |
149 FrameLoadRequest request(callingWindow->document(), ResourceRequest(comp
letedURL, referrer)); | 151 FrameLoadRequest request(callingWindow.document(), ResourceRequest(compl
etedURL, referrer)); |
150 newFrame->loader().load(request); | 152 newFrame->loader().load(request); |
151 } else if (!urlString.isEmpty()) { | 153 } else if (!urlString.isEmpty()) { |
152 newFrame->navigationScheduler().scheduleLocationChange(callingWindow->do
cument(), completedURL.string(), referrer, false); | 154 newFrame->navigationScheduler().scheduleLocationChange(callingWindow.doc
ument(), completedURL.string(), referrer, false); |
153 } | 155 } |
154 return newFrame; | 156 return newFrame; |
155 } | 157 } |
156 | 158 |
157 void createWindowForRequest(const FrameLoadRequest& request, LocalFrame* openerF
rame, NavigationPolicy policy, ShouldSendReferrer shouldSendReferrer) | 159 void createWindowForRequest(const FrameLoadRequest& request, LocalFrame& openerF
rame, NavigationPolicy policy, ShouldSendReferrer shouldSendReferrer) |
158 { | 160 { |
159 if (openerFrame->document()->pageDismissalEventBeingDispatched() != Document
::NoDismissal) | 161 if (openerFrame.document()->pageDismissalEventBeingDispatched() != Document:
:NoDismissal) |
160 return; | 162 return; |
161 | 163 |
162 if (openerFrame->document() && openerFrame->document()->isSandboxed(SandboxP
opups)) | 164 if (openerFrame.document() && openerFrame.document()->isSandboxed(SandboxPop
ups)) |
163 return; | 165 return; |
164 | 166 |
165 if (!DOMWindow::allowPopUp(openerFrame)) | 167 if (!DOMWindow::allowPopUp(openerFrame)) |
166 return; | 168 return; |
167 | 169 |
168 if (policy == NavigationPolicyCurrentTab) | 170 if (policy == NavigationPolicyCurrentTab) |
169 policy = NavigationPolicyNewForegroundTab; | 171 policy = NavigationPolicyNewForegroundTab; |
170 | 172 |
171 WindowFeatures features; | 173 WindowFeatures features; |
172 bool created; | 174 bool created; |
173 LocalFrame* newFrame = createWindow(openerFrame, openerFrame, request, featu
res, policy, shouldSendReferrer, created); | 175 LocalFrame* newFrame = createWindow(openerFrame, openerFrame, request, featu
res, policy, shouldSendReferrer, created); |
174 if (!newFrame) | 176 if (!newFrame) |
175 return; | 177 return; |
176 newFrame->page()->setOpenedByDOM(); | 178 newFrame->page()->setOpenedByDOM(); |
177 if (shouldSendReferrer == MaybeSendReferrer) { | 179 if (shouldSendReferrer == MaybeSendReferrer) { |
178 newFrame->loader().setOpener(openerFrame); | 180 newFrame->loader().setOpener(&openerFrame); |
179 newFrame->document()->setReferrerPolicy(openerFrame->document()->referre
rPolicy()); | 181 newFrame->document()->setReferrerPolicy(openerFrame.document()->referrer
Policy()); |
180 } | 182 } |
181 FrameLoadRequest newRequest(0, request.resourceRequest()); | 183 FrameLoadRequest newRequest(0, request.resourceRequest()); |
182 newRequest.setFormState(request.formState()); | 184 newRequest.setFormState(request.formState()); |
183 newFrame->loader().load(newRequest); | 185 newFrame->loader().load(newRequest); |
184 } | 186 } |
185 | 187 |
186 } // namespace WebCore | 188 } // namespace WebCore |
OLD | NEW |