summaryrefslogtreecommitdiffstats
path: root/tdehtml/tdehtmlpart_p.h
blob: d81643556c3585184e8c33a7554903226d55a181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
#ifndef tdehtmlpart_p_h
#define tdehtmlpart_p_h

/* This file is part of the KDE project
 *
 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
 *                     1999-2001 Lars Knoll <knoll@kde.org>
 *                     1999-2001 Antti Koivisto <koivisto@kde.org>
 *                     2000-2001 Simon Hausmann <hausmann@kde.org>
 *                     2000-2001 Dirk Mueller <mueller@kde.org>
 *                     2000 Stefan Schimanski <1Stein@gmx.de>
 *                     2001-2003 George Stiakos <staikos@kde.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */
#include <kcursor.h>
#include <klibloader.h>
#include <kxmlguifactory.h>
#include <tdeaction.h>
#include <tdeparts/partmanager.h>
#include <tdeparts/statusbarextension.h>
#include <tdeparts/browserextension.h>
#ifndef TDEHTML_NO_WALLET
#include <tdewallet.h>
#endif

#include <tqguardedptr.h>
#include <tqmap.h>
#include <tqtimer.h>
#include <tqvaluelist.h>

#include "html/html_formimpl.h"
#include "tdehtml_run.h"
#include "tdehtml_factory.h"
#include "tdehtml_events.h"
#include "tdehtml_ext.h"
#include "tdehtml_iface.h"
#include "tdehtml_settings.h"
#include "misc/decoder.h"
#include "ecma/kjs_proxy.h"

class KFind;
class KFindDialog;
class TDEPopupMenu;
class TDESelectAction;
class KURLLabel;
class KJavaAppletContext;
class KJSErrorDlg;

namespace TDEIO
{
  class Job;
  class TransferJob;
}
namespace KParts
{
  class StatusBarExtension;
}

namespace tdehtml
{
  class KDE_EXPORT ChildFrame : public TQObject
  {
      TQ_OBJECT
  public:
      enum Type { Frame, IFrame, Object };

      ChildFrame() : TQObject (0L, "tdehtml_child_frame") {
          m_jscript = 0L;
          m_kjs_lib = 0;
          m_bCompleted = false; m_bPreloaded = false; m_type = Frame; m_bNotify = false;
          m_bPendingRedirection = false;
      }

      ~ChildFrame() {
          if (m_run) m_run->abort();
          delete m_jscript;
          if ( m_kjs_lib)
              m_kjs_lib->unload();
      }

    TQGuardedPtr<tdehtml::RenderPart> m_frame;
    TQGuardedPtr<KParts::ReadOnlyPart> m_part;
    TQGuardedPtr<KParts::BrowserExtension> m_extension;
    TQGuardedPtr<KParts::LiveConnectExtension> m_liveconnect;
    TQString m_serviceName;
    TQString m_serviceType;
    KJSProxy *m_jscript;
    KLibrary *m_kjs_lib;
    bool m_bCompleted;
    TQString m_name;
    KParts::URLArgs m_args;
    TQGuardedPtr<TDEHTMLRun> m_run;
    bool m_bPreloaded;
    KURL m_workingURL;
    Type m_type;
    TQStringList m_params;
    bool m_bNotify;
    bool m_bPendingRedirection;
  protected slots:
    void liveConnectEvent(const unsigned long, const TQString&, const KParts::LiveConnectExtension::ArgList&);
  };

}

struct TDEHTMLFrameList : public TQValueList<tdehtml::ChildFrame*>
{
    Iterator find( const TQString &name ) KDE_NO_EXPORT;
};

typedef TDEHTMLFrameList::ConstIterator ConstFrameIt;
typedef TDEHTMLFrameList::Iterator FrameIt;

static int tdehtml_part_dcop_counter = 0;


