source: webkit/trunk/Source/WebCore/loader/CanvasActivityRecord.cpp

Last change on this file was 235897, checked in by [email protected], 7 years ago

Add Web API Statistics Collection
https://bugs.webkit.org/show_bug.cgi?id=187773
<rdar://problem/44155162>

Patch by Woodrow Wang <[email protected]> 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:
File size: 2.2 KB
Line 
1/*
2 * Copyright (C) 2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "CanvasActivityRecord.h"
28
29const unsigned maximumNumberOfStringsToRecord = 10;
30namespace WebCore {
31bool CanvasActivityRecord::recordWrittenOrMeasuredText(const String& text)
32{
33 // We limit the size of the textWritten HashSet to save memory and prevent bloating
34 // the plist with the resourceLoadStatistics entries. A few strings is often enough
35 // to provide sufficient information about the state of canvas activity.
36 if (textWritten.size() >= maximumNumberOfStringsToRecord)
37 return false;
38 return textWritten.add(text).isNewEntry;
39}
40
41void CanvasActivityRecord::mergeWith(const CanvasActivityRecord& otherCanvasActivityRecord)
42{
43 textWritten.add(otherCanvasActivityRecord.textWritten.begin(), otherCanvasActivityRecord.textWritten.end());
44 wasDataRead |= otherCanvasActivityRecord.wasDataRead;
45}
46} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.