1*859212d1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*859212d1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*859212d1SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*859212d1SAndrew Rist * distributed with this work for additional information
6*859212d1SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*859212d1SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*859212d1SAndrew Rist * "License"); you may not use this file except in compliance
9*859212d1SAndrew Rist * with the License. You may obtain a copy of the License at
10*859212d1SAndrew Rist *
11*859212d1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*859212d1SAndrew Rist *
13*859212d1SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*859212d1SAndrew Rist * software distributed under the License is distributed on an
15*859212d1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*859212d1SAndrew Rist * KIND, either express or implied. See the License for the
17*859212d1SAndrew Rist * specific language governing permissions and limitations
18*859212d1SAndrew Rist * under the License.
19*859212d1SAndrew Rist *
20*859212d1SAndrew Rist *************************************************************/
21*859212d1SAndrew Rist
22*859212d1SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include <svl/httpcook.hxx>
25cdf0e10cSrcweir #include <tools/urlobj.hxx>
26cdf0e10cSrcweir #include <vcl/msgbox.hxx>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #ifndef UUI_COOKIEDG_HRC
29cdf0e10cSrcweir #include <cookiedg.hrc>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include <cookiedg.hxx>
32cdf0e10cSrcweir #ifndef UUI_IDS_HRC
33cdf0e10cSrcweir #include <ids.hrc>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir
36cdf0e10cSrcweir // CookiesDialog ---------------------------------------------------------
37cdf0e10cSrcweir
IMPL_LINK(CookiesDialog,ButtonHdl_Impl,PushButton *,pBtn)38cdf0e10cSrcweir IMPL_LINK( CookiesDialog, ButtonHdl_Impl, PushButton *, pBtn )
39cdf0e10cSrcweir {
40cdf0e10cSrcweir short nRet = ( &maSendBtn == pBtn ) ? RET_OK : RET_CANCEL;
41cdf0e10cSrcweir EndDialog( nRet );
42cdf0e10cSrcweir return 1;
43cdf0e10cSrcweir }
44cdf0e10cSrcweir
45cdf0e10cSrcweir // -----------------------------------------------------------------------
CookiesDialog(Window * pParent,CntHTTPCookieRequest * pRequest,ResMgr * pResMgr)46cdf0e10cSrcweir CookiesDialog::CookiesDialog( Window* pParent,
47cdf0e10cSrcweir CntHTTPCookieRequest* pRequest,
48cdf0e10cSrcweir ResMgr* pResMgr ) :
49cdf0e10cSrcweir
50cdf0e10cSrcweir ModalDialog( pParent, ResId( DLG_COOKIES, *pResMgr ) ),
51cdf0e10cSrcweir
52cdf0e10cSrcweir maCookieFB ( this, ResId( FB_COOKIES, *pResMgr ) ),
53cdf0e10cSrcweir maCookieFT ( this, ResId( FT_COOKIES, *pResMgr ) ),
54cdf0e10cSrcweir maInFutureLine ( this, ResId( FL_COOKIES, *pResMgr ) ),
55cdf0e10cSrcweir maInFutureSendBtn ( this, ResId( RB_INFUTURE_SEND, *pResMgr ) ),
56cdf0e10cSrcweir maInFutureIgnoreBtn ( this, ResId( RB_INFUTURE_IGNORE, *pResMgr ) ),
57cdf0e10cSrcweir maInFutureInteractiveBtn( this, ResId( RB_INFUTURE_INTERACTIVE, *pResMgr ) ),
58cdf0e10cSrcweir maInFutureGB ( this, ResId( GB_INFUTURE, *pResMgr ) ),
59cdf0e10cSrcweir maIgnoreBtn ( this, ResId( BTN_COOKIES_CANCEL, *pResMgr ) ),
60cdf0e10cSrcweir maSendBtn ( this, ResId( BTN_COOKIES_OK, *pResMgr ) ),
61cdf0e10cSrcweir
62cdf0e10cSrcweir mpCookieRequest ( pRequest )
63cdf0e10cSrcweir
64cdf0e10cSrcweir {
65cdf0e10cSrcweir FreeResource();
66cdf0e10cSrcweir
67cdf0e10cSrcweir Link aLink( LINK( this, CookiesDialog, ButtonHdl_Impl ) );
68cdf0e10cSrcweir maIgnoreBtn.SetClickHdl( aLink );
69cdf0e10cSrcweir maSendBtn.SetClickHdl( aLink );
70cdf0e10cSrcweir const Bitmap& rBitmap = maCookieFB.GetBitmap();
71cdf0e10cSrcweir Size aSize = rBitmap.GetSizePixel();
72cdf0e10cSrcweir SetMapMode( MapMode( MAP_APPFONT ) );
73cdf0e10cSrcweir Size aLogicSize = PixelToLogic( aSize );
74cdf0e10cSrcweir Point aPoint( 6 ,
75cdf0e10cSrcweir 6 + ( 145 - aLogicSize.Height() ) / 2 );
76cdf0e10cSrcweir maCookieFB.SetPosSizePixel( LogicToPixel( aPoint ), aSize );
77cdf0e10cSrcweir maCookieFB.Show();
78cdf0e10cSrcweir
79cdf0e10cSrcweir sal_uInt16 nOffset = CNTHTTP_COOKIE_REQUEST_RECV == mpCookieRequest->m_eType
80cdf0e10cSrcweir ? 0 : STR_COOKIES_SEND_START - STR_COOKIES_RECV_START;
81cdf0e10cSrcweir INetURLObject aObj( mpCookieRequest->m_rURL );
82cdf0e10cSrcweir SetText( String( ResId( STR_COOKIES_RECV_TITLE + nOffset, *pResMgr ) ) );
83cdf0e10cSrcweir String aMsg( ResId( STR_COOKIES_RECV_START + nOffset, *pResMgr ) );
84cdf0e10cSrcweir aMsg.SearchAndReplaceAscii( "${HOST}", aObj.GetHost() );
85cdf0e10cSrcweir aMsg.SearchAndReplaceAscii( "${PATH}", aObj.GetPath() );
86cdf0e10cSrcweir String aTemplate( ResId( STR_COOKIES_RECV_COOKIES, *pResMgr ) );
87cdf0e10cSrcweir List& rList =mpCookieRequest->m_rCookieList;
88cdf0e10cSrcweir String aPair, aCookie;
89cdf0e10cSrcweir
90cdf0e10cSrcweir for ( sal_uInt16 i = (sal_uInt16)rList.Count(); i--; )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir CntHTTPCookie* pCookie = (CntHTTPCookie*)rList.GetObject(i);
93cdf0e10cSrcweir
94cdf0e10cSrcweir if ( CNTHTTP_COOKIE_POLICY_INTERACTIVE == pCookie->m_nPolicy )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir aCookie = aTemplate;
97cdf0e10cSrcweir aCookie.SearchAndReplaceAscii( "${DOMAIN}", pCookie->m_aDomain );
98cdf0e10cSrcweir aCookie.SearchAndReplaceAscii( "${PATH}", pCookie->m_aPath );
99cdf0e10cSrcweir aPair = pCookie->m_aName;
100cdf0e10cSrcweir aPair += '=';
101cdf0e10cSrcweir aPair += pCookie->m_aValue;
102cdf0e10cSrcweir aCookie.SearchAndReplaceAscii( "${COOKIE}", aPair );
103cdf0e10cSrcweir aMsg += aCookie;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir }
106cdf0e10cSrcweir maInFutureInteractiveBtn.Check( sal_True );
107cdf0e10cSrcweir maCookieFT.SetText( aMsg );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir // -----------------------------------------------------------------------
111cdf0e10cSrcweir
Execute()112cdf0e10cSrcweir short CookiesDialog::Execute()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir maSendBtn.GrabFocus();
115cdf0e10cSrcweir short nRet = ModalDialog::Execute();
116cdf0e10cSrcweir sal_uInt16 nStatus = CNTHTTP_COOKIE_POLICY_INTERACTIVE;
117cdf0e10cSrcweir
118cdf0e10cSrcweir if ( maInFutureSendBtn.IsChecked() )
119cdf0e10cSrcweir nStatus = CNTHTTP_COOKIE_POLICY_ACCEPTED;
120cdf0e10cSrcweir
121cdf0e10cSrcweir if ( maInFutureIgnoreBtn.IsChecked() )
122cdf0e10cSrcweir nStatus = CNTHTTP_COOKIE_POLICY_BANNED;
123cdf0e10cSrcweir List& rList = mpCookieRequest->m_rCookieList;
124cdf0e10cSrcweir
125cdf0e10cSrcweir for ( sal_uInt16 i = (sal_uInt16)rList.Count(); i--; )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir sal_uInt16& rStatus = ( (CntHTTPCookie*)rList.GetObject(i) )->m_nPolicy;
128cdf0e10cSrcweir
129cdf0e10cSrcweir if ( rStatus == CNTHTTP_COOKIE_POLICY_INTERACTIVE )
130cdf0e10cSrcweir rStatus = nStatus;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir if ( nRet == RET_OK )
134cdf0e10cSrcweir mpCookieRequest->m_nRet = CNTHTTP_COOKIE_POLICY_ACCEPTED;
135cdf0e10cSrcweir else
136cdf0e10cSrcweir mpCookieRequest->m_nRet = CNTHTTP_COOKIE_POLICY_BANNED;
137cdf0e10cSrcweir
138cdf0e10cSrcweir return nRet;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141