docshell/base/SerializedLoadContext.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set sw=2 ts=8 et tw=80 : */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "SerializedLoadContext.h"
     8 #include "nsNetUtil.h"
     9 #include "nsIChannel.h"
    10 #include "nsIWebSocketChannel.h"
    12 namespace IPC {
    14 SerializedLoadContext::SerializedLoadContext(nsILoadContext* aLoadContext)
    15 {
    16   Init(aLoadContext);
    17 }
    19 SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel)
    20 {
    21   if (!aChannel) {
    22     Init(nullptr);
    23     return;
    24   }
    26   nsCOMPtr<nsILoadContext> loadContext;
    27   NS_QueryNotificationCallbacks(aChannel, loadContext);
    28   Init(loadContext);
    30   if (!loadContext) {
    31     // Attempt to retrieve the private bit from the channel if it has been
    32     // overriden.
    33     bool isPrivate = false;
    34     bool isOverriden = false;
    35     nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(aChannel);
    36     if (pbChannel &&
    37         NS_SUCCEEDED(pbChannel->IsPrivateModeOverriden(&isPrivate, &isOverriden)) &&
    38         isOverriden) {
    39       mUsePrivateBrowsing = isPrivate;
    40       mIsPrivateBitValid = true;
    41     }
    42   }
    43 }
    45 SerializedLoadContext::SerializedLoadContext(nsIWebSocketChannel* aChannel)
    46 {
    47   nsCOMPtr<nsILoadContext> loadContext;
    48   if (aChannel) {
    49     NS_QueryNotificationCallbacks(aChannel, loadContext);
    50   }
    51   Init(loadContext);
    52 }
    54 void
    55 SerializedLoadContext::Init(nsILoadContext* aLoadContext)
    56 {
    57   if (aLoadContext) {
    58     mIsNotNull = true;
    59     mIsPrivateBitValid = true;
    60     aLoadContext->GetIsContent(&mIsContent);
    61     aLoadContext->GetUsePrivateBrowsing(&mUsePrivateBrowsing);
    62     aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs);
    63     aLoadContext->GetAppId(&mAppId);
    64     aLoadContext->GetIsInBrowserElement(&mIsInBrowserElement);
    65   } else {
    66     mIsNotNull = false;
    67     mIsPrivateBitValid = false;
    68     // none of below values really matter when mIsNotNull == false:
    69     // we won't be GetInterfaced to nsILoadContext
    70     mIsContent = true;
    71     mUsePrivateBrowsing = false;
    72     mUseRemoteTabs = false;
    73     mAppId = 0;
    74     mIsInBrowserElement = false;
    75   }
    76 }
    78 } // namespace IPC

mercurial