View | Details | Raw Unified | Return to bug 58271
Collapse All | Expand All

(-)khtml/khtml_ext.cpp (+13 lines)
Lines 646-651 bool KHTMLPartBrowserHostExtension::open Link Here
646
  return m_part->openURLInFrame( url, urlArgs );
646
  return m_part->openURLInFrame( url, urlArgs );
647
}
647
}
648
648
649
void KHTMLPartBrowserHostExtension::virtual_hook( int id, void *data )
650
{ 
651
  if (id == VIRTUAL_FIND_FRAME_PARENT)
652
  {
653
    FindFrameParentParams *param = static_cast<FindFrameParentParams*>(data);
654
    KHTMLPart *parentPart = m_part->findFrameParent(param->callingPart, param->frame);
655
    if (parentPart)
656
       param->parent = parentPart->browserHostExtension();
657
    return;
658
  }
659
  BrowserHostExtension::virtual_hook( id, data );
660
}
661
649
// BCI: remove in KDE 4
662
// BCI: remove in KDE 4
650
KHTMLZoomFactorAction::KHTMLZoomFactorAction( KHTMLPart *part, bool direction, const QString &text, const QString &icon, const QObject *receiver, const char *slot, QObject *parent, const char *name )
663
KHTMLZoomFactorAction::KHTMLZoomFactorAction( KHTMLPart *part, bool direction, const QString &text, const QString &icon, const QObject *receiver, const char *slot, QObject *parent, const char *name )
651
    : KAction( text, icon, 0, receiver, slot, parent, name )
664
    : KAction( text, icon, 0, receiver, slot, parent, name )
(-)khtml/khtml_ext.h (+3 lines)
Lines 98-103 public: Link Here
98
  virtual const QPtrList<KParts::ReadOnlyPart> frames() const;
98
  virtual const QPtrList<KParts::ReadOnlyPart> frames() const;
99
99
100
  virtual bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
100
  virtual bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
101
102
protected:
103
  virtual void virtual_hook( int id, void* data );
101
private:
104
private:
102
  KHTMLPart *m_part;
105
  KHTMLPart *m_part;
103
};
106
};
(-)khtml/khtml_part.cpp (-72 / +104 lines)
Lines 757-768 DOM::Document KHTMLPart::document() cons Link Here
757
    return d->m_doc;
757
    return d->m_doc;
758
}
758
}
759
759
760
761
KParts::BrowserExtension *KHTMLPart::browserExtension() const
760
KParts::BrowserExtension *KHTMLPart::browserExtension() const
762
{
761
{
763
  return d->m_extension;
762
  return d->m_extension;
764
}
763
}
765
764
765
KParts::BrowserHostExtension *KHTMLPart::browserHostExtension() const
766
{
767
  return d->m_hostExtension;
768
}
769
766
KHTMLView *KHTMLPart::view() const
770
KHTMLView *KHTMLPart::view() const
767
{
771
{
768
  return d->m_view;
772
  return d->m_view;
Lines 880-908 QVariant KHTMLPart::crossFrameExecuteScr Link Here
880
    // we always allow these
884
    // we always allow these
881
  }
885
  }
882
  else {
886
  else {
883
    while (destpart->parentPart())
887
    destpart = findFrame(target);
884
      destpart = destpart->parentPart();
885
    destpart = destpart->findFrame(target);
886
887
    if (!destpart)
888
    if (!destpart)
888
      destpart = this; // ### doesn't make sense, does it?
889
       destpart = this;
889
  }
890
  }
890
891
891
  // easy way out?
892
  // easy way out?
892
  if (destpart == this)
893
  if (destpart == this)
893
    return executeScript(DOM::Node(), script);
894
    return executeScript(DOM::Node(), script);
894
895
895
896
  // now compare the domains
896
  // now compare the domains
897
  if (!destpart->htmlDocument().isNull() &&
897
  if (destpart->checkFrameAccess(this))
898
      !htmlDocument().isNull())  {
898
    return destpart->executeScript(DOM::Node(), script);
899
    DOM::DOMString actDomain = htmlDocument().domain();
900
    DOM::DOMString destDomain = destpart->htmlDocument().domain();
901
902
    if (actDomain == destDomain)
903
      return destpart->executeScript(DOM::Node(), script);
904
  }
905
906
899
907
  // eww, something went wrong. better execute it in our frame
900
  // eww, something went wrong. better execute it in our frame
908
  return executeScript(DOM::Node(), script);
901
  return executeScript(DOM::Node(), script);
