Commit f9855741 authored by darin's avatar darin

Reviewed by John.

	- fixed 3144882 -- pretend to be WinIE for abcnews.com

        * WebView.subproj/WebControllerPrivate.h: Add an enum, UserAgentStringType, with values
	Safari, MacIE, and WinIE. Also add NumUserAgentStringTypes and turn the userAgent and
	userAgentWhenPretendingToBeMacIE strings into an array indexed by type.

        * WebView.subproj/WebController.m:
        (-[WebController setApplicationNameForUserAgent:]): Use a loop to discard the user agent
	strings, since we have an array now.
        (-[WebController userAgentForURL:]): Change user agent algorithm to check two strings rather
	than once against the spoof table, allowing two dots in the "domain name", which is needed
	for "abcnews.go.com". Get a user agent string type from the table rather than just a boolean
	"pretend to be MacIE". Store a string per type rather than one for normalcy and one for MacIE.
	Add a case for WinIE to the user agent computations.

	* English.lproj/StringsNotToBeLocalized.txt: Update for change above.

        * WebView.subproj/WebControllerPrivate.m:
        (-[WebControllerPrivate dealloc]): Use a loop to discard the user agent strings, since we have
	an array now.
        (-[WebController _defaultsDidChange]): Ditto.

        * WebView.subproj/WebUserAgentSpoofTable.gperf: Add a UserAgentStringType field to the struct.
	Add MacIE to each existing table entry, and add a new one that says WinIE for abcnews.go.com.

        * Makefile.am: Pass "-F ,0" to gperf so that we don't get warnings compiling empty entries
	in the hash table.

        * WebView.subproj/WebUserAgentSpoofTable.c: Re-generated.

        - other changes

        * WebView.subproj/WebHTMLView.m: Removed some old, dead, #if 0'd code.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3307 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ffcf8970
