<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[164757] trunk/Source</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/164757">164757</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2014-02-26 16:19:19 -0800 (Wed, 26 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>[iOS] Support network state notification using CPNetworkObserver
https://bugs.webkit.org/show_bug.cgi?id=129358
Reviewed by Dan Bernstein.
Source/WebCore:
Add iOS support for navigator.onLine and online/offline events. Since
it can be expensive to query CPNetworkObserver, wait to do so until
someone calls NetworkStateObserver::onLine() or
NetworkStateObserver::addNetworkStateChangeListener(). For clients that
don't wish to observe network reachability at all, add a global opt-out.
These clients will only pay the cost of CPNetworkObserver if they load
a page that explicitly accesses navigator.onLine.
No new tests. Covered by existing tests.
* WebCore.exp.in: Stopped exporting NetworkStateNotifier::setIsOnLine()
and started exporting Settings::gShouldOptOutOfNetworkStateObservation.
* WebCore.xcodeproj/project.pbxproj: Renamed NetworkStateNotifierIOS.cpp
to NetworkStateNotifierIOS.mm.
* page/Settings.cpp: Defaulted gShouldOptOutOfNetworkStateObservation
to false.
* page/Settings.h:
(WebCore::Settings::setShouldOptOutOfNetworkStateObservation):
(WebCore::Settings::shouldOptOutOfNetworkStateObservation):
* platform/network/NetworkStateNotifier.cpp:
(WebCore::NetworkStateNotifier::addNetworkStateChangeListener): Ignored
the listener if Settings::shouldOptOutOfNetworkStateObservation().
Called registerObserverIfNecessary() and added the listener otherwise.
(WebCore::NetworkStateNotifier::notifyNetworkStateChange): Const qualified.
* platform/network/NetworkStateNotifier.h
(NetworkStateNotifier::onLine):
* platform/network/ios/NetworkStateNotifierIOS.cpp: Removed.
* platform/network/ios/NetworkStateNotifierIOS.mm: Added.
(-[NetworkStateObserver initWithNotifier:WebCore::]): Registered self
as a network reachable observer on CPNetworkObserver.
(-[NetworkStateObserver dealloc]): Removed self as a network reachable
observer.
(-[NetworkStateObserver networkStateChanged:]): Called setOnLine() on
the web thread, passing the reachability value from the notification.
(WebCore::NetworkStateNotifier::NetworkStateNotifier):
(WebCore::NetworkStateNotifier::~NetworkStateNotifier): Cleared
m_observer's pointer back to us.
(WebCore::NetworkStateNotifier::registerObserverIfNecessary): Initialized
m_observer if necessary.
(WebCore::NetworkStateNotifier::onLine): Called
registerObserverIfNecessary() and set an initial value for m_isOnLine
if m_isOnLineInitialized is false. Returned m_isOnLine.
(WebCore::setOnLine): Set m_isOnLine and called
notifyNetworkStateChange() if needed. Unconditionally set
m_isOnLineInitialized to true.
Source/WebKit/mac:
* WebView/WebView.mm:
(-[WebView _setNetworkStateIsOnline:]): Retained an empty
implementation for binary compatibility for UIKit.
(+[WebView _doNotStartObservingNetworkReachability]): Called
Settings::setShouldOptOutOfNetworkStateObservation(true).
* WebView/WebViewPrivate.h: Removed declaration of
_setNetworkStateIsOnline: and declared
_doNotStartObservingNetworkReachability.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorepageSettingscpp">trunk/Source/WebCore/page/Settings.cpp</a></li>
<li><a href="#trunkSourceWebCorepageSettingsh">trunk/Source/WebCore/page/Settings.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkNetworkStateNotifiercpp">trunk/Source/WebCore/platform/network/NetworkStateNotifier.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkNetworkStateNotifierh">trunk/Source/WebCore/platform/network/NetworkStateNotifier.h</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebViewmm">trunk/Source/WebKit/mac/WebView/WebView.mm</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebViewPrivateh">trunk/Source/WebKit/mac/WebView/WebViewPrivate.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformnetworkiosNetworkStateNotifierIOSmm">trunk/Source/WebCore/platform/network/ios/NetworkStateNotifierIOS.mm</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformnetworkiosNetworkStateNotifierIOScpp">trunk/Source/WebCore/platform/network/ios/NetworkStateNotifierIOS.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebCore/ChangeLog        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2014-02-26 Andy Estes <aestes@apple.com>
+
+ [iOS] Support network state notification using CPNetworkObserver
+ https://bugs.webkit.org/show_bug.cgi?id=129358
+
+ Reviewed by Dan Bernstein.
+
+ Add iOS support for navigator.onLine and online/offline events. Since
+ it can be expensive to query CPNetworkObserver, wait to do so until
+ someone calls NetworkStateObserver::onLine() or
+ NetworkStateObserver::addNetworkStateChangeListener(). For clients that
+ don't wish to observe network reachability at all, add a global opt-out.
+ These clients will only pay the cost of CPNetworkObserver if they load
+ a page that explicitly accesses navigator.onLine.
+
+ No new tests. Covered by existing tests.
+
+ * WebCore.exp.in: Stopped exporting NetworkStateNotifier::setIsOnLine()
+ and started exporting Settings::gShouldOptOutOfNetworkStateObservation.
+ * WebCore.xcodeproj/project.pbxproj: Renamed NetworkStateNotifierIOS.cpp
+ to NetworkStateNotifierIOS.mm.
+ * page/Settings.cpp: Defaulted gShouldOptOutOfNetworkStateObservation
+ to false.
+ * page/Settings.h:
+ (WebCore::Settings::setShouldOptOutOfNetworkStateObservation):
+ (WebCore::Settings::shouldOptOutOfNetworkStateObservation):
+ * platform/network/NetworkStateNotifier.cpp:
+ (WebCore::NetworkStateNotifier::addNetworkStateChangeListener): Ignored
+ the listener if Settings::shouldOptOutOfNetworkStateObservation().
+ Called registerObserverIfNecessary() and added the listener otherwise.
+ (WebCore::NetworkStateNotifier::notifyNetworkStateChange): Const qualified.
+ * platform/network/NetworkStateNotifier.h
+ (NetworkStateNotifier::onLine):
+ * platform/network/ios/NetworkStateNotifierIOS.cpp: Removed.
+ * platform/network/ios/NetworkStateNotifierIOS.mm: Added.
+ (-[NetworkStateObserver initWithNotifier:WebCore::]): Registered self
+ as a network reachable observer on CPNetworkObserver.
+ (-[NetworkStateObserver dealloc]): Removed self as a network reachable
+ observer.
+ (-[NetworkStateObserver networkStateChanged:]): Called setOnLine() on
+ the web thread, passing the reachability value from the notification.
+ (WebCore::NetworkStateNotifier::NetworkStateNotifier):
+ (WebCore::NetworkStateNotifier::~NetworkStateNotifier): Cleared
+ m_observer's pointer back to us.
+ (WebCore::NetworkStateNotifier::registerObserverIfNecessary): Initialized
+ m_observer if necessary.
+ (WebCore::NetworkStateNotifier::onLine): Called
+ registerObserverIfNecessary() and set an initial value for m_isOnLine
+ if m_isOnLineInitialized is false. Returned m_isOnLine.
+ (WebCore::setOnLine): Set m_isOnLine and called
+ notifyNetworkStateChange() if needed. Unconditionally set
+ m_isOnLineInitialized to true.
+
</ins><span class="cx"> 2014-02-26 Brian Burg <bburg@apple.com>
</span><span class="cx">
</span><span class="cx"> Unreviewed build fix for !ENABLE(CONTEXT_MENUS).
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -2449,7 +2449,6 @@
</span><span class="cx"> __ZN7WebCore19ResourceRequestBase22setDefaultAllowCookiesEb
</span><span class="cx"> __ZN7WebCore19applicationIsWebAppEv
</span><span class="cx"> __ZN7WebCore19asciiLineBreakTableE
</span><del>-__ZN7WebCore20NetworkStateNotifier11setIsOnLineEb
</del><span class="cx"> __ZN7WebCore20PlatformEventFactory27createPlatformKeyboardEventEP8WebEvent
</span><span class="cx"> __ZN7WebCore20ResourceHandleClient22willCacheResponseAsyncEPNS_14ResourceHandleEPK20_CFCachedURLResponse
</span><span class="cx"> __ZN7WebCore20applicationIsOkCupidEv
</span><span class="lines">@@ -2555,6 +2554,7 @@
</span><span class="cx"> __ZN7WebCore8Settings23setNetworkInterfaceNameERKN3WTF6StringE
</span><span class="cx"> __ZN7WebCore8Settings31setAudioSessionCategoryOverrideEj
</span><span class="cx"> __ZN7WebCore8Settings34setNetworkDataUsageTrackingEnabledEb
</span><ins>+__ZN7WebCore8Settings38gShouldOptOutOfNetworkStateObservationE
</ins><span class="cx"> __ZN7WebCore9FontCache17getCachedFontDataERKNS_15FontDescriptionERKN3WTF12AtomicStringEbNS0_12ShouldRetainE
</span><span class="cx"> __ZN7WebCore9FontCache25getLastResortFallbackFontERKNS_15FontDescriptionENS0_12ShouldRetainE
</span><span class="cx"> __ZN7WebCore9FrameView20setWasScrolledByUserEb
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -1484,7 +1484,7 @@
</span><span class="cx">                 44311CD812E4E24B000A8D19 /* DOMDocumentPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 44311CD512E4E22D000A8D19 /* DOMDocumentPrivate.h */; };
</span><span class="cx">                 44311CD912E4E257000A8D19 /* DOMDocumentFragmentPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 44311CD412E4E22D000A8D19 /* DOMDocumentFragmentPrivate.h */; };
</span><span class="cx">                 44311F8212E4E66C000A8D19 /* DOMDocumentFragmentInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 85E711450AC5D5340053270F /* DOMDocumentFragmentInternal.h */; };
</span><del>-                443F04270E75C8FB007E5407 /* NetworkStateNotifierIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.cpp */; };
</del><ins>+                443F04270E75C8FB007E5407 /* NetworkStateNotifierIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.mm */; };
</ins><span class="cx">                 444D4E230F708B2E003158E0 /* WebCoreURLResponseIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 444D4E210F708B2E003158E0 /* WebCoreURLResponseIOS.mm */; };
</span><span class="cx">                 4476531B133170990006B789 /* SSLKeyGeneratorIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4476531A133170990006B789 /* SSLKeyGeneratorIOS.cpp */; };
</span><span class="cx">                 447958041643B49A001E0A7F /* ParsedContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 447958031643B47B001E0A7F /* ParsedContentType.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -8350,7 +8350,7 @@
</span><span class="cx">                 442AF7A8102CDDEA008FD4D3 /* QuickLook.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QuickLook.mm; sourceTree = "<group>"; };
</span><span class="cx">                 44311CD412E4E22D000A8D19 /* DOMDocumentFragmentPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDocumentFragmentPrivate.h; sourceTree = "<group>"; };
</span><span class="cx">                 44311CD512E4E22D000A8D19 /* DOMDocumentPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDocumentPrivate.h; sourceTree = "<group>"; };
</span><del>-                443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkStateNotifierIOS.cpp; sourceTree = "<group>"; };
</del><ins>+                443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkStateNotifierIOS.mm; sourceTree = "<group>"; };
</ins><span class="cx">                 444D4E210F708B2E003158E0 /* WebCoreURLResponseIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreURLResponseIOS.mm; sourceTree = "<group>"; };
</span><span class="cx">                 4476531A133170990006B789 /* SSLKeyGeneratorIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SSLKeyGeneratorIOS.cpp; path = ios/SSLKeyGeneratorIOS.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 447958021643B47B001E0A7F /* ParsedContentType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentType.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -15290,7 +15290,7 @@
</span><span class="cx">                 4497D58C0EBA854F00A10552 /* ios */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><del>-                                443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.cpp */,
</del><ins>+                                443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.mm */,
</ins><span class="cx">                                 442AF7A7102CDDEA008FD4D3 /* QuickLook.h */,
</span><span class="cx">                                 442AF7A8102CDDEA008FD4D3 /* QuickLook.mm */,
</span><span class="cx">                                 7E428CE413E3407F003B661C /* ResourceHandleIOS.mm */,
</span><span class="lines">@@ -28149,7 +28149,7 @@
</span><span class="cx">                                 5D874F130D161D3200796C3B /* NetscapePlugInStreamLoader.cpp in Sources */,
</span><span class="cx">                                 59C27F05138D28C10079B7E2 /* NetworkResourcesData.cpp in Sources */,
</span><span class="cx">                                 1A7FA61B0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp in Sources */,
</span><del>-                                443F04270E75C8FB007E5407 /* NetworkStateNotifierIOS.cpp in Sources */,
</del><ins>+                                443F04270E75C8FB007E5407 /* NetworkStateNotifierIOS.mm in Sources */,
</ins><span class="cx">                                 1A7FA6490DDA3CBA0028F8A5 /* NetworkStateNotifierMac.cpp in Sources */,
</span><span class="cx">                                 E13EF34916850C470034C83F /* NetworkStorageSessionCFNet.cpp in Sources */,
</span><span class="cx">                                 BCEF43E00E674110001C1287 /* NinePieceImage.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.cpp (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.cpp        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebCore/page/Settings.cpp        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -99,6 +99,7 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> bool Settings::gNetworkDataUsageTrackingEnabled = false;
</span><span class="cx"> bool Settings::gAVKitEnabled = false;
</span><ins>+bool Settings::gShouldOptOutOfNetworkStateObservation = false;
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> // NOTEs
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.h (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.h        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebCore/page/Settings.h        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -271,6 +271,9 @@
</span><span class="cx">
</span><span class="cx"> static void setAVKitEnabled(bool flag) { gAVKitEnabled = flag; }
</span><span class="cx"> static bool avKitEnabled() { return gAVKitEnabled; }
</span><ins>+
+ static void setShouldOptOutOfNetworkStateObservation(bool flag) { gShouldOptOutOfNetworkStateObservation = flag; }
+ static bool shouldOptOutOfNetworkStateObservation() { return gShouldOptOutOfNetworkStateObservation; }
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> private:
</span><span class="lines">@@ -353,6 +356,7 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> static bool gNetworkDataUsageTrackingEnabled;
</span><span class="cx"> static bool gAVKitEnabled;
</span><ins>+ static bool gShouldOptOutOfNetworkStateObservation;
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> static double gHiddenPageDOMTimerAlignmentInterval;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkNetworkStateNotifiercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/NetworkStateNotifier.cpp (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/NetworkStateNotifier.cpp        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebCore/platform/network/NetworkStateNotifier.cpp        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "NetworkStateNotifier.h"
</span><span class="cx">
</span><ins>+#include "Settings.h"
</ins><span class="cx"> #include <mutex>
</span><span class="cx"> #include <wtf/Assertions.h>
</span><span class="cx"> #include <wtf/StdLibExtras.h>
</span><span class="lines">@@ -47,11 +48,16 @@
</span><span class="cx"> void NetworkStateNotifier::addNetworkStateChangeListener(std::function<void (bool)> listener)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(listener);
</span><ins>+#if PLATFORM(IOS)
+ if (Settings::shouldOptOutOfNetworkStateObservation())
+ return;
+ registerObserverIfNecessary();
+#endif
</ins><span class="cx">
</span><span class="cx"> m_listeners.append(std::move(listener));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void NetworkStateNotifier::notifyNetworkStateChange()
</del><ins>+void NetworkStateNotifier::notifyNetworkStateChange() const
</ins><span class="cx"> {
</span><span class="cx"> for (const auto& listener : m_listeners)
</span><span class="cx"> listener(m_isOnLine);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkNetworkStateNotifierh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/NetworkStateNotifier.h (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/NetworkStateNotifier.h        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebCore/platform/network/NetworkStateNotifier.h        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
</del><ins>+ * Copyright (C) 2008, 2014 Apple Inc. All Rights Reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -48,6 +48,11 @@
</span><span class="cx"> typedef struct _Ecore_Fd_Handler Ecore_Fd_Handler;
</span><span class="cx"> typedef unsigned char Eina_Bool;
</span><span class="cx">
</span><ins>+#elif PLATFORM(IOS)
+
+#include <wtf/RetainPtr.h>
+OBJC_CLASS WebNetworkStateObserver;
+
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -56,22 +61,20 @@
</span><span class="cx"> WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><span class="cx"> NetworkStateNotifier();
</span><del>-#if PLATFORM(EFL)
</del><ins>+#if PLATFORM(EFL) || PLATFORM(IOS)
</ins><span class="cx"> ~NetworkStateNotifier();
</span><span class="cx"> #endif
</span><span class="cx"> void addNetworkStateChangeListener(std::function<void (bool isOnLine)>);
</span><span class="cx">
</span><del>- bool onLine() const { return m_isOnLine; }
-
-#if PLATFORM(IOS)
- void setIsOnLine(bool);
-#endif
</del><ins>+ bool onLine() const;
</ins><span class="cx">
</span><span class="cx"> private:
</span><ins>+#if !PLATFORM(IOS)
</ins><span class="cx"> bool m_isOnLine;
</span><ins>+#endif
</ins><span class="cx"> Vector<std::function<void (bool)>> m_listeners;
</span><span class="cx">
</span><del>- void notifyNetworkStateChange();
</del><ins>+ void notifyNetworkStateChange() const;
</ins><span class="cx"> void updateState();
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="lines">@@ -97,6 +100,14 @@
</span><span class="cx">
</span><span class="cx"> int m_netlinkSocket;
</span><span class="cx"> Ecore_Fd_Handler* m_fdHandler;
</span><ins>+
+#elif PLATFORM(IOS)
+ void registerObserverIfNecessary() const;
+ friend void setOnLine(const NetworkStateNotifier*, bool);
+
+ mutable bool m_isOnLine;
+ mutable bool m_isOnLineInitialized;
+ mutable RetainPtr<WebNetworkStateObserver> m_observer;
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx">
</span><span class="lines">@@ -111,8 +122,15 @@
</span><span class="cx">
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if !PLATFORM(IOS)
+inline bool NetworkStateNotifier::onLine() const
+{
+ return m_isOnLine;
+}
+#endif
+
</ins><span class="cx"> NetworkStateNotifier& networkStateNotifier();
</span><span class="cx">
</span><del>-};
</del><ins>+} // namespace WebCore
</ins><span class="cx">
</span><span class="cx"> #endif // NetworkStateNotifier_h
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkiosNetworkStateNotifierIOScpp"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/platform/network/ios/NetworkStateNotifierIOS.cpp (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ios/NetworkStateNotifierIOS.cpp        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebCore/platform/network/ios/NetworkStateNotifierIOS.cpp        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -1,44 +0,0 @@
</span><del>-/*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "NetworkStateNotifier.h"
-
-namespace WebCore {
-
-NetworkStateNotifier::NetworkStateNotifier()
- : m_isOnLine(false)
-{
-}
-
-void NetworkStateNotifier::setIsOnLine(bool isOnLine)
-{
- if (m_isOnLine == isOnLine)
- return;
- m_isOnLine = isOnLine;
- notifyNetworkStateChange();
-}
-
-}
</del></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkiosNetworkStateNotifierIOSmm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/network/ios/NetworkStateNotifierIOS.mm (0 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ios/NetworkStateNotifierIOS.mm         (rev 0)
+++ trunk/Source/WebCore/platform/network/ios/NetworkStateNotifierIOS.mm        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -0,0 +1,121 @@
</span><ins>+/*
+ * Copyright (C) 2008, 2014 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "NetworkStateNotifier.h"
+
+#import "SoftLinking.h"
+#import "WebCoreThreadRun.h"
+
+#if defined(__has_include) && __has_include(<AppSupport/CPNetworkObserver.h>)
+#import <AppSupport/CPNetworkObserver.h>
+#else
+extern NSString * const CPNetworkObserverReachable;
+@interface CPNetworkObserver : NSObject
++ (CPNetworkObserver *)sharedNetworkObserver;
+- (void)addNetworkReachableObserver:(id)observer selector:(SEL)selector;
+- (void)removeNetworkReachableObserver:(id)observer;
+- (BOOL)isNetworkReachable;
+@end
+#endif
+
+SOFT_LINK_PRIVATE_FRAMEWORK(AppSupport);
+SOFT_LINK_CLASS(AppSupport, CPNetworkObserver);
+SOFT_LINK_POINTER(AppSupport, CPNetworkObserverReachable, NSString *);
+
+@interface WebNetworkStateObserver : NSObject
+@property (nonatomic) const WebCore::NetworkStateNotifier* notifier;
+- (id)initWithNotifier:(const WebCore::NetworkStateNotifier*)notifier;
+- (void)networkStateChanged:(NSNotification *)notification;
+@end
+
+@implementation WebNetworkStateObserver
+
+- (id)initWithNotifier:(const WebCore::NetworkStateNotifier*)notifier
+{
+ ASSERT_ARG(notifier, notifier);
+ if (!(self = [super init]))
+ return nil;
+ _notifier = notifier;
+ [[getCPNetworkObserverClass() sharedNetworkObserver] addNetworkReachableObserver:self selector:@selector(networkStateChanged:)];
+ return self;
+}
+
+- (void)dealloc
+{
+ [[getCPNetworkObserverClass() sharedNetworkObserver] removeNetworkReachableObserver:self];
+ [super dealloc];
+}
+
+- (void)networkStateChanged:(NSNotification *)notification
+{
+ ASSERT_ARG(notification, notification);
+ WebThreadRun(^{
+ setOnLine(_notifier, [[[notification userInfo] objectForKey:getCPNetworkObserverReachable()] boolValue]);
+ });
+}
+
+@end
+
+namespace WebCore {
+
+NetworkStateNotifier::NetworkStateNotifier()
+ : m_isOnLine(false)
+ , m_isOnLineInitialized(false)
+{
+}
+
+NetworkStateNotifier::~NetworkStateNotifier()
+{
+ [m_observer setNotifier:nullptr];
+}
+
+void NetworkStateNotifier::registerObserverIfNecessary() const
+{
+ if (!m_observer)
+ m_observer = adoptNS([[WebNetworkStateObserver alloc] initWithNotifier:this]);
+}
+
+bool NetworkStateNotifier::onLine() const
+{
+ registerObserverIfNecessary();
+ if (!m_isOnLineInitialized) {
+ m_isOnLine = [[getCPNetworkObserverClass() sharedNetworkObserver] isNetworkReachable];
+ m_isOnLineInitialized = true;
+ }
+ return m_isOnLine;
+}
+
+void setOnLine(const NetworkStateNotifier* notifier, bool onLine)
+{
+ ASSERT_ARG(notifier, notifier);
+ notifier->m_isOnLineInitialized = true;
+ if (onLine == notifier->m_isOnLine)
+ return;
+ notifier->m_isOnLine = onLine;
+ notifier->notifyNetworkStateChange();
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebKit/mac/ChangeLog        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2014-02-26 Andy Estes <aestes@apple.com>
+
+ [iOS] Support network state notification using CPNetworkObserver
+ https://bugs.webkit.org/show_bug.cgi?id=129358
+
+ Reviewed by Dan Bernstein.
+
+ * WebView/WebView.mm:
+ (-[WebView _setNetworkStateIsOnline:]): Retained an empty
+ implementation for binary compatibility for UIKit.
+ (+[WebView _doNotStartObservingNetworkReachability]): Called
+ Settings::setShouldOptOutOfNetworkStateObservation(true).
+ * WebView/WebViewPrivate.h: Removed declaration of
+ _setNetworkStateIsOnline: and declared
+ _doNotStartObservingNetworkReachability.
+
</ins><span class="cx"> 2014-02-25 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Get rid of VisitedLinkStrategy
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebView.mm        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -3607,11 +3607,9 @@
</span><span class="cx"> return _private->allowsMessaging;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+// FIXME: Remove once this is no longer necessary for UIKit binary compatibility.
</ins><span class="cx"> - (void)_setNetworkStateIsOnline:(BOOL)isOnLine
</span><span class="cx"> {
</span><del>- WebThreadRun(^{
- networkStateNotifier().setIsOnLine(isOnLine);
- });
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)_setFixedLayoutSize:(CGSize)size
</span><span class="lines">@@ -3700,6 +3698,11 @@
</span><span class="cx">
</span><span class="cx"> frame->overflowScrollPositionChangedForNode(roundedIntPoint(offset), node, userScroll);
</span><span class="cx"> }
</span><ins>+
++ (void)_doNotStartObservingNetworkReachability
+{
+ Settings::setShouldOptOutOfNetworkStateObservation(true);
+}
</ins><span class="cx"> #endif // PLATFORM(IOS)
</span><span class="cx">
</span><span class="cx"> #if ENABLE(TOUCH_EVENTS)
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebViewPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebViewPrivate.h (164756 => 164757)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebViewPrivate.h        2014-02-26 23:48:33 UTC (rev 164756)
+++ trunk/Source/WebKit/mac/WebView/WebViewPrivate.h        2014-02-27 00:19:19 UTC (rev 164757)
</span><span class="lines">@@ -572,8 +572,6 @@
</span><span class="cx"> - (void)_setAllowsMessaging:(BOOL)aFlag;
</span><span class="cx"> - (BOOL)_allowsMessaging;
</span><span class="cx">
</span><del>-- (void)_setNetworkStateIsOnline:(BOOL)isOnLine;
-
</del><span class="cx"> - (void)_setCustomFixedPositionLayoutRectInWebThread:(CGRect)rect synchronize:(BOOL)synchronize;
</span><span class="cx"> - (void)_setCustomFixedPositionLayoutRect:(CGRect)rect;
</span><span class="cx">
</span><span class="lines">@@ -583,6 +581,13 @@
</span><span class="cx"> - (void)_overflowScrollPositionChangedTo:(CGPoint)offset forNode:(DOMNode *)node isUserScroll:(BOOL)userScroll;
</span><span class="cx">
</span><span class="cx"> - (NSArray *)_touchEventRegions;
</span><ins>+
+/*!
+ @method _doNotStartObservingNetworkReachability
+ @abstract Does not start observation of network reachability in any WebView.
+ @discussion To take effect, this method must be called before the first WebView is created.
+ */
++ (void)_doNotStartObservingNetworkReachability;
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> #if !TARGET_OS_IPHONE
</span></span></pre>
</div>
</div>
</body>
</html>