This source file includes following definitions.
- createWindow
- createWindow
- createWindowForRequest
#include "config.h"
#include "core/page/CreateWindow.h"
#include "core/dom/Document.h"
#include "core/frame/FrameHost.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
#include "core/loader/FrameLoadRequest.h"
#include "core/page/Chrome.h"
#include "core/page/ChromeClient.h"
#include "core/page/FocusController.h"
#include "core/page/Page.h"
#include "core/page/WindowFeatures.h"
#include "platform/network/ResourceRequest.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "platform/weborigin/SecurityPolicy.h"
namespace WebCore {
static LocalFrame* createWindow(LocalFrame& openerFrame, LocalFrame& lookupFrame, const FrameLoadRequest& request, const WindowFeatures& features, NavigationPolicy policy, ShouldSendReferrer shouldSendReferrer, bool& created)
{
ASSERT(!features.dialog || request.frameName().isEmpty());
if (!request.frameName().isEmpty() && request.frameName() != "_blank" && policy == NavigationPolicyIgnore) {
if (LocalFrame* frame = lookupFrame.loader().findFrameForNavigation(request.frameName(), openerFrame.document())) {
if (request.frameName() != "_self")
frame->page()->focusController().setFocusedFrame(frame);
created = false;
return frame;
}
}
if (openerFrame.document()->isSandboxed(SandboxPopups)) {
openerFrame.document()->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "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.");
return 0;
}
if (openerFrame.settings() && !openerFrame.settings()->supportsMultipleWindows()) {
created = false;
return openerFrame.tree().top();
}
Page* oldPage = openerFrame.page();
if (!oldPage)
return 0;
Page* page = oldPage->chrome().client().createWindow(&openerFrame, request, features, policy, shouldSendReferrer);
if (!page)
return 0;
FrameHost* host = &page->frameHost();
ASSERT(page->mainFrame());
LocalFrame& frame = *page->mainFrame();
if (request.frameName() != "_blank")
frame.tree().setName(request.frameName());
host->chrome().setWindowFeatures(features);
FloatRect windowRect = host->chrome().windowRect();
FloatSize viewportSize = host->chrome().pageRect().size();
if (features.xSet)
windowRect.setX(features.x);
if (features.ySet)
windowRect.setY(features.y);
if (features.widthSet)
windowRect.setWidth(features.width + (windowRect.width() - viewportSize.width()));
if (features.heightSet)
windowRect.setHeight(features.height + (windowRect.height() - viewportSize.height()));
FloatRect newWindowRect = DOMWindow::adjustWindowRect(frame, windowRect);
host->chrome().setWindowRect(newWindowRect);
host->chrome().show(policy);
created = true;
return &frame;
}
LocalFrame* createWindow(const String& urlString, const AtomicString& frameName, const WindowFeatures& windowFeatures,
DOMWindow& callingWindow, LocalFrame& firstFrame, LocalFrame& openerFrame, DOMWindow::PrepareDialogFunction function, void* functionContext)
{
LocalFrame* activeFrame = callingWindow.frame();
ASSERT(activeFrame);
KURL completedURL = urlString.isEmpty() ? KURL(ParsedURLString, emptyString()) : firstFrame.document()->completeURL(urlString);
if (!completedURL.isEmpty() && !completedURL.isValid()) {
callingWindow.printErrorMessage("Unable to open a window with invalid URL '" + completedURL.string() + "'.\n");
return 0;
}
Referrer referrer(SecurityPolicy::generateReferrerHeader(firstFrame.document()->referrerPolicy(), completedURL, firstFrame.document()->outgoingReferrer()), firstFrame.document()->referrerPolicy());
ResourceRequest request(completedURL, referrer);
FrameLoader::addHTTPOriginIfNeeded(request, AtomicString(firstFrame.document()->outgoingOrigin()));
FrameLoadRequest frameRequest(callingWindow.document(), request, frameName);
bool created;
LocalFrame* newFrame = createWindow(*activeFrame, openerFrame, frameRequest, windowFeatures, NavigationPolicyIgnore, MaybeSendReferrer, created);
if (!newFrame)
return 0;
if (newFrame != &openerFrame && newFrame != openerFrame.tree().top())
newFrame->loader().forceSandboxFlags(openerFrame.document()->sandboxFlags());
newFrame->loader().setOpener(&openerFrame);
newFrame->page()->setOpenedByDOM();
if (newFrame->domWindow()->isInsecureScriptAccess(callingWindow, completedURL))
return newFrame;
if (function)
function(newFrame->domWindow(), functionContext);
if (created) {
FrameLoadRequest request(callingWindow.document(), ResourceRequest(completedURL, referrer));
newFrame->loader().load(request);
} else if (!urlString.isEmpty()) {
newFrame->navigationScheduler().scheduleLocationChange(callingWindow.document(), completedURL.string(), referrer, false);
}
return newFrame;
}
void createWindowForRequest(const FrameLoadRequest& request, LocalFrame& openerFrame, NavigationPolicy policy, ShouldSendReferrer shouldSendReferrer)
{
if (openerFrame.document()->pageDismissalEventBeingDispatched() != Document::NoDismissal)
return;
if (openerFrame.document() && openerFrame.document()->isSandboxed(SandboxPopups))
return;
if (!DOMWindow::allowPopUp(openerFrame))
return;
if (policy == NavigationPolicyCurrentTab)
policy = NavigationPolicyNewForegroundTab;
WindowFeatures features;
bool created;
LocalFrame* newFrame = createWindow(openerFrame, openerFrame, request, features, policy, shouldSendReferrer, created);
if (!newFrame)
return;
newFrame->page()->setOpenedByDOM();
if (shouldSendReferrer == MaybeSendReferrer) {
newFrame->loader().setOpener(&openerFrame);
newFrame->document()->setReferrerPolicy(openerFrame.document()->referrerPolicy());
}
FrameLoadRequest newRequest(0, request.resourceRequest());
newRequest.setFormState(request.formState());
newFrame->loader().load(newRequest);
}
}