Compare commits
2 Commits
MICROB_200
...
regalloc_c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c43d4984f | ||
|
|
cfe021ff88 |
134
mozilla/ef/Compiler/RegisterAllocator/BitSet.cpp
Normal file
134
mozilla/ef/Compiler/RegisterAllocator/BitSet.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
// Return the next bit after index set to true or -1 if none.
|
||||
//
|
||||
Int32 BitSet::nextOne(Int32 pos) const
|
||||
{
|
||||
++pos;
|
||||
|
||||
if (pos < 0 || Uint32(pos) >= universeSize)
|
||||
return -1;
|
||||
|
||||
Uint32 offset = getWordOffset(pos);
|
||||
Uint8 index = getBitOffset(pos);
|
||||
Word* ptr = &word[offset];
|
||||
Word currentWord = *ptr++ >> index;
|
||||
|
||||
if (currentWord != Word(0)) {
|
||||
while ((currentWord & Word(1)) == 0) {
|
||||
++index;
|
||||
currentWord >>= 1;
|
||||
}
|
||||
return (offset << nBitsInWordLog2) + index;
|
||||
}
|
||||
|
||||
Word* limit = &word[getSizeInWords(universeSize)];
|
||||
while (ptr < limit) {
|
||||
++offset;
|
||||
currentWord = *ptr++;
|
||||
if (currentWord != Word(0)) {
|
||||
index = 0;
|
||||
while ((currentWord & Word(1)) == 0) {
|
||||
++index;
|
||||
currentWord >>= 1;
|
||||
}
|
||||
return (offset << nBitsInWordLog2) + index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Return the next bit after index set to false or -1 if none.
|
||||
//
|
||||
Int32 BitSet::nextZero(Int32 pos) const
|
||||
{
|
||||
++pos;
|
||||
|
||||
if (pos < 0 || Uint32(pos) >= universeSize)
|
||||
return -1;
|
||||
|
||||
Uint32 offset = getWordOffset(pos);
|
||||
Uint8 index = getBitOffset(pos);
|
||||
Word* ptr = &word[offset];
|
||||
Word currentWord = *ptr++ >> index;
|
||||
|
||||
if (currentWord != Word(~0)) {
|
||||
for (; index < nBitsInWord; ++index) {
|
||||
if ((currentWord & Word(1)) == 0) {
|
||||
Int32 ret = (offset << nBitsInWordLog2) + index;
|
||||
return (Uint32(ret) < universeSize) ? ret : -1;
|
||||
}
|
||||
currentWord >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
Word* limit = &word[getSizeInWords(universeSize)];
|
||||
while (ptr < limit) {
|
||||
++offset;
|
||||
currentWord = *ptr++;
|
||||
if (currentWord != Word(~0)) {
|
||||
for (index = 0; index < nBitsInWord; ++index) {
|
||||
if ((currentWord & Word(1)) == 0) {
|
||||
Int32 ret = (offset << nBitsInWordLog2) + index;
|
||||
return (Uint32(ret) < universeSize) ? ret : -1;
|
||||
}
|
||||
currentWord >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
|
||||
// Print the set.
|
||||
//
|
||||
void BitSet::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("[ "));
|
||||
|
||||
for (Int32 i = firstOne(); i != -1; i = nextOne(i)) {
|
||||
Int32 currentBit = i;
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%d", currentBit));
|
||||
|
||||
Int32 nextBit = nextOne(currentBit);
|
||||
if (nextBit != currentBit + 1) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" "));
|
||||
continue;
|
||||
}
|
||||
|
||||
while ((nextBit != -1) && (nextBit == (currentBit + 1))) {
|
||||
currentBit = nextBit;
|
||||
nextBit = nextOne(nextBit);
|
||||
}
|
||||
|
||||
if (currentBit > (i+1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("-%d ", currentBit));
|
||||
else
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" %d ", currentBit));
|
||||
|
||||
i = currentBit;
|
||||
}
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("]\n"));
|
||||
}
|
||||
|
||||
#endif // DEBUG_LOG
|
||||
195
mozilla/ef/Compiler/RegisterAllocator/BitSet.h
Normal file
195
mozilla/ef/Compiler/RegisterAllocator/BitSet.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _BITSET_H_
|
||||
#define _BITSET_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "LogModule.h"
|
||||
#include "Pool.h"
|
||||
#include <string.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// BitSet -
|
||||
|
||||
class BitSet
|
||||
{
|
||||
private:
|
||||
|
||||
#if (PR_BITS_PER_WORD == 64)
|
||||
typedef Uint64 Word;
|
||||
#elif (PR_BITS_PER_WORD == 32)
|
||||
typedef Uint32 Word;
|
||||
#endif
|
||||
|
||||
static const nBitsInWord = PR_BITS_PER_WORD;
|
||||
static const nBytesInWord = PR_BYTES_PER_WORD;
|
||||
static const nBitsInWordLog2 = PR_BITS_PER_WORD_LOG2;
|
||||
static const nBytesInWordLog2 = PR_BYTES_PER_WORD_LOG2;
|
||||
|
||||
// Return the number of Word need to store the universe.
|
||||
static Uint32 getSizeInWords(Uint32 sizeOfUniverse) {return (sizeOfUniverse + (nBitsInWord - 1)) >> nBitsInWordLog2;}
|
||||
// Return the given element offset in its containing Word.
|
||||
static Uint32 getBitOffset(Uint32 element) {return element & (nBitsInWord - 1);}
|
||||
// Return the Word offset for the given element int the universe.
|
||||
static Uint32 getWordOffset(Uint32 element) {return element >> nBitsInWordLog2;}
|
||||
// Return the mask for the given bit index.
|
||||
static Word getMask(Uint8 index) {return Word(1) << index;}
|
||||
|
||||
private:
|
||||
|
||||
Uint32 universeSize; // Size of the universe
|
||||
Word* word; // universe memory.
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
BitSet(const BitSet&);
|
||||
|
||||
// Check if the given set's universe is of the same size than this universe.
|
||||
void checkUniverseCompatibility(const BitSet& set) const {assert(set.universeSize == universeSize);}
|
||||
// Check if pos is valid for this set's universe.
|
||||
void checkMember(Int32 pos) const {assert(pos >=0 && Uint32(pos) < universeSize);}
|
||||
|
||||
public:
|
||||
|
||||
// Create a bitset of universeSize bits.
|
||||
BitSet(Pool& pool, Uint32 universeSize) : universeSize(universeSize) {word = new(pool) Word[getSizeInWords(universeSize)]; clear();}
|
||||
|
||||
// Return the size of this bitset.
|
||||
Uint32 getSize() const {return universeSize;}
|
||||
|
||||
// Clear the bitset.
|
||||
void clear() {memset(word, 0x00, getSizeInWords(universeSize) << nBytesInWordLog2);}
|
||||
// Clear the bit at index.
|
||||
void clear(Uint32 index) {checkMember(index); word[getWordOffset(index)] &= ~getMask(index);}
|
||||
// Set the bitset.
|
||||
void set() {memset(word, 0xFF, getSizeInWords(universeSize) << nBytesInWordLog2);}
|
||||
// Set the bit at index.
|
||||
void set(Uint32 index) {checkMember(index); word[getWordOffset(index)] |= getMask(index);}
|
||||
// Return true if the bit at index is set.
|
||||
bool test(Uint32 index) const {checkMember(index); return (word[getWordOffset(index)] & getMask(index)) != 0;}
|
||||
// Union with the given bitset.
|
||||
inline void or(const BitSet& set);
|
||||
// Intersection with the given bitset.
|
||||
inline void and(const BitSet& set);
|
||||
// Difference with the given bitset.
|
||||
inline void difference(const BitSet& set);
|
||||
// Copy set.
|
||||
inline BitSet& operator = (const BitSet& set);
|
||||
// Return true if the bitset are identical.
|
||||
friend bool operator == (const BitSet& set1, const BitSet& set2);
|
||||
// Return true if the bitset are different.
|
||||
friend bool operator != (const BitSet& set1, const BitSet& set2);
|
||||
|
||||
// Logical operators.
|
||||
BitSet& operator |= (const BitSet& set) {or(set); return *this;}
|
||||
BitSet& operator &= (const BitSet& set) {and(set); return *this;}
|
||||
BitSet& operator -= (const BitSet& set) {difference(set); return *this;}
|
||||
|
||||
// Return the first bit at set to true or -1 if none.
|
||||
Int32 firstOne() const {return nextOne(-1);}
|
||||
// Return the next bit after index set to true or -1 if none.
|
||||
Int32 nextOne(Int32 pos) const;
|
||||
// Return the first bit at set to false or -1 if none.
|
||||
Int32 firstZero() const {return nextZero(-1);}
|
||||
// Return the next bit after index set to false or -1 if none.
|
||||
Int32 nextZero(Int32 pos) const;
|
||||
|
||||
// Iterator to conform with the set API.
|
||||
typedef Int32 iterator;
|
||||
// Return true if the walk is ordered.
|
||||
static bool isOrdered() {return true;}
|
||||
// Return the iterator for the first element of this set.
|
||||
iterator begin() const {return firstOne();}
|
||||
// Return the next iterator.
|
||||
iterator advance(iterator pos) const {return nextOne(pos);}
|
||||
// Return true if the iterator is at the end of the set.
|
||||
bool done(iterator pos) const {return pos == -1;}
|
||||
// Return the element corresponding to the given iterator.
|
||||
Uint32 get(iterator pos) const {return pos;}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the set.
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
// Union with the given bitset.
|
||||
//
|
||||
inline void BitSet::or(const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Word* src = set.word;
|
||||
Word* dst = word;
|
||||
Word* limit = &src[getSizeInWords(universeSize)];
|
||||
|
||||
while (src < limit)
|
||||
*dst++ |= *src++;
|
||||
}
|
||||
|
||||
// Intersection with the given bitset.
|
||||
//
|
||||
inline void BitSet::and(const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Word* src = set.word;
|
||||
Word* dst = word;
|
||||
Word* limit = &src[getSizeInWords(universeSize)];
|
||||
|
||||
while (src < limit)
|
||||
*dst++ &= *src++;
|
||||
}
|
||||
|
||||
// Difference with the given bitset.
|
||||
//
|
||||
inline void BitSet::difference(const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Word* src = set.word;
|
||||
Word* dst = word;
|
||||
Word* limit = &src[getSizeInWords(universeSize)];
|
||||
|
||||
while (src < limit)
|
||||
*dst++ &= ~*src++;
|
||||
}
|
||||
|
||||
// Copy the given set into this set.
|
||||
//
|
||||
inline BitSet& BitSet::operator = (const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
if (this != &set)
|
||||
memcpy(word, set.word, getSizeInWords(universeSize) << nBytesInWordLog2);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Return true if the given set is identical to this set.
|
||||
inline bool operator == (const BitSet& set1, const BitSet& set2)
|
||||
{
|
||||
set1.checkUniverseCompatibility(set2);
|
||||
|
||||
if (&set1 == &set2)
|
||||
return true;
|
||||
|
||||
return memcmp(set1.word, set2.word, BitSet::getSizeInWords(set1.universeSize) << BitSet::nBytesInWordLog2) == 0;
|
||||
}
|
||||
|
||||
inline bool operator != (const BitSet& set1, const BitSet& set2) {return !(set1 == set2);}
|
||||
|
||||
#endif // _BITSET_H
|
||||
159
mozilla/ef/Compiler/RegisterAllocator/Coalescing.h
Normal file
159
mozilla/ef/Compiler/RegisterAllocator/Coalescing.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _COALESCING_H_
|
||||
#define _COALESCING_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "InterferenceGraph.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "SparseSet.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
|
||||
#if 1
|
||||
// Performing an ultra conservative coalescing meens that when we look at
|
||||
// candidates (source,destination) for coalescing we need to make sure
|
||||
// that the combined interference of the source and destination register
|
||||
// will not exceed the total number of register available for the register
|
||||
// class.
|
||||
#define ULTRA_CONSERVATIVE_COALESCING
|
||||
#else
|
||||
// If we are not doing an ultra conservative coalescing we have to make sure
|
||||
// that the total number of neighbor whose degree is greater than the total
|
||||
// number of register is not greater than the total number of register.
|
||||
#undef ULTRA_CONSERVATIVE_COALESCING
|
||||
#endif
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct Coalescing
|
||||
{
|
||||
static bool coalesce(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Coalescing<RegisterPressure>::coalesce(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
|
||||
// Initialize the lookup table
|
||||
//
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* newRange = new RegisterName[2 * rangeCount];
|
||||
RegisterName* coalescedRange = &newRange[rangeCount];
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
init(coalescedRange, rangeCount);
|
||||
|
||||
SparseSet interferences(pool, rangeCount);
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
bool removedInstructions = false;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.lndList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
|
||||
// Walk the nodes in the loop nesting depth list.
|
||||
for (Int32 n = nNodes - 1; n >= 0; n--) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
|
||||
InstructionList::iterator it = instructions.begin();
|
||||
while (!instructions.done(it)) {
|
||||
Instruction& instruction = instructions.get(it);
|
||||
it = instructions.advance(it);
|
||||
|
||||
if ((instruction.getFlags() & ifCopy) != 0) {
|
||||
assert(instruction.getInstructionUseBegin() != instruction.getInstructionUseEnd() && instruction.getInstructionUseBegin()[0].isRegister());
|
||||
assert(instruction.getInstructionDefineBegin() != instruction.getInstructionDefineEnd() && instruction.getInstructionDefineBegin()[0].isRegister());
|
||||
|
||||
RegisterName source = findRoot(name2range[instruction.getInstructionUseBegin()[0].getRegisterName()], coalescedRange);
|
||||
RegisterName destination = findRoot(name2range[instruction.getInstructionDefineBegin()[0].getRegisterName()], coalescedRange);
|
||||
|
||||
if (source == destination) {
|
||||
instruction.remove();
|
||||
} else if (!iGraph.interfere(source, destination)) {
|
||||
InterferenceVector* sourceVector = iGraph.getInterferenceVector(source);
|
||||
InterferenceVector* destinationVector = iGraph.getInterferenceVector(destination);
|
||||
|
||||
#ifdef ULTRA_CONSERVATIVE_COALESCING
|
||||
interferences.clear();
|
||||
|
||||
InterferenceVector* vector;
|
||||
for (vector = sourceVector; vector != NULL; vector = vector->next) {
|
||||
RegisterName* neighbors = vector->neighbors;
|
||||
for (Uint32 i = 0; i < vector->count; i++)
|
||||
interferences.set(findRoot(neighbors[i], coalescedRange));
|
||||
}
|
||||
for (vector = destinationVector; vector != NULL; vector = vector->next) {
|
||||
RegisterName* neighbors = vector->neighbors;
|
||||
for (Uint32 i = 0; i < vector->count; i++)
|
||||
interferences.set(findRoot(neighbors[i], coalescedRange));
|
||||
}
|
||||
|
||||
Uint32 count = interferences.getSize();
|
||||
#else // ULTRA_CONSERVATIVE_COALESCING
|
||||
trespass("not implemented");
|
||||
Uint32 count = 0;
|
||||
#endif // ULTRA_CONSERVATIVE_COALESCING
|
||||
|
||||
if (count < 6 /* FIX: should get the number from the class */) {
|
||||
// Update the interferences vector.
|
||||
if (sourceVector == NULL) {
|
||||
iGraph.setInterferenceVector(source, destinationVector);
|
||||
sourceVector = destinationVector;
|
||||
} else if (destinationVector == NULL)
|
||||
iGraph.setInterferenceVector(destination, sourceVector);
|
||||
else {
|
||||
InterferenceVector* last = NULL;
|
||||
for (InterferenceVector* v = sourceVector; v != NULL; v = v->next)
|
||||
last = v;
|
||||
assert(last);
|
||||
last->next = destinationVector;
|
||||
iGraph.setInterferenceVector(destination, sourceVector);
|
||||
}
|
||||
// Update the interference matrix.
|
||||
for (InterferenceVector* v = sourceVector; v != NULL; v = v->next) {
|
||||
RegisterName* neighbors = v->neighbors;
|
||||
for (Uint32 i = 0; i < v->count; i++) {
|
||||
RegisterName neighbor = findRoot(neighbors[i], coalescedRange);
|
||||
iGraph.setInterference(neighbor, source);
|
||||
iGraph.setInterference(neighbor, destination);
|
||||
}
|
||||
}
|
||||
|
||||
instruction.remove();
|
||||
coalescedRange[source] = destination;
|
||||
removedInstructions = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerAllocator.rangeCount = compress(registerAllocator.name2range, coalescedRange, registerAllocator.nameCount, rangeCount);
|
||||
delete newRange;
|
||||
|
||||
return removedInstructions;
|
||||
}
|
||||
|
||||
#endif // _COALESCING_H_
|
||||
283
mozilla/ef/Compiler/RegisterAllocator/Coloring.cpp
Normal file
283
mozilla/ef/Compiler/RegisterAllocator/Coloring.cpp
Normal file
@@ -0,0 +1,283 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef NEW_LAURENTM_CODE
|
||||
|
||||
#include "Coloring.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "FastBitSet.h"
|
||||
#include "FastBitMatrix.h"
|
||||
#include "CpuInfo.h"
|
||||
|
||||
bool Coloring::
|
||||
assignRegisters(FastBitMatrix& interferenceMatrix)
|
||||
{
|
||||
PRUint32 *stackPtr = new(pool) PRUint32[vRegManager.count()];
|
||||
|
||||
return select(interferenceMatrix, stackPtr, simplify(interferenceMatrix, stackPtr));
|
||||
}
|
||||
|
||||
PRInt32 Coloring::
|
||||
getLowestSpillCostRegister(FastBitSet& bitset)
|
||||
{
|
||||
PRInt32 lowest = bitset.firstOne();
|
||||
if (lowest != -1)
|
||||
{
|
||||
Flt32 cost = vRegManager.getVirtualRegister(lowest).spillInfo.spillCost;
|
||||
for (PRInt32 r = bitset.nextOne(lowest); r != -1; r = bitset.nextOne(r))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
|
||||
if (!vReg.spillInfo.infiniteSpillCost && (vReg.spillInfo.spillCost < cost))
|
||||
{
|
||||
cost = vReg.spillInfo.spillCost;
|
||||
lowest = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
PRUint32* Coloring::
|
||||
simplify(FastBitMatrix interferenceMatrix, PRUint32* stackPtr)
|
||||
{
|
||||
// first we construct the sets low and high. low contains all nodes of degree
|
||||
// inferior to the number of register available on the processor. All the
|
||||
// nodes with an high degree and a finite spill cost are placed in high.
|
||||
// Nodes of high degree and infinite spill cost are not included in either sets.
|
||||
|
||||
PRUint32 nRegisters = vRegManager.count();
|
||||
FastBitSet low(pool, nRegisters);
|
||||
FastBitSet high(pool, nRegisters);
|
||||
FastBitSet stack(pool, nRegisters);
|
||||
|
||||
for (VirtualRegisterManager::iterator i = vRegManager.begin(); !vRegManager.done(i); i = vRegManager.advance(i))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(i);
|
||||
|
||||
if (vReg.getClass() == vrcStackSlot)
|
||||
{
|
||||
stack.set(i);
|
||||
vReg.colorRegister(nRegisters);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vReg.colorInfo.interferenceDegree < NUMBER_OF_REGISTERS)
|
||||
low.set(i);
|
||||
else // if (!vReg.spillInfo.infiniteSpillCost)
|
||||
high.set(i);
|
||||
|
||||
// Set coloring info.
|
||||
vReg.spillInfo.willSpill = false;
|
||||
|
||||
switch(vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
vReg.colorRegister(LAST_GREGISTER + 1);
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
vReg.colorRegister(LAST_FPREGISTER + 1);
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(false); // Cannot happen.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// push the stack registers
|
||||
PRInt32 j;
|
||||
for (j = stack.firstOne(); j != -1; j = stack.nextOne(j))
|
||||
*stackPtr++ = j;
|
||||
|
||||
// simplify
|
||||
while (true)
|
||||
{
|
||||
PRInt32 r;
|
||||
while ((r = getLowestSpillCostRegister(low)) != -1)
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
|
||||
|
||||
/* update low and high */
|
||||
FastBitSet inter(interferenceMatrix.getRow(r), nRegisters);
|
||||
for (j = inter.firstOne(); j != -1; j = inter.nextOne(j))
|
||||
{
|
||||
VirtualRegister& neighbor = vRegManager.getVirtualRegister(j);
|
||||
// if the new interference degree of one of his neighbor becomes
|
||||
// NUMBER_OF_REGISTERS - 1 then it is added to the set 'low'.
|
||||
|
||||
PRUint32 maxInterference = 0;
|
||||
switch (neighbor.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
maxInterference = NUMBER_OF_GREGISTERS;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
maxInterference = NUMBER_OF_FPREGISTERS;
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(false);
|
||||
}
|
||||
if ((vRegManager.getVirtualRegister(j).colorInfo.interferenceDegree-- == maxInterference))
|
||||
{
|
||||
high.clear(j);
|
||||
low.set(j);
|
||||
}
|
||||
vReg.colorInfo.interferenceDegree--;
|
||||
interferenceMatrix.clear(r, j);
|
||||
interferenceMatrix.clear(j, r);
|
||||
}
|
||||
low.clear(r);
|
||||
|
||||
// Push this register.
|
||||
*stackPtr++ = r;
|
||||
}
|
||||
if ((r = getLowestSpillCostRegister(high)) != -1)
|
||||
{
|
||||
high.clear(r);
|
||||
low.set(r);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return stackPtr;
|
||||
}
|
||||
|
||||
bool Coloring::
|
||||
select(FastBitMatrix& interferenceMatrix, PRUint32* stackBase, PRUint32* stackPtr)
|
||||
{
|
||||
PRUint32 nRegisters = vRegManager.count();
|
||||
FastBitSet usedRegisters(NUMBER_OF_REGISTERS + 1); // usedRegisters if used for both GR & FPR.
|
||||
FastBitSet preColoredRegisters(NUMBER_OF_REGISTERS + 1);
|
||||
FastBitSet usedStack(nRegisters + 1);
|
||||
bool success = true;
|
||||
Int32 lastUsedSSR = -1;
|
||||
|
||||
// select
|
||||
while (stackPtr != stackBase)
|
||||
{
|
||||
// Pop one register.
|
||||
PRUint32 r = *--stackPtr;
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
|
||||
|
||||
FastBitSet neighbors(interferenceMatrix.getRow(r), nRegisters);
|
||||
|
||||
if (vReg.getClass() == vrcStackSlot)
|
||||
// Stack slots coloring.
|
||||
{
|
||||
usedStack.clear();
|
||||
|
||||
for (PRInt32 i = neighbors.firstOne(); i != -1; i = neighbors.nextOne(i))
|
||||
usedStack.set(vRegManager.getVirtualRegister(i).getColor());
|
||||
|
||||
Int32 color = usedStack.firstZero();
|
||||
vReg.colorRegister(color);
|
||||
if (color > lastUsedSSR)
|
||||
lastUsedSSR = color;
|
||||
}
|
||||
else
|
||||
// Integer & Floating point register coloring.
|
||||
{
|
||||
usedRegisters.clear();
|
||||
preColoredRegisters.clear();
|
||||
|
||||
for (PRInt32 i = neighbors.firstOne(); i != -1; i = neighbors.nextOne(i))
|
||||
{
|
||||
VirtualRegister& nvReg = vRegManager.getVirtualRegister(i);
|
||||
usedRegisters.set(nvReg.getColor());
|
||||
if (nvReg.isPreColored())
|
||||
preColoredRegisters.set(nvReg.getPreColor());
|
||||
}
|
||||
if (vReg.hasSpecialInterference)
|
||||
usedRegisters |= vReg.specialInterference;
|
||||
|
||||
PRInt8 c = -1;
|
||||
PRInt8 maxColor = 0;
|
||||
PRInt8 firstColor = 0;
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
firstColor = FIRST_GREGISTER;
|
||||
maxColor = LAST_GREGISTER;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
firstColor = FIRST_FPREGISTER;
|
||||
maxColor = LAST_FPREGISTER;
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(false);
|
||||
}
|
||||
|
||||
if (vReg.isPreColored())
|
||||
{
|
||||
c = vReg.getPreColor();
|
||||
if (usedRegisters.test(c))
|
||||
c = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (c = usedRegisters.nextZero(firstColor - 1); (c >= 0) && (c <= maxColor) && (preColoredRegisters.test(c));
|
||||
c = usedRegisters.nextZero(c)) {}
|
||||
}
|
||||
|
||||
if ((c >= 0) && (c <= maxColor))
|
||||
{
|
||||
vReg.colorRegister(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
VirtualRegister& stackRegister = vRegManager.newVirtualRegister(vrcStackSlot);
|
||||
vReg.equivalentRegister[vrcStackSlot] = &stackRegister;
|
||||
vReg.spillInfo.willSpill = true;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (success)
|
||||
{
|
||||
for (VirtualRegisterManager::iterator i = vRegManager.begin(); !vRegManager.done(i); i = vRegManager.advance(i))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(i);
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
if (vReg.getColor() > LAST_GREGISTER)
|
||||
PR_ASSERT(false);
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
#if NUMBER_OF_FPREGISTERS != 0
|
||||
if (vReg.getColor() > LAST_FPREGISTER)
|
||||
PR_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
vRegManager.nUsedStackSlots = lastUsedSSR + 1;
|
||||
return success;
|
||||
}
|
||||
#endif // NEW_LAURENTM_CODE
|
||||
284
mozilla/ef/Compiler/RegisterAllocator/Coloring.h
Normal file
284
mozilla/ef/Compiler/RegisterAllocator/Coloring.h
Normal file
@@ -0,0 +1,284 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "InterferenceGraph.h"
|
||||
#include "SparseSet.h"
|
||||
#include "Spilling.h"
|
||||
#include "Splits.h"
|
||||
|
||||
UT_EXTERN_LOG_MODULE(RegAlloc);
|
||||
|
||||
template <class RegisterPressure>
|
||||
class Coloring
|
||||
{
|
||||
private:
|
||||
static RegisterName* simplify(RegisterAllocator& registerAllocator, RegisterName* coloringStack);
|
||||
static bool select(RegisterAllocator& registerAllocator, RegisterName* coloringStack, RegisterName* coloringStackPtr);
|
||||
|
||||
public:
|
||||
static bool color(RegisterAllocator& registerAllocator);
|
||||
static void finalColoring(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Coloring<RegisterPressure>::finalColoring(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
RegisterName* color = registerAllocator.color;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
usePtr->setRegisterName(color[name2range[usePtr->getRegisterName()]]);
|
||||
#ifdef DEBUG
|
||||
RegisterID rid = usePtr->getRegisterID();
|
||||
setColoredRegister(rid);
|
||||
usePtr->setRegisterID(rid);
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
definePtr->setRegisterName(color[name2range[definePtr->getRegisterName()]]);
|
||||
#ifdef DEBUG
|
||||
RegisterID rid = definePtr->getRegisterID();
|
||||
setColoredRegister(rid);
|
||||
definePtr->setRegisterID(rid);
|
||||
#endif // DEBUG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Coloring<RegisterPressure>::select(RegisterAllocator& registerAllocator, RegisterName* coloringStack, RegisterName* coloringStackPtr)
|
||||
{
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* color = new RegisterName[rangeCount];
|
||||
registerAllocator.color = color;
|
||||
|
||||
for (Uint32 r = 1; r < rangeCount; r++)
|
||||
color[r] = RegisterName(6); // FIX;
|
||||
|
||||
// Color the preColored registers.
|
||||
//
|
||||
VirtualRegisterManager& vrManager = registerAllocator.vrManager;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
PreColoredRegister* machineEnd = vrManager.getMachineRegistersEnd();
|
||||
for (PreColoredRegister* machinePtr = vrManager.getMachineRegistersBegin(); machinePtr < machineEnd; machinePtr++)
|
||||
if (machinePtr->id != invalidID) {
|
||||
color[name2range[getName(machinePtr->id)]] = machinePtr->color;
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\twill preColor range %d as %d\n", name2range[getName(machinePtr->id)], machinePtr->color));
|
||||
}
|
||||
|
||||
SpillCost* cost = registerAllocator.spillCost;
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet& spill = *new(pool) SparseSet(pool, rangeCount);
|
||||
registerAllocator.willSpill = &spill;
|
||||
SparseSet neighborColors(pool, 6); // FIX
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
|
||||
bool coloringFailed = false;
|
||||
while (coloringStackPtr > coloringStack) {
|
||||
RegisterName range = *--coloringStackPtr;
|
||||
|
||||
if (!cost[range].infinite && cost[range].cost < 0) {
|
||||
coloringFailed = true;
|
||||
spill.set(range);
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tfailed to color %d, will spill.\n", range));
|
||||
} else {
|
||||
neighborColors.clear();
|
||||
|
||||
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
|
||||
for (Int32 i = vector->count - 1; i >= 0; --i) {
|
||||
RegisterName neighborColor = color[vector->neighbors[i]];
|
||||
if (neighborColor < 6) // FIX
|
||||
neighborColors.set(neighborColor);
|
||||
}
|
||||
|
||||
if (neighborColors.getSize() == 6) { // FIX
|
||||
coloringFailed = true;
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tfailed to color %d, ", range));
|
||||
|
||||
if (!Splits<RegisterPressure>::findSplit(registerAllocator, color, range)) {
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("will spill.\n"));
|
||||
spill.set(range);
|
||||
} else
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("will split.\n"));
|
||||
} else {
|
||||
for (Uint32 i = 0; i < 6; i++) // FIX
|
||||
if (!neighborColors.test(i)) {
|
||||
fprintf(stdout, "\twill color %d as %d\n", range, i);
|
||||
color[range] = RegisterName(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
if (coloringFailed) {
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring failed:\n"));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\twill spill: "));
|
||||
spill.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
} else {
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring succeeded:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++)
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\trange %d colored as %d\n", i, color[i]));
|
||||
}
|
||||
#endif
|
||||
|
||||
return !coloringFailed;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
RegisterName* Coloring<RegisterPressure>::simplify(RegisterAllocator& registerAllocator, RegisterName* coloringStack)
|
||||
{
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
SpillCost* spillCost = registerAllocator.spillCost;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
|
||||
Uint32* degree = new Uint32[rangeCount];
|
||||
for (RegisterName i = RegisterName(1); i < rangeCount; i = RegisterName(i + 1)) {
|
||||
InterferenceVector* vector = iGraph.getInterferenceVector(i);
|
||||
degree[i] = (vector != NULL) ? vector->count : 0;
|
||||
}
|
||||
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet low(pool, rangeCount);
|
||||
SparseSet high(pool, rangeCount);
|
||||
SparseSet highInfinite(pool, rangeCount);
|
||||
SparseSet preColored(pool, rangeCount);
|
||||
|
||||
// Get the precolored registers.
|
||||
//
|
||||
VirtualRegisterManager& vrManager = registerAllocator.vrManager;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
PreColoredRegister* machineEnd = vrManager.getMachineRegistersEnd();
|
||||
for (PreColoredRegister* machinePtr = vrManager.getMachineRegistersBegin(); machinePtr < machineEnd; machinePtr++)
|
||||
if (machinePtr->id != invalidID)
|
||||
preColored.set(name2range[getName(machinePtr->id)]);
|
||||
|
||||
// Insert the live ranges in the sets.
|
||||
//
|
||||
for (Uint32 range = 1; range < rangeCount; range++)
|
||||
if (!preColored.test(range))
|
||||
if (degree[range] < 6) // FIX
|
||||
low.set(range);
|
||||
else if (!spillCost[range].infinite)
|
||||
high.set(range);
|
||||
else
|
||||
highInfinite.set(range);
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring sets:\n\tlow = "));
|
||||
low.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\thigh = "));
|
||||
high.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\thighInfinite = "));
|
||||
highInfinite.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tpreColored = "));
|
||||
preColored.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
RegisterName* coloringStackPtr = coloringStack;
|
||||
|
||||
while (low.getSize() != 0 || high.getSize() != 0) {
|
||||
while (low.getSize() != 0) {
|
||||
RegisterName range = RegisterName(low.getOne());
|
||||
low.clear(range);
|
||||
*coloringStackPtr++ = range;
|
||||
|
||||
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
|
||||
for (Int32 i = (vector->count - 1); i >= 0; --i) {
|
||||
RegisterName neighbor = vector->neighbors[i];
|
||||
degree[neighbor]--;
|
||||
|
||||
if (degree[neighbor] < 6) // FIX
|
||||
if (high.test(neighbor)) {
|
||||
high.clear(neighbor);
|
||||
low.set(neighbor);
|
||||
} else if (highInfinite.test(neighbor)) {
|
||||
highInfinite.clear(neighbor);
|
||||
low.set(neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (high.getSize() != 0) {
|
||||
RegisterName best = RegisterName(high.getOne());
|
||||
double bestCost = spillCost[best].cost;
|
||||
double bestDegree = degree[best];
|
||||
|
||||
// Choose the next best candidate.
|
||||
//
|
||||
for (SparseSet::iterator i = high.begin(); !high.done(i); i = high.advance(i)) {
|
||||
RegisterName range = RegisterName(high.get(i));
|
||||
double thisCost = spillCost[range].cost;
|
||||
double thisDegree = degree[range];
|
||||
|
||||
if (thisCost * bestDegree < bestCost * thisDegree) {
|
||||
best = range;
|
||||
bestCost = thisCost;
|
||||
bestDegree = thisDegree;
|
||||
}
|
||||
}
|
||||
|
||||
high.clear(best);
|
||||
low.set(best);
|
||||
}
|
||||
}
|
||||
assert(highInfinite.getSize() == 0);
|
||||
|
||||
delete degree;
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring stack:\n\t"));
|
||||
for (RegisterName* sp = coloringStack; sp < coloringStackPtr; ++sp)
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("%d ", *sp));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\n"));
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
return coloringStackPtr;
|
||||
}
|
||||
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Coloring<RegisterPressure>::color(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
RegisterName* coloringStack = new RegisterName[registerAllocator.rangeCount];
|
||||
return select(registerAllocator, coloringStack, simplify(registerAllocator, coloringStack));
|
||||
}
|
||||
212
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.cpp
Normal file
212
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
|
||||
#include "DominatorGraph.h"
|
||||
|
||||
DominatorGraph::DominatorGraph(ControlGraph& controlGraph) : controlGraph(controlGraph)
|
||||
{
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
GtoV = new Uint32[nNodes + 1];
|
||||
VtoG = new Uint32[nNodes + 1];
|
||||
|
||||
Uint32 v = 1;
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
VtoG[v] = n;
|
||||
GtoV[n] = v++;
|
||||
}
|
||||
|
||||
// Initialize all the 1-based arrays.
|
||||
//
|
||||
parent = new Uint32[v];
|
||||
semi = new Uint32[v];
|
||||
vertex = new Uint32[v];
|
||||
label = new Uint32[v];
|
||||
size = new Uint32[v];
|
||||
ancestor = new Uint32[v];
|
||||
child = new Uint32[v];
|
||||
dom = new Uint32[v];
|
||||
bucket = new DGLinkedList*[v];
|
||||
|
||||
memset(semi, '\0', v * sizeof(Uint32));
|
||||
memset(bucket, '\0', v * sizeof(DGLinkedList*));
|
||||
|
||||
vCount = v;
|
||||
|
||||
build();
|
||||
|
||||
delete parent;
|
||||
delete semi;
|
||||
delete vertex;
|
||||
delete label;
|
||||
delete size;
|
||||
delete ancestor;
|
||||
delete child;
|
||||
delete dom;
|
||||
delete bucket;
|
||||
}
|
||||
|
||||
Uint32 DominatorGraph::DFS(Uint32 vx, Uint32 n)
|
||||
{
|
||||
semi[vx] = ++n;
|
||||
vertex[n] = label[vx] = vx;
|
||||
ancestor[vx] = child[vx] = 0;
|
||||
size[vx] = 1;
|
||||
|
||||
|
||||
ControlNode& node = *controlGraph.dfsList[VtoG[vx]];
|
||||
ControlEdge* successorEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorPtr = node.getSuccessorsBegin(); successorPtr < successorEnd; successorPtr++) {
|
||||
Uint32 w = GtoV[successorPtr->getTarget().dfsNum];
|
||||
if (semi[w] == 0) {
|
||||
parent[w] = vx;
|
||||
n = DFS(w, n);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void DominatorGraph::LINK(Uint32 vx, Uint32 w)
|
||||
{
|
||||
Uint32 s = w;
|
||||
|
||||
while (semi[label[w]] < semi[label[child[s]]]) {
|
||||
if (size[s] + size[child[child[s]]] >= (size[child[s]] << 1)) {
|
||||
ancestor[child[s]] = s;
|
||||
child[s] = child[child[s]];
|
||||
} else {
|
||||
size[child[s]] = size[s];
|
||||
s = ancestor[s] = child[s];
|
||||
}
|
||||
}
|
||||
label[s] = label[w];
|
||||
size[vx] += size[w];
|
||||
if(size[vx] < (size[w] << 1)) {
|
||||
Uint32 t = s;
|
||||
s = child[vx];
|
||||
child[vx] = t;
|
||||
}
|
||||
while( s != 0 ) {
|
||||
ancestor[s] = vx;
|
||||
s = child[s];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DominatorGraph::COMPRESS(Uint32 vx)
|
||||
{
|
||||
if(ancestor[ancestor[vx]] != 0) {
|
||||
COMPRESS(ancestor[vx]);
|
||||
if(semi[label[ancestor[vx]]] < semi[label[vx]])
|
||||
label[vx] = label[ancestor[vx]];
|
||||
ancestor[vx] = ancestor[ancestor[vx]];
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 DominatorGraph::EVAL(Uint32 vx)
|
||||
{
|
||||
if(ancestor[vx] == 0)
|
||||
return label[vx];
|
||||
COMPRESS(vx);
|
||||
return (semi[label[ancestor[vx]]] >= semi[label[vx]]) ? label[vx] : label[ancestor[vx]];
|
||||
}
|
||||
|
||||
void DominatorGraph::build()
|
||||
{
|
||||
Uint32 n = DFS(GtoV[0], 0);
|
||||
size[0] = label[0] = semi[0];
|
||||
|
||||
for (Uint32 i = n; i >= 2; i--) {
|
||||
Uint32 w = vertex[i];
|
||||
|
||||
ControlNode& node = *controlGraph.dfsList[VtoG[w]];
|
||||
const DoublyLinkedList<ControlEdge>& predecessors = node.getPredecessors();
|
||||
for (DoublyLinkedList<ControlEdge>::iterator p = predecessors.begin(); !predecessors.done(p); p = predecessors.advance(p)) {
|
||||
Uint32 vx = GtoV[predecessors.get(p).getSource().dfsNum];
|
||||
Uint32 u = EVAL(vx);
|
||||
|
||||
if(semi[u] < semi[w])
|
||||
semi[w] = semi[u];
|
||||
}
|
||||
|
||||
DGLinkedList* elem = new DGLinkedList();
|
||||
elem->next = bucket[vertex[semi[w]]];
|
||||
elem->index = w;
|
||||
bucket[vertex[semi[w]]] = elem;
|
||||
|
||||
LINK(parent[w], w);
|
||||
|
||||
elem = bucket[parent[w]];
|
||||
while(elem != NULL) {
|
||||
Uint32 vx = elem->index;
|
||||
Uint32 u = EVAL(vx);
|
||||
dom[vx] = (semi[u] < semi[vx]) ? u : parent[w];
|
||||
elem = elem->next;
|
||||
}
|
||||
}
|
||||
|
||||
memset(size, '\0', n * sizeof(Uint32));
|
||||
Pool& pool = controlGraph.pool;
|
||||
nodes = new(pool) DGNode[n];
|
||||
|
||||
for(Uint32 j = 2; j <= n; j++) {
|
||||
Uint32 w = vertex[j];
|
||||
Uint32 d = dom[w];
|
||||
if(d != vertex[semi[w]]) {
|
||||
d = dom[d];
|
||||
dom[w] = d;
|
||||
}
|
||||
size[d]++;
|
||||
}
|
||||
dom[GtoV[0]] = 0;
|
||||
|
||||
for (Uint32 k = 1; k <= n; k++) {
|
||||
DGNode& node = nodes[VtoG[k]];
|
||||
Uint32 count = size[k];
|
||||
node.successorsEnd = node.successorsBegin = (count) ? new(pool) Uint32[count] : (Uint32*) 0;
|
||||
}
|
||||
|
||||
for (Uint32 l = 2; l <= n; l++)
|
||||
*(nodes[VtoG[dom[l]]].successorsEnd)++ = VtoG[l];
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
void DominatorGraph::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Dominator Graph:\n"));
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
for (Uint32 i = 0; i < nNodes; i++) {
|
||||
DGNode& node = nodes[i];
|
||||
if (node.successorsBegin != node.successorsEnd) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tN%d dominates ", i));
|
||||
for (Uint32* successorsPtr = node.successorsBegin; successorsPtr < node.successorsEnd; successorsPtr++)
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("N%d ", *successorsPtr));
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
|
||||
|
||||
80
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.h
Normal file
80
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _DOMINATOR_GRAPH_H_
|
||||
#define _DOMINATOR_GRAPH_H_
|
||||
|
||||
#include "LogModule.h"
|
||||
|
||||
class ControlGraph;
|
||||
|
||||
struct DGNode
|
||||
{
|
||||
Uint32* successorsBegin;
|
||||
Uint32* successorsEnd;
|
||||
};
|
||||
|
||||
struct DGLinkedList
|
||||
{
|
||||
DGLinkedList* next;
|
||||
Uint32 index;
|
||||
};
|
||||
|
||||
class DominatorGraph
|
||||
{
|
||||
private:
|
||||
|
||||
ControlGraph& controlGraph;
|
||||
|
||||
Uint32 vCount;
|
||||
|
||||
Uint32* VtoG;
|
||||
Uint32* GtoV;
|
||||
Uint32* parent;
|
||||
Uint32* semi;
|
||||
Uint32* vertex;
|
||||
Uint32* label;
|
||||
Uint32* size;
|
||||
Uint32* ancestor;
|
||||
Uint32* child;
|
||||
Uint32* dom;
|
||||
DGLinkedList** bucket;
|
||||
DGNode* nodes;
|
||||
|
||||
private:
|
||||
|
||||
void build();
|
||||
|
||||
Uint32 DFS(Uint32 vx, Uint32 n);
|
||||
void LINK(Uint32 vx, Uint32 w);
|
||||
void COMPRESS(Uint32 vx);
|
||||
Uint32 EVAL(Uint32 vx);
|
||||
|
||||
public:
|
||||
|
||||
DominatorGraph(ControlGraph& controlGraph);
|
||||
|
||||
Uint32* getSuccessorsBegin(Uint32 n) const {return nodes[n].successorsBegin;}
|
||||
Uint32* getSuccessorsEnd(Uint32 n) const {return nodes[n].successorsEnd;}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
#endif // _DOMINATOR_GRAPH_H_
|
||||
20
mozilla/ef/Compiler/RegisterAllocator/HashSet.cpp
Normal file
20
mozilla/ef/Compiler/RegisterAllocator/HashSet.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "HashSet.h"
|
||||
97
mozilla/ef/Compiler/RegisterAllocator/HashSet.h
Normal file
97
mozilla/ef/Compiler/RegisterAllocator/HashSet.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _HASH_SET_H_
|
||||
#define _HASH_SET_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include <string.h>
|
||||
|
||||
struct HashSetElement
|
||||
{
|
||||
Uint32 index;
|
||||
HashSetElement* next;
|
||||
};
|
||||
|
||||
class HashSet
|
||||
{
|
||||
private:
|
||||
|
||||
static const hashSize = 64;
|
||||
|
||||
// Return the hash code for the given element index.
|
||||
static Uint32 getHashCode(Uint32 index) {return index & (hashSize - 1);} // Could be better !
|
||||
|
||||
private:
|
||||
|
||||
Pool& allocationPool;
|
||||
HashSetElement** bucket;
|
||||
HashSetElement* free;
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
HashSet(const HashSet&);
|
||||
// No copy operator.
|
||||
void operator = (const HashSet&);
|
||||
|
||||
public:
|
||||
|
||||
// Create a new HashSet.
|
||||
inline HashSet(Pool& pool, Uint32 universeSize);
|
||||
|
||||
// Clear the hashset.
|
||||
void clear();
|
||||
// Clear the element for the given index.
|
||||
void clear(Uint32 index);
|
||||
// Set the element for the given index.
|
||||
void set(Uint32 index);
|
||||
// Return true if the element at index is a member.
|
||||
bool test(Uint32 index) const;
|
||||
// Union with the given hashset.
|
||||
inline void or(const HashSet& set);
|
||||
// Intersection with the given hashset.
|
||||
inline void and(const HashSet& set);
|
||||
// Difference with the given hashset.
|
||||
inline void difference(const HashSet& set);
|
||||
|
||||
// Logical operators.
|
||||
HashSet& operator |= (const HashSet& set) {or(set); return *this;}
|
||||
HashSet& operator &= (const HashSet& set) {and(set); return *this;}
|
||||
HashSet& operator -= (const HashSet& set) {difference(set); return *this;}
|
||||
|
||||
// Iterator to conform with the set API.
|
||||
typedef HashSetElement* iterator;
|
||||
// Return the iterator for the first element of this set.
|
||||
iterator begin() const;
|
||||
// Return the next iterator.
|
||||
iterator advance(iterator pos) const;
|
||||
// Return true if the iterator is at the end of the set.
|
||||
bool done(iterator pos) const {return pos == NULL;}
|
||||
};
|
||||
|
||||
|
||||
inline HashSet::HashSet(Pool& pool, Uint32 /*universeSize*/)
|
||||
: allocationPool(pool), free(NULL)
|
||||
{
|
||||
bucket = new(pool) HashSetElement*[hashSize];
|
||||
memset(bucket, '\0', sizeof(HashSetElement*));
|
||||
}
|
||||
|
||||
#endif // _HASH_SET_H_
|
||||
213
mozilla/ef/Compiler/RegisterAllocator/IndexedPool.h
Normal file
213
mozilla/ef/Compiler/RegisterAllocator/IndexedPool.h
Normal file
@@ -0,0 +1,213 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _INDEXED_POOL_H_
|
||||
#define _INDEXED_POOL_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// IndexedPool<IndexedObjectSubclass> is an indexed pool of objects. The
|
||||
// template parameter 'IndexedObjectSubclass' must be a subclass of the struct
|
||||
// IndexedObject.
|
||||
//
|
||||
// When the indexed pool is ask to allocate and initialize a new object (using
|
||||
// the operator new(anIndexedPool) it will zero the memory used to store the
|
||||
// object and initialize the field 'index' of this object to its position in
|
||||
// the pool.
|
||||
//
|
||||
// An object allocated by the indexed pool can be freed by calling the method
|
||||
// IndexedPool::release(IndexedElement& objectIndex).
|
||||
//
|
||||
// example:
|
||||
//
|
||||
// IndexedPool<IndexedElement> elementPool;
|
||||
//
|
||||
// IndexedElement& element1 = *new(elementPool) IndexedElement();
|
||||
// IndexedElement& element2 = *new(elementPool) IndexedElement();
|
||||
//
|
||||
// indexedPool.release(element1);
|
||||
// IndexedElement& element3 = *new(elementPool) IndexedElement();
|
||||
//
|
||||
// At this point element1 is no longer a valid object, element2 is at
|
||||
// index 2 and element3 is at index 1.
|
||||
//
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// IndexedObject -
|
||||
//
|
||||
|
||||
template<class Object>
|
||||
struct IndexedObject
|
||||
{
|
||||
Uint32 index; // Index in the pool.
|
||||
Object* next; // Used to link IndexedObject together.
|
||||
|
||||
Uint32 getIndex() {return index;}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// IndexedPool<IndexedObject> -
|
||||
//
|
||||
|
||||
template <class IndexedObject>
|
||||
class IndexedPool
|
||||
{
|
||||
private:
|
||||
|
||||
static const blockSize = 4; // Size of one block.
|
||||
|
||||
Uint32 nBlocks; // Number of blocks in the pool.
|
||||
IndexedObject** block; // Array of block pointers.
|
||||
IndexedObject* freeObjects; // Chained list of free IndexedObjects.
|
||||
Uint32 nextIndex; // Index of the next free object in the last block.
|
||||
|
||||
private:
|
||||
|
||||
void allocateAnotherBlock();
|
||||
IndexedObject& newObject();
|
||||
|
||||
public:
|
||||
|
||||
IndexedPool() : nBlocks(0), block(NULL), freeObjects(NULL), nextIndex(1) {}
|
||||
~IndexedPool();
|
||||
|
||||
IndexedObject& get(Uint32 index) const;
|
||||
void release(IndexedObject& object);
|
||||
|
||||
void setSize(Uint32 size) {assert(size < nextIndex); nextIndex = size;}
|
||||
|
||||
// Return the universe size.
|
||||
Uint32 getSize() {return nextIndex;}
|
||||
|
||||
friend void* operator new(size_t, IndexedPool<IndexedObject>& pool); // Needs to call newObject().
|
||||
};
|
||||
|
||||
// Free all the memory allocated for this object.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
IndexedPool<IndexedObject>::~IndexedPool()
|
||||
{
|
||||
for (Uint32 n = 0; n < nBlocks; n++)
|
||||
free(&((IndexedObject **) &block[n][n*blockSize])[-(n + 1)]);
|
||||
}
|
||||
|
||||
// Release the given. This object will be iserted in the chained
|
||||
// list of free IndexedObjects. To minimize the fragmentation the chained list
|
||||
// is ordered by ascending indexes.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
void IndexedPool<IndexedObject>::release(IndexedObject& object)
|
||||
{
|
||||
Uint32 index = object.index;
|
||||
IndexedObject* list = freeObjects;
|
||||
|
||||
assert(&object == &get(index)); // Make sure that object is owned by this pool.
|
||||
|
||||
if (list == NULL) { // The list is empty.
|
||||
freeObjects = &object;
|
||||
object.next = NULL;
|
||||
} else { // The list contains at least 1 element.
|
||||
if (index < list->index) { // insert as first element.
|
||||
freeObjects = &object;
|
||||
object.next = list;
|
||||
} else { // Find this object's place.
|
||||
while ((list->next) != NULL && (list->next->index < index))
|
||||
list = list->next;
|
||||
|
||||
object.next = list->next;
|
||||
list->next = &object;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Sanity check to be sure that the list is correctly ordered.
|
||||
for (IndexedObject* obj = freeObjects; obj != NULL; obj = obj->next)
|
||||
if (obj->next != NULL)
|
||||
assert(obj->index < obj->next->index);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Create a new block of IndexedObjects. We will allocate the memory to
|
||||
// store IndexedPool::blockSize IndexedObject and the new Array of block
|
||||
// pointers.
|
||||
// The newly created IndexedObjects will not be initialized.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
void IndexedPool<IndexedObject>::allocateAnotherBlock()
|
||||
{
|
||||
void* memory = (void *) malloc((nBlocks + 1) * sizeof(Uint32) + blockSize * sizeof(IndexedObject));
|
||||
|
||||
memcpy(memory, block, nBlocks * sizeof(Uint32));
|
||||
|
||||
block = (IndexedObject **) memory;
|
||||
IndexedObject* objects = (IndexedObject *) &block[nBlocks + 1];
|
||||
|
||||
block[nBlocks] = &objects[-(nBlocks * blockSize)];
|
||||
nBlocks++;
|
||||
}
|
||||
|
||||
// Return the IndexedObject at the position 'index' in the pool.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
IndexedObject& IndexedPool<IndexedObject>::get(Uint32 index) const
|
||||
{
|
||||
Uint32 blockIndex = index / blockSize;
|
||||
assert(blockIndex < nBlocks);
|
||||
|
||||
return block[blockIndex][index];
|
||||
}
|
||||
|
||||
// Return the reference of an unused object in the pool.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
IndexedObject& IndexedPool<IndexedObject>::newObject()
|
||||
{
|
||||
if (freeObjects != NULL) {
|
||||
IndexedObject& newObject = *freeObjects;
|
||||
freeObjects = newObject.next;
|
||||
return newObject;
|
||||
}
|
||||
|
||||
Uint32 nextIndex = this->nextIndex++;
|
||||
Uint32 blockIndex = nextIndex / blockSize;
|
||||
|
||||
while (blockIndex >= nBlocks)
|
||||
allocateAnotherBlock();
|
||||
|
||||
IndexedObject& newObject = block[blockIndex][nextIndex];
|
||||
newObject.index = nextIndex;
|
||||
|
||||
return newObject;
|
||||
}
|
||||
|
||||
// Return the address of the next unsused object in the given
|
||||
// indexed pool. The field index of the newly allocated object
|
||||
// will be initialized to the corresponding index of this object
|
||||
// in the pool.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
void* operator new(size_t size, IndexedPool<IndexedObject>& pool)
|
||||
{
|
||||
assert(size == sizeof(IndexedObject));
|
||||
return (void *) &pool.newObject();
|
||||
}
|
||||
|
||||
#endif // _INDEXED_POOL_H_
|
||||
258
mozilla/ef/Compiler/RegisterAllocator/InterferenceGraph.h
Normal file
258
mozilla/ef/Compiler/RegisterAllocator/InterferenceGraph.h
Normal file
@@ -0,0 +1,258 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _INTERFERENCE_GRAPH_H_
|
||||
#define _INTERFERENCE_GRAPH_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "Primitives.h"
|
||||
#include "Instruction.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "SparseSet.h"
|
||||
#include <string.h>
|
||||
|
||||
struct InterferenceVector
|
||||
{
|
||||
Uint32 count;
|
||||
InterferenceVector* next;
|
||||
RegisterName* neighbors;
|
||||
|
||||
InterferenceVector() : count(0), next(NULL) {}
|
||||
};
|
||||
|
||||
class RegisterAllocator;
|
||||
|
||||
template <class RegisterPressure>
|
||||
class InterferenceGraph
|
||||
{
|
||||
private:
|
||||
|
||||
RegisterAllocator& registerAllocator;
|
||||
|
||||
RegisterPressure::Set* interferences;
|
||||
InterferenceVector** vector;
|
||||
Uint32* offset;
|
||||
Uint32 rangeCount;
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
InterferenceGraph(const InterferenceGraph&);
|
||||
// No copy operator.
|
||||
void operator = (const InterferenceGraph&);
|
||||
|
||||
// Check if reg is a member of the universe.
|
||||
void checkMember(RegisterName name) {assert(name < rangeCount);}
|
||||
// Return the edge index for the interference between name1 and name2.
|
||||
Uint32 getEdgeIndex(RegisterName name1, RegisterName name2);
|
||||
|
||||
public:
|
||||
InterferenceGraph(RegisterAllocator& registerAllocator) : registerAllocator(registerAllocator) {}
|
||||
|
||||
// Calculate the interferences.
|
||||
void build();
|
||||
// Return true if reg1 and reg2 interfere.
|
||||
bool interfere(RegisterName name1, RegisterName name2);
|
||||
// Return the interference vector for the given register or NULL if there is none.
|
||||
InterferenceVector* getInterferenceVector(RegisterName name) {return vector[name];}
|
||||
// Set the interference between name1 and name2.
|
||||
void setInterference(RegisterName name1, RegisterName name2);
|
||||
// Set the interference vector for the given register.
|
||||
void setInterferenceVector(RegisterName name, InterferenceVector* v) {vector[name] = v;}
|
||||
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the interferences.
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void InterferenceGraph<RegisterPressure>::build()
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
this->rangeCount = rangeCount;
|
||||
|
||||
// Initialize the structures.
|
||||
//
|
||||
offset = new(pool) Uint32[rangeCount + 1];
|
||||
vector = new(pool) InterferenceVector*[rangeCount];
|
||||
memset(vector, '\0', sizeof(InterferenceVector*) * rangeCount);
|
||||
|
||||
Uint32 o = 0;
|
||||
offset[0] = 0;
|
||||
for (Uint32 i = 1; i <= rangeCount; ++i) {
|
||||
offset[i] = o;
|
||||
o += i;
|
||||
}
|
||||
|
||||
interferences = new(pool) RegisterPressure::Set(pool, (rangeCount * rangeCount) / 2);
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
LivenessInfo<RegisterPressure> liveness = Liveness<RegisterPressure>::analysis(controlGraph, rangeCount, name2range);
|
||||
registerAllocator.liveness = liveness;
|
||||
SparseSet currentLive(pool, rangeCount);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
currentLive = liveness.liveOut[n];
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
// Handle the copy instruction to avoid unnecessary interference between the 2 registers.
|
||||
if ((instruction.getFlags() & ifCopy) != 0) {
|
||||
assert(useBegin != useEnd && useBegin[0].isRegister());
|
||||
currentLive.clear(name2range[useBegin[0].getRegisterName()]);
|
||||
}
|
||||
|
||||
// Create the interferences.
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName define = name2range[definePtr->getRegisterName()];
|
||||
|
||||
for (SparseSet::iterator e = currentLive.begin(); !currentLive.done(e); e = currentLive.advance(e)) {
|
||||
RegisterName live = RegisterName(currentLive.get(e));
|
||||
|
||||
if ((live != define) && !interfere(live, define) && registerAllocator.canInterfere(live, define)) {
|
||||
|
||||
if (vector[define] == NULL)
|
||||
vector[define] = new(pool) InterferenceVector();
|
||||
vector[define]->count++;
|
||||
|
||||
if (vector[live] == NULL)
|
||||
vector[live] = new(pool) InterferenceVector();
|
||||
vector[live]->count++;
|
||||
|
||||
setInterference(live, define);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now update the liveness.
|
||||
//
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentLive.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
currentLive.set(name2range[usePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate the memory to store the interferences.
|
||||
//
|
||||
for (Uint32 e = 0; e < rangeCount; e++)
|
||||
if (vector[e] != NULL) {
|
||||
InterferenceVector& v = *vector[e];
|
||||
v.neighbors = new(pool) RegisterName[v.count];
|
||||
v.count = 0;
|
||||
}
|
||||
|
||||
// Initialize the edges.
|
||||
//
|
||||
if (RegisterPressure::Set::isOrdered()) {
|
||||
RegisterName name1 = RegisterName(0);
|
||||
|
||||
for (RegisterPressure::Set::iterator i = interferences->begin(); !interferences->done(i); i = interferences->advance(i)) {
|
||||
Uint32 interferenceIndex = interferences->get(i);
|
||||
|
||||
while(interferenceIndex >= offset[name1 + 1])
|
||||
name1 = RegisterName(name1 + 1);
|
||||
|
||||
assert((interferenceIndex >= offset[name1]) && (interferenceIndex < offset[name1 + 1]));
|
||||
|
||||
RegisterName name2 = RegisterName(interferenceIndex - offset[name1]);
|
||||
|
||||
assert(interfere(name1, name2));
|
||||
|
||||
InterferenceVector& vector1 = *vector[name1];
|
||||
vector1.neighbors[vector1.count++] = name2;
|
||||
|
||||
InterferenceVector& vector2 = *vector[name2];
|
||||
vector2.neighbors[vector2.count++] = name1;
|
||||
}
|
||||
} else {
|
||||
trespass("not Implemented"); // FIX: need one more pass to initialize the vectors.
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
Uint32 InterferenceGraph<RegisterPressure>::getEdgeIndex(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
checkMember(name1); checkMember(name2);
|
||||
assert(name1 != name2); // This is not possible.
|
||||
return (name1 < name2) ? offset[name2] + name1 : offset[name1] + name2;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void InterferenceGraph<RegisterPressure>::setInterference(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
interferences->set(getEdgeIndex(name1, name2));
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool InterferenceGraph<RegisterPressure>::interfere(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
return interferences->test(getEdgeIndex(name1, name2));
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
template <class RegisterPressure>
|
||||
void InterferenceGraph<RegisterPressure>::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Interference Vectors:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++) {
|
||||
if (vector[i] != NULL) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tvr%d: (", i));
|
||||
for (InterferenceVector* v = vector[i]; v != NULL; v = v->next)
|
||||
for (Uint32 j = 0; j < v->count; j++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%d", v->neighbors[j]));
|
||||
if (v->next != NULL || j != (v->count - 1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (","));
|
||||
}
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (")\n"));
|
||||
}
|
||||
}
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Interference Matrix:\n"));
|
||||
for (RegisterName name1 = RegisterName(1); name1 < rangeCount; name1 = RegisterName(name1 + 1)) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\t%d:\t", name1));
|
||||
for (RegisterName name2 = RegisterName(1); name2 < rangeCount; name2 = RegisterName(name2 + 1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%c", ((name1 != name2) && interfere(name1, name2)) ? '1' : '0'));
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#endif // _INTERFERENCE_GRAPH_H_
|
||||
87
mozilla/ef/Compiler/RegisterAllocator/LiveRange.h
Normal file
87
mozilla/ef/Compiler/RegisterAllocator/LiveRange.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIVE_RANGE_H_
|
||||
#define _LIVE_RANGE_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Primitives.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct LiveRange
|
||||
{
|
||||
static void build(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void LiveRange<RegisterPressure>::build(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
// Intialize the lookup table.
|
||||
//
|
||||
Uint32 nameCount = registerAllocator.nameCount;
|
||||
RegisterName* nameTable = new(registerAllocator.pool) RegisterName[2*nameCount];
|
||||
RegisterName* rangeName = &nameTable[nameCount];
|
||||
|
||||
init(rangeName, nameCount);
|
||||
|
||||
// Walk the graph.
|
||||
//
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
SparseSet destination(registerAllocator.pool, nameCount);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
|
||||
destination.clear();
|
||||
for (InstructionList::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
|
||||
Instruction& phiNode = phiNodes.get(i);
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
|
||||
destination.set(findRoot(phiNode.getInstructionDefineBegin()[0].getRegisterName(), rangeName));
|
||||
}
|
||||
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
|
||||
RegisterName destinationName = phiNode.getInstructionDefineBegin()[0].getRegisterName();
|
||||
RegisterName destinationRoot = findRoot(destinationName, rangeName);
|
||||
|
||||
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++) {
|
||||
assert(usePtr->isRegister());
|
||||
RegisterName sourceName = usePtr->getRegisterName();
|
||||
RegisterName sourceRoot = findRoot(sourceName, rangeName);
|
||||
|
||||
if (sourceRoot != destinationRoot && !destination.test(sourceRoot))
|
||||
rangeName[sourceRoot] = destinationRoot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerAllocator.rangeCount = compress(registerAllocator.name2range, rangeName, nameCount, nameCount);
|
||||
}
|
||||
|
||||
#endif // _LIVE_RANGE_H_
|
||||
163
mozilla/ef/Compiler/RegisterAllocator/LiveRangeGraph.h
Normal file
163
mozilla/ef/Compiler/RegisterAllocator/LiveRangeGraph.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIVE_RANGE_GRAPH_
|
||||
#define _LIVE_RANGE_GRAPH_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterTypes.h"
|
||||
|
||||
class RegisterAllocator;
|
||||
|
||||
template <class RegisterPressure>
|
||||
class LiveRangeGraph
|
||||
{
|
||||
private:
|
||||
|
||||
RegisterAllocator& registerAllocator;
|
||||
|
||||
RegisterPressure::Set* edges;
|
||||
Uint32 rangeCount;
|
||||
|
||||
public:
|
||||
//
|
||||
//
|
||||
LiveRangeGraph(RegisterAllocator& registerAllocator) : registerAllocator(registerAllocator) {}
|
||||
|
||||
//
|
||||
//
|
||||
void build();
|
||||
|
||||
//
|
||||
//
|
||||
void addEdge(RegisterName name1, RegisterName name2);
|
||||
|
||||
//
|
||||
//
|
||||
bool haveEdge(RegisterName name1, RegisterName name2);
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
//
|
||||
//
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void LiveRangeGraph<RegisterPressure>::build()
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
this->rangeCount = rangeCount;
|
||||
|
||||
edges = new(pool) RegisterPressure::Set(pool, rangeCount * rangeCount);
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
LivenessInfo<RegisterPressure>& liveness = registerAllocator.liveness;
|
||||
SparseSet currentLive(pool, rangeCount);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
currentLive = liveness.liveOut[n];
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
if ((instruction.getFlags() & ifCopy) != 0) {
|
||||
assert(useBegin != useEnd && useBegin[0].isRegister());
|
||||
currentLive.clear(name2range[useBegin[0].getRegisterName()]);
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName define = name2range[definePtr->getRegisterName()];
|
||||
|
||||
for (SparseSet::iterator l = currentLive.begin(); !currentLive.done(l); l = currentLive.advance(l)) {
|
||||
RegisterName live = RegisterName(currentLive.get(l));
|
||||
if (define != live && registerAllocator.canInterfere(define, live))
|
||||
addEdge(define, live);
|
||||
}
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentLive.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
currentLive.set(name2range[usePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName use = name2range[usePtr->getRegisterName()];
|
||||
|
||||
for (SparseSet::iterator l = currentLive.begin(); !currentLive.done(l); l = currentLive.advance(l)) {
|
||||
RegisterName live = RegisterName(currentLive.get(l));
|
||||
if (use != live && registerAllocator.canInterfere(use, live))
|
||||
addEdge(use, live);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void LiveRangeGraph<RegisterPressure>::addEdge(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
assert(name1 != name2);
|
||||
edges->set(name1 * rangeCount + name2);
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool LiveRangeGraph<RegisterPressure>::haveEdge(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
assert(name1 != name2);
|
||||
return edges->test(name1 * rangeCount + name2);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
template <class RegisterPressure>
|
||||
void LiveRangeGraph<RegisterPressure>::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Live ranges graph:\n"));
|
||||
for (RegisterName name1 = RegisterName(1); name1 < rangeCount; name1 = RegisterName(name1 + 1)) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\t%d:\t", name1));
|
||||
for (RegisterName name2 = RegisterName(1); name2 < rangeCount; name2 = RegisterName(name2 + 1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%c", ((name1 != name2) && haveEdge(name1, name2)) ? '1' : '0'));
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#endif // _LIVE_RANGE_GRAPH_
|
||||
21
mozilla/ef/Compiler/RegisterAllocator/Liveness.cpp
Normal file
21
mozilla/ef/Compiler/RegisterAllocator/Liveness.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Liveness.h"
|
||||
|
||||
301
mozilla/ef/Compiler/RegisterAllocator/Liveness.h
Normal file
301
mozilla/ef/Compiler/RegisterAllocator/Liveness.h
Normal file
@@ -0,0 +1,301 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIVENESS_H_
|
||||
#define _LIVENESS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterTypes.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// LivenessInfo -
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct LivenessInfo
|
||||
{
|
||||
RegisterPressure::Set* liveIn;
|
||||
RegisterPressure::Set* liveOut;
|
||||
DEBUG_LOG_ONLY(Uint32 size);
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Liveness
|
||||
//
|
||||
// The liveness is defined by the following data-flow equations:
|
||||
//
|
||||
// LiveIn(n) = LocalLive(n) U (LiveOut(n) - Killed(n)).
|
||||
// LiveOut(n) = U LiveIn(s) (s a successor of n).
|
||||
//
|
||||
// where LocalLive(n) is the set of used registers in the block n, Killed(n)
|
||||
// is the set of defined registers in the block n, LiveIn(n) is the set of
|
||||
// live registers at the begining of the block n and LiveOut(n) is the set
|
||||
// of live registers at the end of the block n.
|
||||
//
|
||||
//
|
||||
// We will compute the liveness analysis in two stages:
|
||||
//
|
||||
// 1- Build LocalLive(n) (wich is an approximation of LiveIn(n)) and Killed(n)
|
||||
// for each block n.
|
||||
// 2- Perform a backward data-flow analysis to propagate the liveness information
|
||||
// through the entire control-flow graph.
|
||||
//
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct Liveness
|
||||
{
|
||||
static LivenessInfo<RegisterPressure> analysis(ControlGraph& controlGraph, Uint32 rangeCount, const RegisterName* name2range);
|
||||
static LivenessInfo<RegisterPressure> analysis(ControlGraph& controlGraph, Uint32 nameCount);
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
LivenessInfo<RegisterPressure> Liveness<RegisterPressure>::analysis(ControlGraph& controlGraph, Uint32 rangeCount, const RegisterName* name2range)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
// Allocate the temporary sets.
|
||||
RegisterPressure::Set* killed = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
|
||||
|
||||
// Allocate the globals sets.
|
||||
RegisterPressure::Set* liveIn = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
|
||||
RegisterPressure::Set* liveOut = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
|
||||
|
||||
// First stage of the liveness analysis: Compute the sets LocalLive(stored in LiveIn) and Killed.
|
||||
//
|
||||
for (Uint32 n = 0; n < (nNodes - 1); n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLocalLive = liveIn[n];
|
||||
RegisterPressure::Set& currentKilled = killed[n];
|
||||
|
||||
// Find the instructions contributions to the sets LocalLive and Killed.
|
||||
//
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
// If a VirtualRegister is 'used' before being 'defined' then we add it to set LocalLive.
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
Uint32 index = name2range[usePtr->getRegisterName()];
|
||||
|
||||
if (!currentKilled.test(index))
|
||||
currentLocalLive.set(index);
|
||||
}
|
||||
|
||||
// If a Virtualregister is 'defined' then we add it to the set Killed.
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentKilled.set(name2range[definePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
|
||||
// Second stage of the liveness analysis: We propagate the LiveIn & LiveOut through the entire
|
||||
// control-flow graph.
|
||||
//
|
||||
RegisterPressure::Set temp(pool, rangeCount);
|
||||
|
||||
bool changed;
|
||||
do {
|
||||
changed = false;
|
||||
|
||||
// For all nodes is this graph except the endNode.
|
||||
for (Int32 n = (nNodes - 2); n >= 0; n--) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLiveIn = liveIn[n];
|
||||
RegisterPressure::Set& currentLiveOut = liveOut[n];
|
||||
|
||||
// Compute temp = Union of LiveIn(s) (s a successor of this node) | usedByPhiNodes(n).
|
||||
// temp will be the new LiveOut(n).
|
||||
Uint32 nSuccessors = node.nSuccessors();
|
||||
if (nSuccessors != 0) {
|
||||
temp = liveIn[node.nthSuccessor(0).getTarget().dfsNum];
|
||||
for (Uint32 s = 1; s < nSuccessors; s++)
|
||||
temp |= liveIn[node.nthSuccessor(s).getTarget().dfsNum];
|
||||
} else
|
||||
temp.clear();
|
||||
|
||||
// If temp and LiveOut(n) differ then set LiveOut(n) = temp and recalculate the
|
||||
// new LiveIn(n).
|
||||
if (currentLiveOut != temp) {
|
||||
currentLiveOut = temp;
|
||||
temp -= killed[n]; // FIX: could be optimized with one call to unionDiff !
|
||||
temp |= currentLiveIn;
|
||||
|
||||
if (currentLiveIn != temp) {
|
||||
currentLiveIn = temp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(changed);
|
||||
|
||||
LivenessInfo<RegisterPressure> liveness;
|
||||
liveness.liveIn = liveIn;
|
||||
liveness.liveOut = liveOut;
|
||||
DEBUG_LOG_ONLY(liveness.size = nNodes);
|
||||
return liveness;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
LivenessInfo<RegisterPressure> Liveness<RegisterPressure>::analysis(ControlGraph& controlGraph, Uint32 nameCount)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
// Allocate the temporary sets.
|
||||
RegisterPressure::Set* killed = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
RegisterPressure::Set* usedByPhiNodes = NULL;
|
||||
|
||||
// Allocate the globals sets.
|
||||
RegisterPressure::Set* liveIn = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
RegisterPressure::Set* liveOut = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
|
||||
// First stage of the liveness analysis: Compute the sets LocalLive(stored in LiveIn) and Killed.
|
||||
//
|
||||
for (Uint32 n = 0; n < (nNodes - 1); n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLocalLive = liveIn[n];
|
||||
RegisterPressure::Set& currentKilled = killed[n];
|
||||
|
||||
InstructionList& phiNodes = node.getPhiNodeInstructions();
|
||||
|
||||
if ((usedByPhiNodes == NULL) && !phiNodes.empty())
|
||||
usedByPhiNodes = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
InstructionDefine& define = phiNode.getInstructionDefineBegin()[0];
|
||||
currentKilled.set(define.getRegisterName());
|
||||
|
||||
typedef DoublyLinkedList<ControlEdge> ControlEdgeList;
|
||||
const ControlEdgeList& predecessors = node.getPredecessors();
|
||||
ControlEdgeList::iterator p = predecessors.begin();
|
||||
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++, p = predecessors.advance(p))
|
||||
if (usePtr->isRegister())
|
||||
usedByPhiNodes[predecessors.get(p).getSource().dfsNum].set(usePtr->getRegisterName());
|
||||
}
|
||||
|
||||
// Find the instructions contributions to the sets LocalLive and Killed.
|
||||
//
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
// If a VirtualRegister is 'used' before being 'defined' then we add it to set LocalLive.
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
Uint32 index = usePtr->getRegisterName();
|
||||
|
||||
if (!currentKilled.test(index))
|
||||
currentLocalLive.set(index);
|
||||
}
|
||||
|
||||
// If a Virtualregister is 'defined' then we add it to the set Killed.
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentKilled.set(definePtr->getRegisterName());
|
||||
}
|
||||
}
|
||||
|
||||
// Second stage of the liveness analysis: We propagate the LiveIn & LiveOut through the entire
|
||||
// control-flow graph.
|
||||
//
|
||||
RegisterPressure::Set temp(pool, nameCount);
|
||||
|
||||
bool changed;
|
||||
do {
|
||||
changed = false;
|
||||
|
||||
// For all nodes is this graph except the endNode.
|
||||
for (Int32 n = (nNodes - 2); n >= 0; n--) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLiveIn = liveIn[n];
|
||||
RegisterPressure::Set& currentLiveOut = liveOut[n];
|
||||
|
||||
// Compute temp = Union of LiveIn(s) (s a successor of this node) | usedByPhiNodes(n).
|
||||
// temp will be the new LiveOut(n).
|
||||
Uint32 nSuccessors = node.nSuccessors();
|
||||
if (nSuccessors != 0) {
|
||||
temp = liveIn[node.nthSuccessor(0).getTarget().dfsNum];
|
||||
for (Uint32 s = 1; s < nSuccessors; s++)
|
||||
temp |= liveIn[node.nthSuccessor(s).getTarget().dfsNum];
|
||||
} else
|
||||
temp.clear();
|
||||
|
||||
// Insert the phiNodes contribution.
|
||||
if (usedByPhiNodes != NULL)
|
||||
temp |= usedByPhiNodes[n];
|
||||
|
||||
// If temp and LiveOut(n) differ then set LiveOut(n) = temp and recalculate the
|
||||
// new LiveIn(n).
|
||||
if (currentLiveOut != temp) {
|
||||
currentLiveOut = temp;
|
||||
temp -= killed[n]; // FIX: could be optimized with one call to unionDiff !
|
||||
temp |= currentLiveIn;
|
||||
|
||||
if (currentLiveIn != temp) {
|
||||
currentLiveIn = temp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(changed);
|
||||
|
||||
LivenessInfo<RegisterPressure> liveness;
|
||||
liveness.liveIn = liveIn;
|
||||
liveness.liveOut = liveOut;
|
||||
DEBUG_LOG_ONLY(liveness.size = nNodes);
|
||||
return liveness;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
template <class RegisterPressure>
|
||||
void LivenessInfo<RegisterPressure>::printPretty(LogModuleObject log)
|
||||
{
|
||||
for (Uint32 n = 0; n < size; n++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Node N%d:\n\tliveIn = ", n));
|
||||
liveIn[n].printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tliveOut = "));
|
||||
liveOut[n].printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#endif // _LIVENESS_H_
|
||||
40
mozilla/ef/Compiler/RegisterAllocator/Makefile
Normal file
40
mozilla/ef/Compiler/RegisterAllocator/Makefile
Normal file
@@ -0,0 +1,40 @@
|
||||
#! gmake
|
||||
|
||||
DEPTH = ../..
|
||||
|
||||
MODULE_NAME = RegisterAllocator
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
INCLUDES += \
|
||||
-I$(DEPTH)/Utilities/General \
|
||||
-I$(DEPTH)/Utilities/zlib \
|
||||
-I$(DEPTH)/Runtime/ClassReader \
|
||||
-I$(DEPTH)/Runtime/NativeMethods \
|
||||
-I$(DEPTH)/Runtime/System \
|
||||
-I$(DEPTH)/Runtime/ClassInfo \
|
||||
-I$(DEPTH)/Runtime/FileReader \
|
||||
-I$(DEPTH)/Compiler/PrimitiveGraph \
|
||||
-I$(DEPTH)/Compiler/FrontEnd \
|
||||
-I$(DEPTH)/Compiler/Optimizer \
|
||||
-I$(DEPTH)/Compiler/CodeGenerator \
|
||||
-I$(DEPTH)/Compiler/CodeGenerator/md \
|
||||
-I$(DEPTH)/Compiler/CodeGenerator/md/$(CPU_ARCH) \
|
||||
-I$(DEPTH)/Compiler/RegisterAllocator \
|
||||
-I$(DEPTH)/Driver/StandAloneJava \
|
||||
-I$(DEPTH)/Debugger \
|
||||
$(NULL)
|
||||
|
||||
CXXSRCS = \
|
||||
RegisterAllocator.cpp \
|
||||
RegisterAllocatorTools.cpp \
|
||||
DominatorGraph.cpp \
|
||||
VirtualRegister.cpp \
|
||||
BitSet.cpp \
|
||||
SparseSet.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
libs:: $(MODULE)
|
||||
392
mozilla/ef/Compiler/RegisterAllocator/PhiNodeRemover.h
Normal file
392
mozilla/ef/Compiler/RegisterAllocator/PhiNodeRemover.h
Normal file
@@ -0,0 +1,392 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _PHI_NODE_REMOVER_H_
|
||||
#define _PHI_NODE_REMOVER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "DominatorGraph.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "Liveness.h"
|
||||
#include "Instruction.h"
|
||||
#include "InstructionEmitter.h"
|
||||
#include "SparseSet.h"
|
||||
#include <string.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterNameNode -
|
||||
|
||||
struct RegisterNameNode
|
||||
{
|
||||
RegisterNameNode* next;
|
||||
RegisterName newName;
|
||||
Uint32 nextPushed;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// CopyData -
|
||||
|
||||
struct CopyData
|
||||
{
|
||||
RegisterName source;
|
||||
RegisterClassKind classKind;
|
||||
Uint32 useCount;
|
||||
bool isLiveOut;
|
||||
RegisterName sourceNameToUse;
|
||||
RegisterName temporaryName;
|
||||
RegisterNameNode* newName;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// PhiNodeRemover<RegisterPressure> -
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct PhiNodeRemover
|
||||
{
|
||||
// Replace the phi nodes by copy instructions.
|
||||
static void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
|
||||
};
|
||||
|
||||
// Split some of the critical edges and return true if there are still some
|
||||
// in the graph after that.
|
||||
//
|
||||
static bool splitCriticalEdges(ControlGraph& /*cg*/)
|
||||
{
|
||||
// FIX: not implemented.
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void pushName(Pool& pool, RegisterNameNode** stack, SparseSet& pushed, Uint32* nodeListPointer, RegisterName oldName, RegisterName newName)
|
||||
{
|
||||
RegisterNameNode& newNode = *new(pool) RegisterNameNode();
|
||||
|
||||
if (pushed.test(oldName))
|
||||
(*stack)->newName = newName;
|
||||
else {
|
||||
newNode.newName = newName;
|
||||
newNode.nextPushed = *nodeListPointer;
|
||||
*nodeListPointer = oldName;
|
||||
newNode.next = *stack;
|
||||
*stack = &newNode;
|
||||
pushed.set(oldName);
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void PhiNodeRemover<RegisterPressure>::replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
// Initialize the local variables.
|
||||
//
|
||||
|
||||
// When we insert the copies we will also need to create new VirtualRegisters for
|
||||
// the insertion of temporaries. The maximum number of temporary register will not
|
||||
// exceed the number of phiNodes in the primitive graph.
|
||||
Uint32 nameCount = vrManager.getSize();
|
||||
Uint32 maxNameCount = nameCount;
|
||||
for (Uint32 n = 0; n < nNodes; n++)
|
||||
maxNameCount += nodes[n]->getPhiNodes().length();
|
||||
|
||||
// If the CFG contains some critical edges (backward edge which source has more than one
|
||||
// outgoing edge and destination has more than one incomimg edge) then we need the liveness
|
||||
// information to be able to insert temporary copies.
|
||||
RegisterPressure::Set* liveOut = NULL;
|
||||
if (splitCriticalEdges(controlGraph))
|
||||
liveOut = Liveness<LowRegisterPressure>::analysis(controlGraph, nameCount).liveOut;
|
||||
|
||||
DominatorGraph dGraph(controlGraph);
|
||||
|
||||
SparseSet pushed(pool, maxNameCount);
|
||||
SparseSet destinationList(pool, maxNameCount);
|
||||
SparseSet workList(pool, maxNameCount);
|
||||
|
||||
CopyData* copyStats = new(pool) CopyData[maxNameCount];
|
||||
memset(copyStats, '\0', maxNameCount*sizeof(CopyData));
|
||||
|
||||
struct NodeStack {
|
||||
Uint32* next;
|
||||
Uint32* limit;
|
||||
Uint32 pushedList;
|
||||
};
|
||||
|
||||
// Allocate the node stack and initialize the node stack pointer.
|
||||
NodeStack* nodeStack = new(pool) NodeStack[nNodes + 1];
|
||||
NodeStack* nodeStackPtr = nodeStack;
|
||||
|
||||
// We start by the begin node.
|
||||
Uint32 startNode = 0;
|
||||
Uint32* next = &startNode;
|
||||
Uint32* limit = &startNode + 1;
|
||||
|
||||
while (true) {
|
||||
|
||||
if (next == limit) {
|
||||
// If there are no more node in the sibling, we have to pop the current
|
||||
// frame from the stack and update the copyStats of the pushed nodes.
|
||||
//
|
||||
if (nodeStackPtr == nodeStack)
|
||||
// We are at the bottom of the stack and there are no more nodes
|
||||
// to look at. We are done !
|
||||
break;
|
||||
|
||||
--nodeStackPtr;
|
||||
// We are done with all the children of this node in the dominator tree.
|
||||
// We need to update the copy information of all the new names pushed
|
||||
// during the walk over this node.
|
||||
Uint32 pushedList = nodeStackPtr->pushedList;
|
||||
while (pushedList != 0) {
|
||||
Uint32 nextName = copyStats[pushedList].newName->nextPushed;
|
||||
copyStats[pushedList].newName = copyStats[pushedList].newName->next;
|
||||
pushedList = nextName;
|
||||
}
|
||||
|
||||
// restore the previous frame.
|
||||
next = nodeStackPtr->next;
|
||||
limit = nodeStackPtr->limit;
|
||||
} else {
|
||||
Uint32 currentNode = *next++;
|
||||
Uint32 pushedList = 0;
|
||||
|
||||
|
||||
// Initialize the sets.
|
||||
pushed.clear();
|
||||
destinationList.clear();
|
||||
|
||||
// STEP1:
|
||||
// Walk the instruction list and to replace all the instruction uses with their new name.
|
||||
// If the instruction is a phi node and its defined register is alive at the end of this
|
||||
// block then we push the defined register into the stack.
|
||||
//
|
||||
ControlNode& node = *nodes[currentNode];
|
||||
RegisterPressure::Set* currentLiveOut = (liveOut != NULL) ? &liveOut[currentNode] : (RegisterPressure::Set*) 0;
|
||||
|
||||
InstructionList& phiNodes = node.getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++) {
|
||||
assert(usePtr->isRegister());
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
|
||||
if (copyStats[name].newName != NULL && copyStats[name].newName->newName != name)
|
||||
usePtr->setRegisterName(copyStats[name].newName->newName);
|
||||
}
|
||||
|
||||
if (currentLiveOut != NULL) {
|
||||
// This is a phi node and we have to push its defined name if it is live
|
||||
// at the end of the node. We only need to do this if the CFG has critical edges.
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
|
||||
RegisterName name = phiNode.getInstructionDefineBegin()[0].getRegisterName();
|
||||
|
||||
if (currentLiveOut->test(name))
|
||||
pushName(pool, &(copyStats[name].newName), pushed, &pushedList, name, name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
|
||||
if (copyStats[name].newName != NULL && copyStats[name].newName->newName != name)
|
||||
usePtr->setRegisterName(copyStats[name].newName->newName);
|
||||
}
|
||||
}
|
||||
|
||||
// STEP2:
|
||||
// Look at this node's successors' phiNodes. We keep track of the number of time
|
||||
// a VR will be used by another copy instruction and insert each definition into the
|
||||
// destinationList. This is the only pass over this node's successors as we will
|
||||
// get all the information we need in the CopyData structures.
|
||||
//
|
||||
ControlEdge* successorEdgeEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorEdgePtr = node.getSuccessorsBegin(); successorEdgePtr < successorEdgeEnd; successorEdgePtr++) {
|
||||
Uint32 useIndex = successorEdgePtr->getIndex();
|
||||
ControlNode& successor = successorEdgePtr->getTarget();
|
||||
|
||||
// Look at its phi nodes. The phi nodes are at the top of the instruction list. We exit
|
||||
// as soon as we find an instruction which is not a phi node
|
||||
InstructionList& phiNodes = successor.getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
assert((phiNode.getInstructionUseBegin() + useIndex) < phiNode.getInstructionUseEnd());
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd());
|
||||
|
||||
InstructionUse& source = phiNode.getInstructionUseBegin()[useIndex];
|
||||
InstructionDefine& destination = phiNode.getInstructionDefineBegin()[0];
|
||||
|
||||
assert(source.isRegister() && destination.isRegister());
|
||||
|
||||
RegisterName sourceName = source.getRegisterName();
|
||||
RegisterName destinationName = destination.getRegisterName();
|
||||
|
||||
// Get the correct name for the source.
|
||||
if (copyStats[sourceName].newName != NULL)
|
||||
sourceName = copyStats[sourceName].newName->newName;
|
||||
|
||||
// Update the CopyData structures.
|
||||
if ((sourceName != rnInvalid) && (sourceName != destinationName)) {
|
||||
copyStats[destinationName].source = sourceName;
|
||||
copyStats[destinationName].classKind = destination.getRegisterClass();
|
||||
copyStats[destinationName].isLiveOut = (currentLiveOut != NULL) ? currentLiveOut->test(destinationName) : false;
|
||||
copyStats[destinationName].sourceNameToUse = destinationName;
|
||||
copyStats[sourceName].sourceNameToUse = sourceName;
|
||||
copyStats[sourceName].useCount++;
|
||||
destinationList.set(destinationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// STEP3:
|
||||
// Insert into the worklist only the destination registers that will be not used in
|
||||
// another copy instruction in this block.
|
||||
//
|
||||
assert(workList.getSize() == 0);
|
||||
for (SparseSet::iterator d = destinationList.begin(); !destinationList.done(d); d = destinationList.advance(d)) {
|
||||
Uint32 dest = destinationList.get(d);
|
||||
if (copyStats[dest].useCount == 0)
|
||||
workList.set(dest);
|
||||
}
|
||||
|
||||
// STEP4:
|
||||
// Insert the copy instructions.
|
||||
//
|
||||
Uint32 destinationListSize = destinationList.getSize();
|
||||
InstructionList::iterator endOfTheNode = instructions.end();
|
||||
|
||||
// Find the right place to insert the copy instructions.
|
||||
if (destinationListSize != 0)
|
||||
while (instructions.get(endOfTheNode).getFlags() & ifControl)
|
||||
endOfTheNode = instructions.retreat(endOfTheNode);
|
||||
|
||||
while (destinationListSize != 0) {
|
||||
while(workList.getSize()) {
|
||||
RegisterName destinationName = RegisterName(workList.getOne());
|
||||
RegisterName sourceName = copyStats[destinationName].source;
|
||||
|
||||
workList.clear(destinationName);
|
||||
if (copyStats[destinationName].isLiveOut && !copyStats[destinationName].temporaryName) {
|
||||
// Lost copy problem.
|
||||
copyStats[destinationName].isLiveOut = false;
|
||||
|
||||
RegisterName sourceName = destinationName;
|
||||
RegisterClassKind classKind = copyStats[sourceName].classKind;
|
||||
RegisterName destinationName = getName(vrManager.newVirtualRegister(classKind));
|
||||
assert(destinationName < maxNameCount);
|
||||
|
||||
copyStats[destinationName].classKind = classKind;
|
||||
copyStats[sourceName].useCount = 0;
|
||||
|
||||
// We need to insert a copy to a temporary register to keep the
|
||||
// source register valid at the end of the node defining it.
|
||||
// This copy will be inserted right after the phi node defining it.
|
||||
RegisterName from = copyStats[sourceName].sourceNameToUse;
|
||||
Instruction* definingPhiNode = vrManager.getVirtualRegister(from).getDefiningInstruction();
|
||||
assert(definingPhiNode && (definingPhiNode->getFlags() & ifPhiNode) != 0);
|
||||
|
||||
RegisterID fromID = buildRegisterID(from, classKind);
|
||||
RegisterID toID = buildRegisterID(destinationName, classKind);
|
||||
Instruction& copy = emitter.newCopy(*definingPhiNode->getPrimitive(), fromID, toID);
|
||||
vrManager.getVirtualRegister(destinationName).setDefiningInstruction(copy);
|
||||
definingPhiNode->getPrimitive()->getContainer()->getInstructions().addFirst(copy);
|
||||
|
||||
copyStats[sourceName].temporaryName = destinationName;
|
||||
copyStats[sourceName].sourceNameToUse = destinationName;
|
||||
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
|
||||
}
|
||||
|
||||
// Insert the copy instruction at the end of the current node.
|
||||
RegisterName from = copyStats[sourceName].sourceNameToUse;
|
||||
|
||||
RegisterClassKind classKind = copyStats[destinationName].classKind;
|
||||
RegisterID fromID = buildRegisterID(from, classKind);
|
||||
RegisterID toID = buildRegisterID(destinationName, classKind);
|
||||
Instruction& copy = emitter.newCopy(*vrManager.getVirtualRegister(from).getDefiningInstruction()->getPrimitive(), fromID, toID);
|
||||
instructions.insertAfter(copy, endOfTheNode);
|
||||
endOfTheNode = instructions.advance(endOfTheNode);
|
||||
|
||||
copyStats[sourceName].useCount = 0;
|
||||
if (destinationList.test(sourceName) && copyStats[sourceName].isLiveOut)
|
||||
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
|
||||
copyStats[sourceName].isLiveOut = false;
|
||||
copyStats[sourceName].sourceNameToUse = destinationName;
|
||||
|
||||
if (destinationList.test(sourceName))
|
||||
workList.set(sourceName);
|
||||
destinationList.clear(destinationName);
|
||||
}
|
||||
|
||||
destinationListSize = destinationList.getSize();
|
||||
if (destinationListSize != 0) {
|
||||
RegisterName sourceName = RegisterName(destinationList.getOne());
|
||||
RegisterName destinationName;
|
||||
|
||||
if (!copyStats[sourceName].temporaryName) {
|
||||
// Cycle problem.
|
||||
RegisterClassKind classKind = copyStats[sourceName].classKind;
|
||||
destinationName = getName(vrManager.newVirtualRegister(classKind));
|
||||
assert(destinationName < maxNameCount);
|
||||
|
||||
copyStats[destinationName].classKind = classKind;
|
||||
copyStats[sourceName].temporaryName = destinationName;
|
||||
|
||||
// Insert the copy instruction at the end of the current node.
|
||||
RegisterName from = copyStats[sourceName].sourceNameToUse;
|
||||
|
||||
RegisterID fromID = buildRegisterID(from, classKind);
|
||||
RegisterID toID = buildRegisterID(destinationName, classKind);
|
||||
Instruction& copy = emitter.newCopy(*vrManager.getVirtualRegister(from).getDefiningInstruction()->getPrimitive(), fromID, toID);
|
||||
vrManager.getVirtualRegister(destinationName).setDefiningInstruction(copy);
|
||||
instructions.insertAfter(copy, endOfTheNode);
|
||||
endOfTheNode = instructions.advance(endOfTheNode);
|
||||
} else
|
||||
destinationName = copyStats[sourceName].temporaryName;
|
||||
|
||||
copyStats[sourceName].useCount = 0;
|
||||
copyStats[sourceName].isLiveOut = false;
|
||||
copyStats[sourceName].sourceNameToUse = destinationName;
|
||||
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
|
||||
|
||||
workList.set(sourceName);
|
||||
}
|
||||
}
|
||||
|
||||
nodeStackPtr->pushedList = pushedList;
|
||||
nodeStackPtr->next = next;
|
||||
nodeStackPtr->limit = limit;
|
||||
++nodeStackPtr;
|
||||
next = dGraph.getSuccessorsBegin(currentNode);
|
||||
limit = dGraph.getSuccessorsEnd(currentNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _PHI_NODE_REMOVER_H_
|
||||
155
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.cpp
Normal file
155
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "LogModule.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
#include "PhiNodeRemover.h"
|
||||
#include "LiveRange.h"
|
||||
#include "Liveness.h"
|
||||
#include "InterferenceGraph.h"
|
||||
#include "LiveRangeGraph.h"
|
||||
#include "Coalescing.h"
|
||||
#include "Spilling.h"
|
||||
#include "Coloring.h"
|
||||
#include "Splits.h"
|
||||
|
||||
class Pool;
|
||||
class ControlGraph;
|
||||
class VirtualRegisterManager;
|
||||
class InstructionEmitter;
|
||||
|
||||
UT_DEFINE_LOG_MODULE(RegAlloc);
|
||||
|
||||
void RegisterAllocator::allocateRegisters(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
|
||||
{
|
||||
// Insert the phi node instructions. We want to do this to have a single defined register per instruction.
|
||||
// If we keep the PhiNode (as a DataNode) and a PhiNode is of DoubleWordKind then we have to execute
|
||||
// some special code for the high word annotation.
|
||||
//
|
||||
RegisterAllocatorTools::insertPhiNodeInstructions(controlGraph, emitter);
|
||||
|
||||
// Perform some tests on the instruction graph.
|
||||
//
|
||||
DEBUG_ONLY(RegisterAllocatorTools::testTheInstructionGraph(controlGraph, vrManager));
|
||||
|
||||
// Replace the phi node instructions by their equivalent copy instructions.
|
||||
//
|
||||
PhiNodeRemover<LowRegisterPressure>::replacePhiNodes(controlGraph, vrManager, emitter);
|
||||
|
||||
// Do the register allocation.
|
||||
//
|
||||
RegisterAllocator registerAllocator(pool, controlGraph, vrManager, emitter);
|
||||
registerAllocator.doGraphColoring();
|
||||
}
|
||||
|
||||
void RegisterAllocator::doGraphColoring()
|
||||
{
|
||||
// Initialize the liverange map.
|
||||
//
|
||||
initLiveRanges();
|
||||
|
||||
// Build the live ranges. We do this to compress the number of RegisterNames
|
||||
// used in the insterference graph.
|
||||
//
|
||||
LiveRange<LowRegisterPressure>::build(*this);
|
||||
|
||||
// Remove unnecessary copies.
|
||||
//
|
||||
RegisterAllocatorTools::removeUnnecessaryCopies(*this);
|
||||
|
||||
for (Uint8 loop = 0; loop < 10; loop++) {
|
||||
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("********* RegisterAllocator loop %d *********\n", loop));
|
||||
|
||||
while(true) {
|
||||
// Build the interference graph.
|
||||
//
|
||||
iGraph.build();
|
||||
|
||||
// Coalesce the copy instructions.
|
||||
//
|
||||
if (!Coalescing<LowRegisterPressure>::coalesce(*this))
|
||||
break;
|
||||
}
|
||||
|
||||
// Print the interference graph.
|
||||
//
|
||||
DEBUG_LOG_ONLY(iGraph.printPretty(UT_LOG_MODULE(RegAlloc)));
|
||||
|
||||
// Calculate the spill costs.
|
||||
//
|
||||
Spilling<LowRegisterPressure>::calculateSpillCosts(*this);
|
||||
DEBUG_LOG_ONLY(RegisterAllocatorTools::printSpillCosts(*this));
|
||||
|
||||
// Calculate the split costs.
|
||||
//
|
||||
Splits<LowRegisterPressure>::calculateSplitCosts(*this);
|
||||
DEBUG_LOG_ONLY(RegisterAllocatorTools::printSplitCosts(*this));
|
||||
|
||||
// Build the live range graph.
|
||||
//
|
||||
lGraph.build();
|
||||
DEBUG_LOG_ONLY(lGraph.printPretty(UT_LOG_MODULE(RegAlloc)));
|
||||
|
||||
// Color the graph. If it succeeds then we're done with the
|
||||
// register allocation.
|
||||
//
|
||||
if (Coloring<LowRegisterPressure>::color(*this)) {
|
||||
// Write the final colors in the instruction graph.
|
||||
//
|
||||
Coloring<LowRegisterPressure>::finalColoring(*this);
|
||||
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("********** RegisterAllocator done **********\n"));
|
||||
DEBUG_LOG_ONLY(RegisterAllocatorTools::printInstructions(*this));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to spill some registers.
|
||||
//
|
||||
Spilling<LowRegisterPressure>::insertSpillCode(*this);
|
||||
|
||||
// Insert the split instructions.
|
||||
//
|
||||
Splits<LowRegisterPressure>::insertSplitCode(*this);
|
||||
|
||||
// Update the live ranges.
|
||||
//
|
||||
// FIX
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
RegisterAllocatorTools::updateInstructionGraph(*this);
|
||||
RegisterAllocatorTools::printInstructions(*this);
|
||||
#endif
|
||||
fprintf(stderr, "!!! Coloring failed after 10 loops !!!\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
void RegisterAllocator::initLiveRanges()
|
||||
{
|
||||
Uint32 count = this->nameCount;
|
||||
RegisterName* name2range = new(pool) RegisterName[nameCount];
|
||||
for (RegisterName r = RegisterName(1); r < count; r = RegisterName(r + 1))
|
||||
name2range[r] = r;
|
||||
this->name2range = name2range;
|
||||
rangeCount = count;
|
||||
}
|
||||
88
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.h
Normal file
88
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_ALLOCATOR_H_
|
||||
#define _REGISTER_ALLOCATOR_H_
|
||||
|
||||
class Pool;
|
||||
class ControlGraph;
|
||||
class InstructionEmitter;
|
||||
struct SpillCost;
|
||||
struct SplitCost;
|
||||
|
||||
#include "Liveness.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "RegisterPressure.h" // This should included by Backend.cpp
|
||||
#include "InterferenceGraph.h"
|
||||
#include "LiveRangeGraph.h"
|
||||
|
||||
//template <class RegisterPressure>
|
||||
class RegisterAllocator
|
||||
{
|
||||
public:
|
||||
|
||||
Pool& pool; //
|
||||
ControlGraph& controlGraph; //
|
||||
VirtualRegisterManager& vrManager; //
|
||||
InstructionEmitter& emitter; //
|
||||
|
||||
RegisterName* name2range; //
|
||||
RegisterName* color; //
|
||||
SpillCost* spillCost; //
|
||||
SparseSet* willSpill; //
|
||||
SplitCost* splitCost; //
|
||||
NameLinkedList** splitAround; //
|
||||
InterferenceGraph<LowRegisterPressure> iGraph; //
|
||||
LiveRangeGraph<LowRegisterPressure> lGraph; //
|
||||
LivenessInfo<LowRegisterPressure> liveness; //
|
||||
Uint32 nameCount; //
|
||||
Uint32 rangeCount; //
|
||||
bool splitFound; //
|
||||
|
||||
private:
|
||||
|
||||
//
|
||||
//
|
||||
void doGraphColoring();
|
||||
|
||||
public:
|
||||
|
||||
//
|
||||
//
|
||||
inline RegisterAllocator(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
|
||||
|
||||
//
|
||||
//
|
||||
bool canInterfere(RegisterName /*name1*/, RegisterName /*name2*/) const {return true;}
|
||||
|
||||
//
|
||||
//
|
||||
void initLiveRanges();
|
||||
|
||||
//
|
||||
//
|
||||
static void allocateRegisters(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
|
||||
};
|
||||
|
||||
//
|
||||
//
|
||||
inline RegisterAllocator::RegisterAllocator(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
|
||||
: pool(pool), controlGraph(controlGraph), vrManager(vrManager), emitter(emitter), iGraph(*this), lGraph(*this), nameCount(vrManager.getSize()) {}
|
||||
|
||||
#endif // _REGISTER_ALLOCATOR_H_
|
||||
|
||||
355
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.cpp
Normal file
355
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.cpp
Normal file
@@ -0,0 +1,355 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "LogModule.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Primitives.h"
|
||||
#include "InstructionEmitter.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "Spilling.h"
|
||||
#include "Splits.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
UT_EXTERN_LOG_MODULE(RegAlloc);
|
||||
|
||||
#ifdef DEBUG
|
||||
void RegisterAllocatorTools::testTheInstructionGraph(ControlGraph& controlGraph, VirtualRegisterManager& vrManager)
|
||||
{
|
||||
// Test the declared VirtualRegisters. The register allocator tries to condense the register universe.
|
||||
// Any gap in the VirtualRegister names will be a loss of efficiency !!!!
|
||||
|
||||
Uint32 nameCount = vrManager.getSize();
|
||||
BitSet registerSeen(controlGraph.pool, nameCount);
|
||||
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
registerSeen.set(usePtr->getRegisterName());
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
registerSeen.set(definePtr->getRegisterName());
|
||||
}
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& instruction = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
registerSeen.set(usePtr->getRegisterName());
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
registerSeen.set(definePtr->getRegisterName());
|
||||
}
|
||||
}
|
||||
|
||||
bool renameRegisters = false;
|
||||
for (BitSet::iterator i = registerSeen.nextZero(0); !registerSeen.done(i); i = registerSeen.nextZero(i)) {
|
||||
renameRegisters = true;
|
||||
fprintf(stderr,
|
||||
"WARNING: The VirtualRegister vr%d has been allocated during CodeGeneration but\n"
|
||||
" is never used nor defined by any instruction in the instruction graph\n"
|
||||
" PLEASE FIX \n",
|
||||
i);
|
||||
}
|
||||
if (renameRegisters) {
|
||||
Instruction** definingInstruction = new Instruction*[nameCount];
|
||||
memset(definingInstruction, '\0', nameCount * sizeof(Instruction*));
|
||||
RegisterName* newName = new RegisterName[nameCount];
|
||||
memset(newName, '\0', nameCount * sizeof(RegisterName));
|
||||
RegisterName nextName = RegisterName(1);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
usePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName name = definePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
definePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
}
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& instruction = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
usePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName name = definePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
definePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vrManager.setSize(nextName);
|
||||
|
||||
for (RegisterName r = RegisterName(1); r < nextName; r = RegisterName(r + 1))
|
||||
vrManager.getVirtualRegister(r).definingInstruction = definingInstruction[r];
|
||||
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("RegisterMap:\n"));
|
||||
for (Uint32 i = 1; i < nameCount; i++)
|
||||
if (newName[i] != 0)
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tvr%d becomes vr%d.\n", i, newName[i]));
|
||||
else
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tvr%d is dead.\n", i));
|
||||
|
||||
|
||||
delete newName;
|
||||
delete definingInstruction;
|
||||
}
|
||||
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
void RegisterAllocatorTools::removeUnnecessaryCopies(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i);) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
i = instructions.advance(i);
|
||||
|
||||
if (instruction.getFlags() & ifCopy) {
|
||||
assert(instruction.getInstructionUseBegin() != instruction.getInstructionUseEnd() && instruction.getInstructionUseBegin()[0].isRegister());
|
||||
assert(instruction.getInstructionDefineBegin() != instruction.getInstructionDefineEnd() && instruction.getInstructionDefineBegin()[0].isRegister());
|
||||
|
||||
RegisterName source = name2range[instruction.getInstructionUseBegin()[0].getRegisterName()];
|
||||
RegisterName destination = name2range[instruction.getInstructionDefineBegin()[0].getRegisterName()];
|
||||
|
||||
if (source == destination)
|
||||
instruction.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RegisterAllocatorTools::updateInstructionGraph(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
usePtr->setRegisterName(name2range[usePtr->getRegisterName()]);
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
definePtr->setRegisterName(name2range[definePtr->getRegisterName()]);
|
||||
}
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& instruction = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
usePtr->setRegisterName(name2range[usePtr->getRegisterName()]);
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
definePtr->setRegisterName(name2range[definePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RegisterAllocatorTools::insertPhiNodeInstructions(ControlGraph& controlGraph, InstructionEmitter& emitter)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
DoublyLinkedList<PhiNode>& phiNodes = node.getPhiNodes();
|
||||
|
||||
if (!phiNodes.empty()) {
|
||||
|
||||
// Set the index of the incoming edges.
|
||||
Uint32 index = 0;
|
||||
const DoublyLinkedList<ControlEdge>& predecessors = node.getPredecessors();
|
||||
for (DoublyLinkedList<ControlEdge>::iterator p = predecessors.begin(); !predecessors.done(p); p = predecessors.advance(p))
|
||||
predecessors.get(p).setIndex(index++);
|
||||
|
||||
// Insert the phi node instruction in the instruction list.
|
||||
for (DoublyLinkedList<PhiNode>::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
|
||||
PhiNode& phiNode = phiNodes.get(i);
|
||||
ValueKind kind = phiNode.getKind();
|
||||
|
||||
if (!isStorableKind(kind))
|
||||
continue;
|
||||
|
||||
RegisterClassKind classKind = rckGeneral; // FIX: get class kind from phi node kind.
|
||||
Uint32 nInputs = phiNode.nInputs();
|
||||
|
||||
PhiNodeInstruction& phiNodeInstruction = *new(pool) PhiNodeInstruction(&phiNode, pool, nInputs);
|
||||
|
||||
emitter.defineProducer(phiNode, phiNodeInstruction, 0, classKind, drLow);
|
||||
for (Uint32 whichInput = 0; whichInput < nInputs; whichInput++)
|
||||
emitter.useProducer(phiNode.nthInputVariable(whichInput), phiNodeInstruction, whichInput, classKind, drLow);
|
||||
|
||||
node.addPhiNodeInstruction(phiNodeInstruction);
|
||||
|
||||
if (isDoublewordKind(kind)) {
|
||||
PhiNodeInstruction& phiNodeInstruction = *new(pool) PhiNodeInstruction(&phiNode, pool, nInputs);
|
||||
|
||||
emitter.defineProducer(phiNode, phiNodeInstruction, 0, classKind, drHigh);
|
||||
for (Uint32 whichInput = 0; whichInput < nInputs; whichInput++)
|
||||
emitter.useProducer(phiNode.nthInputVariable(whichInput), phiNodeInstruction, whichInput, classKind, drHigh);
|
||||
|
||||
node.addPhiNodeInstruction(phiNodeInstruction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
|
||||
void RegisterAllocatorTools::printSpillCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
SpillCost* cost = registerAllocator.spillCost;
|
||||
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Spill costs:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\trange %d : ", i));
|
||||
if (cost[i].infinite)
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("infinite\n"));
|
||||
else
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%f\n", cost[i].cost));
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterAllocatorTools::printSplitCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
SplitCost* cost = registerAllocator.splitCost;
|
||||
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Split costs:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\trange %d : loads = %f stores = %f\n", i, cost[i].loads, cost[i].stores));
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterAllocatorTools::printInstructions(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
|
||||
ControlNode** nodes = registerAllocator.controlGraph.dfsList;
|
||||
Uint32 nNodes = registerAllocator.controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("N%d:\n", n));
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
|
||||
if (!phiNodes.empty()) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" PhiNodes:\n", n));
|
||||
for(InstructionList::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
|
||||
phiNodes.get(i).printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
if (!instructions.empty())
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" Instructions:\n", n));
|
||||
}
|
||||
|
||||
for(InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
instructions.get(i).printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
117
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.h
Normal file
117
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.h
Normal file
@@ -0,0 +1,117 @@
|
||||
// -*- mode:C++; tab-width:4; truncate-lines:t -*-
|
||||
//
|
||||
// CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
// NETSCAPE COMMUNICATIONS CORPORATION
|
||||
// Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
// Reserved. Use of this Source Code is subject to the terms of the
|
||||
// applicable license agreement from Netscape Communications Corporation.
|
||||
// The copyright notice(s) in this Source Code does not indicate actual or
|
||||
// intended publication of this Source Code.
|
||||
//
|
||||
// $Id: RegisterAllocatorTools.h,v 1.1.2.1 1999-03-02 16:12:05 fur%netscape.com Exp $
|
||||
//
|
||||
|
||||
#ifndef _REGISTER_ALLOCATOR_TOOLS_H_
|
||||
#define _REGISTER_ALLOCATOR_TOOLS_H_
|
||||
|
||||
#include "LogModule.h"
|
||||
#include "RegisterTypes.h"
|
||||
#include <string.h>
|
||||
|
||||
class RegisterAllocator;
|
||||
class ControlGraph;
|
||||
class InstructionEmitter;
|
||||
class VirtualRegisterManager;
|
||||
|
||||
struct RegisterAllocatorTools
|
||||
{
|
||||
//
|
||||
//
|
||||
static void insertPhiNodeInstructions(ControlGraph& controlGraph, InstructionEmitter& emitter);
|
||||
|
||||
//
|
||||
//
|
||||
static void updateInstructionGraph(RegisterAllocator& registerAllocator);
|
||||
|
||||
//
|
||||
//
|
||||
static void removeUnnecessaryCopies(RegisterAllocator& registerAllocator);
|
||||
|
||||
#ifdef DEBUG
|
||||
//
|
||||
//
|
||||
static void testTheInstructionGraph(ControlGraph& controlGraph, VirtualRegisterManager& vrManager);
|
||||
#endif // DEBUG
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
//
|
||||
//
|
||||
static void printInstructions(RegisterAllocator& registerAllocator);
|
||||
|
||||
//
|
||||
//
|
||||
static void printSpillCosts(RegisterAllocator& registerAllocator);
|
||||
|
||||
//
|
||||
//
|
||||
static void printSplitCosts(RegisterAllocator& registerAllocator);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
//
|
||||
// FIX: this should go in a class (LookupTable ?)
|
||||
//
|
||||
|
||||
inline RegisterName findRoot(RegisterName name, RegisterName* table)
|
||||
{
|
||||
RegisterName* stack = table;
|
||||
RegisterName* stackPtr = stack;
|
||||
|
||||
RegisterName newName;
|
||||
while((newName = table[name]) != name) {
|
||||
*--stackPtr = name;
|
||||
name = newName;
|
||||
}
|
||||
|
||||
while (stackPtr != stack)
|
||||
table[*stackPtr++] = name;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
inline void init(RegisterName* table, Uint32 nameCount)
|
||||
{
|
||||
for (RegisterName r = RegisterName(0); r < nameCount; r = RegisterName(r + 1))
|
||||
table[r] = r;
|
||||
}
|
||||
|
||||
inline Uint32 compress(RegisterName* name2range, RegisterName* table, Uint32 nameCount, Uint32 tableSize)
|
||||
{
|
||||
RegisterName* liveRange = new RegisterName[tableSize];
|
||||
memset(liveRange, '\0', tableSize * sizeof(RegisterName));
|
||||
|
||||
// Update the lookup table.
|
||||
for (RegisterName r = RegisterName(1); r < tableSize; r = RegisterName(r + 1))
|
||||
findRoot(r, table);
|
||||
|
||||
// Count the liveranges.
|
||||
Uint32 liveRangeCount = 1;
|
||||
for (RegisterName s = RegisterName(1); s < tableSize; s = RegisterName(s + 1))
|
||||
if (table[s] == s)
|
||||
liveRange[s] = RegisterName(liveRangeCount++);
|
||||
|
||||
for (RegisterName t = RegisterName(1); t < nameCount; t = RegisterName(t + 1))
|
||||
name2range[t] = liveRange[table[name2range[t]]];
|
||||
|
||||
return liveRangeCount;
|
||||
}
|
||||
|
||||
inline double doLog10(Uint32 power)
|
||||
{
|
||||
double log = 1.0;
|
||||
while (power--)
|
||||
log *= 10.0;
|
||||
return log;
|
||||
}
|
||||
|
||||
#endif // _REGISTER_ALLOCATOR_TOOLS_H_
|
||||
38
mozilla/ef/Compiler/RegisterAllocator/RegisterAssigner.h
Normal file
38
mozilla/ef/Compiler/RegisterAllocator/RegisterAssigner.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_ASSIGNER_H_
|
||||
#define _REGISTER_ASSIGNER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "VirtualRegister.h"
|
||||
|
||||
class FastBitMatrix;
|
||||
|
||||
class RegisterAssigner
|
||||
{
|
||||
protected:
|
||||
VirtualRegisterManager& vRegManager;
|
||||
|
||||
public:
|
||||
RegisterAssigner(VirtualRegisterManager& vrMan) : vRegManager(vrMan) {}
|
||||
|
||||
virtual bool assignRegisters(FastBitMatrix& interferenceMatrix) = 0;
|
||||
};
|
||||
|
||||
#endif /* _REGISTER_ASSIGNER_H_ */
|
||||
25
mozilla/ef/Compiler/RegisterAllocator/RegisterClass.h
Normal file
25
mozilla/ef/Compiler/RegisterAllocator/RegisterClass.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_CLASS_H_
|
||||
#define _REGISTER_CLASS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "RegisterTypes.h"
|
||||
|
||||
#endif // _REGISTER_CLASS_H_
|
||||
37
mozilla/ef/Compiler/RegisterAllocator/RegisterPressure.h
Normal file
37
mozilla/ef/Compiler/RegisterAllocator/RegisterPressure.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_PRESSURE_H_
|
||||
#define _REGISTER_PRESSURE_H_
|
||||
|
||||
#include "BitSet.h"
|
||||
#include "HashSet.h"
|
||||
|
||||
struct LowRegisterPressure
|
||||
{
|
||||
typedef BitSet Set;
|
||||
static const bool setIsOrdered = true;
|
||||
};
|
||||
|
||||
struct HighRegisterPressure
|
||||
{
|
||||
typedef HashSet Set;
|
||||
static const bool setIsOrdered = false;
|
||||
};
|
||||
|
||||
#endif // _REGISTER_PRESSURE_H_
|
||||
104
mozilla/ef/Compiler/RegisterAllocator/RegisterTypes.h
Normal file
104
mozilla/ef/Compiler/RegisterAllocator/RegisterTypes.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_TYPES_H_
|
||||
#define _REGISTER_TYPES_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterName -
|
||||
//
|
||||
|
||||
enum RegisterName {
|
||||
rnInvalid = 0,
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterClassKind -
|
||||
//
|
||||
|
||||
enum RegisterClassKind {
|
||||
rckInvalid = 0,
|
||||
rckGeneral,
|
||||
rckStackSlot,
|
||||
|
||||
nRegisterClassKind
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterID -
|
||||
//
|
||||
|
||||
enum RegisterID {
|
||||
invalidID = 0
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterKind -
|
||||
//
|
||||
|
||||
enum RegisterKind {
|
||||
rkCallerSave = 0,
|
||||
rkCalleeSave,
|
||||
};
|
||||
|
||||
struct NameLinkedList {
|
||||
RegisterName name;
|
||||
NameLinkedList* next;
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
const registerNameMask = 0x03ffffff;
|
||||
const coloredRegisterMask = 0x04000000;
|
||||
const machineRegisterMask = 0x08000000;
|
||||
const registerClassMask = 0xf0000000;
|
||||
|
||||
const registerNameShift = 0;
|
||||
const coloredRegisterShift = 26;
|
||||
const machineRegisterShift = 27;
|
||||
const registerClassShift = 28;
|
||||
|
||||
#else // DEBUG
|
||||
|
||||
const registerNameMask = 0x0fffffff;
|
||||
const registerClassMask = 0xf0000000;
|
||||
|
||||
const registerNameShift = 0;
|
||||
const registerClassShift = 28;
|
||||
|
||||
#endif // DEBUG
|
||||
|
||||
|
||||
inline RegisterClassKind getClass(RegisterID registerID) {return RegisterClassKind((registerID & registerClassMask) >> registerClassShift);}
|
||||
inline RegisterName getName(RegisterID registerID) {return RegisterName((registerID & registerNameMask) >> registerNameShift);}
|
||||
inline void setClass(RegisterID& registerID, RegisterClassKind classKind) {registerID = RegisterID((registerID & ~registerClassMask) | ((classKind << registerClassShift) & registerClassMask));}
|
||||
inline void setName(RegisterID& registerID, RegisterName name) {assert((name & ~registerNameMask) == 0); registerID = RegisterID((registerID & ~registerNameMask) | ((name << registerNameShift) & registerNameMask));}
|
||||
inline RegisterID buildRegisterID(RegisterName name, RegisterClassKind classKind) {return RegisterID(((classKind << registerClassShift) & registerClassMask) | ((name << registerNameShift) & registerNameMask));}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
inline bool isMachineRegister(RegisterID rid) {return (rid & machineRegisterMask) != 0;}
|
||||
inline void setMachineRegister(RegisterID& rid) {rid = RegisterID(rid | machineRegisterMask);}
|
||||
inline bool isColoredRegister(RegisterID rid) {return (rid & coloredRegisterMask) != 0;}
|
||||
inline void setColoredRegister(RegisterID& rid) {rid = RegisterID(rid | coloredRegisterMask);}
|
||||
|
||||
#endif // DEBUG
|
||||
|
||||
#endif // _REGISTER_TYPES_H_
|
||||
32
mozilla/ef/Compiler/RegisterAllocator/SSATools.cpp
Normal file
32
mozilla/ef/Compiler/RegisterAllocator/SSATools.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "SSATools.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "Liveness.h"
|
||||
|
||||
void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager)
|
||||
{
|
||||
if (!controlGraph.hasBackEdges)
|
||||
return;
|
||||
|
||||
Liveness liveness(controlGraph.pool);
|
||||
liveness.buildLivenessAnalysis(controlGraph, vrManager);
|
||||
}
|
||||
29
mozilla/ef/Compiler/RegisterAllocator/SSATools.h
Normal file
29
mozilla/ef/Compiler/RegisterAllocator/SSATools.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SSA_TOOLS_H_
|
||||
#define _SSA_TOOLS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
|
||||
class ControlGraph;
|
||||
class VirtualRegisterManager;
|
||||
|
||||
extern void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager);
|
||||
|
||||
#endif // _SSA_TOOLS_H_
|
||||
37
mozilla/ef/Compiler/RegisterAllocator/SparseSet.cpp
Normal file
37
mozilla/ef/Compiler/RegisterAllocator/SparseSet.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "SparseSet.h"
|
||||
#include "BitSet.h"
|
||||
#include "Pool.h"
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the set.
|
||||
//
|
||||
void SparseSet::printPretty(LogModuleObject log)
|
||||
{
|
||||
Pool pool;
|
||||
BitSet set(pool, universeSize);
|
||||
|
||||
for (Uint32 i = 0; i < count; i++)
|
||||
set.set(node[i].element);
|
||||
|
||||
set.printPretty(log);
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
168
mozilla/ef/Compiler/RegisterAllocator/SparseSet.h
Normal file
168
mozilla/ef/Compiler/RegisterAllocator/SparseSet.h
Normal file
@@ -0,0 +1,168 @@
|
||||
// -*- mode:C++; tab-width:4; truncate-lines:t -*-
|
||||
//
|
||||
// CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
// NETSCAPE COMMUNICATIONS CORPORATION
|
||||
// Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
// Reserved. Use of this Source Code is subject to the terms of the
|
||||
// applicable license agreement from Netscape Communications Corporation.
|
||||
// The copyright notice(s) in this Source Code does not indicate actual or
|
||||
// intended publication of this Source Code.
|
||||
//
|
||||
// $Id: SparseSet.h,v 1.1.2.1 1999-03-02 16:12:07 fur%netscape.com Exp $
|
||||
//
|
||||
|
||||
#ifndef _SPARSE_SET_H_
|
||||
#define _SPARSE_SET_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "LogModule.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
class SparseSet
|
||||
{
|
||||
private:
|
||||
|
||||
struct Node {
|
||||
Uint32 element;
|
||||
Uint32 stackIndex;
|
||||
};
|
||||
|
||||
Node* node;
|
||||
Uint32 count;
|
||||
Uint32 universeSize;
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
SparseSet(const SparseSet&);
|
||||
|
||||
// Check if the given set's universe is of the same size than this universe.
|
||||
void checkUniverseCompatibility(const SparseSet& set) const {assert(set.universeSize == universeSize);}
|
||||
// Check if pos is valid for this set's universe.
|
||||
void checkMember(Int32 pos) const {assert(pos >=0 && Uint32(pos) < universeSize);}
|
||||
|
||||
public:
|
||||
|
||||
SparseSet(Pool& pool, Uint32 universeSize) : universeSize(universeSize) {node = new(pool) Node[universeSize]; clear();}
|
||||
|
||||
// Clear the sparse set.
|
||||
void clear() {count = 0;}
|
||||
// Clear the element at index.
|
||||
inline void clear(Uint32 index);
|
||||
// Set the element at index.
|
||||
inline void set(Uint32 index);
|
||||
// Return true if the element at index is set.
|
||||
inline bool test(Uint32 index) const;
|
||||
// Union with the given sparse set.
|
||||
inline void or(const SparseSet& set);
|
||||
// Intersection with the given sparse set.
|
||||
inline void and(const SparseSet& set);
|
||||
// Difference with the given sparse set.
|
||||
inline void difference(const SparseSet& set);
|
||||
// Copy set.
|
||||
inline SparseSet& operator = (const SparseSet& set);
|
||||
inline SparseSet& operator = (const BitSet& set);
|
||||
// Return true if the sparse sets are identical.
|
||||
friend bool operator == (const SparseSet& set1, const SparseSet& set2);
|
||||
// Return true if the sparse sets are different.
|
||||
friend bool operator != (const SparseSet& set1, const SparseSet& set2);
|
||||
|
||||
// Logical operators.
|
||||
SparseSet& operator |= (const SparseSet& set) {or(set); return *this;}
|
||||
SparseSet& operator &= (const SparseSet& set) {and(set); return *this;}
|
||||
SparseSet& operator -= (const SparseSet& set) {difference(set); return *this;}
|
||||
|
||||
// Iterator to conform with the set API.
|
||||
typedef Int32 iterator;
|
||||
// Return the iterator for the first element of this set.
|
||||
iterator begin() const {return count - 1;}
|
||||
// Return the next iterator.
|
||||
iterator advance(iterator pos) const {return --pos;}
|
||||
// Return true if the iterator is at the end of the set.
|
||||
bool done(iterator pos) const {return pos < 0;}
|
||||
// Return the element for the given iterator;
|
||||
Uint32 get(iterator pos) const {return node[pos].element;}
|
||||
// Return one element of this set.
|
||||
Uint32 getOne() const {assert(count > 0); return node[0].element;}
|
||||
// Return the size of this set.
|
||||
Uint32 getSize() const {return count;}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the set.
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
inline void SparseSet::clear(Uint32 element)
|
||||
{
|
||||
checkMember(element);
|
||||
Uint32 count = this->count;
|
||||
Node* node = this->node;
|
||||
|
||||
Uint32 stackIndex = node[element].stackIndex;
|
||||
|
||||
if ((stackIndex < count) && (node[stackIndex].element == element)) {
|
||||
Uint32 stackTop = node[count - 1].element;
|
||||
|
||||
node[stackIndex].element = stackTop;
|
||||
node[stackTop].stackIndex = stackIndex;
|
||||
this->count = count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void SparseSet::set(Uint32 element)
|
||||
{
|
||||
checkMember(element);
|
||||
Uint32 count = this->count;
|
||||
Node* node = this->node;
|
||||
|
||||
Uint32 stackIndex = node[element].stackIndex;
|
||||
|
||||
if ((stackIndex >= count) || (node[stackIndex].element != element)) {
|
||||
node[count].element = element;
|
||||
node[element].stackIndex = count;
|
||||
this->count = count + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool SparseSet::test(Uint32 element) const
|
||||
{
|
||||
checkMember(element);
|
||||
Node* node = this->node;
|
||||
|
||||
Uint32 stackIndex = node[element].stackIndex;
|
||||
return ((stackIndex < count) && (node[stackIndex].element == element));
|
||||
}
|
||||
|
||||
inline SparseSet& SparseSet::operator = (const SparseSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Uint32 sourceCount = set.getSize();
|
||||
Node* node = this->node;
|
||||
|
||||
memcpy(node, set.node, sourceCount * sizeof(Node));
|
||||
|
||||
for (Uint32 i = 0; i < sourceCount; i++) {
|
||||
Uint32 element = node[i].element;
|
||||
node[element].stackIndex = i;
|
||||
}
|
||||
|
||||
count = sourceCount;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline SparseSet& SparseSet::operator = (const BitSet& set)
|
||||
{
|
||||
// FIX: there's room for optimization here.
|
||||
assert(universeSize == set.getSize());
|
||||
|
||||
clear();
|
||||
for (Int32 i = set.firstOne(); i != -1; i = set.nextOne(i))
|
||||
this->set(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // _SPARSE_SET_H_
|
||||
270
mozilla/ef/Compiler/RegisterAllocator/Spilling.cpp
Normal file
270
mozilla/ef/Compiler/RegisterAllocator/Spilling.cpp
Normal file
@@ -0,0 +1,270 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef NEW_LAURENTM_CODE
|
||||
#define INCLUDE_EMITTER
|
||||
#include "CpuInfo.h"
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "InstructionEmitter.h"
|
||||
#include "Spilling.h"
|
||||
|
||||
|
||||
void Spilling::
|
||||
insertSpillCode(ControlNode** dfsList, Uint32 nNodes)
|
||||
{
|
||||
PRUint32 nVirtualRegisters = vRegManager.count();
|
||||
FastBitSet currentLive(vRegManager.pool, nVirtualRegisters);
|
||||
FastBitSet usedInThisInstruction(vRegManager.pool, nVirtualRegisters);
|
||||
RegisterFifo grNeedLoad(nVirtualRegisters);
|
||||
RegisterFifo fpNeedLoad(nVirtualRegisters);
|
||||
|
||||
for (PRInt32 n = nNodes - 1; n >= 0; n--)
|
||||
{
|
||||
PR_ASSERT(grNeedLoad.empty() & fpNeedLoad.empty());
|
||||
ControlNode& node = *dfsList[n];
|
||||
|
||||
currentLive = node.liveAtEnd;
|
||||
|
||||
PRUint32 nGeneralAlive = 0;
|
||||
PRUint32 nFloatingPointAlive = 0;
|
||||
|
||||
// Get the number of registers alive at the end of this node.
|
||||
for (PRInt32 j = currentLive.firstOne(); j != -1; j = currentLive.nextOne(j))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(j);
|
||||
if (vReg.spillInfo.willSpill)
|
||||
{
|
||||
currentLive.clear(j);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
nGeneralAlive++;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
nFloatingPointAlive++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if(node.dfsNum == 8) printf("\n________Begin Node %d________\n", node.dfsNum);
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i))
|
||||
{
|
||||
Instruction& instruction = instructions.get(i);
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* defPtr;
|
||||
|
||||
// if(node.dfsNum == 8) { printf("\n");
|
||||
// instruction.printPretty(stdout);
|
||||
// printf("\n"); }
|
||||
|
||||
// Handle definitions
|
||||
for (defPtr = defBegin; defPtr < defEnd; defPtr++)
|
||||
if (defPtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = defPtr->getVirtualRegister();
|
||||
currentLive.clear(vReg.getRegisterIndex());
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
nGeneralAlive--;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
nFloatingPointAlive--;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for deaths
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = usePtr->getVirtualRegister();
|
||||
if (!currentLive.test(vReg.getRegisterIndex()))
|
||||
// This is the last use of this register.
|
||||
{
|
||||
currentLive.set(vReg.getRegisterIndex());
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
nGeneralAlive++;
|
||||
while (/*(nGeneralAlive > NUMBER_OF_GREGISTERS) &&*/ !grNeedLoad.empty())
|
||||
{
|
||||
PRUint32 toLoad = grNeedLoad.get();
|
||||
currentLive.clear(toLoad);
|
||||
nGeneralAlive--;
|
||||
|
||||
VirtualRegister& nReg = vRegManager.getVirtualRegister(toLoad);
|
||||
Instruction& lastUsingInstruction = *nReg.spillInfo.lastUsingInstruction;
|
||||
emitter.emitLoadAfter(*lastUsingInstruction.getPrimitive(), lastUsingInstruction.getLinks().prev,
|
||||
nReg.getAlias(), *nReg.equivalentRegister[vrcStackSlot]);
|
||||
nReg.releaseSelf();
|
||||
}
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
nFloatingPointAlive++;
|
||||
while (/*(nFloatingPointAlive > NUMBER_OF_FPREGISTERS) &&*/ !fpNeedLoad.empty())
|
||||
{
|
||||
PRUint32 toLoad = fpNeedLoad.get();
|
||||
currentLive.clear(toLoad);
|
||||
nFloatingPointAlive--;
|
||||
|
||||
VirtualRegister& nReg = vRegManager.getVirtualRegister(toLoad);
|
||||
Instruction& lastUsingInstruction = *nReg.spillInfo.lastUsingInstruction;
|
||||
emitter.emitLoadAfter(*lastUsingInstruction.getPrimitive(), lastUsingInstruction.getLinks().prev,
|
||||
nReg.getAlias(), *nReg.equivalentRegister[vrcStackSlot]);
|
||||
nReg.releaseSelf();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle uses
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = usePtr->getVirtualRegister();
|
||||
PRUint32 registerIndex = vReg.getRegisterIndex();
|
||||
|
||||
if (vReg.spillInfo.willSpill) {
|
||||
#if defined(GENERATE_FOR_X86)
|
||||
if (!instruction.switchUseToSpill((usePtr - useBegin), *vReg.equivalentRegister[vrcStackSlot]))
|
||||
#endif
|
||||
{
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
if (!grNeedLoad.test(registerIndex))
|
||||
{
|
||||
grNeedLoad.put(registerIndex);
|
||||
VirtualRegister& alias = vRegManager.newVirtualRegister(vrcInteger);
|
||||
if (vReg.isPreColored())
|
||||
alias.preColorRegister(vReg.getPreColor());
|
||||
/* if (vReg.hasSpecialInterference) {
|
||||
alias.specialInterference.sizeTo(NUMBER_OF_REGISTERS);
|
||||
alias.specialInterference = vReg.specialInterference;
|
||||
alias.hasSpecialInterference = true;
|
||||
} */
|
||||
vReg.setAlias(alias);
|
||||
vReg.retainSelf();
|
||||
}
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
if (!fpNeedLoad.test(registerIndex))
|
||||
{
|
||||
fpNeedLoad.put(registerIndex);
|
||||
VirtualRegister& alias = vRegManager.newVirtualRegister(vReg.getClass());
|
||||
if (vReg.isPreColored())
|
||||
alias.preColorRegister(vReg.getPreColor());
|
||||
/*if (vReg.hasSpecialInterference) {
|
||||
alias.specialInterference.sizeTo(NUMBER_OF_REGISTERS);
|
||||
alias.specialInterference = vReg.specialInterference;
|
||||
alias.hasSpecialInterference = true;
|
||||
} */
|
||||
vReg.setAlias(alias);
|
||||
vReg.retainSelf();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
usePtr->getVirtualRegisterPtr().initialize(vReg.getAlias());
|
||||
usedInThisInstruction.set(registerIndex);
|
||||
vReg.spillInfo.lastUsingInstruction = &instruction;
|
||||
}
|
||||
currentLive.clear(registerIndex);
|
||||
} else { // will not spill
|
||||
currentLive.set(registerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle definitions
|
||||
for (defPtr = defBegin; defPtr < defEnd; defPtr++)
|
||||
if (defPtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = defPtr->getVirtualRegister();
|
||||
|
||||
if (vReg.spillInfo.willSpill)
|
||||
#if defined(GENERATE_FOR_X86)
|
||||
if (!instruction.switchDefineToSpill((defPtr - defBegin), *vReg.equivalentRegister[vrcStackSlot]))
|
||||
#endif
|
||||
{
|
||||
if (usedInThisInstruction.test(vReg.getRegisterIndex()))
|
||||
// this virtualRegister was used in this instruction and is also defined. We need to move
|
||||
// this virtual register to its alias first and then save it to memory.
|
||||
{
|
||||
emitter.emitStoreAfter(*instruction.getPrimitive(), &instruction.getLinks(),
|
||||
vReg.getAlias(), *vReg.equivalentRegister[vrcStackSlot]);
|
||||
defPtr->getVirtualRegisterPtr().initialize(vReg.getAlias());
|
||||
}
|
||||
else
|
||||
{
|
||||
emitter.emitStoreAfter(*instruction.getPrimitive(), &instruction.getLinks(),
|
||||
vReg, *vReg.equivalentRegister[vrcStackSlot]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!grNeedLoad.empty())
|
||||
{
|
||||
PRUint32 nl = grNeedLoad.get();
|
||||
VirtualRegister& nlReg = vRegManager.getVirtualRegister(nl);
|
||||
Instruction& lastUse = *nlReg.spillInfo.lastUsingInstruction;
|
||||
|
||||
emitter.emitLoadAfter(*lastUse.getPrimitive(), lastUse.getLinks().prev,
|
||||
nlReg.getAlias(), *nlReg.equivalentRegister[vrcStackSlot]);
|
||||
nlReg.releaseSelf();
|
||||
}
|
||||
while (!fpNeedLoad.empty())
|
||||
{
|
||||
PRUint32 nl = fpNeedLoad.get();
|
||||
VirtualRegister& nlReg = vRegManager.getVirtualRegister(nl);
|
||||
Instruction& lastUse = *nlReg.spillInfo.lastUsingInstruction;
|
||||
|
||||
emitter.emitLoadAfter(*lastUse.getPrimitive(), lastUse.getLinks().prev,
|
||||
nlReg.getAlias(), *nlReg.equivalentRegister[vrcStackSlot]);
|
||||
nlReg.releaseSelf();
|
||||
}
|
||||
|
||||
// if(node.dfsNum == 8) printf("\n________End Node %d________\n", node.dfsNum);
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
269
mozilla/ef/Compiler/RegisterAllocator/Spilling.h
Normal file
269
mozilla/ef/Compiler/RegisterAllocator/Spilling.h
Normal file
@@ -0,0 +1,269 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SPILLING_H_
|
||||
#define _SPILLING_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "SparseSet.h"
|
||||
|
||||
template <class RegisterPressure>
|
||||
class Spilling
|
||||
{
|
||||
private:
|
||||
static void insertStoreAfter(Instruction& instruction, RegisterName name);
|
||||
static void insertLoadBefore(Instruction& instruction, RegisterName name);
|
||||
|
||||
public:
|
||||
static void calculateSpillCosts(RegisterAllocator& registerAllocator);
|
||||
static void insertSpillCode(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
struct SpillCost
|
||||
{
|
||||
double loads;
|
||||
double stores;
|
||||
double copies;
|
||||
double cost;
|
||||
bool infinite;
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::insertSpillCode(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet currentLive(pool, rangeCount);
|
||||
SparseSet needLoad(pool, rangeCount);
|
||||
SparseSet mustSpill(pool, rangeCount);
|
||||
SparseSet& willSpill = *registerAllocator.willSpill;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
|
||||
needLoad.clear();
|
||||
currentLive = liveOut[n];
|
||||
mustSpill = currentLive;
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i);) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
i = instructions.retreat(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
bool foundLiveDefine = false;
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
if (currentLive.test(name2range[definePtr->getRegisterName()])) {
|
||||
foundLiveDefine = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
foundLiveDefine = true;
|
||||
break;
|
||||
}
|
||||
if (defineBegin != defineEnd && !foundLiveDefine) {
|
||||
fprintf(stderr, "!!! Removed instruction because it was only defining unused registers !!!\n");
|
||||
instruction.remove();
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName range = name2range[definePtr->getRegisterName()];
|
||||
#ifdef DEBUG
|
||||
if (needLoad.test(range))
|
||||
if (!mustSpill.test(range) && registerAllocator.spillCost[range].infinite && willSpill.test(range)) {
|
||||
fprintf(stderr, "Tried to spill a register with infinite spill cost\n");
|
||||
abort();
|
||||
}
|
||||
#endif // DEBUG
|
||||
if (willSpill.test(range))
|
||||
insertStoreAfter(instruction, range);
|
||||
|
||||
needLoad.clear(range);
|
||||
}
|
||||
|
||||
if (instruction.getFlags() & ifCopy)
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
if (!currentLive.test(range))
|
||||
for (SparseSet::iterator r = needLoad.begin(); !needLoad.done(r); r = needLoad.advance(r)) {
|
||||
RegisterName load = RegisterName(needLoad.get(r));
|
||||
if (willSpill.test(load))
|
||||
insertLoadBefore(instruction, load);
|
||||
mustSpill.set(load);
|
||||
}
|
||||
needLoad.clear();
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentLive.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
currentLive.set(range);
|
||||
needLoad.set(range);
|
||||
}
|
||||
}
|
||||
|
||||
for (SparseSet::iterator l = needLoad.begin(); !needLoad.done(l); l = needLoad.advance(l)) {
|
||||
RegisterName load = RegisterName(needLoad.get(l));
|
||||
if (willSpill.test(load))
|
||||
insertLoadBefore(instructions.first(), load);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::insertLoadBefore(Instruction& /*instruction*/, RegisterName name)
|
||||
{
|
||||
fprintf(stdout, "will insert load for range %d\n", name);
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::insertStoreAfter(Instruction& /*instruction*/, RegisterName name)
|
||||
{
|
||||
fprintf(stdout, "will insert store for range %d\n", name);
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::calculateSpillCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet live(pool, rangeCount);
|
||||
SparseSet needLoad(pool, rangeCount);
|
||||
SparseSet mustSpill(pool, rangeCount);
|
||||
|
||||
SparseSet alreadyStored(pool, rangeCount); // FIX: should get this from previous spilling.
|
||||
|
||||
SpillCost* cost = new SpillCost[rangeCount];
|
||||
memset(cost, '\0', rangeCount * sizeof(SpillCost));
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
double weight = doLog10(node.loopDepth);
|
||||
|
||||
needLoad.clear();
|
||||
live = liveOut[n];
|
||||
mustSpill = live;
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName range = name2range[definePtr->getRegisterName()];
|
||||
|
||||
if (needLoad.test(range))
|
||||
if (!mustSpill.test(range))
|
||||
cost[range].infinite = true;
|
||||
|
||||
if ((false /* !rematerializable(range) */ || !needLoad.test(range)) && !alreadyStored.test(range))
|
||||
cost[range].stores += weight;
|
||||
|
||||
needLoad.clear(range);
|
||||
}
|
||||
|
||||
if (instruction.getFlags() & ifCopy)
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
if (!live.test(name2range[usePtr->getRegisterName()])) {
|
||||
for (SparseSet::iterator l = needLoad.begin(); !needLoad.done(l); l = needLoad.advance(l)) {
|
||||
Uint32 range = needLoad.get(l);
|
||||
cost[range].loads += weight;
|
||||
mustSpill.set(range);
|
||||
}
|
||||
needLoad.clear();
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
live.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
|
||||
live.set(range);
|
||||
needLoad.set(range);
|
||||
}
|
||||
|
||||
if (instruction.getFlags() & ifCopy) {
|
||||
assert(useBegin != useEnd && useBegin[0].isRegister());
|
||||
assert(defineBegin != defineEnd && defineBegin[0].isRegister());
|
||||
|
||||
RegisterName source = name2range[useBegin[0].getRegisterName()];
|
||||
RegisterName destination = name2range[defineBegin[0].getRegisterName()];
|
||||
|
||||
cost[source].copies += weight;
|
||||
cost[destination].copies += weight;
|
||||
}
|
||||
}
|
||||
|
||||
for (SparseSet::iterator s = needLoad.begin(); !needLoad.done(s); s = needLoad.advance(s))
|
||||
cost[needLoad.get(s)].loads += weight;
|
||||
}
|
||||
|
||||
for (Uint32 r = 0; r < rangeCount; r++) {
|
||||
SpillCost& c = cost[r];
|
||||
c.cost = 2 * (c.loads + c.stores) - c.copies;
|
||||
}
|
||||
|
||||
registerAllocator.spillCost = cost;
|
||||
}
|
||||
|
||||
#endif // _SPILLING_H_
|
||||
239
mozilla/ef/Compiler/RegisterAllocator/Splits.h
Normal file
239
mozilla/ef/Compiler/RegisterAllocator/Splits.h
Normal file
@@ -0,0 +1,239 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SPLITS_H_
|
||||
#define _SPLITS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
|
||||
UT_EXTERN_LOG_MODULE(RegAlloc);
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct Splits
|
||||
{
|
||||
static void calculateSplitCosts(RegisterAllocator& registerAllocator);
|
||||
static bool findSplit(RegisterAllocator& registerAllocator, RegisterName* color, RegisterName range);
|
||||
static void insertSplitCode(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
struct SplitCost
|
||||
{
|
||||
double loads;
|
||||
double stores;
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Splits<RegisterPressure>::insertSplitCode(RegisterAllocator& /*registerAllocator*/)
|
||||
{
|
||||
// FIX
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Splits<RegisterPressure>::findSplit(RegisterAllocator& registerAllocator, RegisterName* color, RegisterName range)
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
NameLinkedList** neighborsWithColor = new(pool) NameLinkedList*[6]; // FIX
|
||||
memset(neighborsWithColor, '\0', 6 * sizeof(NameLinkedList*));
|
||||
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
|
||||
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
|
||||
for (Int32 i = vector->count - 1; i >=0; --i) {
|
||||
RegisterName neighbor = vector->neighbors[i];
|
||||
RegisterName c = color[neighbor];
|
||||
|
||||
if (c < 6) { // FIX
|
||||
NameLinkedList* node = new(pool) NameLinkedList();
|
||||
node->name = neighbor;
|
||||
node->next = neighborsWithColor[c];
|
||||
neighborsWithColor[c] = node;
|
||||
}
|
||||
}
|
||||
|
||||
bool splitAroundName = true;
|
||||
|
||||
LiveRangeGraph<RegisterPressure>& lGraph = registerAllocator.lGraph;
|
||||
RegisterName bestColor = RegisterName(6); // FIX
|
||||
double bestCost = registerAllocator.spillCost[range].cost;
|
||||
SplitCost* splitCost = registerAllocator.splitCost;
|
||||
|
||||
for (RegisterName i = RegisterName(0); i < 6; i = RegisterName(i + 1)) { // FIX
|
||||
|
||||
double splitAroundNameCost = 0.0;
|
||||
bool canSplitAroundName = true;
|
||||
|
||||
SplitCost& sCost = splitCost[range];
|
||||
double addedCost = 2.0 * (sCost.stores + sCost.loads);
|
||||
|
||||
for (NameLinkedList* node = neighborsWithColor[i]; node != NULL; node = node->next) {
|
||||
RegisterName neighbor = node->name;
|
||||
if (lGraph.haveEdge(neighbor, range)) {
|
||||
canSplitAroundName = false;
|
||||
break;
|
||||
} else
|
||||
splitAroundNameCost += addedCost;
|
||||
}
|
||||
if (canSplitAroundName && splitAroundNameCost < bestCost) {
|
||||
bestCost = splitAroundNameCost;
|
||||
bestColor = i;
|
||||
splitAroundName = true;
|
||||
}
|
||||
|
||||
double splitAroundColorCost = 0.0;
|
||||
bool canSplitAroundColor = true;
|
||||
|
||||
for (NameLinkedList* node = neighborsWithColor[i]; node != NULL; node = node->next) {
|
||||
RegisterName neighbor = node->name;
|
||||
if (lGraph.haveEdge(range, neighbor)) {
|
||||
canSplitAroundColor = false;
|
||||
break;
|
||||
} else {
|
||||
SplitCost& sCost = splitCost[neighbor];
|
||||
double addedCost = 2.0 * (sCost.stores + sCost.loads);
|
||||
splitAroundColorCost += addedCost;
|
||||
}
|
||||
}
|
||||
if (canSplitAroundColor && splitAroundColorCost < bestCost) {
|
||||
bestCost = splitAroundColorCost;
|
||||
bestColor = i;
|
||||
splitAroundName = false;
|
||||
}
|
||||
}
|
||||
if (bestColor < RegisterName(6)) {
|
||||
color[range] = bestColor;
|
||||
registerAllocator.splitFound = true;
|
||||
|
||||
NameLinkedList** splitAround = registerAllocator.splitAround;
|
||||
|
||||
if (splitAroundName)
|
||||
for (NameLinkedList* node = neighborsWithColor[bestColor]; node != NULL; node = node->next) {
|
||||
NameLinkedList* newNode = new(pool) NameLinkedList();
|
||||
newNode->name = node->name;
|
||||
newNode->next = splitAround[range];
|
||||
splitAround[range] = newNode;
|
||||
}
|
||||
else
|
||||
for (NameLinkedList* node = neighborsWithColor[bestColor]; node != NULL; node = node->next) {
|
||||
NameLinkedList* newNode = new(pool) NameLinkedList();
|
||||
RegisterName neighbor = node->name;
|
||||
newNode->name = range;
|
||||
newNode->next = splitAround[neighbor];
|
||||
splitAround[neighbor] = newNode;
|
||||
}
|
||||
|
||||
trespass("Found a split");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Splits<RegisterPressure>::calculateSplitCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
SplitCost* splitCost = new(pool) SplitCost[rangeCount];
|
||||
memset(splitCost, '\0', rangeCount * sizeof(SplitCost));
|
||||
|
||||
SparseSet live(pool, rangeCount);
|
||||
RegisterPressure::Set* liveIn = registerAllocator.liveness.liveIn;
|
||||
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
double weight = doLog10(node.loopDepth);
|
||||
|
||||
live = liveOut[n];
|
||||
|
||||
ControlEdge* successorsEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorsPtr = node.getSuccessorsBegin(); successorsPtr < successorsEnd; successorsPtr++) {
|
||||
ControlNode& successor = successorsPtr->getTarget();
|
||||
|
||||
if (successor.getControlKind() != ckEnd) {
|
||||
RegisterPressure::Set& successorLiveIn = liveIn[successor.dfsNum];
|
||||
|
||||
for (SparseSet::iterator i = live.begin(); !live.done(i); i = live.advance(i)) {
|
||||
RegisterName name = RegisterName(live.get(i));
|
||||
if (!successorLiveIn.test(name))
|
||||
splitCost[name].loads += doLog10(successor.loopDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
splitCost[name2range[definePtr->getRegisterName()]].stores += weight;
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
if (!live.test(range)) {
|
||||
if (&instruction != &instructions.last())
|
||||
splitCost[range].loads += weight;
|
||||
else {
|
||||
ControlEdge* successorsEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorsPtr = node.getSuccessorsBegin(); successorsPtr < successorsEnd; successorsPtr++)
|
||||
splitCost[range].loads += doLog10(successorsPtr->getTarget().loopDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
live.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
live.set(name2range[usePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
|
||||
NameLinkedList** splitAround = new(pool) NameLinkedList*[rangeCount];
|
||||
memset(splitAround, '\0', rangeCount * sizeof(NameLinkedList*));
|
||||
registerAllocator.splitAround = splitAround;
|
||||
|
||||
registerAllocator.splitCost = splitCost;
|
||||
registerAllocator.splitFound = false;
|
||||
}
|
||||
|
||||
#endif // _SPLITS_H_
|
||||
186
mozilla/ef/Compiler/RegisterAllocator/Timer.cpp
Normal file
186
mozilla/ef/Compiler/RegisterAllocator/Timer.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "HashTable.h"
|
||||
#include "Timer.h"
|
||||
#include "Pool.h"
|
||||
|
||||
static Pool pool; // Pool for the Timer class.
|
||||
static HashTable<TimerEntry*> timerEntries(pool); // Timers hashtable.
|
||||
|
||||
const nTimersInABlock = 128; // Number of timers in a block.
|
||||
static PRTime *timers = new(pool) PRTime[nTimersInABlock]; // A block of timers.
|
||||
static Uint8 nextTimer = 0; // nextAvailableTimer.
|
||||
|
||||
//
|
||||
// Calibrate the call to PR_Now().
|
||||
//
|
||||
static PRTime calibrate()
|
||||
{
|
||||
PRTime t = PR_Now();
|
||||
PRTime& a = *new(pool) PRTime();
|
||||
|
||||
// Call 10 times the PR_Now() function.
|
||||
a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now();
|
||||
a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now();
|
||||
t = (PR_Now() - t + 9) / 10;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static PRTime adjust = calibrate();
|
||||
|
||||
//
|
||||
// Return the named timer..
|
||||
//
|
||||
TimerEntry& Timer::getTimerEntry(const char* name)
|
||||
{
|
||||
if (!timerEntries.exists(name)) {
|
||||
TimerEntry* newEntry = new(pool) TimerEntry();
|
||||
newEntry->accumulator = 0;
|
||||
newEntry->running = false;
|
||||
timerEntries.add(name, newEntry);
|
||||
}
|
||||
|
||||
return *timerEntries[name];
|
||||
}
|
||||
|
||||
//
|
||||
// Return a reference to a new timer.
|
||||
//
|
||||
PRTime& Timer::getNewTimer()
|
||||
{
|
||||
if (nextTimer >= nTimersInABlock) {
|
||||
timers = new(pool) PRTime[nTimersInABlock];
|
||||
nextTimer = 0;
|
||||
}
|
||||
return timers[nextTimer++];
|
||||
}
|
||||
|
||||
static Uint32 timersAreFrozen = 0;
|
||||
|
||||
//
|
||||
// Start the named timer.
|
||||
//
|
||||
void Timer::start(const char* name)
|
||||
{
|
||||
if (timersAreFrozen)
|
||||
return;
|
||||
|
||||
freezeTimers();
|
||||
|
||||
TimerEntry& timer = getTimerEntry(name);
|
||||
PR_ASSERT(!timer.running);
|
||||
|
||||
timer.accumulator = 0;
|
||||
timer.running = true;
|
||||
timer.done = false;
|
||||
|
||||
unfreezeTimers();
|
||||
}
|
||||
|
||||
//
|
||||
// Stop the named timer.
|
||||
//
|
||||
void Timer::stop(const char* name)
|
||||
{
|
||||
if (timersAreFrozen)
|
||||
return;
|
||||
|
||||
freezeTimers();
|
||||
|
||||
TimerEntry& timer = getTimerEntry(name);
|
||||
PR_ASSERT(timer.running);
|
||||
timer.running = false;
|
||||
timer.done = true;
|
||||
|
||||
unfreezeTimers();
|
||||
}
|
||||
|
||||
//
|
||||
// Freeze all the running timers.
|
||||
//
|
||||
void Timer::freezeTimers()
|
||||
{
|
||||
PRTime when = PR_Now() - adjust;
|
||||
|
||||
if (timersAreFrozen == 0) {
|
||||
Vector<TimerEntry*> entries = timerEntries;
|
||||
Uint32 count = entries.size();
|
||||
|
||||
for (Uint32 i = 0; i < count; i++) {
|
||||
TimerEntry& entry = *entries[i];
|
||||
if (entry.running) {
|
||||
entry.accumulator += (when - *entry.startTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
timersAreFrozen++;
|
||||
}
|
||||
|
||||
//
|
||||
// Unfreeze all the running timers.
|
||||
//
|
||||
void Timer::unfreezeTimers()
|
||||
{
|
||||
PR_ASSERT(timersAreFrozen != 0);
|
||||
timersAreFrozen--;
|
||||
|
||||
if (timersAreFrozen == 0) {
|
||||
Vector<TimerEntry *> entries = timerEntries;
|
||||
Uint32 count = entries.size();
|
||||
|
||||
PRTime& newStart = getNewTimer();
|
||||
|
||||
for (Uint32 i = 0; i < count; i++) {
|
||||
TimerEntry& entry = *entries[i];
|
||||
if (entry.running) {
|
||||
entry.startTime = &newStart;
|
||||
}
|
||||
}
|
||||
|
||||
newStart = PR_Now();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Print the named timer in the file f.
|
||||
//
|
||||
void Timer::print(FILE* f, const char *name)
|
||||
{
|
||||
if (timersAreFrozen)
|
||||
return;
|
||||
|
||||
freezeTimers();
|
||||
|
||||
TimerEntry& timer = getTimerEntry(name);
|
||||
|
||||
PR_ASSERT(timer.done);
|
||||
PRTime elapsed = timer.accumulator;
|
||||
|
||||
if (elapsed >> 32) {
|
||||
fprintf(f, "[timer %s out of range]\n", name);
|
||||
} else {
|
||||
fprintf(f, "[%dus in %s]\n", Uint32(elapsed), name);
|
||||
}
|
||||
fflush(f);
|
||||
|
||||
unfreezeTimers();
|
||||
}
|
||||
|
||||
80
mozilla/ef/Compiler/RegisterAllocator/Timer.h
Normal file
80
mozilla/ef/Compiler/RegisterAllocator/Timer.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _TIMER_H_
|
||||
#define _TIMER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "HashTable.h"
|
||||
#include "prtime.h"
|
||||
|
||||
//
|
||||
// Naming convention:
|
||||
// As the class Timer contains only static methods, the timer's name should start with the
|
||||
// module name. Otherwise starting 2 timers with the same name will assert.
|
||||
//
|
||||
|
||||
#ifndef NO_TIMER
|
||||
|
||||
struct TimerEntry
|
||||
{
|
||||
PRTime *startTime; // Current time when we start the timer.
|
||||
PRTime accumulator; // Time spent in this timer.
|
||||
bool running; // True if the timer is running.
|
||||
bool done; // True if the timer was running and was stopped.
|
||||
};
|
||||
|
||||
class Timer
|
||||
{
|
||||
private:
|
||||
|
||||
// Return the named timer.
|
||||
static TimerEntry& getTimerEntry(const char* name);
|
||||
// Return a reference to a new Timer.
|
||||
static PRTime& getNewTimer();
|
||||
|
||||
public:
|
||||
|
||||
// Start the timer.
|
||||
static void start(const char* name);
|
||||
// Stop the timer.
|
||||
static void stop(const char* name);
|
||||
// Freeze all the running timers.
|
||||
static void freezeTimers();
|
||||
// Unfreeze all the running timers.
|
||||
static void unfreezeTimers();
|
||||
// Print the timer.
|
||||
static void print(FILE* f, const char *name);
|
||||
};
|
||||
|
||||
inline void startTimer(const char* name) {Timer::start(name);}
|
||||
inline void stopTimer(const char* name) {Timer::stop(name); Timer::print(stdout, name);}
|
||||
#define START_TIMER_SAFE Timer::freezeTimers();
|
||||
#define END_TIMER_SAFE Timer::unfreezeTimers();
|
||||
#define TIMER_SAFE(x) START_TIMER_SAFE x; END_TIMER_SAFE
|
||||
|
||||
#else /* NO_TIMER */
|
||||
|
||||
inline void startTimer(const char* /*name*/) {}
|
||||
inline void stopTimer(const char* /*name*/) {}
|
||||
#define START_TIMER_SAFE
|
||||
#define END_TIMER_SAFE
|
||||
#define TIMER_SAFE(x) x;
|
||||
|
||||
#endif /* NO_TIMER */
|
||||
#endif /* _TIMER_H_ */
|
||||
40
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.cpp
Normal file
40
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "Instruction.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VirtualRegister -
|
||||
|
||||
#ifdef MANUAL_TEMPLATES
|
||||
template class IndexedPool<VirtualRegister>;
|
||||
#endif
|
||||
|
||||
// Set the defining instruction.
|
||||
//
|
||||
void VirtualRegister::setDefiningInstruction(Instruction& instruction)
|
||||
{
|
||||
if (definingInstruction != NULL) {
|
||||
if ((instruction.getFlags() & ifCopy) && (definingInstruction->getFlags() & ifPhiNode))
|
||||
return;
|
||||
}
|
||||
definingInstruction = &instruction;
|
||||
}
|
||||
|
||||
116
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.h
Normal file
116
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _VIRTUAL_REGISTER_H_
|
||||
#define _VIRTUAL_REGISTER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "IndexedPool.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "RegisterTypes.h"
|
||||
#include "RegisterClass.h"
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VirtualRegister - 24b
|
||||
|
||||
class Instruction;
|
||||
|
||||
class VirtualRegister : public IndexedObject<VirtualRegister>
|
||||
{
|
||||
public:
|
||||
|
||||
Instruction* definingInstruction; // Instruction defining this VR.
|
||||
|
||||
// Initialize a VR of the given classKind.
|
||||
VirtualRegister(RegisterClassKind /*classKind*/) : definingInstruction(NULL) {}
|
||||
|
||||
// Return the defining instruction for this VR.
|
||||
Instruction* getDefiningInstruction() const {return definingInstruction;}
|
||||
// Set the defining instruction.
|
||||
void setDefiningInstruction(Instruction& insn);
|
||||
};
|
||||
|
||||
// Return true if the VirtualRegisters are equals. The only way 2 VRs can be equal is if
|
||||
// they have the same index. If they have the same index then they are at the same
|
||||
// address in the indexed pool.
|
||||
//
|
||||
inline bool operator == (const VirtualRegister& regA, const VirtualRegister& regB) {return ®A == ®B;}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VirtualRegisterManager -
|
||||
|
||||
struct PreColoredRegister
|
||||
{
|
||||
RegisterID id;
|
||||
RegisterName color;
|
||||
};
|
||||
|
||||
class VirtualRegisterManager
|
||||
{
|
||||
private:
|
||||
|
||||
IndexedPool<VirtualRegister> registerPool;
|
||||
PreColoredRegister machineRegister[6];
|
||||
|
||||
public:
|
||||
VirtualRegisterManager()
|
||||
{
|
||||
for (Uint32 i = 0; i < 6; i++)
|
||||
machineRegister[i].id = invalidID;
|
||||
}
|
||||
|
||||
// Return the VirtualRegister at the given index.
|
||||
VirtualRegister& getVirtualRegister(RegisterName name) const {return registerPool.get(name);}
|
||||
|
||||
// Return a new VirtualRegister.
|
||||
RegisterID newVirtualRegister(RegisterClassKind classKind)
|
||||
{
|
||||
VirtualRegister& vReg = *new(registerPool) VirtualRegister(classKind);
|
||||
RegisterID rid;
|
||||
|
||||
setName(rid, RegisterName(vReg.getIndex()));
|
||||
setClass(rid, classKind);
|
||||
return rid;
|
||||
}
|
||||
|
||||
RegisterID newMachineRegister(RegisterName name, RegisterClassKind classKind)
|
||||
{
|
||||
RegisterID rid = machineRegister[name].id;
|
||||
|
||||
if (rid == invalidID) {
|
||||
rid = newVirtualRegister(classKind);
|
||||
DEBUG_ONLY(setMachineRegister(rid));
|
||||
machineRegister[name].id = rid;
|
||||
machineRegister[name].color = name;
|
||||
}
|
||||
|
||||
return rid;
|
||||
}
|
||||
|
||||
PreColoredRegister* getMachineRegistersBegin() const {return (PreColoredRegister*) machineRegister;} // FIX
|
||||
PreColoredRegister* getMachineRegistersEnd() const {return (PreColoredRegister*) &machineRegister[6];} // FIX
|
||||
|
||||
// Return the VirtualRegister universe size.
|
||||
Uint32 getSize() {return registerPool.getSize();}
|
||||
|
||||
void setSize(Uint32 size) {registerPool.setSize(size);}
|
||||
};
|
||||
|
||||
#endif // _VIRTUAL_REGISTER_H_
|
||||
@@ -1,364 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Terry Hayes <thayes@netscape.com>
|
||||
* Javier Delgadillo <javi@netscape.com>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/**
|
||||
* Derived from nsNSSDialogs http://landfill.mozilla.org/mxr-test/seamonkey/source/security/manager/pki/src/nsNSSDialogs.cpp
|
||||
*/
|
||||
#include <strings.h>
|
||||
#include "nsIURI.h"
|
||||
#include "EmbedPrivate.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIWebNavigationInfo.h"
|
||||
#include "nsDocShellCID.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIX509Cert.h"
|
||||
#include "nsIX509CertDB.h"
|
||||
#include "nsILocaleService.h"
|
||||
#include "nsIDateTimeFormat.h"
|
||||
#include "nsDateTimeFormatCID.h"
|
||||
#include "EmbedCertificates.h"
|
||||
#include "nsIKeygenThread.h"
|
||||
#include "nsIX509CertValidity.h"
|
||||
#include "nsICRLInfo.h"
|
||||
#include "gtkmozembed.h"
|
||||
|
||||
#define PIPSTRING_BUNDLE_URL "chrome://pippki/locale/pippki.properties"
|
||||
|
||||
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
||||
EmbedCertificates::EmbedCertificates(void)
|
||||
{
|
||||
}
|
||||
|
||||
EmbedCertificates::~EmbedCertificates()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(EmbedCertificates)
|
||||
NS_IMPL_THREADSAFE_RELEASE(EmbedCertificates)
|
||||
NS_INTERFACE_MAP_BEGIN(EmbedCertificates)
|
||||
NS_INTERFACE_MAP_ENTRY(nsITokenPasswordDialogs)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIBadCertListener)
|
||||
#ifdef BAD_CERT_LISTENER2
|
||||
NS_INTERFACE_MAP_ENTRY(nsIBadCertListener2)
|
||||
#endif
|
||||
NS_INTERFACE_MAP_ENTRY(nsICertificateDialogs)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIClientAuthDialogs)
|
||||
NS_INTERFACE_MAP_ENTRY(nsICertPickDialogs)
|
||||
NS_INTERFACE_MAP_ENTRY(nsITokenDialogs)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIGeneratingKeypairInfoDialogs)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCryptoDialogs)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsresult
|
||||
EmbedCertificates::Init(void)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIStringBundleService> service = do_GetService(kCStringBundleServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return NS_OK;
|
||||
rv = service->CreateBundle(PIPSTRING_BUNDLE_URL,
|
||||
getter_AddRefs(mPIPStringBundle));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedCertificates::SetPassword(nsIInterfaceRequestor *ctx,
|
||||
const PRUnichar *tokenName, PRBool* _canceled)
|
||||
{
|
||||
*_canceled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedCertificates::GetPassword(nsIInterfaceRequestor *ctx,
|
||||
const PRUnichar *tokenName,
|
||||
PRUnichar **_password,
|
||||
PRBool* _canceled)
|
||||
{
|
||||
*_canceled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::ConfirmUnknownIssuer(nsIInterfaceRequestor *socketInfo,
|
||||
nsIX509Cert *cert, PRInt16 *outAddType,
|
||||
PRBool *_retval)
|
||||
{
|
||||
*outAddType = ADD_TRUSTED_FOR_SESSION;
|
||||
*_retval = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::ConfirmMismatchDomain(nsIInterfaceRequestor *socketInfo,
|
||||
const nsACString &targetURL,
|
||||
nsIX509Cert *cert, PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::ConfirmCertExpired(nsIInterfaceRequestor *socketInfo,
|
||||
nsIX509Cert *cert, PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::NotifyCrlNextupdate(nsIInterfaceRequestor *socketInfo,
|
||||
const nsACString &targetURL, nsIX509Cert *cert)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx,
|
||||
nsIX509Cert *cert,
|
||||
PRUint32 *_trust,
|
||||
PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_TRUE;
|
||||
*_trust |= nsIX509CertDB::TRUSTED_SSL;
|
||||
*_trust |= nsIX509CertDB::TRUSTED_EMAIL;
|
||||
*_trust |= nsIX509CertDB::TRUSTED_OBJSIGN;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::NotifyCACertExists(nsIInterfaceRequestor *ctx)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::ChooseCertificate(
|
||||
nsIInterfaceRequestor *ctx,
|
||||
const PRUnichar *cn,
|
||||
const PRUnichar *organization,
|
||||
const PRUnichar *issuer,
|
||||
const PRUnichar **certNickList,
|
||||
const PRUnichar **certDetailsList,
|
||||
PRUint32 count,
|
||||
PRInt32 *selectedIndex,
|
||||
PRBool *canceled)
|
||||
{
|
||||
*canceled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::PickCertificate(
|
||||
nsIInterfaceRequestor *ctx,
|
||||
const PRUnichar **certNickList,
|
||||
const PRUnichar **certDetailsList,
|
||||
PRUint32 count,
|
||||
PRInt32 *selectedIndex,
|
||||
PRBool *canceled)
|
||||
{
|
||||
*canceled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::SetPKCS12FilePassword(
|
||||
nsIInterfaceRequestor *ctx,
|
||||
nsAString &_password,
|
||||
PRBool *_retval)
|
||||
{
|
||||
/* The person who wrote this method implementation did
|
||||
* not read the contract.
|
||||
*/
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::GetPKCS12FilePassword(
|
||||
nsIInterfaceRequestor *ctx,
|
||||
nsAString &_password,
|
||||
PRBool *_retval)
|
||||
{
|
||||
/* The person who wrote this method implementation did
|
||||
* not read the contract.
|
||||
*/
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void viewCert (in nsIX509Cert cert); */
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::ViewCert(
|
||||
nsIInterfaceRequestor *ctx,
|
||||
nsIX509Cert *cert)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::DisplayGeneratingKeypairInfo(nsIInterfaceRequestor *aCtx, nsIKeygenThread *runnable)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::ChooseToken(
|
||||
nsIInterfaceRequestor *aCtx,
|
||||
const PRUnichar **aTokenList,
|
||||
PRUint32 aCount,
|
||||
PRUnichar **aTokenChosen,
|
||||
PRBool *aCanceled)
|
||||
{
|
||||
*aCanceled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* boolean ConfirmKeyEscrow (in nsIX509Cert escrowAuthority); */
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::ConfirmKeyEscrow(nsIX509Cert *escrowAuthority, PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef BAD_CERT_LISTENER2
|
||||
NS_IMETHODIMP
|
||||
EmbedCertificates::ConfirmBadCertificate(
|
||||
nsIInterfaceRequestor *ctx,
|
||||
nsIX509Cert *cert,
|
||||
PRBool aSecSuccess,
|
||||
PRUint32 aError,
|
||||
PRBool *_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
gpointer pCert = NULL;
|
||||
guint messint = 0;
|
||||
nsCOMPtr<nsIDOMWindow> parent(do_GetInterface(ctx));
|
||||
|
||||
GtkMozEmbedCommon * common = nsnull;
|
||||
GtkMozEmbed *parentWidget = GTK_MOZ_EMBED(GetGtkWidgetForDOMWindow(parent));
|
||||
|
||||
if (!parentWidget) {
|
||||
EmbedCommon * embedcommon = EmbedCommon::GetInstance();
|
||||
if (embedcommon)
|
||||
common = GTK_MOZ_EMBED_COMMON(embedcommon->mCommon);
|
||||
}
|
||||
|
||||
if (!(aError & nsIX509Cert::VERIFIED_OK)) {
|
||||
pCert = (gpointer)cert;
|
||||
messint = GTK_MOZ_EMBED_CERT_VERIFIED_OK;
|
||||
if (aError & nsIX509Cert::NOT_VERIFIED_UNKNOWN) {
|
||||
messint |= GTK_MOZ_EMBED_CERT_NOT_VERIFIED_UNKNOWN;
|
||||
}
|
||||
if (aError & nsIX509Cert::CERT_EXPIRED || aError & nsIX509Cert::CERT_REVOKED) {
|
||||
nsCOMPtr<nsIX509CertValidity> validity;
|
||||
rv = cert->GetValidity(getter_AddRefs(validity));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRTime notBefore, notAfter, timeToUse;
|
||||
PRTime now = PR_Now();
|
||||
rv = validity->GetNotBefore(¬Before);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = validity->GetNotAfter(¬After);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (LL_CMP(now, >, notAfter)) {
|
||||
messint |= GTK_MOZ_EMBED_CERT_EXPIRED;
|
||||
timeToUse = notAfter;
|
||||
} else {
|
||||
messint |= GTK_MOZ_EMBED_CERT_REVOKED;
|
||||
timeToUse = notBefore;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (aError & nsIX509Cert::CERT_NOT_TRUSTED) {
|
||||
messint |= GTK_MOZ_EMBED_CERT_UNTRUSTED;
|
||||
}
|
||||
if (aError & nsIX509Cert::ISSUER_UNKNOWN) {
|
||||
messint |= GTK_MOZ_EMBED_CERT_ISSUER_UNKNOWN;
|
||||
}
|
||||
if (aError & nsIX509Cert::ISSUER_NOT_TRUSTED) {
|
||||
messint |= GTK_MOZ_EMBED_CERT_ISSUER_UNTRUSTED;
|
||||
}
|
||||
if (aError & nsIX509Cert::INVALID_CA) {
|
||||
messint |= GTK_MOZ_EMBED_CERT_INVALID_CA;
|
||||
}
|
||||
if (aError & nsIX509Cert::USAGE_NOT_ALLOWED) {
|
||||
}
|
||||
PRBool retVal = PR_FALSE;
|
||||
if (common) {
|
||||
g_signal_emit_by_name(common, "certificate-error", pCert, messint, &retVal);
|
||||
}
|
||||
if (retVal == PR_TRUE) {
|
||||
*_retval = PR_FALSE;
|
||||
rv = NS_ERROR_FAILURE;
|
||||
} else {
|
||||
rv = NS_OK;
|
||||
*_retval = PR_TRUE;
|
||||
}
|
||||
pCert = NULL;
|
||||
} else {
|
||||
rv = NS_OK;
|
||||
*_retval = PR_TRUE;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
@@ -1,96 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Terry Hayes <thayes@netscape.com>
|
||||
* Javier Delgadillo <javi@netscape.com>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/**
|
||||
* Derived from nsNSSDialogs http://landfill.mozilla.org/mxr-test/seamonkey/source/security/manager/pki/src/nsNSSDialogs.h
|
||||
*/
|
||||
#ifndef __EmbedCertificates_h
|
||||
#define __EmbedCertificates_h
|
||||
#include "nsITokenPasswordDialogs.h"
|
||||
#include "nsIBadCertListener.h"
|
||||
#ifdef BAD_CERT_LISTENER2
|
||||
#include "nsIBadCertListener2.h"
|
||||
#endif
|
||||
#include "nsICertificateDialogs.h"
|
||||
#include "nsIClientAuthDialogs.h"
|
||||
#include "nsICertPickDialogs.h"
|
||||
#include "nsITokenDialogs.h"
|
||||
#include "nsIDOMCryptoDialogs.h"
|
||||
#include "nsIGenKeypairInfoDlg.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#define EMBED_CERTIFICATES_CID \
|
||||
{ 0x518e071f, 0x1dd2, 0x11b2, \
|
||||
{ 0x93, 0x7e, 0xc4, 0x5f, 0x14, 0xde, 0xf7, 0x78 }}
|
||||
#define EMBED_CERTIFICATES_DESCRIPTION "Certificates Listener Impl"
|
||||
class EmbedPrivate;
|
||||
class EmbedCertificates
|
||||
: public nsITokenPasswordDialogs,
|
||||
public nsIBadCertListener,
|
||||
#ifdef BAD_CERT_LISTENER2
|
||||
public nsIBadCertListener2,
|
||||
#endif
|
||||
public nsICertificateDialogs,
|
||||
public nsIClientAuthDialogs,
|
||||
public nsICertPickDialogs,
|
||||
public nsITokenDialogs,
|
||||
public nsIDOMCryptoDialogs,
|
||||
public nsIGeneratingKeypairInfoDialogs
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITOKENPASSWORDDIALOGS
|
||||
NS_DECL_NSIBADCERTLISTENER
|
||||
#ifdef BAD_CERT_LISTENER2
|
||||
NS_DECL_NSIBADCERTLISTENER2
|
||||
#endif
|
||||
NS_DECL_NSICERTIFICATEDIALOGS
|
||||
NS_DECL_NSICLIENTAUTHDIALOGS
|
||||
NS_DECL_NSICERTPICKDIALOGS
|
||||
NS_DECL_NSITOKENDIALOGS
|
||||
NS_DECL_NSIDOMCRYPTODIALOGS
|
||||
NS_DECL_NSIGENERATINGKEYPAIRINFODIALOGS
|
||||
EmbedCertificates();
|
||||
virtual ~EmbedCertificates();
|
||||
nsresult Init(void);
|
||||
protected:
|
||||
nsCOMPtr<nsIStringBundle> mPIPStringBundle;
|
||||
};
|
||||
#endif /* __EmbedCertificates_h */
|
||||
@@ -1,182 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
#include "nsIURI.h"
|
||||
|
||||
#include "EmbedContentListener.h"
|
||||
#include "EmbedPrivate.h"
|
||||
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIWebNavigationInfo.h"
|
||||
#include "nsDocShellCID.h"
|
||||
|
||||
EmbedContentListener::EmbedContentListener(void)
|
||||
{
|
||||
mOwner = nsnull;
|
||||
}
|
||||
|
||||
EmbedContentListener::~EmbedContentListener()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(EmbedContentListener,
|
||||
nsIURIContentListener,
|
||||
nsISupportsWeakReference)
|
||||
|
||||
nsresult
|
||||
EmbedContentListener::Init(EmbedPrivate *aOwner)
|
||||
{
|
||||
mOwner = aOwner;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedContentListener::OnStartURIOpen(nsIURI *aURI,
|
||||
PRBool *aAbortOpen)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (mOwner->mOpenBlock) {
|
||||
*aAbortOpen = mOwner->mOpenBlock;
|
||||
mOwner->mOpenBlock = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
nsCAutoString specString;
|
||||
rv = aURI->GetSpec(specString);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
gint return_val = FALSE;
|
||||
|
||||
/* checks if URI scheme is mailto */
|
||||
aURI->SchemeIs("mailto", &return_val);
|
||||
if (return_val) {
|
||||
/* stops URI opening to emit "mailto" signal */
|
||||
*aAbortOpen = TRUE;
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[MAILTO],
|
||||
specString.get());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// otherwise ...
|
||||
return_val = FALSE;
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[OPEN_URI],
|
||||
specString.get(), &return_val);
|
||||
|
||||
*aAbortOpen = return_val;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedContentListener::DoContent(const char *aContentType,
|
||||
PRBool aIsContentPreferred,
|
||||
nsIRequest *aRequest,
|
||||
nsIStreamListener **aContentHandler,
|
||||
PRBool *aAbortProcess)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedContentListener::IsPreferred(const char *aContentType,
|
||||
char **aDesiredContentType,
|
||||
PRBool *aCanHandleContent)
|
||||
{
|
||||
return CanHandleContent(aContentType, PR_TRUE, aDesiredContentType,
|
||||
aCanHandleContent);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedContentListener::CanHandleContent(const char *aContentType,
|
||||
PRBool aIsContentPreferred,
|
||||
char **aDesiredContentType,
|
||||
PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_FALSE;
|
||||
*aDesiredContentType = nsnull;
|
||||
|
||||
if (aContentType) {
|
||||
nsCOMPtr<nsIWebNavigationInfo> webNavInfo(
|
||||
do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID));
|
||||
if (webNavInfo) {
|
||||
PRUint32 canHandle;
|
||||
nsresult rv =
|
||||
webNavInfo->IsTypeSupported(nsDependentCString(aContentType),
|
||||
mOwner ? mOwner->mNavigation.get() : nsnull,
|
||||
&canHandle); //FIXME XXX MEMLEAK
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
*_retval = (canHandle != nsIWebNavigationInfo::UNSUPPORTED);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedContentListener::GetLoadCookie(nsISupports **aLoadCookie)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedContentListener::SetLoadCookie(nsISupports *aLoadCookie)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedContentListener::GetParentContentListener(nsIURIContentListener **aParent)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedContentListener::SetParentContentListener(nsIURIContentListener *aParent)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __EmbedContentListener_h
|
||||
#define __EmbedContentListener_h
|
||||
|
||||
#include "nsIURIContentListener.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
class EmbedPrivate;
|
||||
|
||||
class EmbedContentListener : public nsIURIContentListener,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
|
||||
EmbedContentListener();
|
||||
virtual ~EmbedContentListener();
|
||||
|
||||
nsresult Init(EmbedPrivate *aOwner);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIURICONTENTLISTENER
|
||||
|
||||
private:
|
||||
|
||||
EmbedPrivate *mOwner;
|
||||
|
||||
};
|
||||
|
||||
#endif /* __EmbedContentListener_h */
|
||||
@@ -1,634 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Oleg Romashin. Portions created by Oleg Romashin are Copyright (C) Oleg Romashin. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "EmbedContextMenuInfo.h"
|
||||
#include "nsIImageLoadingContent.h"
|
||||
#include "imgILoader.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIDOMHTMLElement.h"
|
||||
#include "nsIDOMHTMLHtmlElement.h"
|
||||
#include "nsIDOMHTMLAnchorElement.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIDOMHTMLAreaElement.h"
|
||||
#include "nsIDOMHTMLLinkElement.h"
|
||||
#include "nsIDOMDocumentView.h"
|
||||
#include "nsIDOMAbstractView.h"
|
||||
#include "nsIDOMViewCSS.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIDOMCSSValue.h"
|
||||
#include "nsIDOMCSSPrimitiveValue.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsIDOMMouseEvent.h"
|
||||
#include "nsIDOMNSEvent.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMWindowCollection.h"
|
||||
#include "nsIWebBrowser.h"
|
||||
#include "nsIDOM3Document.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIFormControl.h"
|
||||
#include "nsIDOMNSHTMLInputElement.h"
|
||||
#include "nsIDOMNSHTMLTextAreaElement.h"
|
||||
#include "nsIDOMHTMLInputElement.h"
|
||||
#include "nsIDOMHTMLTextAreaElement.h"
|
||||
#include "nsIDOMNSHTMLDocument.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "EmbedPrivate.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <glib.h>
|
||||
#if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
|
||||
#include "nsIFrame.h"
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
// class EmbedContextMenuInfo
|
||||
//*****************************************************************************
|
||||
EmbedContextMenuInfo::EmbedContextMenuInfo(EmbedPrivate *aOwner) : mCtxFrameNum(-1), mEmbedCtxType(0)
|
||||
{
|
||||
mOwner = aOwner;
|
||||
mEventNode = nsnull;
|
||||
mCtxDocument = nsnull;
|
||||
mNSHHTMLElement = nsnull;
|
||||
mNSHHTMLElementSc = nsnull;
|
||||
mCtxEvent = nsnull;
|
||||
mEventNode = nsnull;
|
||||
mFormRect = nsRect(0,0,0,0);
|
||||
}
|
||||
|
||||
EmbedContextMenuInfo::~EmbedContextMenuInfo(void)
|
||||
{
|
||||
mEventNode = nsnull;
|
||||
mCtxDocument = nsnull;
|
||||
mNSHHTMLElement = nsnull;
|
||||
mNSHHTMLElementSc = nsnull;
|
||||
mCtxEvent = nsnull;
|
||||
mEventNode = nsnull;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(EmbedContextMenuInfo)
|
||||
NS_IMPL_RELEASE(EmbedContextMenuInfo)
|
||||
NS_INTERFACE_MAP_BEGIN(EmbedContextMenuInfo)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::SetFrameIndex()
|
||||
{
|
||||
nsCOMPtr<nsIDOMWindowCollection> frames;
|
||||
mCtxDomWindow->GetFrames(getter_AddRefs(frames));
|
||||
nsCOMPtr<nsIDOMWindow> currentWindow;
|
||||
PRUint32 frameCount = 0;
|
||||
frames->GetLength(&frameCount);
|
||||
for (unsigned int i= 0; i < frameCount; i++) {
|
||||
frames->Item(i, getter_AddRefs(currentWindow));
|
||||
nsCOMPtr<nsIDOMDocument> currentDoc;
|
||||
currentWindow->GetDocument(getter_AddRefs(currentDoc));
|
||||
if (currentDoc == mCtxDocument) {
|
||||
mCtxFrameNum = i;
|
||||
mCtxDomWindow = currentWindow;
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(currentDoc);
|
||||
if (doc)
|
||||
mCtxDocTitle = doc->GetDocumentTitle();
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::GetFormControlType(nsIDOMEvent* aEvent)
|
||||
{
|
||||
if (!aEvent)
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
nsevent->GetOriginalTarget(getter_AddRefs(target));
|
||||
// mOrigTarget = target;
|
||||
if (SetFormControlType(target)) {
|
||||
nsCOMPtr<nsIDOMNode> eventNode = do_QueryInterface(target);
|
||||
if (!eventNode)
|
||||
return NS_OK;
|
||||
//Frame Stuff
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
nsresult rv = eventNode->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
if (!NS_SUCCEEDED(rv) || !domDoc) {
|
||||
return NS_OK;
|
||||
}
|
||||
mEventNode = eventNode;
|
||||
mCtxDocument = domDoc;
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mCtxDocument);
|
||||
if (!doc)
|
||||
return NS_OK;
|
||||
nsIPresShell *presShell = doc->GetShellAt(0);
|
||||
if (!presShell)
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIContent> tgContent = do_QueryInterface(mEventTarget);
|
||||
nsIFrame* frame = nsnull;
|
||||
#if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
|
||||
#ifdef MOZILLA_1_8_BRANCH
|
||||
presShell->GetPrimaryFrameFor(tgContent, &frame);
|
||||
#else
|
||||
frame = presShell->GetPrimaryFrameFor(tgContent);
|
||||
#endif
|
||||
if (frame)
|
||||
mFormRect = frame->GetScreenRectExternal();
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::SetFormControlType(nsIDOMEventTarget *originalTarget)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(originalTarget);
|
||||
mCtxFormType = 0;
|
||||
#ifdef MOZILLA_1_8_BRANCH
|
||||
if (targetContent && targetContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) {
|
||||
#else
|
||||
if (targetContent && targetContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL)) {
|
||||
#endif
|
||||
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(targetContent));
|
||||
if (formControl) {
|
||||
mCtxFormType = formControl->GetType();
|
||||
rv = NS_OK;
|
||||
//#ifdef MOZ_LOGGING
|
||||
switch (mCtxFormType) {
|
||||
case NS_FORM_BUTTON_BUTTON:
|
||||
break;
|
||||
case NS_FORM_BUTTON_RESET:
|
||||
break;
|
||||
case NS_FORM_BUTTON_SUBMIT:
|
||||
break;
|
||||
case NS_FORM_INPUT_BUTTON:
|
||||
break;
|
||||
case NS_FORM_INPUT_CHECKBOX:
|
||||
break;
|
||||
case NS_FORM_INPUT_FILE:
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
|
||||
break;
|
||||
case NS_FORM_INPUT_HIDDEN:
|
||||
break;
|
||||
case NS_FORM_INPUT_RESET:
|
||||
break;
|
||||
case NS_FORM_INPUT_IMAGE:
|
||||
break;
|
||||
case NS_FORM_INPUT_PASSWORD:
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IPASSWORD;
|
||||
break;
|
||||
case NS_FORM_INPUT_RADIO:
|
||||
break;
|
||||
case NS_FORM_INPUT_SUBMIT:
|
||||
break;
|
||||
case NS_FORM_INPUT_TEXT:
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
|
||||
break;
|
||||
case NS_FORM_LABEL:
|
||||
break;
|
||||
case NS_FORM_OPTION:
|
||||
break;
|
||||
case NS_FORM_OPTGROUP:
|
||||
break;
|
||||
case NS_FORM_LEGEND:
|
||||
break;
|
||||
case NS_FORM_SELECT:
|
||||
break;
|
||||
case NS_FORM_TEXTAREA:
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
|
||||
break;
|
||||
case NS_FORM_OBJECT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (mEmbedCtxType & GTK_MOZ_EMBED_CTX_INPUT) {
|
||||
PRBool rdonly = PR_FALSE;
|
||||
if (mCtxFormType == NS_FORM_TEXTAREA) {
|
||||
nsCOMPtr<nsIDOMHTMLTextAreaElement> input;
|
||||
input = do_QueryInterface(mEventNode, &rv);
|
||||
if (!NS_FAILED(rv) && input)
|
||||
rv = input->GetReadOnly(&rdonly);
|
||||
if (!NS_FAILED(rv) && rdonly) {
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_ROINPUT;
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> input;
|
||||
input = do_QueryInterface(mEventNode, &rv);
|
||||
if (!NS_FAILED(rv) && input)
|
||||
rv = input->GetReadOnly(&rdonly);
|
||||
if (!NS_FAILED(rv) && rdonly) {
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_ROINPUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
const char*
|
||||
EmbedContextMenuInfo::GetSelectedText()
|
||||
{
|
||||
nsString cString;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (mCtxFormType != 0 && mEventNode) {
|
||||
PRInt32 TextLength = 0, selStart = 0, selEnd = 0;
|
||||
if (mCtxFormType == NS_FORM_INPUT_TEXT || mCtxFormType == NS_FORM_INPUT_FILE) {
|
||||
nsCOMPtr<nsIDOMNSHTMLInputElement> nsinput = do_QueryInterface(mEventNode, &rv);
|
||||
if (NS_SUCCEEDED(rv) && nsinput)
|
||||
nsinput->GetTextLength(&TextLength);
|
||||
if (TextLength > 0) {
|
||||
nsinput->GetSelectionEnd(&selEnd);
|
||||
nsinput->GetSelectionStart(&selStart);
|
||||
if (selStart < selEnd || mCtxFormType == NS_FORM_INPUT_FILE) {
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(mEventNode, &rv);
|
||||
rv = input->GetValue(cString);
|
||||
}
|
||||
}
|
||||
} else if (mCtxFormType == NS_FORM_TEXTAREA) {
|
||||
nsCOMPtr<nsIDOMNSHTMLTextAreaElement> nsinput = do_QueryInterface(mEventNode, &rv);
|
||||
if (NS_SUCCEEDED(rv) && nsinput)
|
||||
nsinput->GetTextLength(&TextLength);
|
||||
if (TextLength > 0) {
|
||||
nsinput->GetSelectionStart(&selStart);
|
||||
nsinput->GetSelectionEnd(&selEnd);
|
||||
if (selStart < selEnd) {
|
||||
nsCOMPtr<nsIDOMHTMLTextAreaElement> input = do_QueryInterface(mEventNode, &rv);
|
||||
rv = input->GetValue(cString);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NS_SUCCEEDED(rv) && !cString.IsEmpty()) {
|
||||
if (selStart < selEnd) {
|
||||
cString.Cut(0, selStart);
|
||||
cString.Cut(selEnd-selStart, TextLength);
|
||||
}
|
||||
rv = NS_OK;
|
||||
}
|
||||
} else if (mCtxDocument) {
|
||||
nsCOMPtr<nsIDOMNSHTMLDocument> htmlDoc = do_QueryInterface(mCtxDocument, &rv);
|
||||
if (NS_FAILED(rv) || !htmlDoc)
|
||||
return nsnull;
|
||||
rv = htmlDoc->GetSelection(cString);
|
||||
if (NS_FAILED(rv) || cString.IsEmpty())
|
||||
return nsnull;
|
||||
rv = NS_OK;
|
||||
}
|
||||
if (rv == NS_OK) {
|
||||
return NS_ConvertUTF16toUTF8(cString).get();
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::CheckDomImageElement(nsIDOMNode *node, nsString& aHref,
|
||||
PRInt32 *aWidth, PRInt32 *aHeight)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> image =
|
||||
do_QueryInterface(node, &rv);
|
||||
if (image) {
|
||||
rv = image->GetSrc(aHref);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
rv = image->GetWidth(aWidth);
|
||||
rv = image->GetHeight(aHeight);
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::GetImageRequest(imgIRequest **aRequest, nsIDOMNode *aDOMNode)
|
||||
{
|
||||
NS_ENSURE_ARG(aDOMNode);
|
||||
NS_ENSURE_ARG_POINTER(aRequest);
|
||||
|
||||
// Get content
|
||||
nsCOMPtr<nsIImageLoadingContent> content(do_QueryInterface(aDOMNode));
|
||||
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
|
||||
|
||||
return content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
||||
aRequest);
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::CheckDomHtmlNode(nsIDOMNode *aNode)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsString uTag;
|
||||
PRUint16 dnode_type;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
if (!aNode && mEventNode)
|
||||
node = mEventNode;
|
||||
nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(node, &rv);
|
||||
if (!element) {
|
||||
element = do_QueryInterface(mOrigNode, &rv);
|
||||
if (element) {
|
||||
node = mOrigNode;
|
||||
element = do_QueryInterface(node, &rv);
|
||||
}
|
||||
}
|
||||
|
||||
rv = node->GetNodeType(&dnode_type);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!((nsIDOMNode::ELEMENT_NODE == dnode_type) && element)) {
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNSHTMLElement> nodeElement = do_QueryInterface(node, &rv);
|
||||
if (NS_SUCCEEDED(rv) && nodeElement) {
|
||||
mNSHHTMLElement = nodeElement;
|
||||
} else {
|
||||
mNSHHTMLElement = nsnull;
|
||||
}
|
||||
rv = element->GetLocalName(uTag);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if (uTag.LowerCaseEqualsLiteral("object")) {
|
||||
}
|
||||
else if (uTag.LowerCaseEqualsLiteral("html")) {
|
||||
}
|
||||
else if (uTag.LowerCaseEqualsLiteral("a")) {
|
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(node);
|
||||
anchor->GetHref(mCtxHref);
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_LINK;
|
||||
if (anchor && !mCtxHref.IsEmpty()) {
|
||||
if (mCtxHref.LowerCaseEqualsLiteral("text/smartbookmark")) {
|
||||
nsCOMPtr<nsIDOMNode> childNode;
|
||||
node->GetFirstChild(getter_AddRefs(childNode));
|
||||
if (childNode) {
|
||||
PRInt32 width, height;
|
||||
rv = CheckDomImageElement(node, mCtxImgHref, &width, &height);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IMAGE;
|
||||
}
|
||||
} else if (StringBeginsWith(mCtxHref, NS_LITERAL_STRING("mailto:"))) {
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_EMAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (uTag.LowerCaseEqualsLiteral("area")) {
|
||||
nsCOMPtr<nsIDOMHTMLAreaElement> area = do_QueryInterface(node, &rv);
|
||||
if (NS_SUCCEEDED(rv) && area) {
|
||||
PRBool aNoHref = PR_FALSE;
|
||||
rv = area->GetNoHref(&aNoHref);
|
||||
if (aNoHref == PR_FALSE)
|
||||
rv = area->GetHref(mCtxHref);
|
||||
else
|
||||
rv = area->GetTarget(mCtxHref);
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_LINK;
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
else if (uTag.LowerCaseEqualsLiteral("img")) {
|
||||
PRInt32 width, height;
|
||||
rv = CheckDomImageElement(node, mCtxImgHref, &width, &height);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IMAGE;
|
||||
} else {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::UpdateContextData(void *aEvent)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEvent);
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMEvent> event = do_QueryInterface((nsISupports*)aEvent, &rv);
|
||||
if (NS_FAILED(rv) || !event)
|
||||
return NS_ERROR_FAILURE;
|
||||
return UpdateContextData(event);
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::GetElementForScroll(nsIDOMEvent *aEvent)
|
||||
{
|
||||
if (!aEvent) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
nsevent->GetOriginalTarget(getter_AddRefs(target));
|
||||
if (!target) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIDOMNode> targetDOMNode(do_QueryInterface(target));
|
||||
if (!targetDOMNode) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIDOMDocument> targetDOMDocument;
|
||||
targetDOMNode->GetOwnerDocument(getter_AddRefs(targetDOMDocument));
|
||||
if (!targetDOMDocument) return NS_ERROR_UNEXPECTED;
|
||||
return GetElementForScroll(targetDOMDocument);
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::GetElementForScroll(nsIDOMDocument *targetDOMDocument)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> targetDOMElement;
|
||||
targetDOMDocument->GetDocumentElement(getter_AddRefs(targetDOMElement));
|
||||
if (!targetDOMElement) return NS_ERROR_UNEXPECTED;
|
||||
nsString bodyName(NS_LITERAL_STRING("body"));
|
||||
nsCOMPtr<nsIDOMNodeList> bodyList;
|
||||
targetDOMElement->GetElementsByTagName(bodyName, getter_AddRefs(bodyList));
|
||||
PRUint32 i = 0;
|
||||
bodyList->GetLength(&i);
|
||||
if (i) {
|
||||
nsCOMPtr<nsIDOMNode> domBodyNode;
|
||||
bodyList->Item(0, getter_AddRefs(domBodyNode));
|
||||
if (!domBodyNode) return NS_ERROR_UNEXPECTED;
|
||||
mNSHHTMLElementSc = do_QueryInterface(domBodyNode);
|
||||
if (!mNSHHTMLElementSc) return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedContextMenuInfo::UpdateContextData(nsIDOMEvent *aDOMEvent)
|
||||
{
|
||||
if (mCtxEvent == aDOMEvent)
|
||||
return NS_OK;
|
||||
|
||||
nsresult rv = nsnull;
|
||||
mCtxEvent = aDOMEvent;
|
||||
NS_ENSURE_ARG_POINTER(mCtxEvent);
|
||||
|
||||
PRUint16 eventphase;
|
||||
mCtxEvent->GetEventPhase(&eventphase);
|
||||
if (!eventphase) {
|
||||
mCtxEvent = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> originalTarget = nsnull;
|
||||
nsCOMPtr<nsIDOMNode> originalNode = nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMNSEvent> aEvent = do_QueryInterface(mCtxEvent, &rv);
|
||||
if (NS_FAILED(rv) || !aEvent)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(mCtxEvent, &rv));
|
||||
if (mouseEvent) {
|
||||
((nsIDOMMouseEvent*)mouseEvent)->GetClientX(&mX);
|
||||
((nsIDOMMouseEvent*)mouseEvent)->GetClientY(&mY);
|
||||
}
|
||||
|
||||
if (aEvent)
|
||||
rv = aEvent->GetOriginalTarget(getter_AddRefs(originalTarget));
|
||||
originalNode = do_QueryInterface(originalTarget);
|
||||
if (NS_FAILED(rv) || !originalNode)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// nsresult SelText = mOwner->ClipBoardAction(GTK_MOZ_EMBED_CAN_COPY);
|
||||
if (originalNode == mOrigNode)
|
||||
return NS_OK;
|
||||
|
||||
mEmbedCtxType = GTK_MOZ_EMBED_CTX_NONE;
|
||||
mOrigNode = originalNode;
|
||||
if (mOrigNode) {
|
||||
nsString SOrigNode;
|
||||
mOrigNode->GetNodeName(SOrigNode);
|
||||
if (SOrigNode.EqualsLiteral("#document"))
|
||||
return NS_OK;
|
||||
if (SOrigNode.EqualsLiteral("xul:thumb")
|
||||
|| SOrigNode.EqualsLiteral("xul:slider")
|
||||
|| SOrigNode.EqualsLiteral("xul:scrollbarbutton")
|
||||
|| SOrigNode.EqualsLiteral("xul:vbox")
|
||||
|| SOrigNode.EqualsLiteral("xul:spacer")) {
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_XUL;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
if (mCtxEvent)
|
||||
rv = mCtxEvent->GetTarget(getter_AddRefs(mEventTarget));
|
||||
if (NS_FAILED(rv) || !mEventTarget) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> eventNode = do_QueryInterface(mEventTarget, &rv);
|
||||
mEventNode = eventNode;
|
||||
//Frame Stuff
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
if (mEventNode)
|
||||
rv = mEventNode->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
if (!NS_SUCCEEDED(rv) || !domDoc) {
|
||||
// return NS_OK;
|
||||
}
|
||||
if (NS_SUCCEEDED(rv) && domDoc && mCtxDocument != domDoc) {
|
||||
mCtxDocument = domDoc;
|
||||
mNSHHTMLElementSc = nsnull;
|
||||
nsCOMPtr<nsIDOM3Document> docuri = do_QueryInterface(mCtxDocument);
|
||||
docuri->GetDocumentURI(mCtxURI);
|
||||
NS_ENSURE_ARG_POINTER(mOwner);
|
||||
nsCOMPtr<nsIWebBrowser> webBrowser;
|
||||
mOwner->mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
|
||||
webBrowser->GetContentDOMWindow(getter_AddRefs(mCtxDomWindow));
|
||||
nsCOMPtr<nsIDOMDocument> mainDocument;
|
||||
mCtxDomWindow->GetDocument(getter_AddRefs(mainDocument));
|
||||
if (!mainDocument) {
|
||||
return NS_OK;
|
||||
}
|
||||
mCtxFrameNum = -1;
|
||||
if (mainDocument != domDoc) {
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IFRAME;
|
||||
SetFrameIndex();
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIDOMElement> targetDOMElement;
|
||||
mCtxDocument->GetDocumentElement(getter_AddRefs(targetDOMElement));
|
||||
if (!targetDOMElement) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIDOMNSHTMLDocument> htmlDoc = do_QueryInterface(mCtxDocument);
|
||||
if (htmlDoc) {
|
||||
nsString DMode;
|
||||
htmlDoc->GetDesignMode(DMode);
|
||||
if (DMode.EqualsLiteral("on")) {
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_RICHEDIT;
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mCtxDocument);
|
||||
if (!doc)
|
||||
return NS_OK;
|
||||
nsIPresShell *presShell = doc->GetShellAt(0);
|
||||
if (!presShell)
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIContent> tgContent = do_QueryInterface(mEventTarget);
|
||||
nsIFrame* frame = nsnull;
|
||||
#if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
|
||||
if (mEmbedCtxType & GTK_MOZ_EMBED_CTX_RICHEDIT)
|
||||
frame = presShell->GetRootFrame();
|
||||
else {
|
||||
#ifdef MOZILLA_1_8_BRANCH
|
||||
frame = nsnull;
|
||||
presShell->GetPrimaryFrameFor(tgContent, &frame);
|
||||
#else
|
||||
frame = presShell->GetPrimaryFrameFor(tgContent);
|
||||
#endif
|
||||
}
|
||||
if (frame) {
|
||||
mFormRect = frame->GetScreenRectExternal();
|
||||
}
|
||||
#endif
|
||||
if (NS_SUCCEEDED(SetFormControlType(mEventTarget))) {
|
||||
return NS_OK;
|
||||
}
|
||||
CheckDomHtmlNode();
|
||||
nsCOMPtr<nsIDOMNode> node = mEventNode;
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
node->GetParentNode(getter_AddRefs(parentNode));
|
||||
node = parentNode;
|
||||
while (node) {
|
||||
if (NS_FAILED(CheckDomHtmlNode()))
|
||||
break;
|
||||
node->GetParentNode(getter_AddRefs(parentNode));
|
||||
node = parentNode;
|
||||
}
|
||||
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_DOCUMENT;
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Oleg Romashin. Portions created by Oleg Romashin are Copyright (C) Oleg Romashin. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef EmbedContextMenuInfo_h__
|
||||
#define EmbedContextMenuInfo_h__
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "imgIRequest.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsRect.h"
|
||||
// for strings
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#endif
|
||||
#include "EmbedWindow.h"
|
||||
#include "nsIDOMNSHTMLElement.h"
|
||||
//*****************************************************************************
|
||||
// class EmbedContextMenuInfo
|
||||
//
|
||||
//*****************************************************************************
|
||||
class EmbedContextMenuInfo : public nsISupports
|
||||
{
|
||||
public:
|
||||
EmbedContextMenuInfo(EmbedPrivate *aOwner);
|
||||
virtual ~EmbedContextMenuInfo(void);
|
||||
NS_DECL_ISUPPORTS
|
||||
nsresult GetFormControlType(nsIDOMEvent *aDOMEvent);
|
||||
nsresult UpdateContextData(nsIDOMEvent *aDOMEvent);
|
||||
nsresult UpdateContextData(void *aEvent);
|
||||
const char* GetSelectedText();
|
||||
nsresult GetElementForScroll(nsIDOMDocument *targetDOMDocument);
|
||||
nsresult GetElementForScroll(nsIDOMEvent *aEvent);
|
||||
nsresult CheckDomImageElement(nsIDOMNode *node, nsString& aHref,
|
||||
PRInt32 *aWidth, PRInt32 *aHeight);
|
||||
nsresult GetImageRequest(imgIRequest **aRequest, nsIDOMNode *aDOMNode);
|
||||
nsString GetCtxDocTitle(void) { return mCtxDocTitle; };
|
||||
|
||||
|
||||
PRInt32 mX, mY, mObjWidth, mObjHeight, mCtxFrameNum;
|
||||
nsString mCtxURI, mCtxHref, mCtxImgHref;
|
||||
PRUint32 mEmbedCtxType;
|
||||
PRInt32 mCtxFormType;
|
||||
nsCOMPtr<nsIDOMNode> mEventNode;
|
||||
nsCOMPtr<nsIDOMEventTarget> mEventTarget;
|
||||
nsCOMPtr<nsIDOMDocument>mCtxDocument;
|
||||
nsRect mFormRect;
|
||||
nsCOMPtr<nsIDOMWindow> mCtxDomWindow;
|
||||
nsCOMPtr<nsIDOMEvent> mCtxEvent;
|
||||
nsCOMPtr<nsIDOMNSHTMLElement> mNSHHTMLElement;
|
||||
nsCOMPtr<nsIDOMNSHTMLElement> mNSHHTMLElementSc;
|
||||
private:
|
||||
nsresult SetFrameIndex();
|
||||
nsresult SetFormControlType(nsIDOMEventTarget *originalTarget);
|
||||
nsresult CheckDomHtmlNode(nsIDOMNode *aNode = nsnull);
|
||||
|
||||
EmbedPrivate *mOwner;
|
||||
nsCOMPtr<nsIDOMNode> mOrigNode;
|
||||
nsString mCtxDocTitle;
|
||||
}; // class EmbedContextMenuInfo
|
||||
#endif // EmbedContextMenuInfo_h__
|
||||
@@ -1,328 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/**
|
||||
* Derived from GContentHandler http://landfill.mozilla.org/mxr-test/gnome/source/galeon/mozilla/ContentHandler.cpp
|
||||
*/
|
||||
#include "EmbedDownloadMgr.h"
|
||||
#include "EmbedGtkTools.h"
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsXPIDLString.h"
|
||||
#else
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#endif
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIPromptService.h"
|
||||
#include "nsIWebProgressListener2.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIExternalHelperAppService.h"
|
||||
#include "nsCExternalHandlerService.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsNetError.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsNetCID.h"
|
||||
#include <unistd.h>
|
||||
#include "gtkmozembed_download.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
#define UNKNOWN_FILE_SIZE -1
|
||||
|
||||
class EmbedDownloadMgr;
|
||||
class ProgressListener : public nsIWebProgressListener2
|
||||
{
|
||||
public:
|
||||
ProgressListener(EmbedDownload *aDownload):mDownload(aDownload)
|
||||
{
|
||||
};
|
||||
|
||||
~ProgressListener(void)
|
||||
{
|
||||
};
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER2
|
||||
|
||||
EmbedDownload *mDownload;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS2(ProgressListener, nsIWebProgressListener2, nsIWebProgressListener)
|
||||
NS_IMPL_ISUPPORTS1(EmbedDownloadMgr, nsIHelperAppLauncherDialog)
|
||||
|
||||
EmbedDownloadMgr::EmbedDownloadMgr(void)
|
||||
{
|
||||
}
|
||||
|
||||
EmbedDownloadMgr::~EmbedDownloadMgr(void)
|
||||
{
|
||||
}
|
||||
|
||||
static gchar *
|
||||
RemoveSchemeFromFilePath(gchar *path)
|
||||
{
|
||||
gchar *new_path = path;
|
||||
|
||||
if (!strncmp(path, "file://", 7)) {
|
||||
/* XXX this should really look for the first non / after file:/ instead of
|
||||
* assuming file://tmp v. file:///tmp
|
||||
*/
|
||||
new_path = g_strdup(path+sizeof("file:/"));
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
return new_path;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedDownloadMgr::Show(nsIHelperAppLauncher *aLauncher,
|
||||
nsISupports *aContext,
|
||||
PRUint32 aForced)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
/* create a Download object */
|
||||
GtkObject* instance = gtk_moz_embed_download_new();
|
||||
mDownload = (EmbedDownload *) GTK_MOZ_EMBED_DOWNLOAD(instance)->data;
|
||||
mDownload->parent = instance;
|
||||
|
||||
rv = GetDownloadInfo(aLauncher, aContext);
|
||||
|
||||
/* Retrieve GtkMozEmbed object from DOM Window */
|
||||
nsCOMPtr<nsIDOMWindow> parentDOMWindow = do_GetInterface(aContext);
|
||||
mDownload->gtkMozEmbedParentWidget = GetGtkWidgetForDOMWindow(parentDOMWindow);
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mDownload->gtkMozEmbedParentWidget),
|
||||
moz_embed_signals[DOWNLOAD_REQUEST],
|
||||
mDownload->server,
|
||||
mDownload->file_name,
|
||||
mDownload->file_type,
|
||||
(gulong) mDownload->file_size,
|
||||
1);
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mDownload->parent),
|
||||
moz_embed_download_signals[DOWNLOAD_STARTED_SIGNAL],
|
||||
&mDownload->file_name_with_path);
|
||||
|
||||
if (!mDownload->file_name_with_path) {
|
||||
gtk_moz_embed_download_do_command(GTK_MOZ_EMBED_DOWNLOAD(mDownload->parent),
|
||||
GTK_MOZ_EMBED_DOWNLOAD_CANCEL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mDownload->file_name_with_path = RemoveSchemeFromFilePath(mDownload->file_name_with_path);
|
||||
|
||||
return aLauncher->SaveToDisk(nsnull, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
EmbedDownloadMgr::GetDownloadInfo(nsIHelperAppLauncher *aLauncher,
|
||||
nsISupports *aContext)
|
||||
{
|
||||
/* File type */
|
||||
nsCOMPtr<nsIMIMEInfo> mimeInfo;
|
||||
nsresult rv = aLauncher->GetMIMEInfo(getter_AddRefs(mimeInfo));
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCAutoString mimeType;
|
||||
rv = mimeInfo->GetMIMEType(mimeType);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
/* File name */
|
||||
nsCAutoString tempFileName;
|
||||
nsAutoString suggestedFileName;
|
||||
rv = aLauncher->GetSuggestedFileName(suggestedFileName);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
tempFileName = NS_ConvertUTF16toUTF8(suggestedFileName);
|
||||
|
||||
/* Complete source URL */
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = aLauncher->GetSource(getter_AddRefs(uri));
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCAutoString spec;
|
||||
rv = uri->Resolve(NS_LITERAL_CSTRING("."), spec);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
/* Sets download object to keep control of each download. */
|
||||
mDownload->launcher = aLauncher;
|
||||
mDownload->downloaded_size = -1;
|
||||
mDownload->file_name = g_strdup((gchar *) tempFileName.get());
|
||||
mDownload->server = g_strconcat(spec.get(), (gchar *) mDownload->file_name, NULL);
|
||||
mDownload->file_type = g_strdup(mimeType.get());
|
||||
mDownload->file_size = UNKNOWN_FILE_SIZE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EmbedDownloadMgr::PromptForSaveToFile(nsIHelperAppLauncher *aLauncher,
|
||||
nsISupports *aWindowContext,
|
||||
const PRUnichar *aDefaultFile,
|
||||
const PRUnichar *aSuggestedFileExtension,
|
||||
nsILocalFile **_retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
|
||||
nsCAutoString filePath;
|
||||
filePath.Assign(mDownload->file_name_with_path);
|
||||
|
||||
nsCOMPtr<nsILocalFile> destFile;
|
||||
NS_NewNativeLocalFile(filePath,
|
||||
PR_TRUE,
|
||||
getter_AddRefs(destFile));
|
||||
if (!destFile)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
/* Progress listener to follow the download and connecting it to
|
||||
the launcher which controls the download. */
|
||||
nsCOMPtr<nsIWebProgressListener2> listener = new ProgressListener(mDownload);
|
||||
if (!listener)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = aLauncher->SetWebProgressListener(listener);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ADDREF(*_retval = destFile);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIWebProgressListener Functions
|
||||
all these methods must be here due to nsIWebProgressListener/2 inheritance */
|
||||
NS_IMETHODIMP ProgressListener::OnStatusChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
nsresult aStatus,
|
||||
const PRUnichar *aMessage)
|
||||
{
|
||||
if (NS_SUCCEEDED(aStatus))
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ProgressListener::OnStateChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest, PRUint32 aStateFlags,
|
||||
nsresult aStatus)
|
||||
{
|
||||
if (NS_FAILED(aStatus))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (aStateFlags & STATE_STOP)
|
||||
gtk_signal_emit(GTK_OBJECT(mDownload->parent),
|
||||
moz_embed_download_signals[DOWNLOAD_COMPLETED_SIGNAL]);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ProgressListener::OnProgressChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest, PRInt32 aCurSelfProgress,
|
||||
PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress,
|
||||
PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
return OnProgressChange64(aWebProgress,
|
||||
aRequest,
|
||||
aCurSelfProgress,
|
||||
aMaxSelfProgress,
|
||||
aCurTotalProgress,
|
||||
aMaxTotalProgress);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ProgressListener::OnLocationChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest, nsIURI *location)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ProgressListener::OnSecurityChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest, PRUint32 state)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* nsIWebProgressListener2 method */
|
||||
NS_IMETHODIMP ProgressListener::OnProgressChange64(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest, PRInt64 aCurSelfProgress,
|
||||
PRInt64 aMaxSelfProgress, PRInt64 aCurTotalProgress,
|
||||
PRInt64 aMaxTotalProgress)
|
||||
{
|
||||
mDownload->request = aRequest;
|
||||
|
||||
if (aMaxSelfProgress != UNKNOWN_FILE_SIZE) {
|
||||
gtk_signal_emit(GTK_OBJECT(mDownload->parent),
|
||||
moz_embed_download_signals[DOWNLOAD_PROGRESS_SIGNAL],
|
||||
(gulong) aCurSelfProgress, (gulong) aMaxSelfProgress, 1);
|
||||
}
|
||||
else {
|
||||
gtk_signal_emit(GTK_OBJECT(mDownload->parent),
|
||||
moz_embed_download_signals[DOWNLOAD_PROGRESS_SIGNAL],
|
||||
(gulong) aCurSelfProgress, 0, 1);
|
||||
}
|
||||
|
||||
/* storing current downloaded size. */
|
||||
mDownload->downloaded_size = (gulong) aCurSelfProgress;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ProgressListener::OnRefreshAttempted(nsIWebProgress *aWebProgress,
|
||||
nsIURI *aUri, PRInt32 aDelay,
|
||||
PRBool aSameUri,
|
||||
PRBool *allowRefresh)
|
||||
{
|
||||
*allowRefresh = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/**
|
||||
* Derived from GContentHandler http://landfill.mozilla.org/mxr-test/gnome/source/galeon/mozilla/ContentHandler.h
|
||||
*/
|
||||
#ifndef __EmbedDownloadMgr_h
|
||||
#define __EmbedDownloadMgr_h
|
||||
|
||||
#include "EmbedPrivate.h"
|
||||
#include "nsIHelperAppLauncherDialog.h"
|
||||
#include "nsIMIMEInfo.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIExternalHelperAppService.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#include "nsWeakReference.h"
|
||||
#define EMBED_DOWNLOADMGR_DESCRIPTION "MicroB Download Manager"
|
||||
#define EMBED_DOWNLOADMGR_CID {0x53df12a2, 0x1f4a, 0x4382, {0x99, 0x4e, 0xed, 0x62, 0xcf, 0x0d, 0x6b, 0x3a}}
|
||||
|
||||
class nsIURI;
|
||||
class nsIFile;
|
||||
class nsIFactory;
|
||||
class nsExternalAppHandler;
|
||||
|
||||
typedef struct _EmbedDownload EmbedDownload;
|
||||
|
||||
struct _EmbedDownload
|
||||
{
|
||||
GtkObject* parent;
|
||||
GtkWidget* gtkMozEmbedParentWidget;/** Associated gtkmozembed widget */
|
||||
|
||||
char* file_name; /** < The file's name */
|
||||
char* file_name_with_path; /** < The file's name */
|
||||
const char* server; /** < The server's name */
|
||||
const char* file_type; /** < The file's type */
|
||||
const char* handler_app; /** < The application's name */
|
||||
PRInt64 file_size; /** < The file's size */
|
||||
PRInt64 downloaded_size; /** < The download's size */
|
||||
gboolean is_paused; /** < If download is paused or not */
|
||||
gboolean open_with; /** < If the file can be opened by other application */
|
||||
|
||||
/* Pointer to mozilla interfaces */
|
||||
nsIHelperAppLauncher* launcher; /** < The mozilla's download dialog */
|
||||
nsIRequest* request; /** < The download request */
|
||||
};
|
||||
|
||||
class EmbedDownloadMgr : public nsIHelperAppLauncherDialog
|
||||
{
|
||||
public:
|
||||
EmbedDownloadMgr();
|
||||
virtual ~EmbedDownloadMgr();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
|
||||
|
||||
private:
|
||||
/** Gets all informations about a file which is being downloaded.
|
||||
*/
|
||||
NS_METHOD GetDownloadInfo(nsIHelperAppLauncher *aLauncher, nsISupports *aContext);
|
||||
|
||||
EmbedDownload *mDownload;
|
||||
};
|
||||
#endif /* __EmbedDownloadMgr_h */
|
||||
@@ -1,955 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
* Tomaz Noleto <tnoleto@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMMouseEvent.h"
|
||||
|
||||
#include "nsIDOMNSEvent.h"
|
||||
#include "nsIDOMKeyEvent.h"
|
||||
#include "nsIDOMUIEvent.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
|
||||
#include "EmbedEventListener.h"
|
||||
#include "EmbedPrivate.h"
|
||||
#include "gtkmozembed_internal.h"
|
||||
|
||||
static PRInt32 sLongPressTimer = 0, mLongMPressDelay = 1000;
|
||||
static PRInt32 sX = 0, sY = 0;
|
||||
static PRBool sMPressed = PR_FALSE, sIsScrolling = PR_FALSE;
|
||||
static char* gFavLocation = NULL;
|
||||
|
||||
EmbedEventListener::EmbedEventListener(void)
|
||||
{
|
||||
mOwner = nsnull;
|
||||
}
|
||||
|
||||
EmbedEventListener::~EmbedEventListener()
|
||||
{
|
||||
delete mCtxInfo;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(EmbedEventListener)
|
||||
NS_IMPL_RELEASE(EmbedEventListener)
|
||||
NS_INTERFACE_MAP_BEGIN(EmbedEventListener)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMKeyListener)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMKeyListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMUIListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMMouseMotionListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsresult
|
||||
EmbedEventListener::Init(EmbedPrivate *aOwner)
|
||||
{
|
||||
mOwner = aOwner;
|
||||
mCtxInfo = nsnull;
|
||||
mClickCount = 1;
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
mCtxInfo = new EmbedContextMenuInfo(aOwner);
|
||||
#endif
|
||||
mOwner->mNeedFav = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::HandleLink(nsIDOMNode* node)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> linkElement;
|
||||
linkElement = do_QueryInterface(node);
|
||||
if (!linkElement) return NS_ERROR_FAILURE;
|
||||
|
||||
nsString name;
|
||||
rv = linkElement->GetAttribute(NS_LITERAL_STRING("rel"), name);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsString link;
|
||||
rv = linkElement->GetAttribute(NS_LITERAL_STRING("href"), link);
|
||||
if (NS_FAILED(rv) || link.IsEmpty()) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
rv = node->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
if (NS_FAILED(rv) || !domDoc) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOM3Node> domnode = do_QueryInterface(domDoc);
|
||||
if (!domnode) return NS_ERROR_FAILURE;
|
||||
|
||||
nsString spec;
|
||||
domnode->GetBaseURI(spec);
|
||||
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
rv = NewURI(getter_AddRefs(baseURI), NS_ConvertUTF16toUTF8(spec).get());
|
||||
if (NS_FAILED(rv) || !baseURI) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCString url;
|
||||
rv = baseURI->Resolve(NS_ConvertUTF16toUTF8(link), url);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsString type;
|
||||
rv = linkElement->GetAttribute(NS_LITERAL_STRING("type"), type);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsString title;
|
||||
rv = linkElement->GetAttribute(NS_LITERAL_STRING("title"), title);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
// XXX This does not handle |BLAH ICON POWER"
|
||||
if (mOwner->mNeedFav && (name.LowerCaseEqualsLiteral("icon") ||
|
||||
name.LowerCaseEqualsLiteral("shortcut icon"))) {
|
||||
mOwner->mNeedFav = PR_FALSE;
|
||||
this->GetFaviconFromURI(url.get());
|
||||
}
|
||||
else if (name.LowerCaseEqualsLiteral("alternate") &&
|
||||
type.LowerCaseEqualsLiteral("application/rss+xml")) {
|
||||
|
||||
NS_ConvertUTF16toUTF8 narrowTitle(title);
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[RSS_REQUEST],
|
||||
(gchar *)url.get(),
|
||||
narrowTitle.get());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::HandleEvent(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsString eventType;
|
||||
aDOMEvent->GetType(eventType);
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
if (eventType.EqualsLiteral("focus"))
|
||||
if (mCtxInfo->GetFormControlType(aDOMEvent)) {
|
||||
if (mCtxInfo->mEmbedCtxType & GTK_MOZ_EMBED_CTX_INPUT) {
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_FOCUS],
|
||||
(void *)aDOMEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (eventType.EqualsLiteral("DOMLinkAdded")) {
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMEventTarget> eventTarget;
|
||||
|
||||
aDOMEvent->GetTarget(getter_AddRefs(eventTarget));
|
||||
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(eventTarget, &rv);
|
||||
if (NS_FAILED(rv) || !node)
|
||||
return NS_ERROR_FAILURE;
|
||||
HandleLink(node);
|
||||
} else if (eventType.EqualsLiteral("load")) {
|
||||
|
||||
nsIWebBrowser *webBrowser = nsnull;
|
||||
gtk_moz_embed_get_nsIWebBrowser(mOwner->mOwningWidget, &webBrowser);
|
||||
if (!webBrowser) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> DOMWindow;
|
||||
webBrowser->GetContentDOMWindow(getter_AddRefs(DOMWindow));
|
||||
if (!DOMWindow) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
DOMWindow->GetDocument(getter_AddRefs(doc));
|
||||
if (!doc) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMNodeList> nodelist = nsnull;
|
||||
doc->GetElementsByTagName( NS_LITERAL_STRING( "rss" ), getter_AddRefs( nodelist ));
|
||||
if (nodelist) {
|
||||
PRUint32 length = 0;
|
||||
nodelist->GetLength(&length);
|
||||
if (length >= 1) {
|
||||
char *url = gtk_moz_embed_get_location(mOwner->mOwningWidget);
|
||||
char *title = gtk_moz_embed_get_title(mOwner->mOwningWidget);
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[RSS_REQUEST],
|
||||
(gchar*)url,
|
||||
(gchar*)title);
|
||||
if (url)
|
||||
NS_Free(url);
|
||||
if (title)
|
||||
NS_Free(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mOwner->mNeedFav) {
|
||||
mOwner->mNeedFav = PR_FALSE;
|
||||
nsCString favicon_url = mOwner->mPrePath;
|
||||
favicon_url.AppendLiteral("/favicon.ico");
|
||||
this->GetFaviconFromURI(favicon_url.get());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::KeyDown(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMKeyEvent> keyEvent;
|
||||
keyEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!keyEvent)
|
||||
return NS_OK;
|
||||
// Return FALSE to this function to mark the event as not
|
||||
// consumed...
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_KEY_DOWN],
|
||||
(void *)keyEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::KeyUp(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMKeyEvent> keyEvent;
|
||||
keyEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!keyEvent)
|
||||
return NS_OK;
|
||||
// return FALSE to this function to mark this event as not
|
||||
// consumed...
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_KEY_UP],
|
||||
(void *)keyEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
} else {
|
||||
//mCtxInfo->UpdateContextData(aDOMEvent);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::KeyPress(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMKeyEvent> keyEvent;
|
||||
keyEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!keyEvent)
|
||||
return NS_OK;
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_KEY_PRESS],
|
||||
(void *)keyEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sLongMPress(void *aOwningWidget)
|
||||
{
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
if (!sMPressed || sIsScrolling)
|
||||
return FALSE;
|
||||
sMPressed = PR_FALSE;
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(aOwningWidget),
|
||||
moz_embed_signals[DOM_MOUSE_LONG_PRESS],
|
||||
(void *)0, &return_val);
|
||||
if (return_val) {
|
||||
sMPressed = PR_FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::MouseDown(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
|
||||
mouseEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!mouseEvent)
|
||||
return NS_OK;
|
||||
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
sMPressed = PR_TRUE;
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_MOUSE_DOWN],
|
||||
(void *)mouseEvent, &return_val);
|
||||
if (return_val) {
|
||||
mClickCount = 2;
|
||||
sMPressed = PR_FALSE;
|
||||
#if 1
|
||||
if (sLongPressTimer)
|
||||
g_source_remove(sLongPressTimer);
|
||||
#else
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
#endif
|
||||
} else {
|
||||
mClickCount = 1;
|
||||
sLongPressTimer = g_timeout_add(mLongMPressDelay, sLongMPress, mOwner->mOwningWidget);
|
||||
((nsIDOMMouseEvent*)mouseEvent)->GetScreenX(&sX);
|
||||
((nsIDOMMouseEvent*)mouseEvent)->GetScreenY(&sY);
|
||||
}
|
||||
|
||||
// handling event internally.
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
HandleSelection(mouseEvent);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::MouseUp(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
|
||||
mouseEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!mouseEvent)
|
||||
return NS_OK;
|
||||
|
||||
// handling event internally, first.
|
||||
HandleSelection(mouseEvent);
|
||||
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
if (sLongPressTimer)
|
||||
g_source_remove(sLongPressTimer);
|
||||
sMPressed = PR_FALSE;
|
||||
mOwner->mOpenBlock = sIsScrolling;
|
||||
sIsScrolling = sMPressed;
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_MOUSE_UP],
|
||||
(void *)mouseEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::MouseClick(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
|
||||
mouseEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!mouseEvent)
|
||||
return NS_OK;
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
sMPressed = PR_FALSE;
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_MOUSE_CLICK],
|
||||
(void *)mouseEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::MouseDblClick(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
|
||||
mouseEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!mouseEvent)
|
||||
return NS_OK;
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
if (sLongPressTimer)
|
||||
g_source_remove(sLongPressTimer);
|
||||
sMPressed = PR_FALSE;
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_MOUSE_DBL_CLICK],
|
||||
(void *)mouseEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::MouseOver(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
|
||||
mouseEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!mouseEvent)
|
||||
return NS_OK;
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_MOUSE_OVER],
|
||||
(void *)mouseEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
} else {
|
||||
//mCtxInfo->UpdateContextData(aDOMEvent);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::MouseOut(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
|
||||
mouseEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!mouseEvent)
|
||||
return NS_OK;
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_MOUSE_OUT],
|
||||
(void *)mouseEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::Activate(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!uiEvent)
|
||||
return NS_OK;
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_ACTIVATE],
|
||||
(void *)uiEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::FocusIn(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!uiEvent)
|
||||
return NS_OK;
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_FOCUS_IN],
|
||||
(void *)uiEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::FocusOut(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!uiEvent)
|
||||
return NS_OK;
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_FOCUS_OUT],
|
||||
(void *)uiEvent, &return_val);
|
||||
if (return_val) {
|
||||
aDOMEvent->StopPropagation();
|
||||
aDOMEvent->PreventDefault();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::MouseMove(nsIDOMEvent* aDOMEvent)
|
||||
{
|
||||
if (mCurSelCon)
|
||||
mCurSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
||||
|
||||
if (sMPressed &&
|
||||
gtk_signal_handler_pending(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_MOUSE_SCROLL], TRUE)) {
|
||||
// Return TRUE from your signal handler to mark the event as consumed.
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aDOMEvent);
|
||||
if (!mouseEvent)
|
||||
return NS_OK;
|
||||
PRInt32 newX, newY, subX, subY;
|
||||
((nsIDOMMouseEvent*)mouseEvent)->GetScreenX(&newX);
|
||||
((nsIDOMMouseEvent*)mouseEvent)->GetScreenY(&newY);
|
||||
subX = newX - sX;
|
||||
subY = newY - sY;
|
||||
nsresult rv = NS_OK;
|
||||
if (ABS(subX) > 10 || ABS(subY) > 10 || (sIsScrolling && sMPressed)) {
|
||||
if (!sIsScrolling) {
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_MOUSE_SCROLL],
|
||||
(void *)mouseEvent, &return_val);
|
||||
if (!return_val) {
|
||||
sIsScrolling = PR_TRUE;
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
if (mCtxInfo)
|
||||
rv = mCtxInfo->GetElementForScroll(aDOMEvent);
|
||||
#endif
|
||||
} else {
|
||||
sMPressed = PR_FALSE;
|
||||
sIsScrolling = PR_FALSE;
|
||||
}
|
||||
}
|
||||
if (sIsScrolling)
|
||||
{
|
||||
if (sLongPressTimer)
|
||||
g_source_remove(sLongPressTimer);
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
if (mCtxInfo->mNSHHTMLElementSc) {
|
||||
PRInt32 x, y;
|
||||
mCtxInfo->mNSHHTMLElementSc->GetScrollTop(&y);
|
||||
mCtxInfo->mNSHHTMLElementSc->GetScrollLeft(&x);
|
||||
#ifdef MOZ_SCROLL_TOP_LEFT_HACK
|
||||
rv = mCtxInfo->mNSHHTMLElementSc->ScrollTopLeft(y - subY, x - subX);
|
||||
#endif
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
if (rv == NS_ERROR_UNEXPECTED) {
|
||||
nsCOMPtr<nsIDOMWindow> DOMWindow;
|
||||
nsIWebBrowser *webBrowser = nsnull;
|
||||
gtk_moz_embed_get_nsIWebBrowser(mOwner->mOwningWidget, &webBrowser);
|
||||
webBrowser->GetContentDOMWindow(getter_AddRefs(DOMWindow));
|
||||
DOMWindow->ScrollBy(-subX, -subY);
|
||||
}
|
||||
}
|
||||
sX = newX;
|
||||
sY = newY;
|
||||
sIsScrolling = sMPressed;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::DragMove(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::Focus(nsIDOMEvent* aEvent)
|
||||
{
|
||||
nsString eventType;
|
||||
aEvent->GetType(eventType);
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
if (eventType.EqualsLiteral("focus") &&
|
||||
mCtxInfo->GetFormControlType(aEvent) &&
|
||||
mCtxInfo->mEmbedCtxType & GTK_MOZ_EMBED_CTX_INPUT) {
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DOM_FOCUS],
|
||||
(void *)aEvent, &return_val);
|
||||
if (return_val) {
|
||||
aEvent->StopPropagation();
|
||||
aEvent->PreventDefault();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::Blur(nsIDOMEvent* aEvent)
|
||||
{
|
||||
gint return_val = FALSE;
|
||||
mFocusInternalFrame = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
nsevent->GetOriginalTarget(getter_AddRefs(target));
|
||||
|
||||
if (!target)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);
|
||||
|
||||
if (targetContent) {
|
||||
#ifdef MOZILLA_1_8_BRANCH
|
||||
if (targetContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) {
|
||||
#else
|
||||
if (targetContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL)) {
|
||||
#endif
|
||||
if (sLongPressTimer)
|
||||
g_source_remove(sLongPressTimer);
|
||||
|
||||
sMPressed = sIsScrolling ? PR_FALSE : sMPressed;
|
||||
sIsScrolling = PR_FALSE;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::HandleSelection(nsIDOMMouseEvent* aDOMMouseEvent)
|
||||
{
|
||||
nsresult rv;
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
/* This function gets called everytime that a mousedown or a mouseup
|
||||
* event occurs.
|
||||
*/
|
||||
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aDOMMouseEvent));
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
rv = nsevent->GetOriginalTarget(getter_AddRefs(target));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> eventNode = do_QueryInterface(target);
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
rv = eventNode->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc, &rv);
|
||||
if (NS_FAILED(rv) || !doc)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsIPresShell *presShell = doc->GetShellAt(0);
|
||||
|
||||
/* Gets nsISelectionController interface for the current context */
|
||||
mCurSelCon = do_QueryInterface(presShell);
|
||||
if (!mCurSelCon)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
/* Gets event type */
|
||||
nsString eventType;
|
||||
rv = aDOMMouseEvent->GetType(eventType);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
/* Updates context to check which context is being clicked on */
|
||||
mCtxInfo->UpdateContextData(aDOMMouseEvent);
|
||||
|
||||
/* If a mousedown after 1 click is done (and if clicked context is not a XUL
|
||||
* one (e.g. scrollbar), the selection is disabled for that context.
|
||||
*/
|
||||
if (mCtxInfo->mEmbedCtxType & GTK_MOZ_EMBED_CTX_XUL || mCtxInfo->mEmbedCtxType & GTK_MOZ_EMBED_CTX_RICHEDIT)
|
||||
return rv;
|
||||
|
||||
if (eventType.EqualsLiteral("mousedown")) {
|
||||
|
||||
if (mClickCount == 1)
|
||||
rv = mCurSelCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF);
|
||||
|
||||
} // mousedown
|
||||
|
||||
/* If a mouseup occurs, the selection for context is enabled again (despite of
|
||||
* number of clicks). If this event occurs after 1 click, the selection of
|
||||
* both last and current contexts are cleaned up.
|
||||
*/
|
||||
if (eventType.EqualsLiteral("mouseup")) {
|
||||
|
||||
/* Selection controller of current event context */
|
||||
if (mCurSelCon) {
|
||||
rv = mCurSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
||||
if (mClickCount == 1) {
|
||||
nsCOMPtr<nsISelection> domSel;
|
||||
mCurSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
getter_AddRefs(domSel));
|
||||
rv = domSel->RemoveAllRanges();
|
||||
}
|
||||
}
|
||||
/* Selection controller of previous event context */
|
||||
if (mLastSelCon) {
|
||||
rv = mLastSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
||||
if (mClickCount == 1) {
|
||||
nsCOMPtr<nsISelection> domSel;
|
||||
mLastSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
getter_AddRefs(domSel));
|
||||
rv = domSel->RemoveAllRanges();
|
||||
}
|
||||
}
|
||||
|
||||
/* If 1 click was done (despite the event type), sets the last context's
|
||||
* selection controller with current one
|
||||
*/
|
||||
if (mClickCount == 1)
|
||||
mLastSelCon = mCurSelCon;
|
||||
} // mouseup
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedEventListener::NewURI(nsIURI **result,
|
||||
const char *spec)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCString cSpec(spec);
|
||||
nsCOMPtr<nsIIOService> ioService;
|
||||
rv = GetIOService(getter_AddRefs(ioService));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = ioService->NewURI(cSpec, nsnull, nsnull, result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedEventListener::GetIOService(nsIIOService **ioService)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> mgr;
|
||||
NS_GetServiceManager(getter_AddRefs(mgr));
|
||||
if (!mgr) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = mgr->GetServiceByContractID("@mozilla.org/network/io-service;1",
|
||||
NS_GET_IID(nsIIOService),
|
||||
(void **)ioService);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
void
|
||||
EmbedEventListener::GeneratePixBuf()
|
||||
{
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
pixbuf = gdk_pixbuf_new_from_file(::gFavLocation, NULL);
|
||||
if (!pixbuf) {
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[ICON_CHANGED],
|
||||
NULL );
|
||||
|
||||
// remove the wrong favicon
|
||||
// FIXME: need better impl...
|
||||
nsCOMPtr<nsILocalFile> faviconFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
|
||||
if (!faviconFile) {
|
||||
NS_Free(::gFavLocation);
|
||||
gFavLocation = nsnull;
|
||||
return;
|
||||
}
|
||||
|
||||
nsCString faviconLocation(::gFavLocation);
|
||||
faviconFile->InitWithNativePath(faviconLocation);
|
||||
faviconFile->Remove(FALSE);
|
||||
NS_Free(::gFavLocation);
|
||||
gFavLocation = nsnull;
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[ICON_CHANGED],
|
||||
pixbuf );
|
||||
//mOwner->mNeedFav = PR_FALSE;
|
||||
NS_Free(::gFavLocation);
|
||||
gFavLocation = nsnull;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
EmbedEventListener::GetFaviconFromURI(const char* aURI)
|
||||
{
|
||||
gchar *file_name = NS_strdup(aURI);
|
||||
gchar *favicon_uri = NS_strdup(aURI);
|
||||
|
||||
gint i = 0;
|
||||
gint rv = 0;
|
||||
|
||||
nsCOMPtr<nsIWebBrowserPersist> persist = do_CreateInstance(NS_WEBBROWSERPERSIST_CONTRACTID);
|
||||
if (!persist) {
|
||||
NS_Free(file_name);
|
||||
NS_Free(favicon_uri);
|
||||
return;
|
||||
}
|
||||
persist->SetProgressListener(this);
|
||||
|
||||
while (file_name[i] != '\0') {
|
||||
if (file_name[i] == '/' || file_name[i] == ':')
|
||||
file_name[i] = '_';
|
||||
i++;
|
||||
}
|
||||
|
||||
nsCString fileName(file_name);
|
||||
|
||||
nsCOMPtr<nsILocalFile> favicon_dir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
|
||||
if (!favicon_dir) {
|
||||
NS_Free(favicon_uri);
|
||||
NS_Free(file_name);
|
||||
return;
|
||||
}
|
||||
|
||||
nsCString faviconDir("~/.mozilla/favicon");
|
||||
favicon_dir->InitWithNativePath(faviconDir);
|
||||
|
||||
PRBool isExist;
|
||||
rv = favicon_dir->Exists(&isExist);
|
||||
if (NS_SUCCEEDED(rv) && !isExist) {
|
||||
rv = favicon_dir->Create(nsIFile::DIRECTORY_TYPE,0775);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_Free(file_name);
|
||||
NS_Free(favicon_uri);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nsCAutoString favicon_path("~/.mozilla/favicon");
|
||||
nsCOMPtr<nsILocalFile> target_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
if (!target_file) {
|
||||
NS_Free(file_name);
|
||||
NS_Free(favicon_uri);
|
||||
return;
|
||||
}
|
||||
target_file->InitWithNativePath(favicon_path);
|
||||
target_file->Append(NS_ConvertUTF8toUTF16(fileName));
|
||||
|
||||
nsString path;
|
||||
target_file->GetPath(path);
|
||||
::gFavLocation = NS_strdup(NS_ConvertUTF16toUTF8(path).get());
|
||||
nsCOMPtr<nsIIOService> ios(do_GetService(NS_IOSERVICE_CONTRACTID));
|
||||
if (!ios) {
|
||||
NS_Free(file_name);
|
||||
NS_Free(favicon_uri);
|
||||
NS_Free(::gFavLocation);
|
||||
gFavLocation = nsnull;
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
|
||||
rv = ios->NewURI(nsDependentCString(favicon_uri), "", nsnull, getter_AddRefs(uri));
|
||||
if (!uri) {
|
||||
NS_Free(file_name);
|
||||
NS_Free(favicon_uri);
|
||||
NS_Free(::gFavLocation);
|
||||
gFavLocation = nsnull;
|
||||
return;
|
||||
}
|
||||
NS_Free(file_name);
|
||||
NS_Free(favicon_uri);
|
||||
|
||||
// save the favicon if the icon does not exist
|
||||
rv = target_file->Exists(&isExist);
|
||||
if (NS_SUCCEEDED(rv) && !isExist) {
|
||||
rv = persist->SaveURI(uri, nsnull, nsnull, nsnull, "", target_file);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
GeneratePixBuf();
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::OnStateChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRUint32 aStateFlags,
|
||||
nsresult aStatus)
|
||||
{
|
||||
/* if (!(aStateFlags & (STATE_STOP | STATE_IS_NETWORK | STATE_IS_DOCUMENT))){*/
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
if (aStateFlags & STATE_STOP)
|
||||
/* FINISH DOWNLOADING */
|
||||
/* XXX sometimes this==0x0 and it cause crash in GeneratePixBuf, need workaround check for this */
|
||||
if (NS_SUCCEEDED(aStatus) && this)
|
||||
GeneratePixBuf();
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::OnProgressChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt32 aCurSelfProgress,
|
||||
PRInt32 aMaxSelfProgress,
|
||||
PRInt32 aCurTotalProgress,
|
||||
PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::OnLocationChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
nsIURI *aLocation)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::OnStatusChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
nsresult aStatus,
|
||||
const PRUnichar *aMessage)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedEventListener::OnSecurityChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRUint32 aState)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __EmbedEventListener_h
|
||||
#define __EmbedEventListener_h
|
||||
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMUIListener.h"
|
||||
|
||||
#include "nsIDOMMouseMotionListener.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "EmbedContextMenuInfo.h"
|
||||
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOM3Node.h"
|
||||
|
||||
#include "nsIURI.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsCWebBrowserPersist.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsISelectionController.h"
|
||||
#include "nsIDOMMouseEvent.h"
|
||||
#include "nsXPCOMStrings.h"
|
||||
#include "nsCRTGlue.h"
|
||||
|
||||
class EmbedPrivate;
|
||||
|
||||
class EmbedEventListener : public nsIDOMKeyListener,
|
||||
public nsIDOMMouseListener,
|
||||
public nsIDOMUIListener,
|
||||
public nsIDOMMouseMotionListener,
|
||||
public nsIWebProgressListener,
|
||||
public nsIDOMFocusListener
|
||||
{
|
||||
public:
|
||||
|
||||
EmbedEventListener();
|
||||
virtual ~EmbedEventListener();
|
||||
|
||||
nsresult Init(EmbedPrivate *aOwner);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// NS_DECL_NSIDOMEVENTLISTENER
|
||||
// nsIDOMEventListener
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD HandleLink(nsIDOMNode* node);
|
||||
// nsIDOMKeyListener
|
||||
|
||||
NS_IMETHOD KeyDown(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD KeyUp(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD KeyPress(nsIDOMEvent* aDOMEvent);
|
||||
|
||||
// nsIDOMMouseListener
|
||||
|
||||
NS_IMETHOD MouseDown(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD MouseUp(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD MouseClick(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD MouseDblClick(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD MouseOver(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD MouseOut(nsIDOMEvent* aDOMEvent);
|
||||
|
||||
// nsIDOMUIListener
|
||||
|
||||
NS_IMETHOD Activate(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD FocusIn(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD FocusOut(nsIDOMEvent* aDOMEvent);
|
||||
|
||||
// nsIDOMMouseMotionListener
|
||||
NS_IMETHOD MouseMove(nsIDOMEvent* aDOMEvent);
|
||||
NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent);
|
||||
EmbedContextMenuInfo* GetContextInfo() { return mCtxInfo; };
|
||||
|
||||
// nsIDOMFocusListener
|
||||
NS_IMETHOD Focus(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Blur(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD HandleSelection(nsIDOMMouseEvent* aDOMMouseEvent);
|
||||
|
||||
nsresult NewURI (nsIURI **result,
|
||||
const char *spec);
|
||||
nsresult GetIOService (nsIIOService **ioService);
|
||||
|
||||
void GeneratePixBuf ();
|
||||
|
||||
void GetFaviconFromURI (const char* aURI);
|
||||
private:
|
||||
|
||||
EmbedPrivate *mOwner;
|
||||
EmbedContextMenuInfo *mCtxInfo;
|
||||
|
||||
// Selection and some clipboard stuff
|
||||
nsCOMPtr<nsISelectionController> mCurSelCon;
|
||||
nsCOMPtr<nsISelectionController> mLastSelCon;
|
||||
PRBool mFocusInternalFrame;
|
||||
PRInt32 mClickCount;
|
||||
};
|
||||
|
||||
#endif /* __EmbedEventListener_h */
|
||||
@@ -1,207 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Antonio Gomes <tonikitoo@gmail.com>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "EmbedFilePicker.h"
|
||||
#include "EmbedGtkTools.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsStringGlue.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "prenv.h"
|
||||
|
||||
#ifdef MOZ_LOGGING
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
NS_IMPL_ISUPPORTS1(EmbedFilePicker, nsIFilePicker)
|
||||
|
||||
EmbedFilePicker::EmbedFilePicker(): mParent (nsnull),
|
||||
mMode(nsIFilePicker::modeOpen)
|
||||
{
|
||||
}
|
||||
|
||||
EmbedFilePicker::~EmbedFilePicker()
|
||||
{
|
||||
}
|
||||
|
||||
/* void init (in nsIDOMWindowInternal parent, in wstring title, in short mode); */
|
||||
NS_IMETHODIMP EmbedFilePicker::Init(nsIDOMWindow *parent, const nsAString &title, PRInt16 mode)
|
||||
{
|
||||
mParent = parent;
|
||||
mMode = mode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void appendFilters (in long filterMask); */
|
||||
NS_IMETHODIMP EmbedFilePicker::AppendFilters(PRInt32 filterMask)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void appendFilter (in wstring title, in wstring filter); */
|
||||
NS_IMETHODIMP EmbedFilePicker::AppendFilter(const nsAString &title, const nsAString &filter)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* attribute wstring defaultString; */
|
||||
NS_IMETHODIMP EmbedFilePicker::GetDefaultString(nsAString &aDefaultString)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EmbedFilePicker::SetDefaultString(const nsAString &aDefaultString)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* attribute wstring defaultExtension; */
|
||||
NS_IMETHODIMP EmbedFilePicker::GetDefaultExtension(nsAString &aDefaultExtension)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EmbedFilePicker::SetDefaultExtension(const nsAString &aDefaultExtension)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* attribute long filterIndex; */
|
||||
NS_IMETHODIMP EmbedFilePicker::GetFilterIndex(PRInt32 *aFilterIndex)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EmbedFilePicker::SetFilterIndex(PRInt32 aFilterIndex)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* attribute nsILocalFile displayDirectory; */
|
||||
NS_IMETHODIMP EmbedFilePicker::GetDisplayDirectory(nsILocalFile **aDisplayDirectory)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EmbedFilePicker::SetDisplayDirectory(nsILocalFile *aDisplayDirectory)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* readonly attribute nsILocalFile file; */
|
||||
NS_IMETHODIMP EmbedFilePicker::GetFile(nsILocalFile **aFile)
|
||||
{
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aFile);
|
||||
|
||||
if (mFilename.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(baseURI), mFilename);
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(baseURI, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = fileURL->GetFile(getter_AddRefs(file));
|
||||
|
||||
nsCOMPtr<nsILocalFile> localfile;
|
||||
localfile = do_QueryInterface(file, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ADDREF(*aFile = localfile);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(mParent, NS_OK);
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(mParent);
|
||||
NS_ENSURE_TRUE(parentWidget, NS_OK);
|
||||
/* XXX this message isn't really sure what it's trying to say */
|
||||
g_signal_emit_by_name(GTK_OBJECT(parentWidget), "alert", "File protocol not supported.", NULL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIFileURL fileURL; */
|
||||
NS_IMETHODIMP EmbedFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFileURL);
|
||||
*aFileURL = nsnull;
|
||||
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
GetFile(getter_AddRefs(file));
|
||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_CreateInstance(NS_STANDARDURL_CONTRACTID);
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_OUT_OF_MEMORY);
|
||||
fileURL->SetFile(file);
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsISimpleEnumerator files; */
|
||||
NS_IMETHODIMP EmbedFilePicker::GetFiles(nsISimpleEnumerator * *aFiles)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* short show (); */
|
||||
NS_IMETHODIMP EmbedFilePicker::Show(PRInt16 *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
NS_ENSURE_TRUE(mParent, NS_OK);
|
||||
|
||||
GtkWidget *parentWidget = GetGtkWidgetForDOMWindow(mParent);
|
||||
NS_ENSURE_TRUE(parentWidget, NS_OK);
|
||||
|
||||
gboolean response = 0;
|
||||
char *retname = nsnull;
|
||||
g_signal_emit_by_name(GTK_OBJECT(parentWidget),
|
||||
"upload_dialog",
|
||||
PR_GetEnv("HOME"),
|
||||
"",
|
||||
&retname,
|
||||
&response,
|
||||
NULL);
|
||||
|
||||
*_retval = response ? nsIFilePicker::returnOK : nsIFilePicker::returnCancel;
|
||||
|
||||
mFilename = retname;
|
||||
if (retname)
|
||||
NS_Free(retname);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __EmbedFilePicker_h
|
||||
#define __EmbedFilePicker_h
|
||||
|
||||
#include "nsIFilePicker.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
#include "gtkmozembed.h"
|
||||
#include "gtkmozembed_common.h"
|
||||
#include "EmbedPrivate.h"
|
||||
|
||||
#define EMBED_FILEPICKER_CID \
|
||||
{ /* f097d33b-1c97-48a6-af4c-07022857eb7c */ \
|
||||
0xf097d33b, \
|
||||
0x1c97, \
|
||||
0x48a6, \
|
||||
{0xaf, 0x4c, 0x07, 0x02, 0x28, 0x57, 0xeb, 0x7c} \
|
||||
}
|
||||
|
||||
#define EMBED_FILEPICKER_CONTRACTID "@mozilla.org/filepicker;1"
|
||||
#define EMBED_FILEPICKER_CLASSNAME "File Picker Implementation"
|
||||
|
||||
class EmbedFilePicker : public nsIFilePicker
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFILEPICKER
|
||||
EmbedFilePicker();
|
||||
|
||||
protected:
|
||||
nsIDOMWindow *mParent;
|
||||
PRInt16 mMode;
|
||||
nsCString mFilename;
|
||||
|
||||
private:
|
||||
~EmbedFilePicker();
|
||||
};
|
||||
#endif
|
||||
@@ -1,920 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Conrad Carlen <ccarlen@netscape.com>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
* (from original mozilla/embedding/lite/nsEmbedGlobalHistory.cpp)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/* XXX This file is probably out of sync with its original.
|
||||
* This is a bad thing
|
||||
*/
|
||||
#include "EmbedGlobalHistory.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsInt64.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "gtkmozembed_common.h"
|
||||
#include "nsISeekableStream.h"
|
||||
#ifndef MOZILLA_INTERNAL_API
|
||||
#include "nsCRT.h"
|
||||
#endif
|
||||
#include "nsILineInputStream.h"
|
||||
|
||||
// Constants
|
||||
#define defaultSeparator 1
|
||||
// Number of changes in history before automatic flush
|
||||
static const PRInt32 kNewEntriesBetweenFlush = 10;
|
||||
static const PRInt32 kMaxSafeReadEntriesCount = 2000;
|
||||
// Default expiration interval: used if can't get preference service value
|
||||
static const PRUint32 kDefaultExpirationIntervalDays = 7;
|
||||
// Mozilla and EAL standard are different each other
|
||||
static const PRInt64 kMSecsPerDay = LL_INIT(0, 60 * 60 * 24 * 1000);
|
||||
static const PRInt64 kOneThousand = LL_INIT(0, 1000);
|
||||
// The history list and the entries counter
|
||||
static GList *mURLList; /** < The history list */
|
||||
static PRInt64 mExpirationInterval; /** < Expiration interval time */
|
||||
static EmbedGlobalHistory *sEmbedGlobalHistory = nsnull;
|
||||
|
||||
//*****************************************************************************
|
||||
// HistoryEntryOld: an entry object and its methods
|
||||
//*****************************************************************************
|
||||
class HistoryEntry
|
||||
{
|
||||
public:
|
||||
PRInt64 mLastVisitTime; // Millisecs
|
||||
PRPackedBool mWritten; // TRUE if ever persisted
|
||||
nsCString mTitle; // The entry title
|
||||
nsCString mUrl; // The url itself
|
||||
};
|
||||
|
||||
#define CLOSE_FILE_HANDLE(file_handle) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (file_handle) { \
|
||||
close_output_stream(file_handle); \
|
||||
NS_RELEASE(file_handle); \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
static void close_output_stream(OUTPUT_STREAM *file_handle)
|
||||
{
|
||||
file_handle->Close();
|
||||
return;
|
||||
}
|
||||
|
||||
static bool file_handle_uri_exists(LOCAL_FILE *uri)
|
||||
{
|
||||
g_return_val_if_fail(uri, false);
|
||||
PRBool exists = PR_FALSE;
|
||||
uri->Exists(&exists);
|
||||
return exists;
|
||||
}
|
||||
|
||||
static LOCAL_FILE* file_handle_uri_new(const char *uri)
|
||||
{
|
||||
g_return_val_if_fail(uri, nsnull);
|
||||
nsresult rv;
|
||||
LOCAL_FILE *historyFile = nsnull;
|
||||
rv = NS_NewNativeLocalFile(nsDependentCString(uri), 1, &historyFile);
|
||||
return historyFile;
|
||||
}
|
||||
|
||||
static void file_handle_uri_release(LOCAL_FILE *uri)
|
||||
{
|
||||
g_return_if_fail(uri);
|
||||
NS_RELEASE(uri);
|
||||
}
|
||||
|
||||
|
||||
static bool file_handle_create_uri(OUTPUT_STREAM **file_handle, LOCAL_FILE *uri)
|
||||
{
|
||||
g_return_val_if_fail(file_handle, false);
|
||||
nsresult rv;
|
||||
rv = NS_NewLocalFileOutputStream(file_handle, uri, PR_RDWR | PR_APPEND | PR_CREATE_FILE, 0660);
|
||||
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
static bool file_handle_open_uri(OUTPUT_STREAM **file_handle, LOCAL_FILE *uri)
|
||||
{
|
||||
g_return_val_if_fail(file_handle, false);
|
||||
nsresult rv;
|
||||
rv = NS_NewLocalFileOutputStream(file_handle, uri, PR_RDWR, 0660);
|
||||
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
static bool file_handle_seek(OUTPUT_STREAM *file_handle, gboolean end)
|
||||
{
|
||||
g_return_val_if_fail(file_handle, false);
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(file_handle, &rv);
|
||||
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, end ? -1 : 0);
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
static bool file_handle_truncate(OUTPUT_STREAM *file_handle)
|
||||
{
|
||||
g_return_val_if_fail(file_handle, false);
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(file_handle, &rv);
|
||||
rv = seekable->SetEOF();
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
static guint64 file_handle_write(OUTPUT_STREAM *file_handle, gpointer line)
|
||||
{
|
||||
g_return_val_if_fail(file_handle, 0);
|
||||
PRUint32 amt = 0;
|
||||
nsresult rv;
|
||||
rv = file_handle->Write((char*)line, strlen((char*)line), &amt);
|
||||
/* XXX booleans are not equivalent to guint64 */
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
// Static Routine Prototypes
|
||||
//GnomeVFSHandle
|
||||
static nsresult writeEntry(OUTPUT_STREAM *file_handle, HistoryEntry *entry);
|
||||
// when an entry is visited
|
||||
nsresult OnVisited(HistoryEntry *entry)
|
||||
{
|
||||
NS_ENSURE_ARG(entry);
|
||||
entry->mLastVisitTime = PR_Now();
|
||||
LL_DIV(entry->mLastVisitTime, entry->mLastVisitTime, kOneThousand);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Return the last time an entry was visited
|
||||
PRInt64 GetLastVisitTime(HistoryEntry *entry)
|
||||
{
|
||||
NS_ENSURE_ARG(entry);
|
||||
return entry->mLastVisitTime;
|
||||
}
|
||||
|
||||
// Change the last time an entry was visited
|
||||
nsresult SetLastVisitTime(HistoryEntry *entry, const PRInt64& aTime)
|
||||
{
|
||||
NS_ENSURE_ARG(entry);
|
||||
NS_ENSURE_ARG_POINTER(aTime);
|
||||
entry->mLastVisitTime = aTime;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Return TRUE if an entry has been written
|
||||
PRBool GetIsWritten(HistoryEntry *entry)
|
||||
{
|
||||
NS_ENSURE_ARG(entry);
|
||||
return entry->mWritten;
|
||||
}
|
||||
|
||||
// Set TRUE when an entry is visited
|
||||
nsresult SetIsWritten(HistoryEntry *entry)
|
||||
{
|
||||
NS_ENSURE_ARG(entry);
|
||||
entry->mWritten = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Change the entry title
|
||||
#define SET_TITLE(entry, aTitle) (entry->mTitle.Assign(aTitle))
|
||||
|
||||
// Return the entry title
|
||||
#define GET_TITLE(entry) (entry && !entry->mTitle.IsEmpty() ? entry->mTitle.get() : "")
|
||||
|
||||
// Change the entry title
|
||||
nsresult SET_URL(HistoryEntry *aEntry, const char *aUrl)
|
||||
{
|
||||
NS_ENSURE_ARG(aEntry);
|
||||
NS_ENSURE_ARG(aUrl);
|
||||
aEntry->mUrl.Assign(aUrl);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Return the entry url
|
||||
const char* GET_URL(HistoryEntry *aEntry)
|
||||
{
|
||||
return (aEntry && !aEntry->mUrl.IsEmpty()) ? aEntry->mUrl.get() : "";
|
||||
}
|
||||
|
||||
// Traverse the history list trying to find a frame
|
||||
int history_entry_find_exist(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return g_ascii_strcasecmp((char*)GET_URL((HistoryEntry *)a), (char *) b);
|
||||
}
|
||||
|
||||
// Traverse the history list looking for the correct place to add a new item
|
||||
int find_insertion_place(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
PRInt64 lastVisitTime = GetLastVisitTime((HistoryEntry *) a);
|
||||
PRInt64 tempTime = GetLastVisitTime((HistoryEntry *) b);
|
||||
return LL_CMP(lastVisitTime, <, tempTime);
|
||||
}
|
||||
|
||||
// Check whether an entry has expired
|
||||
PRBool entryHasExpired(HistoryEntry *entry)
|
||||
{
|
||||
// convert "now" from microsecs to millisecs
|
||||
PRInt64 nowInMilliSecs = PR_Now();
|
||||
LL_DIV(nowInMilliSecs, nowInMilliSecs, kOneThousand);
|
||||
// determine when the entry would have expired
|
||||
PRInt64 expirationIntervalAgo;
|
||||
LL_SUB(expirationIntervalAgo, nowInMilliSecs, mExpirationInterval);
|
||||
PRInt64 lastVisitTime = GetLastVisitTime(entry);
|
||||
return LL_CMP(lastVisitTime, <, expirationIntervalAgo);
|
||||
}
|
||||
|
||||
// Traverse the history list to get all the entry data
|
||||
void history_entry_foreach_to_remove(gpointer data, gpointer user_data)
|
||||
{
|
||||
HistoryEntry *entry = (HistoryEntry *) data;
|
||||
if (entry) {
|
||||
entry->mLastVisitTime = 0;
|
||||
delete entry;
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// EmbedGlobalHistory - Creation/Destruction
|
||||
//*****************************************************************************
|
||||
NS_IMPL_ISUPPORTS2(EmbedGlobalHistory, nsIGlobalHistory2, nsIObserver)
|
||||
/* static */
|
||||
EmbedGlobalHistory*
|
||||
EmbedGlobalHistory::GetInstance()
|
||||
{
|
||||
if (!sEmbedGlobalHistory)
|
||||
{
|
||||
sEmbedGlobalHistory = new EmbedGlobalHistory();
|
||||
if (!sEmbedGlobalHistory)
|
||||
return nsnull;
|
||||
NS_ADDREF(sEmbedGlobalHistory); // addref the global
|
||||
if (NS_FAILED(sEmbedGlobalHistory->Init()))
|
||||
{
|
||||
NS_RELEASE(sEmbedGlobalHistory);
|
||||
return nsnull;
|
||||
}
|
||||
}
|
||||
else
|
||||
NS_ADDREF(sEmbedGlobalHistory); // addref the return result
|
||||
return sEmbedGlobalHistory;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
EmbedGlobalHistory::DeleteInstance()
|
||||
{
|
||||
if (sEmbedGlobalHistory)
|
||||
{
|
||||
delete sEmbedGlobalHistory;
|
||||
}
|
||||
}
|
||||
|
||||
// The global history component constructor
|
||||
EmbedGlobalHistory::EmbedGlobalHistory()
|
||||
: mFileHandle(nsnull)
|
||||
{
|
||||
if (!mURLList) {
|
||||
mDataIsLoaded = PR_FALSE;
|
||||
mFlushModeFullWriteNeeded = PR_FALSE;
|
||||
mEntriesAddedSinceFlush = 0;
|
||||
mHistoryFile = nsnull;
|
||||
LL_I2L(mExpirationInterval, kDefaultExpirationIntervalDays);
|
||||
LL_MUL(mExpirationInterval, mExpirationInterval, kMSecsPerDay);
|
||||
}
|
||||
}
|
||||
|
||||
// The global history component destructor
|
||||
EmbedGlobalHistory::~EmbedGlobalHistory()
|
||||
{
|
||||
LoadData();
|
||||
FlushData(kFlushModeFullWrite);
|
||||
if (mURLList) {
|
||||
g_list_foreach(mURLList, (GFunc) history_entry_foreach_to_remove, NULL);
|
||||
g_list_free(mURLList);
|
||||
mURLList = NULL;
|
||||
}
|
||||
if (mFileHandle) {
|
||||
CLOSE_FILE_HANDLE(mFileHandle);
|
||||
}
|
||||
if (mHistoryFile) {
|
||||
g_free(mHistoryFile);
|
||||
mHistoryFile = nsnull;
|
||||
}
|
||||
if (sEmbedGlobalHistory)
|
||||
sEmbedGlobalHistory = nsnull;
|
||||
}
|
||||
|
||||
// Initialize the global history component
|
||||
NS_IMETHODIMP EmbedGlobalHistory::Init()
|
||||
{
|
||||
if (mURLList) return NS_OK;
|
||||
// Get Pref and convert to millisecs
|
||||
|
||||
PRInt32 expireDays;
|
||||
int success = gtk_moz_embed_common_get_pref(G_TYPE_INT, EMBED_HISTORY_PREF_EXPIRE_DAYS, &expireDays);
|
||||
if (success) {
|
||||
LL_I2L(mExpirationInterval, expireDays);
|
||||
LL_MUL(mExpirationInterval, mExpirationInterval, kMSecsPerDay);
|
||||
}
|
||||
// register to observe profile changes
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
|
||||
NS_ASSERTION(observerService, "failed to get observer service");
|
||||
if (observerService) {
|
||||
observerService->AddObserver(this, "quit-application", PR_FALSE);
|
||||
observerService->AddObserver(this, "RemoveEntries", PR_FALSE);
|
||||
}
|
||||
nsresult rv = InitFile();
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
rv = LoadData();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#define BROKEN_RV_HANDLING_CODE(rv) PR_BEGIN_MACRO \
|
||||
if (NS_FAILED(rv)) { \
|
||||
/* OOPS the coder (not timeless) didn't handle this case well at all. \
|
||||
* unfortunately the coder will remain anonymous. \
|
||||
* XXX please fix me. \
|
||||
*/ \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#define BROKEN_STRING_GETTER(out) PR_BEGIN_MACRO \
|
||||
/* OOPS the coder (not timeless) decided not to do anything in this \
|
||||
* method, but to return NS_OK anyway. That's not very polite. \
|
||||
*/ \
|
||||
out.Truncate(); \
|
||||
PR_END_MACRO
|
||||
|
||||
#define BROKEN_STRING_BUILDER(var) PR_BEGIN_MACRO \
|
||||
/* This is just wrong */ \
|
||||
PR_END_MACRO
|
||||
|
||||
#define UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(newed) PR_BEGIN_MACRO \
|
||||
/* OOPS this code is using a glib allocation function which \
|
||||
* will cause the application to crash when it runs out of \
|
||||
* memory. This is not cool. either g_try methods should be \
|
||||
* used or malloc, or new (note that gecko /will/ be replacing \
|
||||
* its operator new such that new will not throw exceptions). \
|
||||
* XXX please fix me. \
|
||||
*/ \
|
||||
if (!newed) { \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#define ALLOC_NOT_CHECKED(newed) PR_BEGIN_MACRO \
|
||||
/* This might not crash, but the code probably isn't really \
|
||||
* designed to handle it, perhaps the code should be fixed? \
|
||||
*/ \
|
||||
if (!newed) { \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
//*****************************************************************************
|
||||
// EmbedGlobalHistory::nsIGlobalHistory
|
||||
//*****************************************************************************
|
||||
// Add a new URI to the history
|
||||
NS_IMETHODIMP EmbedGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aToplevel, nsIURI *aReferrer)
|
||||
{
|
||||
NS_ENSURE_ARG(aURI);
|
||||
nsCAutoString URISpec;
|
||||
aURI->GetSpec(URISpec);
|
||||
const char *aURL = URISpec.get();
|
||||
if (!aToplevel)
|
||||
return NS_OK;
|
||||
PRBool isHTTP, isHTTPS;
|
||||
nsresult rv = NS_OK;
|
||||
rv |= aURI->SchemeIs("http", &isHTTP);
|
||||
rv |= aURI->SchemeIs("https", &isHTTPS);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
// Only get valid uri schemes
|
||||
if (!isHTTP && !isHTTPS)
|
||||
{
|
||||
/* the following blacklist is silly.
|
||||
* if there's some need to whitelist http(s) + ftp,
|
||||
* that's what we should do.
|
||||
*/
|
||||
PRBool isAbout, isImap, isNews, isMailbox, isViewSource, isChrome, isData, isJavascript;
|
||||
rv = aURI->SchemeIs("about", &isAbout);
|
||||
rv |= aURI->SchemeIs("imap", &isImap);
|
||||
rv |= aURI->SchemeIs("news", &isNews);
|
||||
rv |= aURI->SchemeIs("mailbox", &isMailbox);
|
||||
rv |= aURI->SchemeIs("view-source", &isViewSource);
|
||||
rv |= aURI->SchemeIs("chrome", &isChrome);
|
||||
rv |= aURI->SchemeIs("data", &isData);
|
||||
rv |= aURI->SchemeIs("javascript", &isJavascript);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
|
||||
if (isAbout ||
|
||||
isImap ||
|
||||
isNews ||
|
||||
isMailbox ||
|
||||
isViewSource ||
|
||||
isChrome ||
|
||||
isData ||
|
||||
isJavascript) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
NS_WARNING("[HISTORY] Visited URL: %s\n", aURL);
|
||||
#endif
|
||||
rv = LoadData();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
GList *node = g_list_find_custom(mURLList, aURL, (GCompareFunc) history_entry_find_exist);
|
||||
HistoryEntry *entry = NULL;
|
||||
if (node && node->data)
|
||||
entry = (HistoryEntry *)(node->data);
|
||||
nsCAutoString hostname;
|
||||
aURI->GetHost(hostname);
|
||||
|
||||
// It is not in the history
|
||||
if (!entry) {
|
||||
entry = new HistoryEntry;
|
||||
ALLOC_NOT_CHECKED(entry);
|
||||
rv |= OnVisited(entry);
|
||||
SET_TITLE(entry, hostname);
|
||||
rv |= SET_URL(entry, aURL);
|
||||
BROKEN_RV_HANDLING_CODE(rv);
|
||||
unsigned int listSize = g_list_length(mURLList);
|
||||
if (listSize+1 > kDefaultMaxSize) {
|
||||
GList *last = g_list_last(mURLList);
|
||||
mURLList = g_list_remove(mURLList, last->data);
|
||||
}
|
||||
mURLList = g_list_insert_sorted(mURLList, entry,
|
||||
(GCompareFunc) find_insertion_place);
|
||||
// Flush after kNewEntriesBetweenFlush changes
|
||||
BROKEN_RV_HANDLING_CODE(rv);
|
||||
if (++mEntriesAddedSinceFlush >= kNewEntriesBetweenFlush)
|
||||
rv |= FlushData(kFlushModeAppend);
|
||||
// At this point, something understands there's a new global history item
|
||||
} else {
|
||||
// update the last visited time
|
||||
rv |= OnVisited(entry);
|
||||
SET_TITLE(entry, hostname);
|
||||
// Move the element to the start of the list
|
||||
BROKEN_RV_HANDLING_CODE(rv);
|
||||
mURLList = g_list_remove(mURLList, entry);
|
||||
mURLList = g_list_insert_sorted(mURLList, entry, (GCompareFunc) find_insertion_place);
|
||||
// Flush after kNewEntriesBetweenFlush changes
|
||||
BROKEN_RV_HANDLING_CODE(rv);
|
||||
|
||||
mFlushModeFullWriteNeeded = PR_TRUE;
|
||||
if (++mEntriesAddedSinceFlush >= kNewEntriesBetweenFlush)
|
||||
rv |= FlushData(kFlushModeFullWrite);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Return TRUE if the url is already in history
|
||||
NS_IMETHODIMP EmbedGlobalHistory::IsVisited(nsIURI *aURI, PRBool *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(aURI);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
nsCAutoString URISpec;
|
||||
aURI->GetSpec(URISpec);
|
||||
const char *aURL = URISpec.get();
|
||||
nsresult rv = LoadData();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
GList *node = g_list_find_custom(mURLList, aURL,
|
||||
(GCompareFunc) history_entry_find_exist);
|
||||
*_retval = (node && node->data);
|
||||
return rv;
|
||||
}
|
||||
|
||||
// It is called when Mozilla get real name of a URL
|
||||
NS_IMETHODIMP EmbedGlobalHistory::SetPageTitle(nsIURI *aURI,
|
||||
const nsAString & aTitle)
|
||||
{
|
||||
NS_ENSURE_ARG(aURI);
|
||||
nsresult rv;
|
||||
// skip about: URIs to avoid reading in the db (about:blank, especially)
|
||||
PRBool isAbout;
|
||||
rv = aURI->SchemeIs("about", &isAbout);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (isAbout)
|
||||
return NS_OK;
|
||||
nsCAutoString URISpec;
|
||||
aURI->GetSpec(URISpec);
|
||||
const char *aURL = URISpec.get();
|
||||
rv |= LoadData();
|
||||
BROKEN_RV_HANDLING_CODE(rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
GList *node = g_list_find_custom(mURLList, aURL,
|
||||
(GCompareFunc) history_entry_find_exist);
|
||||
HistoryEntry *entry = NULL;
|
||||
if (node)
|
||||
entry = (HistoryEntry *)(node->data);
|
||||
if (entry) {
|
||||
SET_TITLE(entry, NS_ConvertUTF16toUTF8(aTitle).get());
|
||||
BROKEN_RV_HANDLING_CODE(rv);
|
||||
|
||||
mFlushModeFullWriteNeeded = PR_TRUE;
|
||||
if (++mEntriesAddedSinceFlush >= kNewEntriesBetweenFlush)
|
||||
rv |= FlushData(kFlushModeFullWrite);
|
||||
BROKEN_RV_HANDLING_CODE(rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult EmbedGlobalHistory::RemoveEntries(const PRUnichar *url, int time)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (!mURLList)
|
||||
return rv;
|
||||
|
||||
if (url) {
|
||||
GList *node = g_list_find_custom(mURLList, NS_ConvertUTF16toUTF8(url).get(), (GCompareFunc) history_entry_find_exist);
|
||||
if (!node) return rv;
|
||||
if (node->data) {
|
||||
HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry *,
|
||||
node->data);
|
||||
|
||||
entry->mLastVisitTime = 0;
|
||||
delete entry;
|
||||
mURLList = g_list_remove(mURLList, entry);
|
||||
}
|
||||
} else {
|
||||
g_list_foreach (mURLList, (GFunc) history_entry_foreach_to_remove, NULL);
|
||||
g_list_free(mURLList);
|
||||
mURLList = NULL;
|
||||
}
|
||||
|
||||
mFlushModeFullWriteNeeded = PR_TRUE;
|
||||
mEntriesAddedSinceFlush++;
|
||||
rv = FlushData(kFlushModeFullWrite);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// EmbedGlobalHistory::nsIObserver
|
||||
//*****************************************************************************
|
||||
NS_IMETHODIMP EmbedGlobalHistory::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
const PRUnichar *aData)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
// used when the browser is closed and the EmbedGlobalHistory destructor is not called
|
||||
if (strcmp(aTopic, "quit-application") == 0) {
|
||||
rv = LoadData();
|
||||
// we have to sort the list before flush it
|
||||
rv |= FlushData(kFlushModeFullWrite);
|
||||
if (mURLList) {
|
||||
g_list_foreach(mURLList, (GFunc) history_entry_foreach_to_remove, NULL);
|
||||
g_list_free(mURLList);
|
||||
mURLList = NULL;
|
||||
}
|
||||
if (mFileHandle) {
|
||||
CLOSE_FILE_HANDLE(mFileHandle);
|
||||
}
|
||||
} else if (strcmp(aTopic, "RemoveEntries") == 0) {
|
||||
rv |= RemoveEntries(aData, 0);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
GetHistoryFileName(char **aHistoryFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aHistoryFile);
|
||||
// Get the history file in our profile dir.
|
||||
// Notice we are not just getting NS_APP_HISTORY_50_FILE
|
||||
// because it is used by the "real" global history component.
|
||||
if (EmbedPrivate::sProfileDir) {
|
||||
nsCString path;
|
||||
EmbedPrivate::sProfileDir->GetNativePath(path);
|
||||
*aHistoryFile = g_strdup_printf("%s/history.dat", path.get());
|
||||
BROKEN_STRING_BUILDER(aHistoryFile);
|
||||
} else {
|
||||
*aHistoryFile = g_strdup_printf("%s/history.dat", g_get_tmp_dir());
|
||||
BROKEN_STRING_BUILDER(aHistoryFile);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
//*****************************************************************************
|
||||
// EmbedGlobalHistory
|
||||
//*****************************************************************************
|
||||
// Open/Create the history.dat file if it does not exist
|
||||
nsresult EmbedGlobalHistory::InitFile()
|
||||
{
|
||||
if (!mHistoryFile) {
|
||||
if (NS_FAILED(GetHistoryFileName(&mHistoryFile)))
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
LOCAL_FILE *uri = file_handle_uri_new(mHistoryFile);
|
||||
if (!uri)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
gboolean rs = FALSE;
|
||||
if (!file_handle_uri_exists(uri)) {
|
||||
if (!file_handle_create_uri(&mFileHandle, uri)) {
|
||||
NS_WARNING("Could not create a history file\n");
|
||||
file_handle_uri_release(uri);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
CLOSE_FILE_HANDLE(mFileHandle);
|
||||
}
|
||||
rs = file_handle_open_uri(&mFileHandle, uri);
|
||||
|
||||
file_handle_uri_release(uri);
|
||||
|
||||
if (!rs) {
|
||||
NS_WARNING("Could not open a history file\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get the data from history.dat file
|
||||
nsresult EmbedGlobalHistory::LoadData()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (!mDataIsLoaded) {
|
||||
mDataIsLoaded = PR_TRUE;
|
||||
LOCAL_FILE *uri = file_handle_uri_new(mHistoryFile);
|
||||
if (uri) {
|
||||
rv |= ReadEntries(uri);
|
||||
file_handle_uri_release(uri);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Call a function to write each entry in the history hash table
|
||||
nsresult EmbedGlobalHistory::WriteEntryIfWritten(GList *list, OUTPUT_STREAM *file_handle)
|
||||
{
|
||||
if (!file_handle)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
unsigned int counter = g_list_length(list);
|
||||
while (counter > 0) {
|
||||
HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry*, g_list_nth_data(list, counter-1));
|
||||
counter--;
|
||||
if (!entry || entryHasExpired(entry)) {
|
||||
continue;
|
||||
}
|
||||
writeEntry(file_handle, entry);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Call a function to write each unwritten entry in the history hash table
|
||||
nsresult EmbedGlobalHistory::WriteEntryIfUnwritten(GList *list, OUTPUT_STREAM *file_handle)
|
||||
{
|
||||
if (!file_handle)
|
||||
return NS_ERROR_FAILURE;
|
||||
unsigned int counter = g_list_length(list);
|
||||
while (counter > 0) {
|
||||
HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry*, g_list_nth_data(list, counter-1));
|
||||
if (!entry || entryHasExpired(entry)) {
|
||||
counter--;
|
||||
continue;
|
||||
}
|
||||
if (!GetIsWritten(entry))
|
||||
writeEntry(file_handle, entry);
|
||||
counter--;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Write the history in history.dat file
|
||||
nsresult EmbedGlobalHistory::FlushData(PRIntn mode)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mEntriesAddedSinceFlush == 0)
|
||||
return NS_OK;
|
||||
if (!mHistoryFile)
|
||||
{
|
||||
rv = InitFile();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = FlushData(kFlushModeFullWrite);
|
||||
return rv;
|
||||
}
|
||||
LOCAL_FILE *uri = file_handle_uri_new(mHistoryFile);
|
||||
if (!uri) return NS_ERROR_FAILURE;
|
||||
|
||||
gboolean rs = file_handle_uri_exists(uri);
|
||||
file_handle_uri_release(uri);
|
||||
|
||||
if (!rs && NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (mode == kFlushModeFullWrite || mFlushModeFullWriteNeeded == PR_TRUE)
|
||||
{
|
||||
if (!file_handle_seek(mFileHandle, FALSE))
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!file_handle_truncate(mFileHandle))
|
||||
return NS_ERROR_FAILURE;
|
||||
WriteEntryIfWritten(mURLList, mFileHandle);
|
||||
mFlushModeFullWriteNeeded = PR_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!file_handle_seek(mFileHandle, TRUE))
|
||||
return NS_ERROR_FAILURE;
|
||||
WriteEntryIfUnwritten(mURLList, mFileHandle);
|
||||
}
|
||||
|
||||
mEntriesAddedSinceFlush = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Split an entry in last visit time, title and url.
|
||||
// Add a stored entry in the history.dat file in the history hash table
|
||||
nsresult EmbedGlobalHistory::GetEntry(const char *entry)
|
||||
{
|
||||
char separator = (char) defaultSeparator;
|
||||
int pos = 0;
|
||||
nsInt64 outValue = 0;
|
||||
while (PR_TRUE) {
|
||||
PRInt32 digit;
|
||||
if (entry[pos] == separator) {
|
||||
pos++;
|
||||
break;
|
||||
}
|
||||
if (entry[pos] == '\0' || !isdigit(entry[pos]))
|
||||
return NS_ERROR_FAILURE;
|
||||
digit = entry[pos] - '0';
|
||||
outValue *= nsInt64(10);
|
||||
outValue += nsInt64(digit);
|
||||
pos++;
|
||||
}
|
||||
char url[1024], title[1024];
|
||||
int urlLength= 0, titleLength= 0, numStrings=1;
|
||||
// get the url and title
|
||||
// FIXME
|
||||
while(PR_TRUE) {
|
||||
if (entry[pos] == separator) {
|
||||
numStrings++;
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
if (numStrings > 2)
|
||||
break;
|
||||
if (numStrings==1) {
|
||||
url[urlLength++] = entry[pos];
|
||||
} else {
|
||||
title[titleLength++] = entry[pos];
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
url[urlLength]='\0';
|
||||
title[titleLength]='\0';
|
||||
HistoryEntry *newEntry = new HistoryEntry;
|
||||
if (!newEntry)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
SET_TITLE(newEntry, title);
|
||||
rv |= SetLastVisitTime(newEntry, outValue);
|
||||
rv |= SetIsWritten(newEntry);
|
||||
rv |= SET_URL(newEntry, url);
|
||||
BROKEN_RV_HANDLING_CODE(rv);
|
||||
// Check wheter the entry has expired
|
||||
if (!entryHasExpired(newEntry)) {
|
||||
mURLList = g_list_prepend(mURLList, newEntry);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// Get the history entries from history.dat file
|
||||
nsresult EmbedGlobalHistory::ReadEntries(LOCAL_FILE *file_uri)
|
||||
{
|
||||
if (!file_uri)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIInputStream> fileStream;
|
||||
NS_NewLocalFileInputStream(getter_AddRefs(fileStream), file_uri);
|
||||
if (!fileStream)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsILineInputStream> lineStream = do_QueryInterface(fileStream, &rv);
|
||||
NS_ASSERTION(lineStream, "File stream is not an nsILineInputStream");
|
||||
// Read the header
|
||||
nsCString utf8Buffer;
|
||||
PRBool moreData = PR_FALSE;
|
||||
|
||||
PRInt32 safe_limit = 0;
|
||||
do {
|
||||
rv = lineStream->ReadLine(utf8Buffer, &moreData);
|
||||
safe_limit++;
|
||||
if (NS_FAILED(rv))
|
||||
return NS_OK;
|
||||
|
||||
if (utf8Buffer.IsEmpty())
|
||||
continue;
|
||||
rv = GetEntry(utf8Buffer.get());
|
||||
} while (moreData && safe_limit < kMaxSafeReadEntriesCount);
|
||||
fileStream->Close();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Static Functions
|
||||
//*****************************************************************************
|
||||
// Get last visit time from a string
|
||||
static nsresult writePRInt64(char time[14], const PRInt64& inValue)
|
||||
{
|
||||
nsInt64 value(inValue);
|
||||
if (value == nsInt64(0)) {
|
||||
strcpy(time, "0");
|
||||
return NS_OK;
|
||||
}
|
||||
nsCAutoString tempString;
|
||||
while (value != nsInt64(0)) {
|
||||
PRInt32 ones = PRInt32(value % nsInt64(10));
|
||||
value /= nsInt64(10);
|
||||
tempString.Insert(char('0' + ones), 0);
|
||||
}
|
||||
strcpy(time,(char *) tempString.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Write an entry in the history.dat file
|
||||
nsresult writeEntry(OUTPUT_STREAM *file_handle, HistoryEntry *entry)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
char sep = (char) defaultSeparator;
|
||||
char time[14];
|
||||
writePRInt64(time, GetLastVisitTime(entry));
|
||||
char *line = g_strdup_printf("%s%c%s%c%s%c\n", time, sep, GET_URL(entry), sep, GET_TITLE(entry), sep);
|
||||
BROKEN_STRING_BUILDER(line);
|
||||
guint64 size = file_handle_write(file_handle, (gpointer)line);
|
||||
if (size != strlen(line))
|
||||
rv = NS_ERROR_FAILURE;
|
||||
rv |= SetIsWritten(entry);
|
||||
g_free(line);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult EmbedGlobalHistory::GetContentList(GtkMozHistoryItem **GtkHI, int *count)
|
||||
{
|
||||
if (!mURLList) return NS_ERROR_FAILURE;
|
||||
|
||||
unsigned int num_items = 0;
|
||||
*GtkHI = g_new0(GtkMozHistoryItem, g_list_length(mURLList));
|
||||
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(*GtkHI);
|
||||
GtkMozHistoryItem * item = (GtkMozHistoryItem *)*GtkHI;
|
||||
while (num_items < g_list_length(mURLList)) {
|
||||
HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry*,
|
||||
g_list_nth_data(mURLList, num_items));
|
||||
// verify if the entry has expired and discard it
|
||||
if (entryHasExpired(entry)) {
|
||||
break;
|
||||
}
|
||||
glong accessed;
|
||||
PRInt64 temp, outValue;
|
||||
LL_MUL(outValue, GetLastVisitTime(entry), kOneThousand);
|
||||
LL_DIV(temp, outValue, PR_USEC_PER_SEC);
|
||||
LL_L2I(accessed, temp);
|
||||
// Set the External history list
|
||||
item[num_items].title = GET_TITLE(entry);
|
||||
BROKEN_STRING_BUILDER(item[num_items].title);
|
||||
item[num_items].url = GET_URL(entry);
|
||||
item[num_items].accessed = accessed;
|
||||
num_items++;
|
||||
}
|
||||
*count = num_items;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Conrad Carlen <ccarlen@netscape.com>
|
||||
* Changes: andre.pedralho@indt.org.br (from original: mozilla/embedding/lite/nsEmbedGlobalHistory.h)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef __EMBEDGLOBALHISTORY_h
|
||||
#define __EMBEDGLOBALHISTORY_h
|
||||
#include "nsIGlobalHistory2.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "EmbedPrivate.h"
|
||||
#include <prenv.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "nsDocShellCID.h"
|
||||
|
||||
#define OUTPUT_STREAM nsIOutputStream
|
||||
#define LOCAL_FILE nsILocalFile
|
||||
|
||||
//#include "gtkmozembed_common.h"
|
||||
/* {2f977d51-5485-11d4-87e2-0010a4e75ef2} */
|
||||
#define NS_EMBEDGLOBALHISTORY_CID \
|
||||
{ 0x2f977d51, 0x5485, 0x11d4, \
|
||||
{ 0x87, 0xe2, 0x00, 0x10, 0xa4, 0xe7, 0x5e, 0xf2 } }
|
||||
#define EMBED_HISTORY_PREF_EXPIRE_DAYS "browser.history_expire_days"
|
||||
/** The Mozilla History Class
|
||||
* This class is responsible for handling the history stuff.
|
||||
*/
|
||||
class EmbedGlobalHistory: public nsIGlobalHistory2,
|
||||
public nsIObserver
|
||||
{
|
||||
public:
|
||||
EmbedGlobalHistory();
|
||||
virtual ~EmbedGlobalHistory();
|
||||
static EmbedGlobalHistory* GetInstance();
|
||||
static void DeleteInstance();
|
||||
NS_IMETHOD Init();
|
||||
nsresult GetContentList(GtkMozHistoryItem**, int *count);
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGLOBALHISTORY2
|
||||
NS_DECL_NSIOBSERVER
|
||||
nsresult RemoveEntries(const PRUnichar *url = nsnull, int time = 0);
|
||||
|
||||
protected:
|
||||
enum {
|
||||
kFlushModeAppend, /** < Add a new entry in the history file */
|
||||
kFlushModeFullWrite /** < Rewrite all history file */
|
||||
};
|
||||
/** Initiates the history file
|
||||
* @return NS_OK on the success.
|
||||
*/
|
||||
nsresult InitFile();
|
||||
/** Loads the history file
|
||||
* @return NS_OK on the success.
|
||||
*/
|
||||
nsresult LoadData();
|
||||
/** Writes entries in the history file
|
||||
* @param list The internal history list.
|
||||
* @param handle A Gnome VFS handle.
|
||||
* @return NS_OK on the success.
|
||||
*/
|
||||
nsresult WriteEntryIfWritten(GList *list, OUTPUT_STREAM *file_handle);
|
||||
/** Writes entries in the history file
|
||||
* @param list The internal history list.
|
||||
* @param handle A Gnome VFS handle.
|
||||
* @return NS_OK on the success.
|
||||
*/
|
||||
nsresult WriteEntryIfUnwritten(GList *list, OUTPUT_STREAM *file_handle);
|
||||
/** Writes entries in the history file
|
||||
* @param mode How to write in the history file
|
||||
* @return NS_OK on the success.
|
||||
*/
|
||||
nsresult FlushData(PRIntn mode = kFlushModeFullWrite);
|
||||
/** Remove entries from the URL table
|
||||
* @return NS_OK on the success.
|
||||
*/
|
||||
nsresult ResetData();
|
||||
/** Reads the history entries using GnomeVFS
|
||||
* @param vfs_handle A Gnome VFS handle.
|
||||
* @return NS_OK on the success.
|
||||
*/
|
||||
nsresult ReadEntries(LOCAL_FILE *file_uri);
|
||||
/** Gets a history entry
|
||||
* @param name The history entry name.
|
||||
* @return NS_OK if the history entry name was gotten.
|
||||
*/
|
||||
nsresult GetEntry(const char *);
|
||||
protected:
|
||||
OUTPUT_STREAM *mFileHandle; /** < The History File handle */
|
||||
PRBool mDataIsLoaded; /** < If the data is loaded */
|
||||
PRBool mFlushModeFullWriteNeeded;/** < If needs a full flush */
|
||||
PRInt32 mEntriesAddedSinceFlush; /** < Number of entries added since flush */
|
||||
gchar* mHistoryFile; /** < The history file path */
|
||||
};
|
||||
// Default maximum history entries
|
||||
static const PRUint32 kDefaultMaxSize = 1000;
|
||||
#endif
|
||||
@@ -1,88 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=4 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Oleg Romashin. Portions created by Oleg Romashin are Copyright (C) Oleg Romashin. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "EmbedGtkTools.h"
|
||||
#ifndef MOZILLA_INTERNAL_API
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#endif
|
||||
#include "EmbedPrivate.h"
|
||||
|
||||
GtkWidget * GetGtkWidgetForDOMWindow(nsIDOMWindow* aDOMWindow)
|
||||
{
|
||||
nsCOMPtr<nsIWindowWatcher> wwatch = do_GetService("@mozilla.org/embedcomp/window-watcher;1");
|
||||
if (!aDOMWindow)
|
||||
return NULL;
|
||||
nsCOMPtr<nsIWebBrowserChrome> chrome;
|
||||
wwatch->GetChromeForWindow(aDOMWindow, getter_AddRefs(chrome));
|
||||
if (!chrome) {
|
||||
return GTK_WIDGET(EmbedCommon::GetAnyLiveWidget());
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow = nsnull;
|
||||
siteWindow = do_QueryInterface(chrome);
|
||||
|
||||
if (!siteWindow) {
|
||||
return GTK_WIDGET(EmbedCommon::GetAnyLiveWidget());
|
||||
}
|
||||
|
||||
GtkWidget* parentWidget;
|
||||
siteWindow->GetSiteWindow((void**)&parentWidget);
|
||||
if (GTK_IS_WIDGET(parentWidget))
|
||||
return parentWidget;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GtkWindow * GetGtkWindowForDOMWindow(nsIDOMWindow* aDOMWindow)
|
||||
{
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aDOMWindow);
|
||||
if (!parentWidget)
|
||||
return NULL;
|
||||
GtkWidget* gtkWin = gtk_widget_get_toplevel(parentWidget);
|
||||
if (GTK_WIDGET_TOPLEVEL(gtkWin))
|
||||
return GTK_WINDOW(gtkWin);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nsresult GetContentViewer(nsIWebBrowser *webBrowser, nsIContentViewer **aViewer)
|
||||
{
|
||||
g_return_val_if_fail(webBrowser, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIDocShell> docShell(do_GetInterface((nsISupports*)webBrowser));
|
||||
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
||||
return docShell->GetContentViewer(aViewer);
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Oleg Romashin. Portions created by Oleg Romashin are Copyright (C) Oleg Romashin. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef __EmbedTools_h
|
||||
#define __EmbedTools_h
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsString.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIEmbeddingSiteWindow.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
GtkWidget*
|
||||
GetGtkWidgetForDOMWindow(nsIDOMWindow* aDOMWindow);
|
||||
|
||||
GtkWindow*
|
||||
GetGtkWindowForDOMWindow(nsIDOMWindow* aDOMWindow);
|
||||
|
||||
nsresult
|
||||
GetContentViewer(nsIWebBrowser *webBrowser, nsIContentViewer **aViewer);
|
||||
|
||||
#endif /* __EmbedTools_h */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,227 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Password Manager.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Brian Ryner.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
* Changes: romaxa@gmail.com (from original: mozilla/toolkit/components/passwordmgr/base/nsPasswordManager.h)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCPasswordManager.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIFormSubmitObserver.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsIDOMLoadListener.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPromptFactory.h"
|
||||
#include "nsIAuthPromptWrapper.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIAuthPrompt2.h"
|
||||
#include "EmbedPrivate.h"
|
||||
|
||||
#define EMBED_PASSWORDMANAGER_DESCRIPTION "MicroB PSM Dialog Impl"
|
||||
/* 360565c4-2ef3-4f6a-bab9-94cca891b2a7 */
|
||||
#define EMBED_PASSWORDMANAGER_CID \
|
||||
{0x360565c4, 0x2ef3, 0x4f6a, {0xba, 0xb9, 0x94, 0xcc, 0xa8, 0x91, 0xb2, 0xa7}}
|
||||
|
||||
class nsIFile;
|
||||
class nsIStringBundle;
|
||||
class nsIComponentManager;
|
||||
class nsIContent;
|
||||
class nsIDOMWindowInternal;
|
||||
class nsIURI;
|
||||
class nsIDOMHTMLInputElement;
|
||||
class nsIDOMWindow;
|
||||
class nsIPromptService2;
|
||||
|
||||
struct nsModuleComponentInfo;
|
||||
|
||||
class EmbedPasswordMgr : public nsIPasswordManager,
|
||||
public nsIPasswordManagerInternal,
|
||||
public nsIObserver,
|
||||
public nsIFormSubmitObserver,
|
||||
public nsIWebProgressListener,
|
||||
public nsIDOMFocusListener,
|
||||
public nsIPromptFactory,
|
||||
public nsIDOMLoadListener,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
class SignonDataEntry;
|
||||
class SignonHashEntry;
|
||||
class PasswordEntry;
|
||||
EmbedPasswordMgr();
|
||||
virtual ~EmbedPasswordMgr();
|
||||
static EmbedPasswordMgr* GetInstance();
|
||||
static EmbedPasswordMgr* GetInstance(EmbedPrivate *aOwner);
|
||||
nsresult Init();
|
||||
static PRBool SingleSignonEnabled();
|
||||
static NS_METHOD Register(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath,
|
||||
const char* aRegistryLocation,
|
||||
const char* aComponentType,
|
||||
const nsModuleComponentInfo* aInfo);
|
||||
static NS_METHOD Unregister(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath,
|
||||
const char* aRegistryLocation,
|
||||
const nsModuleComponentInfo* aInfo);
|
||||
static void Shutdown();
|
||||
static void GetLocalizedString(const nsAString& key,
|
||||
nsAString& aResult,
|
||||
PRBool aFormatted = PR_FALSE,
|
||||
const PRUnichar** aFormatArgs = nsnull,
|
||||
PRUint32 aFormatArgsLength = 0);
|
||||
static nsresult DecryptData(const nsAString& aData, nsAString& aPlaintext);
|
||||
static nsresult EncryptData(const nsAString& aPlaintext,
|
||||
nsACString& aEncrypted);
|
||||
static nsresult EncryptDataUCS2(const nsAString& aPlaintext,
|
||||
nsAString& aEncrypted);
|
||||
nsresult InsertLogin(const char* username, const char* password = nsnull);
|
||||
nsresult RemovePasswords(const char *aHostName, const char *aUserName);
|
||||
nsresult RemovePasswordsByIndex(PRUint32 aIndex);
|
||||
nsresult IsEqualToLastHostQuery(nsCString& aHost);
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPASSWORDMANAGER
|
||||
NS_DECL_NSIPASSWORDMANAGERINTERNAL
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_NSIPROMPTFACTORY
|
||||
// nsIFormSubmitObserver
|
||||
NS_IMETHOD Notify(nsIContent* aFormNode,
|
||||
nsIDOMWindowInternal* aWindow,
|
||||
nsIURI* aActionURL,
|
||||
PRBool* aCancelSubmit);
|
||||
// nsIDOMFocusListener
|
||||
NS_IMETHOD Focus(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Blur(nsIDOMEvent* aEvent);
|
||||
// nsIDOMEventListener
|
||||
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
||||
// nsIDOMLoadListener
|
||||
NS_IMETHOD Load(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Unload(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
|
||||
NS_IMETHOD Error(nsIDOMEvent* aEvent);
|
||||
protected:
|
||||
void WritePasswords(nsIFile* aPasswordFile);
|
||||
void AddSignonData(const nsACString& aRealm, SignonDataEntry* aEntry);
|
||||
nsresult FindPasswordEntryInternal(const SignonDataEntry* aEntry,
|
||||
const nsAString& aUser,
|
||||
const nsAString& aPassword,
|
||||
const nsAString& aUserField,
|
||||
SignonDataEntry** aResult);
|
||||
nsresult FillPassword(nsIDOMEvent* aEvent = nsnull);
|
||||
void AttachToInput(nsIDOMHTMLInputElement* aElement);
|
||||
PRBool GetPasswordRealm(nsIURI* aURI, nsACString& aRealm);
|
||||
static PLDHashOperator PR_CALLBACK FindEntryEnumerator(const nsACString& aKey,
|
||||
SignonHashEntry* aEntry,
|
||||
void* aUserData);
|
||||
static PLDHashOperator PR_CALLBACK WriteRejectEntryEnumerator(const nsACString& aKey,
|
||||
PRInt32 aEntry,
|
||||
void* aUserData);
|
||||
static PLDHashOperator PR_CALLBACK WriteSignonEntryEnumerator(const nsACString& aKey,
|
||||
SignonHashEntry* aEntry,
|
||||
void* aUserData);
|
||||
static PLDHashOperator PR_CALLBACK BuildArrayEnumerator(const nsACString& aKey,
|
||||
SignonHashEntry* aEntry,
|
||||
void* aUserData);
|
||||
static PLDHashOperator PR_CALLBACK BuildRejectArrayEnumerator(const nsACString& aKey,
|
||||
PRInt32 aEntry,
|
||||
void* aUserData);
|
||||
static PLDHashOperator PR_CALLBACK RemoveForDOMDocumentEnumerator(nsISupports* aKey,
|
||||
PRInt32& aEntry,
|
||||
void* aUserData);
|
||||
static void EnsureDecoderRing();
|
||||
nsClassHashtable<nsCStringHashKey,SignonHashEntry> mSignonTable;
|
||||
nsDataHashtable<nsCStringHashKey,PRInt32> mRejectTable;
|
||||
nsDataHashtable<nsISupportsHashKey,PRInt32> mAutoCompleteInputs;
|
||||
nsCOMPtr<nsIFile> mSignonFile;
|
||||
nsCOMPtr<nsIPrefBranch> mPrefBranch;
|
||||
nsIDOMHTMLInputElement* mAutoCompletingField;
|
||||
nsIDOMHTMLInputElement* mGlobalUserField;
|
||||
nsIDOMHTMLInputElement* mGlobalPassField;
|
||||
SignonHashEntry * mLastSignonHashEntry;
|
||||
int lastIndex;
|
||||
nsCAutoString mLastHostQuery;
|
||||
EmbedCommon* mCommonObject;
|
||||
public:
|
||||
PRBool mFormAttachCount;
|
||||
// nsAString mLastHostQuery;
|
||||
};
|
||||
|
||||
/* 1baf3398-f759-4a72-a21f-0abdc9cc9960 */
|
||||
#define NS_SINGLE_SIGNON_PROMPT_CID \
|
||||
{0x1baf3398, 0xf759, 0x4a72, {0xa2, 0x1f, 0x0a, 0xbd, 0xc9, 0xcc, 0x99, 0x60}}
|
||||
|
||||
// Our wrapper for username/password prompts - this allows us to prefill
|
||||
// the password dialog and add a "remember this password" checkbox.
|
||||
class EmbedSignonPrompt : public nsIAuthPromptWrapper
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIAUTHPROMPT
|
||||
NS_DECL_NSIAUTHPROMPTWRAPPER
|
||||
EmbedSignonPrompt() {}
|
||||
virtual ~EmbedSignonPrompt() {}
|
||||
protected:
|
||||
void GetLocalizedString(const nsAString& aKey, nsAString& aResult);
|
||||
nsCOMPtr<nsIPrompt> mPrompt;
|
||||
};
|
||||
|
||||
// A wrapper for the newer nsIAuthPrompt2 interface
|
||||
// Its purpose is the same as nsSingleSignonPrompt, but wraps an nsIDOMWindow
|
||||
// instead of an nsIPrompt.
|
||||
|
||||
class EmbedSignonPrompt2 : public nsIAuthPrompt2
|
||||
{
|
||||
public:
|
||||
EmbedSignonPrompt2(nsIPromptService2* aService, nsIDOMWindow* aParent);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIAUTHPROMPT2
|
||||
|
||||
private:
|
||||
~EmbedSignonPrompt2();
|
||||
|
||||
nsCOMPtr<nsIPromptService2> mService;
|
||||
nsCOMPtr<nsIDOMWindow> mParent;
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,268 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __EmbedPrivate_h
|
||||
#define __EmbedPrivate_h
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsString.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#endif
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsISHistory.h"
|
||||
// for our one function that gets the EmbedPrivate via the chrome
|
||||
// object.
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIAppShell.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
// app component registration
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
|
||||
#include "nsIDocCharset.h"
|
||||
#include "nsIMarkupDocumentViewer.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIWebBrowserFind.h"
|
||||
// for the focus hacking we need to do
|
||||
#include "nsIFocusController.h"
|
||||
// for frames
|
||||
#include "nsIDOMWindowCollection.h"
|
||||
#include "gtkmozembedprivate.h"
|
||||
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
|
||||
#include "EmbedGtkTools.h"
|
||||
class EmbedProgress;
|
||||
class EmbedWindow;
|
||||
class EmbedContentListener;
|
||||
class EmbedEventListener;
|
||||
|
||||
class nsPIDOMWindow;
|
||||
class nsIDirectoryServiceProvider;
|
||||
|
||||
class EmbedCommon {
|
||||
public:
|
||||
EmbedCommon() {
|
||||
};
|
||||
~EmbedCommon() { };
|
||||
static EmbedCommon* GetInstance();
|
||||
static void DeleteInstance();
|
||||
nsresult Init(void);
|
||||
GtkObject *mCommon;
|
||||
static GtkMozEmbed* GetAnyLiveWidget();
|
||||
};
|
||||
class EmbedPrivate {
|
||||
|
||||
public:
|
||||
|
||||
EmbedPrivate();
|
||||
~EmbedPrivate();
|
||||
|
||||
nsresult Init (GtkMozEmbed *aOwningWidget);
|
||||
nsresult Realize (PRBool *aAlreadRealized);
|
||||
void Unrealize (void);
|
||||
void Show (void);
|
||||
void Hide (void);
|
||||
void Resize (PRUint32 aWidth, PRUint32 aHeight);
|
||||
void Destroy (void);
|
||||
void SetURI (const char *aURI);
|
||||
void LoadCurrentURI (void);
|
||||
void Reload (PRUint32 reloadFlags);
|
||||
|
||||
void SetChromeMask (PRUint32 chromeMask);
|
||||
void ApplyChromeMask ();
|
||||
|
||||
static void PushStartup (void);
|
||||
static void PopStartup (void);
|
||||
static void SetPath (const char *aPath);
|
||||
static void SetCompPath (const char *aPath);
|
||||
|
||||
static void SetAppComponents (const nsModuleComponentInfo* aComps,
|
||||
int aNumComponents);
|
||||
static void SetProfilePath (const char *aDir, const char *aName);
|
||||
static void SetDirectoryServiceProvider (nsIDirectoryServiceProvider * appFileLocProvider);
|
||||
|
||||
nsresult OpenStream (const char *aBaseURI, const char *aContentType);
|
||||
nsresult AppendToStream (const PRUint8 *aData, PRUint32 aLen);
|
||||
nsresult CloseStream (void);
|
||||
|
||||
// This function will find the specific EmbedPrivate object for a
|
||||
// given nsIWebBrowserChrome.
|
||||
static EmbedPrivate *FindPrivateForBrowser(nsIWebBrowserChrome *aBrowser);
|
||||
|
||||
// This is an upcall that will come from the progress listener
|
||||
// whenever there is a content state change. We need this so we can
|
||||
// attach event listeners.
|
||||
void ContentStateChange (void);
|
||||
|
||||
// This is an upcall from the progress listener when content is
|
||||
// finished loading. We have this so that if it's chrome content
|
||||
// that we can size to content properly and show ourselves if
|
||||
// visibility is set.
|
||||
void ContentFinishedLoading(void);
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
// these let the widget code know when the toplevel window gets and
|
||||
// looses focus.
|
||||
void TopLevelFocusIn (void);
|
||||
void TopLevelFocusOut(void);
|
||||
#endif
|
||||
|
||||
// these are when the widget itself gets focus in and focus out
|
||||
// events
|
||||
void ChildFocusIn (void);
|
||||
void ChildFocusOut(void);
|
||||
PRBool ClipBoardAction(GtkMozEmbedClipboard type);
|
||||
char* GetEncoding ();
|
||||
nsresult SetEncoding (const char *encoding);
|
||||
PRBool FindText(const char *exp, PRBool reverse,
|
||||
PRBool whole_word, PRBool case_sensitive,
|
||||
PRBool restart);
|
||||
void SetScrollTop(PRUint32 aTop);
|
||||
nsresult ScrollToSelectedNode(nsIDOMNode *aDOMNode);
|
||||
nsresult InsertTextToNode(nsIDOMNode *aDOMNode, const char *string);
|
||||
nsresult GetFocusController(nsIFocusController **controller);
|
||||
nsresult GetDOMWindowByNode(nsIDOMNode *aNode, nsIDOMWindow * *aDOMWindow);
|
||||
nsresult GetZoom(PRInt32 *aZoomLevel, nsISupports *aContext = nsnull);
|
||||
nsresult SetZoom(PRInt32 aZoomLevel, nsISupports *aContext = nsnull);
|
||||
nsresult HasFrames(PRUint32 *numberOfFrames);
|
||||
nsresult GetMIMEInfo(const char **aMime, nsIDOMNode *aDOMNode = nsnull);
|
||||
nsresult GetCacheEntry(const char *aStorage,
|
||||
const char *aKeyName,
|
||||
PRUint32 aAccess,
|
||||
PRBool aIsBlocking,
|
||||
nsICacheEntryDescriptor **aDescriptor);
|
||||
nsresult GetSHistoryList(GtkMozHistoryItem **GtkHI,
|
||||
GtkMozEmbedSessionHistory type, gint *count);
|
||||
|
||||
|
||||
#ifdef MOZ_ACCESSIBILITY_ATK
|
||||
void *GetAtkObjectForCurrentDocument();
|
||||
#endif
|
||||
|
||||
GtkMozEmbed *mOwningWidget;
|
||||
|
||||
// all of the objects that we own
|
||||
EmbedWindow *mWindow;
|
||||
nsCOMPtr<nsISupports> mWindowGuard;
|
||||
EmbedProgress *mProgress;
|
||||
nsCOMPtr<nsISupports> mProgressGuard;
|
||||
EmbedContentListener *mContentListener;
|
||||
nsCOMPtr<nsISupports> mContentListenerGuard;
|
||||
EmbedEventListener *mEventListener;
|
||||
nsCOMPtr<nsISupports> mEventListenerGuard;
|
||||
|
||||
nsCOMPtr<nsIWebNavigation> mNavigation;
|
||||
nsCOMPtr<nsISHistory> mSessionHistory;
|
||||
|
||||
// our event receiver
|
||||
nsCOMPtr<nsIDOMEventReceiver> mEventReceiver;
|
||||
|
||||
// the currently loaded uri
|
||||
nsString mURI;
|
||||
nsCString mPrePath;
|
||||
|
||||
// the number of widgets that have been created
|
||||
static PRUint32 sWidgetCount;
|
||||
// the path to the GRE
|
||||
static char *sPath;
|
||||
// the path to components
|
||||
static char *sCompPath;
|
||||
// the list of application-specific components to register
|
||||
static const nsModuleComponentInfo *sAppComps;
|
||||
static int sNumAppComps;
|
||||
// the appshell we have created
|
||||
static nsIAppShell *sAppShell;
|
||||
// the list of all open windows
|
||||
static nsVoidArray *sWindowList;
|
||||
// what is our profile path?
|
||||
static nsILocalFile *sProfileDir;
|
||||
static nsISupports *sProfileLock;
|
||||
|
||||
static nsIDirectoryServiceProvider * sAppFileLocProvider;
|
||||
|
||||
// chrome mask
|
||||
PRUint32 mChromeMask;
|
||||
// is this a chrome window?
|
||||
PRBool mIsChrome;
|
||||
// has the chrome finished loading?
|
||||
PRBool mChromeLoaded;
|
||||
|
||||
// has the network finished loading?
|
||||
PRBool mLoadFinished;
|
||||
|
||||
// saved window ID for reparenting later
|
||||
GtkWidget *mMozWindowWidget;
|
||||
// has someone called Destroy() on us?
|
||||
PRBool mIsDestroyed;
|
||||
|
||||
//Open Blocker for Create Window class //Fixme...
|
||||
//I just tried to block it on earlier moment
|
||||
PRBool mOpenBlock;
|
||||
PRBool mNeedFav;
|
||||
private:
|
||||
|
||||
// is the chrome listener attached yet?
|
||||
PRBool mListenersAttached;
|
||||
PRBool mDoResizeEmbed;
|
||||
|
||||
void GetListener (void);
|
||||
void AttachListeners(void);
|
||||
void DetachListeners(void);
|
||||
|
||||
// this will get the PIDOMWindow for this widget
|
||||
nsresult GetPIDOMWindow (nsPIDOMWindow **aPIWin);
|
||||
|
||||
static nsresult RegisterAppComponents();
|
||||
|
||||
// offscreen window methods and the offscreen widget
|
||||
static void EnsureOffscreenWindow(void);
|
||||
static void DestroyOffscreenWindow(void);
|
||||
static GtkWidget *sOffscreenWindow;
|
||||
static GtkWidget *sOffscreenFixed;
|
||||
|
||||
};
|
||||
|
||||
#endif /* __EmbedPrivate_h */
|
||||
@@ -1,324 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Antonio Gomes <tonikitoo@gmail.com>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "EmbedProgress.h"
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsXPIDLString.h"
|
||||
#endif
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "EmbedPasswordMgr.h"
|
||||
|
||||
#include "nsIURI.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
static PRInt32 sStopSignalTimer = 0;
|
||||
static gboolean
|
||||
progress_emit_stop(void * data)
|
||||
{
|
||||
g_return_val_if_fail(data, FALSE);
|
||||
EmbedPrivate *owner = (EmbedPrivate*)data;
|
||||
if (!owner->mLoadFinished) {
|
||||
owner->mLoadFinished = PR_TRUE;
|
||||
gtk_signal_emit(GTK_OBJECT(owner->mOwningWidget),
|
||||
moz_embed_signals[NET_STOP]);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EmbedProgress::EmbedProgress(void)
|
||||
{
|
||||
mOwner = nsnull;
|
||||
}
|
||||
|
||||
EmbedProgress::~EmbedProgress()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(EmbedProgress,
|
||||
nsIWebProgressListener,
|
||||
nsISupportsWeakReference)
|
||||
|
||||
nsresult
|
||||
EmbedProgress::Init(EmbedPrivate *aOwner)
|
||||
{
|
||||
mOwner = aOwner;
|
||||
mStopLevel = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRUint32 aStateFlags,
|
||||
nsresult aStatus)
|
||||
{
|
||||
// give the widget a chance to attach any listeners
|
||||
mOwner->ContentStateChange();
|
||||
|
||||
if (sStopSignalTimer &&
|
||||
(
|
||||
(aStateFlags & GTK_MOZ_EMBED_FLAG_TRANSFERRING)
|
||||
|| (aStateFlags & GTK_MOZ_EMBED_FLAG_REDIRECTING)
|
||||
|| (aStateFlags & GTK_MOZ_EMBED_FLAG_NEGOTIATING)
|
||||
)
|
||||
) {
|
||||
g_source_remove(sStopSignalTimer);
|
||||
mStopLevel = 0;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[NET_START]);
|
||||
mOwner->mLoadFinished = PR_FALSE;
|
||||
}
|
||||
|
||||
// if we've got the start flag, emit the signal
|
||||
if ((aStateFlags & GTK_MOZ_EMBED_FLAG_IS_NETWORK) &&
|
||||
(aStateFlags & GTK_MOZ_EMBED_FLAG_START)) {
|
||||
// FIXME: workaround for broken progress values.
|
||||
mOwner->mOwningWidget->current_number_of_requests = 0;
|
||||
mOwner->mOwningWidget->total_number_of_requests = 0;
|
||||
|
||||
if (mOwner->mLoadFinished) {
|
||||
mOwner->mLoadFinished = PR_FALSE;
|
||||
mStopLevel = 0;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[NET_START]);
|
||||
}
|
||||
}
|
||||
// get the uri for this request
|
||||
nsCString tmpString;
|
||||
RequestToURIString(aRequest, tmpString);
|
||||
|
||||
// FIXME: workaround for broken progress values.
|
||||
if (mOwner->mOwningWidget) {
|
||||
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_REQUEST) {
|
||||
if (aStateFlags & GTK_MOZ_EMBED_FLAG_START)
|
||||
mOwner->mOwningWidget->total_number_of_requests ++;
|
||||
else if (aStateFlags & GTK_MOZ_EMBED_FLAG_STOP)
|
||||
mOwner->mOwningWidget->current_number_of_requests++;
|
||||
}
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[PROGRESS_ALL],
|
||||
(const gchar *) tmpString.get(),
|
||||
mOwner->mOwningWidget->current_number_of_requests,
|
||||
mOwner->mOwningWidget->total_number_of_requests);
|
||||
}
|
||||
// is it the same as the current URI?
|
||||
if (mOwner->mURI.Equals(NS_ConvertUTF8toUTF16(tmpString))) {
|
||||
// for people who know what they are doing
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[NET_STATE],
|
||||
aStateFlags, aStatus);
|
||||
}
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[NET_STATE_ALL],
|
||||
(const gchar *)tmpString.get(),
|
||||
(gint)aStateFlags, (gint)aStatus);
|
||||
|
||||
// and for stop, too
|
||||
if (aStateFlags & GTK_MOZ_EMBED_FLAG_STOP) {
|
||||
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_REQUEST)
|
||||
mStopLevel = 1;
|
||||
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_DOCUMENT)
|
||||
mStopLevel = mStopLevel == 1 ? 2 : 0;
|
||||
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_WINDOW) {
|
||||
mStopLevel = mStopLevel == 2 ? 3 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (aStateFlags & GTK_MOZ_EMBED_FLAG_STOP) {
|
||||
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_NETWORK) {
|
||||
if (sStopSignalTimer)
|
||||
g_source_remove(sStopSignalTimer);
|
||||
progress_emit_stop(mOwner);
|
||||
// let our owner know that the load finished
|
||||
mOwner->ContentFinishedLoading();
|
||||
|
||||
} else if (mStopLevel == 3) {
|
||||
if (sStopSignalTimer)
|
||||
g_source_remove(sStopSignalTimer);
|
||||
mStopLevel = 0;
|
||||
sStopSignalTimer = g_timeout_add(1000, progress_emit_stop, mOwner);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedProgress::OnProgressChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt32 aCurSelfProgress,
|
||||
PRInt32 aMaxSelfProgress,
|
||||
PRInt32 aCurTotalProgress,
|
||||
PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
nsCString tmpString;
|
||||
RequestToURIString(aRequest, tmpString);
|
||||
|
||||
// is it the same as the current uri?
|
||||
if (mOwner->mURI.Equals(NS_ConvertUTF8toUTF16(tmpString))) {
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[PROGRESS],
|
||||
aCurTotalProgress, aMaxTotalProgress);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedProgress::OnLocationChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
nsIURI *aLocation)
|
||||
{
|
||||
nsCAutoString newURI;
|
||||
nsCAutoString prePath;
|
||||
NS_ENSURE_ARG_POINTER(aLocation);
|
||||
aLocation->GetSpec(newURI);
|
||||
aLocation->GetPrePath(prePath);
|
||||
|
||||
// Make sure that this is the primary frame change and not
|
||||
// just a subframe.
|
||||
PRBool isSubFrameLoad = PR_FALSE;
|
||||
if (aWebProgress) {
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
nsCOMPtr<nsIDOMWindow> topDomWindow;
|
||||
|
||||
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
||||
|
||||
// get the root dom window
|
||||
if (domWindow)
|
||||
domWindow->GetTop(getter_AddRefs(topDomWindow));
|
||||
|
||||
if (domWindow != topDomWindow)
|
||||
isSubFrameLoad = PR_TRUE;
|
||||
}
|
||||
|
||||
if (!isSubFrameLoad) {
|
||||
mOwner->SetURI(newURI.get());
|
||||
mOwner->mPrePath.Assign(prePath.get());
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[LOCATION]);
|
||||
}
|
||||
mOwner->mNeedFav = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedProgress::OnStatusChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
nsresult aStatus,
|
||||
const PRUnichar *aMessage)
|
||||
{
|
||||
// need to make a copy so we can safely cast to a void *
|
||||
PRUnichar *tmpString = NS_strdup(aMessage);
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[STATUS_CHANGE],
|
||||
NS_STATIC_CAST(void *, aRequest),
|
||||
NS_STATIC_CAST(gint, aStatus),
|
||||
NS_STATIC_CAST(void *, tmpString));
|
||||
|
||||
NS_Free(tmpString);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedProgress::OnSecurityChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRUint32 aState)
|
||||
{
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[SECURITY_CHANGE],
|
||||
NS_STATIC_CAST(void *, aRequest),
|
||||
aState);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
EmbedProgress::RequestToURIString(nsIRequest *aRequest, nsCString& aString)
|
||||
{
|
||||
// is it a channel
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
channel = do_QueryInterface(aRequest);
|
||||
if (!channel)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
channel->GetURI(getter_AddRefs(uri));
|
||||
if (!uri)
|
||||
return;
|
||||
|
||||
uri->GetSpec(aString);
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedProgress::HandleHTTPStatus(nsIRequest *aRequest, const char *aUri, PRBool &aSucceeded)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest, &rv));
|
||||
aSucceeded = PR_FALSE;
|
||||
|
||||
if (NS_FAILED(rv) || !httpChannel)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
rv = httpChannel->GetRequestSucceeded(&aSucceeded);
|
||||
|
||||
if (aSucceeded)
|
||||
return NS_OK;
|
||||
|
||||
PRUint32 responseCode = 0;
|
||||
nsCString responseText;
|
||||
rv = httpChannel->GetResponseStatus(&responseCode);
|
||||
// it has to handle more http errors code ??? 401 ? responseCode >= 500 && responseCode <= 505
|
||||
rv = httpChannel->GetResponseStatusText(responseText);
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[NETWORK_ERROR],
|
||||
responseCode, responseText.get(), (const gchar*)aUri);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __EmbedProgress_h
|
||||
#define __EmbedProgress_h
|
||||
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "EmbedPrivate.h"
|
||||
|
||||
class EmbedProgress : public nsIWebProgressListener,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
EmbedProgress();
|
||||
virtual ~EmbedProgress();
|
||||
|
||||
nsresult Init(EmbedPrivate *aOwner);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
|
||||
private:
|
||||
|
||||
static void RequestToURIString(nsIRequest *aRequest, nsCString& aString);
|
||||
nsresult HandleHTTPStatus(nsIRequest *aRequest, const char *aUri, PRBool &aSucceeded);
|
||||
|
||||
EmbedPrivate *mOwner;
|
||||
PRBool mStopLevel;
|
||||
};
|
||||
|
||||
#endif /* __EmbedProgress_h */
|
||||
@@ -1,434 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=4 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "EmbedPrompter.h"
|
||||
|
||||
#define ALLOC_NOT_CHECKED(newed) PR_BEGIN_MACRO \
|
||||
/* This might not crash, but the code probably isn't really \
|
||||
* designed to handle it, perhaps the code should be fixed? \
|
||||
*/ \
|
||||
if (!newed) { \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
enum {
|
||||
INCLUDE_USERNAME = 1 << 0,
|
||||
INCLUDE_PASSWORD = 1 << 1,
|
||||
INCLUDE_CHECKBOX = 1 << 2,
|
||||
INCLUDE_CANCEL = 1 << 3
|
||||
};
|
||||
|
||||
struct DialogDescription {
|
||||
int flags;
|
||||
gchar* icon;
|
||||
};
|
||||
|
||||
// This table contains the optional widgets and icons associated with
|
||||
// each type of dialog.
|
||||
|
||||
static const DialogDescription DialogTable[] = {
|
||||
{ 0, GTK_STOCK_DIALOG_WARNING }, // ALERT
|
||||
{ INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_WARNING }, // ALERT_CHECK
|
||||
{ INCLUDE_CANCEL, GTK_STOCK_DIALOG_QUESTION }, // CONFIRM
|
||||
{ INCLUDE_CHECKBOX |
|
||||
INCLUDE_CANCEL, GTK_STOCK_DIALOG_QUESTION }, // CONFIRM_CHECK
|
||||
{ INCLUDE_CANCEL |
|
||||
INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_QUESTION }, // PROMPT
|
||||
{ INCLUDE_CANCEL |
|
||||
INCLUDE_USERNAME |
|
||||
INCLUDE_PASSWORD |
|
||||
INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_QUESTION }, // PROMPT_USER_PASS
|
||||
{ INCLUDE_CANCEL |
|
||||
INCLUDE_PASSWORD |
|
||||
INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_QUESTION }, // PROMPT_PASS
|
||||
{ INCLUDE_CANCEL, GTK_STOCK_DIALOG_QUESTION }, // SELECT
|
||||
{ INCLUDE_CANCEL |
|
||||
INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_QUESTION } // UNIVERSAL
|
||||
};
|
||||
|
||||
EmbedPrompter::EmbedPrompter(void)
|
||||
: mCheckValue(PR_FALSE),
|
||||
mItemList(nsnull),
|
||||
mItemCount(0),
|
||||
mButtonPressed(0),
|
||||
mConfirmResult(PR_FALSE),
|
||||
mSelectedItem(0),
|
||||
mWindow(NULL),
|
||||
mUserField(NULL),
|
||||
mPassField(NULL),
|
||||
mTextField(NULL),
|
||||
mOptionMenu(NULL),
|
||||
mCheckBox(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
EmbedPrompter::~EmbedPrompter(void)
|
||||
{
|
||||
if (mItemList)
|
||||
delete[] mItemList;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedPrompter::Create(PromptType aType, GtkWindow* aParentWindow)
|
||||
|
||||
{
|
||||
mWindow = gtk_dialog_new_with_buttons(
|
||||
mTitle.get(),
|
||||
aParentWindow,
|
||||
(GtkDialogFlags)0,
|
||||
NULL);
|
||||
// only add the dialog to the window group if the parent already has a window group,
|
||||
// so as not to break app's expectations about modal dialogs.
|
||||
if (aParentWindow && aParentWindow->group) {
|
||||
gtk_window_group_add_window(aParentWindow->group, GTK_WINDOW(mWindow));
|
||||
}
|
||||
|
||||
// gtk will resize this for us as necessary
|
||||
gtk_window_set_default_size(GTK_WINDOW(mWindow), 100, 50);
|
||||
|
||||
// this HBox will contain the icon, and a vbox which contains the
|
||||
// dialog text and other widgets.
|
||||
GtkWidget* dialogHBox = gtk_hbox_new(FALSE, 12);
|
||||
|
||||
|
||||
// Set up dialog properties according to the GNOME HIG
|
||||
// (http://developer.gnome.org/projects/gup/hig/1.0/windows.html#alert-windows)
|
||||
|
||||
gtk_container_set_border_width(GTK_CONTAINER(mWindow), 6);
|
||||
gtk_dialog_set_has_separator(GTK_DIALOG(mWindow), FALSE);
|
||||
gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(mWindow)->vbox), 12);
|
||||
gtk_container_set_border_width(GTK_CONTAINER(dialogHBox), 6);
|
||||
|
||||
|
||||
// This is the VBox which will contain the label and other controls.
|
||||
GtkWidget* contentsVBox = gtk_vbox_new(FALSE, 12);
|
||||
|
||||
// get the stock icon for this dialog and put it in the box
|
||||
const gchar* iconDesc = DialogTable[aType].icon;
|
||||
GtkWidget* icon = gtk_image_new_from_stock(iconDesc, GTK_ICON_SIZE_DIALOG);
|
||||
gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0.0);
|
||||
gtk_box_pack_start(GTK_BOX(dialogHBox), icon, FALSE, FALSE, 0);
|
||||
|
||||
// now pack the label into the vbox
|
||||
GtkWidget* label = gtk_label_new(mMessageText.get());
|
||||
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
|
||||
gtk_label_set_selectable(GTK_LABEL(label), TRUE);
|
||||
gtk_box_pack_start(GTK_BOX(contentsVBox), label, FALSE, FALSE, 0);
|
||||
|
||||
int widgetFlags = DialogTable[aType].flags;
|
||||
|
||||
if (widgetFlags & (INCLUDE_USERNAME | INCLUDE_PASSWORD)) {
|
||||
|
||||
// If we're creating a username and/or password field, make an hbox
|
||||
// which will contain two vboxes, one for the labels and one for the
|
||||
// text fields. This will let us line up the textfields.
|
||||
|
||||
GtkWidget* userPassHBox = gtk_hbox_new(FALSE, 12);
|
||||
GtkWidget* userPassLabels = gtk_vbox_new(TRUE, 6);
|
||||
GtkWidget* userPassFields = gtk_vbox_new(TRUE, 6);
|
||||
|
||||
if (widgetFlags & INCLUDE_USERNAME) {
|
||||
GtkWidget* userLabel = gtk_label_new("User Name:");
|
||||
gtk_box_pack_start(GTK_BOX(userPassLabels), userLabel, FALSE,
|
||||
FALSE, 0);
|
||||
|
||||
mUserField = gtk_entry_new();
|
||||
|
||||
if (!mUser.IsEmpty())
|
||||
gtk_entry_set_text(GTK_ENTRY(mUserField), mUser.get());
|
||||
|
||||
gtk_entry_set_activates_default(GTK_ENTRY(mUserField), TRUE);
|
||||
|
||||
gtk_box_pack_start(
|
||||
GTK_BOX(userPassFields),
|
||||
mUserField,
|
||||
FALSE,
|
||||
FALSE,
|
||||
0);
|
||||
}
|
||||
if (widgetFlags & INCLUDE_PASSWORD) {
|
||||
GtkWidget* passLabel = gtk_label_new("Password:");
|
||||
gtk_box_pack_start(
|
||||
GTK_BOX(userPassLabels),
|
||||
passLabel,
|
||||
FALSE,
|
||||
FALSE,
|
||||
0);
|
||||
mPassField = gtk_entry_new();
|
||||
if (!mPass.IsEmpty())
|
||||
gtk_entry_set_text(GTK_ENTRY(mPassField), mPass.get());
|
||||
gtk_entry_set_visibility(GTK_ENTRY(mPassField), FALSE);
|
||||
gtk_entry_set_activates_default(GTK_ENTRY(mPassField), TRUE);
|
||||
gtk_box_pack_start(
|
||||
GTK_BOX(userPassFields),
|
||||
mPassField,
|
||||
FALSE,
|
||||
FALSE,
|
||||
0);
|
||||
}
|
||||
gtk_box_pack_start(
|
||||
GTK_BOX(userPassHBox),
|
||||
userPassLabels,
|
||||
FALSE,
|
||||
FALSE,
|
||||
0);
|
||||
gtk_box_pack_start(
|
||||
GTK_BOX(userPassHBox),
|
||||
userPassFields,
|
||||
FALSE,
|
||||
FALSE,
|
||||
0);
|
||||
gtk_box_pack_start(
|
||||
GTK_BOX(contentsVBox),
|
||||
userPassHBox,
|
||||
FALSE,
|
||||
FALSE,
|
||||
0);
|
||||
}
|
||||
if (aType == TYPE_PROMPT) {
|
||||
mTextField = gtk_entry_new();
|
||||
if (!mTextValue.IsEmpty())
|
||||
gtk_entry_set_text(GTK_ENTRY(mTextField), mTextValue.get());
|
||||
gtk_entry_set_activates_default(GTK_ENTRY(mTextField), TRUE);
|
||||
gtk_box_pack_start(GTK_BOX(contentsVBox), mTextField, FALSE, FALSE, 0);
|
||||
}
|
||||
// Add a checkbox
|
||||
if ((widgetFlags & INCLUDE_CHECKBOX) && !mCheckMessage.IsEmpty()) {
|
||||
mCheckBox = gtk_check_button_new_with_label(mCheckMessage.get());
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mCheckBox),
|
||||
mCheckValue);
|
||||
gtk_label_set_line_wrap(
|
||||
GTK_LABEL(gtk_bin_get_child(GTK_BIN(mCheckBox))),
|
||||
TRUE);
|
||||
gtk_box_pack_start(GTK_BOX(contentsVBox), mCheckBox, FALSE, FALSE, 0);
|
||||
}
|
||||
// Add a dropdown menu
|
||||
if (aType == TYPE_SELECT) {
|
||||
// Build up a GtkMenu containing the items
|
||||
GtkWidget* menu = gtk_menu_new();
|
||||
for (PRUint32 i = 0; i < mItemCount; ++i) {
|
||||
GtkWidget* item = gtk_menu_item_new_with_label(mItemList[i].get());
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
||||
}
|
||||
|
||||
// Now create an OptionMenu and set this as the menu
|
||||
mOptionMenu = gtk_option_menu_new();
|
||||
|
||||
gtk_option_menu_set_menu(GTK_OPTION_MENU(mOptionMenu), menu);
|
||||
gtk_box_pack_start(GTK_BOX(contentsVBox), mOptionMenu, FALSE, FALSE, 0);
|
||||
}
|
||||
|
||||
if (aType == TYPE_UNIVERSAL) {
|
||||
// Create buttons based on the flags passed in.
|
||||
for (int i = EMBED_MAX_BUTTONS; i >= 0; --i) {
|
||||
if (!mButtonLabels[i].IsEmpty())
|
||||
gtk_dialog_add_button(GTK_DIALOG(mWindow),
|
||||
mButtonLabels[i].get(), i);
|
||||
}
|
||||
gtk_dialog_set_default_response(GTK_DIALOG(mWindow), 0);
|
||||
} else {
|
||||
// Create standard ok and cancel buttons
|
||||
if (widgetFlags & INCLUDE_CANCEL)
|
||||
gtk_dialog_add_button(GTK_DIALOG(mWindow), GTK_STOCK_CANCEL,
|
||||
GTK_RESPONSE_CANCEL);
|
||||
|
||||
GtkWidget* okButton = gtk_dialog_add_button(GTK_DIALOG(mWindow),
|
||||
GTK_STOCK_OK,
|
||||
GTK_RESPONSE_ACCEPT);
|
||||
gtk_widget_grab_default(okButton);
|
||||
}
|
||||
// Pack the contentsVBox into the dialogHBox and the dialog.
|
||||
gtk_box_pack_start(GTK_BOX(dialogHBox), contentsVBox, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(
|
||||
GTK_BOX(GTK_DIALOG(mWindow)->vbox),
|
||||
dialogHBox,
|
||||
FALSE,
|
||||
FALSE,
|
||||
0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SetTitle(const PRUnichar *aTitle)
|
||||
{
|
||||
mTitle.Assign(NS_ConvertUTF16toUTF8(aTitle));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SetTextValue(const PRUnichar *aTextValue)
|
||||
{
|
||||
mTextValue.Assign(NS_ConvertUTF16toUTF8(aTextValue));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SetCheckMessage(const PRUnichar *aMessage)
|
||||
{
|
||||
mCheckMessage.Assign(NS_ConvertUTF16toUTF8(aMessage));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SetMessageText(const PRUnichar *aMessageText)
|
||||
{
|
||||
mMessageText.Assign(NS_ConvertUTF16toUTF8(aMessageText));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SetUser(const PRUnichar *aUser)
|
||||
{
|
||||
mUser.Assign(NS_ConvertUTF16toUTF8(aUser));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SetPassword(const PRUnichar *aPass)
|
||||
{
|
||||
mPass.Assign(NS_ConvertUTF16toUTF8(aPass));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SetCheckValue(const PRBool aValue)
|
||||
{
|
||||
mCheckValue = aValue;
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SetItems(const PRUnichar** aItemArray, PRUint32 aCount)
|
||||
{
|
||||
if (mItemList)
|
||||
delete[] mItemList;
|
||||
|
||||
mItemCount = aCount;
|
||||
mItemList = new nsCString[aCount];
|
||||
ALLOC_NOT_CHECKED(mItemList);
|
||||
for (PRUint32 i = 0; i < aCount; ++i)
|
||||
mItemList[i].Assign(NS_ConvertUTF16toUTF8(aItemArray[i]));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SetButtons(const PRUnichar* aButton0Label,
|
||||
const PRUnichar* aButton1Label,
|
||||
const PRUnichar* aButton2Label)
|
||||
{
|
||||
mButtonLabels[0].Assign(NS_ConvertUTF16toUTF8(aButton0Label));
|
||||
mButtonLabels[1].Assign(NS_ConvertUTF16toUTF8(aButton1Label));
|
||||
mButtonLabels[2].Assign(NS_ConvertUTF16toUTF8(aButton2Label));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::GetCheckValue(PRBool *aValue)
|
||||
{
|
||||
*aValue = mCheckValue;
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::GetConfirmValue(PRBool *aConfirmValue)
|
||||
{
|
||||
*aConfirmValue = mConfirmResult;
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::GetTextValue(PRUnichar **aTextValue)
|
||||
{
|
||||
*aTextValue = ToNewUnicode(NS_ConvertUTF8toUTF16(mTextValue));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::GetUser(PRUnichar **aUser)
|
||||
{
|
||||
*aUser = ToNewUnicode(NS_ConvertUTF8toUTF16(mUser));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::GetPassword(PRUnichar **aPass)
|
||||
{
|
||||
*aPass = ToNewUnicode(NS_ConvertUTF8toUTF16(mPass));
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::GetSelectedItem(PRInt32 *aIndex)
|
||||
{
|
||||
*aIndex = mSelectedItem;
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::GetButtonPressed(PRInt32 *aButton)
|
||||
{
|
||||
*aButton = mButtonPressed;
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::Run(void)
|
||||
{
|
||||
gtk_widget_show_all(mWindow);
|
||||
gint response = gtk_dialog_run(GTK_DIALOG(mWindow));
|
||||
switch (response) {
|
||||
case GTK_RESPONSE_NONE:
|
||||
case GTK_RESPONSE_CANCEL:
|
||||
case GTK_RESPONSE_DELETE_EVENT:
|
||||
mConfirmResult = PR_FALSE;
|
||||
break;
|
||||
case GTK_RESPONSE_ACCEPT:
|
||||
mConfirmResult = PR_TRUE;
|
||||
SaveDialogValues();
|
||||
break;
|
||||
default:
|
||||
mButtonPressed = response;
|
||||
SaveDialogValues();
|
||||
}
|
||||
|
||||
gtk_widget_destroy(mWindow);
|
||||
}
|
||||
|
||||
void
|
||||
EmbedPrompter::SaveDialogValues()
|
||||
{
|
||||
if (mUserField)
|
||||
mUser.Assign(gtk_entry_get_text(GTK_ENTRY(mUserField)));
|
||||
|
||||
if (mPassField)
|
||||
mPass.Assign(gtk_entry_get_text(GTK_ENTRY(mPassField)));
|
||||
|
||||
if (mCheckBox)
|
||||
mCheckValue = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mCheckBox));
|
||||
|
||||
if (mTextField)
|
||||
mTextValue.Assign(gtk_entry_get_text(GTK_ENTRY(mTextField)));
|
||||
|
||||
if (mOptionMenu)
|
||||
mSelectedItem = gtk_option_menu_get_history(GTK_OPTION_MENU(mOptionMenu));
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#define EMBED_MAX_BUTTONS 3
|
||||
|
||||
class EmbedPrompter {
|
||||
|
||||
public:
|
||||
|
||||
EmbedPrompter();
|
||||
~EmbedPrompter();
|
||||
|
||||
enum PromptType {
|
||||
TYPE_ALERT,
|
||||
TYPE_ALERT_CHECK,
|
||||
TYPE_CONFIRM,
|
||||
TYPE_CONFIRM_CHECK,
|
||||
TYPE_PROMPT,
|
||||
TYPE_PROMPT_USER_PASS,
|
||||
TYPE_PROMPT_PASS,
|
||||
TYPE_SELECT,
|
||||
TYPE_UNIVERSAL
|
||||
};
|
||||
|
||||
nsresult Create(PromptType aType, GtkWindow* aParentWindow);
|
||||
void SetTitle(const PRUnichar *aTitle);
|
||||
void SetTextValue(const PRUnichar *aTextValue);
|
||||
void SetCheckMessage(const PRUnichar *aCheckMessage);
|
||||
void SetCheckValue(const PRBool aValue);
|
||||
void SetMessageText(const PRUnichar *aMessageText);
|
||||
void SetUser(const PRUnichar *aUser);
|
||||
void SetPassword(const PRUnichar *aPass);
|
||||
void SetButtons(const PRUnichar* aButton0Label,
|
||||
const PRUnichar* aButton1Label,
|
||||
const PRUnichar* aButton2Label);
|
||||
void SetItems(const PRUnichar **aItemArray, PRUint32 aCount);
|
||||
|
||||
void GetCheckValue(PRBool *aValue);
|
||||
void GetConfirmValue(PRBool *aConfirmValue);
|
||||
void GetTextValue(PRUnichar **aTextValue);
|
||||
void GetUser(PRUnichar **aUser);
|
||||
void GetPassword(PRUnichar **aPass);
|
||||
void GetButtonPressed(PRInt32 *aButton);
|
||||
void GetSelectedItem(PRInt32 *aIndex);
|
||||
|
||||
void Run(void);
|
||||
|
||||
private:
|
||||
|
||||
void SaveDialogValues();
|
||||
|
||||
nsCString mTitle;
|
||||
nsCString mMessageText;
|
||||
nsCString mTextValue;
|
||||
nsCString mCheckMessage;
|
||||
PRBool mCheckValue;
|
||||
nsCString mUser;
|
||||
nsCString mPass;
|
||||
nsCString mButtonLabels[EMBED_MAX_BUTTONS];
|
||||
nsCString *mItemList;
|
||||
PRUint32 mItemCount;
|
||||
|
||||
PRInt32 mButtonPressed;
|
||||
PRBool mConfirmResult;
|
||||
PRInt32 mSelectedItem;
|
||||
|
||||
GtkWidget *mWindow;
|
||||
GtkWidget *mUserField;
|
||||
GtkWidget *mPassField;
|
||||
GtkWidget *mTextField;
|
||||
GtkWidget *mOptionMenu;
|
||||
GtkWidget *mCheckBox;
|
||||
};
|
||||
@@ -1,507 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCWebBrowser.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIWidget.h"
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsReadableUtils.h"
|
||||
#else
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#endif
|
||||
#include "EmbedWindow.h"
|
||||
#include "EmbedPrivate.h"
|
||||
#include "EmbedPrompter.h"
|
||||
|
||||
GtkWidget *EmbedWindow::sTipWindow = nsnull;
|
||||
|
||||
EmbedWindow::EmbedWindow(void)
|
||||
{
|
||||
mOwner = nsnull;
|
||||
mVisibility = PR_FALSE;
|
||||
mIsModal = PR_FALSE;
|
||||
}
|
||||
|
||||
EmbedWindow::~EmbedWindow(void)
|
||||
{
|
||||
ExitModalEventLoop(PR_FALSE);
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedWindow::Init(EmbedPrivate *aOwner)
|
||||
{
|
||||
// save our owner for later
|
||||
mOwner = aOwner;
|
||||
|
||||
// create our nsIWebBrowser object and set up some basic defaults.
|
||||
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
|
||||
if (!mWebBrowser)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, this));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(mWebBrowser);
|
||||
item->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
EmbedWindow::CreateWindow(void)
|
||||
{
|
||||
nsresult rv;
|
||||
GtkWidget *ownerAsWidget = GTK_WIDGET(mOwner->mOwningWidget);
|
||||
|
||||
// Get the base window interface for the web browser object and
|
||||
// create the window.
|
||||
mBaseWindow = do_QueryInterface(mWebBrowser);
|
||||
rv = mBaseWindow->InitWindow(GTK_WIDGET(mOwner->mOwningWidget),
|
||||
nsnull,
|
||||
0, 0,
|
||||
ownerAsWidget->allocation.width,
|
||||
ownerAsWidget->allocation.height);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = mBaseWindow->Create();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
EmbedWindow::ReleaseChildren(void)
|
||||
{
|
||||
ExitModalEventLoop(PR_FALSE);
|
||||
|
||||
mBaseWindow->Destroy();
|
||||
mBaseWindow = 0;
|
||||
mWebBrowser = 0;
|
||||
}
|
||||
|
||||
// nsISupports
|
||||
|
||||
NS_IMPL_ADDREF(EmbedWindow)
|
||||
NS_IMPL_RELEASE(EmbedWindow)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(EmbedWindow)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
|
||||
// NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
// nsIWebBrowserChrome
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::SetStatus(PRUint32 aStatusType, const PRUnichar *aStatus)
|
||||
{
|
||||
switch (aStatusType) {
|
||||
case STATUS_SCRIPT:
|
||||
{
|
||||
mJSStatus = aStatus; //FIXME MEMORY LEAK
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[JS_STATUS]);
|
||||
}
|
||||
break;
|
||||
case STATUS_SCRIPT_DEFAULT:
|
||||
// Gee, that's nice.
|
||||
break;
|
||||
case STATUS_LINK:
|
||||
{
|
||||
mLinkMessage = aStatus;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[LINK_MESSAGE]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::GetWebBrowser(nsIWebBrowser **aWebBrowser)
|
||||
{
|
||||
*aWebBrowser = mWebBrowser;
|
||||
NS_IF_ADDREF(*aWebBrowser);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::SetWebBrowser(nsIWebBrowser *aWebBrowser)
|
||||
{
|
||||
mWebBrowser = aWebBrowser;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::GetChromeFlags(PRUint32 *aChromeFlags)
|
||||
{
|
||||
*aChromeFlags = mOwner->mChromeMask;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::SetChromeFlags(PRUint32 aChromeFlags)
|
||||
{
|
||||
mOwner->SetChromeMask(aChromeFlags);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::DestroyBrowserWindow(void)
|
||||
{
|
||||
// mark the owner as destroyed so it won't emit events anymore.
|
||||
mOwner->mIsDestroyed = PR_TRUE;
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[DESTROY_BROWSER]);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
|
||||
{
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[SIZE_TO], aCX, aCY);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::ShowAsModal(void)
|
||||
{
|
||||
mIsModal = PR_TRUE;
|
||||
GtkWidget *toplevel;
|
||||
toplevel = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
|
||||
gtk_grab_add(toplevel);
|
||||
gtk_main();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::IsWindowModal(PRBool *_retval)
|
||||
{
|
||||
*_retval = mIsModal;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::ExitModalEventLoop(nsresult aStatus)
|
||||
{
|
||||
if (mIsModal) {
|
||||
GtkWidget *toplevel;
|
||||
toplevel = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
|
||||
gtk_grab_remove(toplevel);
|
||||
mIsModal = PR_FALSE;
|
||||
gtk_main_quit();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIWebBrowserChromeFocus
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::FocusNextElement()
|
||||
{
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
GtkWidget* parent = GTK_WIDGET(mOwner->mOwningWidget)->parent;
|
||||
|
||||
if (GTK_IS_CONTAINER(parent))
|
||||
gtk_container_focus(GTK_CONTAINER(parent),
|
||||
GTK_DIR_TAB_FORWARD);
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
GtkWidget *toplevel;
|
||||
toplevel = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
|
||||
if (!GTK_WIDGET_TOPLEVEL(toplevel))
|
||||
return NS_OK;
|
||||
|
||||
g_signal_emit_by_name(G_OBJECT(toplevel), "move_focus",
|
||||
GTK_DIR_TAB_FORWARD);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::FocusPrevElement()
|
||||
{
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
GtkWidget* parent = GTK_WIDGET(mOwner->mOwningWidget)->parent;
|
||||
|
||||
if (GTK_IS_CONTAINER(parent))
|
||||
gtk_container_focus(GTK_CONTAINER(parent),
|
||||
GTK_DIR_TAB_BACKWARD);
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
GtkWidget *toplevel;
|
||||
toplevel = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
|
||||
if (!GTK_WIDGET_TOPLEVEL(toplevel))
|
||||
return NS_OK;
|
||||
|
||||
g_signal_emit_by_name(G_OBJECT(toplevel), "move_focus",
|
||||
GTK_DIR_TAB_BACKWARD);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIEmbeddingSiteWindow
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::SetDimensions(PRUint32 aFlags, PRInt32 aX, PRInt32 aY,
|
||||
PRInt32 aCX, PRInt32 aCY)
|
||||
{
|
||||
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
|
||||
(aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
|
||||
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
|
||||
return mBaseWindow->SetPositionAndSize(aX, aY, aCX, aCY, PR_TRUE);
|
||||
}
|
||||
else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
|
||||
return mBaseWindow->SetPosition(aX, aY);
|
||||
}
|
||||
else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
|
||||
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
|
||||
return mBaseWindow->SetSize(aCX, aCY, PR_TRUE);
|
||||
}
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::GetDimensions(PRUint32 aFlags, PRInt32 *aX,
|
||||
PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY)
|
||||
{
|
||||
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
|
||||
(aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
|
||||
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
|
||||
return mBaseWindow->GetPositionAndSize(aX, aY, aCX, aCY);
|
||||
}
|
||||
else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
|
||||
return mBaseWindow->GetPosition(aX, aY);
|
||||
}
|
||||
else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
|
||||
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
|
||||
return mBaseWindow->GetSize(aCX, aCY);
|
||||
}
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::SetFocus(void)
|
||||
{
|
||||
// XXX might have to do more here.
|
||||
return mBaseWindow->SetFocus();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::GetTitle(PRUnichar **aTitle)
|
||||
{
|
||||
*aTitle = ToNewUnicode(mTitle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::SetTitle(const PRUnichar *aTitle)
|
||||
{
|
||||
mTitle = aTitle;
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[TITLE]);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::GetSiteWindow(void **aSiteWindow)
|
||||
{
|
||||
GtkWidget *ownerAsWidget(GTK_WIDGET(mOwner->mOwningWidget));
|
||||
*aSiteWindow = NS_STATIC_CAST(void *, ownerAsWidget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::GetVisibility(PRBool *aVisibility)
|
||||
{
|
||||
*aVisibility = mVisibility ||
|
||||
!mOwner->mIsChrome &&
|
||||
mOwner->mOwningWidget &&
|
||||
GTK_WIDGET_MAPPED(mOwner->mOwningWidget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::SetVisibility(PRBool aVisibility)
|
||||
{
|
||||
// We always set the visibility so that if it's chrome and we finish
|
||||
// the load we know that we have to show the window.
|
||||
mVisibility = aVisibility;
|
||||
|
||||
// if this is a chrome window and the chrome hasn't finished loading
|
||||
// yet then don't show the window yet.
|
||||
if (mOwner->mIsChrome && !mOwner->mChromeLoaded)
|
||||
return NS_OK;
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
|
||||
moz_embed_signals[VISIBILITY],
|
||||
aVisibility);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsITooltipListener
|
||||
|
||||
#if 0
|
||||
static gint
|
||||
tooltips_paint_window(GtkWidget *window)
|
||||
{
|
||||
// draw tooltip style border around the text
|
||||
gtk_paint_flat_box(window->style, window->window,
|
||||
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
|
||||
NULL, window, "tooltip",
|
||||
0, 0,
|
||||
window->allocation.width, window->allocation.height);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords,
|
||||
const PRUnichar *aTipText)
|
||||
{
|
||||
nsAutoString tipText(aTipText);
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
const char* tipString = ToNewCString(tipText);
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
const char* tipString = ToNewUTF8String(tipText);
|
||||
#endif
|
||||
|
||||
if (sTipWindow)
|
||||
gtk_widget_destroy(sTipWindow);
|
||||
|
||||
// get the root origin for this content window
|
||||
nsCOMPtr<nsIWidget> mainWidget;
|
||||
mBaseWindow->GetMainWidget(getter_AddRefs(mainWidget));
|
||||
GdkWindow *window;
|
||||
window = NS_STATIC_CAST(GdkWindow *,
|
||||
mainWidget->GetNativeData(NS_NATIVE_WINDOW));
|
||||
gint root_x, root_y;
|
||||
gdk_window_get_origin(window, &root_x, &root_y);
|
||||
|
||||
// XXX work around until I can get pink to figure out why
|
||||
// tooltips vanish if they show up right at the origin of the
|
||||
// cursor.
|
||||
root_y += 10;
|
||||
|
||||
sTipWindow = gtk_window_new(GTK_WINDOW_POPUP);
|
||||
gtk_widget_set_app_paintable(sTipWindow, TRUE);
|
||||
gtk_window_set_policy(GTK_WINDOW(sTipWindow), FALSE, FALSE, TRUE);
|
||||
// needed to get colors + fonts etc correctly
|
||||
gtk_widget_set_name(sTipWindow, "gtk-tooltips");
|
||||
|
||||
// set up the popup window as a transient of the widget.
|
||||
GtkWidget *toplevel_window;
|
||||
toplevel_window = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
|
||||
if (!GTK_WINDOW(toplevel_window)) {
|
||||
NS_ERROR("no gtk window in hierarchy!\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
gtk_window_set_transient_for(GTK_WINDOW(sTipWindow),
|
||||
GTK_WINDOW(toplevel_window));
|
||||
|
||||
// realize the widget
|
||||
gtk_widget_realize(sTipWindow);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(sTipWindow), "expose_event",
|
||||
GTK_SIGNAL_FUNC(tooltips_paint_window), NULL);
|
||||
|
||||
// set up the label for the tooltip
|
||||
GtkWidget *label = gtk_label_new(tipString);
|
||||
// wrap automatically
|
||||
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
|
||||
gtk_container_add(GTK_CONTAINER(sTipWindow), label);
|
||||
gtk_container_set_border_width(GTK_CONTAINER(sTipWindow), 4);
|
||||
// set the coords for the widget
|
||||
gtk_widget_set_uposition(sTipWindow, aXCoords + root_x,
|
||||
aYCoords + root_y);
|
||||
|
||||
// and show it.
|
||||
gtk_widget_show_all(sTipWindow);
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
gtk_widget_popup(sTipWindow, aXCoords + root_x, aYCoords + root_y); */
|
||||
#endif /* MOZ_WIDGET_GTK */
|
||||
|
||||
nsMemory::Free((void*)tipString);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::OnHideTooltip(void)
|
||||
{
|
||||
if (sTipWindow)
|
||||
gtk_widget_destroy(sTipWindow);
|
||||
sTipWindow = NULL;
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
// nsIInterfaceRequestor
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindow::GetInterface(const nsIID &aIID, void** aInstancePtr)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = QueryInterface(aIID, aInstancePtr);
|
||||
|
||||
// pass it up to the web browser object
|
||||
if (NS_FAILED(rv) || !*aInstancePtr) {
|
||||
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(mWebBrowser);
|
||||
return ir->GetInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __EmbedWindow_h
|
||||
#define __EmbedWindow_h
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsString.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIWebBrowserChromeFocus.h"
|
||||
#include "nsIEmbeddingSiteWindow.h"
|
||||
//#include "nsITooltipListener.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIWebBrowser.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
class EmbedPrivate;
|
||||
|
||||
class EmbedWindow : public nsIWebBrowserChrome,
|
||||
public nsIWebBrowserChromeFocus,
|
||||
public nsIEmbeddingSiteWindow,
|
||||
// public nsITooltipListener,
|
||||
public nsIInterfaceRequestor
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
EmbedWindow();
|
||||
virtual ~EmbedWindow();
|
||||
|
||||
nsresult Init (EmbedPrivate *aOwner);
|
||||
nsresult CreateWindow (void);
|
||||
void ReleaseChildren (void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIWEBBROWSERCHROME
|
||||
|
||||
NS_DECL_NSIWEBBROWSERCHROMEFOCUS
|
||||
|
||||
NS_DECL_NSIEMBEDDINGSITEWINDOW
|
||||
|
||||
// NS_DECL_NSITOOLTIPLISTENER
|
||||
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
nsString mTitle;
|
||||
nsString mJSStatus;
|
||||
nsString mLinkMessage;
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> mBaseWindow; // [OWNER]
|
||||
|
||||
private:
|
||||
|
||||
EmbedPrivate *mOwner;
|
||||
nsCOMPtr<nsIWebBrowser> mWebBrowser; // [OWNER]
|
||||
static GtkWidget *sTipWindow;
|
||||
PRBool mVisibility;
|
||||
PRBool mIsModal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* __EmbedWindow_h */
|
||||
@@ -1,117 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard.
|
||||
* Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "EmbedWindowCreator.h"
|
||||
#include "EmbedPrivate.h"
|
||||
#include "EmbedWindow.h"
|
||||
|
||||
// in order to create orphaned windows
|
||||
#include "gtkmozembedprivate.h"
|
||||
|
||||
EmbedWindowCreator::EmbedWindowCreator(PRBool *aOpenBlockPtr)
|
||||
{
|
||||
mOpenBlock = aOpenBlockPtr;
|
||||
}
|
||||
|
||||
EmbedWindowCreator::~EmbedWindowCreator()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(EmbedWindowCreator, nsIWindowCreator)
|
||||
|
||||
NS_IMETHODIMP
|
||||
EmbedWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent,
|
||||
PRUint32 aChromeFlags,
|
||||
nsIWebBrowserChrome **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
if (mOpenBlock) {
|
||||
if (*mOpenBlock == PR_TRUE) {
|
||||
*mOpenBlock = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
GtkMozEmbed *newEmbed = nsnull;
|
||||
|
||||
// No parent? Ask via the singleton object instead.
|
||||
if (!aParent) {
|
||||
gtk_moz_embed_single_create_window(&newEmbed,
|
||||
(guint)aChromeFlags);
|
||||
} else {
|
||||
// Find the EmbedPrivate object for this web browser chrome object.
|
||||
EmbedPrivate *embedPrivate = EmbedPrivate::FindPrivateForBrowser(aParent);
|
||||
|
||||
if (!embedPrivate)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(embedPrivate->mOwningWidget),
|
||||
moz_embed_signals[NEW_WINDOW],
|
||||
&newEmbed, (guint)aChromeFlags);
|
||||
|
||||
}
|
||||
|
||||
// check to make sure that we made a new window
|
||||
if (!newEmbed)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// The window _must_ be realized before we pass it back to the
|
||||
// function that created it. Functions that create new windows
|
||||
// will do things like GetDocShell() and the widget has to be
|
||||
// realized before that can happen.
|
||||
gtk_widget_realize(GTK_WIDGET(newEmbed));
|
||||
|
||||
EmbedPrivate *newEmbedPrivate = NS_STATIC_CAST(EmbedPrivate *,
|
||||
newEmbed->data);
|
||||
|
||||
// set the chrome flag on the new window if it's a chrome open
|
||||
if (aChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)
|
||||
newEmbedPrivate->mIsChrome = PR_TRUE;
|
||||
|
||||
*_retval = NS_STATIC_CAST(nsIWebBrowserChrome *,
|
||||
(newEmbedPrivate->mWindow));
|
||||
|
||||
if (*_retval) {
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __EmbedWindowCreator_h
|
||||
#define __EmbedWindowCreator_h
|
||||
|
||||
#include "nsIWindowCreator.h"
|
||||
|
||||
class EmbedWindowCreator : public nsIWindowCreator
|
||||
{
|
||||
public:
|
||||
EmbedWindowCreator(PRBool *aOpenBlockPtr);
|
||||
virtual ~EmbedWindowCreator();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWINDOWCREATOR
|
||||
|
||||
private:
|
||||
PRBool *mOpenBlock;
|
||||
};
|
||||
|
||||
#endif /* __EmbedWindowCreator_h */
|
||||
@@ -1,587 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=4 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "GtkPromptService.h"
|
||||
#include "EmbedGtkTools.h"
|
||||
#include "gtkmozembedprivate.h"
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
#include "EmbedPrompter.h"
|
||||
#endif
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsString.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
#include "nsIWindowWatcher.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIEmbeddingSiteWindow.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#define UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(newed) PR_BEGIN_MACRO \
|
||||
/* OOPS this code is using a glib allocation function which \
|
||||
* will cause the application to crash when it runs out of \
|
||||
* memory. This is not cool. either g_try methods should be \
|
||||
* used or malloc, or new (note that gecko /will/ be replacing \
|
||||
* its operator new such that new will not throw exceptions). \
|
||||
* XXX please fix me. \
|
||||
*/ \
|
||||
if (!newed) { \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
GtkPromptService::GtkPromptService()
|
||||
{
|
||||
}
|
||||
|
||||
GtkPromptService::~GtkPromptService()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(GtkPromptService, nsIPromptService, nsICookiePromptService)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::Alert(
|
||||
nsIDOMWindow* aParent,
|
||||
const PRUnichar* aDialogTitle,
|
||||
const PRUnichar* aDialogText)
|
||||
{
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
|
||||
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[ALERT], TRUE)) {
|
||||
gtk_signal_emit(GTK_OBJECT(parentWidget),
|
||||
moz_embed_signals[ALERT],
|
||||
(const gchar *) NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
(const gchar *) NS_ConvertUTF16toUTF8(aDialogText).get());
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
EmbedPrompter prompter;
|
||||
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Alert").get());
|
||||
prompter.SetMessageText(aDialogText);
|
||||
prompter.Create(EmbedPrompter::TYPE_ALERT,
|
||||
GetGtkWindowForDOMWindow(aParent));
|
||||
prompter.Run();
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::AlertCheck(
|
||||
nsIDOMWindow* aParent,
|
||||
const PRUnichar* aDialogTitle,
|
||||
const PRUnichar* aDialogText,
|
||||
const PRUnichar* aCheckMsg,
|
||||
PRBool* aCheckValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aCheckValue);
|
||||
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
|
||||
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[ALERT_CHECK], TRUE)) {
|
||||
gtk_signal_emit(GTK_OBJECT(parentWidget),
|
||||
moz_embed_signals[ALERT_CHECK],
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
|
||||
aCheckValue);
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
EmbedPrompter prompter;
|
||||
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Alert").get());
|
||||
prompter.SetMessageText(aDialogText);
|
||||
prompter.SetCheckMessage(aCheckMsg);
|
||||
prompter.SetCheckValue(*aCheckValue);
|
||||
prompter.Create(EmbedPrompter::TYPE_ALERT_CHECK,
|
||||
GetGtkWindowForDOMWindow(aParent));
|
||||
prompter.Run();
|
||||
prompter.GetCheckValue(aCheckValue);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::Confirm(
|
||||
nsIDOMWindow* aParent,
|
||||
const PRUnichar* aDialogTitle,
|
||||
const PRUnichar* aDialogText,
|
||||
PRBool* aConfirm)
|
||||
{
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
|
||||
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[CONFIRM], TRUE)) {
|
||||
gtk_signal_emit(GTK_OBJECT(parentWidget),
|
||||
moz_embed_signals[CONFIRM],
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(), NS_ConvertUTF16toUTF8(aDialogText).get(), aConfirm);
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
EmbedPrompter prompter;
|
||||
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Confirm").get());
|
||||
prompter.SetMessageText(aDialogText);
|
||||
prompter.Create(EmbedPrompter::TYPE_CONFIRM,
|
||||
GetGtkWindowForDOMWindow(aParent));
|
||||
prompter.Run();
|
||||
prompter.GetConfirmValue(aConfirm);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::ConfirmCheck(
|
||||
nsIDOMWindow* aParent,
|
||||
const PRUnichar* aDialogTitle,
|
||||
const PRUnichar* aDialogText,
|
||||
const PRUnichar* aCheckMsg,
|
||||
PRBool* aCheckValue,
|
||||
PRBool* aConfirm)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aCheckValue);
|
||||
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
|
||||
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[CONFIRM_CHECK], TRUE)) {
|
||||
gtk_signal_emit(GTK_OBJECT(parentWidget),
|
||||
moz_embed_signals[CONFIRM_CHECK],
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
|
||||
aCheckValue,
|
||||
aConfirm);
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
EmbedPrompter prompter;
|
||||
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Confirm").get());
|
||||
prompter.SetMessageText(aDialogText);
|
||||
prompter.SetCheckMessage(aCheckMsg);
|
||||
prompter.SetCheckValue(*aCheckValue);
|
||||
prompter.Create(EmbedPrompter::TYPE_CONFIRM_CHECK,
|
||||
GetGtkWindowForDOMWindow(aParent));
|
||||
prompter.Run();
|
||||
prompter.GetCheckValue(aCheckValue);
|
||||
prompter.GetConfirmValue(aConfirm);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::ConfirmEx(
|
||||
nsIDOMWindow* aParent,
|
||||
const PRUnichar* aDialogTitle,
|
||||
const PRUnichar* aDialogText,
|
||||
PRUint32 aButtonFlags,
|
||||
const PRUnichar* aButton0Title,
|
||||
const PRUnichar* aButton1Title,
|
||||
const PRUnichar* aButton2Title,
|
||||
const PRUnichar* aCheckMsg,
|
||||
PRBool* aCheckValue,
|
||||
PRInt32* aRetVal)
|
||||
{
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
|
||||
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[CONFIRM_EX], TRUE)) {
|
||||
gtk_signal_emit(GTK_OBJECT(parentWidget),
|
||||
moz_embed_signals[CONFIRM_EX],
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
NS_ConvertUTF16toUTF8(aDialogText).get(),
|
||||
aButtonFlags,
|
||||
NS_ConvertUTF16toUTF8(aButton0Title).get(),
|
||||
NS_ConvertUTF16toUTF8(aButton1Title).get(),
|
||||
NS_ConvertUTF16toUTF8(aButton2Title).get(),
|
||||
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
|
||||
aCheckValue,
|
||||
aRetVal);
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
EmbedPrompter prompter;
|
||||
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Confirm").get());
|
||||
prompter.SetMessageText(aDialogText);
|
||||
|
||||
nsAutoString button0Label, button1Label, button2Label;
|
||||
GetButtonLabel(aButtonFlags, BUTTON_POS_0, aButton0Title, button0Label);
|
||||
GetButtonLabel(aButtonFlags, BUTTON_POS_1, aButton1Title, button1Label);
|
||||
GetButtonLabel(aButtonFlags, BUTTON_POS_2, aButton2Title, button2Label);
|
||||
prompter.SetButtons(button0Label.get(),
|
||||
button1Label.get(),
|
||||
button2Label.get());
|
||||
|
||||
if (aCheckMsg)
|
||||
prompter.SetCheckMessage(aCheckMsg);
|
||||
if (aCheckValue)
|
||||
prompter.SetCheckValue(*aCheckValue);
|
||||
|
||||
prompter.Create(EmbedPrompter::TYPE_UNIVERSAL,
|
||||
GetGtkWindowForDOMWindow(aParent));
|
||||
prompter.Run();
|
||||
|
||||
if (aCheckValue)
|
||||
prompter.GetCheckValue(aCheckValue);
|
||||
|
||||
prompter.GetButtonPressed(aRetVal);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#define XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(confused) PR_BEGIN_MACRO \
|
||||
/* There is no way that this unforunate and confused object can \
|
||||
* possibly be handled correctly. It started its life as an \
|
||||
* XPCOM allocated pointer. \
|
||||
* Then someone called it a gchar which confused it. \
|
||||
* Then it was passed to a random function which probably \
|
||||
* assumed it had ownership. \
|
||||
* Finally it was freed using g_free. \
|
||||
* This pointer is seriously confused. \
|
||||
* XXX please please please help this pointer find some way to \
|
||||
* rest in peace. \
|
||||
*/ \
|
||||
PR_END_MACRO
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::Prompt(
|
||||
nsIDOMWindow* aParent,
|
||||
const PRUnichar* aDialogTitle,
|
||||
const PRUnichar* aDialogText,
|
||||
PRUnichar** aValue,
|
||||
const PRUnichar* aCheckMsg,
|
||||
PRBool* aCheckValue,
|
||||
PRBool* aConfirm)
|
||||
{
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
|
||||
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[PROMPT], TRUE)) {
|
||||
gchar * value = ToNewCString(NS_ConvertUTF16toUTF8(*aValue));
|
||||
XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(value);
|
||||
gtk_signal_emit(GTK_OBJECT(parentWidget),
|
||||
moz_embed_signals[PROMPT],
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
NS_ConvertUTF16toUTF8(aDialogText).get(),
|
||||
&value,
|
||||
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
|
||||
aCheckValue,
|
||||
aConfirm,
|
||||
NULL);
|
||||
if (*aConfirm) {
|
||||
if (*aValue)
|
||||
NS_Free(*aValue);
|
||||
*aValue = ToNewUnicode(NS_ConvertUTF8toUTF16(value));
|
||||
}
|
||||
g_free(value);
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
EmbedPrompter prompter;
|
||||
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Prompt").get());
|
||||
prompter.SetMessageText(aDialogText);
|
||||
prompter.SetTextValue(*aValue);
|
||||
if (aCheckMsg)
|
||||
prompter.SetCheckMessage(aCheckMsg);
|
||||
if (aCheckValue)
|
||||
prompter.SetCheckValue(*aCheckValue);
|
||||
|
||||
prompter.Create(EmbedPrompter::TYPE_PROMPT,
|
||||
GetGtkWindowForDOMWindow(aParent));
|
||||
prompter.Run();
|
||||
if (aCheckValue)
|
||||
prompter.GetCheckValue(aCheckValue);
|
||||
prompter.GetConfirmValue(aConfirm);
|
||||
if (*aConfirm) {
|
||||
if (*aValue)
|
||||
NS_Free(*aValue);
|
||||
prompter.GetTextValue(aValue);
|
||||
}
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::PromptUsernameAndPassword(
|
||||
nsIDOMWindow* aParent,
|
||||
const PRUnichar* aDialogTitle,
|
||||
const PRUnichar* aDialogText,
|
||||
PRUnichar** aUsername,
|
||||
PRUnichar** aPassword,
|
||||
const PRUnichar* aCheckMsg,
|
||||
PRBool* aCheckValue,
|
||||
PRBool* aConfirm)
|
||||
{
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
|
||||
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[PROMPT_AUTH], TRUE)) {
|
||||
gchar * username = ToNewCString(NS_ConvertUTF16toUTF8(*aUsername));
|
||||
XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(username);
|
||||
gchar * password = ToNewCString(NS_ConvertUTF16toUTF8(*aPassword));
|
||||
XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(password);
|
||||
|
||||
gtk_signal_emit(GTK_OBJECT(parentWidget),
|
||||
moz_embed_signals[PROMPT_AUTH],
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
NS_ConvertUTF16toUTF8(aDialogText).get(),
|
||||
&username, &password,
|
||||
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
|
||||
aCheckValue, aConfirm);
|
||||
|
||||
if (*aConfirm) {
|
||||
if (*aUsername)
|
||||
NS_Free(*aUsername);
|
||||
*aUsername = ToNewUnicode(NS_ConvertUTF8toUTF16(username));
|
||||
if (*aPassword)
|
||||
NS_Free(*aPassword);
|
||||
*aPassword = ToNewUnicode(NS_ConvertUTF8toUTF16(password));
|
||||
}
|
||||
g_free(username);
|
||||
g_free(password);
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
EmbedPrompter prompter;
|
||||
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Prompt").get());
|
||||
prompter.SetMessageText(aDialogText);
|
||||
prompter.SetUser(*aUsername);
|
||||
prompter.SetPassword(*aPassword);
|
||||
if (aCheckMsg)
|
||||
prompter.SetCheckMessage(aCheckMsg);
|
||||
if (aCheckValue)
|
||||
prompter.SetCheckValue(*aCheckValue);
|
||||
|
||||
prompter.Create(EmbedPrompter::TYPE_PROMPT_USER_PASS,
|
||||
GetGtkWindowForDOMWindow(aParent));
|
||||
prompter.Run();
|
||||
if (aCheckValue)
|
||||
prompter.GetCheckValue(aCheckValue);
|
||||
prompter.GetConfirmValue(aConfirm);
|
||||
if (*aConfirm) {
|
||||
if (*aUsername)
|
||||
NS_Free(*aUsername);
|
||||
prompter.GetUser(aUsername);
|
||||
|
||||
if (*aPassword)
|
||||
NS_Free(*aPassword);
|
||||
prompter.GetPassword(aPassword);
|
||||
}
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::PromptPassword(
|
||||
nsIDOMWindow* aParent,
|
||||
const PRUnichar* aDialogTitle,
|
||||
const PRUnichar* aDialogText,
|
||||
PRUnichar** aPassword,
|
||||
const PRUnichar* aCheckMsg,
|
||||
PRBool* aCheckValue, PRBool* aConfirm)
|
||||
{
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
|
||||
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[PROMPT_AUTH], TRUE)) {
|
||||
gchar * password = ToNewCString(NS_ConvertUTF16toUTF8(*aPassword));
|
||||
XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(password);
|
||||
gtk_signal_emit(GTK_OBJECT(parentWidget),
|
||||
moz_embed_signals[PROMPT_AUTH],
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
NS_ConvertUTF16toUTF8(aDialogText).get(),
|
||||
NULL,
|
||||
&password,
|
||||
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
|
||||
aCheckValue,
|
||||
aConfirm);
|
||||
if (*aConfirm) {
|
||||
if (*aPassword)
|
||||
NS_Free(*aPassword);
|
||||
*aPassword = ToNewUnicode(NS_ConvertUTF8toUTF16(password));
|
||||
}
|
||||
g_free(password);
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
EmbedPrompter prompter;
|
||||
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Prompt").get());
|
||||
prompter.SetMessageText(aDialogText);
|
||||
prompter.SetPassword(*aPassword);
|
||||
if (aCheckMsg)
|
||||
prompter.SetCheckMessage(aCheckMsg);
|
||||
if (aCheckValue)
|
||||
prompter.SetCheckValue(*aCheckValue);
|
||||
|
||||
prompter.Create(EmbedPrompter::TYPE_PROMPT_PASS,
|
||||
GetGtkWindowForDOMWindow(aParent));
|
||||
prompter.Run();
|
||||
if (aCheckValue)
|
||||
prompter.GetCheckValue(aCheckValue);
|
||||
prompter.GetConfirmValue(aConfirm);
|
||||
if (*aConfirm) {
|
||||
if (*aPassword)
|
||||
NS_Free(*aPassword);
|
||||
prompter.GetPassword(aPassword);
|
||||
}
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::Select(
|
||||
nsIDOMWindow* aParent,
|
||||
const PRUnichar* aDialogTitle,
|
||||
const PRUnichar* aDialogText,
|
||||
PRUint32 aCount,
|
||||
const PRUnichar** aSelectList,
|
||||
PRInt32* outSelection,
|
||||
PRBool* aConfirm)
|
||||
{
|
||||
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
|
||||
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[SELECT], TRUE)) {
|
||||
GList * list = NULL;
|
||||
nsCString *itemList = new nsCString[aCount];
|
||||
NS_ENSURE_TRUE(itemList, NS_ERROR_OUT_OF_MEMORY);
|
||||
for (PRUint32 i = 0; i < aCount; ++i) {
|
||||
itemList[i] = ToNewCString(NS_ConvertUTF16toUTF8(aSelectList[i]));
|
||||
list = g_list_append(list, (gpointer)itemList[i].get());
|
||||
}
|
||||
gtk_signal_emit(GTK_OBJECT(parentWidget),
|
||||
moz_embed_signals[SELECT],
|
||||
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
|
||||
NS_ConvertUTF16toUTF8(aDialogText).get(),
|
||||
(const GList**)&list,
|
||||
outSelection,
|
||||
aConfirm);
|
||||
delete[] itemList;
|
||||
g_list_free(list);
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
EmbedPrompter prompter;
|
||||
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Select").get());
|
||||
prompter.SetMessageText(aDialogText);
|
||||
prompter.SetItems(aSelectList, aCount);
|
||||
prompter.Create(EmbedPrompter::TYPE_SELECT,
|
||||
GetGtkWindowForDOMWindow(aParent));
|
||||
prompter.Run();
|
||||
prompter.GetSelectedItem(outSelection);
|
||||
prompter.GetConfirmValue(aConfirm);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
/* nsCookiePromptService */
|
||||
NS_IMETHODIMP
|
||||
GtkPromptService::CookieDialog(
|
||||
nsIDOMWindow *aParent,
|
||||
nsICookie *aCookie,
|
||||
const nsACString &aHostname,
|
||||
PRInt32 aCookiesFromHost,
|
||||
PRBool aChangingCookie,
|
||||
PRBool *aRememberDecision,
|
||||
PRInt32 *aAccept)
|
||||
{
|
||||
/* FIXME - missing gint actions and gboolean illegal_path */
|
||||
gint actions = 1;
|
||||
nsCString hostName(aHostname);
|
||||
nsCString aName;
|
||||
aCookie->GetName(aName);
|
||||
nsCString aValue;
|
||||
aCookie->GetValue(aValue);
|
||||
nsCString aDomain;
|
||||
aCookie->GetHost(aDomain);
|
||||
nsCString aPath;
|
||||
aCookie->GetPath(aPath);
|
||||
/* We have to investigate a value to use here */
|
||||
gboolean illegal_path = FALSE;
|
||||
PRUint64 aExpires;
|
||||
aCookie->GetExpires(&aExpires);
|
||||
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(aParent));
|
||||
GtkMozEmbed *parentWidget = GTK_MOZ_EMBED(GetGtkWidgetForDOMWindow(domWindow));
|
||||
GtkMozEmbedCookie *cookie_struct = g_new0(GtkMozEmbedCookie, 1);
|
||||
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(cookie_struct);
|
||||
if (parentWidget && cookie_struct) {
|
||||
g_signal_emit_by_name(
|
||||
GTK_OBJECT(parentWidget->common),
|
||||
"ask-cookie",
|
||||
cookie_struct,
|
||||
actions,
|
||||
(const gchar *) hostName.get(),
|
||||
(const gchar *) aName.get(),
|
||||
(const gchar *) aValue.get(),
|
||||
(const gchar *) aDomain.get(),
|
||||
(const gchar *) aPath.get(),
|
||||
illegal_path,
|
||||
aExpires,
|
||||
NULL);
|
||||
}
|
||||
*aRememberDecision = cookie_struct->remember_decision;
|
||||
*aAccept = cookie_struct->accept;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
void
|
||||
GtkPromptService::GetButtonLabel(
|
||||
PRUint32 aFlags,
|
||||
PRUint32 aPos,
|
||||
const PRUnichar* aStringValue,
|
||||
nsAString& aLabel)
|
||||
{
|
||||
PRUint32 posFlag = (aFlags & (255 * aPos)) / aPos;
|
||||
switch (posFlag) {
|
||||
case 0:
|
||||
break;
|
||||
case BUTTON_TITLE_OK:
|
||||
aLabel.AssignLiteral(GTK_STOCK_OK);
|
||||
break;
|
||||
case BUTTON_TITLE_CANCEL:
|
||||
aLabel.AssignLiteral(GTK_STOCK_CANCEL);
|
||||
break;
|
||||
case BUTTON_TITLE_YES:
|
||||
aLabel.AssignLiteral(GTK_STOCK_YES);
|
||||
break;
|
||||
case BUTTON_TITLE_NO:
|
||||
aLabel.AssignLiteral(GTK_STOCK_NO);
|
||||
break;
|
||||
case BUTTON_TITLE_SAVE:
|
||||
aLabel.AssignLiteral(GTK_STOCK_SAVE);
|
||||
break;
|
||||
case BUTTON_TITLE_DONT_SAVE:
|
||||
aLabel.AssignLiteral("Don't Save");
|
||||
break;
|
||||
case BUTTON_TITLE_REVERT:
|
||||
aLabel.AssignLiteral("Revert");
|
||||
break;
|
||||
case BUTTON_TITLE_IS_STRING:
|
||||
aLabel = aStringValue;
|
||||
break;
|
||||
default:
|
||||
NS_WARNING("Unexpected button flags");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,72 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIPromptService.h"
|
||||
#include "nsICookiePromptService.h"
|
||||
#include "nsICookie.h"
|
||||
#include "nsNetCID.h"
|
||||
#include <gtk/gtk.h>
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsString.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
#define NS_PROMPTSERVICE_CID \
|
||||
{0x95611356, 0xf583, 0x46f5, {0x81, 0xff, 0x4b, 0x3e, 0x01, 0x62, 0xc6, 0x19}}
|
||||
|
||||
class nsIDOMWindow;
|
||||
|
||||
class GtkPromptService : public nsIPromptService,
|
||||
public nsICookiePromptService
|
||||
{
|
||||
public:
|
||||
GtkPromptService();
|
||||
virtual ~GtkPromptService();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPROMPTSERVICE
|
||||
NS_DECL_NSICOOKIEPROMPTSERVICE
|
||||
|
||||
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
private:
|
||||
void GetButtonLabel(PRUint32 aFlags, PRUint32 aPos,
|
||||
const PRUnichar* aStringValue, nsAString &aLabel);
|
||||
#endif
|
||||
};
|
||||
@@ -1,231 +0,0 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is the Mozilla browser.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Christopher Blizzard.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1999
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Christopher Blizzard <blizzard@mozilla.org>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = gtkembedmoz
|
||||
LIBRARY_NAME = gtkembedmoz
|
||||
LIBXUL_LIBRARY = 1
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
||||
LOCAL_INCLUDES += \
|
||||
-I. \
|
||||
$(NULL)
|
||||
|
||||
#Temporary define for full migration from libxul
|
||||
#MOZ_GTKEMBED_DYN = 1
|
||||
|
||||
ifdef MOZ_GTKEMBED_DYN
|
||||
#DEFINES += -DFIXED_BUG347731
|
||||
FORCE_SHARED_LIB = 1
|
||||
ifdef MOZ_ENABLE_LIBXUL
|
||||
LIBXUL_LIBRARY =
|
||||
endif
|
||||
endif
|
||||
|
||||
DEFINES += -DIMPL_XREAPI
|
||||
|
||||
# New Stuff in GtkMozEmbed
|
||||
ifdef MOZ_MICROBEMBED
|
||||
DEFINES += -DBAD_CERT_LISTENER2
|
||||
#Probably scrolling can be fixed without this hack
|
||||
DEFINES += -DMOZ_SCROLL_TOP_LEFT_HACK
|
||||
|
||||
MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT = 1
|
||||
DEFINES += -DMOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
|
||||
MOZ_GTKPASSWORD_INTERFACE = 1
|
||||
DEFINES += -DMOZ_GTKPASSWORD_INTERFACE
|
||||
endif
|
||||
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
content \
|
||||
docshell \
|
||||
necko \
|
||||
widget \
|
||||
dom \
|
||||
gfx \
|
||||
intl \
|
||||
imglib2 \
|
||||
layout \
|
||||
locale \
|
||||
unicharutil \
|
||||
uriloader \
|
||||
webbrwsr \
|
||||
shistory \
|
||||
composer \
|
||||
editor \
|
||||
embed_base \
|
||||
windowwatcher \
|
||||
webshell \
|
||||
pipnss \
|
||||
history \
|
||||
pref \
|
||||
nspr \
|
||||
xulapp \
|
||||
exthandler \
|
||||
mimetype \
|
||||
chardet \
|
||||
find \
|
||||
webbrowserpersist \
|
||||
cookie \
|
||||
nkcache \
|
||||
pipboot \
|
||||
$(NULL)
|
||||
|
||||
ifdef ACCESSIBILITY
|
||||
REQUIRES += accessibility
|
||||
endif
|
||||
|
||||
CPPSRCS = \
|
||||
gtkmozembed2.cpp \
|
||||
EmbedPrivate.cpp \
|
||||
EmbedWindow.cpp \
|
||||
EmbedProgress.cpp \
|
||||
EmbedContentListener.cpp \
|
||||
EmbedEventListener.cpp \
|
||||
EmbedWindowCreator.cpp \
|
||||
EmbedGtkTools.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_ENABLE_GTK2
|
||||
CPPSRCS += \
|
||||
gtkmozembed_common.cpp \
|
||||
gtkmozembed_download.cpp \
|
||||
EmbedContextMenuInfo.cpp \
|
||||
EmbedCertificates.cpp \
|
||||
EmbedDownloadMgr.cpp \
|
||||
EmbedGlobalHistory.cpp \
|
||||
EmbedFilePicker.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_GTKPASSWORD_INTERFACE
|
||||
CPPSRCS += \
|
||||
EmbedPasswordMgr.cpp \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS += \
|
||||
nsIPassword.idl \
|
||||
nsIPasswordInternal.idl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
CSRCS = \
|
||||
gtkmozembedmarshal.c
|
||||
|
||||
CPPSRCS += \
|
||||
GtkPromptService.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
|
||||
CPPSRCS += \
|
||||
EmbedPrompter.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
EXPORTS = \
|
||||
gtkmozembed.h \
|
||||
gtkmozembed_glue.cpp \
|
||||
gtkmozembed_internal.h \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_ENABLE_GTK2
|
||||
EXPORTS += \
|
||||
gtkmozembed_common.h \
|
||||
gtkmozembed_download.h \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifdef MOZ_GTKEMBED_DYN
|
||||
ifneq (,$(filter gtk gtk2 qt xlib,$(MOZ_WIDGET_TOOLKIT)))
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
$(DIST)/lib/libxpcomglue_s.$(LIB_SUFFIX) \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
$(MOZ_GTK2_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
#Any Idea what can be used instead -lxul in FF configuration?
|
||||
ifndef MOZ_ENABLE_LIBXUL
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
-lxul \
|
||||
$(NULL)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifeq ($(OS_ARCH), SunOS)
|
||||
ifndef GNU_CC
|
||||
# When using Sun's WorkShop compiler, including
|
||||
# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h
|
||||
# causes most of these compiles to fail with:
|
||||
# line 29: Error: Multiple declaration for std::tm.
|
||||
# So, this gets around the problem.
|
||||
DEFINES += -D_TIME_H=1
|
||||
endif
|
||||
endif
|
||||
|
||||
CXXFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)
|
||||
CFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)
|
||||
ifdef MOZ_GNOMEVFS_CFLAGS
|
||||
CXXFLAGS += $(MOZ_GNOMEVFS_CFLAGS)
|
||||
CFLAGS += $(MOZ_GNOMEVFS_CFLAGS)
|
||||
endif
|
||||
DEFINES += -D_IMPL_GTKMOZEMBED
|
||||
|
||||
|
||||
MARSHAL_FILE = gtkmozembedmarshal
|
||||
MARSHAL_PREFIX = gtkmozembed
|
||||
|
||||
$(MARSHAL_FILE).h: $(MARSHAL_FILE).list
|
||||
glib-genmarshal --prefix=$(MARSHAL_PREFIX) $(srcdir)/$(MARSHAL_FILE).list --skip-source --header > $(MARSHAL_FILE).h
|
||||
|
||||
$(MARSHAL_FILE).c: $(MARSHAL_FILE).list $(MARSHAL_FILE).h
|
||||
glib-genmarshal --prefix=$(MARSHAL_PREFIX) $(srcdir)/$(MARSHAL_FILE).list --skip-source --body > $(MARSHAL_FILE).c
|
||||
|
||||
|
||||
@@ -1,396 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Ramiro Estrugo <ramiro@eazel.com>
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
* Antonio Gomes <tonikitoo@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef gtkmozembed_h
|
||||
#define gtkmozembed_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <stddef.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef MOZILLA_CLIENT
|
||||
#include "nscore.h"
|
||||
#else /* MOZILLA_CLIENT */
|
||||
#ifndef nscore_h__
|
||||
/* Because this header may be included from files which not part of the mozilla
|
||||
build system, define macros from nscore.h */
|
||||
|
||||
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
|
||||
#define NS_HIDDEN __attribute__((visibility("hidden")))
|
||||
#else
|
||||
#define NS_HIDDEN
|
||||
#endif
|
||||
|
||||
#define NS_FROZENCALL
|
||||
#define NS_EXPORT_(type) type
|
||||
#define NS_IMPORT_(type) type
|
||||
#endif /* nscore_h__ */
|
||||
#endif /* MOZILLA_CLIENT */
|
||||
|
||||
#ifdef XPCOM_GLUE
|
||||
|
||||
#define GTKMOZEMBED_API(type, name, params) \
|
||||
typedef type (NS_FROZENCALL * name##Type) params; \
|
||||
extern name##Type name NS_HIDDEN;
|
||||
|
||||
#else /* XPCOM_GLUE */
|
||||
|
||||
#ifdef _IMPL_GTKMOZEMBED
|
||||
#define GTKMOZEMBED_API(type, name, params) NS_EXPORT_(type) name params;
|
||||
#else
|
||||
#define GTKMOZEMBED_API(type,name, params) NS_IMPORT_(type) name params;
|
||||
#endif
|
||||
|
||||
#endif /* XPCOM_GLUE */
|
||||
|
||||
/** @struct GtkWebHistoryItem.
|
||||
* Defines a web history item.
|
||||
*/
|
||||
typedef struct _GtkMozHistoryItem GtkMozHistoryItem;
|
||||
struct _GtkMozHistoryItem
|
||||
{
|
||||
const gchar *title; /** < URL title */
|
||||
const gchar *url; /** < URL */
|
||||
long accessed; /** < The last time that the URL was accessed */
|
||||
};
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
#include "gtkmozembed_common.h"
|
||||
#endif
|
||||
|
||||
#define GTK_TYPE_MOZ_EMBED (gtk_moz_embed_get_type())
|
||||
#define GTK_MOZ_EMBED(obj) GTK_CHECK_CAST((obj), GTK_TYPE_MOZ_EMBED, GtkMozEmbed)
|
||||
#define GTK_MOZ_EMBED_CLASS(klass) GTK_CHECK_CLASS_CAST((klass), GTK_TYPE_MOZ_EMBED, GtkMozEmbedClass)
|
||||
#define GTK_IS_MOZ_EMBED(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_MOZ_EMBED)
|
||||
#define GTK_IS_MOZ_EMBED_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_MOZ_EMBED)
|
||||
|
||||
typedef struct _GtkMozEmbed GtkMozEmbed;
|
||||
typedef struct _GtkMozEmbedClass GtkMozEmbedClass;
|
||||
|
||||
struct _GtkMozEmbed
|
||||
{
|
||||
GtkBin bin;
|
||||
void *data;
|
||||
GtkObject *common;
|
||||
/* FIXME: This is a temporary solution for incorrect progress values
|
||||
* being passed up. Oleg has mentioned something about a bug in JS.
|
||||
*/
|
||||
gint current_number_of_requests;
|
||||
gint total_number_of_requests;
|
||||
gint number_of_frames_loaded;
|
||||
|
||||
};
|
||||
|
||||
struct _GtkMozEmbedClass
|
||||
{
|
||||
GtkBinClass parent_class;
|
||||
|
||||
void (* link_message) (GtkMozEmbed *embed);
|
||||
void (* js_status) (GtkMozEmbed *embed);
|
||||
void (* location) (GtkMozEmbed *embed);
|
||||
void (* title) (GtkMozEmbed *embed);
|
||||
void (* progress) (GtkMozEmbed *embed, gint curprogress,
|
||||
gint maxprogress);
|
||||
void (* progress_all) (GtkMozEmbed *embed, const gchar *aURI,
|
||||
gint curprogress, gint maxprogress);
|
||||
void (* net_state) (GtkMozEmbed *embed, gint state, guint status);
|
||||
void (* net_state_all) (GtkMozEmbed *embed, const gchar *aURI,
|
||||
gint state, guint status);
|
||||
void (* net_start) (GtkMozEmbed *embed);
|
||||
void (* net_stop) (GtkMozEmbed *embed);
|
||||
void (* new_window) (GtkMozEmbed *embed, GtkMozEmbed **newEmbed,
|
||||
guint chromemask);
|
||||
void (* visibility) (GtkMozEmbed *embed, gboolean visibility);
|
||||
void (* destroy_brsr) (GtkMozEmbed *embed);
|
||||
gint (* open_uri) (GtkMozEmbed *embed, const char *aURI);
|
||||
void (* size_to) (GtkMozEmbed *embed, gint width, gint height);
|
||||
gint (* dom_key_down) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_key_press) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_key_up) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_mouse_down) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_mouse_up) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_mouse_click) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_mouse_dbl_click) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_mouse_over) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_mouse_out) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
/* gint (* dom_mouse_move) (GtkMozEmbed *embed, gpointer dom_event); */
|
||||
gint (* dom_mouse_scroll) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_mouse_long_press)(GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_focus) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_blur) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
void (* security_change) (GtkMozEmbed *embed, gpointer request,
|
||||
guint state);
|
||||
void (* status_change) (GtkMozEmbed *embed, gpointer request,
|
||||
gint status, gpointer message);
|
||||
gint (* dom_activate) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_focus_in) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
gint (* dom_focus_out) (GtkMozEmbed *embed, gpointer dom_event);
|
||||
void (* alert) (GtkMozEmbed *embed, const char *title, const char *text);
|
||||
void (* alert_check) (GtkMozEmbed *embed, const char *title, const char *text,
|
||||
const char *check_msg, gboolean *check_val);
|
||||
gboolean (* confirm) (GtkMozEmbed *embed, const char *title, const char *text);
|
||||
gboolean (* confirm_check) (GtkMozEmbed *embed, const char *title, const char *text,
|
||||
const char *check_msg, gboolean *check_val);
|
||||
gint (* confirm_ex) (GtkMozEmbed *embed, const char *title, const char *text, guint bt_flags,
|
||||
const char *button1, const char *button2, const char *button3,
|
||||
const char *check_msg, gboolean *check_val);
|
||||
gboolean (* prompt) (GtkMozEmbed *embed, const char *title, const char *text,
|
||||
char **value, const char *check_msg, gboolean *check_val);
|
||||
gboolean (* prompt_auth) (GtkMozEmbed *embed, const char *title, const char *text,
|
||||
char **user, char **pass, const char *check_msg, gboolean *check_val);
|
||||
gboolean (* select) (GtkMozEmbed *embed, const char *title, const char *text,
|
||||
GList *list, gint *selected_item);
|
||||
void (* download_request)(GtkMozEmbed *, const char *, const char *, const char *, long, int, gpointer);
|
||||
gboolean (* upload_dialog) (GtkMozEmbed *, const char *, const char *, char **);
|
||||
void (* icon_changed) (GtkMozEmbed *, gpointer*);
|
||||
void (* mailto) (GtkMozEmbed *, gchar *);
|
||||
void (* network_error) (GtkMozEmbed *, gchar *, const gint, const gchar **);
|
||||
void (* rss_request) (GtkMozEmbed *, gchar *, gchar *);
|
||||
};
|
||||
|
||||
GTKMOZEMBED_API(GtkType, gtk_moz_embed_get_type, (void))
|
||||
GTKMOZEMBED_API(GtkWidget*, gtk_moz_embed_new, (void))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_push_startup, (void))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_pop_startup, (void))
|
||||
|
||||
/* Tell gtkmozembed where the gtkmozembed libs live. If this is not specified,
|
||||
The MOZILLA_FIVE_HOME environment variable is checked. */
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_set_path, (const char *aPath))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_set_comp_path, (const char *aPath))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_set_profile_path, (const char *aDir, const char *aName))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_load_url, (GtkMozEmbed *embed, const char *url))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_stop_load, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_can_go_back, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_can_go_forward, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_go_back, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_go_forward, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_render_data, (GtkMozEmbed *embed, const char *data, guint32 len,
|
||||
const char *base_uri, const char *mime_type))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_open_stream, (GtkMozEmbed *embed,
|
||||
const char *base_uri, const char *mime_type))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_append_data, (GtkMozEmbed *embed,
|
||||
const char *data, guint32 len))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_close_stream, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(gchar*, gtk_moz_embed_get_link_message, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(gchar*, gtk_moz_embed_get_js_status, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(gchar*, gtk_moz_embed_get_title, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(gchar*, gtk_moz_embed_get_location, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_reload, (GtkMozEmbed *embed, gint32 flags))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_set_chrome_mask, (GtkMozEmbed *embed, guint32 flags))
|
||||
GTKMOZEMBED_API(guint32, gtk_moz_embed_get_chrome_mask, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_get_zoom_level, (GtkMozEmbed *embed, gint*, gpointer))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_set_zoom_level, (GtkMozEmbed *embed, gint, gpointer))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_find_text, (GtkMozEmbed *embed, const gchar*, gboolean, gboolean, gboolean, gboolean, gint))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_clipboard, (GtkMozEmbed *embed, guint, gint))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_notify_plugins, (GtkMozEmbed *embed, guint))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_check_logins, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(char*, gtk_moz_embed_get_encoding, (GtkMozEmbed *embed, gint))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_set_encoding, (GtkMozEmbed *embed, const gchar *, gint))
|
||||
GTKMOZEMBED_API(guint, gtk_moz_embed_get_context_info, (GtkMozEmbed *embed, gpointer event, gpointer *node,
|
||||
gint *x, gint *y, gint *docindex,
|
||||
const gchar **url, const gchar **objurl, const gchar **docurl))
|
||||
GTKMOZEMBED_API(const gchar*, gtk_moz_embed_get_selection, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_get_doc_info, (GtkMozEmbed *embed, gpointer node, gint docindex, const gchar**title,
|
||||
const gchar**location, const gchar **file_type, guint *file_size,
|
||||
gint *width, gint *height))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_insert_text, (GtkMozEmbed *embed, const gchar*, gpointer node))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_save_target, (GtkMozEmbed *embed, gchar*, gchar*, gint))
|
||||
GTKMOZEMBED_API(gint, gtk_moz_embed_get_shistory_list, (GtkMozEmbed *embed, GtkMozHistoryItem **GtkHI, guint type))
|
||||
GTKMOZEMBED_API(gint, gtk_moz_embed_get_shistory_index, (GtkMozEmbed *embed))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_shistory_goto_index, (GtkMozEmbed *embed, gint index))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_get_server_cert, (GtkMozEmbed *embed, gpointer *aCert, gpointer))
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_BACK_SHISTORY,
|
||||
GTK_MOZ_EMBED_FORWARD_SHISTORY
|
||||
} GtkMozEmbedSessionHistory;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_SELECT_ALL,
|
||||
GTK_MOZ_EMBED_CAN_SELECT,
|
||||
GTK_MOZ_EMBED_CUT,
|
||||
GTK_MOZ_EMBED_COPY,
|
||||
GTK_MOZ_EMBED_PASTE,
|
||||
GTK_MOZ_EMBED_CAN_CUT,
|
||||
GTK_MOZ_EMBED_CAN_PASTE,
|
||||
GTK_MOZ_EMBED_CAN_COPY
|
||||
} GtkMozEmbedClipboard;
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_CTX_NONE = 0,
|
||||
GTK_MOZ_EMBED_CTX_XUL = 1 << 1,
|
||||
GTK_MOZ_EMBED_CTX_SIDEBAR = 1 << 2,
|
||||
GTK_MOZ_EMBED_CTX_DOCUMENT = 1 << 3,
|
||||
GTK_MOZ_EMBED_CTX_LINK = 1 << 4,
|
||||
GTK_MOZ_EMBED_CTX_IMAGE = 1 << 5,
|
||||
GTK_MOZ_EMBED_CTX_IFRAME = 1 << 6,
|
||||
GTK_MOZ_EMBED_CTX_INPUT = 1 << 7,
|
||||
GTK_MOZ_EMBED_CTX_IPASSWORD = 1 << 8,
|
||||
GTK_MOZ_EMBED_CTX_EMAIL = 1 << 9,
|
||||
GTK_MOZ_EMBED_CTX_RICHEDIT = 1 << 10,
|
||||
GTK_MOZ_EMBED_CTX_ROINPUT = 1 << 11
|
||||
} GtkMozEmbedContext;
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_DIALOG_BUTTON_OK,
|
||||
GTK_MOZ_EMBED_DIALOG_BUTTON_CANCEL,
|
||||
GTK_MOZ_EMBED_DIALOG_BUTTON_YES,
|
||||
GTK_MOZ_EMBED_DIALOG_BUTTON_NO,
|
||||
GTK_MOZ_EMBED_DIALOG_BUTTON_SAVE,
|
||||
GTK_MOZ_EMBED_DIALOG_BUTTON_DONT_SAVE,
|
||||
GTK_MOZ_EMBED_DIALOG_BUTTON_REVERT,
|
||||
GTK_MOZ_EMBED_DIALOG_BUTTON_STRING
|
||||
} GtkMozEmbedDialogButtons;
|
||||
/* These are straight out of nsIWebProgressListener.h */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_FLAG_START = 1,
|
||||
GTK_MOZ_EMBED_FLAG_REDIRECTING = 2,
|
||||
GTK_MOZ_EMBED_FLAG_TRANSFERRING = 4,
|
||||
GTK_MOZ_EMBED_FLAG_NEGOTIATING = 8,
|
||||
GTK_MOZ_EMBED_FLAG_STOP = 16,
|
||||
|
||||
GTK_MOZ_EMBED_FLAG_IS_REQUEST = 65536,
|
||||
GTK_MOZ_EMBED_FLAG_IS_DOCUMENT = 131072,
|
||||
GTK_MOZ_EMBED_FLAG_IS_NETWORK = 262144,
|
||||
GTK_MOZ_EMBED_FLAG_IS_WINDOW = 524288,
|
||||
|
||||
GTK_MOZ_EMBED_FLAG_RESTORING = 16777216
|
||||
} GtkMozEmbedProgressFlags;
|
||||
|
||||
/* These are from various networking headers */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* NS_ERROR_UNKNOWN_HOST */
|
||||
GTK_MOZ_EMBED_STATUS_FAILED_DNS = 2152398878U,
|
||||
/* NS_ERROR_CONNECTION_REFUSED */
|
||||
GTK_MOZ_EMBED_STATUS_FAILED_CONNECT = 2152398861U,
|
||||
/* NS_ERROR_NET_TIMEOUT */
|
||||
GTK_MOZ_EMBED_STATUS_FAILED_TIMEOUT = 2152398862U,
|
||||
/* NS_BINDING_ABORTED */
|
||||
GTK_MOZ_EMBED_STATUS_FAILED_USERCANCELED = 2152398850U,
|
||||
/* NS_ERROR_PROXY_CONNECTION_REFUSED */
|
||||
GTK_MOZ_EMBED_STATUS_PROXY_FAILED = 2152398920U
|
||||
} GtkMozEmbedStatusFlags;
|
||||
|
||||
/* These used to be straight out of nsIWebNavigation.h until the API
|
||||
changed. Now there's a mapping table that maps these values to the
|
||||
internal values. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_FLAG_RELOADNORMAL = 0,
|
||||
GTK_MOZ_EMBED_FLAG_RELOADBYPASSCACHE = 1,
|
||||
GTK_MOZ_EMBED_FLAG_RELOADBYPASSPROXY = 2,
|
||||
GTK_MOZ_EMBED_FLAG_RELOADBYPASSPROXYANDCACHE = 3,
|
||||
GTK_MOZ_EMBED_FLAG_RELOADCHARSETCHANGE = 4
|
||||
} GtkMozEmbedReloadFlags;
|
||||
|
||||
/* These are straight out of nsIWebBrowserChrome.h */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_FLAG_DEFAULTCHROME = 1U,
|
||||
GTK_MOZ_EMBED_FLAG_WINDOWBORDERSON = 2U,
|
||||
GTK_MOZ_EMBED_FLAG_WINDOWCLOSEON = 4U,
|
||||
GTK_MOZ_EMBED_FLAG_WINDOWRESIZEON = 8U,
|
||||
GTK_MOZ_EMBED_FLAG_MENUBARON = 16U,
|
||||
GTK_MOZ_EMBED_FLAG_TOOLBARON = 32U,
|
||||
GTK_MOZ_EMBED_FLAG_LOCATIONBARON = 64U,
|
||||
GTK_MOZ_EMBED_FLAG_STATUSBARON = 128U,
|
||||
GTK_MOZ_EMBED_FLAG_PERSONALTOOLBARON = 256U,
|
||||
GTK_MOZ_EMBED_FLAG_SCROLLBARSON = 512U,
|
||||
GTK_MOZ_EMBED_FLAG_TITLEBARON = 1024U,
|
||||
GTK_MOZ_EMBED_FLAG_EXTRACHROMEON = 2048U,
|
||||
GTK_MOZ_EMBED_FLAG_ALLCHROME = 4094U,
|
||||
GTK_MOZ_EMBED_FLAG_WINDOWRAISED = 33554432U,
|
||||
GTK_MOZ_EMBED_FLAG_WINDOWLOWERED = 67108864U,
|
||||
GTK_MOZ_EMBED_FLAG_CENTERSCREEN = 134217728U,
|
||||
GTK_MOZ_EMBED_FLAG_DEPENDENT = 268435456U,
|
||||
GTK_MOZ_EMBED_FLAG_MODAL = 536870912U,
|
||||
GTK_MOZ_EMBED_FLAG_OPENASDIALOG = 1073741824U,
|
||||
GTK_MOZ_EMBED_FLAG_OPENASCHROME = 2147483648U
|
||||
} GtkMozEmbedChromeFlags;
|
||||
|
||||
/* this is a singleton object that you can hook up to to get signals
|
||||
that are not handed out on a per widget basis. */
|
||||
|
||||
#define GTK_TYPE_MOZ_EMBED_SINGLE (gtk_moz_embed_single_get_type())
|
||||
#define GTK_MOZ_EMBED_SINGLE(obj) GTK_CHECK_CAST((obj), GTK_TYPE_MOZ_EMBED_SINGLE, GtkMozEmbedSingle)
|
||||
#define GTK_MOZ_EMBED_SINGLE_CLASS(klass) GTK_CHEK_CLASS_CAST((klass), GTK_TYPE_MOZ_EMBED_SINGLE, GtkMozEmbedSingleClass)
|
||||
#define GTK_IS_MOZ_EMBED_SINGLE(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_MOZ_EMBED_SINGLE)
|
||||
#define GTK_IS_MOZ_EMBED_SINGLE_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_MOZ_EMBED)
|
||||
|
||||
typedef struct _GtkMozEmbedSingle GtkMozEmbedSingle;
|
||||
typedef struct _GtkMozEmbedSingleClass GtkMozEmbedSingleClass;
|
||||
|
||||
struct _GtkMozEmbedSingle
|
||||
{
|
||||
GtkObject object;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct _GtkMozEmbedSingleClass
|
||||
{
|
||||
GtkObjectClass parent_class;
|
||||
|
||||
void (* new_window_orphan) (GtkMozEmbedSingle *embed,
|
||||
GtkMozEmbed **newEmbed,
|
||||
guint chromemask);
|
||||
};
|
||||
|
||||
GTKMOZEMBED_API(GtkType, gtk_moz_embed_single_get_type, (void))
|
||||
GTKMOZEMBED_API(GtkMozEmbedSingle *, gtk_moz_embed_single_get, (void))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* gtkmozembed_h */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,752 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard.
|
||||
* Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Ramiro Estrugo <ramiro@eazel.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "gtkmozembed.h"
|
||||
#include "gtkmozembed_common.h"
|
||||
#include "gtkmozembedprivate.h"
|
||||
#include "gtkmozembed_internal.h"
|
||||
#include "EmbedPrivate.h"
|
||||
#include "EmbedWindow.h"
|
||||
|
||||
#ifdef MOZ_GTKPASSWORD_INTERFACE
|
||||
#include "EmbedPasswordMgr.h"
|
||||
#include "nsIPassword.h"
|
||||
#endif
|
||||
|
||||
#include "EmbedGlobalHistory.h"
|
||||
//#include "EmbedDownloadMgr.h"
|
||||
// so we can do our get_nsIWebBrowser later...
|
||||
#include "nsIWebBrowser.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsICookieManager.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsICookie.h"
|
||||
#include "nsIX509Cert.h"
|
||||
// for strings
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsString.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#endif
|
||||
// for plugins
|
||||
#include "nsIDOMNavigator.h"
|
||||
#include "nsIDOMPluginArray.h"
|
||||
#include "nsIDOMPlugin.h"
|
||||
#include <plugin/nsIPluginHost.h>
|
||||
#include "nsIDOMMimeType.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
||||
//for security
|
||||
#include "nsIWebProgressListener.h"
|
||||
|
||||
//for cache
|
||||
#include "nsICacheService.h"
|
||||
#include "nsICache.h"
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
#include "gtkmozembedmarshal.h"
|
||||
#define NEW_TOOLKIT_STRING(x) g_strdup(NS_ConvertUTF16toUTF8(x).get())
|
||||
#define GET_TOOLKIT_STRING(x) NS_ConvertUTF16toUTF8(x).get()
|
||||
#define GET_OBJECT_CLASS_TYPE(x) G_OBJECT_CLASS_TYPE(x)
|
||||
#endif /* MOZ_WIDGET_GTK2 */
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
// so we can get callbacks from the mozarea
|
||||
#include <gtkmozarea.h>
|
||||
// so we get the right marshaler for gtk 1.2
|
||||
#define gtkmozembed_VOID__INT_UINT \
|
||||
gtk_marshal_NONE__INT_INT
|
||||
#define gtkmozembed_VOID__STRING_INT_INT \
|
||||
gtk_marshal_NONE__POINTER_INT_INT
|
||||
#define gtkmozembed_VOID__STRING_INT_UINT \
|
||||
gtk_marshal_NONE__POINTER_INT_INT
|
||||
#define gtkmozembed_VOID__POINTER_INT_POINTER \
|
||||
gtk_marshal_NONE__POINTER_INT_POINTER
|
||||
#define gtkmozembed_BOOL__STRING \
|
||||
gtk_marshal_BOOL__POINTER
|
||||
#define gtkmozembed_VOID__INT_INT_BOOLEAN \
|
||||
gtk_marshal_NONE__INT_INT_BOOLEAN
|
||||
|
||||
#define G_SIGNAL_TYPE_STATIC_SCOPE 0
|
||||
#define NEW_TOOLKIT_STRING(x) g_strdup(NS_LossyConvertUTF16toASCII(x).get())
|
||||
#define GET_TOOLKIT_STRING(x) NS_LossyConvertUTF16toASCII(x).get()
|
||||
#define GET_OBJECT_CLASS_TYPE(x) (GTK_OBJECT_CLASS(x)->type)
|
||||
#endif /* MOZ_WIDGET_GTK */
|
||||
|
||||
#define UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(newed) PR_BEGIN_MACRO \
|
||||
/* OOPS this code is using a glib allocation function which \
|
||||
* will cause the application to crash when it runs out of \
|
||||
* memory. This is not cool. either g_try methods should be \
|
||||
* used or malloc, or new (note that gecko /will/ be replacing \
|
||||
* its operator new such that new will not throw exceptions). \
|
||||
* XXX please fix me. \
|
||||
*/ \
|
||||
if (!newed) { \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#define ALLOC_NOT_CHECKED(newed) PR_BEGIN_MACRO \
|
||||
/* This might not crash, but the code probably isn't really \
|
||||
* designed to handle it, perhaps the code should be fixed? \
|
||||
*/ \
|
||||
if (!newed) { \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
// CID used to get the plugin manager
|
||||
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
|
||||
|
||||
// class and instance initialization
|
||||
|
||||
static void
|
||||
gtk_moz_embed_common_class_init(GtkMozEmbedCommonClass *klass);
|
||||
|
||||
static void
|
||||
gtk_moz_embed_common_init(GtkMozEmbedCommon *embed);
|
||||
|
||||
static GtkObjectClass *common_parent_class = NULL;
|
||||
|
||||
// GtkObject methods
|
||||
|
||||
static void
|
||||
gtk_moz_embed_common_destroy(GtkObject *object);
|
||||
|
||||
guint moz_embed_common_signals[COMMON_LAST_SIGNAL] = { 0 };
|
||||
|
||||
// GtkObject + class-related functions
|
||||
GtkType
|
||||
gtk_moz_embed_common_get_type(void)
|
||||
{
|
||||
static GtkType moz_embed_common_type = 0;
|
||||
if (!moz_embed_common_type)
|
||||
{
|
||||
static const GtkTypeInfo moz_embed_common_info =
|
||||
{
|
||||
"GtkMozEmbedCommon",
|
||||
sizeof(GtkMozEmbedCommon),
|
||||
sizeof(GtkMozEmbedCommonClass),
|
||||
(GtkClassInitFunc)gtk_moz_embed_common_class_init,
|
||||
(GtkObjectInitFunc)gtk_moz_embed_common_init,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
moz_embed_common_type = gtk_type_unique(GTK_TYPE_BIN, &moz_embed_common_info);
|
||||
}
|
||||
return moz_embed_common_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_moz_embed_common_class_init(GtkMozEmbedCommonClass *klass)
|
||||
{
|
||||
GtkObjectClass *object_class;
|
||||
object_class = GTK_OBJECT_CLASS(klass);
|
||||
common_parent_class = (GtkObjectClass *)gtk_type_class(gtk_object_get_type());
|
||||
object_class->destroy = gtk_moz_embed_common_destroy;
|
||||
moz_embed_common_signals[COMMON_CERT_ERROR] =
|
||||
gtk_signal_new("certificate-error",
|
||||
GTK_RUN_LAST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
|
||||
certificate_error),
|
||||
gtkmozembed_BOOL__POINTER_UINT,
|
||||
G_TYPE_BOOLEAN,
|
||||
2,
|
||||
GTK_TYPE_POINTER,
|
||||
GTK_TYPE_UINT);
|
||||
moz_embed_common_signals[COMMON_SELECT_LOGIN] =
|
||||
gtk_signal_new("select-login",
|
||||
GTK_RUN_LAST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
|
||||
select_login),
|
||||
gtk_marshal_INT__POINTER,
|
||||
G_TYPE_INT,
|
||||
1,
|
||||
G_TYPE_POINTER);
|
||||
moz_embed_common_signals[COMMON_REMEMBER_LOGIN] =
|
||||
gtk_signal_new("remember-login",
|
||||
GTK_RUN_LAST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
|
||||
remember_login),
|
||||
gtkmozembed_INT__VOID,
|
||||
G_TYPE_INT, 0);
|
||||
// set up our signals
|
||||
moz_embed_common_signals[COMMON_ASK_COOKIE] =
|
||||
gtk_signal_new("ask-cookie",
|
||||
GTK_RUN_FIRST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass, ask_cookie),
|
||||
gtkmozembed_VOID__POINTER_INT_STRING_STRING_STRING_STRING_STRING_BOOLEAN_INT,
|
||||
G_TYPE_NONE, 9,
|
||||
GTK_TYPE_POINTER,
|
||||
GTK_TYPE_INT,
|
||||
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
GTK_TYPE_BOOL,
|
||||
GTK_TYPE_INT);
|
||||
/*
|
||||
moz_embed_common_signals[COMMON_CERT_DIALOG] =
|
||||
gtk_signal_new("certificate-dialog",
|
||||
GTK_RUN_LAST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
|
||||
certificate_dialog),
|
||||
gtk_marshal_BOOL__POINTER,
|
||||
G_TYPE_BOOLEAN, 1, GTK_TYPE_POINTER);
|
||||
moz_embed_common_signals[COMMON_CERT_PASSWD_DIALOG] =
|
||||
gtk_signal_new("certificate-password-dialog",
|
||||
GTK_RUN_FIRST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
|
||||
certificate_password_dialog),
|
||||
gtkmozembed_VOID__STRING_STRING_POINTER,
|
||||
G_TYPE_NONE,
|
||||
3,
|
||||
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
GTK_TYPE_POINTER);
|
||||
moz_embed_common_signals[COMMON_CERT_DETAILS_DIALOG] =
|
||||
gtk_signal_new("certificate-details",
|
||||
GTK_RUN_FIRST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
|
||||
certificate_details),
|
||||
gtk_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
GTK_TYPE_POINTER);
|
||||
moz_embed_common_signals[COMMON_HISTORY_ADDED] =
|
||||
gtk_signal_new("global-history-item-added",
|
||||
GTK_RUN_FIRST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
|
||||
history_added),
|
||||
gtk_marshal_VOID__STRING,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
|
||||
moz_embed_common_signals[COMMON_ON_SUBMIT_SIGNAL] =
|
||||
gtk_signal_new("on-submit",
|
||||
GTK_RUN_LAST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
|
||||
on_submit),
|
||||
gtkmozembed_INT__VOID,
|
||||
G_TYPE_INT, 0);
|
||||
moz_embed_common_signals[COMMON_MODAL_DIALOG] =
|
||||
gtk_signal_new("modal_dialog",
|
||||
GTK_RUN_LAST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
|
||||
modal_dialog),
|
||||
gtkmozembed_INT__STRING_STRING_INT_INT_INT_INT,
|
||||
G_TYPE_INT,
|
||||
6,
|
||||
G_TYPE_STRING, G_TYPE_STRING,
|
||||
G_TYPE_INT, G_TYPE_INT,
|
||||
G_TYPE_INT, G_TYPE_INT);
|
||||
*/
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
gtk_object_class_add_signals(object_class, moz_embed_common_signals,
|
||||
COMMON_LAST_SIGNAL);
|
||||
#endif /* MOZ_WIDGET_GTK */
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_moz_embed_common_init(GtkMozEmbedCommon *common)
|
||||
{
|
||||
// this is a placeholder for later in case we need to stash data at
|
||||
// a later data and maintain backwards compatibility.
|
||||
common->data = nsnull;
|
||||
EmbedCommon *priv = EmbedCommon::GetInstance();
|
||||
priv->mCommon = GTK_OBJECT(common);
|
||||
common->data = priv;
|
||||
EmbedGlobalHistory::GetInstance();
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_moz_embed_common_destroy(GtkObject *object)
|
||||
{
|
||||
g_return_if_fail(object != NULL);
|
||||
g_return_if_fail(GTK_IS_MOZ_EMBED_COMMON(object));
|
||||
GtkMozEmbedCommon *embed = nsnull;
|
||||
EmbedCommon *commonPrivate = nsnull;
|
||||
embed = GTK_MOZ_EMBED_COMMON(object);
|
||||
commonPrivate = (EmbedCommon *)embed->data;
|
||||
if (commonPrivate) {
|
||||
delete commonPrivate;
|
||||
embed->data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gtk_moz_embed_common_new(void)
|
||||
{
|
||||
GtkWidget *widget = (GtkWidget*) gtk_type_new(gtk_moz_embed_common_get_type());
|
||||
gtk_widget_set_name(widget, "gtkmozembedcommon");
|
||||
return (GtkWidget *) widget;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_moz_embed_common_set_pref(GtkType type, gchar *name, gpointer value)
|
||||
{
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
||||
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
|
||||
|
||||
if (pref) {
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
switch (type) {
|
||||
case GTK_TYPE_BOOL:
|
||||
{
|
||||
/* I doubt this cast pair is correct */
|
||||
rv = pref->SetBoolPref(name, !!*(int*)value);
|
||||
break;
|
||||
}
|
||||
case GTK_TYPE_INT:
|
||||
{
|
||||
/* I doubt this cast pair is correct */
|
||||
rv = pref->SetIntPref(name, *(int*)value);
|
||||
break;
|
||||
}
|
||||
case GTK_TYPE_STRING:
|
||||
{
|
||||
g_return_val_if_fail (value, FALSE);
|
||||
rv = pref->SetCharPref(name, (gchar*)value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_moz_embed_common_get_pref(GtkType type, gchar *name, gpointer value)
|
||||
{
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
||||
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (pref){
|
||||
switch (type) {
|
||||
case GTK_TYPE_BOOL:
|
||||
{
|
||||
rv = pref->GetBoolPref(name, (gboolean*)value);
|
||||
break;
|
||||
}
|
||||
case GTK_TYPE_INT:
|
||||
{
|
||||
rv = pref->GetIntPref(name, (gint*)value);
|
||||
break;
|
||||
}
|
||||
case GTK_TYPE_STRING:
|
||||
{
|
||||
rv = pref->GetCharPref(name, (gchar**)value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_moz_embed_common_save_prefs()
|
||||
{
|
||||
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREF_CONTRACTID);
|
||||
g_return_val_if_fail (prefService != nsnull, FALSE);
|
||||
if (prefService == nsnull)
|
||||
return FALSE;
|
||||
nsresult rv = prefService->SavePrefFile (nsnull);
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
gint
|
||||
gtk_moz_embed_common_get_logins(const char* uri, GList **list)
|
||||
{
|
||||
gint ret = 0;
|
||||
#ifdef MOZ_GTKPASSWORD_INTERFACE
|
||||
EmbedPasswordMgr *passwordManager = EmbedPasswordMgr::GetInstance();
|
||||
nsCOMPtr<nsISimpleEnumerator> passwordEnumerator;
|
||||
nsresult result = passwordManager->GetEnumerator(getter_AddRefs(passwordEnumerator));
|
||||
PRBool enumResult;
|
||||
for (passwordEnumerator->HasMoreElements(&enumResult) ;
|
||||
enumResult == PR_TRUE ;
|
||||
passwordEnumerator->HasMoreElements(&enumResult))
|
||||
{
|
||||
nsCOMPtr<nsIPassword> nsPassword;
|
||||
result = passwordEnumerator->GetNext(getter_AddRefs(nsPassword));
|
||||
if (NS_FAILED(result)) {
|
||||
/* this almost certainly leaks logins */
|
||||
return ret;
|
||||
}
|
||||
nsCString host;
|
||||
nsPassword->GetHost(host);
|
||||
nsCString nsCURI(uri);
|
||||
if (uri) {
|
||||
if (!StringBeginsWith(nsCURI, host)
|
||||
// && !StringBeginsWith(host, nsCURI)
|
||||
)
|
||||
continue;
|
||||
} else if (!passwordManager->IsEqualToLastHostQuery(host))
|
||||
continue;
|
||||
|
||||
if (list) {
|
||||
nsString unicodeName;
|
||||
nsString unicodePassword;
|
||||
nsPassword->GetUser(unicodeName);
|
||||
nsPassword->GetPassword(unicodePassword);
|
||||
GtkMozLogin * login = g_new0(GtkMozLogin, 1);
|
||||
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(login);
|
||||
login->user = ToNewUTF8String(unicodeName);
|
||||
ALLOC_NOT_CHECKED(login->user);
|
||||
login->pass = ToNewUTF8String(unicodePassword);
|
||||
ALLOC_NOT_CHECKED(login->pass);
|
||||
login->host = NS_strdup(host.get());
|
||||
ALLOC_NOT_CHECKED(login->host);
|
||||
login->index = ret;
|
||||
*list = g_list_append(*list, login);
|
||||
}
|
||||
ret++;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_moz_embed_common_remove_passwords(const gchar *host, const gchar *user, gint index)
|
||||
{
|
||||
#ifdef MOZ_GTKPASSWORD_INTERFACE
|
||||
EmbedPasswordMgr *passwordManager = EmbedPasswordMgr::GetInstance();
|
||||
if (index >= 0) {
|
||||
passwordManager->RemovePasswordsByIndex(index);
|
||||
} else {
|
||||
passwordManager->RemovePasswords(host, user);
|
||||
}
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
gtk_moz_embed_common_get_history_list(GtkMozHistoryItem **GtkHI)
|
||||
{
|
||||
gint count = 0;
|
||||
EmbedGlobalHistory *history = EmbedGlobalHistory::GetInstance();
|
||||
history->GetContentList(GtkHI, &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
gint
|
||||
gtk_moz_embed_common_remove_history(gchar *url, gint time) {
|
||||
nsresult rv;
|
||||
// The global history service
|
||||
nsCOMPtr<nsIGlobalHistory2> globalHistory(do_GetService("@mozilla.org/browser/global-history;2"));
|
||||
if (!globalHistory) return NS_ERROR_NULL_POINTER;
|
||||
// The browser history interface
|
||||
nsCOMPtr<nsIObserver> myHistory = do_QueryInterface(globalHistory, &rv);
|
||||
if (!myHistory) return NS_ERROR_NULL_POINTER ;
|
||||
if (!url)
|
||||
myHistory->Observe(nsnull, "RemoveEntries", nsnull);
|
||||
else {
|
||||
EmbedGlobalHistory *history = EmbedGlobalHistory::GetInstance();
|
||||
PRUnichar *uniurl = ToNewUnicode(NS_ConvertUTF8toUTF16(url));
|
||||
rv = history->RemoveEntries(uniurl, time);
|
||||
NS_Free(uniurl);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
GSList*
|
||||
gtk_moz_embed_common_get_cookie_list(void)
|
||||
{
|
||||
GSList *cookies = NULL;
|
||||
nsresult result;
|
||||
nsCOMPtr<nsICookieManager> cookieManager =
|
||||
do_GetService(NS_COOKIEMANAGER_CONTRACTID);
|
||||
nsCOMPtr<nsISimpleEnumerator> cookieEnumerator;
|
||||
result = cookieManager->GetEnumerator(getter_AddRefs(cookieEnumerator));
|
||||
g_return_val_if_fail(NS_SUCCEEDED(result), NULL);
|
||||
PRBool enumResult;
|
||||
for (cookieEnumerator->HasMoreElements(&enumResult);
|
||||
enumResult == PR_TRUE;
|
||||
cookieEnumerator->HasMoreElements(&enumResult))
|
||||
{
|
||||
GtkMozCookieList *c;
|
||||
nsCOMPtr<nsICookie> nsCookie;
|
||||
result = cookieEnumerator->GetNext(getter_AddRefs(nsCookie));
|
||||
g_return_val_if_fail(NS_SUCCEEDED(result), NULL);
|
||||
c = g_new0(GtkMozCookieList, 1);
|
||||
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(c);
|
||||
nsCAutoString transfer;
|
||||
nsCookie->GetHost(transfer);
|
||||
c->domain = g_strdup(transfer.get());
|
||||
nsCookie->GetName(transfer);
|
||||
c->name = g_strdup(transfer.get());
|
||||
nsCookie->GetValue(transfer);
|
||||
c->value = g_strdup(transfer.get());
|
||||
nsCookie->GetPath(transfer);
|
||||
/* this almost certainly leaks g_strconcat */
|
||||
if (strchr(c->domain,'.'))
|
||||
c->path = g_strdup(g_strconcat("http://*",c->domain,"/",NULL));
|
||||
else
|
||||
c->path = g_strdup(g_strconcat("http://",c->domain,"/",NULL));
|
||||
cookies = g_slist_prepend(cookies, c);
|
||||
}
|
||||
cookies = g_slist_reverse(cookies);
|
||||
return cookies;
|
||||
}
|
||||
|
||||
gint
|
||||
gtk_moz_embed_common_delete_all_cookies(GSList *deletedCookies)
|
||||
{
|
||||
nsCOMPtr<nsIPermissionManager> permissionManager =
|
||||
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
||||
|
||||
if (!permissionManager)
|
||||
return 1;
|
||||
|
||||
permissionManager->RemoveAll();
|
||||
|
||||
if (!deletedCookies)
|
||||
return 1;
|
||||
|
||||
nsCOMPtr<nsICookieManager> cookieManager =
|
||||
do_GetService(NS_COOKIEMANAGER_CONTRACTID);
|
||||
|
||||
if (!cookieManager)
|
||||
return 1;
|
||||
cookieManager->RemoveAll();
|
||||
|
||||
g_slist_free(deletedCookies);
|
||||
return 0;//False in GWebStatus means OK, as opposed to gboolean in C
|
||||
}
|
||||
|
||||
unsigned char *
|
||||
gtk_moz_embed_common_nsx509_to_raw(void *nsIX509Ptr, guint *len)
|
||||
{
|
||||
if (!nsIX509Ptr)
|
||||
return NULL;
|
||||
unsigned char *data;
|
||||
((nsIX509Cert*)nsIX509Ptr)->GetRawDER(len, (PRUint8 **)&data);
|
||||
if (!data)
|
||||
return NULL;
|
||||
return data;
|
||||
}
|
||||
|
||||
gint
|
||||
gtk_moz_embed_common_get_plugins_list(GList **pluginArray)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPluginManager> pluginMan =
|
||||
do_GetService(kPluginManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
g_print("Could not get the plugin manager\n");
|
||||
return -1;
|
||||
}
|
||||
pluginMan->ReloadPlugins(PR_TRUE); //FIXME XXX MEMLEAK
|
||||
|
||||
nsCOMPtr<nsIPluginHost> pluginHost =
|
||||
do_GetService(kPluginManagerCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
PRUint32 aLength;
|
||||
pluginHost->GetPluginCount(&aLength);
|
||||
|
||||
if (!pluginArray)
|
||||
return (gint)aLength;
|
||||
|
||||
nsIDOMPlugin **aItems = nsnull;
|
||||
aItems = new nsIDOMPlugin*[aLength];
|
||||
if (!aItems)
|
||||
return -1; //NO MEMORY
|
||||
|
||||
rv = pluginHost->GetPlugins(aLength, aItems);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete [] aItems;
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsString string;
|
||||
for (int plugin_index = 0; plugin_index < (gint) aLength; plugin_index++)
|
||||
{
|
||||
GtkMozPlugin *list_item = g_new0(GtkMozPlugin, 1);
|
||||
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(list_item);
|
||||
|
||||
rv = aItems[plugin_index]->GetName(string);
|
||||
if (!NS_FAILED(rv))
|
||||
list_item->title = g_strdup(NS_ConvertUTF16toUTF8(string).get());
|
||||
|
||||
aItems[plugin_index]->GetFilename(string);
|
||||
if (!NS_FAILED(rv))
|
||||
list_item->path = g_strdup(NS_ConvertUTF16toUTF8(string).get());
|
||||
|
||||
nsCOMPtr<nsIDOMMimeType> mimeType;
|
||||
PRUint32 mime_count = 0;
|
||||
rv = aItems[plugin_index]->GetLength(&mime_count);
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
nsString single_mime;
|
||||
string.SetLength(0);
|
||||
for (int mime_index = 0; mime_index < mime_count; ++mime_index) {
|
||||
rv = aItems[plugin_index]->Item(mime_index, getter_AddRefs(mimeType));
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
rv = mimeType->GetDescription(single_mime);
|
||||
if (!NS_FAILED(rv)) {
|
||||
string.Append(single_mime);
|
||||
string.AppendLiteral(";");
|
||||
}
|
||||
}
|
||||
|
||||
list_item->type = g_strdup(NS_ConvertUTF16toUTF8(string).get());
|
||||
if (!NS_FAILED(rv))
|
||||
*pluginArray = g_list_append(*pluginArray, list_item);
|
||||
}
|
||||
delete [] aItems;
|
||||
return (gint)aLength;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_moz_embed_common_reload_plugins()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPluginManager> pluginMan =
|
||||
do_GetService(kPluginManagerCID, &rv);
|
||||
pluginMan->ReloadPlugins(PR_TRUE); //FIXME XXX MEMLEAK
|
||||
}
|
||||
|
||||
guint
|
||||
gtk_moz_embed_common_get_security_mode(guint sec_state)
|
||||
{
|
||||
GtkMozEmbedSecurityMode sec_mode;
|
||||
|
||||
switch (sec_state) {
|
||||
case nsIWebProgressListener::STATE_IS_INSECURE:
|
||||
sec_mode = GTK_MOZ_EMBED_NO_SECURITY;
|
||||
//g_print("GTK_MOZ_EMBED_NO_SECURITY\n");
|
||||
break;
|
||||
case nsIWebProgressListener::STATE_IS_BROKEN:
|
||||
sec_mode = GTK_MOZ_EMBED_NO_SECURITY;
|
||||
//g_print("GTK_MOZ_EMBED_NO_SECURITY\n");
|
||||
break;
|
||||
case nsIWebProgressListener::STATE_IS_SECURE|
|
||||
nsIWebProgressListener::STATE_SECURE_HIGH:
|
||||
sec_mode = GTK_MOZ_EMBED_HIGH_SECURITY;
|
||||
//g_print("GTK_MOZ_EMBED_HIGH_SECURITY");
|
||||
break;
|
||||
case nsIWebProgressListener::STATE_IS_SECURE|
|
||||
nsIWebProgressListener::STATE_SECURE_MED:
|
||||
sec_mode = GTK_MOZ_EMBED_MEDIUM_SECURITY;
|
||||
//g_print("GTK_MOZ_EMBED_MEDIUM_SECURITY\n");
|
||||
break;
|
||||
case nsIWebProgressListener::STATE_IS_SECURE|
|
||||
nsIWebProgressListener::STATE_SECURE_LOW:
|
||||
sec_mode = GTK_MOZ_EMBED_LOW_SECURITY;
|
||||
//g_print("GTK_MOZ_EMBED_LOW_SECURITY\n");
|
||||
break;
|
||||
default:
|
||||
sec_mode = GTK_MOZ_EMBED_UNKNOWN_SECURITY;
|
||||
//g_print("GTK_MOZ_EMBED_UNKNOWN_SECURITY\n");
|
||||
break;
|
||||
}
|
||||
return sec_mode;
|
||||
}
|
||||
|
||||
gint
|
||||
gtk_moz_embed_common_clear_cache(void)
|
||||
{
|
||||
nsCacheStoragePolicy storagePolicy;
|
||||
|
||||
nsCOMPtr<nsICacheService> cacheService = do_GetService(NS_CACHESERVICE_CONTRACTID);
|
||||
|
||||
if (cacheService)
|
||||
{
|
||||
//clean disk cache and memory cache
|
||||
storagePolicy = nsICache::STORE_ANYWHERE;
|
||||
cacheService->EvictEntries(storagePolicy);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_moz_embed_common_observe(const gchar* service_id,
|
||||
gpointer object,
|
||||
const gchar* topic,
|
||||
gunichar* data)
|
||||
{
|
||||
nsresult rv;
|
||||
if (service_id) {
|
||||
nsCOMPtr<nsISupports> service = do_GetService(service_id, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, FALSE);
|
||||
nsCOMPtr<nsIObserver> Observer = do_QueryInterface(service, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, FALSE);
|
||||
rv = Observer->Observe((nsISupports*)object, topic, (PRUnichar*)data);
|
||||
} else {
|
||||
//This is the correct?
|
||||
nsCOMPtr<nsIObserverService> obsService =
|
||||
do_GetService("@mozilla.org/observer-service;1", &rv);
|
||||
if (obsService)
|
||||
rv = obsService->NotifyObservers((nsISupports*)object, topic, (PRUnichar*)data);
|
||||
}
|
||||
return NS_FAILED(rv) ? FALSE : TRUE;
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Ramiro Estrugo <ramiro@eazel.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef gtkmozembed_common_h
|
||||
#define gtkmozembed_common_h
|
||||
#include "gtkmozembed.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#include <stddef.h>
|
||||
#include <gtk/gtk.h>
|
||||
#ifdef MOZILLA_CLIENT
|
||||
#include "nscore.h"
|
||||
#else // MOZILLA_CLIENT
|
||||
#ifndef nscore_h__
|
||||
/* Because this header may be included from files which not part of the mozilla
|
||||
build system, define macros from nscore.h */
|
||||
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
|
||||
#define NS_HIDDEN __attribute__((visibility("hidden")))
|
||||
#else
|
||||
#define NS_HIDDEN
|
||||
#endif
|
||||
#define NS_FROZENCALL
|
||||
#define NS_EXPORT_(type) type
|
||||
#define NS_IMPORT_(type) type
|
||||
#endif // nscore_h__
|
||||
#endif // MOZILLA_CLIENT
|
||||
#ifdef XPCOM_GLUE
|
||||
#define GTKMOZEMBED_API(type, name, params) \
|
||||
typedef type (NS_FROZENCALL * name##Type) params; \
|
||||
extern name##Type name NS_HIDDEN;
|
||||
#else // XPCOM_GLUE
|
||||
#ifdef _IMPL_GTKMOZEMBED
|
||||
#define GTKMOZEMBED_API(type, name, params) NS_EXPORT_(type) name params;
|
||||
#else
|
||||
#define GTKMOZEMBED_API(type,name, params) NS_IMPORT_(type) name params;
|
||||
#endif
|
||||
#endif // XPCOM_GLUE
|
||||
#define GTK_TYPE_MOZ_EMBED_COMMON (gtk_moz_embed_common_get_type())
|
||||
#define GTK_MOZ_EMBED_COMMON(obj) GTK_CHECK_CAST((obj), GTK_TYPE_MOZ_EMBED_COMMON, GtkMozEmbedCommon)
|
||||
#define GTK_MOZ_EMBED_COMMON_CLASS(klass) GTK_CHECK_CLASS_CAST((klass), GTK_TYPE_MOZ_EMBED_COMMON, GtkMozEmbedCommonClass)
|
||||
#define GTK_IS_MOZ_EMBED_COMMON(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_MOZ_EMBED_COMMON)
|
||||
#define GTK_IS_MOZ_EMBED_COMMON_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_MOZ_EMBED_COMMON)
|
||||
typedef struct _GtkMozEmbedCommon GtkMozEmbedCommon;
|
||||
typedef struct _GtkMozEmbedCommonClass GtkMozEmbedCommonClass;
|
||||
struct _GtkMozEmbedCommon
|
||||
{
|
||||
GtkBin object;
|
||||
void *data;
|
||||
};
|
||||
struct _GtkMozEmbedCommonClass
|
||||
{
|
||||
GtkBinClass parent_class;
|
||||
gboolean (* certificate_error) (GObject *, GObject*, guint);
|
||||
gint (* select_login) (GObject *, GList*);
|
||||
gint (* remember_login) (GObject *);
|
||||
void (* ask_cookie) (GObject * , gint , const gchar * , const gchar * , const gchar * ,
|
||||
const gchar *, const gchar * , gboolean , gint , GObject *);
|
||||
// void (* ask_cookie) (GObject * , gpointer , gint , const gchar * , const gchar * , const gchar * ,
|
||||
// const gchar *, const gchar * , gboolean , gint , GObject *);
|
||||
// gint (* modal_dialog) (GObject *, const gchar *, const gchar *, gint, gint, gint, gint);
|
||||
// gboolean (* certificate_dialog) (GObject * , GObject *);
|
||||
// void (*certificate_password_dialog) (GObject *, const gchar *, const gchar *, gchar **);
|
||||
// void (*certificate_details) (GObject *, gpointer );
|
||||
// gint (*on_submit) (GObject *);
|
||||
// gint (*select_match) (GObject *, gpointer);
|
||||
// void (*history_added) (GObject *, const gchar *, GObject*);
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_CERT_VERIFIED_OK = 0x0000,
|
||||
GTK_MOZ_EMBED_CERT_UNTRUSTED = 0x0001,
|
||||
GTK_MOZ_EMBED_CERT_NOT_VERIFIED_UNKNOWN = 0x0002,
|
||||
GTK_MOZ_EMBED_CERT_EXPIRED = 0x0004,
|
||||
GTK_MOZ_EMBED_CERT_REVOKED = 0x0008,
|
||||
GTK_MOZ_EMBED_UNKNOWN_CERT = 0x0010,
|
||||
GTK_MOZ_EMBED_CERT_ISSUER_UNTRUSTED = 0x0020,
|
||||
GTK_MOZ_EMBED_CERT_ISSUER_UNKNOWN = 0x0040,
|
||||
GTK_MOZ_EMBED_CERT_INVALID_CA = 0x0080
|
||||
} GtkMozEmbedCertificateType;
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_LOGIN_REMEMBER_FOR_THIS_SITE,
|
||||
GTK_MOZ_EMBED_LOGIN_REMEMBER_FOR_THIS_SERVER,
|
||||
GTK_MOZ_EMBED_LOGIN_NOT_NOW,
|
||||
GTK_MOZ_EMBED_LOGIN_NEVER_FOR_SITE,
|
||||
GTK_MOZ_EMBED_LOGIN_NEVER_FOR_SERVER
|
||||
} GtkMozEmbedLoginType;
|
||||
/* GTK_MOZ_EMBED_CERT_USAGE_NOT_ALLOWED,
|
||||
GTK_MOZ_EMBED_CA_CERT,
|
||||
GTK_MOZ_EMBED_USER_CERT,
|
||||
GTK_MOZ_EMBED_EMAIL_CERT,
|
||||
GTK_MOZ_EMBED_SERVER_CERT
|
||||
*/
|
||||
|
||||
/** GtkMozEmbedSecurityMode.
|
||||
* Enumerates security modes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_NO_SECURITY = 0,
|
||||
GTK_MOZ_EMBED_LOW_SECURITY,
|
||||
GTK_MOZ_EMBED_MEDIUM_SECURITY,
|
||||
GTK_MOZ_EMBED_HIGH_SECURITY,
|
||||
GTK_MOZ_EMBED_UNKNOWN_SECURITY
|
||||
} GtkMozEmbedSecurityMode;
|
||||
|
||||
typedef struct _GtkMozCookieList GtkMozCookieList;
|
||||
struct _GtkMozCookieList
|
||||
{
|
||||
gchar *domain; /** < The domain's name */
|
||||
gchar *name; /** < The cookie's name */
|
||||
gchar *value; /** < The cookie's value */
|
||||
gchar *path; /** < The cookie's path */
|
||||
};
|
||||
typedef struct _GtkMozEmbedCookie GtkMozEmbedCookie;
|
||||
struct _GtkMozEmbedCookie
|
||||
{
|
||||
gboolean remember_decision;
|
||||
gboolean accept;
|
||||
};
|
||||
/** @struct GtkMozPlugin.
|
||||
* Defines a Mozilla Plugin.
|
||||
*/
|
||||
typedef struct _GtkMozPlugin GtkMozPlugin;
|
||||
struct _GtkMozPlugin
|
||||
{
|
||||
gchar *title; /** < Plugin title */
|
||||
gchar *path; /** < Plugin path */
|
||||
gchar *type; /** < Plugin type */
|
||||
gboolean isDisabled; /** < is plugin enabled */
|
||||
};
|
||||
|
||||
typedef struct _GtkMozLogin GtkMozLogin;
|
||||
struct _GtkMozLogin
|
||||
{
|
||||
const gchar *user; /** < Plugin title */
|
||||
const gchar *pass; /** < Plugin path */
|
||||
const gchar *host; /** < Plugin type */
|
||||
guint index;
|
||||
};
|
||||
|
||||
GTKMOZEMBED_API(GtkType, gtk_moz_embed_common_get_type, (void))
|
||||
GTKMOZEMBED_API(GtkWidget*, gtk_moz_embed_common_new, (void))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_set_pref, (GtkType type, gchar*, gpointer))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_get_pref, (GtkType type, gchar*, gpointer))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_save_prefs, (void))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_login, (GtkWidget *embed, const gchar* username))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_remove_passwords, (const gchar *host, const gchar *user, gint index))
|
||||
GTKMOZEMBED_API(gint, gtk_moz_embed_common_get_logins, (const char* uri, GList **list))
|
||||
GTKMOZEMBED_API(gint, gtk_moz_embed_common_get_history_list, (GtkMozHistoryItem **GtkHI))
|
||||
GTKMOZEMBED_API(gint, gtk_moz_embed_common_remove_history, (gchar *url, gint time))
|
||||
GTKMOZEMBED_API(GSList*, gtk_moz_embed_common_get_cookie_list, (void))
|
||||
GTKMOZEMBED_API(gint, gtk_moz_embed_common_delete_all_cookies,(GSList *deletedCookies))
|
||||
GTKMOZEMBED_API(unsigned char*, gtk_moz_embed_common_nsx509_to_raw, (void *nsIX509Ptr, guint *len))
|
||||
GTKMOZEMBED_API(gint, gtk_moz_embed_common_get_plugins_list, (GList **pluginArray))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_common_reload_plugins, (void))
|
||||
GTKMOZEMBED_API(guint, gtk_moz_embed_common_get_security_mode, (guint sec_state))
|
||||
GTKMOZEMBED_API(gint, gtk_moz_embed_common_clear_cache, (void))
|
||||
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_observe, (const gchar*, gpointer, const gchar*, gunichar*))
|
||||
|
||||
|
||||
/*typedef struct _GtkMozEmbedCertContext GtkMozEmbedCertContext;
|
||||
struct _GtkMozEmbedCertContext
|
||||
{
|
||||
GObject * cert;
|
||||
guint message;
|
||||
GtkWidget *parent;
|
||||
};*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* gtkmozembed_common_h */
|
||||
@@ -1,313 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Ramiro Estrugo <ramiro@eazel.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "gtkmozembed.h"
|
||||
#include "gtkmozembed_download.h"
|
||||
#include "gtkmozembedprivate.h"
|
||||
#include "gtkmozembed_internal.h"
|
||||
#include "EmbedPrivate.h"
|
||||
#include "EmbedWindow.h"
|
||||
#include "EmbedDownloadMgr.h"
|
||||
// so we can do our get_nsIWebBrowser later...
|
||||
#include "nsIWebBrowser.h"
|
||||
|
||||
// for strings
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
#include "gtkmozembedmarshal.h"
|
||||
#define NEW_TOOLKIT_STRING(x) g_strdup(NS_ConvertUTF16toUTF8(x).get())
|
||||
#define GET_TOOLKIT_STRING(x) NS_ConvertUTF16toUTF8(x).get()
|
||||
#define GET_OBJECT_CLASS_TYPE(x) G_OBJECT_CLASS_TYPE(x)
|
||||
#endif /* MOZ_WIDGET_GTK2 */
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
// so we can get callbacks from the mozarea
|
||||
#include <gtkmozarea.h>
|
||||
// so we get the right marshaler for gtk 1.2
|
||||
#define gtkmozembed_VOID__INT_UINT \
|
||||
gtk_marshal_NONE__INT_INT
|
||||
#define gtkmozembed_VOID__STRING_INT_INT \
|
||||
gtk_marshal_NONE__POINTER_INT_INT
|
||||
#define gtkmozembed_VOID__STRING_INT_UINT \
|
||||
gtk_marshal_NONE__POINTER_INT_INT
|
||||
#define gtkmozembed_VOID__POINTER_INT_POINTER \
|
||||
gtk_marshal_NONE__POINTER_INT_POINTER
|
||||
#define gtkmozembed_BOOL__STRING \
|
||||
gtk_marshal_BOOL__POINTER
|
||||
#define gtkmozembed_VOID__INT_INT_BOOLEAN \
|
||||
gtk_marshal_NONE__INT_INT_BOOLEAN
|
||||
#define G_SIGNAL_TYPE_STATIC_SCOPE 0
|
||||
#define NEW_TOOLKIT_STRING(x) g_strdup(NS_LossyConvertUTF16toASCII(x).get())
|
||||
#define GET_TOOLKIT_STRING(x) NS_LossyConvertUTF16toASCII(x).get()
|
||||
#define GET_OBJECT_CLASS_TYPE(x) (GTK_OBJECT_CLASS(x)->type)
|
||||
#endif /* MOZ_WIDGET_GTK */
|
||||
|
||||
static void gtk_moz_embed_download_set_latest_object(GtkObject *o);
|
||||
static GtkObject *latest_download_object = nsnull;
|
||||
|
||||
// class and instance initialization
|
||||
guint moz_embed_download_signals[DOWNLOAD_LAST_SIGNAL] = { 0 };
|
||||
static void gtk_moz_embed_download_class_init(GtkMozEmbedDownloadClass *klass);
|
||||
static void gtk_moz_embed_download_init(GtkMozEmbedDownload *embed);
|
||||
static void gtk_moz_embed_download_destroy(GtkObject *object);
|
||||
GtkObject * gtk_moz_embed_download_new(void);
|
||||
|
||||
// GtkObject + class-related functions
|
||||
GtkType
|
||||
gtk_moz_embed_download_get_type(void)
|
||||
{
|
||||
static GtkType moz_embed_download_type = 0;
|
||||
if (!moz_embed_download_type)
|
||||
{
|
||||
static const GtkTypeInfo moz_embed_download_info =
|
||||
{
|
||||
"GtkMozEmbedDownload",
|
||||
sizeof(GtkMozEmbedDownload),
|
||||
sizeof(GtkMozEmbedDownloadClass),
|
||||
(GtkClassInitFunc)gtk_moz_embed_download_class_init,
|
||||
(GtkObjectInitFunc)gtk_moz_embed_download_init,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
moz_embed_download_type = gtk_type_unique(GTK_TYPE_OBJECT, &moz_embed_download_info);
|
||||
}
|
||||
return moz_embed_download_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_moz_embed_download_class_init(GtkMozEmbedDownloadClass *klass)
|
||||
{
|
||||
GtkObjectClass *object_class;
|
||||
object_class = GTK_OBJECT_CLASS(klass);
|
||||
object_class->destroy = gtk_moz_embed_download_destroy;
|
||||
|
||||
// set up our signals
|
||||
moz_embed_download_signals[DOWNLOAD_STARTED_SIGNAL] =
|
||||
gtk_signal_new("started",
|
||||
GTK_RUN_FIRST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, started),
|
||||
gtk_marshal_NONE__POINTER,
|
||||
GTK_TYPE_NONE,
|
||||
1,
|
||||
G_TYPE_POINTER);
|
||||
|
||||
moz_embed_download_signals[DOWNLOAD_COMPLETED_SIGNAL] =
|
||||
gtk_signal_new("completed",
|
||||
GTK_RUN_FIRST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, completed),
|
||||
gtk_marshal_NONE__NONE,
|
||||
GTK_TYPE_NONE, 0);
|
||||
|
||||
moz_embed_download_signals[DOWNLOAD_FAILED_SIGNAL] =
|
||||
gtk_signal_new("error",
|
||||
GTK_RUN_FIRST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, error),
|
||||
gtk_marshal_NONE__NONE,
|
||||
GTK_TYPE_NONE, 0);
|
||||
|
||||
moz_embed_download_signals[DOWNLOAD_DESTROYED_SIGNAL] =
|
||||
gtk_signal_new("aborted",
|
||||
GTK_RUN_FIRST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, aborted),
|
||||
gtk_marshal_NONE__NONE,
|
||||
GTK_TYPE_NONE, 0);
|
||||
|
||||
moz_embed_download_signals[DOWNLOAD_PROGRESS_SIGNAL] =
|
||||
gtk_signal_new("progress",
|
||||
GTK_RUN_FIRST,
|
||||
GET_OBJECT_CLASS_TYPE(klass),
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, progress),
|
||||
gtkmozembed_VOID__ULONG_ULONG_ULONG,
|
||||
GTK_TYPE_NONE,
|
||||
3,
|
||||
G_TYPE_ULONG,
|
||||
G_TYPE_ULONG,
|
||||
G_TYPE_ULONG);
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
gtk_object_class_add_signals(object_class, moz_embed_download_signals,
|
||||
DOWNLOAD_LAST_SIGNAL);
|
||||
#endif /* MOZ_WIDGET_GTK */
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_moz_embed_download_init(GtkMozEmbedDownload *download)
|
||||
{
|
||||
// this is a placeholder for later in case we need to stash data at
|
||||
// a later data and maintain backwards compatibility.
|
||||
download->data = nsnull;
|
||||
EmbedDownload *priv = new EmbedDownload();
|
||||
download->data = priv;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_moz_embed_download_destroy(GtkObject *object)
|
||||
{
|
||||
g_return_if_fail(object != NULL);
|
||||
g_return_if_fail(GTK_IS_MOZ_EMBED_DOWNLOAD(object));
|
||||
|
||||
GtkMozEmbedDownload *embed;
|
||||
EmbedDownload *downloadPrivate;
|
||||
|
||||
embed = GTK_MOZ_EMBED_DOWNLOAD(object);
|
||||
downloadPrivate = (EmbedDownload *)embed->data;
|
||||
|
||||
if (downloadPrivate) {
|
||||
delete downloadPrivate;
|
||||
embed->data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
GtkObject *
|
||||
gtk_moz_embed_download_new(void)
|
||||
{
|
||||
GtkObject *instance = (GtkObject *) gtk_type_new(gtk_moz_embed_download_get_type());
|
||||
gtk_moz_embed_download_set_latest_object(instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
GtkObject *
|
||||
gtk_moz_embed_download_get_latest_object(void)
|
||||
{
|
||||
return latest_download_object;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_moz_embed_download_set_latest_object(GtkObject *obj)
|
||||
{
|
||||
latest_download_object = obj;
|
||||
return ;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_moz_embed_download_do_command(GtkMozEmbedDownload *item, guint command)
|
||||
{
|
||||
EmbedDownload *download_priv = (EmbedDownload *) item->data;
|
||||
|
||||
if (!download_priv)
|
||||
return;
|
||||
|
||||
if (command == GTK_MOZ_EMBED_DOWNLOAD_CANCEL) {
|
||||
download_priv->launcher->Cancel(GTK_MOZ_EMBED_STATUS_FAILED_USERCANCELED);
|
||||
download_priv->launcher->SetWebProgressListener(nsnull);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == GTK_MOZ_EMBED_DOWNLOAD_RESUME) {
|
||||
download_priv->request->Resume();
|
||||
download_priv->is_paused = FALSE;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == GTK_MOZ_EMBED_DOWNLOAD_PAUSE) {
|
||||
if (download_priv->request) {
|
||||
download_priv->request->Suspend();
|
||||
download_priv->is_paused = TRUE;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == GTK_MOZ_EMBED_DOWNLOAD_RELOAD) {
|
||||
if (download_priv->gtkMozEmbedParentWidget) {}
|
||||
}
|
||||
// FIXME: missing GTK_MOZ_EMBED_DOWNLOAD_STORE and GTK_MOZ_EMBED_DOWNLOAD_RESTORE implementation.
|
||||
}
|
||||
|
||||
gchar*
|
||||
gtk_moz_embed_download_get_file_name(GtkMozEmbedDownload *item)
|
||||
{
|
||||
EmbedDownload *download_priv = (EmbedDownload *) item->data;
|
||||
|
||||
if (!download_priv)
|
||||
return nsnull;
|
||||
|
||||
return (gchar *) download_priv->file_name;
|
||||
}
|
||||
|
||||
gchar*
|
||||
gtk_moz_embed_download_get_url(GtkMozEmbedDownload *item)
|
||||
{
|
||||
EmbedDownload *download_priv = (EmbedDownload *) item->data;
|
||||
|
||||
if (!download_priv)
|
||||
return nsnull;
|
||||
|
||||
// FIXME : 'server' is storing the wrong value. See EmbedDownloadMgr.cpp l. 189.
|
||||
return (gchar *) download_priv->server;
|
||||
}
|
||||
|
||||
glong
|
||||
gtk_moz_embed_download_get_progress(GtkMozEmbedDownload *item)
|
||||
{
|
||||
EmbedDownload *download_priv = (EmbedDownload *) item->data;
|
||||
|
||||
if (!download_priv)
|
||||
return -1;
|
||||
|
||||
return (glong) download_priv->downloaded_size;
|
||||
}
|
||||
|
||||
glong
|
||||
gtk_moz_embed_download_get_file_size(GtkMozEmbedDownload *item)
|
||||
{
|
||||
EmbedDownload *download_priv = (EmbedDownload *) item->data;
|
||||
|
||||
if (!download_priv)
|
||||
return -1;
|
||||
|
||||
return (glong) download_priv->file_size;
|
||||
}
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Ramiro Estrugo <ramiro@eazel.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef gtkmozembed_download_h
|
||||
#define gtkmozembed_download_h
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#include <stddef.h>
|
||||
#include <gtk/gtk.h>
|
||||
#ifdef MOZILLA_CLIENT
|
||||
#include "nscore.h"
|
||||
#else // MOZILLA_CLIENT
|
||||
#ifndef nscore_h__
|
||||
/* Because this header may be included from files which not part of the mozilla
|
||||
build system, define macros from nscore.h */
|
||||
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
|
||||
#define NS_HIDDEN __attribute__((visibility("hidden")))
|
||||
#else
|
||||
#define NS_HIDDEN
|
||||
#endif
|
||||
#define NS_FROZENCALL
|
||||
#define NS_EXPORT_(type) type
|
||||
#define NS_IMPORT_(type) type
|
||||
#endif // nscore_h__
|
||||
#endif // MOZILLA_CLIENT
|
||||
#ifdef XPCOM_GLUE
|
||||
#define GTKMOZEMBED_API(type, name, params) \
|
||||
typedef type (NS_FROZENCALL * name##Type) params; \
|
||||
extern name##Type name NS_HIDDEN;
|
||||
#else // XPCOM_GLUE
|
||||
#ifdef _IMPL_GTKMOZEMBED
|
||||
#define GTKMOZEMBED_API(type, name, params) NS_EXPORT_(type) name params;
|
||||
#else
|
||||
#define GTKMOZEMBED_API(type,name, params) NS_IMPORT_(type) name params;
|
||||
#endif
|
||||
#endif // XPCOM_GLUE
|
||||
|
||||
#define GTK_TYPE_MOZ_EMBED_DOWNLOAD (gtk_moz_embed_download_get_type())
|
||||
#define GTK_MOZ_EMBED_DOWNLOAD(obj) GTK_CHECK_CAST((obj), GTK_TYPE_MOZ_EMBED_DOWNLOAD, GtkMozEmbedDownload)
|
||||
#define GTK_MOZ_EMBED_DOWNLOAD_CLASS(klass) GTK_CHECK_CLASS_CAST((klass), GTK_TYPE_MOZ_EMBED_DOWNLOAD, GtkMozEmbedDownloadClass)
|
||||
#define GTK_IS_MOZ_EMBED_DOWNLOAD(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_MOZ_EMBED_DOWNLOAD)
|
||||
#define GTK_IS_MOZ_EMBED_DOWNLOAD_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_MOZ_EMBED_DOWNLOAD)
|
||||
|
||||
typedef struct _GtkMozEmbedDownload GtkMozEmbedDownload;
|
||||
typedef struct _GtkMozEmbedDownloadClass GtkMozEmbedDownloadClass;
|
||||
|
||||
struct _GtkMozEmbedDownload
|
||||
{
|
||||
GtkObject object;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct _GtkMozEmbedDownloadClass
|
||||
{
|
||||
GtkObjectClass parent_class;
|
||||
void (*started) (GtkMozEmbedDownload* item, gchar **file_name_with_path);
|
||||
void (*completed) (GtkMozEmbedDownload* item);
|
||||
void (*error) (GtkMozEmbedDownload* item);
|
||||
void (*aborted) (GtkMozEmbedDownload* item);
|
||||
void (*progress) (GtkMozEmbedDownload* item, gulong downloaded_bytes, gulong total_bytes, gdouble kbps);
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GTK_MOZ_EMBED_DOWNLOAD_RESUME,
|
||||
GTK_MOZ_EMBED_DOWNLOAD_CANCEL,
|
||||
GTK_MOZ_EMBED_DOWNLOAD_PAUSE,
|
||||
GTK_MOZ_EMBED_DOWNLOAD_RELOAD,
|
||||
GTK_MOZ_EMBED_DOWNLOAD_STORE,
|
||||
GTK_MOZ_EMBED_DOWNLOAD_RESTORE
|
||||
} GtkMozEmbedDownloadActions;
|
||||
|
||||
GTKMOZEMBED_API(GtkType, gtk_moz_embed_download_get_type, (void))
|
||||
GTKMOZEMBED_API(GtkObject *, gtk_moz_embed_download_new, (void))
|
||||
GTKMOZEMBED_API(GtkObject *, gtk_moz_embed_download_get_latest_object, (void))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_download_do_command, (GtkMozEmbedDownload *item, guint command))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_download_do_command, (GtkMozEmbedDownload *item, guint command))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_download_do_command, (GtkMozEmbedDownload *item, guint command))
|
||||
GTKMOZEMBED_API(void, gtk_moz_embed_download_do_command, (GtkMozEmbedDownload *item, guint command))
|
||||
GTKMOZEMBED_API(gchar*, gtk_moz_embed_download_get_file_name, (GtkMozEmbedDownload *item))
|
||||
GTKMOZEMBED_API(gchar*, gtk_moz_embed_download_get_url, (GtkMozEmbedDownload *item))
|
||||
GTKMOZEMBED_API(glong, gtk_moz_embed_download_get_progress, (GtkMozEmbedDownload *item))
|
||||
GTKMOZEMBED_API(glong, gtk_moz_embed_download_get_file_size, (GtkMozEmbedDownload *item))
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* gtkmozembed_download_h */
|
||||
@@ -1,135 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla embedding.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Benjamin Smedberg <benjamin@smedbergs.us>.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// This file is an implementation file, meant to be #included in a
|
||||
// single C++ file of an embedding application. It is called after
|
||||
// XPCOMGlueStartup to glue the gtkmozembed functions.
|
||||
|
||||
#include "gtkmozembed.h"
|
||||
#include "gtkmozembed_internal.h"
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
#include "gtkmozembed_common.h"
|
||||
#include "gtkmozembed_download.h"
|
||||
#endif
|
||||
#include "nsXPCOMGlue.h"
|
||||
|
||||
#ifndef XPCOM_GLUE
|
||||
#error This file only makes sense when XPCOM_GLUE is defined.
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
#define GTKMOZEMBED2_FUNCTIONS \
|
||||
GTKF(gtk_moz_embed_download_get_type) \
|
||||
GTKF(gtk_moz_embed_download_new) \
|
||||
GTKF(gtk_moz_embed_common_get_type) \
|
||||
GTKF(gtk_moz_embed_common_new) \
|
||||
GTKF(gtk_moz_embed_common_set_pref) \
|
||||
GTKF(gtk_moz_embed_common_get_pref) \
|
||||
GTKF(gtk_moz_embed_common_save_prefs) \
|
||||
GTKF(gtk_moz_embed_common_remove_passwords) \
|
||||
GTKF(gtk_moz_embed_common_get_history_list) \
|
||||
GTKF(gtk_moz_embed_get_zoom_level) \
|
||||
GTKF(gtk_moz_embed_set_zoom_level) \
|
||||
GTKF(gtk_moz_embed_find_text) \
|
||||
GTKF(gtk_moz_embed_clipboard) \
|
||||
GTKF(gtk_moz_embed_notify_plugins) \
|
||||
GTKF(gtk_moz_embed_get_context_info) \
|
||||
GTKF(gtk_moz_embed_get_selection) \
|
||||
GTKF(gtk_moz_embed_get_doc_info) \
|
||||
GTKF(gtk_moz_embed_insert_text) \
|
||||
GTKF(gtk_moz_embed_common_nsx509_to_raw) \
|
||||
GTKF(gtk_moz_embed_common_observe) \
|
||||
GTKF(gtk_moz_embed_get_shistory_list) \
|
||||
GTKF(gtk_moz_embed_get_shistory_index) \
|
||||
GTKF(gtk_moz_embed_shistory_goto_index) \
|
||||
GTKF(gtk_moz_embed_get_server_cert) \
|
||||
GTKF(gtk_moz_embed_get_nsIWebBrowser)
|
||||
#else
|
||||
#define GTKMOZEMBED2_FUNCTIONS
|
||||
#endif
|
||||
|
||||
#define GTKMOZEMBED_FUNCTIONS \
|
||||
GTKF(gtk_moz_embed_get_type) \
|
||||
GTKF(gtk_moz_embed_new) \
|
||||
GTKF(gtk_moz_embed_push_startup) \
|
||||
GTKF(gtk_moz_embed_pop_startup) \
|
||||
GTKF(gtk_moz_embed_set_path) \
|
||||
GTKF(gtk_moz_embed_set_comp_path) \
|
||||
GTKF(gtk_moz_embed_set_profile_path) \
|
||||
GTKF(gtk_moz_embed_load_url) \
|
||||
GTKF(gtk_moz_embed_stop_load) \
|
||||
GTKF(gtk_moz_embed_can_go_back) \
|
||||
GTKF(gtk_moz_embed_can_go_forward) \
|
||||
GTKF(gtk_moz_embed_go_back) \
|
||||
GTKF(gtk_moz_embed_go_forward) \
|
||||
GTKF(gtk_moz_embed_render_data) \
|
||||
GTKF(gtk_moz_embed_open_stream) \
|
||||
GTKF(gtk_moz_embed_append_data) \
|
||||
GTKF(gtk_moz_embed_close_stream) \
|
||||
GTKF(gtk_moz_embed_get_link_message) \
|
||||
GTKF(gtk_moz_embed_get_js_status) \
|
||||
GTKF(gtk_moz_embed_get_title) \
|
||||
GTKF(gtk_moz_embed_get_location) \
|
||||
GTKF(gtk_moz_embed_reload) \
|
||||
GTKF(gtk_moz_embed_set_chrome_mask) \
|
||||
GTKF(gtk_moz_embed_get_chrome_mask) \
|
||||
GTKF(gtk_moz_embed_single_get_type) \
|
||||
GTKF(gtk_moz_embed_single_get) \
|
||||
GTKMOZEMBED2_FUNCTIONS
|
||||
|
||||
#define GTKF(fname) fname##Type fname;
|
||||
|
||||
GTKMOZEMBED_FUNCTIONS
|
||||
|
||||
#undef GTKF
|
||||
|
||||
#define GTKF(fname) { #fname, (NSFuncPtr*) &fname },
|
||||
|
||||
static const nsDynamicFunctionLoad GtkSymbols[] = {
|
||||
GTKMOZEMBED_FUNCTIONS
|
||||
{ nsnull, nsnull }
|
||||
};
|
||||
|
||||
#undef GTKF
|
||||
|
||||
static nsresult
|
||||
GTKEmbedGlueStartup()
|
||||
{
|
||||
return XPCOMGlueLoadXULFunctions(GtkSymbols);
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef gtkmozembed_internal_h
|
||||
#define gtkmozembed_internal_h
|
||||
|
||||
#include "nsIWebBrowser.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct nsModuleComponentInfo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
GTKMOZEMBED_API(void,
|
||||
gtk_moz_embed_get_nsIWebBrowser, (GtkMozEmbed *embed,
|
||||
nsIWebBrowser **retval))
|
||||
|
||||
GTKMOZEMBED_API(PRUnichar*,
|
||||
gtk_moz_embed_get_title_unichar, (GtkMozEmbed *embed))
|
||||
|
||||
GTKMOZEMBED_API(PRUnichar*,
|
||||
gtk_moz_embed_get_js_status_unichar, (GtkMozEmbed *embed))
|
||||
|
||||
GTKMOZEMBED_API(PRUnichar*,
|
||||
gtk_moz_embed_get_link_message_unichar, (GtkMozEmbed *embed))
|
||||
|
||||
GTKMOZEMBED_API(void,
|
||||
gtk_moz_embed_set_directory_service_provider, (nsIDirectoryServiceProvider *appFileLocProvider))
|
||||
|
||||
GTKMOZEMBED_API(void,
|
||||
gtk_moz_embed_set_app_components, (const nsModuleComponentInfo *aComps,
|
||||
int aNumComps))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* gtkmozembed_internal_h */
|
||||
@@ -1,31 +0,0 @@
|
||||
BOOL:STRING
|
||||
BOOL:STRING,STRING
|
||||
BOOL:STRING,STRING,POINTER
|
||||
BOOL:STRING,STRING,POINTER,INT
|
||||
BOOL:STRING,STRING,POINTER,POINTER,STRING,POINTER
|
||||
BOOL:STRING,STRING,POINTER,STRING,POINTER
|
||||
BOOL:STRING,STRING,STRING,POINTER
|
||||
INT:STRING,INT,INT,INT,INT,INT
|
||||
INT:STRING,STRING,INT,INT,INT,INT
|
||||
INT:STRING,STRING,UINT,STRING,STRING,STRING,STRING,POINTER
|
||||
INT:VOID
|
||||
STRING:STRING,STRING
|
||||
VOID:BOOL
|
||||
VOID:INT,INT,BOOL
|
||||
VOID:INT,STRING
|
||||
VOID:INT,STRING,STRING
|
||||
VOID:INT,UINT
|
||||
VOID:POINTER,INT,POINTER
|
||||
VOID:POINTER,INT,STRING,STRING,STRING,STRING,STRING,BOOLEAN,INT
|
||||
VOID:POINTER,STRING,BOOL,BOOL
|
||||
VOID:STRING,INT,INT
|
||||
VOID:STRING,INT,UINT
|
||||
VOID:STRING,STRING
|
||||
VOID:STRING,STRING,POINTER
|
||||
VOID:STRING,STRING,STRING,ULONG,INT
|
||||
VOID:STRING,STRING,STRING,POINTER
|
||||
VOID:UINT,INT,INT,STRING,STRING,STRING,STRING
|
||||
VOID:ULONG,ULONG,ULONG
|
||||
BOOL:POINTER,UINT
|
||||
VOID:POINTER
|
||||
BOOL:STRING,STRING,POINTER
|
||||
@@ -1,147 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef gtkmozembedprivate_h
|
||||
#define gtkmozembedprivate_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "gtkmozembed.h"
|
||||
|
||||
/* signals */
|
||||
|
||||
enum {
|
||||
LINK_MESSAGE,
|
||||
JS_STATUS,
|
||||
LOCATION,
|
||||
TITLE,
|
||||
PROGRESS,
|
||||
PROGRESS_ALL,
|
||||
NET_STATE,
|
||||
NET_STATE_ALL,
|
||||
NET_START,
|
||||
NET_STOP,
|
||||
NEW_WINDOW,
|
||||
VISIBILITY,
|
||||
DESTROY_BROWSER,
|
||||
OPEN_URI,
|
||||
SIZE_TO,
|
||||
DOM_KEY_DOWN,
|
||||
DOM_KEY_PRESS,
|
||||
DOM_KEY_UP,
|
||||
DOM_MOUSE_DOWN,
|
||||
DOM_MOUSE_UP,
|
||||
DOM_MOUSE_CLICK,
|
||||
DOM_MOUSE_DBL_CLICK,
|
||||
DOM_MOUSE_OVER,
|
||||
DOM_MOUSE_OUT,
|
||||
SECURITY_CHANGE,
|
||||
STATUS_CHANGE,
|
||||
DOM_ACTIVATE,
|
||||
DOM_FOCUS_IN,
|
||||
DOM_FOCUS_OUT,
|
||||
ALERT,
|
||||
ALERT_CHECK,
|
||||
CONFIRM,
|
||||
CONFIRM_CHECK,
|
||||
CONFIRM_EX,
|
||||
PROMPT,
|
||||
PROMPT_AUTH,
|
||||
SELECT,
|
||||
DOWNLOAD_REQUEST,
|
||||
DOM_MOUSE_SCROLL,
|
||||
DOM_MOUSE_LONG_PRESS,
|
||||
DOM_FOCUS,
|
||||
DOM_BLUR,
|
||||
UPLOAD_DIALOG,
|
||||
ICON_CHANGED,
|
||||
MAILTO,
|
||||
NETWORK_ERROR,
|
||||
RSS_REQUEST,
|
||||
EMBED_LAST_SIGNAL
|
||||
};
|
||||
|
||||
// DOM_MOUSE_MOVE,
|
||||
extern guint moz_embed_signals[EMBED_LAST_SIGNAL];
|
||||
|
||||
#if 0
|
||||
enum {
|
||||
COMMON_CERT_DIALOG,
|
||||
COMMON_CERT_PASSWD_DIALOG,
|
||||
COMMON_CERT_DETAILS_DIALOG,
|
||||
COMMON_HISTORY_ADDED,
|
||||
COMMON_ON_SUBMIT_SIGNAL,
|
||||
COMMON_SELECT_MATCH_SIGNAL,
|
||||
COMMON_MODAL_DIALOG,
|
||||
COMMON_LAST_SIGNAL
|
||||
};
|
||||
#endif
|
||||
|
||||
enum {
|
||||
COMMON_CERT_ERROR,
|
||||
COMMON_SELECT_LOGIN,
|
||||
COMMON_REMEMBER_LOGIN,
|
||||
COMMON_ASK_COOKIE,
|
||||
COMMON_LAST_SIGNAL
|
||||
};
|
||||
|
||||
extern guint moz_embed_common_signals[COMMON_LAST_SIGNAL];
|
||||
|
||||
enum
|
||||
{
|
||||
DOWNLOAD_STARTED_SIGNAL,
|
||||
DOWNLOAD_STOPPED_SIGNAL,
|
||||
DOWNLOAD_COMPLETED_SIGNAL,
|
||||
DOWNLOAD_FAILED_SIGNAL,
|
||||
DOWNLOAD_DESTROYED_SIGNAL,
|
||||
DOWNLOAD_PROGRESS_SIGNAL,
|
||||
DOWNLOAD_LAST_SIGNAL
|
||||
};
|
||||
|
||||
extern guint moz_embed_download_signals[DOWNLOAD_LAST_SIGNAL];
|
||||
extern void gtk_moz_embed_single_create_window(GtkMozEmbed **aNewEmbed,
|
||||
guint aChromeFlags);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* gtkmozembedprivate_h */
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications, Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(CF39C2B0-1E4B-11d5-A549-0010A401EB10)]
|
||||
|
||||
/**
|
||||
* An optional interface for clients wishing to access a
|
||||
* password object
|
||||
*
|
||||
* @status FROZEN
|
||||
*/
|
||||
|
||||
interface nsIPassword : nsISupports {
|
||||
|
||||
/**
|
||||
* the name of the host corresponding to the login being saved
|
||||
*
|
||||
* The form of the host depends on how the nsIPassword object was created
|
||||
*
|
||||
* - if it was created as a result of submitting a form to a site, then the
|
||||
* host is the url of the site, as obtained from a call to GetSpec
|
||||
*
|
||||
* - if it was created as a result of another app (e.g., mailnews) calling a
|
||||
* prompt routine such at PromptUsernameAndPassword, then the host is whatever
|
||||
* arbitrary string the app decided to pass in.
|
||||
*
|
||||
* Whatever form it is in, it will be used by the password manager to uniquely
|
||||
* identify the login realm, so that "newsserver:119" is not the same thing as
|
||||
* "newsserver".
|
||||
*/
|
||||
readonly attribute AUTF8String host;
|
||||
|
||||
/**
|
||||
* the user name portion of the login
|
||||
*/
|
||||
readonly attribute AString user;
|
||||
|
||||
/**
|
||||
* the password portion of the login
|
||||
*/
|
||||
readonly attribute AString password;
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Darin Fisher <darin@meer.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIPassword.idl"
|
||||
|
||||
/**
|
||||
* This interface is supported by password manager entries to expose the
|
||||
* fieldnames passed to nsIPasswordManagerInternal's addUserFull method.
|
||||
*/
|
||||
[scriptable, uuid(2cc35c67-978f-42a9-a958-16e97ad2f4c8)]
|
||||
interface nsIPasswordInternal : nsIPassword
|
||||
{
|
||||
/**
|
||||
* The name of the field that contained the username.
|
||||
*/
|
||||
readonly attribute AString userFieldName;
|
||||
|
||||
/**
|
||||
* The name of the field that contained the password.
|
||||
*/
|
||||
readonly attribute AString passwordFieldName;
|
||||
};
|
||||
Reference in New Issue
Block a user