Commit 855ec4bc authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Fix 64 bit truncation issues in renderer/modules

Use wtf_size_t where appropriate.

BUG=879657

Change-Id: I26f766e7f6f29c6beaf0d396d665f1eba1235d83
Reviewed-on: https://chromium-review.googlesource.com/c/1298246
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603101}
parent 0a8ce562
......@@ -52,7 +52,7 @@ class CORE_EXPORT LayoutWorklet : public Worklet,
explicit LayoutWorklet(LocalFrame*);
// TODO(ikilpatrick): Make selection of the global scope non-deterministic.
size_t SelectGlobalScope() final { return 0u; }
wtf_size_t SelectGlobalScope() final { return 0u; }
private:
friend class LayoutWorkletTest;
......
......@@ -113,7 +113,7 @@ WorkletGlobalScopeProxy* TaskWorklet::CreateGlobalScope() {
}
// We select a global scope without this getting called.
size_t TaskWorklet::SelectGlobalScope() {
wtf_size_t TaskWorklet::SelectGlobalScope() {
NOTREACHED();
return 0u;
}
......
......@@ -41,7 +41,7 @@ class TaskWorklet final : public Worklet,
bool NeedsToCreateGlobalScope() final;
WorkletGlobalScopeProxy* CreateGlobalScope() final;
size_t SelectGlobalScope() final;
wtf_size_t SelectGlobalScope() final;
};
} // namespace blink
......
......@@ -164,7 +164,7 @@ void Worklet::FetchAndInvokeScript(const KURL& module_url_record,
}
}
size_t Worklet::SelectGlobalScope() {
wtf_size_t Worklet::SelectGlobalScope() {
DCHECK_EQ(GetNumberOfGlobalScopes(), 1u);
return 0u;
}
......
......@@ -58,7 +58,7 @@ class CORE_EXPORT Worklet : public ScriptWrappable,
// Returns one of available global scopes.
WorkletGlobalScopeProxy* FindAvailableGlobalScope();
size_t GetNumberOfGlobalScopes() const { return proxies_.size(); }
wtf_size_t GetNumberOfGlobalScopes() const { return proxies_.size(); }
WorkletModuleResponsesMap* ModuleResponsesMap() const {
return module_responses_map_.Get();
......@@ -85,7 +85,7 @@ class CORE_EXPORT Worklet : public ScriptWrappable,
// there are multiple global scopes, this function MUST be overriden. The
// default behavior is to return the global scope at index 0, which is for the
// case where there is only one global scope.
virtual size_t SelectGlobalScope();
virtual wtf_size_t SelectGlobalScope();
// "A Worklet has a module responses map. This is a ordered map of module URLs
// to values that are a fetch responses. The map's entries are ordered based
// on their insertion order. Access to this map should be thread-safe."
......
......@@ -66,9 +66,9 @@ OffscreenCanvas* HTMLCanvasElementModule::TransferControlToOffscreenInternal(
OffscreenCanvas* offscreen_canvas =
OffscreenCanvas::Create(canvas.width(), canvas.height());
int canvas_id = DOMNodeIds::IdForNode(&canvas);
DOMNodeId canvas_id = DOMNodeIds::IdForNode(&canvas);
offscreen_canvas->SetPlaceholderCanvasId(canvas_id);
canvas.RegisterPlaceholder(canvas_id);
canvas.RegisterPlaceholder(static_cast<int>(canvas_id));
SurfaceLayerBridge* bridge = canvas.SurfaceLayerBridge();
if (bridge) {
......
......@@ -15,7 +15,7 @@
namespace blink {
const size_t PaintWorklet::kNumGlobalScopes = 2u;
const wtf_size_t PaintWorklet::kNumGlobalScopes = 2u;
const size_t kMaxPaintCountToSwitch = 30u;
DocumentPaintDefinition* const kInvalidDocumentPaintDefinition = nullptr;
......@@ -52,7 +52,7 @@ void PaintWorklet::AddPendingGenerator(const String& name,
// calls (rand(kMaxPaintCountToSwitch)).
// This approach ensures non-deterministic of global scope selecting, and that
// there is a max of one switching within one frame.
size_t PaintWorklet::SelectGlobalScope() {
wtf_size_t PaintWorklet::SelectGlobalScope() {
size_t current_paint_frame_count = GetFrame()->View()->PaintFrameCount();
// Whether a new frame starts or not.
bool frame_changed = current_paint_frame_count != active_frame_count_;
......@@ -82,8 +82,8 @@ int PaintWorklet::GetPaintsBeforeSwitching() {
return base::RandInt(0, kMaxPaintCountToSwitch - 1);
}
size_t PaintWorklet::SelectNewGlobalScope() {
return static_cast<size_t>(base::RandGenerator(kNumGlobalScopes));
wtf_size_t PaintWorklet::SelectNewGlobalScope() {
return static_cast<wtf_size_t>(base::RandGenerator(kNumGlobalScopes));
}
scoped_refptr<Image> PaintWorklet::Paint(const String& name,
......
......@@ -29,7 +29,7 @@ class MODULES_EXPORT PaintWorklet : public Worklet,
static const char kSupplementName[];
// At this moment, paint worklet allows at most two global scopes at any time.
static const size_t kNumGlobalScopes;
static const wtf_size_t kNumGlobalScopes;
static PaintWorklet* From(LocalDOMWindow&);
static PaintWorklet* Create(LocalFrame*);
......@@ -54,8 +54,8 @@ class MODULES_EXPORT PaintWorklet : public Worklet,
// Since paint worklet has more than one global scope, we MUST override this
// function and provide our own selection logic.
size_t SelectGlobalScope() final;
size_t GetActiveGlobalScopeForTesting() { return active_global_scope_; }
wtf_size_t SelectGlobalScope() final;
wtf_size_t GetActiveGlobalScopeForTesting() { return active_global_scope_; }
private:
friend class PaintWorkletTest;
......@@ -68,7 +68,7 @@ class MODULES_EXPORT PaintWorklet : public Worklet,
// global scopes.
virtual int GetPaintsBeforeSwitching();
// This function calculates the next global scope to switch to.
virtual size_t SelectNewGlobalScope();
virtual wtf_size_t SelectNewGlobalScope();
Member<PaintWorkletPendingGeneratorRegistry> pending_generator_registry_;
DocumentDefinitionMap document_definition_map_;
......@@ -77,7 +77,7 @@ class MODULES_EXPORT PaintWorklet : public Worklet,
// tell when we begin painting on a new frame.
size_t active_frame_count_ = 0u;
// The current global scope being used for painting.
size_t active_global_scope_ = 0u;
wtf_size_t active_global_scope_ = 0u;
// The number of paint calls remaining before Paint will select a new global
// scope. SelectGlobalScope resets this at the beginning of each frame.
int paints_before_switching_global_scope_;
......
......@@ -23,13 +23,13 @@ class TestPaintWorklet : public PaintWorklet {
public:
explicit TestPaintWorklet(LocalFrame* frame) : PaintWorklet(frame) {}
void SetPaintsToSwitch(size_t num) { paints_to_switch_ = num; }
void SetPaintsToSwitch(int num) { paints_to_switch_ = num; }
int GetPaintsBeforeSwitching() override { return paints_to_switch_; }
// We always switch to another global scope so that we can tell how often it
// was switched in the test.
size_t SelectNewGlobalScope() override {
wtf_size_t SelectNewGlobalScope() override {
return (GetActiveGlobalScopeForTesting() + 1) %
PaintWorklet::kNumGlobalScopes;
}
......@@ -37,7 +37,7 @@ class TestPaintWorklet : public PaintWorklet {
size_t GetActiveGlobalScope() { return GetActiveGlobalScopeForTesting(); }
private:
size_t paints_to_switch_;
int paints_to_switch_;
};
class PaintWorkletTest : public PageTestBase {
......@@ -66,7 +66,7 @@ class PaintWorkletTest : public PageTestBase {
// Helper function used in GlobalScopeSelection test.
void ExpectSwitchGlobalScope(bool expect_switch_within_frame,
size_t num_paint_calls,
size_t paint_cnt_to_switch,
int paint_cnt_to_switch,
size_t expected_num_paints_before_switch,
TestPaintWorklet* paint_worklet_to_test) {
paint_worklet_to_test->GetFrame()->View()->UpdateAllLifecyclePhases();
......
......@@ -45,7 +45,7 @@ constexpr int kMaxDepth = 4;
// Some strings are very long, and we don't currently use those, so limit string
// length to something reasonable to avoid undue pressure on Icing. Note that
// App Indexing supports strings up to length 20k.
constexpr int kMaxStringLength = 200;
constexpr wtf_size_t kMaxStringLength = 200;
// Enforced by App Indexing, so stop processing early if possible.
constexpr wtf_size_t kMaxNumFields = 20;
// Enforced by App Indexing, so stop processing early if possible.
......@@ -231,7 +231,7 @@ void extractTopLevelEntity(const JSONObject& val, Vector<EntityPtr>& entities) {
void extractEntitiesFromArray(const JSONArray& arr,
Vector<EntityPtr>& entities) {
for (size_t i = 0; i < arr.size(); ++i) {
for (wtf_size_t i = 0; i < arr.size(); ++i) {
const JSONValue* val = arr.at(i);
if (val->GetType() == JSONValue::ValueType::kTypeObject) {
extractTopLevelEntity(*(JSONObject::Cast(val)), entities);
......
......@@ -83,18 +83,18 @@ String TextDecoder::decode(const BufferSource& input,
if (input.IsArrayBufferView()) {
const char* start = static_cast<const char*>(
input.GetAsArrayBufferView().View()->BaseAddress());
size_t length = input.GetAsArrayBufferView().View()->byteLength();
uint32_t length = input.GetAsArrayBufferView().View()->byteLength();
return decode(start, length, options, exception_state);
}
DCHECK(input.IsArrayBuffer());
const char* start =
static_cast<const char*>(input.GetAsArrayBuffer()->Data());
size_t length = input.GetAsArrayBuffer()->ByteLength();
uint32_t length = input.GetAsArrayBuffer()->ByteLength();
return decode(start, length, options, exception_state);
}
String TextDecoder::decode(const char* start,
size_t length,
uint32_t length,
const TextDecodeOptions& options,
ExceptionState& exception_state) {
WTF::FlushBehavior flush =
......
......@@ -67,7 +67,7 @@ class TextDecoder final : public ScriptWrappable {
TextDecoder(const WTF::TextEncoding&, bool fatal, bool ignore_bom);
String decode(const char* start,
size_t length,
uint32_t length,
const TextDecodeOptions&,
ExceptionState&);
......
......@@ -60,7 +60,7 @@ class TextDecoderStream::Transformer final : public TransformStreamTransformer {
return;
}
const char* start = static_cast<const char*>(view->BaseAddress());
size_t length = view->byteLength();
uint32_t length = view->byteLength();
DecodeAndEnqueue(start, length, WTF::FlushBehavior::kDoNotFlush,
controller, exception_state);
return;
......@@ -74,7 +74,7 @@ class TextDecoderStream::Transformer final : public TransformStreamTransformer {
return;
}
const char* start = static_cast<const char*>(array_buffer->Data());
size_t length = array_buffer->ByteLength();
uint32_t length = array_buffer->ByteLength();
DecodeAndEnqueue(start, length, WTF::FlushBehavior::kDoNotFlush, controller,
exception_state);
}
......@@ -95,7 +95,7 @@ class TextDecoderStream::Transformer final : public TransformStreamTransformer {
// Implements the second part of "decode and enqueue a chunk" as well as the
// "flush and enqueue" algorithm.
void DecodeAndEnqueue(const char* start,
size_t length,
uint32_t length,
WTF::FlushBehavior flush,
TransformStreamDefaultController* controller,
ExceptionState& exception_state) {
......
......@@ -101,8 +101,8 @@ class TextEncoderStream::Transformer final : public TransformStreamTransformer {
static DOMUint8Array* CreateDOMUint8ArrayFromTwoCStringsConcatenated(
const CString& string1,
const CString& string2) {
const size_t length1 = string1.length();
const size_t length2 = string2.length();
const wtf_size_t length1 = string1.length();
const wtf_size_t length2 = string2.length();
DOMUint8Array* const array = DOMUint8Array::Create(length1 + length2);
if (length1 > 0)
memcpy(array->Data(), string1.data(), length1);
......@@ -144,8 +144,8 @@ class TextEncoderStream::Transformer final : public TransformStreamTransformer {
}
// Third argument is ignored, as above.
*result =
encoder_->Encode(begin, end - begin, WTF::kEntitiesForUnencodables);
*result = encoder_->Encode(begin, static_cast<wtf_size_t>(end - begin),
WTF::kEntitiesForUnencodables);
DCHECK_NE(result->length(), 0u);
return true;
}
......
......@@ -54,6 +54,7 @@
#include "third_party/blink/renderer/platform/network/mime/content_type.h"
#include "third_party/blink/renderer/platform/timer.h"
#include "third_party/blink/renderer/platform/wtf/ascii_ctype.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#define MEDIA_KEY_SESSION_LOG_LEVEL 3
......@@ -895,7 +896,7 @@ void MediaKeySession::Message(MessageType message_type,
break;
}
init.setMessage(DOMArrayBuffer::Create(static_cast<const void*>(message),
message_length));
SafeCast<uint32_t>(message_length)));
MediaKeyMessageEvent* event =
MediaKeyMessageEvent::Create(EventTypeNames::message, init);
......
......@@ -100,7 +100,7 @@ class MapIterationSource final
// m_map is stored just for keeping it alive. It needs to be kept
// alive while JavaScript holds the iterator to it.
const Member<const MediaKeyStatusMap> map_;
size_t current_;
uint32_t current_;
};
void MediaKeyStatusMap::Clear() {
......@@ -110,20 +110,20 @@ void MediaKeyStatusMap::Clear() {
void MediaKeyStatusMap::AddEntry(WebData key_id, const String& status) {
// Insert new entry into sorted list.
MapEntry* entry = MapEntry::Create(key_id, status);
size_t index = 0;
uint32_t index = 0;
while (index < entries_.size() &&
MapEntry::CompareLessThan(entries_[index], entry))
++index;
entries_.insert(index, entry);
}
const MediaKeyStatusMap::MapEntry& MediaKeyStatusMap::at(size_t index) const {
const MediaKeyStatusMap::MapEntry& MediaKeyStatusMap::at(uint32_t index) const {
DCHECK_LT(index, entries_.size());
return *entries_.at(index);
}
size_t MediaKeyStatusMap::IndexOf(const DOMArrayPiece& key) const {
for (size_t index = 0; index < entries_.size(); ++index) {
uint32_t MediaKeyStatusMap::IndexOf(const DOMArrayPiece& key) const {
for (uint32_t index = 0; index < entries_.size(); ++index) {
auto* const current = entries_.at(index)->KeyId();
if (key == *current)
return index;
......@@ -131,17 +131,17 @@ size_t MediaKeyStatusMap::IndexOf(const DOMArrayPiece& key) const {
// Not found, so return an index outside the valid range. The caller
// must ensure this value is not exposed outside this class.
return std::numeric_limits<size_t>::max();
return std::numeric_limits<uint32_t>::max();
}
bool MediaKeyStatusMap::has(const ArrayBufferOrArrayBufferView& key_id) {
size_t index = IndexOf(key_id);
uint32_t index = IndexOf(key_id);
return index < entries_.size();
}
ScriptValue MediaKeyStatusMap::get(ScriptState* script_state,
const ArrayBufferOrArrayBufferView& key_id) {
size_t index = IndexOf(key_id);
uint32_t index = IndexOf(key_id);
if (index >= entries_.size())
return ScriptValue(script_state, v8::Undefined(script_state->GetIsolate()));
return ScriptValue::From(script_state, at(index).Status());
......
......@@ -39,10 +39,10 @@ class MediaKeyStatusMap final
void Clear();
void AddEntry(WebData key_id, const String& status);
const MapEntry& at(size_t) const;
const MapEntry& at(uint32_t) const;
// IDL attributes / methods
size_t size() const { return entries_.size(); }
uint32_t size() const { return entries_.size(); }
bool has(const ArrayBufferOrArrayBufferView& key_id);
ScriptValue get(ScriptState*, const ArrayBufferOrArrayBufferView& key_id);
......@@ -52,7 +52,7 @@ class MediaKeyStatusMap final
// PairIterable<> implementation.
IterationSource* StartIteration(ScriptState*, ExceptionState&) override;
size_t IndexOf(const DOMArrayPiece& key_id) const;
uint32_t IndexOf(const DOMArrayPiece& key_id) const;
MediaKeyStatusMapType entries_;
};
......
......@@ -19,6 +19,7 @@
#include "third_party/blink/renderer/modules/encryptedmedia/media_keys_controller.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/timer.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink {
......@@ -70,8 +71,8 @@ class NewCdmResultPromise : public ContentDecryptionModuleResultPromise {
// NavigatorRequestMediaKeySystemAccess.
static Vector<String> ConvertInitDataTypes(
const WebVector<WebEncryptedMediaInitDataType>& init_data_types) {
Vector<String> result(init_data_types.size());
for (size_t i = 0; i < init_data_types.size(); i++)
Vector<String> result(SafeCast<wtf_size_t>(init_data_types.size()));
for (wtf_size_t i = 0; i < result.size(); i++)
result[i] =
EncryptedMediaUtils::ConvertFromInitDataType(init_data_types[i]);
return result;
......@@ -79,8 +80,9 @@ static Vector<String> ConvertInitDataTypes(
static HeapVector<MediaKeySystemMediaCapability> ConvertCapabilities(
const WebVector<WebMediaKeySystemMediaCapability>& capabilities) {
HeapVector<MediaKeySystemMediaCapability> result(capabilities.size());
for (size_t i = 0; i < capabilities.size(); i++) {
HeapVector<MediaKeySystemMediaCapability> result(
SafeCast<wtf_size_t>(capabilities.size()));
for (wtf_size_t i = 0; i < result.size(); i++) {
MediaKeySystemMediaCapability capability;
capability.setContentType(capabilities[i].content_type);
capability.setRobustness(capabilities[i].robustness);
......@@ -119,8 +121,8 @@ static String ConvertMediaKeysRequirement(
static Vector<String> ConvertSessionTypes(
const WebVector<WebEncryptedMediaSessionType>& session_types) {
Vector<String> result(session_types.size());
for (size_t i = 0; i < session_types.size(); i++)
Vector<String> result(SafeCast<wtf_size_t>(session_types.size()));
for (wtf_size_t i = 0; i < result.size(); i++)
result[i] = EncryptedMediaUtils::ConvertFromSessionType(session_types[i]);
return result;
}
......
......@@ -47,7 +47,7 @@ const char kEncryptedMediaFeaturePolicyConsoleWarning[] =
static WebVector<WebEncryptedMediaInitDataType> ConvertInitDataTypes(
const Vector<String>& init_data_types) {
WebVector<WebEncryptedMediaInitDataType> result(init_data_types.size());
for (size_t i = 0; i < init_data_types.size(); ++i)
for (wtf_size_t i = 0; i < init_data_types.size(); ++i)
result[i] = EncryptedMediaUtils::ConvertToInitDataType(init_data_types[i]);
return result;
}
......@@ -66,7 +66,7 @@ ConvertEncryptionScheme(const String& encryption_scheme) {
static WebVector<WebMediaKeySystemMediaCapability> ConvertCapabilities(
const HeapVector<MediaKeySystemMediaCapability>& capabilities) {
WebVector<WebMediaKeySystemMediaCapability> result(capabilities.size());
for (size_t i = 0; i < capabilities.size(); ++i) {
for (wtf_size_t i = 0; i < capabilities.size(); ++i) {
const WebString& content_type = capabilities[i].contentType();
result[i].content_type = content_type;
ParsedContentType type(content_type);
......@@ -115,7 +115,7 @@ static WebMediaKeySystemConfiguration::Requirement ConvertMediaKeysRequirement(
static WebVector<WebEncryptedMediaSessionType> ConvertSessionTypes(
const Vector<String>& session_types) {
WebVector<WebEncryptedMediaSessionType> result(session_types.size());
for (size_t i = 0; i < session_types.size(); ++i)
for (wtf_size_t i = 0; i < session_types.size(); ++i)
result[i] = EncryptedMediaUtils::ConvertToSessionType(session_types[i]);
return result;
}
......@@ -170,7 +170,7 @@ MediaKeySystemAccessInitializer::MediaKeySystemAccessInitializer(
: resolver_(ScriptPromiseResolver::Create(script_state)),
key_system_(key_system),
supported_configurations_(supported_configurations.size()) {
for (size_t i = 0; i < supported_configurations.size(); ++i) {
for (wtf_size_t i = 0; i < supported_configurations.size(); ++i) {
const MediaKeySystemConfiguration& config = supported_configurations[i];
WebMediaKeySystemConfiguration web_config;
......
......@@ -47,8 +47,8 @@ class MODULES_EXPORT MediaRecorder final
MediaStream* stream() const { return stream_.Get(); }
const String& mimeType() const { return mime_type_; }
String state() const;
unsigned long videoBitsPerSecond() const { return video_bits_per_second_; }
unsigned long audioBitsPerSecond() const { return audio_bits_per_second_; }
uint32_t videoBitsPerSecond() const { return video_bits_per_second_; }
uint32_t audioBitsPerSecond() const { return audio_bits_per_second_; }
DEFINE_ATTRIBUTE_EVENT_LISTENER(start);
DEFINE_ATTRIBUTE_EVENT_LISTENER(stop);
......
......@@ -171,7 +171,7 @@ class SourceBuffer final : public EventTargetWithInlineData,
bool first_initialization_segment_received_;
Vector<unsigned char> pending_append_data_;
size_t pending_append_data_offset_;
wtf_size_t pending_append_data_offset_;
Member<AsyncMethodRunner<SourceBuffer>> append_buffer_async_part_runner_;
double pending_remove_start_;
......
......@@ -47,13 +47,13 @@ void SourceBufferList::Add(SourceBuffer* buffer) {
ScheduleEvent(EventTypeNames::addsourcebuffer);
}
void SourceBufferList::insert(size_t position, SourceBuffer* buffer) {
void SourceBufferList::insert(wtf_size_t position, SourceBuffer* buffer) {
list_.insert(position, buffer);
ScheduleEvent(EventTypeNames::addsourcebuffer);
}
void SourceBufferList::Remove(SourceBuffer* buffer) {
size_t index = list_.Find(buffer);
wtf_size_t index = list_.Find(buffer);
if (index == kNotFound)
return;
list_.EraseAt(index);
......
......@@ -62,9 +62,9 @@ class SourceBufferList final : public EventTargetWithInlineData,
}
void Add(SourceBuffer*);
void insert(size_t position, SourceBuffer*);
void insert(wtf_size_t position, SourceBuffer*);
void Remove(SourceBuffer*);
size_t Find(SourceBuffer* buffer) { return list_.Find(buffer); }
wtf_size_t Find(SourceBuffer* buffer) { return list_.Find(buffer); }
bool Contains(SourceBuffer* buffer) {
return list_.Find(buffer) != kNotFound;
}
......
......@@ -277,20 +277,21 @@ void MediaDevices::DevicesEnumerated(
return;
}
DCHECK_EQ(static_cast<size_t>(MediaDeviceType::NUM_MEDIA_DEVICE_TYPES),
DCHECK_EQ(static_cast<wtf_size_t>(MediaDeviceType::NUM_MEDIA_DEVICE_TYPES),
enumeration.size());
if (!video_input_capabilities.IsEmpty()) {
DCHECK_EQ(
enumeration[static_cast<size_t>(MediaDeviceType::MEDIA_VIDEO_INPUT)]
enumeration[static_cast<wtf_size_t>(MediaDeviceType::MEDIA_VIDEO_INPUT)]
.size(),
video_input_capabilities.size());
}
MediaDeviceInfoVector media_devices;
for (size_t i = 0;
i < static_cast<size_t>(MediaDeviceType::NUM_MEDIA_DEVICE_TYPES); ++i) {
for (size_t j = 0; j < enumeration[i].size(); ++j) {
for (wtf_size_t i = 0;
i < static_cast<wtf_size_t>(MediaDeviceType::NUM_MEDIA_DEVICE_TYPES);
++i) {
for (wtf_size_t j = 0; j < enumeration[i].size(); ++j) {
MediaDeviceType device_type = static_cast<MediaDeviceType>(i);
mojom::blink::MediaDeviceInfoPtr device_info =
std::move(enumeration[i][j]);
......
......@@ -223,7 +223,7 @@ class MediaDevicesTest : public testing::Test {
void DevicesEnumerated(const MediaDeviceInfoVector& device_infos) {
devices_enumerated_ = true;
for (size_t i = 0; i < device_infos.size(); i++) {
for (wtf_size_t i = 0; i < device_infos.size(); i++) {
device_infos_->push_back(MediaDeviceInfo::Create(
device_infos[i]->deviceId(), device_infos[i]->label(),
device_infos[i]->groupId(), device_infos[i]->DeviceType()));
......
......@@ -38,8 +38,8 @@ namespace blink {
static bool ContainsSource(MediaStreamTrackVector& track_vector,
MediaStreamSource* source) {
for (size_t i = 0; i < track_vector.size(); ++i) {
if (source->Id() == track_vector[i]->Component()->Source()->Id())
for (MediaStreamTrack* track : track_vector) {
if (source->Id() == track->Component()->Source()->Id())
return true;
}
return false;
......@@ -66,11 +66,11 @@ MediaStream* MediaStream::Create(ExecutionContext* context,
MediaStreamTrackVector audio_tracks;
MediaStreamTrackVector video_tracks;
for (size_t i = 0; i < stream->audio_tracks_.size(); ++i)
ProcessTrack(stream->audio_tracks_[i].Get(), audio_tracks);
for (MediaStreamTrack* track : stream->audio_tracks_)
ProcessTrack(track, audio_tracks);
for (size_t i = 0; i < stream->video_tracks_.size(); ++i)
ProcessTrack(stream->video_tracks_[i].Get(), video_tracks);
for (MediaStreamTrack* track : stream->video_tracks_)
ProcessTrack(track, video_tracks);
return new MediaStream(context, audio_tracks, video_tracks);
}
......@@ -80,9 +80,9 @@ MediaStream* MediaStream::Create(ExecutionContext* context,
MediaStreamTrackVector audio_tracks;
MediaStreamTrackVector video_tracks;
for (size_t i = 0; i < tracks.size(); ++i)
ProcessTrack(tracks[i].Get(),
tracks[i]->kind() == "audio" ? audio_tracks : video_tracks);
for (MediaStreamTrack* track : tracks) {
ProcessTrack(track, track->kind() == "audio" ? audio_tracks : video_tracks);
}
return new MediaStream(context, audio_tracks, video_tracks);
}
......@@ -110,18 +110,18 @@ MediaStream::MediaStream(ExecutionContext* context,
&MediaStream::ScheduledEventTimerFired) {
descriptor_->SetClient(this);
size_t number_of_audio_tracks = descriptor_->NumberOfAudioComponents();
uint32_t number_of_audio_tracks = descriptor_->NumberOfAudioComponents();
audio_tracks_.ReserveCapacity(number_of_audio_tracks);
for (size_t i = 0; i < number_of_audio_tracks; i++) {
for (uint32_t i = 0; i < number_of_audio_tracks; i++) {
MediaStreamTrack* new_track =
MediaStreamTrack::Create(context, descriptor_->AudioComponent(i));
new_track->RegisterMediaStream(this);
audio_tracks_.push_back(new_track);
}
size_t number_of_video_tracks = descriptor_->NumberOfVideoComponents();
uint32_t number_of_video_tracks = descriptor_->NumberOfVideoComponents();
video_tracks_.ReserveCapacity(number_of_video_tracks);
for (size_t i = 0; i < number_of_video_tracks; i++) {
for (uint32_t i = 0; i < number_of_video_tracks; i++) {
MediaStreamTrack* new_track =
MediaStreamTrack::Create(context, descriptor_->VideoComponent(i));
new_track->RegisterMediaStream(this);
......@@ -146,15 +146,13 @@ MediaStream::MediaStream(ExecutionContext* context,
descriptor_->SetClient(this);
audio_tracks_.ReserveCapacity(audio_tracks.size());
for (size_t i = 0; i < audio_tracks.size(); ++i) {
MediaStreamTrack* audio_track = audio_tracks[i];
for (MediaStreamTrack* audio_track : audio_tracks) {
DCHECK_EQ("audio", audio_track->kind());
audio_track->RegisterMediaStream(this);
audio_tracks_.push_back(audio_track);
}
video_tracks_.ReserveCapacity(video_tracks.size());
for (size_t i = 0; i < video_tracks.size(); ++i) {
MediaStreamTrack* video_track = video_tracks[i];
for (MediaStreamTrack* video_track : video_tracks) {
DCHECK_EQ("video", video_track->kind());
video_track->RegisterMediaStream(this);
video_tracks_.push_back(video_track);
......@@ -220,13 +218,13 @@ bool MediaStream::EmptyOrOnlyEndedTracks() {
bool MediaStream::TracksMatchDescriptor() {
if (audio_tracks_.size() != descriptor_->NumberOfAudioComponents())
return false;
for (size_t i = 0; i < audio_tracks_.size(); i++) {
for (wtf_size_t i = 0; i < audio_tracks_.size(); i++) {
if (audio_tracks_[i]->Component() != descriptor_->AudioComponent(i))
return false;
}
if (video_tracks_.size() != descriptor_->NumberOfVideoComponents())
return false;
for (size_t i = 0; i < video_tracks_.size(); i++) {
for (wtf_size_t i = 0; i < video_tracks_.size(); i++) {
if (video_tracks_[i]->Component() != descriptor_->VideoComponent(i))
return false;
}
......@@ -285,7 +283,7 @@ void MediaStream::removeTrack(MediaStreamTrack* track,
return;
}
size_t pos = kNotFound;
wtf_size_t pos = kNotFound;
switch (track->Component()->Source()->GetType()) {
case MediaStreamSource::kTypeAudio:
pos = audio_tracks_.Find(track);
......@@ -421,8 +419,8 @@ void MediaStream::RemoveTrackByComponentAndFireEvents(
break;
}
size_t index = kNotFound;
for (size_t i = 0; i < tracks->size(); ++i) {
wtf_size_t index = kNotFound;
for (wtf_size_t i = 0; i < tracks->size(); ++i) {
if ((*tracks)[i]->Component() == component) {
index = i;
break;
......
......@@ -84,10 +84,10 @@ SkBitmap NotificationImageLoader::ScaleDownIfNeeded(const SkBitmap& image,
static_cast<double>(max_height_px) / image.height());
TimeTicks start_time = CurrentTimeTicks();
// TODO(peter): Try using RESIZE_BETTER for large images.
SkBitmap scaled_image =
skia::ImageOperations::Resize(image, skia::ImageOperations::RESIZE_BEST,
std::lround(scale * image.width()),
std::lround(scale * image.height()));
SkBitmap scaled_image = skia::ImageOperations::Resize(
image, skia::ImageOperations::RESIZE_BEST,
static_cast<int>(std::lround(scale * image.width())),
static_cast<int>(std::lround(scale * image.height())));
NOTIFICATION_HISTOGRAM_COUNTS(
LoadScaleDownTime, type,
base::saturated_cast<base::HistogramBase::Sample>(
......@@ -155,8 +155,10 @@ void NotificationImageLoader::DidFinishLoading(
1000 * 60 * 60 /* 1 hour max */);
if (data_) {
NOTIFICATION_HISTOGRAM_COUNTS(LoadFileSize, type_, data_->size(),
10000000 /* ~10mb max */);
NOTIFICATION_HISTOGRAM_COUNTS(
LoadFileSize, type_,
base::saturated_cast<base::HistogramBase::Sample>(data_->size()),
10000000 /* ~10mb max */);
const bool data_complete = true;
std::unique_ptr<ImageDecoder> decoder = ImageDecoder::Create(
......
......@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/modules/notifications/notification_manager.h"
#include "base/numerics/safe_conversions.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/mojom/notifications/notification.mojom-blink.h"
#include "third_party/blink/public/platform/interface_provider.h"
......@@ -155,7 +156,8 @@ void NotificationManager::DisplayPersistentNotification(
DEFINE_THREAD_SAFE_STATIC_LOCAL(
CustomCountHistogram, notification_data_size_histogram,
("Notifications.AuthorDataSize", 1, 1000, 50));
notification_data_size_histogram.Count(author_data_size);
notification_data_size_histogram.Count(
base::saturated_cast<base::HistogramBase::Sample>(author_data_size));
if (author_data_size >
mojom::blink::NotificationData::kMaximumDeveloperDataSize) {
......@@ -210,7 +212,7 @@ void NotificationManager::DidGetNotifications(
HeapVector<Member<Notification>> notifications;
notifications.ReserveInitialCapacity(notification_ids.size());
for (size_t i = 0; i < notification_ids.size(); ++i) {
for (wtf_size_t i = 0; i < notification_ids.size(); ++i) {
notifications.push_back(Notification::Create(
resolver->GetExecutionContext(), notification_ids[i],
std::move(notification_datas[i]), true /* showing */));
......
......@@ -29,9 +29,9 @@ void NotificationResourcesLoader::Start(
DCHECK(!started_);
started_ = true;
size_t num_actions = notification_data.actions.has_value()
? notification_data.actions->size()
: 0;
wtf_size_t num_actions = notification_data.actions.has_value()
? notification_data.actions->size()
: 0;
pending_request_count_ = 3 /* image, icon, badge */ + num_actions;
// TODO(johnme): ensure image is not loaded when it will not be used.
......@@ -50,7 +50,7 @@ void NotificationResourcesLoader::Start(
WrapWeakPersistent(this)));
action_icons_.resize(num_actions);
for (size_t i = 0; i < num_actions; i++)
for (wtf_size_t i = 0; i < num_actions; i++)
LoadImage(context, NotificationImageLoader::Type::kActionIcon,
notification_data.actions.value()[i]->icon,
WTF::Bind(&NotificationResourcesLoader::DidLoadActionIcon,
......@@ -109,7 +109,7 @@ void NotificationResourcesLoader::DidLoadBadge(const SkBitmap& image) {
DidFinishRequest();
}
void NotificationResourcesLoader::DidLoadActionIcon(size_t action_index,
void NotificationResourcesLoader::DidLoadActionIcon(wtf_size_t action_index,
const SkBitmap& image) {
DCHECK_LT(action_index, action_icons_.size());
......
......@@ -63,7 +63,7 @@ class MODULES_EXPORT NotificationResourcesLoader final
void DidLoadImage(const SkBitmap& image);
void DidLoadIcon(const SkBitmap& image);
void DidLoadBadge(const SkBitmap& image);
void DidLoadActionIcon(size_t action_index, const SkBitmap& image);
void DidLoadActionIcon(wtf_size_t action_index, const SkBitmap& image);
// Decrements |m_pendingRequestCount| and runs |m_completionCallback| if
// there are no more pending requests.
......
......@@ -37,6 +37,7 @@
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_peer_connection.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink {
......@@ -164,7 +165,7 @@ String RTCDataChannel::readyState() const {
}
unsigned RTCDataChannel::bufferedAmount() const {
return handler_->BufferedAmount();
return SafeCast<unsigned>(handler_->BufferedAmount());
}
unsigned RTCDataChannel::bufferedAmountLowThreshold() const {
......@@ -285,7 +286,8 @@ void RTCDataChannel::DidReceiveRawData(const char* data, size_t data_length) {
return;
}
if (binary_type_ == kBinaryTypeArrayBuffer) {
DOMArrayBuffer* buffer = DOMArrayBuffer::Create(data, data_length);
DOMArrayBuffer* buffer =
DOMArrayBuffer::Create(data, SafeCast<unsigned>(data_length));
ScheduleDispatchEvent(MessageEvent::Create(buffer));
return;
}
......
......@@ -64,7 +64,8 @@ class MockHandler final : public WebRTCDataChannelHandler {
unsigned long old_buffered_amount = buffered_amount_;
buffered_amount_ -= bytes;
if (client_) {
client_->DidDecreaseBufferedAmount(old_buffered_amount);
client_->DidDecreaseBufferedAmount(
static_cast<unsigned>(old_buffered_amount));
}
}
......
......@@ -113,6 +113,7 @@
#include "third_party/blink/renderer/platform/peerconnection/rtc_answer_options_platform.h"
#include "third_party/blink/renderer/platform/peerconnection/rtc_offer_options_platform.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/time.h"
#include "third_party/webrtc/api/jsep.h"
#include "third_party/webrtc/api/peerconnectioninterface.h"
......@@ -404,7 +405,7 @@ webrtc::PeerConnectionInterface::RTCConfiguration ParseConfiguration(
configuration.certificates();
std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates_copy(
certificates.size());
for (size_t i = 0; i < certificates.size(); ++i) {
for (wtf_size_t i = 0; i < certificates.size(); ++i) {
certificates_copy[i] = certificates[i]->Certificate();
}
web_configuration.certificates = std::move(certificates_copy);
......@@ -461,22 +462,24 @@ bool FingerprintMismatch(String old_sdp, String new_sdp) {
// It's impossible to generate a valid fingerprint without createOffer
// or createAnswer, so this only applies when there are no fingerprints.
// This is allowed.
const size_t new_fingerprint_pos = new_sdp.Find("\na=fingerprint:");
const wtf_size_t new_fingerprint_pos = new_sdp.Find("\na=fingerprint:");
if (new_fingerprint_pos == kNotFound) {
return false;
}
// Look for fingerprint having been added. Not allowed.
const size_t old_fingerprint_pos = old_sdp.Find("\na=fingerprint:");
const wtf_size_t old_fingerprint_pos = old_sdp.Find("\na=fingerprint:");
if (old_fingerprint_pos == kNotFound) {
return true;
}
// Look for fingerprint being modified. Not allowed. Handle differences in
// line endings ('\r\n' vs, '\n' when looking for the end of the fingerprint).
size_t old_fingerprint_end = old_sdp.Find("\r\n", old_fingerprint_pos + 1);
wtf_size_t old_fingerprint_end =
old_sdp.Find("\r\n", old_fingerprint_pos + 1);
if (old_fingerprint_end == WTF::kNotFound) {
old_fingerprint_end = old_sdp.Find("\n", old_fingerprint_pos + 1);
}
size_t new_fingerprint_end = new_sdp.Find("\r\n", new_fingerprint_pos + 1);
wtf_size_t new_fingerprint_end =
new_sdp.Find("\r\n", new_fingerprint_pos + 1);
if (new_fingerprint_end == WTF::kNotFound) {
new_fingerprint_end = new_sdp.Find("\n", new_fingerprint_pos + 1);
}
......@@ -1116,14 +1119,15 @@ void RTCPeerConnection::getConfiguration(RTCConfiguration& result) {
}
HeapVector<RTCIceServer> ice_servers;
ice_servers.ReserveCapacity(webrtc_configuration.servers.size());
ice_servers.ReserveCapacity(
SafeCast<wtf_size_t>(webrtc_configuration.servers.size()));
for (const auto& webrtc_server : webrtc_configuration.servers) {
ice_servers.emplace_back();
auto& ice_server = ice_servers.back();
StringOrStringSequence urls;
Vector<String> url_vector;
url_vector.ReserveCapacity(webrtc_server.urls.size());
url_vector.ReserveCapacity(SafeCast<wtf_size_t>(webrtc_server.urls.size()));
for (const auto& url : webrtc_server.urls) {
url_vector.emplace_back(url.c_str());
}
......@@ -1137,7 +1141,8 @@ void RTCPeerConnection::getConfiguration(RTCConfiguration& result) {
if (!webrtc_configuration.certificates.empty()) {
HeapVector<blink::Member<RTCCertificate>> certificates;
certificates.ReserveCapacity(webrtc_configuration.certificates.size());
certificates.ReserveCapacity(
SafeCast<wtf_size_t>(webrtc_configuration.certificates.size()));
for (const auto& webrtc_certificate : webrtc_configuration.certificates) {
certificates.emplace_back(new RTCCertificate(webrtc_certificate));
}
......@@ -1761,7 +1766,7 @@ RTCRtpSender* RTCPeerConnection::addTrack(MediaStreamTrack* track,
}
WebVector<WebMediaStream> web_streams(streams.size());
for (size_t i = 0; i < streams.size(); ++i) {
for (wtf_size_t i = 0; i < streams.size(); ++i) {
web_streams[i] = streams[i]->Descriptor();
}
webrtc::RTCErrorOr<std::unique_ptr<WebRTCRtpTransceiver>>
......
......@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/modules/peerconnection/rtc_rtp_capabilities.h"
#include "third_party/blink/renderer/modules/peerconnection/web_rtc_stats_report_callback_resolver.h"
#include "third_party/blink/renderer/platform/bindings/microtask.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/webrtc/api/rtpparameters.h"
......@@ -106,7 +107,8 @@ void RTCRtpReceiver::getCapabilities(
blink::Platform::Current()->GetRtpSenderCapabilities(kind);
HeapVector<RTCRtpCodecCapability> codecs;
codecs.ReserveInitialCapacity(rtc_capabilities->codecs.size());
codecs.ReserveInitialCapacity(
SafeCast<wtf_size_t>(rtc_capabilities->codecs.size()));
for (const auto& rtc_codec : rtc_capabilities->codecs) {
codecs.emplace_back();
auto& codec = codecs.back();
......@@ -129,7 +131,7 @@ void RTCRtpReceiver::getCapabilities(
HeapVector<RTCRtpHeaderExtensionCapability> header_extensions;
header_extensions.ReserveInitialCapacity(
rtc_capabilities->header_extensions.size());
SafeCast<wtf_size_t>(rtc_capabilities->header_extensions.size()));
for (const auto& rtc_header_extension : rtc_capabilities->header_extensions) {
header_extensions.emplace_back();
auto& header_extension = header_extensions.back();
......
......@@ -17,6 +17,7 @@
#include "third_party/blink/renderer/modules/peerconnection/web_rtc_stats_report_callback_resolver.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/peerconnection/rtc_void_request.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink {
......@@ -107,7 +108,7 @@ bool HasInvalidModification(const RTCRtpSendParameters& parameters,
new_parameters.headerExtensions().size())
return true;
for (size_t i = 0; i < parameters.headerExtensions().size(); ++i) {
for (wtf_size_t i = 0; i < parameters.headerExtensions().size(); ++i) {
const auto& header_extension = parameters.headerExtensions()[i];
const auto& new_header_extension = new_parameters.headerExtensions()[i];
if (header_extension.hasUri() != new_header_extension.hasUri() ||
......@@ -145,7 +146,7 @@ bool HasInvalidModification(const RTCRtpSendParameters& parameters,
if (parameters.codecs().size() != new_parameters.codecs().size())
return true;
for (std::size_t i = 0; i < parameters.codecs().size(); ++i) {
for (wtf_size_t i = 0; i < parameters.codecs().size(); ++i) {
const auto& codec = parameters.codecs()[i];
const auto& new_codec = new_parameters.codecs()[i];
if (codec.hasPayloadType() != new_codec.hasPayloadType() ||
......@@ -300,7 +301,8 @@ void RTCRtpSender::getParameters(RTCRtpSendParameters& parameters) {
parameters.setRtcp(rtcp);
HeapVector<RTCRtpEncodingParameters> encodings;
encodings.ReserveCapacity(webrtc_parameters->encodings.size());
encodings.ReserveCapacity(
SafeCast<wtf_size_t>(webrtc_parameters->encodings.size()));
for (const auto& web_encoding : webrtc_parameters->encodings) {
// TODO(orphis): Forward missing fields from the WebRTC library:
// codecPayloadType, dtx, ptime, maxFramerate, scaleResolutionDownBy, rid
......@@ -315,7 +317,8 @@ void RTCRtpSender::getParameters(RTCRtpSendParameters& parameters) {
parameters.setEncodings(encodings);
HeapVector<RTCRtpHeaderExtensionParameters> headers;
headers.ReserveCapacity(webrtc_parameters->header_extensions.size());
headers.ReserveCapacity(
SafeCast<wtf_size_t>(webrtc_parameters->header_extensions.size()));
for (const auto& web_header : webrtc_parameters->header_extensions) {
headers.emplace_back();
RTCRtpHeaderExtensionParameters& header = headers.back();
......@@ -326,7 +329,8 @@ void RTCRtpSender::getParameters(RTCRtpSendParameters& parameters) {
parameters.setHeaderExtensions(headers);
HeapVector<RTCRtpCodecParameters> codecs;
codecs.ReserveCapacity(webrtc_parameters->codecs.size());
codecs.ReserveCapacity(
SafeCast<wtf_size_t>(webrtc_parameters->codecs.size()));
for (const auto& web_codec : webrtc_parameters->codecs) {
codecs.emplace_back();
RTCRtpCodecParameters& codec = codecs.back();
......@@ -459,7 +463,8 @@ void RTCRtpSender::getCapabilities(
blink::Platform::Current()->GetRtpSenderCapabilities(kind);
HeapVector<RTCRtpCodecCapability> codecs;
codecs.ReserveInitialCapacity(rtc_capabilities->codecs.size());
codecs.ReserveInitialCapacity(
SafeCast<wtf_size_t>(rtc_capabilities->codecs.size()));
for (const auto& rtc_codec : rtc_capabilities->codecs) {
codecs.emplace_back();
auto& codec = codecs.back();
......@@ -482,7 +487,7 @@ void RTCRtpSender::getCapabilities(
HeapVector<RTCRtpHeaderExtensionCapability> header_extensions;
header_extensions.ReserveInitialCapacity(
rtc_capabilities->header_extensions.size());
SafeCast<wtf_size_t>(rtc_capabilities->header_extensions.size()));
for (const auto& rtc_header_extension : rtc_capabilities->header_extensions) {
header_extensions.emplace_back();
auto& header_extension = header_extensions.back();
......
......@@ -116,6 +116,10 @@ class RTCStatsReportIterationSource final
RTCStatsReport::RTCStatsReport(std::unique_ptr<WebRTCStatsReport> report)
: report_(std::move(report)) {}
uint32_t RTCStatsReport::size() const {
return base::saturated_cast<uint32_t>(report_->Size());
}
PairIterable<String, v8::Local<v8::Value>>::IterationSource*
RTCStatsReport::StartIteration(ScriptState*, ExceptionState&) {
return new RTCStatsReportIterationSource(report_->CopyHandle());
......
......@@ -23,7 +23,7 @@ class RTCStatsReport final : public ScriptWrappable,
public:
RTCStatsReport(std::unique_ptr<WebRTCStatsReport>);
size_t size() const { return report_->Size(); }
uint32_t size() const;
// Maplike<String, v8::Local<v8::Value>>
PairIterable<String, v8::Local<v8::Value>>::IterationSource* StartIteration(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment