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 | // Copyright (c) 2010 Google Inc. |
michael@0 | 2 | // All rights reserved. |
michael@0 | 3 | // |
michael@0 | 4 | // Redistribution and use in source and binary forms, with or without |
michael@0 | 5 | // modification, are permitted provided that the following conditions are |
michael@0 | 6 | // met: |
michael@0 | 7 | // |
michael@0 | 8 | // * Redistributions of source code must retain the above copyright |
michael@0 | 9 | // notice, this list of conditions and the following disclaimer. |
michael@0 | 10 | // * Redistributions in binary form must reproduce the above |
michael@0 | 11 | // copyright notice, this list of conditions and the following disclaimer |
michael@0 | 12 | // in the documentation and/or other materials provided with the |
michael@0 | 13 | // distribution. |
michael@0 | 14 | // * Neither the name of Google Inc. nor the names of its |
michael@0 | 15 | // contributors may be used to endorse or promote products derived from |
michael@0 | 16 | // this software without specific prior written permission. |
michael@0 | 17 | // |
michael@0 | 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 29 | |
michael@0 | 30 | // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
michael@0 | 31 | |
michael@0 | 32 | // dwarf_line_to_module.cc: Implementation of DwarfLineToModule class. |
michael@0 | 33 | // See dwarf_line_to_module.h for details. |
michael@0 | 34 | |
michael@0 | 35 | #include <string> |
michael@0 | 36 | |
michael@0 | 37 | #include "common/dwarf_line_to_module.h" |
michael@0 | 38 | #include "common/using_std_string.h" |
michael@0 | 39 | #include "common/logging.h" |
michael@0 | 40 | |
michael@0 | 41 | // Trying to support Windows paths in a reasonable way adds a lot of |
michael@0 | 42 | // variations to test; it would be better to just put off dealing with |
michael@0 | 43 | // it until we actually have to deal with DWARF on Windows. |
michael@0 | 44 | |
michael@0 | 45 | // Return true if PATH is an absolute path, false if it is relative. |
michael@0 | 46 | static bool PathIsAbsolute(const string &path) { |
michael@0 | 47 | return (path.size() >= 1 && path[0] == '/'); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | static bool HasTrailingSlash(const string &path) { |
michael@0 | 51 | return (path.size() >= 1 && path[path.size() - 1] == '/'); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | // If PATH is an absolute path, return PATH. If PATH is a relative path, |
michael@0 | 55 | // treat it as relative to BASE and return the combined path. |
michael@0 | 56 | static string ExpandPath(const string &path, |
michael@0 | 57 | const string &base) { |
michael@0 | 58 | if (PathIsAbsolute(path) || base.empty()) |
michael@0 | 59 | return path; |
michael@0 | 60 | return base + (HasTrailingSlash(base) ? "" : "/") + path; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | namespace google_breakpad { |
michael@0 | 64 | |
michael@0 | 65 | void DwarfLineToModule::DefineDir(const string &name, uint32 dir_num) { |
michael@0 | 66 | // Directory number zero is reserved to mean the compilation |
michael@0 | 67 | // directory. Silently ignore attempts to redefine it. |
michael@0 | 68 | if (dir_num != 0) |
michael@0 | 69 | directories_[dir_num] = ExpandPath(name, compilation_dir_); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | void DwarfLineToModule::DefineFile(const string &name, int32 file_num, |
michael@0 | 73 | uint32 dir_num, uint64 mod_time, |
michael@0 | 74 | uint64 length) { |
michael@0 | 75 | if (file_num == -1) |
michael@0 | 76 | file_num = ++highest_file_number_; |
michael@0 | 77 | else if (file_num > highest_file_number_) |
michael@0 | 78 | highest_file_number_ = file_num; |
michael@0 | 79 | |
michael@0 | 80 | string dir_name; |
michael@0 | 81 | if (dir_num == 0) { |
michael@0 | 82 | // Directory number zero is the compilation directory, and is stored as |
michael@0 | 83 | // an attribute on the compilation unit, rather than in the program table. |
michael@0 | 84 | dir_name = compilation_dir_; |
michael@0 | 85 | } else { |
michael@0 | 86 | DirectoryTable::const_iterator directory_it = directories_.find(dir_num); |
michael@0 | 87 | if (directory_it != directories_.end()) { |
michael@0 | 88 | dir_name = directory_it->second; |
michael@0 | 89 | } else { |
michael@0 | 90 | if (!warned_bad_directory_number_) { |
michael@0 | 91 | BPLOG(INFO) << "warning: DWARF line number data refers to undefined" |
michael@0 | 92 | << " directory numbers"; |
michael@0 | 93 | warned_bad_directory_number_ = true; |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | string full_name = ExpandPath(name, dir_name); |
michael@0 | 99 | |
michael@0 | 100 | // Find a Module::File object of the given name, and add it to the |
michael@0 | 101 | // file table. |
michael@0 | 102 | files_[file_num] = module_->FindFile(full_name); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | void DwarfLineToModule::AddLine(uint64 address, uint64 length, |
michael@0 | 106 | uint32 file_num, uint32 line_num, |
michael@0 | 107 | uint32 column_num) { |
michael@0 | 108 | if (length == 0) |
michael@0 | 109 | return; |
michael@0 | 110 | |
michael@0 | 111 | // Clip lines not to extend beyond the end of the address space. |
michael@0 | 112 | if (address + length < address) |
michael@0 | 113 | length = -address; |
michael@0 | 114 | |
michael@0 | 115 | // Should we omit this line? (See the comments for omitted_line_end_.) |
michael@0 | 116 | if (address == 0 || address == omitted_line_end_) { |
michael@0 | 117 | omitted_line_end_ = address + length; |
michael@0 | 118 | return; |
michael@0 | 119 | } else { |
michael@0 | 120 | omitted_line_end_ = 0; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | // Find the source file being referred to. |
michael@0 | 124 | Module::File *file = files_[file_num]; |
michael@0 | 125 | if (!file) { |
michael@0 | 126 | if (!warned_bad_file_number_) { |
michael@0 | 127 | BPLOG(INFO) << "warning: DWARF line number data refers to " |
michael@0 | 128 | << "undefined file numbers"; |
michael@0 | 129 | warned_bad_file_number_ = true; |
michael@0 | 130 | } |
michael@0 | 131 | return; |
michael@0 | 132 | } |
michael@0 | 133 | Module::Line line; |
michael@0 | 134 | line.address = address; |
michael@0 | 135 | // We set the size when we get the next line or the EndSequence call. |
michael@0 | 136 | line.size = length; |
michael@0 | 137 | line.file = file; |
michael@0 | 138 | line.number = line_num; |
michael@0 | 139 | lines_->push_back(line); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | } // namespace google_breakpad |