コード例 #1
0
ファイル: WebDocument.cpp プロジェクト: mirror/chromium
void WebDocument::forms(WebVector<WebFormElement>& results) const {
  HTMLCollection* forms =
      const_cast<Document*>(constUnwrap<Document>())->forms();
  size_t sourceLength = forms->length();
  Vector<WebFormElement> temp;
  temp.reserveCapacity(sourceLength);
  for (size_t i = 0; i < sourceLength; ++i) {
    Element* element = forms->item(i);
    // Strange but true, sometimes node can be 0.
    if (element && element->isHTMLElement())
      temp.append(WebFormElement(toHTMLFormElement(element)));
  }
  results.assign(temp);
}
コード例 #2
0
HTMLImageElement* HTMLMapElement::imageElement()
{
    HTMLCollection* images = document()->images();
    for (unsigned i = 0; Node* curr = images->item(i); i++) {
        if (!curr->hasTagName(imgTag))
            continue;
        
        // The HTMLImageElement's useMap() value includes the '#' symbol at the beginning,
        // which has to be stripped off.
        HTMLImageElement* imageElement = static_cast<HTMLImageElement*>(curr);
        String useMapName = imageElement->getAttribute(usemapAttr).string().substring(1);
        if (equalIgnoringCase(useMapName, m_name))
            return imageElement;
    }
    
    return 0;    
}
コード例 #3
0
HTMLElement* HTMLTableRowElement::insertCell(int index,
                                             ExceptionState& exceptionState) {
  HTMLCollection* children = cells();
  int numCells = children ? children->length() : 0;
  if (index < -1 || index > numCells) {
    exceptionState.throwDOMException(
        IndexSizeError, "The value provided (" + String::number(index) +
                            ") is outside the range [-1, " +
                            String::number(numCells) + "].");
    return nullptr;
  }

  HTMLTableCellElement* cell = HTMLTableCellElement::create(tdTag, document());
  if (numCells == index || index == -1)
    appendChild(cell, exceptionState);
  else
    insertBefore(cell, children->item(index), exceptionState);
  return cell;
}
コード例 #4
0
// HTMLCollections are strange objects, they support both get and call,
// so that document.forms.item(0) and document.forms(0) both work.
static EncodedJSValue JSC_HOST_CALL callHTMLCollection(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return JSValue::encode(jsUndefined());

    // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case.
    JSHTMLCollection* jsCollection = static_cast<JSHTMLCollection*>(exec->callee());
    HTMLCollection* collection = jsCollection->impl();

    // Also, do we need the TypeError test here ?

    if (exec->argumentCount() == 1) {
        // Support for document.all(<index>) etc.
        bool ok;
        UString string = exec->argument(0).toString(exec);
        unsigned index = Identifier::toUInt32(string, ok);
        if (ok)
            return JSValue::encode(toJS(exec, jsCollection->globalObject(), collection->item(index)));

        // Support for document.images('<name>') etc.
        return JSValue::encode(getNamedItems(exec, jsCollection, Identifier(exec, string)));
    }

    // The second arg, if set, is the index of the item we want
    bool ok;
    UString string = exec->argument(0).toString(exec);
    unsigned index = Identifier::toUInt32(exec->argument(1).toString(exec), ok);
    if (ok) {
        String pstr = ustringToString(string);
        Node* node = collection->namedItem(pstr);
        while (node) {
            if (!index)
                return JSValue::encode(toJS(exec, jsCollection->globalObject(), node));
            node = collection->nextNamedItem(pstr);
            --index;
        }
    }

    return JSValue::encode(jsUndefined());
}
コード例 #5
0
// HTMLCollections are strange objects, they support both get and call,
// so that document.forms.item(0) and document.forms(0) both work.
static JSValue JSC_HOST_CALL callHTMLCollection(ExecState* exec, JSObject* function, JSValue, const ArgList& args)
{
    if (args.size() < 1)
        return jsUndefined();

    // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case.
    JSHTMLCollection* jsCollection = static_cast<JSHTMLCollection*>(function);
    HTMLCollection* collection = jsCollection->impl();

    // Also, do we need the TypeError test here ?

    if (args.size() == 1) {
        // Support for document.all(<index>) etc.
        bool ok;
        UString string = args.at(0).toString(exec);
        unsigned index = string.toUInt32(&ok, false);
        if (ok)
            return toJS(exec, jsCollection->globalObject(), collection->item(index));

        // Support for document.images('<name>') etc.
        return getNamedItems(exec, jsCollection, Identifier(exec, string));
    }

    // The second arg, if set, is the index of the item we want
    bool ok;
    UString string = args.at(0).toString(exec);
    unsigned index = args.at(1).toString(exec).toUInt32(&ok, false);
    if (ok) {
        String pstr = string;
        Node* node = collection->namedItem(pstr);
        while (node) {
            if (!index)
                return toJS(exec, jsCollection->globalObject(), node);
            node = collection->nextNamedItem(pstr);
            --index;
        }
    }

    return jsUndefined();
}
コード例 #6
0
void HTMLTableRowElement::deleteCell(int index,
                                     ExceptionState& exceptionState) {
  HTMLCollection* children = cells();
  int numCells = children ? children->length() : 0;
  // 1. If index is less than −1 or greater than or equal to the number of
  // elements in the cells collection, then throw "IndexSizeError".
  if (index < -1 || index >= numCells) {
    exceptionState.throwDOMException(
        IndexSizeError, "The value provided (" + String::number(index) +
                            ") is outside the range [0, " +
                            String::number(numCells) + ").");
    return;
  }
  // 2. If index is −1, remove the last element in the cells collection
  // from its parent, or do nothing if the cells collection is empty.
  if (index == -1) {
    if (numCells == 0)
      return;
    index = numCells - 1;
  }
  // 3. Remove the indexth element in the cells collection from its parent.
  Element* cell = children->item(index);
  HTMLElement::removeChild(cell, exceptionState);
}
コード例 #7
0
ファイル: V8WindowCustom.cpp プロジェクト: mirror/chromium
void V8Window::namedPropertyGetterCustom(
    const AtomicString& name,
    const v8::PropertyCallbackInfo<v8::Value>& info) {
  DOMWindow* window = V8Window::toImpl(info.Holder());
  if (!window)
    return;

  Frame* frame = window->frame();
  // window is detached from a frame.
  if (!frame)
    return;

  // Note that the spec doesn't allow any cross-origin named access to the
  // window object. However, UAs have traditionally allowed named access to
  // named child browsing contexts, even across origins. So first, search child
  // frames for a frame with a matching name.
  Frame* child = frame->tree().scopedChild(name);
  if (child) {
    v8SetReturnValueFast(info, child->domWindow(), window);
    return;
  }

  // If the frame is remote, the caller will never be able to access further
  // named results.
  if (!frame->isLocalFrame())
    return;

  // Search named items in the document.
  Document* doc = toLocalFrame(frame)->document();
  if (!doc || !doc->isHTMLDocument())
    return;

  // This is an AllCanRead interceptor.  Check that the caller has access to the
  // named results.
  if (!BindingSecurity::shouldAllowAccessTo(
          currentDOMWindow(info.GetIsolate()), window,
          BindingSecurity::ErrorReportOption::DoNotReport))
    return;

  bool hasNamedItem = toHTMLDocument(doc)->hasNamedItem(name);
  bool hasIdItem = doc->hasElementWithId(name);

  if (!hasNamedItem && !hasIdItem)
    return;

  if (!hasNamedItem && hasIdItem &&
      !doc->containsMultipleElementsWithId(name)) {
    v8SetReturnValueFast(info, doc->getElementById(name), window);
    return;
  }

  HTMLCollection* items = doc->windowNamedItems(name);
  if (!items->isEmpty()) {
    // TODO(esprehn): Firefox doesn't return an HTMLCollection here if there's
    // multiple with the same name, but Chrome and Safari does. What's the
    // right behavior?
    if (items->hasExactlyOneItem()) {
      v8SetReturnValueFast(info, items->item(0), window);
      return;
    }
    v8SetReturnValueFast(info, items, window);
    return;
  }
}