📄 jsdomwindowbase.cpp
字号:
/* * Copyright (C) 2000 Harri Porten (porten@kde.org) * Copyright (C) 2006 Jon Shier (jshier@iastate.edu) * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved. * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA */#include "config.h"#include "JSDOMWindowBase.h"#include "CString.h"#include "Console.h"#include "DOMTimer.h"#include "DOMWindow.h"#include "Element.h"#include "EventListener.h"#include "ExceptionCode.h"#include "FloatRect.h"#include "Frame.h"#include "FrameLoadRequest.h"#include "FrameLoader.h"#include "FrameTree.h"#include "GCController.h"#include "HTMLDocument.h"#include "InspectorController.h"#include "JSAudioConstructor.h"#include "JSDOMWindowCustom.h"#include "JSEvent.h"#include "JSEventListener.h"#include "JSHTMLCollection.h"#include "JSImageConstructor.h"#include "JSMessageChannelConstructor.h"#include "JSNode.h"#include "JSWebKitCSSMatrixConstructor.h"#include "JSOptionConstructor.h"#include "JSWebKitPointConstructor.h"#include "JSWorkerConstructor.h"#include "JSXMLHttpRequestConstructor.h"#include "JSXSLTProcessorConstructor.h"#include "Logging.h"#include "MediaPlayer.h"#include "Page.h"#include "PlatformScreen.h"#include "PluginInfoStore.h"#include "RenderView.h"#include "ScheduledAction.h"#include "ScriptController.h"#include "SecurityOrigin.h"#include "Settings.h"#include "WindowFeatures.h"#include "htmlediting.h"#include <runtime/Error.h>#include <runtime/JSLock.h>#include <wtf/AlwaysInline.h>#include <wtf/MathExtras.h>using namespace JSC;static JSValuePtr windowProtoFuncOpen(ExecState*, JSObject*, JSValuePtr, const ArgList&);static JSValuePtr windowProtoFuncShowModalDialog(ExecState*, JSObject*, JSValuePtr, const ArgList&);static JSValuePtr windowProtoFuncNotImplemented(ExecState*, JSObject*, JSValuePtr, const ArgList&);static JSValuePtr jsDOMWindowBaseCrypto(ExecState*, const Identifier&, const PropertySlot&);static JSValuePtr jsDOMWindowBaseEvent(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseEvent(ExecState*, JSObject*, JSValuePtr);// Constructorsstatic JSValuePtr jsDOMWindowBaseAudio(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseAudio(ExecState*, JSObject*, JSValuePtr);static JSValuePtr jsDOMWindowBaseImage(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseImage(ExecState*, JSObject*, JSValuePtr);static JSValuePtr jsDOMWindowBaseMessageChannel(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseMessageChannel(ExecState*, JSObject*, JSValuePtr);static JSValuePtr jsDOMWindowBaseWorker(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseWorker(ExecState*, JSObject*, JSValuePtr);static JSValuePtr jsDOMWindowBaseOption(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseOption(ExecState*, JSObject*, JSValuePtr);static JSValuePtr jsDOMWindowBaseWebKitCSSMatrix(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseWebKitCSSMatrix(ExecState*, JSObject*, JSValuePtr);static JSValuePtr jsDOMWindowBaseWebKitPoint(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseWebKitPoint(ExecState*, JSObject*, JSValuePtr);static JSValuePtr jsDOMWindowBaseXMLHttpRequest(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseXMLHttpRequest(ExecState*, JSObject*, JSValuePtr);static JSValuePtr jsDOMWindowBaseXSLTProcessor(ExecState*, const Identifier&, const PropertySlot&);static void setJSDOMWindowBaseXSLTProcessor(ExecState*, JSObject*, JSValuePtr);#include "JSDOMWindowBase.lut.h"namespace WebCore {////////////////////// JSDOMWindowBase Object ////////////////////////const ClassInfo JSDOMWindowBase::s_info = { "Window", 0, &JSDOMWindowBaseTable, 0 };/*@begin JSDOMWindowBaseTable# -- Functions -- open windowProtoFuncOpen DontDelete|Function 3 showModalDialog windowProtoFuncShowModalDialog DontDelete|Function 1# Not implemented captureEvents windowProtoFuncNotImplemented DontDelete|Function 0 releaseEvents windowProtoFuncNotImplemented DontDelete|Function 0# -- Attributes -- crypto jsDOMWindowBaseCrypto DontDelete|ReadOnly event jsDOMWindowBaseEvent DontDelete# -- Constructors -- Audio jsDOMWindowBaseAudio DontDelete Image jsDOMWindowBaseImage DontDelete MessageChannel jsDOMWindowBaseMessageChannel DontDelete Option jsDOMWindowBaseOption DontDelete WebKitCSSMatrix jsDOMWindowBaseWebKitCSSMatrix DontDelete WebKitPoint jsDOMWindowBaseWebKitPoint DontDelete Worker jsDOMWindowBaseWorker DontDelete XMLHttpRequest jsDOMWindowBaseXMLHttpRequest DontDelete XSLTProcessor jsDOMWindowBaseXSLTProcessor DontDelete@end*/JSDOMWindowBase::JSDOMWindowBaseData::JSDOMWindowBaseData(PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell) : impl(window) , returnValueSlot(0) , shell(shell){}JSDOMWindowBase::JSDOMWindowBase(PassRefPtr<Structure> structure, PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell) : JSDOMGlobalObject(structure, new JSDOMWindowBaseData(window, shell), shell){ GlobalPropertyInfo staticGlobals[] = { GlobalPropertyInfo(Identifier(globalExec(), "document"), jsNull(), DontDelete | ReadOnly), GlobalPropertyInfo(Identifier(globalExec(), "window"), d()->shell, DontDelete | ReadOnly) }; addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));}void JSDOMWindowBase::updateDocument(){ ASSERT(d()->impl->document()); ExecState* exec = globalExec(); symbolTablePutWithAttributes(Identifier(exec, "document"), toJS(exec, d()->impl->document()), DontDelete | ReadOnly);}JSDOMWindowBase::~JSDOMWindowBase(){ if (d()->impl->frame()) d()->impl->frame()->script()->clearFormerWindow(asJSDOMWindow(this));}ScriptExecutionContext* JSDOMWindowBase::scriptExecutionContext() const{ return d()->impl->document();}static bool allowPopUp(ExecState* exec){ Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); ASSERT(frame); if (frame->script()->processingUserGesture()) return true; Settings* settings = frame->settings(); return settings && settings->JavaScriptCanOpenWindowsAutomatically();}static HashMap<String, String> parseModalDialogFeatures(const String& featuresArg){ HashMap<String, String> map; Vector<String> features; featuresArg.split(';', features); Vector<String>::const_iterator end = features.end(); for (Vector<String>::const_iterator it = features.begin(); it != end; ++it) { String s = *it; int pos = s.find('='); int colonPos = s.find(':'); if (pos >= 0 && colonPos >= 0) continue; // ignore any strings that have both = and : if (pos < 0) pos = colonPos; if (pos < 0) { // null string for value means key without value map.set(s.stripWhiteSpace().lower(), String()); } else { String key = s.left(pos).stripWhiteSpace().lower(); String val = s.substring(pos + 1).stripWhiteSpace().lower(); int spacePos = val.find(' '); if (spacePos != -1) val = val.left(spacePos); map.set(key, val); } } return map;}static Frame* createWindow(ExecState* exec, Frame* openerFrame, const String& url, const String& frameName, const WindowFeatures& windowFeatures, JSValuePtr dialogArgs){ Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); ASSERT(activeFrame); ResourceRequest request; request.setHTTPReferrer(activeFrame->loader()->outgoingReferrer()); FrameLoader::addHTTPOriginIfNeeded(request, activeFrame->loader()->outgoingOrigin()); FrameLoadRequest frameRequest(request, frameName); // FIXME: It's much better for client API if a new window starts with a URL, here where we // know what URL we are going to open. Unfortunately, this code passes the empty string // for the URL, but there's a reason for that. Before loading we have to set up the opener, // openedByDOM, and dialogArguments values. Also, to decide whether to use the URL we currently // do an allowsAccessFrom call using the window we create, which can't be done before creating it. // We'd have to resolve all those issues to pass the URL instead of "". bool created; // We pass in the opener frame here so it can be used for looking up the frame name, in case the active frame // is different from the opener frame, and the name references a frame relative to the opener frame, for example // "_self" or "_parent". Frame* newFrame = activeFrame->loader()->createWindow(openerFrame->loader(), frameRequest, windowFeatures, created); if (!newFrame) return 0; newFrame->loader()->setOpener(openerFrame); newFrame->loader()->setOpenedByDOM(); JSDOMWindow* newWindow = toJSDOMWindow(newFrame); if (dialogArgs) newWindow->putDirect(Identifier(exec, "dialogArguments"), dialogArgs); if (!protocolIs(url, "javascript") || newWindow->allowsAccessFrom(exec)) { KURL completedURL = url.isEmpty() ? KURL("") : activeFrame->document()->completeURL(url); bool userGesture = activeFrame->script()->processingUserGesture(); if (created) newFrame->loader()->changeLocation(completedURL, activeFrame->loader()->outgoingReferrer(), false, false, userGesture); else if (!url.isEmpty()) newFrame->loader()->scheduleLocationChange(completedURL.string(), activeFrame->loader()->outgoingReferrer(), !activeFrame->script()->anyPageIsProcessingUserGesture(), false, userGesture); } return newFrame;}static bool canShowModalDialog(const Frame* frame){ if (!frame) return false; Page* page = frame->page(); if (!page) return false; return page->chrome()->canRunModal();}static bool canShowModalDialogNow(const Frame* frame){ if (!frame) return false; Page* page = frame->page(); if (!page) return false; return page->chrome()->canRunModalNow();}static JSValuePtr showModalDialog(ExecState* exec, Frame* frame, const String& url, JSValuePtr dialogArgs, const String& featureArgs){ if (!canShowModalDialogNow(frame) || !allowPopUp(exec)) return jsUndefined(); const HashMap<String, String> features = parseModalDialogFeatures(featureArgs); const bool trusted = false; // The following features from Microsoft's documentation are not implemented: // - default font settings // - width, height, left, and top specified in units other than "px" // - edge (sunken or raised, default is raised) // - dialogHide: trusted && boolFeature(features, "dialoghide"), makes dialog hide when you print // - help: boolFeature(features, "help", true), makes help icon appear in dialog (what does it do on Windows?) // - unadorned: trusted && boolFeature(features, "unadorned"); if (!frame) return jsUndefined(); FloatRect screenRect = screenAvailableRect(frame->view()); WindowFeatures wargs; wargs.width = WindowFeatures::floatFeature(features, "dialogwidth", 100, screenRect.width(), 620); // default here came from frame size of dialog in MacIE wargs.widthSet = true; wargs.height = WindowFeatures::floatFeature(features, "dialogheight", 100, screenRect.height(), 450); // default here came from frame size of dialog in MacIE wargs.heightSet = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -