Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2006 The Android Open Source Project |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | #include "SkAnimateMaker.h" |
michael@0 | 11 | #include "SkAnimator.h" |
michael@0 | 12 | #include "SkAnimatorScript.h" |
michael@0 | 13 | #include "SkDisplayable.h" |
michael@0 | 14 | #include "SkDisplayApply.h" |
michael@0 | 15 | #include "SkDisplayList.h" |
michael@0 | 16 | #include "SkDisplayMovie.h" |
michael@0 | 17 | #include "SkDisplayType.h" |
michael@0 | 18 | #include "SkExtras.h" |
michael@0 | 19 | #include "SkMemberInfo.h" |
michael@0 | 20 | #include "SkStream.h" |
michael@0 | 21 | #include "SkSystemEventTypes.h" |
michael@0 | 22 | #include "SkTime.h" |
michael@0 | 23 | |
michael@0 | 24 | class DefaultTimeline : public SkAnimator::Timeline { |
michael@0 | 25 | virtual SkMSec getMSecs() const { |
michael@0 | 26 | return SkTime::GetMSecs(); |
michael@0 | 27 | } |
michael@0 | 28 | } gDefaultTimeline; |
michael@0 | 29 | |
michael@0 | 30 | SkAnimateMaker::SkAnimateMaker(SkAnimator* animator, SkCanvas* canvas, SkPaint* paint) |
michael@0 | 31 | : fActiveEvent(NULL), fAdjustedStart(0), fCanvas(canvas), fEnableTime(0), |
michael@0 | 32 | fHostEventSinkID(0), fMinimumInterval((SkMSec) -1), fPaint(paint), fParentMaker(NULL), |
michael@0 | 33 | fTimeline(&gDefaultTimeline), fInInclude(false), fInMovie(false), |
michael@0 | 34 | fFirstScriptError(false), fLoaded(false), fIDs(256), fAnimator(animator) |
michael@0 | 35 | { |
michael@0 | 36 | fScreenplay.time = 0; |
michael@0 | 37 | #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING |
michael@0 | 38 | fDebugTimeBase = (SkMSec) -1; |
michael@0 | 39 | #endif |
michael@0 | 40 | #ifdef SK_DUMP_ENABLED |
michael@0 | 41 | fDumpEvents = fDumpGConditions = fDumpPosts = false; |
michael@0 | 42 | #endif |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | SkAnimateMaker::~SkAnimateMaker() { |
michael@0 | 46 | deleteMembers(); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | #if 0 |
michael@0 | 50 | SkMSec SkAnimateMaker::adjustDelay(SkMSec expectedBase, SkMSec delay) { |
michael@0 | 51 | SkMSec appTime = (*fTimeCallBack)(); |
michael@0 | 52 | if (appTime) |
michael@0 | 53 | delay -= appTime - expectedBase; |
michael@0 | 54 | if (delay < 0) |
michael@0 | 55 | delay = 0; |
michael@0 | 56 | return delay; |
michael@0 | 57 | } |
michael@0 | 58 | #endif |
michael@0 | 59 | |
michael@0 | 60 | void SkAnimateMaker::appendActive(SkActive* active) { |
michael@0 | 61 | fDisplayList.append(active); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | void SkAnimateMaker::clearExtraPropertyCallBack(SkDisplayTypes type) { |
michael@0 | 65 | SkExtras** end = fExtras.end(); |
michael@0 | 66 | for (SkExtras** extraPtr = fExtras.begin(); extraPtr < end; extraPtr++) { |
michael@0 | 67 | SkExtras* extra = *extraPtr; |
michael@0 | 68 | if (extra->definesType(type)) { |
michael@0 | 69 | extra->fExtraCallBack = NULL; |
michael@0 | 70 | extra->fExtraStorage = NULL; |
michael@0 | 71 | break; |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | bool SkAnimateMaker::computeID(SkDisplayable* displayable, SkDisplayable* parent, SkString* newID) { |
michael@0 | 77 | const char* script; |
michael@0 | 78 | if (findKey(displayable, &script) == false) |
michael@0 | 79 | return true; |
michael@0 | 80 | return SkAnimatorScript::EvaluateString(*this, displayable, parent, script, newID); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | SkDisplayable* SkAnimateMaker::createInstance(const char name[], size_t len) { |
michael@0 | 84 | SkDisplayTypes type = SkDisplayType::GetType(this, name, len ); |
michael@0 | 85 | if ((int)type >= 0) |
michael@0 | 86 | return SkDisplayType::CreateInstance(this, type); |
michael@0 | 87 | return NULL; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | // differs from SkAnimator::decodeStream in that it does not reset error state |
michael@0 | 91 | bool SkAnimateMaker::decodeStream(SkStream* stream) |
michael@0 | 92 | { |
michael@0 | 93 | SkDisplayXMLParser parser(*this); |
michael@0 | 94 | return parser.parse(*stream); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | // differs from SkAnimator::decodeURI in that it does not set URI base |
michael@0 | 98 | bool SkAnimateMaker::decodeURI(const char uri[]) { |
michael@0 | 99 | // SkDebugf("animator decode %s\n", uri); |
michael@0 | 100 | |
michael@0 | 101 | // SkStream* stream = SkStream::GetURIStream(fPrefix.c_str(), uri); |
michael@0 | 102 | SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(uri)); |
michael@0 | 103 | if (stream.get()) { |
michael@0 | 104 | bool success = decodeStream(stream); |
michael@0 | 105 | if (hasError() && fError.hasNoun() == false) |
michael@0 | 106 | fError.setNoun(uri); |
michael@0 | 107 | return success; |
michael@0 | 108 | } else { |
michael@0 | 109 | return false; |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | #if defined SK_DEBUG && 0 |
michael@0 | 114 | //used for the if'd out section of deleteMembers |
michael@0 | 115 | #include "SkTSearch.h" |
michael@0 | 116 | |
michael@0 | 117 | extern "C" { |
michael@0 | 118 | int compare_disp(const void* a, const void* b) { |
michael@0 | 119 | return *(const SkDisplayable**)a - *(const SkDisplayable**)b; |
michael@0 | 120 | } |
michael@0 | 121 | } |
michael@0 | 122 | #endif |
michael@0 | 123 | |
michael@0 | 124 | void SkAnimateMaker::delayEnable(SkApply* apply, SkMSec time) { |
michael@0 | 125 | int index = fDelayed.find(apply); |
michael@0 | 126 | if (index < 0) { |
michael@0 | 127 | *fDelayed.append() = apply; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | (new SkEvent(SK_EventType_Delay, fAnimator->getSinkID()))->postTime(time); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | void SkAnimateMaker::deleteMembers() { |
michael@0 | 134 | int index; |
michael@0 | 135 | #if defined SK_DEBUG && 0 |
michael@0 | 136 | //this code checks to see if helpers are among the children, but it is not complete - |
michael@0 | 137 | //it should check the children of the children |
michael@0 | 138 | int result; |
michael@0 | 139 | SkTDArray<SkDisplayable*> children(fChildren.begin(), fChildren.count()); |
michael@0 | 140 | SkQSort(children.begin(), children.count(), sizeof(SkDisplayable*),compare_disp); |
michael@0 | 141 | for (index = 0; index < fHelpers.count(); index++) { |
michael@0 | 142 | SkDisplayable* helper = fHelpers[index]; |
michael@0 | 143 | result = SkTSearch(children.begin(), children.count(), helper, sizeof(SkDisplayable*)); |
michael@0 | 144 | SkASSERT(result < 0); |
michael@0 | 145 | } |
michael@0 | 146 | #endif |
michael@0 | 147 | for (index = 0; index < fChildren.count(); index++) { |
michael@0 | 148 | SkDisplayable* child = fChildren[index]; |
michael@0 | 149 | delete child; |
michael@0 | 150 | } |
michael@0 | 151 | for (index = 0; index < fHelpers.count(); index++) { |
michael@0 | 152 | SkDisplayable* helper = fHelpers[index]; |
michael@0 | 153 | delete helper; |
michael@0 | 154 | } |
michael@0 | 155 | for (index = 0; index < fExtras.count(); index++) { |
michael@0 | 156 | SkExtras* extras = fExtras[index]; |
michael@0 | 157 | delete extras; |
michael@0 | 158 | } |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | void SkAnimateMaker::doDelayedEvent() { |
michael@0 | 162 | fEnableTime = getAppTime(); |
michael@0 | 163 | for (int index = 0; index < fDelayed.count(); ) { |
michael@0 | 164 | SkDisplayable* child = fDelayed[index]; |
michael@0 | 165 | SkASSERT(child->isApply()); |
michael@0 | 166 | SkApply* apply = (SkApply*) child; |
michael@0 | 167 | apply->interpolate(*this, fEnableTime); |
michael@0 | 168 | if (apply->hasDelayedAnimator()) |
michael@0 | 169 | index++; |
michael@0 | 170 | else |
michael@0 | 171 | fDelayed.remove(index); |
michael@0 | 172 | } |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | bool SkAnimateMaker::doEvent(const SkEvent& event) { |
michael@0 | 176 | return (!fInMovie || fLoaded) && fAnimator->doEvent(event); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | #ifdef SK_DUMP_ENABLED |
michael@0 | 180 | void SkAnimateMaker::dump(const char* match) { |
michael@0 | 181 | SkTDict<SkDisplayable*>::Iter iter(fIDs); |
michael@0 | 182 | const char* name; |
michael@0 | 183 | SkDisplayable* result; |
michael@0 | 184 | while ((name = iter.next(&result)) != NULL) { |
michael@0 | 185 | if (strcmp(match,name) == 0) |
michael@0 | 186 | result->dump(this); |
michael@0 | 187 | } |
michael@0 | 188 | } |
michael@0 | 189 | #endif |
michael@0 | 190 | |
michael@0 | 191 | int SkAnimateMaker::dynamicProperty(SkString& nameStr, SkDisplayable** displayablePtr ) { |
michael@0 | 192 | const char* name = nameStr.c_str(); |
michael@0 | 193 | const char* dot = strchr(name, '.'); |
michael@0 | 194 | SkASSERT(dot); |
michael@0 | 195 | SkDisplayable* displayable; |
michael@0 | 196 | if (find(name, dot - name, &displayable) == false) { |
michael@0 | 197 | SkASSERT(0); |
michael@0 | 198 | return 0; |
michael@0 | 199 | } |
michael@0 | 200 | const char* fieldName = dot + 1; |
michael@0 | 201 | const SkMemberInfo* memberInfo = displayable->getMember(fieldName); |
michael@0 | 202 | *displayablePtr = displayable; |
michael@0 | 203 | return (int) memberInfo->fOffset; |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | SkMSec SkAnimateMaker::getAppTime() const { |
michael@0 | 207 | return fTimeline->getMSecs(); |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | #ifdef SK_DEBUG |
michael@0 | 211 | SkAnimator* SkAnimateMaker::getRoot() |
michael@0 | 212 | { |
michael@0 | 213 | SkAnimateMaker* maker = this; |
michael@0 | 214 | while (maker->fParentMaker) |
michael@0 | 215 | maker = maker->fParentMaker; |
michael@0 | 216 | return maker == this ? NULL : maker->fAnimator; |
michael@0 | 217 | } |
michael@0 | 218 | #endif |
michael@0 | 219 | |
michael@0 | 220 | void SkAnimateMaker::helperAdd(SkDisplayable* trackMe) { |
michael@0 | 221 | SkASSERT(fHelpers.find(trackMe) < 0); |
michael@0 | 222 | *fHelpers.append() = trackMe; |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | void SkAnimateMaker::helperRemove(SkDisplayable* alreadyTracked) { |
michael@0 | 226 | int helperIndex = fHelpers.find(alreadyTracked); |
michael@0 | 227 | if (helperIndex >= 0) |
michael@0 | 228 | fHelpers.remove(helperIndex); |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | #if 0 |
michael@0 | 232 | void SkAnimateMaker::loadMovies() { |
michael@0 | 233 | for (SkDisplayable** dispPtr = fMovies.begin(); dispPtr < fMovies.end(); dispPtr++) { |
michael@0 | 234 | SkDisplayable* displayable = *dispPtr; |
michael@0 | 235 | SkASSERT(displayable->getType() == SkType_Movie); |
michael@0 | 236 | SkDisplayMovie* movie = (SkDisplayMovie*) displayable; |
michael@0 | 237 | SkAnimateMaker* movieMaker = movie->fMovie.fMaker; |
michael@0 | 238 | movieMaker->fEvents.doEvent(*movieMaker, SkDisplayEvent::kOnload, NULL); |
michael@0 | 239 | movieMaker->fEvents.removeEvent(SkDisplayEvent::kOnload, NULL); |
michael@0 | 240 | movieMaker->loadMovies(); |
michael@0 | 241 | } |
michael@0 | 242 | } |
michael@0 | 243 | #endif |
michael@0 | 244 | |
michael@0 | 245 | void SkAnimateMaker::notifyInval() { |
michael@0 | 246 | if (fHostEventSinkID) |
michael@0 | 247 | fAnimator->onEventPost(new SkEvent(SK_EventType_Inval), fHostEventSinkID); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | void SkAnimateMaker::notifyInvalTime(SkMSec time) { |
michael@0 | 251 | if (fHostEventSinkID) |
michael@0 | 252 | fAnimator->onEventPostTime(new SkEvent(SK_EventType_Inval), fHostEventSinkID, time); |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | void SkAnimateMaker::postOnEnd(SkAnimateBase* animate, SkMSec end) { |
michael@0 | 256 | SkEvent evt; |
michael@0 | 257 | evt.setS32("time", animate->getStart() + end); |
michael@0 | 258 | evt.setPtr("anim", animate); |
michael@0 | 259 | evt.setType(SK_EventType_OnEnd); |
michael@0 | 260 | SkEventSinkID sinkID = fAnimator->getSinkID(); |
michael@0 | 261 | fAnimator->onEventPost(new SkEvent(evt), sinkID); |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | void SkAnimateMaker::reset() { |
michael@0 | 265 | deleteMembers(); |
michael@0 | 266 | fChildren.reset(); |
michael@0 | 267 | fHelpers.reset(); |
michael@0 | 268 | fIDs.reset(); |
michael@0 | 269 | fEvents.reset(); |
michael@0 | 270 | fDisplayList.hardReset(); |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | void SkAnimateMaker::removeActive(SkActive* active) { |
michael@0 | 274 | if (active == NULL) |
michael@0 | 275 | return; |
michael@0 | 276 | fDisplayList.remove(active); |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | bool SkAnimateMaker::resolveID(SkDisplayable* displayable, SkDisplayable* original) { |
michael@0 | 280 | SkString newID; |
michael@0 | 281 | bool success = computeID(original, NULL, &newID); |
michael@0 | 282 | if (success) |
michael@0 | 283 | setID(displayable, newID); |
michael@0 | 284 | return success; |
michael@0 | 285 | } |
michael@0 | 286 | |
michael@0 | 287 | void SkAnimateMaker::setErrorString() { |
michael@0 | 288 | fErrorString.reset(); |
michael@0 | 289 | if (fError.hasError()) { |
michael@0 | 290 | SkString err; |
michael@0 | 291 | if (fFileName.size() > 0) |
michael@0 | 292 | fErrorString.set(fFileName.c_str()); |
michael@0 | 293 | else |
michael@0 | 294 | fErrorString.set("screenplay error"); |
michael@0 | 295 | int line = fError.getLineNumber(); |
michael@0 | 296 | if (line >= 0) { |
michael@0 | 297 | fErrorString.append(", "); |
michael@0 | 298 | fErrorString.append("line "); |
michael@0 | 299 | fErrorString.appendS32(line); |
michael@0 | 300 | } |
michael@0 | 301 | fErrorString.append(": "); |
michael@0 | 302 | fError.getErrorString(&err); |
michael@0 | 303 | fErrorString.append(err); |
michael@0 | 304 | #if defined SK_DEBUG |
michael@0 | 305 | SkDebugf("%s\n", fErrorString.c_str()); |
michael@0 | 306 | #endif |
michael@0 | 307 | } |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | void SkAnimateMaker::setEnableTime(SkMSec appTime, SkMSec expectedTime) { |
michael@0 | 311 | #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING |
michael@0 | 312 | SkString debugOut; |
michael@0 | 313 | SkMSec time = getAppTime(); |
michael@0 | 314 | debugOut.appendS32(time - fDebugTimeBase); |
michael@0 | 315 | debugOut.append(" set enable old enable="); |
michael@0 | 316 | debugOut.appendS32(fEnableTime - fDebugTimeBase); |
michael@0 | 317 | debugOut.append(" old adjust="); |
michael@0 | 318 | debugOut.appendS32(fAdjustedStart); |
michael@0 | 319 | debugOut.append(" new enable="); |
michael@0 | 320 | debugOut.appendS32(expectedTime - fDebugTimeBase); |
michael@0 | 321 | debugOut.append(" new adjust="); |
michael@0 | 322 | debugOut.appendS32(appTime - expectedTime); |
michael@0 | 323 | SkDebugf("%s\n", debugOut.c_str()); |
michael@0 | 324 | #endif |
michael@0 | 325 | fAdjustedStart = appTime - expectedTime; |
michael@0 | 326 | fEnableTime = expectedTime; |
michael@0 | 327 | SkDisplayable** firstMovie = fMovies.begin(); |
michael@0 | 328 | SkDisplayable** endMovie = fMovies.end(); |
michael@0 | 329 | for (SkDisplayable** ptr = firstMovie; ptr < endMovie; ptr++) { |
michael@0 | 330 | SkDisplayMovie* movie = (SkDisplayMovie*) *ptr; |
michael@0 | 331 | movie->fMovie.fMaker->setEnableTime(appTime, expectedTime); |
michael@0 | 332 | } |
michael@0 | 333 | } |
michael@0 | 334 | |
michael@0 | 335 | void SkAnimateMaker::setExtraPropertyCallBack(SkDisplayTypes type, |
michael@0 | 336 | SkScriptEngine::_propertyCallBack callBack, void* userStorage) { |
michael@0 | 337 | SkExtras** end = fExtras.end(); |
michael@0 | 338 | for (SkExtras** extraPtr = fExtras.begin(); extraPtr < end; extraPtr++) { |
michael@0 | 339 | SkExtras* extra = *extraPtr; |
michael@0 | 340 | if (extra->definesType(type)) { |
michael@0 | 341 | extra->fExtraCallBack = callBack; |
michael@0 | 342 | extra->fExtraStorage = userStorage; |
michael@0 | 343 | break; |
michael@0 | 344 | } |
michael@0 | 345 | } |
michael@0 | 346 | } |
michael@0 | 347 | |
michael@0 | 348 | void SkAnimateMaker::setID(SkDisplayable* displayable, const SkString& newID) { |
michael@0 | 349 | fIDs.set(newID.c_str(), displayable); |
michael@0 | 350 | #ifdef SK_DEBUG |
michael@0 | 351 | displayable->_id.set(newID); |
michael@0 | 352 | displayable->id = displayable->_id.c_str(); |
michael@0 | 353 | #endif |
michael@0 | 354 | } |
michael@0 | 355 | |
michael@0 | 356 | void SkAnimateMaker::setScriptError(const SkScriptEngine& engine) { |
michael@0 | 357 | SkString errorString; |
michael@0 | 358 | #ifdef SK_DEBUG |
michael@0 | 359 | engine.getErrorString(&errorString); |
michael@0 | 360 | #endif |
michael@0 | 361 | setErrorNoun(errorString); |
michael@0 | 362 | setErrorCode(SkDisplayXMLParserError::kErrorInScript); |
michael@0 | 363 | } |
michael@0 | 364 | |
michael@0 | 365 | bool SkAnimateMaker::GetStep(const char* token, size_t len, void* stepPtr, SkScriptValue* value) { |
michael@0 | 366 | if (SK_LITERAL_STR_EQUAL("step", token, len)) { |
michael@0 | 367 | value->fOperand.fS32 = *(int32_t*) stepPtr; |
michael@0 | 368 | value->fType = SkType_Int; |
michael@0 | 369 | return true; |
michael@0 | 370 | } |
michael@0 | 371 | return false; |
michael@0 | 372 | } |