class TDEHTMLWalletQueue : public TQObject
{
  TQ_OBJECT
  public:
    TDEHTMLWalletQueue(TQObject *parent) : TQObject(parent) {
#ifndef TDEHTML_NO_WALLET
      wallet = 0L;
#endif // TDEHTML_NO_WALLET
    }

    virtual ~TDEHTMLWalletQueue() {
#ifndef TDEHTML_NO_WALLET
      delete wallet;
      wallet = 0L;
#endif // TDEHTML_NO_WALLET
    }
#ifndef TDEHTML_NO_WALLET
    TDEWallet::Wallet *wallet;
#endif // TDEHTML_NO_WALLET
    typedef TQPair<DOM::HTMLFormElementImpl*, TQGuardedPtr<DOM::DocumentImpl> > Caller;
    typedef TQValueList<Caller> CallerList;
    CallerList callers;
    TQValueList<TQPair<TQString, TQMap<TQString, TQString> > > savers;

  signals:
    void walletOpened(TDEWallet::Wallet*);

  public slots:
    void walletOpened(bool success) {
#ifndef TDEHTML_NO_WALLET
      if (!success) {
        delete wallet;
        wallet = 0L;
      }
      emit walletOpened(wallet);
      if (wallet) {
        if (!wallet->hasFolder(TDEWallet::Wallet::FormDataFolder())) {
          wallet->createFolder(TDEWallet::Wallet::FormDataFolder());
        }
        for (CallerList::Iterator i = callers.begin(); i != callers.end(); ++i) {
          if ((*i).first && (*i).second) {
            (*i).first->walletOpened(wallet);
          }
        }
        wallet->setFolder(TDEWallet::Wallet::FormDataFolder());
        for (TQValueList<TQPair<TQString, TQMap<TQString, TQString> > >::Iterator i = savers.begin(); i != savers.end(); ++i) {
          wallet->writeMap((*i).first, (*i).second);
        }
      }
      callers.clear();
      savers.clear();
      wallet = 0L; // gave it away
#endif // TDEHTML_NO_WALLET
    }
};

