Esempio n. 1
0
 static void srcAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
   INC_STATS("DOM.HTMLSourceElement.src._set");
   HTMLSourceElement* imp = V8HTMLSourceElement::toNative(info.Holder());
   V8Parameter<> v = value;
   imp->setSrc(v);
   return;
 }
Esempio n. 2
0
void JSHTMLSourceElement::putValueProperty(ExecState* exec, int token, JSValue* value)
{
    switch (token) {
    case SrcAttrNum: {
        HTMLSourceElement* imp = static_cast<HTMLSourceElement*>(impl());
        imp->setSrc(value->toString(exec));
        break;
    }
    case TypeAttrNum: {
        HTMLSourceElement* imp = static_cast<HTMLSourceElement*>(impl());
        imp->setType(value->toString(exec));
        break;
    }
    case MediaAttrNum: {
        HTMLSourceElement* imp = static_cast<HTMLSourceElement*>(impl());
        imp->setMedia(value->toString(exec));
        break;
    }
    }
}
Esempio n. 3
0
void MediaDocumentParser::createDocumentStructure()
{
    RefPtr<Element> rootElement = document()->createElement(htmlTag, false);
    document()->appendChild(rootElement, IGNORE_EXCEPTION);
    document()->setCSSTarget(rootElement.get());
    static_cast<HTMLHtmlElement*>(rootElement.get())->insertedByParser();

    if (document()->frame())
        document()->frame()->loader()->dispatchDocumentElementAvailable();
        
    RefPtr<Element> body = document()->createElement(bodyTag, false);
    rootElement->appendChild(body, IGNORE_EXCEPTION);

    RefPtr<Element> mediaElement = document()->createElement(videoTag, false);

    m_mediaElement = static_cast<HTMLVideoElement*>(mediaElement.get());
    m_mediaElement->setAttribute(controlsAttr, "");
    m_mediaElement->setAttribute(autoplayAttr, "");

    m_mediaElement->setAttribute(nameAttr, "media");

    RefPtr<Element> sourceElement = document()->createElement(sourceTag, false);
    HTMLSourceElement* source = static_cast<HTMLSourceElement*>(sourceElement.get());
    source->setSrc(document()->url());

    if (DocumentLoader* loader = document()->loader())
        source->setType(loader->responseMIMEType());

    m_mediaElement->appendChild(sourceElement, IGNORE_EXCEPTION);
    body->appendChild(mediaElement, IGNORE_EXCEPTION);

    Frame* frame = document()->frame();
    if (!frame)
        return;

    frame->loader()->activeDocumentLoader()->setMainResourceDataBufferingPolicy(DoNotBufferData);
}
void setJSHTMLSourceElementSrc(ExecState* exec, JSObject* thisObject, JSValue value)
{
    JSHTMLSourceElement* castedThisObj = static_cast<JSHTMLSourceElement*>(thisObject);
    HTMLSourceElement* imp = static_cast<HTMLSourceElement*>(castedThisObj->impl());
    imp->setSrc(value.toString(exec));
}
Esempio n. 5
0
void MediaDocumentParser::createDocumentStructure() {
  DCHECK(document());
  HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*document());
  document()->appendChild(rootElement);
  rootElement->insertedByParser();

  if (isDetached())
    return;  // runScriptsAtDocumentElementAvailable can detach the frame.

  HTMLHeadElement* head = HTMLHeadElement::create(*document());
  HTMLMetaElement* meta = HTMLMetaElement::create(*document());
  meta->setAttribute(nameAttr, "viewport");
  meta->setAttribute(contentAttr, "width=device-width");
  head->appendChild(meta);

  HTMLVideoElement* media = HTMLVideoElement::create(*document());
  media->setAttribute(controlsAttr, "");
  media->setAttribute(autoplayAttr, "");
  media->setAttribute(nameAttr, "media");

  HTMLSourceElement* source = HTMLSourceElement::create(*document());
  source->setSrc(document()->url());

  if (DocumentLoader* loader = document()->loader())
    source->setType(loader->responseMIMEType());

  media->appendChild(source);

  HTMLBodyElement* body = HTMLBodyElement::create(*document());
  body->setAttribute(styleAttr, "margin: 0px;");

  document()->willInsertBody();

  HTMLDivElement* div = HTMLDivElement::create(*document());
  // Style sheets for media controls are lazily loaded until a media element is
  // encountered.  As a result, elements encountered before the media element
  // will not get the right style at first if we put the styles in
  // mediacontrols.css. To solve this issue, set the styles inline so that they
  // will be applied when the page loads.  See w3c example on how to centering
  // an element: https://www.w3.org/Style/Examples/007/center.en.html
  div->setAttribute(styleAttr,
                    "display: flex;"
                    "flex-direction: column;"
                    "justify-content: center;"
                    "align-items: center;"
                    "min-height: min-content;"
                    "height: 100%;");
  HTMLContentElement* content = HTMLContentElement::create(*document());
  div->appendChild(content);

  if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) {
    HTMLAnchorElement* anchor = HTMLAnchorElement::create(*document());
    anchor->setAttribute(downloadAttr, "");
    anchor->setURL(document()->url());
    anchor->setTextContent(
        document()
            ->getCachedLocale(document()->contentLanguage())
            .queryString(WebLocalizedString::DownloadButtonLabel)
            .upper());
    // Using CSS style according to Android material design.
    anchor->setAttribute(
        styleAttr,
        "display: inline-block;"
        "margin-top: 32px;"
        "padding: 0 16px 0 16px;"
        "height: 36px;"
        "background: #000000;"
        "-webkit-tap-highlight-color: rgba(255, 255, 255, 0.12);"
        "font-family: Roboto;"
        "font-size: 14px;"
        "border-radius: 5px;"
        "color: white;"
        "font-weight: 500;"
        "text-decoration: none;"
        "line-height: 36px;");
    EventListener* listener = MediaDownloadEventListener::create();
    anchor->addEventListener(EventTypeNames::click, listener, false);
    HTMLDivElement* buttonContainer = HTMLDivElement::create(*document());
    buttonContainer->setAttribute(styleAttr,
                                  "text-align: center;"
                                  "height: 0;"
                                  "flex: none");
    buttonContainer->appendChild(anchor);
    div->appendChild(buttonContainer);
    recordDownloadMetric(MediaDocumentDownloadButtonShown);
  }

  // According to
  // https://html.spec.whatwg.org/multipage/browsers.html#read-media,
  // MediaDocument should have a single child which is the video element. Use
  // shadow root to hide all the elements we added here.
  ShadowRoot& shadowRoot = body->ensureUserAgentShadowRoot();
  shadowRoot.appendChild(div);
  body->appendChild(media);
  rootElement->appendChild(head);
  rootElement->appendChild(body);

  m_didBuildDocumentStructure = true;
}