gfx/skia/trunk/src/core/SkAnnotation.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 2012 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 "SkAnnotation.h"
michael@0 9 #include "SkData.h"
michael@0 10 #include "SkReadBuffer.h"
michael@0 11 #include "SkWriteBuffer.h"
michael@0 12 #include "SkPoint.h"
michael@0 13 #include "SkStream.h"
michael@0 14
michael@0 15 SkAnnotation::SkAnnotation(const char key[], SkData* value) : fKey(key) {
michael@0 16 if (NULL == value) {
michael@0 17 value = SkData::NewEmpty();
michael@0 18 } else {
michael@0 19 value->ref();
michael@0 20 }
michael@0 21 fData = value;
michael@0 22 }
michael@0 23
michael@0 24 SkAnnotation::~SkAnnotation() {
michael@0 25 fData->unref();
michael@0 26 }
michael@0 27
michael@0 28 SkData* SkAnnotation::find(const char key[]) const {
michael@0 29 return fKey.equals(key) ? fData : NULL;
michael@0 30 }
michael@0 31
michael@0 32 SkAnnotation::SkAnnotation(SkReadBuffer& buffer) {
michael@0 33 buffer.readString(&fKey);
michael@0 34 fData = buffer.readByteArrayAsData();
michael@0 35 }
michael@0 36
michael@0 37 void SkAnnotation::writeToBuffer(SkWriteBuffer& buffer) const {
michael@0 38 buffer.writeString(fKey.c_str());
michael@0 39 buffer.writeDataAsByteArray(fData);
michael@0 40 }
michael@0 41
michael@0 42 const char* SkAnnotationKeys::URL_Key() {
michael@0 43 return "SkAnnotationKey_URL";
michael@0 44 };
michael@0 45
michael@0 46 const char* SkAnnotationKeys::Define_Named_Dest_Key() {
michael@0 47 return "SkAnnotationKey_Define_Named_Dest";
michael@0 48 };
michael@0 49
michael@0 50 const char* SkAnnotationKeys::Link_Named_Dest_Key() {
michael@0 51 return "SkAnnotationKey_Link_Named_Dest";
michael@0 52 };
michael@0 53
michael@0 54 ///////////////////////////////////////////////////////////////////////////////
michael@0 55
michael@0 56 #include "SkCanvas.h"
michael@0 57
michael@0 58 static void annotate_paint(SkPaint& paint, const char* key, SkData* value) {
michael@0 59 paint.setAnnotation(SkAnnotation::Create(key, value))->unref();
michael@0 60 }
michael@0 61
michael@0 62 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) {
michael@0 63 if (NULL == value) {
michael@0 64 return;
michael@0 65 }
michael@0 66 SkPaint paint;
michael@0 67 annotate_paint(paint, SkAnnotationKeys::URL_Key(), value);
michael@0 68 canvas->drawRect(rect, paint);
michael@0 69 }
michael@0 70
michael@0 71 void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData* name) {
michael@0 72 if (NULL == name) {
michael@0 73 return;
michael@0 74 }
michael@0 75 SkPaint paint;
michael@0 76 annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name);
michael@0 77 canvas->drawPoint(point.x(), point.y(), paint);
michael@0 78 }
michael@0 79
michael@0 80 void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* name) {
michael@0 81 if (NULL == name) {
michael@0 82 return;
michael@0 83 }
michael@0 84 SkPaint paint;
michael@0 85 annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name);
michael@0 86 canvas->drawRect(rect, paint);
michael@0 87 }

mercurial