2003-01-12 Darin Adler <darin@apple.com>
Reviewed by John.
- fixed 3144882 -- pretend to be WinIE for abcnews.com
* WebView.subproj/WebControllerPrivate.h: Add an enum, UserAgentStringType, with values
Safari, MacIE, and WinIE. Also add NumUserAgentStringTypes and turn the userAgent and
userAgentWhenPretendingToBeMacIE strings into an array indexed by type.
* WebView.subproj/WebController.m:
(-[WebController setApplicationNameForUserAgent:]): Use a loop to discard the user agent
strings, since we have an array now.
(-[WebController userAgentForURL:]): Change user agent algorithm to check two strings rather
than once against the spoof table, allowing two dots in the "domain name", which is needed
for "abcnews.go.com". Get a user agent string type from the table rather than just a boolean
"pretend to be MacIE". Store a string per type rather than one for normalcy and one for MacIE.
Add a case for WinIE to the user agent computations.
* English.lproj/StringsNotToBeLocalized.txt: Update for change above.
* WebView.subproj/WebControllerPrivate.m:
(-[WebControllerPrivate dealloc]): Use a loop to discard the user agent strings, since we have
an array now.
(-[WebController _defaultsDidChange]): Ditto.
* WebView.subproj/WebUserAgentSpoofTable.gperf: Add a UserAgentStringType field to the struct.
Add MacIE to each existing table entry, and add a new one that says WinIE for abcnews.go.com.
* Makefile.am: Pass "-F ,0" to gperf so that we don't get warnings compiling empty entries
in the hash table.
* WebView.subproj/WebUserAgentSpoofTable.c: Re-generated.
- other changes
* WebView.subproj/WebHTMLView.m: Removed some old, dead, #if 0'd code.
2003-01-11 Darin Adler <darin@apple.com>
Reviewed by John.
......
......@@ -77,6 +77,8 @@
"MP4 Video"
"Mozilla/4.0 (compatible; MSIE 5.2; Mac_PowerPC) AppleWebKit/%@ %@"
"Mozilla/4.0 (compatible; MSIE 5.2; Mac_PowerPC) AppleWebKit/%@"
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT) AppleWebKit/%@ %@"
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT) AppleWebKit/%@"
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko) %@"
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko)"
"NETSCAPE2"
......
......@@ -7,7 +7,7 @@ clean-am:
rm -rf $(SYMROOTS)/Safari.app/Frameworks/WebKit.framework
WebView.subproj/WebUserAgentSpoofTable.c: WebView.subproj/WebUserAgentSpoofTable.gperf Makefile.am previous-clean-timestamp
gperf -CEot -L 'ANSI-C' -k '*' -N _web_findSpoofTableEntry $< > $@
gperf -CEot -L 'ANSI-C' -k '*' -N _web_findSpoofTableEntry -F ,0 $< > $@
BUILT_SOURCES = WebView.subproj/WebUserAgentSpoofTable.c
CLEANFILES = $(BUILT_SOURCES)
......
......@@ -322,8 +322,11 @@ - (void)setApplicationNameForUserAgent:(NSString *)applicationName
NSString *name = [applicationName copy];
[_private->applicationNameForUserAgent release];
_private->applicationNameForUserAgent = name;
[_private->userAgent release];
_private->userAgent = nil;
int i;
for (i = 0; i != NumUserAgentStringTypes; ++i) {
[_private->userAgent[i] release];
_private->userAgent[i] = nil;
}
}
- (NSString *)applicationNameForUserAgent
......@@ -369,17 +372,20 @@ - (NSString *)userAgentForURL:(NSURL *)URL
// Look to see if we need to spoof.
// First step is to get the host as a C-format string.
BOOL pretendToBeMacIE = NO;
UserAgentStringType type = Safari;
NSString *host = [URL host];
char hostBuffer[256];
if (host && CFStringGetCString((CFStringRef)host, hostBuffer, sizeof(hostBuffer), kCFStringEncodingASCII)) {
// Next step is to find the last part of the name. The part with only one dot.
// Next step is to find the last part of the name.
// We get the part with only two dots, and the part with only one dot.
const char *thirdToLastPeriod = NULL;
const char *nextToLastPeriod = NULL;
const char *lastPeriod = NULL;
char c;
char *p = hostBuffer;
while ((c = *p)) {
if (c == '.') {
thirdToLastPeriod = nextToLastPeriod;
nextToLastPeriod = lastPeriod;
lastPeriod = p;
} else {
......@@ -389,13 +395,23 @@ - (NSString *)userAgentForURL:(NSURL *)URL
}
// Now look up that last part in the gperf spoof table.
if (lastPeriod) {
const char *domain = nextToLastPeriod ? nextToLastPeriod + 1 : hostBuffer;
pretendToBeMacIE = _web_findSpoofTableEntry(domain, p - domain) != NULL;
const char *lastPart;
const struct UserAgentSpoofTableEntry *entry = NULL;
if (nextToLastPeriod) {
lastPart = thirdToLastPeriod ? thirdToLastPeriod + 1 : hostBuffer;
entry = _web_findSpoofTableEntry(lastPart, p - lastPart);
}
if (!entry) {
lastPart = nextToLastPeriod ? nextToLastPeriod + 1 : hostBuffer;
entry = _web_findSpoofTableEntry(lastPart, p - lastPart);
}
if (entry) {
type = entry->type;
}
}
}
NSString **userAgentStorage = pretendToBeMacIE
? &_private->userAgentWhenPretendingToBeMacIE : &_private->userAgent;
NSString **userAgentStorage = &_private->userAgent[type];
NSString *userAgent = *userAgentStorage;
if (userAgent) {
......@@ -409,7 +425,17 @@ - (NSString *)userAgentForURL:(NSURL *)URL
objectForInfoDictionaryKey:(id)kCFBundleVersionKey];
NSString *applicationName = _private->applicationNameForUserAgent;
if (pretendToBeMacIE) {
switch (type) {
case Safari:
if ([applicationName length]) {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko) %@",
language, sourceVersion, applicationName];
} else {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko)",
language, sourceVersion];
}
break;
case MacIE:
if ([applicationName length]) {
userAgent = [NSString stringWithFormat:@"Mozilla/4.0 (compatible; MSIE 5.2; Mac_PowerPC) AppleWebKit/%@ %@",
language, sourceVersion, applicationName];
......@@ -417,14 +443,16 @@ - (NSString *)userAgentForURL:(NSURL *)URL
userAgent = [NSString stringWithFormat:@"Mozilla/4.0 (compatible; MSIE 5.2; Mac_PowerPC) AppleWebKit/%@",
language, sourceVersion];
}
} else {
break;
case WinIE:
if ([applicationName length]) {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko) %@",
userAgent = [NSString stringWithFormat:@"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT) AppleWebKit/%@ %@",
language, sourceVersion, applicationName];
} else {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko)",
userAgent = [NSString stringWithFormat:@"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT) AppleWebKit/%@",
language, sourceVersion];
}
break;
}
*userAgentStorage = [userAgent retain];
......
......@@ -9,6 +9,9 @@
@class WebError;
@class WebFrame;
typedef enum { Safari, MacIE, WinIE } UserAgentStringType;
enum { NumUserAgentStringTypes = WinIE + 1 };
@interface WebControllerPrivate : NSObject
{
@public
......@@ -30,8 +33,7 @@
NSString *applicationNameForUserAgent;
NSString *userAgentOverride;
NSString *userAgent;
NSString *userAgentWhenPretendingToBeMacIE;
NSString *userAgent[NumUserAgentStringTypes];
BOOL defersCallbacks;
......
......@@ -64,8 +64,10 @@ - (void)dealloc
[backForwardList release];
[applicationNameForUserAgent release];
[userAgentOverride release];
[userAgent release];
[userAgentWhenPretendingToBeMacIE release];
int i;
for (i = 0; i != NumUserAgentStringTypes; ++i) {
[userAgent[i] release];
}
[controllerSetName release];
[topLevelFrameName release];
......@@ -334,10 +336,11 @@ - (void)_mouseDidMoveOverElement:(NSDictionary *)dictionary modifierFlags:(unsig
- (void)_defaultsDidChange
{
[_private->userAgent release];
_private->userAgent = nil;
[_private->userAgentWhenPretendingToBeMacIE release];
_private->userAgentWhenPretendingToBeMacIE = nil;
int i;
for (i = 0; i != NumUserAgentStringTypes; ++i) {
[_private->userAgent[i] release];
_private->userAgent[i] = nil;
}
}
@end
......@@ -672,62 +672,6 @@ - (void)mouseMovedNotification:(NSNotification *)notification
[self _updateMouseoverWithEvent:[[notification userInfo] objectForKey:@"NSEvent"]];
}
#if 0
// Why don't we call KHTMLView's keyPressEvent/keyReleaseEvent?
// Because we currently don't benefit from any of the code in there.
// It implements its own version of keyboard scrolling, but we have our
// version in WebView. It implements some keyboard access to individual
// nodes, but we are probably going to handle that on the NSView side.
// We already handle normal typing through the responder chain.
// One of the benefits of not calling through to KHTMLView is that we don't
// have to have the isScrollEvent function at all.
- (void)keyDown: (NSEvent *)event
{
LOG(Events, "keyDown: %@", event);
int state = 0;
// FIXME: We don't want to call keyPressEvent for scrolling key events,
// so we have to have some logic for deciding which events go to the KHTMLView.
// Best option is probably to only pass in certain events that we know it
// handles in a way we like.
if (passToWidget) {
[self _addModifiers:[event modifierFlags] toState:&state];
QKeyEvent kEvent(QEvent::KeyPress, 0, 0, state, NSSTRING_TO_QSTRING([event characters]), [event isARepeat], 1);
KHTMLView *widget = _private->widget;
if (widget)
widget->keyPressEvent(&kEvent);
} else {
[super keyDown:event];
}
}
- (void)keyUp: (NSEvent *)event
{
LOG(Events, "keyUp: %@", event);
int state = 0;
// FIXME: Make sure this logic matches keyDown above.
if (passToWidget) {
[self _addModifiers:[event modifierFlags] toState:&state];
QKeyEvent kEvent(QEvent::KeyPress, 0, 0, state, NSSTRING_TO_QSTRING([event characters]), [event isARepeat], 1);
KHTMLView *widget = _private->widget;
if (widget)
widget->keyReleaseEvent(&kEvent);
} else {
[super keyUp:event];
}
}
#endif
- (BOOL)supportsTextEncoding
{
return YES;
......
/* ANSI-C code produced by gperf version 2.7.2 */
/* Command-line: gperf -CEot -L ANSI-C -k '*' -N _web_findSpoofTableEntry WebView.subproj/WebUserAgentSpoofTable.gperf */
struct UserAgentSpoofTableEntry { const char *name; };
/* Command-line: gperf -CEot -L ANSI-C -k '*' -N _web_findSpoofTableEntry -F ,0 WebView.subproj/WebUserAgentSpoofTable.gperf */
struct UserAgentSpoofTableEntry { const char *name; UserAgentStringType type; };
/* maximum key range = 18, duplicates = 0 */
#ifdef __GNUC__
......@@ -26,7 +26,7 @@ hash (register const char *str, register unsigned int len)
27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
27, 27, 27, 27, 27, 27, 27, 0, 0, 0,
0, 0, 10, 0, 0, 0, 5, 27, 0, 0,
0, 0, 0, 27, 0, 0, 0, 0, 0, 0,
0, 0, 0, 27, 0, 0, 0, 0, 5, 0,
27, 5, 27, 27, 27, 27, 27, 27, 27, 27,
27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
......@@ -96,7 +96,7 @@ _web_findSpoofTableEntry (register const char *str, register unsigned int len)
{
enum
{
TOTAL_KEYWORDS = 12,
TOTAL_KEYWORDS = 13,
MIN_WORD_LENGTH = 9,
MAX_WORD_LENGTH = 18,
MIN_HASH_VALUE = 9,
......@@ -105,23 +105,25 @@ _web_findSpoofTableEntry (register const char *str, register unsigned int len)
static const struct UserAgentSpoofTableEntry wordlist[] =
{
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{"watch.com"},
{"battle.net"},
{"porsche.com"},
{""},
{"hondacars.com"},
{"oregonlive.com"},
{"jaguar.com"},
{"olympic.org"},
{""},
{"hondaredriders.com"},
{""}, {""},
{"freebsd.org"},
{"firstusa.com"},
{"microsoft.com"},
{""}, {""},
{"bang-olufsen.com"}
{"",0}, {"",0}, {"",0}, {"",0}, {"",0}, {"",0}, {"",0},
{"",0}, {"",0},
{"watch.com", MacIE},
{"battle.net", MacIE},
{"porsche.com", MacIE},
{"",0},
{"hondacars.com", MacIE},
{"abcnews.go.com", WinIE},
{"jaguar.com", MacIE},
{"olympic.org", MacIE},
{"",0},
{"hondaredriders.com", MacIE},
{"oregonlive.com", MacIE},
{"",0},
{"freebsd.org", MacIE},
{"firstusa.com", MacIE},
{"microsoft.com", MacIE},
{"",0}, {"",0},
{"bang-olufsen.com", MacIE}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
......
struct UserAgentSpoofTableEntry { const char *name; };
struct UserAgentSpoofTableEntry { const char *name; UserAgentStringType type; };
%%
# At the moment, any entry in this table means "pretend to be Mac IE"
# for all URLs within this domain, where domain is defined as URLs with
# host strings of "xxx.com" or "<anything>.xxx.com".
# Entries in this table apply to all hosts with strings of "xxx.com" or "<anything>.xxx.com".
# Entries must have either one dot or two dots in them.
#
# pretend to be Mac IE because these sites forbid unknown browsers
bang-olufsen.com
hondacars.com
hondaredriders.com
jaguar.com
porsche.com
bang-olufsen.com, MacIE
hondacars.com, MacIE
hondaredriders.com, MacIE
jaguar.com, MacIE
porsche.com, MacIE
#
# pretend to be Mac IE because otherwise the site tries to use layers
watch.com
watch.com, MacIE
#
# pretend to be Mac IE to make the return key work to log in
firstusa.com
firstusa.com, MacIE
#
# pretend to be Mac IE to avoid bad-quality CSS the site gives us otherwise
microsoft.com
olympic.org
microsoft.com, MacIE
olympic.org, MacIE
#
# pretend to be Mac IE to get the cool animation on the battle.net/war3 page that Darin likes
battle.net
battle.net, MacIE
#
# pretend to be Mac IE to avoid gzipped HTML which we don't support yet
freebsd.org
freebsd.org, MacIE
#
# pretend to be Mac IE to work around bug and avoid "spewage" at the bottom of some pages
oregonlive.com
oregonlive.com, MacIE
#
# pretend to be Win IE to get the smaller font sizes the site gives for Windows
abcnews.go.com, WinIE
......@@ -322,8 +322,11 @@ - (void)setApplicationNameForUserAgent:(NSString *)applicationName
NSString *name = [applicationName copy];
[_private->applicationNameForUserAgent release];
_private->applicationNameForUserAgent = name;
[_private->userAgent release];
_private->userAgent = nil;
int i;
for (i = 0; i != NumUserAgentStringTypes; ++i) {
[_private->userAgent[i] release];
_private->userAgent[i] = nil;
}
}
- (NSString *)applicationNameForUserAgent
......@@ -369,17 +372,20 @@ - (NSString *)userAgentForURL:(NSURL *)URL
// Look to see if we need to spoof.
// First step is to get the host as a C-format string.
BOOL pretendToBeMacIE = NO;
UserAgentStringType type = Safari;
NSString *host = [URL host];
char hostBuffer[256];
if (host && CFStringGetCString((CFStringRef)host, hostBuffer, sizeof(hostBuffer), kCFStringEncodingASCII)) {
// Next step is to find the last part of the name. The part with only one dot.
// Next step is to find the last part of the name.
// We get the part with only two dots, and the part with only one dot.
const char *thirdToLastPeriod = NULL;
const char *nextToLastPeriod = NULL;
const char *lastPeriod = NULL;
char c;
char *p = hostBuffer;
while ((c = *p)) {
if (c == '.') {
thirdToLastPeriod = nextToLastPeriod;
nextToLastPeriod = lastPeriod;
lastPeriod = p;
} else {
......@@ -389,13 +395,23 @@ - (NSString *)userAgentForURL:(NSURL *)URL
}
// Now look up that last part in the gperf spoof table.
if (lastPeriod) {
const char *domain = nextToLastPeriod ? nextToLastPeriod + 1 : hostBuffer;
pretendToBeMacIE = _web_findSpoofTableEntry(domain, p - domain) != NULL;
const char *lastPart;
const struct UserAgentSpoofTableEntry *entry = NULL;
if (nextToLastPeriod) {
lastPart = thirdToLastPeriod ? thirdToLastPeriod + 1 : hostBuffer;
entry = _web_findSpoofTableEntry(lastPart, p - lastPart);
}
if (!entry) {
lastPart = nextToLastPeriod ? nextToLastPeriod + 1 : hostBuffer;
entry = _web_findSpoofTableEntry(lastPart, p - lastPart);
}
if (entry) {
type = entry->type;
}
}
}
NSString **userAgentStorage = pretendToBeMacIE
? &_private->userAgentWhenPretendingToBeMacIE : &_private->userAgent;
NSString **userAgentStorage = &_private->userAgent[type];
NSString *userAgent = *userAgentStorage;
if (userAgent) {
......@@ -409,7 +425,17 @@ - (NSString *)userAgentForURL:(NSURL *)URL
objectForInfoDictionaryKey:(id)kCFBundleVersionKey];
NSString *applicationName = _private->applicationNameForUserAgent;
if (pretendToBeMacIE) {
switch (type) {
case Safari:
if ([applicationName length]) {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko) %@",
language, sourceVersion, applicationName];
} else {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko)",
language, sourceVersion];
}
break;
case MacIE:
if ([applicationName length]) {
userAgent = [NSString stringWithFormat:@"Mozilla/4.0 (compatible; MSIE 5.2; Mac_PowerPC) AppleWebKit/%@ %@",
language, sourceVersion, applicationName];
......@@ -417,14 +443,16 @@ - (NSString *)userAgentForURL:(NSURL *)URL
userAgent = [NSString stringWithFormat:@"Mozilla/4.0 (compatible; MSIE 5.2; Mac_PowerPC) AppleWebKit/%@",
language, sourceVersion];
}
} else {
break;
case WinIE:
if ([applicationName length]) {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko) %@",
userAgent = [NSString stringWithFormat:@"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT) AppleWebKit/%@ %@",
language, sourceVersion, applicationName];
} else {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; %@) AppleWebKit/%@ (like Gecko)",
userAgent = [NSString stringWithFormat:@"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT) AppleWebKit/%@",
language, sourceVersion];
}
break;
}
*userAgentStorage = [userAgent retain];
......
......@@ -9,6 +9,9 @@
@class WebError;
@class WebFrame;
typedef enum { Safari, MacIE, WinIE } UserAgentStringType;
enum { NumUserAgentStringTypes = WinIE + 1 };
@interface WebControllerPrivate : NSObject
{
@public
......@@ -30,8 +33,7 @@
NSString *applicationNameForUserAgent;
NSString *userAgentOverride;
NSString *userAgent;
NSString *userAgentWhenPretendingToBeMacIE;
NSString *userAgent[NumUserAgentStringTypes];
BOOL defersCallbacks;
......
......@@ -64,8 +64,10 @@ - (void)dealloc
[backForwardList release];
[applicationNameForUserAgent release];
[userAgentOverride release];
[userAgent release];
[userAgentWhenPretendingToBeMacIE release];
int i;
for (i = 0; i != NumUserAgentStringTypes; ++i) {
[userAgent[i] release];
}
[controllerSetName release];
[topLevelFrameName release];
......@@ -334,10 +336,11 @@ - (void)_mouseDidMoveOverElement:(NSDictionary *)dictionary modifierFlags:(unsig
- (void)_defaultsDidChange
{
[_private->userAgent release];
_private->userAgent = nil;
[_private->userAgentWhenPretendingToBeMacIE release];
_private->userAgentWhenPretendingToBeMacIE = nil;
int i;
for (i = 0; i != NumUserAgentStringTypes; ++i) {
[_private->userAgent[i] release];
_private->userAgent[i] = nil;
}
}
@end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment