TextureImageEGL::TextureImageEGL(GLuint aTexture,
                                 const nsIntSize& aSize,
                                 GLenum aWrapMode,
                                 ContentType aContentType,
                                 GLContext* aContext,
                                 Flags aFlags,
                                 TextureState aTextureState,
                                 TextureImage::ImageFormat aImageFormat)
    : TextureImage(aSize, aWrapMode, aContentType, aFlags)
    , mGLContext(aContext)
    , mUpdateFormat(aImageFormat)
    , mEGLImage(nullptr)
    , mTexture(aTexture)
    , mSurface(nullptr)
    , mConfig(nullptr)
    , mTextureState(aTextureState)
    , mBound(false)
{
    if (mUpdateFormat == gfxImageFormat::Unknown) {
        mUpdateFormat = gfxPlatform::GetPlatform()->OptimalFormatForContent(GetContentType());
    }

    if (mUpdateFormat == gfxImageFormat::RGB16_565) {
        mTextureFormat = gfx::SurfaceFormat::R8G8B8X8;
    } else if (mUpdateFormat == gfxImageFormat::RGB24) {
        // RGB24 means really RGBX for Thebes, which means we have to
        // use the right shader and ignore the uninitialized alpha
        // value.
        mTextureFormat = gfx::SurfaceFormat::B8G8R8X8;
    } else {
        mTextureFormat = gfx::SurfaceFormat::B8G8R8A8;
    }
}
TextureImageEGL::TextureImageEGL(GLuint aTexture,
                                 const gfx::IntSize& aSize,
                                 GLenum aWrapMode,
                                 ContentType aContentType,
                                 GLContext* aContext,
                                 Flags aFlags,
                                 TextureState aTextureState,
                                 TextureImage::ImageFormat aImageFormat)
    : TextureImage(aSize, aWrapMode, aContentType, aFlags)
    , mGLContext(aContext)
    , mUpdateFormat(gfx::ImageFormatToSurfaceFormat(aImageFormat))
    , mEGLImage(nullptr)
    , mTexture(aTexture)
    , mSurface(nullptr)
    , mConfig(nullptr)
    , mTextureState(aTextureState)
    , mBound(false)
{
    if (mUpdateFormat == gfx::SurfaceFormat::UNKNOWN) {
        mUpdateFormat =
                gfxPlatform::GetPlatform()->Optimal2DFormatForContent(GetContentType());
    }

    if (mUpdateFormat == gfx::SurfaceFormat::R5G6B5_UINT16) {
        mTextureFormat = gfx::SurfaceFormat::R8G8B8X8;
    } else if (mUpdateFormat == gfx::SurfaceFormat::B8G8R8X8) {
        mTextureFormat = gfx::SurfaceFormat::B8G8R8X8;
    } else {
        mTextureFormat = gfx::SurfaceFormat::B8G8R8A8;
    }
}
Beispiel #3
0
BOOL
MediaSourceImpl::VerifyContentType()
{
	if (m_verified_content_type)
		return TRUE;

	OP_ASSERT(m_use_url->GetAttribute(URL::KMultimedia) != FALSE);
	ContentDetector content_detector(m_use_url->GetRep(), TRUE, TRUE);
	OP_STATUS status = content_detector.DetectContentType();
	if (OpStatus::IsSuccess(status) &&
		(content_detector.WasTheCheckDeterministic() || IsLoadedURL(m_use_url)))
	{
		const char* sniffed_type = GetContentType();
		BOOL3 can_play = NO;
		status = g_media_module.CanPlayType(&can_play, sniffed_type);
		if (OpStatus::IsSuccess(status))
		{
			if (can_play == NO)
				status = OpStatus::ERR_NOT_SUPPORTED;
			else
				m_verified_content_type = TRUE;
		}
	}

	if (OpStatus::IsError(status))
	{
		RAISE_IF_MEMORY_ERROR(status);
		LoadFailed();
	}

	return m_verified_content_type;
}
gfx::DrawTarget*
BasicTextureImage::BeginUpdate(nsIntRegion& aRegion)
{
    NS_ASSERTION(!mUpdateDrawTarget, "BeginUpdate() without EndUpdate()?");

    // determine the region the client will need to repaint
    if (CanUploadSubTextures(mGLContext)) {
        GetUpdateRegion(aRegion);
    } else {
        aRegion = IntRect(IntPoint(0, 0), mSize);
    }

    mUpdateRegion = aRegion;

    IntRect rgnSize = mUpdateRegion.GetBounds();
    if (!IntRect(IntPoint(0, 0), mSize).Contains(rgnSize)) {
        NS_ERROR("update outside of image");
        return nullptr;
    }

    gfx::SurfaceFormat format =
        (GetContentType() == gfxContentType::COLOR) ?
        gfx::SurfaceFormat::B8G8R8X8 : gfx::SurfaceFormat::B8G8R8A8;
    mUpdateDrawTarget =
        GetDrawTargetForUpdate(gfx::IntSize(rgnSize.width, rgnSize.height), format);

    return mUpdateDrawTarget;
}
Beispiel #5
0
bool CWebserverRequest::SendFile(const std::string path,const std::string filename)
{
	if( (tmpint = OpenFile(path, filename) ) != -1 )
	{							// Wenn Datei geöffnet werden konnte
		if (!SocketWrite("HTTP/1.0 200 OK\r\n"))
		{
			close(tmpint);
			return false;
		}
		HttpStatus = 200;

		if (!SocketWrite("Content-Type: " + GetContentType(FileExt) + "\r\n\r\n"))
		{
			close(tmpint);
			return false;
		}
		if (Method == M_HEAD) {
			close(tmpint);
			return true;
		}
		off_t start = 0;
		off_t end = lseek(tmpint,0,SEEK_END);
		int written = 0;
		if((written = sendfile(Socket,tmpint,&start,end)) == -1)
			perror("sendfile failed");
		close(tmpint);
		return true;
	}
	else
	{
		Send404Error();
		return false;
	}
}
NS_IMETHODIMP
WebBrowserPersistLocalDocument::GetContentType(nsACString& aContentType) {
  nsAutoString utf16Type;
  mDocument->GetContentType(utf16Type);
  CopyUTF16toUTF8(utf16Type, aContentType);
  return NS_OK;
}
gfx::DrawTarget*
TiledTextureImage::BeginUpdate(nsIntRegion& aRegion)
{
    NS_ASSERTION(!mInUpdate, "nested update");
    mInUpdate = true;

    // Note, we don't call GetUpdateRegion here as if the updated region is
    // fully contained in a single tile, we get to avoid iterating through
    // the tiles again (and a little copying).
    if (mTextureState != Valid)
    {
        // if the texture hasn't been initialized yet, or something important
        // changed, we need to recreate our backing surface and force the
        // client to paint everything
        aRegion = IntRect(IntPoint(0, 0), mSize);
    }

    IntRect bounds = aRegion.GetBounds();

    for (unsigned i = 0; i < mImages.Length(); i++) {
        int xPos = (i % mColumns) * mTileSize;
        int yPos = (i / mColumns) * mTileSize;
        nsIntRegion imageRegion =
          nsIntRegion(IntRect(IntPoint(xPos,yPos),
                                mImages[i]->GetSize()));

        // a single Image can handle this update request
        if (imageRegion.Contains(aRegion)) {
            // adjust for tile offset
            aRegion.MoveBy(-xPos, -yPos);
            // forward the actual call
            RefPtr<gfx::DrawTarget> drawTarget = mImages[i]->BeginUpdate(aRegion);
            // caller expects container space
            aRegion.MoveBy(xPos, yPos);
            // we don't have a temp surface
            mUpdateDrawTarget = nullptr;
            // remember which image to EndUpdate
            mCurrentImage = i;
            return drawTarget.get();
        }
    }

    // Get the real updated region, taking into account the capabilities of
    // each TextureImage tile
    GetUpdateRegion(aRegion);
    mUpdateRegion = aRegion;
    bounds = aRegion.GetBounds();

    // update covers multiple Images - create a temp surface to paint in
    gfx::SurfaceFormat format =
        (GetContentType() == gfxContentType::COLOR) ?
        gfx::SurfaceFormat::B8G8R8X8: gfx::SurfaceFormat::B8G8R8A8;
    mUpdateDrawTarget = gfx::Factory::CreateDrawTarget(gfx::BackendType::CAIRO,
                                                       bounds.Size(),
                                                       format);

    return mUpdateDrawTarget;;
}
Beispiel #8
0
void AuthDataBlk::Dump( std::ostream &os ) const
{
	// Output buf and data length
	os << "(AuthDataBlock " << endl;
	os << " ContentType=" << (long)GetContentType();
	os << "  UserId="    << mUserId << endl;
    for (AuthCertificateBase::AccessList::const_iterator itr = mAccessList.begin(); itr != mAccessList.end(); ++itr)
        os << " CommunityId=" << itr->mCommunityId << " TrustLevel=" << itr->mTrustLevel << endl;
	os << "  PublicKey=" << mPubKey << endl << ')';
}
Beispiel #9
0
bool CertificateDataBlock::Serialize( WONCommon::RawBuffer &theRawBuf ) const
{
	unsigned short aDataTag = GetContentType();
	theRawBuf.append(reinterpret_cast<const unsigned char*>(&aDataTag), sizeof(aDataTag));

	unsigned short aDataLength = ComputeSize();
	theRawBuf.append(reinterpret_cast<const unsigned char*>(&aDataLength), sizeof(aDataLength));

	return true;
}
void QtCodeToHtmlMainDialog::on_button_convert_clicked()
{
  if (ui->tab_source->currentIndex() == 0)
  {
    //Convert code snippet
    const std::string source
      = std::string(std::tmpnam(0))
      + (GetContentType() == c2h::ContentType::cpp ? ".cpp" : ".txt");
    {
      const std::vector<std::string> v = EditToVector(ui->edit_source_snippet);
      std::ofstream f(source.c_str());
      std::copy(v.begin(),v.end(),std::ostream_iterator<std::string>(f,"\n"));
    }
    c2h::Dialog d(
      GetPageType(),
      source,
      GetContentType(),
      GetTechInfo());
    const std::vector<std::string> v = d.ToHtml();
    Display(v);
    boost::filesystem::remove(source);
  }
  else
  {
    //Convert file or folder
    const std::string source = ui->edit_source->text().toStdString();
    if (!boost::filesystem::exists(source))
    {
      ui->button_convert->setText("Source (file or folder) does not exist");
      ui->button_convert->setEnabled(false);
      return;
    }
    c2h::Dialog d(
      GetPageType(),
      source,
      GetContentType(),
      GetTechInfo());
    const std::vector<std::string> v = d.ToHtml();
    Display(v);
  }
  //Make a screenshot
 // QPixmap::grabWidget(this).save("ToolCodeToHtmlMainDialog.png");
}
NS_IMETHODIMP
WebBrowserPersistLocalDocument::GetContentType(nsACString& aContentType)
{
    nsAutoString utf16Type;
    nsresult rv;

    rv = mDocument->GetContentType(utf16Type);
    NS_ENSURE_SUCCESS(rv, rv);
    aContentType = NS_ConvertUTF16toUTF8(utf16Type);
    return NS_OK;
}
Beispiel #12
0
LPMIMEBLOCK CMime::AddFile( LPCTSTR pFile, LPBYTE buf, DWORD size, DWORD flags )
{_STT();
	// Allocate memory
	LPMIMEBLOCK node = new MIMEBLOCK;
	if ( node == NULL ) return NULL;
	ZeroMimeBlock( node );

	// Get the file name
	if ( pFile != NULL ) { strcpy_sz( node->fname, pFile ); }

	// Get MIME type
	GetContentType( node->fname, node->ctype );

	// Create Content-Type string
	char typestr[ MIME_STRSIZE ];
	wsprintf( typestr, "%s;\r\n\tname=\"%s\"", node->ctype, node->fname );

	// Save header information
	node->var.AddVar( "Content-Type", typestr );
	node->var.AddVar( "Content-Transfer-Encoding", "base64" );

	if ( ( flags & MBF1_ATTACHMENT ) != 0 )
	{
		char disp[ MIME_STRSIZE ];
		wsprintf( disp, "attachment;\r\n\tfilename=\"%s\"", node->fname );
		node->var.AddVar( "Content-Disposition", disp );
	} // end if

	// Save flags
	node->f1 = flags;
	node->f1 |= MBF1_DECODED;

	// Use base64 encoding
	node->encode = MBEN_BASE64;

	// Any data?
	if ( size > 0 )
	{
		// Allocate memory
		node->pdata = new char[ size + 1 ];
		if ( node->pdata == NULL ) { delete node; return FALSE; }

		// Copy the data
		memcpy( node->pdata, buf, size );
		node->dsize = size;

		// NULL terminate (just in case)
		( (LPBYTE)node->pdata )[ size ] = 0;

	} // end if

	return AddBlock( node );
}
Beispiel #13
0
   // Return the media type represented by Content-Type field (see RFC 2046)
   MimeHeader::MediaType MimeHeader::GetMediaType() const
   {
      const char* pszType = GetContentType();
      if (!pszType)
         pszType = "text";

      int nIndex = 0;
      while (m_TypeTable[nIndex] != NULL &&
         ::_memicmp(pszType, m_TypeTable[nIndex], ::strlen(m_TypeTable[nIndex])) != 0)
         nIndex++;
      return (MediaType) nIndex;
   }