class TDEHTMLPartPrivate
{
  TDEHTMLPartPrivate(const TDEHTMLPartPrivate & other);
  TDEHTMLPartPrivate& operator=(const TDEHTMLPartPrivate&);
public:
  TDEHTMLPartPrivate(TQObject* parent)
  {
    m_doc = 0L;
    m_decoder = 0L;
    m_wallet = 0L;
    m_bWalletOpened = false;
    m_runningScripts = 0;
    m_job = 0L;
    m_bComplete = true;
    m_bLoadEventEmitted = true;
    m_cachePolicy = TDEIO::CC_Verify;
    m_manager = 0L;
    m_settings = new TDEHTMLSettings(*TDEHTMLFactory::defaultHTMLSettings());
    m_bClearing = false;
    m_bCleared = false;
    m_zoomFactor = 100;
    m_bDnd = true;
    m_startOffset = m_endOffset = 0;
    m_startBeforeEnd = true;
    m_extendAtEnd = true;
    m_linkCursor = KCursor::handCursor();
    m_loadedObjects = 0;
    m_totalObjectCount = 0;
    m_jobPercent = 0;
    m_haveEncoding = false;
    m_activeFrame = 0L;
    m_find = 0;
    m_findDialog = 0;
    m_ssl_in_use = false;
    m_jsedlg = 0;
    m_formNotification = TDEHTMLPart::NoNotification;

#ifndef Q_WS_QWS
    m_javaContext = 0;
#endif
    m_cacheId = 0;
    m_frameNameId = 1;

    m_restored = false;
    m_restoreScrollPosition = false;

    m_focusNodeNumber = -1;
    m_focusNodeRestored = false;

    m_bJScriptForce = false;
    m_bJScriptOverride = false;
    m_bJavaForce = false;
    m_bJavaOverride = false;
    m_bPluginsForce = false;
    m_bPluginsOverride = false;
    m_onlyLocalReferences = false;

    m_caretMode = false;
    m_designMode = false;

    m_metaRefreshEnabled = true;
    m_statusMessagesEnabled = true;

    m_bFirstData = true;
    m_submitForm = 0;
    m_delayRedirect = 0;
    m_autoDetectLanguage = tdehtml::Decoder::SemiautomaticDetection;

    // inherit settings from parent
    if(parent && parent->inherits("TDEHTMLPart"))
    {
        TDEHTMLPart* part = static_cast<TDEHTMLPart*>(parent);
        if(part->d)
        {
            m_bJScriptForce = part->d->m_bJScriptForce;
            m_bJScriptOverride = part->d->m_bJScriptOverride;
            m_bJavaForce = part->d->m_bJavaForce;
            m_bJavaOverride = part->d->m_bJavaOverride;
            m_bPluginsForce = part->d->m_bPluginsForce;
            m_bPluginsOverride = part->d->m_bPluginsOverride;
            // Same for SSL settings
            m_ssl_in_use = part->d->m_ssl_in_use;
            m_onlyLocalReferences = part->d->m_onlyLocalReferences;
            m_caretMode = part->d->m_caretMode;
            m_designMode = part->d->m_designMode;
            m_zoomFactor = part->d->m_zoomFactor;
            m_autoDetectLanguage = part->d->m_autoDetectLanguage;
            m_encoding = part->d->m_encoding;
            m_haveEncoding = part->d->m_haveEncoding;
        }
    }

    m_focusNodeNumber = -1;
    m_focusNodeRestored = false;
    m_opener = 0;
    m_openedByJS = false;
    m_newJSInterpreterExists = false;
    m_dcopobject = 0;
    m_jobspeed = 0;
    m_dcop_counter = ++tdehtml_part_dcop_counter;
    m_statusBarWalletLabel = 0L;
    m_statusBarUALabel = 0L;
    m_statusBarJSErrorLabel = 0L;
    m_userStyleSheetLastModified = 0;
    m_wq = 0;
  }
  ~TDEHTMLPartPrivate()
  {
    delete m_dcopobject;
    delete m_statusBarExtension;
    delete m_extension;
    delete m_settings;
#ifndef TDEHTML_NO_WALLET
    delete m_wallet;
#endif
#ifndef Q_WS_QWS
    //delete m_javaContext;
#endif
  }

  TQGuardedPtr<tdehtml::ChildFrame> m_frame;
  TDEHTMLFrameList m_frames;
  TDEHTMLFrameList m_objects;

  TQGuardedPtr<TDEHTMLView> m_view;
  TDEHTMLPartBrowserExtension *m_extension;
  KParts::StatusBarExtension *m_statusBarExtension;
  TDEHTMLPartBrowserHostExtension *m_hostExtension;
  KURLLabel* m_statusBarIconLabel;
  KURLLabel* m_statusBarWalletLabel;
  KURLLabel* m_statusBarUALabel;
  KURLLabel* m_statusBarJSErrorLabel;
  KURLLabel* m_statusBarPopupLabel;
  TQValueList<TQGuardedPtr<TDEHTMLPart> > m_suppressedPopupOriginParts;
  int m_openableSuppressedPopups;
  DOM::DocumentImpl *m_doc;
  tdehtml::Decoder *m_decoder;
  TQString m_encoding;
  TQString m_sheetUsed;
  long m_cacheId;
  TQString scheduledScript;
  DOM::Node scheduledScriptNode;

  TDEWallet::Wallet* m_wallet;
  int m_runningScripts;
  bool m_bOpenMiddleClick :1;
  bool m_bBackRightClick :1;
  bool m_bJScriptEnabled :1;
  bool m_bJScriptDebugEnabled :1;
  bool m_bJavaEnabled :1;
  bool m_bPluginsEnabled :1;
  bool m_bJScriptForce :1;
  bool m_bJScriptOverride :1;
  bool m_bJavaForce :1;
  bool m_bJavaOverride :1;
  bool m_bPluginsForce :1;
  bool m_metaRefreshEnabled :1;
  bool m_bPluginsOverride :1;
  bool m_restored :1;
  bool m_restoreScrollPosition :1;
  bool m_statusMessagesEnabled :1;
  bool m_bWalletOpened :1;
  bool m_urlSelectedOpenedURL:1; // KDE4: remove
  int m_frameNameId;
  int m_dcop_counter;
  DCOPObject *m_dcopobject;

#ifndef Q_WS_QWS
  KJavaAppletContext *m_javaContext;
#endif

