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 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "SkLuaCanvas.h" |
michael@0 | 9 | #include "SkLua.h" |
michael@0 | 10 | |
michael@0 | 11 | extern "C" { |
michael@0 | 12 | #include "lua.h" |
michael@0 | 13 | #include "lauxlib.h" |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | class AutoCallLua : public SkLua { |
michael@0 | 17 | public: |
michael@0 | 18 | AutoCallLua(lua_State* L, const char func[], const char verb[]) : INHERITED(L) { |
michael@0 | 19 | lua_getglobal(L, func); |
michael@0 | 20 | if (!lua_isfunction(L, -1)) { |
michael@0 | 21 | int t = lua_type(L, -1); |
michael@0 | 22 | SkDebugf("--- expected function %d\n", t); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | lua_newtable(L); |
michael@0 | 26 | this->pushString(verb, "verb"); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | ~AutoCallLua() { |
michael@0 | 30 | lua_State* L = this->get(); |
michael@0 | 31 | if (lua_pcall(L, 1, 0, 0) != LUA_OK) { |
michael@0 | 32 | SkDebugf("lua err: %s\n", lua_tostring(L, -1)); |
michael@0 | 33 | } |
michael@0 | 34 | lua_settop(L, -1); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | void pushEncodedText(SkPaint::TextEncoding, const void*, size_t); |
michael@0 | 38 | |
michael@0 | 39 | private: |
michael@0 | 40 | typedef SkLua INHERITED; |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | #define AUTO_LUA(verb) AutoCallLua lua(fL, fFunc.c_str(), verb) |
michael@0 | 44 | |
michael@0 | 45 | |
michael@0 | 46 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 47 | |
michael@0 | 48 | void AutoCallLua::pushEncodedText(SkPaint::TextEncoding enc, const void* text, |
michael@0 | 49 | size_t length) { |
michael@0 | 50 | switch (enc) { |
michael@0 | 51 | case SkPaint::kUTF8_TextEncoding: |
michael@0 | 52 | this->pushString((const char*)text, length, "text"); |
michael@0 | 53 | break; |
michael@0 | 54 | case SkPaint::kUTF16_TextEncoding: { |
michael@0 | 55 | SkString str; |
michael@0 | 56 | str.setUTF16((const uint16_t*)text, length); |
michael@0 | 57 | this->pushString(str, "text"); |
michael@0 | 58 | } break; |
michael@0 | 59 | case SkPaint::kGlyphID_TextEncoding: |
michael@0 | 60 | this->pushArrayU16((const uint16_t*)text, SkToInt(length >> 1), |
michael@0 | 61 | "glyphs"); |
michael@0 | 62 | break; |
michael@0 | 63 | case SkPaint::kUTF32_TextEncoding: |
michael@0 | 64 | break; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 69 | |
michael@0 | 70 | void SkLuaCanvas::pushThis() { |
michael@0 | 71 | SkLua(fL).pushCanvas(this); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 75 | |
michael@0 | 76 | SkLuaCanvas::SkLuaCanvas(int width, int height, lua_State* L, const char func[]) |
michael@0 | 77 | : INHERITED(width, height) |
michael@0 | 78 | , fL(L) |
michael@0 | 79 | , fFunc(func) { |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | SkLuaCanvas::~SkLuaCanvas() {} |
michael@0 | 83 | |
michael@0 | 84 | void SkLuaCanvas::willSave(SaveFlags flags) { |
michael@0 | 85 | AUTO_LUA("save"); |
michael@0 | 86 | this->INHERITED::willSave(flags); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | SkCanvas::SaveLayerStrategy SkLuaCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, |
michael@0 | 90 | SaveFlags flags) { |
michael@0 | 91 | AUTO_LUA("saveLayer"); |
michael@0 | 92 | if (bounds) { |
michael@0 | 93 | lua.pushRect(*bounds, "bounds"); |
michael@0 | 94 | } |
michael@0 | 95 | if (paint) { |
michael@0 | 96 | lua.pushPaint(*paint, "paint"); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | this->INHERITED::willSaveLayer(bounds, paint, flags); |
michael@0 | 100 | // No need for a layer. |
michael@0 | 101 | return kNoLayer_SaveLayerStrategy; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | void SkLuaCanvas::willRestore() { |
michael@0 | 105 | AUTO_LUA("restore"); |
michael@0 | 106 | this->INHERITED::willRestore(); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | void SkLuaCanvas::didTranslate(SkScalar dx, SkScalar dy) { |
michael@0 | 110 | AUTO_LUA("translate"); |
michael@0 | 111 | lua.pushScalar(dx, "dx"); |
michael@0 | 112 | lua.pushScalar(dy, "dy"); |
michael@0 | 113 | this->INHERITED::didTranslate(dx, dy); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | void SkLuaCanvas::didScale(SkScalar sx, SkScalar sy) { |
michael@0 | 117 | AUTO_LUA("scale"); |
michael@0 | 118 | lua.pushScalar(sx, "sx"); |
michael@0 | 119 | lua.pushScalar(sy, "sy"); |
michael@0 | 120 | this->INHERITED::didScale(sx, sy); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | void SkLuaCanvas::didRotate(SkScalar degrees) { |
michael@0 | 124 | AUTO_LUA("rotate"); |
michael@0 | 125 | lua.pushScalar(degrees, "degrees"); |
michael@0 | 126 | this->INHERITED::didRotate(degrees); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | void SkLuaCanvas::didSkew(SkScalar kx, SkScalar ky) { |
michael@0 | 130 | AUTO_LUA("skew"); |
michael@0 | 131 | lua.pushScalar(kx, "kx"); |
michael@0 | 132 | lua.pushScalar(ky, "ky"); |
michael@0 | 133 | this->INHERITED::didSkew(kx, ky); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | void SkLuaCanvas::didConcat(const SkMatrix& matrix) { |
michael@0 | 137 | AUTO_LUA("concat"); |
michael@0 | 138 | this->INHERITED::didConcat(matrix); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | void SkLuaCanvas::didSetMatrix(const SkMatrix& matrix) { |
michael@0 | 142 | this->INHERITED::didSetMatrix(matrix); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | void SkLuaCanvas::onClipRect(const SkRect& r, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
michael@0 | 146 | AUTO_LUA("clipRect"); |
michael@0 | 147 | lua.pushRect(r, "rect"); |
michael@0 | 148 | lua.pushBool(kSoft_ClipEdgeStyle == edgeStyle, "aa"); |
michael@0 | 149 | this->INHERITED::onClipRect(r, op, edgeStyle); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | void SkLuaCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
michael@0 | 153 | AUTO_LUA("clipRRect"); |
michael@0 | 154 | lua.pushRRect(rrect, "rrect"); |
michael@0 | 155 | lua.pushBool(kSoft_ClipEdgeStyle == edgeStyle, "aa"); |
michael@0 | 156 | this->INHERITED::onClipRRect(rrect, op, edgeStyle); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | void SkLuaCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
michael@0 | 160 | AUTO_LUA("clipPath"); |
michael@0 | 161 | lua.pushPath(path, "path"); |
michael@0 | 162 | lua.pushBool(kSoft_ClipEdgeStyle == edgeStyle, "aa"); |
michael@0 | 163 | this->INHERITED::onClipPath(path, op, edgeStyle); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | void SkLuaCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
michael@0 | 167 | AUTO_LUA("clipRegion"); |
michael@0 | 168 | this->INHERITED::onClipRegion(deviceRgn, op); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | void SkLuaCanvas::drawPaint(const SkPaint& paint) { |
michael@0 | 172 | AUTO_LUA("drawPaint"); |
michael@0 | 173 | lua.pushPaint(paint, "paint"); |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | void SkLuaCanvas::drawPoints(PointMode mode, size_t count, |
michael@0 | 177 | const SkPoint pts[], const SkPaint& paint) { |
michael@0 | 178 | AUTO_LUA("drawPoints"); |
michael@0 | 179 | lua.pushPaint(paint, "paint"); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | void SkLuaCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { |
michael@0 | 183 | AUTO_LUA("drawOval"); |
michael@0 | 184 | lua.pushRect(rect, "rect"); |
michael@0 | 185 | lua.pushPaint(paint, "paint"); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | void SkLuaCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
michael@0 | 189 | AUTO_LUA("drawRect"); |
michael@0 | 190 | lua.pushRect(rect, "rect"); |
michael@0 | 191 | lua.pushPaint(paint, "paint"); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | void SkLuaCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
michael@0 | 195 | AUTO_LUA("drawRRect"); |
michael@0 | 196 | lua.pushRRect(rrect, "rrect"); |
michael@0 | 197 | lua.pushPaint(paint, "paint"); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | void SkLuaCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
michael@0 | 201 | const SkPaint& paint) { |
michael@0 | 202 | AUTO_LUA("drawDRRect"); |
michael@0 | 203 | lua.pushRRect(outer, "outer"); |
michael@0 | 204 | lua.pushRRect(inner, "inner"); |
michael@0 | 205 | lua.pushPaint(paint, "paint"); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | void SkLuaCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
michael@0 | 209 | AUTO_LUA("drawPath"); |
michael@0 | 210 | lua.pushPath(path, "path"); |
michael@0 | 211 | lua.pushPaint(paint, "paint"); |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | void SkLuaCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, |
michael@0 | 215 | const SkPaint* paint) { |
michael@0 | 216 | AUTO_LUA("drawBitmap"); |
michael@0 | 217 | if (paint) { |
michael@0 | 218 | lua.pushPaint(*paint, "paint"); |
michael@0 | 219 | } |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | void SkLuaCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
michael@0 | 223 | const SkRect& dst, const SkPaint* paint, |
michael@0 | 224 | DrawBitmapRectFlags flags) { |
michael@0 | 225 | AUTO_LUA("drawBitmapRectToRect"); |
michael@0 | 226 | if (paint) { |
michael@0 | 227 | lua.pushPaint(*paint, "paint"); |
michael@0 | 228 | } |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | void SkLuaCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, |
michael@0 | 232 | const SkPaint* paint) { |
michael@0 | 233 | AUTO_LUA("drawBitmapMatrix"); |
michael@0 | 234 | if (paint) { |
michael@0 | 235 | lua.pushPaint(*paint, "paint"); |
michael@0 | 236 | } |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | void SkLuaCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, |
michael@0 | 240 | const SkPaint* paint) { |
michael@0 | 241 | AUTO_LUA("drawSprite"); |
michael@0 | 242 | if (paint) { |
michael@0 | 243 | lua.pushPaint(*paint, "paint"); |
michael@0 | 244 | } |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | void SkLuaCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
michael@0 | 248 | SkScalar y, const SkPaint& paint) { |
michael@0 | 249 | AUTO_LUA("drawText"); |
michael@0 | 250 | lua.pushEncodedText(paint.getTextEncoding(), text, byteLength); |
michael@0 | 251 | lua.pushPaint(paint, "paint"); |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | void SkLuaCanvas::drawPosText(const void* text, size_t byteLength, |
michael@0 | 255 | const SkPoint pos[], const SkPaint& paint) { |
michael@0 | 256 | AUTO_LUA("drawPosText"); |
michael@0 | 257 | lua.pushEncodedText(paint.getTextEncoding(), text, byteLength); |
michael@0 | 258 | lua.pushPaint(paint, "paint"); |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | void SkLuaCanvas::drawPosTextH(const void* text, size_t byteLength, |
michael@0 | 262 | const SkScalar xpos[], SkScalar constY, |
michael@0 | 263 | const SkPaint& paint) { |
michael@0 | 264 | AUTO_LUA("drawPosTextH"); |
michael@0 | 265 | lua.pushEncodedText(paint.getTextEncoding(), text, byteLength); |
michael@0 | 266 | lua.pushPaint(paint, "paint"); |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | void SkLuaCanvas::drawTextOnPath(const void* text, size_t byteLength, |
michael@0 | 270 | const SkPath& path, const SkMatrix* matrix, |
michael@0 | 271 | const SkPaint& paint) { |
michael@0 | 272 | AUTO_LUA("drawTextOnPath"); |
michael@0 | 273 | lua.pushPath(path, "path"); |
michael@0 | 274 | lua.pushEncodedText(paint.getTextEncoding(), text, byteLength); |
michael@0 | 275 | lua.pushPaint(paint, "paint"); |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | void SkLuaCanvas::drawPicture(SkPicture& picture) { |
michael@0 | 279 | AUTO_LUA("drawPicture"); |
michael@0 | 280 | // call through so we can see the nested picture ops |
michael@0 | 281 | this->INHERITED::drawPicture(picture); |
michael@0 | 282 | } |
michael@0 | 283 | |
michael@0 | 284 | void SkLuaCanvas::drawVertices(VertexMode vmode, int vertexCount, |
michael@0 | 285 | const SkPoint vertices[], const SkPoint texs[], |
michael@0 | 286 | const SkColor colors[], SkXfermode* xmode, |
michael@0 | 287 | const uint16_t indices[], int indexCount, |
michael@0 | 288 | const SkPaint& paint) { |
michael@0 | 289 | AUTO_LUA("drawVertices"); |
michael@0 | 290 | lua.pushPaint(paint, "paint"); |
michael@0 | 291 | } |
michael@0 | 292 | |
michael@0 | 293 | void SkLuaCanvas::drawData(const void* data, size_t length) { |
michael@0 | 294 | AUTO_LUA("drawData"); |
michael@0 | 295 | } |