void WMLTimerElement::timerFired(Timer<WMLTimerElement>*) { if (!m_card) return; WMLPageState* pageState = wmlPageStateForDocument(document()); if (!pageState) return; String value = this->value(); // When the timer expires, set the name varialbe of timer to '0' if (!m_name.isEmpty()) { value = "0"; pageState->storeVariable(m_name, value); } WMLIntrinsicEventType eventType = WMLIntrinsicEventOnTimer; WMLIntrinsicEventHandler* eventHandler = m_card->eventHandler(); bool hasIntrinsicEvent = false; if (eventHandler && eventHandler->hasIntrinsicEvent(eventType)) hasIntrinsicEvent = true; else if (m_card->templateElement()) { eventHandler = m_card->templateElement()->eventHandler(); if (eventHandler && eventHandler->hasIntrinsicEvent(eventType)) hasIntrinsicEvent = true; } if (hasIntrinsicEvent) eventHandler->triggerIntrinsicEvent(eventType); }
bool WMLDocument::initialize(bool aboutToFinishParsing) { WMLPageState* wmlPageState = wmlPageStateForDocument(this); if (!wmlPageState || !wmlPageState->canAccessDeck()) return false; // Remember that we'e successfully entered the deck wmlPageState->resetAccessControlData(); // Notify the existance of templates to all cards of the current deck WMLTemplateElement::registerTemplatesInDocument(this); // Set destination card m_activeCard = WMLCardElement::determineActiveCard(this); if (!m_activeCard) { reportWMLError(this, WMLErrorNoCardInDocument); return true; } // Handle deck-level task overrides m_activeCard->handleDeckLevelTaskOverridesIfNeeded(); // Handle card-level intrinsic event if (!aboutToFinishParsing) m_activeCard->handleIntrinsicEventIfNeeded(); return true; }
void WMLInputElement::initialize() { String nameVariable = formControlName(); String variableValue; WMLPageState* pageSate = wmlPageStateForDocument(document()); ASSERT(pageSate); if (!nameVariable.isEmpty()) variableValue = pageSate->getVariable(nameVariable); if (variableValue.isEmpty() || !isConformedToInputMask(variableValue)) { String val = value(); if (isConformedToInputMask(val)) variableValue = val; else variableValue = ""; pageSate->storeVariable(nameVariable, variableValue); } setValue(variableValue); if (!hasAttribute(WMLNames::emptyokAttr)) { if (m_formatMask.isEmpty() || // check if the format codes is just "*f" (m_formatMask.length() == 2 && m_formatMask[0] == '*' && formatCodes().find(m_formatMask[1]) != -1)) m_isEmptyOk = true; } }
void WMLSelectElement::calculateDefaultOptionIndices() { WMLPageState* pageState = wmlPageStateForDocument(document()); if (!pageState) return; String variable; // Spec: If the 'iname' attribute is specified and names a variable that is set, // then the default option index is the validated value of that variable. String iname = this->iname(); if (!iname.isEmpty()) { variable = pageState->getVariable(iname); if (!variable.isEmpty()) m_defaultOptionIndices = parseIndexValueString(variable); } // Spec: If the default option index is empty and the 'ivalue' attribute is specified, // then the default option index is the validated attribute value. String ivalue = this->ivalue(); if (m_defaultOptionIndices.isEmpty() && !ivalue.isEmpty()) m_defaultOptionIndices = parseIndexValueString(ivalue); // Spec: If the default option index is empty, and the 'name' attribute is specified // and the 'name' ttribute names a variable that is set, then for each value in the 'name' // variable that is present as a value in the select's option elements, the index of the // first option element containing that value is added to the default index if that // index has not been previously added. String name = this->name(); if (m_defaultOptionIndices.isEmpty() && !name.isEmpty()) { variable = pageState->getVariable(name); if (!variable.isEmpty()) m_defaultOptionIndices = valueStringToOptionIndices(variable); } String value = parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::valueAttr)); // Spec: If the default option index is empty and the 'value' attribute is specified then // for each value in the 'value' attribute that is present as a value in the select's // option elements, the index of the first option element containing that value is added // to the default index if that index has not been previously added. if (m_defaultOptionIndices.isEmpty() && !value.isEmpty()) m_defaultOptionIndices = valueStringToOptionIndices(value); // Spec: If the default option index is empty and the select is a multi-choice, then the // default option index is set to zero. If the select is single-choice, then the default // option index is set to one. if (m_defaultOptionIndices.isEmpty()) m_defaultOptionIndices.append((unsigned) !m_data.multiple()); }
void WMLPrevElement::executeTask(Event*) { WMLPageState* pageState = wmlPageStateForDocument(document()); if (!pageState) return; WMLCardElement* card = pageState->activeCard(); if (!card) return; storeVariableState(pageState); // Stop the timer of the current card if it is active if (WMLTimerElement* eventTimer = card->eventTimer()) eventTimer->stop(); pageState->page()->goBack(); }
void WMLDoElement::defaultEventHandler(Event* event) { if (m_isOptional) return; if (event->type() == eventNames().keypressEvent) { WMLElement::defaultEventHandler(event); return; } if (event->type() != eventNames().clickEvent && event->type() != eventNames().keydownEvent) return; if (event->isKeyboardEvent() && static_cast<KeyboardEvent*>(event)->keyIdentifier() != "Enter") return; if (m_type == "accept" || m_type == "options") { if (m_task) m_task->executeTask(); } else if (m_type == "prev") { ASSERT(document()->isWMLDocument()); WMLDocument* document = static_cast<WMLDocument*>(this->document()); WMLPageState* pageState = wmlPageStateForDocument(document); if (!pageState) return; // Stop the timer of the current card if it is active if (WMLCardElement* card = document->activeCard()) { if (WMLTimerElement* eventTimer = card->eventTimer()) eventTimer->stop(); } pageState->page()->goBack(); } else if (m_type == "reset") { WMLPageState* pageState = wmlPageStateForDocument(document()); if (!pageState) return; pageState->reset(); } }
void WMLSelectElement::updateVariables() { WMLPageState* pageState = wmlPageStateForDocument(document()); if (!pageState) return; String name = this->name(); String iname = this->iname(); if (iname.isEmpty() && name.isEmpty()) return; String nameString; String inameString; unsigned optionIndex = 0; const Vector<Element*>& items = m_data.listItems(this); for (unsigned i = 0; i < items.size(); ++i) { OptionElement* optionElement = toOptionElement(items[i]); if (!optionElement) continue; ++optionIndex; if (!optionElement->selected()) continue; if (!nameString.isEmpty()) nameString += ";"; if (!inameString.isEmpty()) inameString += ";"; nameString += optionElement->value(); inameString += String::number(optionIndex); } if (!name.isEmpty()) pageState->storeVariable(name, nameString); if (!iname.isEmpty()) pageState->storeVariable(iname, inameString); }
void WMLSelectElement::initializeVariables() { ASSERT(!m_defaultOptionIndices.isEmpty()); WMLPageState* pageState = wmlPageStateForDocument(document()); if (!pageState) return; const Vector<Element*>& items = m_data.listItems(this); if (items.isEmpty()) return; // Spec: If the 'iname' attribute is specified, then the named variable is set with the default option index. String iname = this->iname(); if (!iname.isEmpty()) pageState->storeVariable(iname, optionIndicesToString()); String name = this->name(); if (name.isEmpty()) return; if (m_data.multiple()) { // Spec: If the 'name' attribute is specified and the select is a multiple-choice element, // then for each index greater than zero, the value of the 'value' attribute on the option // element at the index is added to the name variable. pageState->storeVariable(name, optionIndicesToValueString()); return; } // Spec: If the 'name' attribute is specified and the select is a single-choice element, // then the named variable is set with the value of the 'value' attribute on the option // element at the default option index. unsigned optionIndex = m_defaultOptionIndices.first(); ASSERT(optionIndex >= 1); int listIndex = optionToListIndex(optionIndex - 1); ASSERT(listIndex >= 0); ASSERT(listIndex < (int) items.size()); if (OptionElement* optionElement = toOptionElement(items[listIndex])) pageState->storeVariable(name, optionElement->value()); }
void Text::insertedIntoDocument() { CharacterData::insertedIntoDocument(); if (!parentNode()->isWMLElement() || !length()) return; WMLPageState* pageState = wmlPageStateForDocument(document()); if (!pageState->hasVariables()) return; String text = data(); if (!text.impl() || text.impl()->containsOnlyWhitespace()) return; text = substituteVariableReferences(text, document()); ExceptionCode ec; setData(text, ec); }
void WMLDocument::finishedParsing() { if (ScriptableDocumentParser* parser = this->scriptableDocumentParser()) { if (!parser->wellFormed()) { Document::finishedParsing(); return; } } bool hasAccess = initialize(true); Document::finishedParsing(); if (!hasAccess) { m_activeCard = 0; WMLPageState* wmlPageState = wmlPageStateForDocument(this); if (!wmlPageState) return; Page* page = wmlPageState->page(); if (!page) return; HistoryItem* item = page->backForward()->backItem(); if (!item) return; page->goToItem(item, FrameLoadTypeBackWMLDeckNotAccessible); return; } /// M: ALPS00439551 set a flag to prevent infinite loop in WMLDocument @{ if (m_policyDownloadError) { m_policyDownloadError = false; return; } /// @} /// M: ALPS00439551 use a timer to trigger handleIntrinsicEventIfNeeded() m_intrinsicEventTimer.startOneShot(0.0f); }
void WMLPrevElement::executeTask() { ASSERT(document()->isWMLDocument()); WMLDocument* document = static_cast<WMLDocument*>(this->document()); WMLPageState* pageState = wmlPageStateForDocument(document); if (!pageState) return; WMLCardElement* card = document->activeCard(); if (!card) return; storeVariableState(pageState); // Stop the timer of the current card if it is active if (WMLTimerElement* eventTimer = card->eventTimer()) eventTimer->stop(); pageState->page()->goBack(); }
void WMLDocument::finishedParsing() { if (Tokenizer* tokenizer = this->tokenizer()) { if (!tokenizer->wellFormed()) { Document::finishedParsing(); return; } } bool hasAccess = initialize(true); Document::finishedParsing(); if (!hasAccess) { m_activeCard = 0; WMLPageState* wmlPageState = wmlPageStateForDocument(this); if (!wmlPageState) return; Page* page = wmlPageState->page(); if (!page) return; BackForwardList* list = page->backForwardList(); if (!list) return; HistoryItem* item = list->backItem(); if (!item) return; page->goToItem(item, FrameLoadTypeBackWMLDeckNotAccessible); return; } if (m_activeCard) { m_activeCard->handleIntrinsicEventIfNeeded(); m_activeCard = 0; } }
void WMLDocument::finishedParsing() { if (Tokenizer* tokenizer = this->tokenizer()) { if (!tokenizer->wellFormed()) { Document::finishedParsing(); return; } } WMLPageState* wmlPageState = wmlPageStateForDocument(this); if (!wmlPageState->isDeckAccessible()) { reportWMLError(this, WMLErrorDeckNotAccessible); Document::finishedParsing(); return; } // Remember that we'e successfully entered the deck wmlPageState->setNeedCheckDeckAccess(false); // Notify the existance of templates to all cards of the current deck WMLTemplateElement::registerTemplatesInDocument(this); // Set destination card WMLCardElement* card = WMLCardElement::determineActiveCard(this); if (!card) { reportWMLError(this, WMLErrorNoCardInDocument); Document::finishedParsing(); return; } // Handle deck-level task overrides card->handleDeckLevelTaskOverridesIfNeeded(); // Handle card-level intrinsic event card->handleIntrinsicEventIfNeeded(); Document::finishedParsing(); }
String substituteVariableReferences(const String& reference, Document* document, WMLVariableEscapingMode escapeMode) { ASSERT(document); if (reference.isEmpty()) return reference; WMLPageState* pageState = wmlPageStateForDocument(document); if (!pageState) return reference; bool isValid = true; String remainingInput = reference; String result; while (!remainingInput.isEmpty()) { ASSERT(isValid); int start = remainingInput.find("$"); if (start == -1) { // Consume all remaining characters, as there's nothing more to substitute result += remainingInput; break; } // Consume all characters until the variable reference beginning result += remainingInput.left(start); remainingInput.remove(0, start); // Transform adjacent dollar signs into a single dollar sign as string literal if (remainingInput[1] == '$') { result += "$"; remainingInput.remove(0, 2); continue; } String variableName; String conversionMode; if (remainingInput[1] == '(') { int referenceEndPosition = remainingInput.find(")"); if (referenceEndPosition == -1) { isValid = false; break; } variableName = remainingInput.substring(2, referenceEndPosition - 2); remainingInput.remove(0, referenceEndPosition + 1); // Determine variable conversion mode string int pos = variableName.find(':'); if (pos != -1) { conversionMode = variableName.substring(pos + 1, variableName.length() - (pos + 1)); variableName = variableName.left(pos); } } else { int length = remainingInput.length(); int referenceEndPosition = 1; for (; referenceEndPosition < length; ++referenceEndPosition) { if (!isValidVariableNameCharacter(remainingInput[referenceEndPosition])) break; } variableName = remainingInput.substring(1, referenceEndPosition - 1); remainingInput.remove(0, referenceEndPosition); } isValid = isValidVariableName(variableName); if (!isValid) break; ASSERT(!variableName.isEmpty()); String variableValue = pageState->getVariable(variableName); if (variableValue.isEmpty()) continue; if (containsVariableReference(variableValue, isValid)) { if (!isValid) break; variableValue = substituteVariableReferences(variableValue, document, escapeMode); continue; } if (!conversionMode.isEmpty()) { // Override default escape mode, if desired WMLVariableEscapingMode specifiedEscapeMode = WMLVariableEscapingNone; if ((isValid = isValidVariableEscapingModeString(conversionMode, specifiedEscapeMode))) escapeMode = specifiedEscapeMode; if (!isValid) break; } switch (escapeMode) { case WMLVariableEscapingNone: break; case WMLVariableEscapingEscape: variableValue = encodeWithURLEscapeSequences(variableValue); break; case WMLVariableEscapingUnescape: variableValue = decodeURLEscapeSequences(variableValue); break; } result += variableValue; ASSERT(isValid); } if (!isValid) { reportWMLError(document, WMLErrorInvalidVariableReference); return reference; } return result; }
void WMLGoElement::executeTask() { ASSERT(document()->isWMLDocument()); WMLDocument* document = static_cast<WMLDocument*>(this->document()); WMLPageState* pageState = wmlPageStateForDocument(document); if (!pageState) return; WMLCardElement* card = document->activeCard(); if (!card) return; Frame* frame = document->frame(); if (!frame) return; FrameLoader* loader = frame->loader(); if (!loader) return; String href = getAttribute(HTMLNames::hrefAttr); if (href.isEmpty()) return; // Substitute variables within target url attribute value KURL url = document->completeURL(substituteVariableReferences(href, document, WMLVariableEscapingEscape)); if (url.isEmpty()) return; storeVariableState(pageState); // Stop the timer of the current card if it is active if (WMLTimerElement* eventTimer = card->eventTimer()) eventTimer->stop(); // FIXME: 'newcontext' handling not implemented for external cards bool inSameDeck = document->url().path() == url.path(); if (inSameDeck && url.hasFragmentIdentifier()) { if (WMLCardElement* card = WMLCardElement::findNamedCardInDocument(document, url.fragmentIdentifier())) { if (card->isNewContext()) pageState->reset(); } } // Prepare loading the destination url ResourceRequest request(url); if (getAttribute(sendrefererAttr) == "true") request.setHTTPReferrer(loader->outgoingReferrer()); String cacheControl = getAttribute(cache_controlAttr); if (m_formAttributes.method() == FormSubmission::PostMethod) preparePOSTRequest(request, inSameDeck, cacheControl); else prepareGETRequest(request, url); // Set HTTP cache-control header if needed if (!cacheControl.isEmpty()) { request.setHTTPHeaderField("cache-control", cacheControl); if (cacheControl == "no-cache") request.setCachePolicy(ReloadIgnoringCacheData); } loader->load(request, false); }