Add Web API Statistics Collection
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Sep 2018 17:14:07 +0000 (17:14 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Sep 2018 17:14:07 +0000 (17:14 +0000)
commit95a6ea97d0e419297988458f39248873231a6943
tree4f6c7101028e8017f39ec8d598c7b277ac07ccc1
parent002385f94f0f38306102feea5e40034bbf41377c
Add Web API Statistics Collection
https://bugs.webkit.org/show_bug.cgi?id=187773
<rdar://problem/44155162>

Patch by Woodrow Wang <woodrow_wang@apple.com> on 2018-09-11
Reviewed by Brent Fulgham.

Source/WebCore:

Added data collection for web API statistics, specifically regarding the canvas, font loads,
screen functions, and navigator functions. The data collection code is placed under a runtime
enabled feature flag. The statistics are stored in a ResourceLoadStatistics object and written
to a plist on disk. Added a new file CanvasActivityRecord.h and CanvasActivityRecord.cpp which
includes a struct to keep track of HTML5 canvas element read and writes.

Tests: http/tests/webAPIStatistics/canvas-read-and-write-data-collection.html
       http/tests/webAPIStatistics/font-load-data-collection.html
       http/tests/webAPIStatistics/navigator-functions-accessed-data-collection.html
       http/tests/webAPIStatistics/screen-functions-accessed-data-collection.html

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::load):
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::fontRangesForFamily):
(WebCore::CSSFontSelector::fallbackFontAt):

The following are the functions where we'd like to record a canvas read.

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::toDataURL):
(WebCore::HTMLCanvasElement::toBlob):
(WebCore::HTMLCanvasElement::getImageData):
(WebCore::HTMLCanvasElement::toMediaSample):
(WebCore::HTMLCanvasElement::captureStream):

The following are the functions where we'd like to record a canvas write.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::measureText):
(WebCore::CanvasRenderingContext2D::drawTextInternal):

The following files and functions handle the CanvasActivityRecord struct and
its respective functions.

* loader/CanvasActivityRecord.cpp: Added.
(WebCore::CanvasActivityRecord::recordWrittenOrMeasuredText):
(WebCore::CanvasActivityRecord::mergeWith):
* loader/CanvasActivityRecord.h: Added.
(WebCore::CanvasActivityRecord::encode const):
(WebCore::CanvasActivityRecord::decode):

* loader/DocumentThreadableLoader.cpp:
* loader/FrameLoader.cpp:
* loader/ResourceLoadObserver.cpp:
(WebCore::ResourceLoadObserver::logFontLoad):
(WebCore::ResourceLoadObserver::logCanvasRead):
(WebCore::ResourceLoadObserver::logCanvasWriteOrMeasure):
(WebCore::ResourceLoadObserver::logNavigatorAPIAccessed):
(WebCore::ResourceLoadObserver::logScreenAPIAccessed):

Before, entries in the ResourceLoadStatistics involving HashSets used "origin" as the key.
Now the encodeHashSet function has been generalized to take any key to encode the entries
in the HashSet. Also added functionality to encode an OptionSet by converting it to its
raw bitmask state.

* loader/ResourceLoadObserver.h:
* loader/ResourceLoadStatistics.cpp:
(WebCore::encodeHashSet):
(WebCore::encodeOriginHashSet):
(WebCore::encodeOptionSet):
(WebCore::encodeFontHashSet):
(WebCore::encodeCanvasActivityRecord):
(WebCore::ResourceLoadStatistics::encode const):
(WebCore::decodeHashSet):
(WebCore::decodeOriginHashSet):
(WebCore::decodeOptionSet):
(WebCore::decodeFontHashSet):
(WebCore::decodeCanvasActivityRecord):
(WebCore::ResourceLoadStatistics::decode):
(WebCore::navigatorAPIEnumToString):
(WebCore::screenAPIEnumToString):
(WebCore::appendNavigatorAPIOptionSet):
(WebCore::appendScreenAPIOptionSet):
(WebCore::ResourceLoadStatistics::toString const):
(WebCore::ResourceLoadStatistics::merge):
* loader/ResourceLoadStatistics.h:
* loader/ResourceTiming.cpp:

The following are the navigator functions recorded for the web API statistics.

* page/Navigator.cpp:
(WebCore::Navigator::appVersion const):
(WebCore::Navigator::userAgent const):
(WebCore::Navigator::plugins):
(WebCore::Navigator::mimeTypes):
(WebCore::Navigator::cookieEnabled const):
(WebCore::Navigator::javaEnabled const):

The following are the screen functions recorded for the web API statistics.

* page/Screen.cpp:
(WebCore::Screen::height const):
(WebCore::Screen::width const):
(WebCore::Screen::colorDepth const):
(WebCore::Screen::pixelDepth const):
(WebCore::Screen::availLeft const):
(WebCore::Screen::availTop const):
(WebCore::Screen::availHeight const):
(WebCore::Screen::availWidth const):

Source/WebKit:

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<ResourceLoadStatistics>::encode):
(IPC::ArgumentCoder<ResourceLoadStatistics>::decode):
* UIProcess/ResourceLoadStatisticsMemoryStore.cpp:

LayoutTests:

Added new tests and expectations for the web API statistics data collection.

* TestExpectations:
* http/tests/webAPIStatistics/canvas-read-and-write-data-collection-expected.txt: Added.
* http/tests/webAPIStatistics/canvas-read-and-write-data-collection.html: Added.
* http/tests/webAPIStatistics/font-load-data-collection-expected.txt: Added.
* http/tests/webAPIStatistics/font-load-data-collection.html: Added.
* http/tests/webAPIStatistics/navigator-functions-accessed-data-collection-expected.txt: Added.
* http/tests/webAPIStatistics/navigator-functions-accessed-data-collection.html: Added.
* http/tests/webAPIStatistics/screen-functions-accessed-data-collection-expected.txt: Added.
* http/tests/webAPIStatistics/screen-functions-accessed-data-collection.html: Added.
* platform/ios-wk2/TestExpectations:
* platform/mac-wk2/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235897 268f45cc-cd09-0410-ab3c-d52691b4dbfc
33 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/webAPIStatistics/canvas-read-and-write-data-collection-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/webAPIStatistics/canvas-read-and-write-data-collection.html [new file with mode: 0644]
LayoutTests/http/tests/webAPIStatistics/font-load-data-collection-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/webAPIStatistics/font-load-data-collection.html [new file with mode: 0644]
LayoutTests/http/tests/webAPIStatistics/navigator-functions-accessed-data-collection-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/webAPIStatistics/navigator-functions-accessed-data-collection.html [new file with mode: 0644]
LayoutTests/http/tests/webAPIStatistics/screen-functions-accessed-data-collection-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/webAPIStatistics/screen-functions-accessed-data-collection.html [new file with mode: 0644]
LayoutTests/platform/ios-wk2/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSFontFaceSource.cpp
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/loader/CanvasActivityRecord.cpp [new file with mode: 0644]
Source/WebCore/loader/CanvasActivityRecord.h [new file with mode: 0644]
Source/WebCore/loader/DocumentThreadableLoader.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/ResourceLoadObserver.cpp
Source/WebCore/loader/ResourceLoadObserver.h
Source/WebCore/loader/ResourceLoadStatistics.cpp
Source/WebCore/loader/ResourceLoadStatistics.h
Source/WebCore/loader/ResourceTiming.cpp
Source/WebCore/page/Navigator.cpp
Source/WebCore/page/Screen.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/UIProcess/ResourceLoadStatisticsMemoryStore.cpp