  TDEHTMLSettings *m_settings;

  TDEIO::TransferJob * m_job;

  TQString m_statusBarText[3];
  unsigned long m_jobspeed;
  TQString m_lastModified;
  TQString m_httpHeaders;
  TQString m_pageServices;

  // QStrings for SSL metadata
  // Note: When adding new variables don't forget to update ::saveState()/::restoreState()!
  bool m_ssl_in_use;
  TQString m_ssl_peer_certificate,
          m_ssl_peer_chain,
          m_ssl_peer_ip,
          m_ssl_cipher,
          m_ssl_cipher_desc,
          m_ssl_cipher_version,
          m_ssl_cipher_used_bits,
          m_ssl_cipher_bits,
          m_ssl_cert_state,
          m_ssl_parent_ip,
          m_ssl_parent_cert;

  bool m_bComplete:1;
  bool m_bLoadEventEmitted:1;
  bool m_haveEncoding:1;
  bool m_onlyLocalReferences :1;
  bool m_redirectLockHistory:1;

  KURL m_workingURL;

  TDEIO::CacheControl m_cachePolicy;
  TQTimer m_redirectionTimer;
  TQTime m_parsetime;
  int m_delayRedirect;
  TQString m_redirectURL;

  TDEAction *m_paViewDocument;
  TDEAction *m_paViewFrame;
  TDEAction *m_paViewInfo;
  TDEAction *m_paSaveBackground;
  TDEAction *m_paSaveDocument;
  TDEAction *m_paSaveFrame;
  TDEAction *m_paSecurity;
  TDEActionMenu *m_paSetEncoding;
  TDESelectAction *m_paUseStylesheet;
  TDEHTMLZoomFactorAction *m_paIncZoomFactor;
  TDEHTMLZoomFactorAction *m_paDecZoomFactor;
  TDEAction *m_paLoadImages;
  TDEAction *m_paFind;
  TDEAction *m_paFindNext;
  TDEAction *m_paFindPrev;
  TDEAction *m_paFindAheadText;
  TDEAction *m_paFindAheadLinks;
  TDEAction *m_paPrintFrame;
  TDEAction *m_paSelectAll;
  TDEAction *m_paDebugScript;
  TDEAction *m_paDebugDOMTree;
  TDEAction *m_paDebugRenderTree;
  TDEAction *m_paStopAnimations;
  TDEToggleAction *m_paToggleCaretMode;

  KParts::PartManager *m_manager;

  TQString m_popupMenuXML;
  TDEHTMLPart::GUIProfile m_guiProfile;

  int m_zoomFactor;

  TQString m_strSelectedURL;
  TQString m_strSelectedURLTarget;
  TQString m_referrer;
  TQString m_pageReferrer;

  struct SubmitForm
  {
    const char *submitAction;
    TQString submitUrl;
    TQByteArray submitFormData;
    TQString target;
    TQString submitContentType;
    TQString submitBoundary;
  };

  SubmitForm *m_submitForm;

  bool m_bMousePressed;
  bool m_bRightMousePressed;
  DOM::Node m_mousePressNode; //node under the mouse when the mouse was pressed (set in the mouse handler)

  // simply using the selection limits for the caret position does not suffice
  // as we need to know on which side to extend the selection
//  DOM::Node m_caretNode;	// node containing the caret
//  long m_caretOffset;		// offset within this node (0-based)

