void DOMWindowFileSystem::webkitRequestFileSystem(DOMWindow& windowArg, int type, long long size, FileSystemCallback* successCallback, ErrorCallback* errorCallback) { LocalDOMWindow& window = toLocalDOMWindow(windowArg); if (!window.isCurrentlyDisplayedInFrame()) return; Document* document = window.document(); if (!document) return; if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(document->securityOrigin()->protocol())) UseCounter::count(document, UseCounter::RequestFileSystemNonWebbyOrigin); if (!document->securityOrigin()->canAccessFileSystem()) { DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::SECURITY_ERR)); return; } FileSystemType fileSystemType = static_cast<FileSystemType>(type); if (!DOMFileSystemBase::isValidType(fileSystemType)) { DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR)); return; } LocalFileSystem::from(*document)->requestFileSystem(document, fileSystemType, size, FileSystemCallbacks::create(successCallback, errorCallback, document, fileSystemType)); }
void V8Window::eventAttributeGetterCustom( const v8::PropertyCallbackInfo<v8::Value>& info) { LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); ExceptionState exceptionState(ExceptionState::GetterContext, "event", "Window", info.Holder(), info.GetIsolate()); if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, exceptionState)) { return; } LocalFrame* frame = impl->frame(); ASSERT(frame); // This is a fast path to retrieve info.Holder()->CreationContext(). v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current(info.GetIsolate())); if (context.IsEmpty()) return; v8::Local<v8::Value> jsEvent = V8HiddenValue::getHiddenValue( ScriptState::current(info.GetIsolate()), context->Global(), V8HiddenValue::event(info.GetIsolate())); if (jsEvent.IsEmpty()) return; v8SetReturnValue(info, jsEvent); }
void V8Window::openMethodCustom( const v8::FunctionCallbackInfo<v8::Value>& info) { DOMWindow* impl = V8Window::toImpl(info.Holder()); ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Window", info.Holder(), info.GetIsolate()); if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, exceptionState)) { return; } TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, urlString, info[0]); AtomicString frameName; if (info[1]->IsUndefined() || info[1]->IsNull()) { frameName = "_blank"; } else { TOSTRING_VOID(V8StringResource<>, frameNameResource, info[1]); frameName = frameNameResource; } TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, windowFeaturesString, info[2]); // |impl| has to be a LocalDOMWindow, since RemoteDOMWindows wouldn't have // passed the BindingSecurity check above. DOMWindow* openedWindow = toLocalDOMWindow(impl)->open( urlString, frameName, windowFeaturesString, currentDOMWindow(info.GetIsolate()), enteredDOMWindow(info.GetIsolate())); if (!openedWindow) { v8SetReturnValueNull(info); return; } v8SetReturnValueFast(info, openedWindow, impl); }
Database* DOMWindowWebDatabase::openDatabase(DOMWindow& windowArg, const String& name, const String& version, const String& displayName, unsigned estimatedSize, DatabaseCallback* creationCallback, ExceptionState& exceptionState) { LocalDOMWindow& window = toLocalDOMWindow(windowArg); if (!window.isCurrentlyDisplayedInFrame()) return nullptr; Database* database = nullptr; DatabaseManager& dbManager = DatabaseManager::manager(); DatabaseError error = DatabaseError::None; if (RuntimeEnabledFeatures::databaseEnabled() && window.document()->getSecurityOrigin()->canAccessDatabase()) { String errorMessage; database = dbManager.openDatabase(window.document(), name, version, displayName, estimatedSize, creationCallback, error, errorMessage); ASSERT(database || error != DatabaseError::None); if (error != DatabaseError::None) DatabaseManager::throwExceptionForDatabaseError(error, errorMessage, exceptionState); } else { exceptionState.throwSecurityError( "Access to the WebDatabase API is denied in this context."); } return database; }
static float pageZoomFactor(const UIEvent* event) { if (!event->view() || !event->view()->isLocalDOMWindow()) return 1; LocalFrame* frame = toLocalDOMWindow(event->view())->frame(); if (!frame) return 1; return frame->pageZoomFactor(); }
void TouchEvent::preventDefault() { UIEventWithKeyState::preventDefault(); // A common developer error is to wait too long before attempting to stop // scrolling by consuming a touchmove event. Generate a warning if this // event is uncancelable. if (!cancelable() && view() && view()->isLocalDOMWindow() && view()->frame()) { toLocalDOMWindow(view())->frame()->console().addMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "Ignored attempt to cancel a " + type() + " event with cancelable=false, for example because scrolling is in progress and cannot be interrupted.")); } }
static LayoutSize contentsScrollOffset(AbstractView* abstractView) { if (!abstractView || !abstractView->isLocalDOMWindow()) return LayoutSize(); LocalFrame* frame = toLocalDOMWindow(abstractView)->frame(); if (!frame) return LayoutSize(); FrameView* frameView = frame->view(); if (!frameView) return LayoutSize(); float scaleFactor = frame->pageZoomFactor(); return LayoutSize(frameView->scrollX() / scaleFactor, frameView->scrollY() / scaleFactor); }
void V8DevToolsHost::showContextMenuAtPointMethodCustom( const v8::FunctionCallbackInfo<v8::Value>& info) { if (info.Length() < 3) return; ExceptionState exceptionState(ExceptionState::ExecutionContext, "showContextMenuAtPoint", "DevToolsHost", info.Holder(), info.GetIsolate()); v8::Isolate* isolate = info.GetIsolate(); float x = toRestrictedFloat(isolate, info[0], exceptionState); if (exceptionState.hadException()) return; float y = toRestrictedFloat(isolate, info[1], exceptionState); if (exceptionState.hadException()) return; v8::Local<v8::Value> array = v8::Local<v8::Value>::Cast(info[2]); if (!array->IsArray()) return; ContextMenu menu; if (!populateContextMenuItems(isolate, v8::Local<v8::Array>::Cast(array), menu)) return; Document* document = nullptr; if (info.Length() >= 4 && v8::Local<v8::Value>::Cast(info[3])->IsObject()) { v8::Local<v8::Object> documentWrapper = v8::Local<v8::Object>::Cast(info[3]); if (!V8HTMLDocument::wrapperTypeInfo.equals( toWrapperTypeInfo(documentWrapper))) return; document = V8HTMLDocument::toImpl(documentWrapper); } else { v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChain( isolate->GetEnteredContext()->Global(), isolate); if (windowWrapper.IsEmpty()) return; DOMWindow* window = V8Window::toImpl(windowWrapper); document = window ? toLocalDOMWindow(window)->document() : nullptr; } if (!document || !document->frame()) return; DevToolsHost* devtoolsHost = V8DevToolsHost::toImpl(info.Holder()); Vector<ContextMenuItem> items = menu.items(); devtoolsHost->showContextMenu(document->frame(), x, y, items); }
AtomicString V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix) { v8::Isolate* isolate = m_scriptState->isolate(); v8::Local<v8::Function> lookupNamespaceURIFunc; v8::Local<v8::String> lookupNamespaceURIName = v8AtomicString(isolate, "lookupNamespaceURI"); // Check if the resolver has a function property named lookupNamespaceURI. v8::Local<v8::Value> lookupNamespaceURI; if (m_resolver->Get(m_scriptState->context(), lookupNamespaceURIName) .ToLocal(&lookupNamespaceURI) && lookupNamespaceURI->IsFunction()) lookupNamespaceURIFunc = v8::Local<v8::Function>::Cast(lookupNamespaceURI); if (lookupNamespaceURIFunc.IsEmpty() && !m_resolver->IsFunction()) { LocalFrame* frame = toLocalDOMWindow(toDOMWindow(m_scriptState->context()))->frame(); if (frame && frame->host()) frame->console().addMessage(ConsoleMessage::create( JSMessageSource, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.")); return nullAtom; } // Catch exceptions from calling the namespace resolver. v8::TryCatch tryCatch(isolate); tryCatch.SetVerbose(true); // Print exceptions to console. const int argc = 1; v8::Local<v8::Value> argv[argc] = {v8String(isolate, prefix)}; v8::Local<v8::Function> function = lookupNamespaceURIFunc.IsEmpty() ? v8::Local<v8::Function>::Cast(m_resolver) : lookupNamespaceURIFunc; v8::Local<v8::Value> retval; // Eat exceptions from namespace resolver and return an empty string. This // will most likely cause NamespaceError. if (!V8ScriptRunner::callFunction( function, toExecutionContext(m_scriptState->context()), m_resolver, argc, argv, isolate) .ToLocal(&retval)) return nullAtom; TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, returnString, retval, nullAtom); return returnString; }
void V8Window::eventAttributeSetterCustom(v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) { LocalFrame* frame = toLocalDOMWindow(V8Window::toImpl(info.Holder()))->frame(); ExceptionState exceptionState(ExceptionState::SetterContext, "event", "Window", info.Holder(), info.GetIsolate()); if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), frame, exceptionState)) { exceptionState.throwIfNeeded(); return; } ASSERT(frame); // This is a fast path to retrieve info.Holder()->CreationContext(). v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current(info.GetIsolate())); if (context.IsEmpty()) return; V8HiddenValue::setHiddenValue(info.GetIsolate(), context->Global(), V8HiddenValue::event(info.GetIsolate()), value); }
static bool securityCheck(v8::Local<v8::Object> host) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local<v8::Object> window = V8Window::findInstanceInPrototypeChain(host, isolate); if (window.IsEmpty()) return false; // the frame is gone. DOMWindow* targetWindow = V8Window::toImpl(window); ASSERT(targetWindow); if (!targetWindow->isLocalDOMWindow()) return false; LocalFrame* target = toLocalDOMWindow(targetWindow)->frame(); if (!target) return false; // Notify the loader's client if the initial document has been accessed. if (target->loader().stateMachine()->isDisplayingInitialEmptyDocument()) target->loader().didAccessInitialDocument(); return BindingSecurity::shouldAllowAccessToFrame(isolate, target, DoNotReportSecurityError); }
void V8Window::frameElementAttributeGetterCustom( const v8::PropertyCallbackInfo<v8::Value>& info) { LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); if (!BindingSecurity::shouldAllowAccessTo( currentDOMWindow(info.GetIsolate()), impl->frameElement(), BindingSecurity::ErrorReportOption::DoNotReport)) { v8SetReturnValueNull(info); return; } // The wrapper for an <iframe> should get its prototype from the context of // the frame it's in, rather than its own frame. // So, use its containing document as the creation context when wrapping. v8::Local<v8::Value> creationContext = toV8(&impl->frameElement()->document(), info.Holder(), info.GetIsolate()); RELEASE_ASSERT(!creationContext.IsEmpty()); v8::Local<v8::Value> wrapper = toV8(impl->frameElement(), v8::Local<v8::Object>::Cast(creationContext), info.GetIsolate()); v8SetReturnValue(info, wrapper); }
void V8Window::frameElementAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info) { LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); ExceptionState exceptionState(ExceptionState::GetterContext, "frame", "Window", info.Holder(), info.GetIsolate()); // Do the security check against the parent frame rather than // frameElement() itself, so that a remote parent frame can be handled // properly. In that case, there's no frameElement(), yet we should still // throw a proper exception and deny access. Frame* target = impl->frame() ? impl->frame()->tree().parent() : nullptr; if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), target, exceptionState)) { v8SetReturnValueNull(info); exceptionState.throwIfNeeded(); return; } // The wrapper for an <iframe> should get its prototype from the context of the frame it's in, rather than its own frame. // So, use its containing document as the creation context when wrapping. v8::Local<v8::Value> creationContext = toV8(&impl->frameElement()->document(), info.Holder(), info.GetIsolate()); RELEASE_ASSERT(!creationContext.IsEmpty()); v8::Local<v8::Value> wrapper = toV8(impl->frameElement(), v8::Local<v8::Object>::Cast(creationContext), info.GetIsolate()); v8SetReturnValue(info, wrapper); }
MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> abstractView, int detail, const IntPoint& screenLocation, const IntPoint& rootFrameLocation, const IntPoint& movementDelta, PlatformEvent::Modifiers modifiers, double platformTimeStamp, PositionType positionType, InputDeviceCapabilities* sourceCapabilities) : UIEventWithKeyState(eventType, canBubble, cancelable, abstractView, detail, modifiers, platformTimeStamp, sourceCapabilities) , m_screenLocation(screenLocation) , m_movementDelta(movementDelta) , m_positionType(positionType) { LayoutPoint adjustedPageLocation; LayoutPoint scrollPosition; LocalFrame* frame = view() && view()->isLocalDOMWindow() ? toLocalDOMWindow(view())->frame() : nullptr; if (frame && hasPosition()) { if (FrameView* frameView = frame->view()) { scrollPosition = frameView->scrollPosition(); adjustedPageLocation = frameView->rootFrameToContents(rootFrameLocation); float scaleFactor = 1 / frame->pageZoomFactor(); if (scaleFactor != 1.0f) { adjustedPageLocation.scale(scaleFactor, scaleFactor); scrollPosition.scale(scaleFactor, scaleFactor); } } } m_clientLocation = adjustedPageLocation - toLayoutSize(scrollPosition); m_pageLocation = adjustedPageLocation; // Set up initial values for coordinates. // Correct values are computed lazily, see computeRelativePosition. m_layerLocation = m_pageLocation; m_offsetLocation = m_pageLocation; computePageLocation(); m_hasCachedRelativePosition = false; }
void DOMWindowFileSystem::webkitResolveLocalFileSystemURL(DOMWindow& windowArg, const String& url, EntryCallback* successCallback, ErrorCallback* errorCallback) { LocalDOMWindow& window = toLocalDOMWindow(windowArg); if (!window.isCurrentlyDisplayedInFrame()) return; Document* document = window.document(); if (!document) return; SecurityOrigin* securityOrigin = document->securityOrigin(); KURL completedURL = document->completeURL(url); if (!securityOrigin->canAccessFileSystem() || !securityOrigin->canRequest(completedURL)) { DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::SECURITY_ERR)); return; } if (!completedURL.isValid()) { DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::ENCODING_ERR)); return; } LocalFileSystem::from(*document)->resolveURL(document, completedURL, ResolveURICallbacks::create(successCallback, errorCallback, document)); }
// static Worklet* WindowAnimationWorklet::animationWorklet(DOMWindow& window) { return from(toLocalDOMWindow(window)).animationWorklet(); }
// static Storage* DOMWindowStorage::localStorage(DOMWindow& window, ExceptionState& exceptionState) { return from(toLocalDOMWindow(window)).localStorage(exceptionState); }
IDBFactory* DOMWindowIndexedDatabase::indexedDB(DOMWindow& window) { return from(toLocalDOMWindow(window)).indexedDB(); }
// static SpeechSynthesis* DOMWindowSpeechSynthesis::speechSynthesis(DOMWindow& window) { return DOMWindowSpeechSynthesis::from(toLocalDOMWindow(window)) .speechSynthesis(); }
IDBFactory* GlobalIndexedDB::indexedDB(DOMWindow& window) { return GlobalIndexedDBImpl<LocalDOMWindow>::from(toLocalDOMWindow(window)) .idbFactory(toLocalDOMWindow(window)); }
// static Performance* DOMWindowPerformance::performance(DOMWindow& window) { return from(toLocalDOMWindow(window)).performance(); }
THREE* DOMWindowTHREE::three(DOMWindow& window) { return DOMWindowTHREE::from(toLocalDOMWindow(window)).three(); }
LocalDOMWindow* ScriptState::domWindow() const { v8::HandleScope scope(m_isolate); return toLocalDOMWindow(toDOMWindow(context())); }
// static DeprecatedStorageInfo* DOMWindowQuota::webkitStorageInfo(DOMWindow& window) { return DOMWindowQuota::from(toLocalDOMWindow(window)).webkitStorageInfo(); }
bool MainThreadDebugger::callingContextCanAccessContext(v8::Local<v8::Context> calling, v8::Local<v8::Context> target) { DOMWindow* window = toDOMWindow(target); return window && BindingSecurity::shouldAllowAccessTo(m_isolate, toLocalDOMWindow(toDOMWindow(calling)), window, DoNotReportSecurityError); }
Crypto* DOMWindowCrypto::crypto(DOMWindow& window) { return DOMWindowCrypto::from(toLocalDOMWindow(window)).crypto(); }
WebCL* DOMWindowWebCL::webcl(DOMWindow& window) { return from(toLocalDOMWindow(window)).webcl(); }
CacheStorage* GlobalCacheStorage::caches(DOMWindow& window, ExceptionState& exceptionState) { return GlobalCacheStorageImpl<LocalDOMWindow>::from( toLocalDOMWindow(window), window.getExecutionContext()) .caches(toLocalDOMWindow(window), exceptionState); }