Changeset 33457 in webkit


Ignore:
Timestamp:
May 14, 2008 2:30:46 PM (16 years ago)
Author:
andersca@apple.com
Message:

2008-05-14 Anders Carlsson <andersca@apple.com>

Reviewed by Brady.

<rdar://problem/5931742> Support navigator.onLine from HTML5


  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj: Add NetworkStateNotifier files.


  • dom/EventNames.h: Add offline and online events.


  • page/Navigator.cpp: (WebCore::Navigator::onLine):
  • page/Navigator.h:
  • page/Navigator.idl: Add navigator.onLine.


  • page/Page.cpp: (WebCore::networkStateChanged): Dispatch offline/online events to all frames.


(WebCore::Page::Page):
Set state change callback.


  • platform/network/NetworkStateNotifier.cpp: Added.
  • platform/network/NetworkStateNotifier.h: Added.
  • platform/network/mac/NetworkStateNotifierMac.cpp: Added. Mac network state notifier.
Location:
trunk/WebCore
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r33455 r33457  
     12008-05-14  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Brady.
     4
     5        <rdar://problem/5931742> Support navigator.onLine from HTML5
     6       
     7        * WebCore.vcproj/WebCore.vcproj:
     8        * WebCore.xcodeproj/project.pbxproj:
     9        Add NetworkStateNotifier files.
     10       
     11        * dom/EventNames.h:
     12        Add offline and online events.
     13       
     14        * page/Navigator.cpp:
     15        (WebCore::Navigator::onLine):
     16        * page/Navigator.h:
     17        * page/Navigator.idl:
     18        Add navigator.onLine.
     19       
     20        * page/Page.cpp:
     21        (WebCore::networkStateChanged):
     22        Dispatch offline/online events to all frames.
     23       
     24        (WebCore::Page::Page):
     25        Set state change callback.
     26       
     27        * platform/network/NetworkStateNotifier.cpp: Added.
     28        * platform/network/NetworkStateNotifier.h: Added.
     29
     30        * platform/network/mac/NetworkStateNotifierMac.cpp: Added.
     31        Mac network state notifier.
     32
    1332008-05-14  Adam Roben  <aroben@apple.com>
    234
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r33410 r33457  
    63026302                                </File>
    63036303                                <File
     6304                                    RelativePath="..\platform\network\NetworkStateNotifier.h"
     6305                                    >
     6306                            </File>
     6307                                <File
     6308                                    RelativePath="..\platform\network\NetworkStateNotifier.cpp"
     6309                                    >
     6310                            </File>
     6311                                <File
    63046312                                        RelativePath="..\platform\network\ProtectionSpace.cpp"
    63056313                                        >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r33400 r33457  
    182182                1A7CCB1C0CD9469A00B7B64E /* SQLTransactionErrorCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7CCB180CD9469A00B7B64E /* SQLTransactionErrorCallback.h */; };
    183183                1A7CCB240CD946FD00B7B64E /* SQLTransaction.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7CCB220CD946FD00B7B64E /* SQLTransaction.h */; };
     184                1A7FA6190DDA3B3A0028F8A5 /* NetworkStateNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7FA6180DDA3B3A0028F8A5 /* NetworkStateNotifier.h */; };
     185                1A7FA61B0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7FA61A0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp */; };
     186                1A7FA6490DDA3CBA0028F8A5 /* NetworkStateNotifierMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7FA6470DDA3CBA0028F8A5 /* NetworkStateNotifierMac.cpp */; };
     187                1A7FA7CC0DDA4B770028F8A5 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A7FA7CB0DDA4B770028F8A5 /* SystemConfiguration.framework */; };
    184188                1A820D910A13EBA600AF843C /* ImageDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A820D8F0A13EBA600AF843C /* ImageDocument.cpp */; };
    185189                1A820D920A13EBA600AF843C /* ImageDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A820D900A13EBA600AF843C /* ImageDocument.h */; };
     
    46354639                1A7CCB220CD946FD00B7B64E /* SQLTransaction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLTransaction.h; sourceTree = "<group>"; };
    46364640                1A7CCB230CD946FD00B7B64E /* SQLTransaction.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SQLTransaction.idl; sourceTree = "<group>"; };
     4641                1A7FA6180DDA3B3A0028F8A5 /* NetworkStateNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkStateNotifier.h; sourceTree = "<group>"; };
     4642                1A7FA61A0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkStateNotifier.cpp; sourceTree = "<group>"; };
     4643                1A7FA6470DDA3CBA0028F8A5 /* NetworkStateNotifierMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkStateNotifierMac.cpp; sourceTree = "<group>"; };
     4644                1A7FA7CB0DDA4B770028F8A5 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<absolute>"; };
    46374645                1A820D8F0A13EBA600AF843C /* ImageDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ImageDocument.cpp; sourceTree = "<group>"; };
    46384646                1A820D900A13EBA600AF843C /* ImageDocument.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ImageDocument.h; sourceTree = "<group>"; };
     
    83768384                                1CFAE3230A6D6A3F0032593D /* libobjc.dylib in Frameworks */,
    83778385                                DD763BB20992C2C900740B8E /* libxml2.dylib in Frameworks */,
     8386                                1A7FA7CC0DDA4B770028F8A5 /* SystemConfiguration.framework in Frameworks */,
    83788387                        );
    83798388                        runOnlyForDeploymentPostprocessing = 0;
     
    84358444                                DD763BB10992C2C900740B8E /* libxml2.dylib */,
    84368445                                A85D7A2F0879EBA9006A9172 /* QuartzCore.framework */,
     8446                                1A7FA7CB0DDA4B770028F8A5 /* SystemConfiguration.framework */,
    84378447                        );
    84388448                        name = Frameworks;
     
    88918901                                514C765D0CE923A1007EF3CD /* HTTPParsers.cpp */,
    88928902                                514C765E0CE923A1007EF3CD /* HTTPParsers.h */,
     8903                                1A7FA61A0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp */,
     8904                                1A7FA6180DDA3B3A0028F8A5 /* NetworkStateNotifier.h */,
    88938905                                514C765F0CE923A1007EF3CD /* ProtectionSpace.cpp */,
    88948906                                514C76600CE923A1007EF3CD /* ProtectionSpace.h */,
     
    89148926                                514C76440CE9234E007EF3CD /* FormDataStreamMac.h */,
    89158927                                514C76450CE9234E007EF3CD /* FormDataStreamMac.mm */,
     8928                                1A7FA6470DDA3CBA0028F8A5 /* NetworkStateNotifierMac.cpp */,
    89168929                                514C76460CE9234E007EF3CD /* ResourceErrorMac.mm */,
    89178930                                514C76470CE9234E007EF3CD /* ResourceHandleMac.mm */,
     
    1508015093                                BC34C33F0DD607DE00090123 /* AccessItemRule.h in Headers */,
    1508115094                                BC76AC130DD7AD5C00415F34 /* ParserUtilities.h in Headers */,
     15095                                1A7FA6190DDA3B3A0028F8A5 /* NetworkStateNotifier.h in Headers */,
    1508215096                        );
    1508315097                        runOnlyForDeploymentPostprocessing = 0;
     
    1679416808                                BC34C33C0DD607DE00090123 /* AccessItem.cpp in Sources */,
    1679516809                                BC34C33E0DD607DE00090123 /* AccessItemRule.cpp in Sources */,
     16810                                1A7FA61B0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp in Sources */,
     16811                                1A7FA6490DDA3CBA0028F8A5 /* NetworkStateNotifierMac.cpp in Sources */,
    1679616812                        );
    1679716813                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/dom/EventNames.h

    r32006 r33457  
    6666    macro(mousewheel) \
    6767    macro(noupdate) \
     68    macro(offline) \
     69    macro(online) \
    6870    macro(overflowchanged) \
    6971    macro(paste) \
  • trunk/WebCore/page/Navigator.cpp

    r30923 r33457  
    3030#include "Language.h"
    3131#include "MimeTypeArray.h"
     32#include "NetworkStateNotifier.h"
    3233#include "PlatformString.h"
    3334#include "PluginArray.h"
     
    170171    return m_frame->settings()->isJavaEnabled();
    171172}
     173   
     174bool Navigator::onLine() const
     175{
     176    return networkStateNotifier().onLine();
     177}
    172178
    173179} // namespace WebCore
  • trunk/WebCore/page/Navigator.h

    r30923 r33457  
    5656        bool javaEnabled() const;
    5757
     58        bool onLine() const;
    5859    private:
    5960        Navigator(Frame*);
  • trunk/WebCore/page/Navigator.idl

    r30923 r33457  
    3535        readonly attribute boolean cookieEnabled;
    3636        boolean javaEnabled();
     37       
     38        readonly attribute boolean onLine;
    3739    };
    3840
  • trunk/WebCore/page/Page.cpp

    r33447 r33457  
    2929#include "DOMWindow.h"
    3030#include "DragController.h"
     31#include "EventNames.h"
    3132#include "FileSystem.h"
    3233#include "FocusController.h"
     
    3940#include "JavaScriptDebugServer.h"
    4041#include "Logging.h"
     42#include "NetworkStateNotifier.h"
    4143#include "Navigator.h"
    4244#include "PageGroup.h"
     
    6264namespace WebCore {
    6365
     66using namespace EventNames;
     67
    6468static HashSet<Page*>* allPages;
    6569
     
    7983#endif
    8084
     85static void networkStateChanged()
     86{
     87    Vector<RefPtr<Frame> > frames;
     88   
     89    // Get all the frames of all the pages in all the page groups
     90    HashSet<Page*>::iterator end = allPages->end();
     91    for (HashSet<Page*>::iterator it = allPages->begin(); it != end; ++it) {
     92        for (Frame* frame = (*it)->mainFrame(); frame; frame = frame->tree()->traverseNext())
     93            frames.append(frame);
     94    }
     95
     96    AtomicString eventName = networkStateNotifier().onLine() ? onlineEvent : offlineEvent;
     97   
     98    for (unsigned i = 0; i < frames.size(); i++) {
     99        Document* document = frames[i]->document();
     100       
     101        if (!document)
     102            continue;
     103
     104        // If the document does not have a body the event should be dispatched to the document
     105        EventTargetNode* eventTarget = document->body();
     106        if (!eventTarget)
     107            eventTarget = document;
     108       
     109        eventTarget->dispatchHTMLEvent(eventName, false, false);
     110    }
     111}
     112   
    81113Page::Page(ChromeClient* chromeClient, ContextMenuClient* contextMenuClient, EditorClient* editorClient, DragClient* dragClient, InspectorClient* inspectorClient)
    82114    : m_chrome(new Chrome(this, chromeClient))
     
    103135        allPages = new HashSet<Page*>;
    104136        setFocusRingColorChangeFunction(setNeedsReapplyStyles);
     137       
     138        networkStateNotifier().setNetworkStateChangedFunction(networkStateChanged);
    105139    }
    106140
Note: See TracChangeset for help on using the changeset viewer.