  // the caret uses the selection variables for its position. If m_extendAtEnd
  // is true, m_selectionEnd and m_endOffset contain the mandatory caret
  // position, otherwise it's m_selectionStart and m_startOffset.
  DOM::Node m_selectionStart;
  long m_startOffset;
  DOM::Node m_selectionEnd;
  long m_endOffset;
  DOM::Node m_initialNode;	// (Node, Offset) pair on which the
  long m_initialOffset;		// selection has been initiated
  TQString m_overURL;
  TQString m_overURLTarget;

  bool m_startBeforeEnd;
  bool m_extendAtEnd;		// true if selection is to be extended at its end
  enum { ExtendByChar, ExtendByWord, ExtendByLine } m_extendMode;
  bool m_bDnd;
  bool m_bFirstData;
  bool m_bClearing;
  bool m_bCleared;
  bool m_bSecurityInQuestion;
  bool m_focusNodeRestored;

  int m_focusNodeNumber;

  TQPoint m_dragStartPos;
#ifdef TDEHTML_NO_SELECTION
  TQPoint m_dragLastPos;
#endif

  bool m_designMode;
  bool m_caretMode;

  TQCursor m_linkCursor;
  TQTimer m_scrollTimer;

  unsigned long m_loadedObjects;
  unsigned long m_totalObjectCount;
  unsigned int m_jobPercent;

  TDEHTMLPart::FormNotification m_formNotification;
  TQTimer m_progressUpdateTimer;

  TQStringList m_pluginPageQuestionAsked;

  /////////// 'Find' feature
  struct StringPortion
  {
      // Just basic ref/deref on our node to make sure it doesn't get deleted
      StringPortion( int i, DOM::NodeImpl* n ) : index(i), node(n) { if (node) node->ref(); }
      StringPortion() : index(0), node(0) {} // for QValueList
      StringPortion( const StringPortion& other ) : node(0) { operator=(other); }
      StringPortion& operator=( const StringPortion& other ) {
          index=other.index;
          if (other.node) other.node->ref();
          if (node) node->deref();
          node=other.node;
          return *this;
      }
      ~StringPortion() { if (node) node->deref(); }

      int index;
      DOM::NodeImpl *node;
  };
  TQValueList<StringPortion> m_stringPortions;

  KFind *m_find;
  KFindDialog *m_findDialog;

  struct findState
  {
    findState() : options( 0 ), last_dir( -1 ) {}
    TQStringList history;
    TQString text;
    int options;
    int last_dir; // -1=unknown,0=forward,1=backward
  };

  findState m_lastFindState;

  KJSErrorDlg *m_jsedlg;

  DOM::NodeImpl *m_findNode; // current node
  DOM::NodeImpl *m_findNodeEnd; // end node
  DOM::NodeImpl *m_findNodeStart; // start node
  DOM::NodeImpl *m_findNodePrevious; // previous node used for find
  int m_findPos; // current pos in current node
  int m_findPosEnd; // pos in end node
  int m_findPosStart; // pos in start node
  /////////

  //TQGuardedPtr<KParts::Part> m_activeFrame;
  KParts::Part * m_activeFrame;
  TQGuardedPtr<TDEHTMLPart> m_opener;
  bool m_openedByJS;
  bool m_newJSInterpreterExists; // set to 1 by setOpenedByJS, for window.open

  tdehtml::Decoder::AutoDetectLanguage m_autoDetectLanguage;
  TDEPopupMenu *m_automaticDetection;
  TDESelectAction *m_manualDetection;

  void setFlagRecursively(bool TDEHTMLPartPrivate::*flag, bool value);
  /** returns the caret node */
  DOM::Node &caretNode() {
    return m_extendAtEnd ? m_selectionEnd : m_selectionStart;
  }
  /** returns the caret offset */
  long &caretOffset() {
    return m_extendAtEnd ? m_endOffset : m_startOffset;
  }

  time_t m_userStyleSheetLastModified;

  TDEHTMLWalletQueue *m_wq;
};

#endif