content/html/document/src/VideoDocument.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "MediaDocument.h"
     7 #include "nsGkAtoms.h"
     8 #include "nsNodeInfoManager.h"
     9 #include "nsContentCreatorFunctions.h"
    10 #include "mozilla/dom/HTMLMediaElement.h"
    11 #include "nsIDocumentInlines.h"
    12 #include "nsContentUtils.h"
    13 #include "mozilla/dom/Element.h"
    15 namespace mozilla {
    16 namespace dom {
    18 class VideoDocument MOZ_FINAL : public MediaDocument
    19 {
    20 public:
    21   virtual nsresult StartDocumentLoad(const char*         aCommand,
    22                                      nsIChannel*         aChannel,
    23                                      nsILoadGroup*       aLoadGroup,
    24                                      nsISupports*        aContainer,
    25                                      nsIStreamListener** aDocListener,
    26                                      bool                aReset = true,
    27                                      nsIContentSink*     aSink = nullptr);
    28   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
    30 protected:
    32   // Sets document <title> to reflect the file name and description.
    33   void UpdateTitle(nsIChannel* aChannel);
    35   nsresult CreateSyntheticVideoDocument(nsIChannel* aChannel,
    36                                         nsIStreamListener** aListener);
    38   nsRefPtr<MediaDocumentStreamListener> mStreamListener;
    39 };
    41 nsresult
    42 VideoDocument::StartDocumentLoad(const char*         aCommand,
    43                                  nsIChannel*         aChannel,
    44                                  nsILoadGroup*       aLoadGroup,
    45                                  nsISupports*        aContainer,
    46                                  nsIStreamListener** aDocListener,
    47                                  bool                aReset,
    48                                  nsIContentSink*     aSink)
    49 {
    50   nsresult rv =
    51     MediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer,
    52                                      aDocListener, aReset, aSink);
    53   NS_ENSURE_SUCCESS(rv, rv);
    55   mStreamListener = new MediaDocumentStreamListener(this);
    57   // Create synthetic document
    58   rv = CreateSyntheticVideoDocument(aChannel,
    59       getter_AddRefs(mStreamListener->mNextStream));
    60   NS_ENSURE_SUCCESS(rv, rv);
    62   NS_ADDREF(*aDocListener = mStreamListener);
    63   return rv;
    64 }
    66 void
    67 VideoDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
    68 {
    69   // Set the script global object on the superclass before doing
    70   // anything that might require it....
    71   MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
    73   if (aScriptGlobalObject) {
    74     if (!nsContentUtils::IsChildOfSameType(this) &&
    75         GetReadyStateEnum() != nsIDocument::READYSTATE_COMPLETE) {
    76       LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelVideoDocument.css"));
    77       LinkStylesheet(NS_LITERAL_STRING("chrome://global/skin/media/TopLevelVideoDocument.css"));
    78     }
    79     BecomeInteractive();
    80   }
    81 }
    83 nsresult
    84 VideoDocument::CreateSyntheticVideoDocument(nsIChannel* aChannel,
    85                                             nsIStreamListener** aListener)
    86 {
    87   // make our generic document
    88   nsresult rv = MediaDocument::CreateSyntheticDocument();
    89   NS_ENSURE_SUCCESS(rv, rv);
    91   Element* body = GetBodyElement();
    92   if (!body) {
    93     NS_WARNING("no body on video document!");
    94     return NS_ERROR_FAILURE;
    95   }
    97   // make content
    98   nsCOMPtr<nsINodeInfo> nodeInfo;
    99   nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::video, nullptr,
   100                                            kNameSpaceID_XHTML,
   101                                            nsIDOMNode::ELEMENT_NODE);
   103   nsRefPtr<HTMLMediaElement> element =
   104     static_cast<HTMLMediaElement*>(NS_NewHTMLVideoElement(nodeInfo.forget(),
   105                                                           NOT_FROM_PARSER));
   106   if (!element)
   107     return NS_ERROR_OUT_OF_MEMORY;
   108   element->SetAutoplay(true);
   109   element->SetControls(true);
   110   element->LoadWithChannel(aChannel, aListener);
   111   UpdateTitle(aChannel);
   113   if (nsContentUtils::IsChildOfSameType(this)) {
   114     // Video documents that aren't toplevel should fill their frames and
   115     // not have margins
   116     element->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
   117         NS_LITERAL_STRING("position:absolute; top:0; left:0; width:100%; height:100%"),
   118         true);
   119   }
   121   return body->AppendChildTo(element, false);
   122 }
   124 void
   125 VideoDocument::UpdateTitle(nsIChannel* aChannel)
   126 {
   127   if (!aChannel)
   128     return;
   130   nsAutoString fileName;
   131   GetFileName(fileName);
   132   SetTitle(fileName);
   133 }
   135 } // namespace dom
   136 } // namespace mozilla
   138 nsresult
   139 NS_NewVideoDocument(nsIDocument** aResult)
   140 {
   141   mozilla::dom::VideoDocument* doc = new mozilla::dom::VideoDocument();
   143   NS_ADDREF(doc);
   144   nsresult rv = doc->Init();
   146   if (NS_FAILED(rv)) {
   147     NS_RELEASE(doc);
   148   }
   150   *aResult = doc;
   152   return rv;
   153 }

mercurial