void WtDialog::on_button_convert_clicked()
{
  if (ui.m_stack->currentIndex() == 0)
  {
    const std::string source
      = std::string(std::tmpnam(0))
      + (GetContentType() == c2h::ContentType::cpp ? ".cpp" : ".txt");

    {
      const std::vector<std::string> v = AreaToVector(ui.m_area_snippet);
      std::ofstream f(source.c_str());
      std::copy(v.begin(),v.end(),std::ostream_iterator<std::string>(f,"\n"));
    }
    c2h::Dialog d(
      GetPageType(),
      source,
      GetContentType(),
      GetTechInfo());
    const std::vector<std::string> v = d.ToHtml();
    Display(v);
    boost::filesystem::remove(source);
  }
  else
  {
    //assert(ui->tab_source->currentWidget() == ui->tab_source_snippet);
    const std::string source = ui.m_edit_source->text().toUTF8();
    if (!boost::filesystem::exists(source))
    {
      ui.m_button_convert->setText("Source (file or folder) does not exist");
      return;
    }
    c2h::Dialog d(
      GetPageType(),
      source,
      GetContentType(),
      GetTechInfo());
    const std::vector<std::string> v = d.ToHtml();
    Display(v);
  }
}
Beispiel #15
0
nsresult
ChannelMediaResource::RecreateChannel()
{
  nsLoadFlags loadFlags =
    nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY |
    (mLoadInBackground ? nsIRequest::LOAD_BACKGROUND : 0);

  MediaDecoderOwner* owner = mDecoder->GetMediaOwner();
  if (!owner) {
    // The decoder is being shut down, so don't bother opening a new channel
    return NS_OK;
  }
  dom::HTMLMediaElement* element = owner->GetMediaElement();
  if (!element) {
    // The decoder is being shut down, so don't bother opening a new channel
    return NS_OK;
  }
  nsCOMPtr<nsILoadGroup> loadGroup = element->GetDocumentLoadGroup();
  NS_ENSURE_TRUE(loadGroup, NS_ERROR_NULL_POINTER);

  nsCOMPtr<nsIChannel> channel;
  nsresult rv = NS_NewChannel(getter_AddRefs(channel),
                              mURI,
                              nullptr,
                              loadGroup,
                              nullptr,
                              loadFlags);
  mChannel = new nsMainThreadPtrHolder<nsIChannel>(channel);

  // We have cached the Content-Type, which should not change. Give a hint to
  // the channel to avoid a sniffing failure, which would be expected because we
  // are probably seeking in the middle of the bitstream, and sniffing relies
  // on the presence of a magic number at the beginning of the stream.
  NS_ASSERTION(!GetContentType().IsEmpty(),
      "When recreating a channel, we should know the Content-Type.");
  mChannel->SetContentType(GetContentType());

  return rv;
}
Beispiel #16
0
int CheckIfFileIsFlash(const char * filename)
{
 // if (AmmServer_FileExists(filename))
  {
    char contentType[512];
    GetContentType(filename,contentType,512);
    if ( GetExtentionType(contentType)==FLASH)
    {
      //Todo also check internals of files ( file magic number headers etc )
      return 1;
    }
  }
  return 0;
}
Beispiel #17
0
// retrieves file and sends it to client
bool GetFile(int conn, const char *fname)
{
 if (!fname) return false;
 
 // open file
 FILE *fp = fopen(fname,"rb");
 if (!fp) return false;
 
 // get file size
 fseek(fp,0,SEEK_END);
 const int size = ftell(fp);
 fseek(fp,0,SEEK_SET);
 
 // read data
 char *data = NULL;
 if (size > 0) {
  data = new char[size];
  fread(data,size,1,fp);
 }
 
 // close file
 fclose( fp );
 
 // raw head by default
 const char *ctype = GetContentType( fname );
 
 const char *fmt = "HTTP/1.1 200 OK\r\n"
                   "Content-Length: %i\r\n"
                   "Content-Type: %s\r\n"
                 //"Connection: close\r\n"
                   "\r\n";
 
 // write header to client socket
 char head[256];
 sprintf(head, fmt, size, ctype);
 write(conn, head, strlen(head) );
 
 // write data to client socket
 if (data) {
  write(conn, data, size);
 }
 
 // deallocate
 if (data) {
  delete [] data;
 }
 
 // success
 return true;
}
int CHttpString::GetCharset(){
	CString strContentType = GetContentType();
	int nLeft = strContentType.Find("charset=");
	nLeft = nLeft + 8;
	CString strChatset = "";
	strChatset = strContentType.Mid(nLeft,strContentType.GetLength() - nLeft);
	strChatset.Replace(" ","");
	strChatset.Replace("\t","");
	strChatset.Replace("\r","");
	strChatset.Replace("\n","");
	if(strChatset == "ANSI") return 1;
	else if(strChatset == "UTF-8") return 2;
	else return -1;
}
Beispiel #19
0
   // initialize the content of this body part with a mail message
   bool MimeBody::SetMessage(const MimeBody* pMM)
   {
      ASSERT(pMM != NULL);
      int nSize = pMM->GetLength();
      if (!AllocateBuffer(nSize+4))
         return false;

      pMM->Store(m_pbText);

      const char* pszType = GetContentType();
      if (!pszType || ::_memicmp(pszType, "message", 7) != 0)
         SetContentType("message/rfc822", "");

      return true;
   }