Lines 3358-3364 void KHTMLPart::urlSelected( const QStri Link Here
3358
  if ( hasTarget )
3351
  if ( hasTarget )
3359
  {
3352
  {
3360
    // unknown frame names should open in a new window.
3353
    // unknown frame names should open in a new window.
3361
    khtml::ChildFrame *frame = recursiveFrameRequest( cURL, args, false );
3354
    khtml::ChildFrame *frame = recursiveFrameRequest( this, cURL, args, false );
3362
    if ( frame )
3355
    if ( frame )
3363
    {
3356
    {
3364
      args.metaData()["referrer"] = d->m_referrer;
3357
      args.metaData()["referrer"] = d->m_referrer;
Lines 4364-4369 void KHTMLPart::slotChildDocCreated() Link Here
4364
void KHTMLPart::slotChildURLRequest( const KURL &url, const KParts::URLArgs &args )
4357
void KHTMLPart::slotChildURLRequest( const KURL &url, const KParts::URLArgs &args )
4365
{
4358
{
4366
  khtml::ChildFrame *child = frame( sender()->parent() );
4359
  khtml::ChildFrame *child = frame( sender()->parent() );
4360
  KHTMLPart *callingHtmlPart = const_cast<KHTMLPart *>(dynamic_cast<const KHTMLPart *>(sender()));
4367
4361
4368
  // TODO: handle child target correctly! currently the script are always executed fur the parent
4362
  // TODO: handle child target correctly! currently the script are always executed fur the parent
4369
  QString urlStr = url.url();
4363
  QString urlStr = url.url();
Lines 4395-4401 void KHTMLPart::slotChildURLRequest( con Link Here
4395
    }
4389
    }
4396
    else if ( frameName != QString::fromLatin1( "_self" ) )
4390
    else if ( frameName != QString::fromLatin1( "_self" ) )
4397
    {
4391
    {
4398
      khtml::ChildFrame *_frame = recursiveFrameRequest( url, args );
4392
      khtml::ChildFrame *_frame = recursiveFrameRequest( callingHtmlPart, url, args );
4399
4393
4400
      if ( !_frame )
4394
      if ( !_frame )
4401
      {
4395
      {
Lines 4437-4482 khtml::ChildFrame *KHTMLPart::frame( con Link Here
4437
    return 0L;
4431
    return 0L;
4438
}
4432
}
4439
4433
4440
//#define DEBUG_FINDFRAME
4434
#define DEBUG_FINDFRAME
4441
4435
4442
KHTMLPart *KHTMLPart::findFrame( const QString &f )
4436
bool KHTMLPart::checkFrameAccess(KHTMLPart *callingHtmlPart)
4443
{
4437
{
4438
  if (callingHtmlPart == this)
4439
    return true; // trivial
4440
4441
  if (htmlDocument().isNull()) {
4444
#ifdef DEBUG_FINDFRAME
4442
#ifdef DEBUG_FINDFRAME
4445
  kdDebug(6050) << "KHTMLPart::findFrame '" << f << "'" << endl;
4443
    kdDebug(6050) << "KHTMLPart::checkFrameAccess: Empty part " << this << " URL = " << m_url << endl;
4446
  FrameIt it2 = d->m_frames.begin();
4447
  FrameIt end = d->m_frames.end();
4448
  for (; it2 != end; ++it2 )
4449
      kdDebug(6050) << "  - having frame '" << (*it2).m_name << "'" << endl;
4450
#endif
4444
#endif
4451
  // ### http://www.w3.org/TR/html4/appendix/notes.html#notes-frames
4445
    return false; // we are empty?
4452
  ConstFrameIt it = d->m_frames.find( f );
4446
  }
4453
  if ( it == d->m_frames.end() )
4447
4454
  {
4448
  // now compare the domains
4449
  if (callingHtmlPart && !callingHtmlPart->htmlDocument().isNull() &&
4450
      !htmlDocument().isNull())  {
4451
    DOM::DOMString actDomain = callingHtmlPart->htmlDocument().domain();
4452
    DOM::DOMString destDomain = htmlDocument().domain();
4453
4455
#ifdef DEBUG_FINDFRAME
4454
#ifdef DEBUG_FINDFRAME
4456
    kdDebug(6050) << "KHTMLPart::findFrame frame " << f << " not found" << endl;
4455
    kdDebug(6050) << "KHTMLPart::checkFrameAccess: actDomain = '" << actDomain.string() << "' destDomain = '" << destDomain.string() << "'" << endl;
4457
#endif
4456
#endif
4458
    return 0L;
4457
4458
    if (actDomain == destDomain)
4459
      return true;
4459
  }
4460
  }
4460
  else {
4461
    KParts::ReadOnlyPart *p = (*it).m_part;
4462
    if ( p && p->inherits( "KHTMLPart" ))
4463
    {
4464
#ifdef DEBUG_FINDFRAME
4461
#ifdef DEBUG_FINDFRAME
4465
      kdDebug(6050) << "KHTMLPart::findFrame frame " << f << " is a KHTMLPart, ok" << endl;
4462
  else
4463
  {
4464
    kdDebug(6050) << "KHTMLPart::checkFrameAccess: Unknown part/domain " << callingHtmlPart << " tries to access part " << this << endl;
4465
  }
4466
#endif
4466
#endif
4467
      return (KHTMLPart*)p;
4467
  return false;
4468
    }
4468
}
4469
    else
4469
4470
    {
4470
KHTMLPart *
4471
KHTMLPart::findFrameParent( KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame )
4472
{
4471
#ifdef DEBUG_FINDFRAME
4473
#ifdef DEBUG_FINDFRAME
4472
      if (p)
4474
  kdDebug(6050) << "KHTMLPart::findFrameParent: this = " << this << " URL = " << m_url << " findFrameParent( " << f << " )" << endl;
4473
        kdWarning() << "KHTMLPart::findFrame frame " << f << " found but isn't a KHTMLPart ! " << p->className() << endl;
4475
#endif
4474
      else
4476
  // Check access
4475
        kdWarning() << "KHTMLPart::findFrame frame " << f << " found but m_part=0L" << endl;
4477
  KHTMLPart *callingHtmlPart = dynamic_cast<KHTMLPart *>(callingPart);
4478
  
4479
  if (!checkFrameAccess(callingHtmlPart))
4480
     return 0;
4481
4482
  FrameIt it = d->m_frames.find( f );
4483
  FrameIt end = d->m_frames.end();
4484
  if ( it != end )
4485
  {
4486
#ifdef DEBUG_FINDFRAME
4487
     kdDebug(6050) << "KHTMLPart::findFrameParent: FOUND!" << endl;
4476
#endif
4488
#endif
4477
      return 0L;
4489
     if (childFrame)
4490
        *childFrame = &(*it);
4491
     return this;
4492
  }
4493
     
4494
  it = d->m_frames.begin();
4495
  for (; it != end; ++it )
4496
  {
4497
    KParts::ReadOnlyPart *p = (*it).m_part;
4498
    if ( p && p->inherits( "KHTMLPart" ))
4499
    {
4500
      KHTMLPart *frameParent = static_cast<KHTMLPart*>(p)->findFrameParent(callingPart, f, childFrame);
4501
      if (frameParent)
4502
         return frameParent;
4478
    }
4503
    }
4479
  }
4504
  }
4505
  return 0;
4506
}
4507
4508
4509
KHTMLPart *KHTMLPart::findFrame( const QString &f )
4510
{
4511
  khtml::ChildFrame *childFrame;
4512
  KHTMLPart *parentFrame = findFrameParent(this, f, &childFrame);
4513
  if (parentFrame)
4514
  {
4515
     KParts::ReadOnlyPart *p = childFrame->m_part;
4516
     if ( p && p->inherits( "KHTMLPart" ))
4517
        return static_cast<KHTMLPart *>(p);
4518
  }
4519
  return 0;
4480
}
4520
}
4481
4521
4482
KParts::ReadOnlyPart *KHTMLPart::currentFrame() const
4522
KParts::ReadOnlyPart *KHTMLPart::currentFrame() const
Lines 4514-4550 KHTMLPart *KHTMLPart::parentPart() Link Here
4514
  return (KHTMLPart *)parent();
4554
  return (KHTMLPart *)parent();
4515
}
4555
}
4516
4556
4517
khtml::ChildFrame *KHTMLPart::recursiveFrameRequest( const KURL &url, const KParts::URLArgs &args,
4557
khtml::ChildFrame *KHTMLPart::recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, 
4518
                                                     bool callParent )
4558
                                                     const KParts::URLArgs &args, bool callParent )
4519
{
4559
{
4520
  FrameIt it = d->m_frames.find( args.frameName );
4560
#ifdef DEBUG_FINDFRAME
4521
4561
  kdDebug( 6050 ) << "KHTMLPart::recursiveFrameRequest this = " << this << ", frame = " << args.frameName << ", url = " << url << endl;
4522
  if ( it != d->m_frames.end() )
4562
#endif  
4523
    return &(*it);
4563
  khtml::ChildFrame *childFrame;
4524
4564
  KHTMLPart *childPart = findFrameParent(callingHtmlPart, args.frameName, &childFrame);
4525
  it = d->m_frames.begin();
4565
  if (childPart)
4526
  FrameIt end = d->m_frames.end();
4566
  {
4527
  for (; it != end; ++it )
4567
     if (childPart == this)
4528
    if ( (*it).m_part && (*it).m_part->inherits( "KHTMLPart" ) )
4568
        return childFrame;
4529
    {
4569
     
4530
      KHTMLPart *childPart = (KHTMLPart *)(KParts::ReadOnlyPart *)(*it).m_part;
4570
     childPart->requestObject( childFrame, url, args );
4531
4571
     return 0;
4532
      khtml::ChildFrame *res = childPart->recursiveFrameRequest( url, args, false );
4572
  }
4533
      if ( !res )
4534
        continue;
4535
4536
      childPart->requestObject( res, url, args );
4537
      return 0L;
4538
    }
4539
4573
4540
  if ( parentPart() && callParent )
4574
  if ( parentPart() && callParent )
4541
  {
4575
  {
4542
    khtml::ChildFrame *res = parentPart()->recursiveFrameRequest( url, args );
4576
     khtml::ChildFrame *res = parentPart()->recursiveFrameRequest( callingHtmlPart, url, args, callParent );
4543
4577
4544
    if ( res )
4578
     if ( res )
4545
      parentPart()->requestObject( res, url, args );
4579
       parentPart()->requestObject( res, url, args );
4546
4547
    return 0L;
4548
  }
4580
  }
4549
4581
4550
  return 0L;
4582
  return 0L;
Lines 4552-4558 khtml::ChildFrame *KHTMLPart::recursiveF Link Here
4552
4584
4553
void KHTMLPart::saveState( QDataStream &stream )
4585
void KHTMLPart::saveState( QDataStream &stream )
4554
{
4586
{
4555
  kdDebug( 6050 ) << "KHTMLPart::saveState saving URL " << m_url.url() << endl;
4587
  kdDebug( 6050 ) << "KHTMLPart::saveState this = " << this << " saving URL " << m_url.url() << endl;
4556
4588
4557
  stream << m_url << (Q_INT32)d->m_view->contentsX() << (Q_INT32)d->m_view->contentsY()
4589
  stream << m_url << (Q_INT32)d->m_view->contentsX() << (Q_INT32)d->m_view->contentsY()
4558
         << (Q_INT32) d->m_view->contentsWidth() << (Q_INT32) d->m_view->contentsHeight() << (Q_INT32) d->m_view->marginWidth() << (Q_INT32) d->m_view->marginHeight();
4590
         << (Q_INT32) d->m_view->contentsWidth() << (Q_INT32) d->m_view->contentsHeight() << (Q_INT32) d->m_view->marginWidth() << (Q_INT32) d->m_view->marginHeight();
(-)khtml/khtml_part.h (-1 / +14 lines)
Lines 287-292 public: Link Here
287
   */
287
   */
288
  KParts::BrowserExtension *browserExtension() const;
288
  KParts::BrowserExtension *browserExtension() const;
289
  KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
289
  KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
290
  KParts::BrowserHostExtension *browserHostExtension() const;
290
291
291
  /**
292
  /**
292
   * Returns a pointer to the HTML document's view.
293
   * Returns a pointer to the HTML document's view.
Lines 812-817 public: Link Here
812
  KHTMLPart *findFrame( const QString &f );
813
  KHTMLPart *findFrame( const QString &f );
813
814
814
  /**
815
  /**
816
   * @internal
817
   * Recursively finds the part containing the frame with name @p f 
818
   * and checks if it is accessible by @p callingPart
819
   * Returns 0L if no suitable frame can't be found.
820
   * Returns parent part if a suitable frame was found and
821
   * frame info in @p *childFrame
822
   */
823
  KHTMLPart *findFrameParent( KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame=0 );
824
825
  /**
815
   * Return the current frame (the one that has focus)
826
   * Return the current frame (the one that has focus)
816
   * Not necessarily a direct child of ours, framesets can be nested.
827
   * Not necessarily a direct child of ours, framesets can be nested.
817
   * Returns "this" if this part isn't a frameset.
828
   * Returns "this" if this part isn't a frameset.
Lines 1376-1381 private: Link Here
1376
1387
1377
  bool restoreURL( const KURL &url );
1388
  bool restoreURL( const KURL &url );
1378
  void emitSelectionChanged();
1389
  void emitSelectionChanged();
1390
  // Returns whether callingHtmlPart may access this part
1391
  bool checkFrameAccess(KHTMLPart *callingHtmlPart);
1379
  bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
1392
  bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
1380
  void startAutoScroll();
1393
  void startAutoScroll();
1381
  void stopAutoScroll();
1394
  void stopAutoScroll();
Lines 1434-1440 private: Link Here
1434
  DOM::DocumentImpl *xmlDocImpl() const;
1447
  DOM::DocumentImpl *xmlDocImpl() const;
1435
  khtml::ChildFrame *frame( const QObject *obj );
1448
  khtml::ChildFrame *frame( const QObject *obj );
1436
1449
1437
  khtml::ChildFrame *recursiveFrameRequest( const KURL &url, const KParts::URLArgs &args, bool callParent = true );
1450
  khtml::ChildFrame *recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, const KParts::URLArgs &args, bool callParent = true );
1438
1451
1439
  bool checkLinkSecurity( const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null );
1452
  bool checkLinkSecurity( const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null );
1440
  QVariant executeScript( const QString& filename, int baseLine, const DOM::Node &n, const QString& script );
1453
  QVariant executeScript( const QString& filename, int baseLine, const DOM::Node &n, const QString& script );
(-)kparts/browserextension.cpp (+11 lines)
Lines 636-641 BrowserHostExtension *BrowserHostExtensi Link Here
636
void BrowserExtension::virtual_hook( int, void* )
636
void BrowserExtension::virtual_hook( int, void* )
637
{ /*BASE::virtual_hook( id, data );*/ }
637
{ /*BASE::virtual_hook( id, data );*/ }
638
638
639
BrowserHostExtension *
640
BrowserHostExtension::findFrameParent(KParts::ReadOnlyPart *callingPart, const QString &frame)
641
{
642
    FindFrameParentParams param;
643
    param.parent = 0;
644
    param.callingPart = callingPart;
645
    param.frame = frame;
646
    virtual_hook(VIRTUAL_FIND_FRAME_PARENT, &param);
647
    return param.parent;
648
}
649
639
void BrowserHostExtension::virtual_hook( int, void* )
650
void BrowserHostExtension::virtual_hook( int, void* )
640
{ /*BASE::virtual_hook( id, data );*/ }
651
{ /*BASE::virtual_hook( id, data );*/ }
641
652
(-)kparts/browserextension.h (-1 / +20 lines)
Lines 671-680 public: Link Here
671
   *
671
   *
672
   * Note that this method does not query the child objects recursively.
672
   * Note that this method does not query the child objects recursively.
673
   */
673
   */
674
675
  virtual const QPtrList<KParts::ReadOnlyPart> frames() const;
674
  virtual const QPtrList<KParts::ReadOnlyPart> frames() const;
676
675
677
  /**
676
  /**
677
   * @internal
678
   * Returns the part that contains @p frame and that may be accessed
679
   * by @p callingPart
680
   */
681
  BrowserHostExtension *findFrameParent(KParts::ReadOnlyPart *callingPart, const QString &frame);
682
683
  /**
678
   * Opens the given url in a hosted child frame. The frame name is specified in the
684
   * Opens the given url in a hosted child frame. The frame name is specified in the
679
   * frameName variable in the urlArgs argument structure (see KParts::URLArgs ) .
685
   * frameName variable in the urlArgs argument structure (see KParts::URLArgs ) .
680
   */
686
   */
Lines 687-692 public: Link Here
687
  static BrowserHostExtension *childObject( QObject *obj );
693
  static BrowserHostExtension *childObject( QObject *obj );
688
694
689
protected:
695
protected:
696
  /** This 'enum' along with the structure below is NOT part of the public API.
697
   * It's going to disappear in KDE 4.0 and is likely to change inbetween.
698
   *
699
   * @internal
700
   */
701
  enum { VIRTUAL_FIND_FRAME_PARENT = 0x10 };
702
  struct FindFrameParentParams
703
  {
704
      BrowserHostExtension *parent;
705
      KParts::ReadOnlyPart *callingPart;
706
      QString frame;
707
  };
708
                                                    
690
  virtual void virtual_hook( int id, void* data );
709
  virtual void virtual_hook( int id, void* data );
691
private:
710
private:
692
  class BrowserHostExtensionPrivate;
711
  class BrowserHostExtensionPrivate;

Return to bug 58271