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 2011 Google Inc. |
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 | #include "SkViewInflate.h" |
michael@0 | 9 | #include "SkView.h" |
michael@0 | 10 | #include <stdio.h> |
michael@0 | 11 | |
michael@0 | 12 | SkViewInflate::SkViewInflate() : fIDs(kMinIDStrAlloc), fStrings(kMinIDStrAlloc) |
michael@0 | 13 | { |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | SkViewInflate::~SkViewInflate() |
michael@0 | 17 | { |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | void SkViewInflate::rInflate(const SkDOM& dom, const SkDOM::Node* node, SkView* parent) |
michael@0 | 21 | { |
michael@0 | 22 | const char* str = dom.findAttr(node, "id"); |
michael@0 | 23 | if (str) |
michael@0 | 24 | fIDs.set(str, parent); |
michael@0 | 25 | |
michael@0 | 26 | const SkDOM::Node* child = dom.getFirstChild(node); |
michael@0 | 27 | while (child) |
michael@0 | 28 | { |
michael@0 | 29 | SkView* view = this->createView(dom, child); |
michael@0 | 30 | if (view) |
michael@0 | 31 | { |
michael@0 | 32 | this->rInflate(dom, child, view); |
michael@0 | 33 | parent->attachChildToFront(view)->unref(); |
michael@0 | 34 | } |
michael@0 | 35 | else |
michael@0 | 36 | { |
michael@0 | 37 | const char* name = dom.getName(child); |
michael@0 | 38 | const char* target; |
michael@0 | 39 | |
michael@0 | 40 | if (!strcmp(name, "listenTo") && (target = dom.findAttr(child, "target")) != NULL) |
michael@0 | 41 | this->addIDStr(&fListenTo, parent, target); |
michael@0 | 42 | |
michael@0 | 43 | if (!strcmp(name, "broadcastTo") && (target = dom.findAttr(child, "target")) != NULL) |
michael@0 | 44 | this->addIDStr(&fBroadcastTo, parent, target); |
michael@0 | 45 | } |
michael@0 | 46 | child = dom.getNextSibling(child); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | parent->setVisibleP(true); |
michael@0 | 50 | this->inflateView(parent, dom, node); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | void SkViewInflate::inflateView(SkView* view, const SkDOM& dom, const SkDOM::Node* node) |
michael@0 | 54 | { |
michael@0 | 55 | // called after all of view's children have been instantiated. |
michael@0 | 56 | // this may be overridden by a subclass, to load in layout or other helpers |
michael@0 | 57 | // they should call through to us (INHERITED) before or after their patch |
michael@0 | 58 | view->inflate(dom, node); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | SkView* SkViewInflate::inflate(const SkDOM& dom, const SkDOM::Node* node, SkView* root) |
michael@0 | 62 | { |
michael@0 | 63 | fIDs.reset(); |
michael@0 | 64 | |
michael@0 | 65 | if (root == NULL) |
michael@0 | 66 | { |
michael@0 | 67 | root = this->createView(dom, node); |
michael@0 | 68 | if (root == NULL) |
michael@0 | 69 | { |
michael@0 | 70 | printf("createView returned NULL on <%s>\n", dom.getName(node)); |
michael@0 | 71 | return NULL; |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | this->rInflate(dom, node, root); |
michael@0 | 75 | |
michael@0 | 76 | // resolve listeners and broadcasters |
michael@0 | 77 | { |
michael@0 | 78 | SkView* target; |
michael@0 | 79 | const IDStr* iter = fListenTo.begin(); |
michael@0 | 80 | const IDStr* stop = fListenTo.end(); |
michael@0 | 81 | for (; iter < stop; iter++) |
michael@0 | 82 | { |
michael@0 | 83 | if (fIDs.find(iter->fStr, &target)) |
michael@0 | 84 | target->addListenerID(iter->fView->getSinkID()); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | iter = fBroadcastTo.begin(); |
michael@0 | 88 | stop = fBroadcastTo.end(); |
michael@0 | 89 | for (; iter < stop; iter++) |
michael@0 | 90 | { |
michael@0 | 91 | if (fIDs.find(iter->fStr, &target)) |
michael@0 | 92 | iter->fView->addListenerID(target->getSinkID()); |
michael@0 | 93 | } |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | // now that the tree is built, give everyone a shot at the ID dict |
michael@0 | 97 | root->postInflate(fIDs); |
michael@0 | 98 | return root; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | SkView* SkViewInflate::inflate(const char xml[], size_t len, SkView* root) |
michael@0 | 102 | { |
michael@0 | 103 | SkDOM dom; |
michael@0 | 104 | const SkDOM::Node* node = dom.build(xml, len); |
michael@0 | 105 | |
michael@0 | 106 | return node ? this->inflate(dom, node, root) : NULL; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | SkView* SkViewInflate::findViewByID(const char id[]) const |
michael@0 | 110 | { |
michael@0 | 111 | SkASSERT(id); |
michael@0 | 112 | SkView* view; |
michael@0 | 113 | return fIDs.find(id, &view) ? view : NULL; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | SkView* SkViewInflate::createView(const SkDOM& dom, const SkDOM::Node* node) |
michael@0 | 117 | { |
michael@0 | 118 | if (!strcmp(dom.getName(node), "view")) |
michael@0 | 119 | return new SkView; |
michael@0 | 120 | return NULL; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | void SkViewInflate::addIDStr(SkTDArray<IDStr>* list, SkView* view, const char* str) |
michael@0 | 124 | { |
michael@0 | 125 | size_t len = strlen(str) + 1; |
michael@0 | 126 | IDStr* pair = list->append(); |
michael@0 | 127 | pair->fView = view; |
michael@0 | 128 | pair->fStr = (char*)fStrings.alloc(len, SkChunkAlloc::kThrow_AllocFailType); |
michael@0 | 129 | memcpy(pair->fStr, str, len); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | #ifdef SK_DEBUG |
michael@0 | 133 | void SkViewInflate::dump() const |
michael@0 | 134 | { |
michael@0 | 135 | const IDStr* iter = fListenTo.begin(); |
michael@0 | 136 | const IDStr* stop = fListenTo.end(); |
michael@0 | 137 | for (; iter < stop; iter++) |
michael@0 | 138 | SkDebugf("inflate: listenTo(\"%s\")\n", iter->fStr); |
michael@0 | 139 | |
michael@0 | 140 | iter = fBroadcastTo.begin(); |
michael@0 | 141 | stop = fBroadcastTo.end(); |
michael@0 | 142 | for (; iter < stop; iter++) |
michael@0 | 143 | SkDebugf("inflate: broadcastFrom(\"%s\")\n", iter->fStr); |
michael@0 | 144 | } |
michael@0 | 145 | #endif |