Beispiel #20
0
 // get the top-level media type
 string MimeHeader::GetMainType() const
 {
    string strType;
    const char* pszType = GetContentType();
    if (pszType != NULL)
    {
       const char* pszSlash = ::strchr(pszType, '/');
       if (pszSlash != NULL)
          strType.assign(pszType, pszSlash-pszType);
       else
          strType = pszType;
    }
    else
       strType = "text";
    return strType;
 }
Beispiel #21
0
/*
	GetIcyData()
*/
void CIcy::GetIcyData(ICYDATA* pIcyData)
{
	memset(pIcyData,'\0',sizeof(ICYDATA));
	if(m_nResponse==ICY_CODE_OK)
	{
		strcpyn(pIcyData->station,GetStationName(),ICY_MAX_STATION+1);
		strcpyn(pIcyData->genre,GetGenre(),ICY_MAX_GENRE+1);
		strcpyn(pIcyData->url,GetUrl(),ICY_MAX_URL+1);
		strcpyn(pIcyData->contenttype,GetContentType(),ICY_MAX_CONTENT+1);
		pIcyData->metaint = GetMetaInterval();
		pIcyData->bitrate = GetBitRate();
		strcpyn(pIcyData->notice,GetNotice(),ICY_MAX_NOTICE+1);
		strcpyn(pIcyData->noticeinfo,GetNoticeInfo(),ICY_MAX_NOTICE+1);
		pIcyData->code = m_nResponse;
	}
}
Beispiel #22
0
// initialize the content of this body part with a mail message
bool CMimeBody::SetMessage(const CMimeMessage* pMM)
{
	ASSERT(pMM != NULL);
	int nSize = pMM->GetLength();
	if (!AllocateBuffer(nSize+4))
		return false;

	nSize = pMM->Store((char*)m_pbText, nSize);
	m_pbText[nSize] = 0;
	m_nTextSize = nSize;

	const char* pszType = GetContentType();
	if (!pszType || ::memicmp(pszType, "message", 7) != 0)
		SetContentType("message/rfc822");
	//SetTransferEncoding(CMimeConst::EncodingBinary());	// in case the default 7bit cause folding
	return true;
}
void CPlayerPlaylistBar::ParsePlayList(CAtlList<CString>& fns, CAtlList<CString>* subs)
{
    if (fns.IsEmpty()) {
        return;
    }

    const CAppSettings& s = AfxGetAppSettings();

    ResolveLinkFiles(fns);

    CAtlList<CString> sl;
    if (SearchFiles(fns.GetHead(), sl)) {
        if (sl.GetCount() > 1) {
            subs = NULL;
        }
        POSITION pos = sl.GetHeadPosition();
        while (pos) {
            ParsePlayList(sl.GetNext(pos), subs);
        }
        return;
    }

    CAtlList<CString> redir;
    CStringA ct = GetContentType(fns.GetHead(), &redir);
    if (!redir.IsEmpty()) {
        POSITION pos = redir.GetHeadPosition();
        while (pos) {
            ParsePlayList(sl.GetNext(pos), subs);
        }
        return;
    }

    if (ct == "application/x-mpc-playlist") {
        ParseMPCPlayList(fns.GetHead());
        return;
    } else {
#if INTERNAL_SOURCEFILTER_MPEG
        if (ct == "application/x-bdmv-playlist" && s.SrcFilters[SRC_MPEG]) {
            ParseBDMVPlayList(fns.GetHead());
            return;
        }
#endif
    }

    AddItem(fns, subs);
}
Beispiel #24
0
int GetExtensionImage(char * filename, char * theimagepath,unsigned int theimagepath_length)
{
   //fprintf(stderr,"GetExtensionImage for %s \n",filename);
   GetContentType(filename,theimagepath,theimagepath_length);
   //fprintf(stderr,"GetExtentionType for %s \n",filename);
   int res=GetExtentionType(theimagepath);
   //fprintf(stderr,"yields %u\n",res);
   switch (res)
   {
     case TEXT       :  snprintf(theimagepath,theimagepath_length,"doc.gif");    break;
     case IMAGE      :  snprintf(theimagepath,theimagepath_length,"img.gif");  break;
     case VIDEO      :  snprintf(theimagepath,theimagepath_length,"vid.gif");  break;
     case AUDIO      :  snprintf(theimagepath,theimagepath_length,"mus.gif");  break;
     case EXECUTABLE :  snprintf(theimagepath,theimagepath_length,"exe.gif");    break;
     default         :  snprintf(theimagepath,theimagepath_length,"dir.gif");  break;
   }
   if ( res == NO_FILETYPE ) { return 0; }
   return 1;
}
Beispiel #25
0
already_AddRefed<gfxASurface>
gfxWindowsSurface::CreateSimilarSurface(gfxContentType aContent,
                                        const gfxIntSize& aSize)
{
    if (!mSurface || !mSurfaceValid) {
        return nullptr;
    }

    cairo_surface_t *surface;
    if (!mForPrinting && GetContentType() == gfxContentType::COLOR_ALPHA) {
        // When creating a similar surface to a transparent surface, ensure
        // the new surface uses a DIB. cairo_surface_create_similar won't
        // use  a DIB for a gfxContentType::COLOR surface if this surface doesn't
        // have a DIB (e.g. if we're a transparent window surface). But
        // we need a DIB to perform well if the new surface is composited into
        // a surface that's the result of create_similar(gfxContentType::COLOR_ALPHA)
        // (e.g. a backbuffer for the window) --- that new surface *would*
        // have a DIB.
        surface =
          cairo_win32_surface_create_with_dib((cairo_format_t)(int)gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent),
                                              aSize.width, aSize.height);
    } else {
        surface =
          cairo_surface_create_similar(mSurface, (cairo_content_t)(int)aContent,
                                       aSize.width, aSize.height);
    }

    if (cairo_surface_status(surface)) {
        cairo_surface_destroy(surface);
        return nullptr;
    }

    nsRefPtr<gfxASurface> result = Wrap(surface);
    if (mForPrinting) {
      MOZ_ASSERT(result->GetType() == gfxSurfaceType::Recording);
      gfxUnknownSurface *unknown = static_cast<gfxUnknownSurface*>(result.get());
      unknown->SetSize(aSize);
    }
    cairo_surface_destroy(surface);
    return result.forget();
}
already_AddRefed<gfxASurface>
gfxWindowsSurface::CreateSimilarSurface(gfxContentType aContent,
                                        const mozilla::gfx::IntSize& aSize)
{
    if (!mSurface || !mSurfaceValid) {
        return nullptr;
    }

    cairo_surface_t *surface;
    if (!mForPrinting && GetContentType() == gfxContentType::COLOR_ALPHA) {
        // When creating a similar surface to a transparent surface, ensure
        // the new surface uses a DIB. cairo_surface_create_similar won't
        // use  a DIB for a gfxContentType::COLOR surface if this surface doesn't
        // have a DIB (e.g. if we're a transparent window surface). But
        // we need a DIB to perform well if the new surface is composited into
        // a surface that's the result of create_similar(gfxContentType::COLOR_ALPHA)
        // (e.g. a backbuffer for the window) --- that new surface *would*
        // have a DIB.
        gfxImageFormat gformat =
            gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
        cairo_format_t cformat = gfxImageFormatToCairoFormat(gformat);
        surface = cairo_win32_surface_create_with_dib(cformat, aSize.width,
                                                      aSize.height);
    } else {
        surface =
          cairo_surface_create_similar(mSurface, (cairo_content_t)(int)aContent,
                                       aSize.width, aSize.height);
    }

    if (cairo_surface_status(surface)) {
        cairo_surface_destroy(surface);
        return nullptr;
    }

    RefPtr<gfxASurface> result = Wrap(surface, aSize);
    cairo_surface_destroy(surface);
    return result.forget();
}
already_AddRefed<MediaResource> ChannelMediaResource::CloneData(MediaDecoder* aDecoder)
{
  NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
  NS_ASSERTION(mCacheStream.IsAvailableForSharing(), "Stream can't be cloned");

  nsRefPtr<ChannelMediaResource> resource =
    new ChannelMediaResource(aDecoder,
                             nullptr,
                             mURI,
                             GetContentType());
  if (resource) {
    // Initially the clone is treated as suspended by the cache, because
    // we don't have a channel. If the cache needs to read data from the clone
    // it will call CacheClientResume (or CacheClientSeek with aResume true)
    // which will recreate the channel. This way, if all of the media data
    // is already in the cache we don't create an unnecessary HTTP channel
    // and perform a useless HTTP transaction.
    resource->mSuspendCount = 1;
    resource->mCacheStream.InitAsClone(&mCacheStream);
    resource->mChannelStatistics = new MediaChannelStatistics(mChannelStatistics);
    resource->mChannelStatistics->Stop();
  }
  return resource.forget();
}
already_AddRefed<gfxASurface>
gfxWindowsSurface::CreateSimilarSurface(gfxContentType aContent,
                                        const gfxIntSize& aSize)
{
    if (!mSurface || !mSurfaceValid) {
        return nsnull;
    }

    cairo_surface_t *surface;
    if (GetContentType() == CONTENT_COLOR_ALPHA) {
        // When creating a similar surface to a transparent surface, ensure
        // the new surface uses a DIB. cairo_surface_create_similar won't
        // use  a DIB for a CONTENT_COLOR surface if this surface doesn't
        // have a DIB (e.g. if we're a transparent window surface). But
        // we need a DIB to perform well if the new surface is composited into
        // a surface that's the result of create_similar(CONTENT_COLOR_ALPHA)
        // (e.g. a backbuffer for the window) --- that new surface *would*
        // have a DIB.
        surface =
          cairo_win32_surface_create_with_dib(cairo_format_t(gfxASurface::FormatFromContent(aContent)),
                                              aSize.width, aSize.height);
    } else {
        surface =
          cairo_surface_create_similar(mSurface, cairo_content_t(aContent),
                                       aSize.width, aSize.height);
    }

    if (cairo_surface_status(surface)) {
        cairo_surface_destroy(surface);
        return nsnull;
    }

    nsRefPtr<gfxASurface> result = Wrap(surface);
    cairo_surface_destroy(surface);
    return result.forget();
}
STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR* pszAdditionalHeaders)
{
  if (!szURL)
  {
    return E_POINTER;
  }
  std::wstring src = szURL;
  UnescapeUrl(src);
  DEBUG_GENERAL(src);

  std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol);

  if (pszAdditionalHeaders)
  {
    *pszAdditionalHeaders = nullptr;
  }

  CComPtr<IHttpNegotiate> httpNegotiate;
  QueryServiceFromClient(&httpNegotiate);
  // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need.
  // There doesn't seem to be any other way to get this header before the request has been made.
  HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK;

  if (pszAdditionalHeaders && *pszAdditionalHeaders)
  {
    m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Referer:", L"\n");
  }
  m_boundDomain = TrimString(m_boundDomain);
  m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDomain, src);

  CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId());
  CPluginClient* client = CPluginClient::GetInstance();

  if (tab && client)
  {
    std::wstring documentUrl = tab->GetDocumentUrl();
    // Page is identical to document => don't block
    if (documentUrl == src)
    {
      return nativeHr;
    }
    else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhitelistedUrl(documentUrl))
    {
      if (tab->IsFrameCached(src))
      {
        m_contentType = ContentType::CONTENT_TYPE_SUBDOCUMENT;
      }
    }
  }

  if (IsFlashRequest(pszAdditionalHeaders))
  {
    m_contentType = ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST;
  }

  if (pszAdditionalHeaders && *pszAdditionalHeaders && IsXmlHttpRequest(*pszAdditionalHeaders))
  {
    m_contentType = ContentType::CONTENT_TYPE_XMLHTTPREQUEST;
  }

  if (client->ShouldBlock(szURL, m_contentType, m_boundDomain, /*debug flag but must be set*/true))
  {
    // NOTE: Feeding custom HTML to Flash, instead of original object subrequest
    // doesn't have much sense. It also can manifest in unwanted result
    // like video being blocked (See https://issues.adblockplus.org/ticket/1669)
    // So we report blocked object subrequests as failed, not just empty HTML.
    m_isCustomResponse = m_contentType != ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST;
    return E_ABORT;
  }
  return nativeHr;
}
Beispiel #30
0
// CertificateDataBlock::Compare
// Compares two CertificateDataBlock objects.
// This function should be called from the base class Compare.
//
int CertificateDataBlock::Compare(const CertificateDataBlock& theDataR) const
{
	return ( GetContentType() - theDataR.GetContentType() );
}