Changeset 20867 in webkit


Ignore:
Timestamp:
Apr 12, 2007, 9:32:51 PM (18 years ago)
Author:
ggaren
Message:

JavaScriptCore:

Reviewed by Darin Adler.

http://bugs.webkit.org/show_bug.cgi?id=13029
rdar://problem/4994849
Bug 13029: Permit NPAPI plug-ins to see HTTP response headers.
This doesn't actually change JavaScriptCore, but that's where npapi.h is.

  • bindings/npapi.h: Add headers member to NPStream struct. Also increase NP_VERSION_MINOR to 18. Increasing to >= 17 allows plug-ins to safely detect whether to look for NPStream::headers. Increasing from 17 to 18 reflects presence of NPObject enumeration, which was added in a prior patch, and which has been agreed to constitute version 18 by the plugin-futures list. Also add other missing bits of npapi.h to catch up from 14 to 18. This includes features that are not implemented in WebKit, but those are safely stubbed.

LayoutTests:

Reviewed by Darin Adler.

http://bugs.webkit.org/show_bug.cgi?id=13029
rdar://problem/4994849
Bug 13029: Permit NPAPI plug-ins to see HTTP response headers.

  • http/tests/plugins/npapi-response-headers-expected.txt: Added.
  • http/tests/plugins/npapi-response-headers.html: Added.
  • http/tests/plugins/resources/load-me-1.txt: Added.
  • http/tests/plugins/resources/load-me-2.txt: Added.

WebKit:

Reviewed by Darin Adler.

http://bugs.webkit.org/show_bug.cgi?id=13029
rdar://problem/4994849
Bug 13029: Permit NPAPI plug-ins to see HTTP response headers.

  • Plugins/WebBaseNetscapePluginStream.h: declarations.
  • Plugins/WebBaseNetscapePluginStream.mm: main implementation. (-[WebBaseNetscapePluginStream dealloc]): cleanup. (-[WebBaseNetscapePluginStream finalize]): cleanup. (-[WebBaseNetscapePluginStream startStreamResponseURL:expectedContentLength:lastModifiedDate:MIMEType:headers:]): Pass headers along. (-[WebBaseNetscapePluginStream startStreamWithResponse:]): Main work is here. Extract headers from NSHTTPURLResponse object into a byte sequence. See comments here about how it would be nice to have low-level access to the HTTP response. (-[WebBaseNetscapePluginStream _destroyStream]): cleanup.
  • Plugins/WebBaseNetscapePluginView.mm: (-[WebBaseNetscapePluginView evaluateJavaScriptPluginRequest:]): Conform to new startStream params. Not applicable here, pass nil.

WebKitTools:

Reviewed by Darin Adler.

http://bugs.webkit.org/show_bug.cgi?id=13029
rdar://problem/4994849
Bug 13029: Permit NPAPI plug-ins to see HTTP response headers.
Changes in WebKitTools are only for the NPAPI test plugin.

  • DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c: main test logic. (pluginInvoke): support null window argument for NPStream creation. (pluginAllocate): initialization. (pluginDeallocate): cleanup. (handleCallback): add second JS callback arg: header dump. (notifyStream): added; hook from NPP_NewStream to record headers.
  • DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.h: declarations.
  • DumpRenderTree/TestNetscapePlugIn.subproj/main.c: call new header hook. (NPP_NewStream): call new header hook.
Location:
trunk
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r20836 r20867  
     12007-04-12  Deneb Meketa  <[email protected]>
     2
     3        Reviewed by Darin Adler.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=13029
     6        rdar://problem/4994849
     7        Bug 13029: Permit NPAPI plug-ins to see HTTP response headers.
     8        This doesn't actually change JavaScriptCore, but that's where npapi.h is.
     9
     10        * bindings/npapi.h:
     11        Add headers member to NPStream struct.  Also increase NP_VERSION_MINOR to 18.
     12        Increasing to >= 17 allows plug-ins to safely detect whether to look for
     13        NPStream::headers.  Increasing from 17 to 18 reflects presence of NPObject
     14        enumeration, which was added in a prior patch, and which has been agreed to
     15        constitute version 18 by the plugin-futures list.  Also add other missing
     16        bits of npapi.h to catch up from 14 to 18.  This includes features that are
     17        not implemented in WebKit, but those are safely stubbed.
     18
    1192007-04-10  Geoffrey Garen  <[email protected]>
    220
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r20835 r20867  
    13901390                        isa = PBXProject;
    13911391                        buildConfigurationList = 149C277108902AFE008A9EFC /* Build configuration list for PBXProject "JavaScriptCore" */;
    1392                         compatibilityVersion = "Xcode 2.4";
    13931392                        hasScannedForEncodings = 1;
    13941393                        mainGroup = 0867D691FE84028FC02AAC07 /* JavaScriptCore */;
     
    13961395                        projectDirPath = "";
    13971396                        projectRoot = "";
    1398                         shouldCheckCompatibility = 1;
    13991397                        targets = (
    14001398                                932F5BE30822A1C700736975 /* All */,
  • trunk/JavaScriptCore/bindings/npapi.h

    r20613 r20867  
    105105
    106106#define NP_VERSION_MAJOR 0
    107 #define NP_VERSION_MINOR 17
     107#define NP_VERSION_MINOR 18
    108108
    109109
     
    188188    uint32       lastmodified;
    189189    void*        notifyData;
     190    const char*  headers;      /* Response headers from host.
     191                                * Exists only for >= NPVERS_HAS_RESPONSE_HEADERS.
     192                                * Used for HTTP only; NULL for non-HTTP.
     193                                * Available from NPP_NewStream onwards.
     194                                * Plugin should copy this data before storing it.
     195                                * Includes HTTP status line and all headers,
     196                                * preferably verbatim as received from server,
     197                                * headers formatted as in HTTP ("Header: Value"),
     198                                * and newlines (\n, NOT \r\n) separating lines.
     199                                * Terminated by \n\0 (NOT \n\n\0). */
    190200} NPStream;
    191201
     
    315325
    316326    /* Get the NPObject for scripting the plugin. */
    317     NPPVpluginScriptableNPObject  = 15
     327    NPPVpluginScriptableNPObject  = 15,
     328
     329    /* Get the plugin value (as \0-terminated UTF-8 string data) for
     330     * form submission if the plugin is part of a form. Use
     331     * NPN_MemAlloc() to allocate memory for the string data.
     332     */
     333    NPPVformValue = 16    /* Not implemented in WebKit */
    318334} NPPVariable;
    319335
     
    588604#define NPVERS_68K_HAS_LIVECONNECT    11
    589605#define NPVERS_HAS_WINDOWLESS       11
     606#define NPVERS_HAS_XPCONNECT_SCRIPTING    13  /* Not implemented in WebKit */
     607#define NPVERS_HAS_NPRUNTIME_SCRIPTING    14
     608#define NPVERS_HAS_FORM_VALUES            15  /* Not implemented in WebKit; see bug 13061 */
     609#define NPVERS_HAS_POPUPS_ENABLED_STATE   16  /* Not implemented in WebKit */
     610#define NPVERS_HAS_RESPONSE_HEADERS       17
     611#define NPVERS_HAS_NPOBJECT_ENUM          18
    590612
    591613
  • trunk/LayoutTests/ChangeLog

    r20866 r20867  
     12007-04-12  Deneb Meketa  <[email protected]>
     2
     3        Reviewed by Darin Adler.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=13029
     6        rdar://problem/4994849
     7        Bug 13029: Permit NPAPI plug-ins to see HTTP response headers.
     8
     9        * http/tests/plugins/npapi-response-headers-expected.txt: Added.
     10        * http/tests/plugins/npapi-response-headers.html: Added.
     11        * http/tests/plugins/resources/load-me-1.txt: Added.
     12        * http/tests/plugins/resources/load-me-2.txt: Added.
     13
    1142007-04-12  Justin Garcia  <[email protected]>
    215
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r20862 r20867  
    1127511275                        isa = PBXProject;
    1127611276                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
    11277                         compatibilityVersion = "Xcode 2.4";
    1127811277                        hasScannedForEncodings = 1;
    1127911278                        knownRegions = (
     
    1129011289                        projectDirPath = "";
    1129111290                        projectRoot = "";
    11292                         shouldCheckCompatibility = 1;
    1129311291                        targets = (
    1129411292                                93F198A508245E59001E9ABC /* WebCore */,
  • trunk/WebKit/ChangeLog

    r20863 r20867  
     12007-04-12  Deneb Meketa  <[email protected]>
     2
     3        Reviewed by Darin Adler.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=13029
     6        rdar://problem/4994849
     7        Bug 13029: Permit NPAPI plug-ins to see HTTP response headers.
     8
     9        * Plugins/WebBaseNetscapePluginStream.h: declarations.
     10        * Plugins/WebBaseNetscapePluginStream.mm: main implementation.
     11        (-[WebBaseNetscapePluginStream dealloc]): cleanup.
     12        (-[WebBaseNetscapePluginStream finalize]): cleanup.
     13        (-[WebBaseNetscapePluginStream startStreamResponseURL:expectedContentLength:lastModifiedDate:MIMEType:headers:]):
     14        Pass headers along.
     15        (-[WebBaseNetscapePluginStream startStreamWithResponse:]):
     16        Main work is here.  Extract headers from NSHTTPURLResponse object into a byte sequence.
     17        See comments here about how it would be nice to have low-level access to the HTTP response.
     18        (-[WebBaseNetscapePluginStream _destroyStream]): cleanup.
     19        * Plugins/WebBaseNetscapePluginView.mm:
     20        (-[WebBaseNetscapePluginView evaluateJavaScriptPluginRequest:]):
     21        Conform to new startStream params.  Not applicable here, pass nil.
     22
    1232007-04-12  Brady Eidson  <[email protected]>
    224
  • trunk/WebKit/Plugins/WebBaseNetscapePluginStream.h

    r20671 r20867  
    4949    BOOL sendNotification;
    5050    void *notifyData;
     51    char *headers;
    5152    WebBaseNetscapePluginView *pluginView;
    5253    NPReason reason;
     
    8182         expectedContentLength:(long long)expectedContentLength
    8283              lastModifiedDate:(NSDate *)lastModifiedDate
    83                       MIMEType:(NSString *)MIMEType;
     84                      MIMEType:(NSString *)MIMEType
     85                       headers:(NSData *)theHeaders;
    8486
    8587// cancelLoadWithError cancels the NSURLConnection and informs WebKit of the load error.
  • trunk/WebKit/Plugins/WebBaseNetscapePluginStream.mm

    r20671 r20867  
    142142    free((void *)stream.url);
    143143    free(path);
     144    free(headers);
    144145
    145146    streams().remove(&stream);
     
    159160    free((void *)stream.url);
    160161    free(path);
     162    free(headers);
    161163
    162164    streams().remove(&stream);
     
    229231              lastModifiedDate:(NSDate *)lastModifiedDate
    230232                      MIMEType:(NSString *)theMIMEType
     233                       headers:(NSData *)theHeaders
    231234{
    232235    ASSERT(!isTerminated);
     
    242245    stream.lastmodified = (uint32)[lastModifiedDate timeIntervalSince1970];
    243246    stream.notifyData = notifyData;
     247
     248    if (theHeaders) {
     249        unsigned len = [theHeaders length];
     250        headers = (char*) malloc(len + 1);
     251        [theHeaders getBytes:headers];
     252        headers[len] = 0;
     253        stream.headers = headers;
     254    }
    244255   
    245256    transferMode = NP_NORMAL;
     
    283294- (void)startStreamWithResponse:(NSURLResponse *)r
    284295{
     296    NSMutableData *theHeaders = nil;
     297    if ([r isKindOfClass:[NSHTTPURLResponse class]]) {
     298        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)r;
     299        theHeaders = [NSMutableData dataWithCapacity:1024];
     300       
     301        // FIXME: it would be nice to be able to get the raw HTTP header block.
     302        // This includes the HTTP version, the real status text,
     303        // all headers in their original order and including duplicates,
     304        // and all original bytes verbatim, rather than sent through Unicode translation.
     305        // Unfortunately NSHTTPURLResponse doesn't provide access at that low a level.
     306       
     307        [theHeaders appendBytes:"HTTP " length:5];
     308        char statusStr[10];
     309        snprintf(statusStr, sizeof(statusStr), "%d", [httpResponse statusCode]);
     310        [theHeaders appendBytes:statusStr length:strlen(statusStr)];
     311        [theHeaders appendBytes:" OK\n" length:4];
     312
     313        // HACK: pass the headers through as UTF-8.
     314        // This is not the intended behavior; we're supposed to pass original bytes verbatim.
     315        // But we don't have the original bytes, we have NSStrings built by the URL loading system.
     316        // It hopefully shouldn't matter, since RFC2616/RFC822 require ASCII-only headers,
     317        // but surely someone out there is using non-ASCII characters, and hopefully UTF-8 is adequate here.
     318        // It seems better than NSASCIIStringEncoding, which will lose information if non-ASCII is used.
     319
     320        NSDictionary *headerDict = [httpResponse allHeaderFields];
     321        NSArray *keys = [[headerDict allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
     322        NSEnumerator *i = [keys objectEnumerator];
     323        NSString *k;
     324        while ((k = [i nextObject]) != nil) {
     325            NSString *v = [headerDict objectForKey:k];
     326            [theHeaders appendData:[k dataUsingEncoding:NSUTF8StringEncoding]];
     327            [theHeaders appendBytes:": " length:2];
     328            [theHeaders appendData:[v dataUsingEncoding:NSUTF8StringEncoding]];
     329            [theHeaders appendBytes:"\n" length:1];
     330        }
     331
     332        // startStreamResponseURL:... will null-terminate.
     333    }
     334
    285335    [self startStreamResponseURL:[r URL]
    286336           expectedContentLength:[r expectedContentLength]
    287337                lastModifiedDate:WKGetNSURLResponseLastModifiedDate(r)
    288                         MIMEType:[r MIMEType]];
     338                        MIMEType:[r MIMEType]
     339                         headers:theHeaders];
    289340}
    290341
     
    331382        [pv didCallPlugInFunction];
    332383        LOG(Plugins, "NPP_DestroyStream responseURL=%@ error=%d", responseURL, npErr);
     384
     385        free(headers);
     386        headers = NULL;
     387        stream.headers = NULL;
    333388
    334389        stream.ndata = nil;
  • trunk/WebKit/Plugins/WebBaseNetscapePluginView.mm

    r20765 r20867  
    20432043                 expectedContentLength:[JSData length]
    20442044                      lastModifiedDate:nil
    2045                               MIMEType:@"text/plain"];
     2045                              MIMEType:@"text/plain"
     2046                               headers:nil];
    20462047        [stream receivedData:JSData];
    20472048        [stream finishedLoadingWithData:JSData];
  • trunk/WebKitTools/ChangeLog

    r20820 r20867  
     12007-04-12  Deneb Meketa  <[email protected]>
     2
     3        Reviewed by Darin Adler.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=13029
     6        rdar://problem/4994849
     7        Bug 13029: Permit NPAPI plug-ins to see HTTP response headers.
     8        Changes in WebKitTools are only for the NPAPI test plugin.
     9
     10        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c: main test logic.
     11        (pluginInvoke): support null window argument for NPStream creation.
     12        (pluginAllocate): initialization.
     13        (pluginDeallocate): cleanup.
     14        (handleCallback): add second JS callback arg: header dump.
     15        (notifyStream): added; hook from NPP_NewStream to record headers.
     16        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.h: declarations.
     17        * DumpRenderTree/TestNetscapePlugIn.subproj/main.c: call new header hook.
     18        (NPP_NewStream): call new header hook.
     19
    1202007-04-09  Geoffrey Garen  <[email protected]>
    221
  • trunk/WebKitTools/DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c

    r20742 r20867  
    242242        return true;
    243243    } else if (name == pluginMethodIdentifiers[ID_TEST_GET_URL_NOTIFY]) {
    244         if (argCount == 3 && NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[1]) && NPVARIANT_IS_STRING(args[2])) {
     244        if (argCount == 3
     245          && NPVARIANT_IS_STRING(args[0])
     246          && (NPVARIANT_IS_STRING(args[1]) || NPVARIANT_IS_NULL(args[1]))
     247          && NPVARIANT_IS_STRING(args[2])) {
    245248            NPUTF8* urlString = createCStringFromNPVariant(&args[0]);
    246             NPUTF8* targetString = createCStringFromNPVariant(&args[1]);           
     249            NPUTF8* targetString = (NPVARIANT_IS_STRING(args[1]) ? createCStringFromNPVariant(&args[1]) : NULL);
    247250            NPUTF8* callbackString = createCStringFromNPVariant(&args[2]);
    248251           
     
    333336    newInstance->stream = 0;
    334337   
     338    newInstance->firstUrl = NULL;
     339    newInstance->firstHeaders = NULL;
     340    newInstance->lastUrl = NULL;
     341    newInstance->lastHeaders = NULL;
     342   
    335343    return (NPObject *)newInstance;
    336344}
     
    341349   
    342350    browser->releaseobject(obj->testObject);
    343    
    344     free(header);
     351
     352    free(obj->firstUrl);
     353    free(obj->firstHeaders);
     354    free(obj->lastUrl);
     355    free(obj->lastHeaders);
     356
     357    free(obj);
    345358}
    346359
     
    349362    assert(object);
    350363   
    351     NPVariant args[1];
     364    NPVariant args[2];
    352365   
    353366    NPObject *windowScriptObject;
     
    358371    INT32_TO_NPVARIANT(reason, args[0]);
    359372
     373    char *strHdr = NULL;
     374    if (object->firstUrl && object->firstHeaders && object->lastUrl && object->lastHeaders) {
     375        // Format expected by JavaScript validator: four fields separated by \n\n:
     376        // First URL; first header block; last URL; last header block.
     377        // Note that header blocks already end with \n due to how NPStream::headers works.
     378        int len = strlen(object->firstUrl) + 2
     379            + strlen(object->firstHeaders) + 1
     380            + strlen(object->lastUrl) + 2
     381            + strlen(object->lastHeaders) + 1;
     382        strHdr = malloc(len + 1);
     383        snprintf(strHdr, len + 1, "%s\n\n%s\n%s\n\n%s\n",
     384                 object->firstUrl, object->firstHeaders, object->lastUrl, object->lastHeaders);
     385        STRINGN_TO_NPVARIANT(strHdr, len, args[1]);
     386    } else
     387        NULL_TO_NPVARIANT(args[1]);
     388
    360389    NPVariant browserResult;
    361     browser->invoke(object->npp, windowScriptObject, callbackIdentifier, args, 1, &browserResult);
     390    browser->invoke(object->npp, windowScriptObject, callbackIdentifier, args, 2, &browserResult);
    362391    browser->releasevariantvalue(&browserResult);
    363 }
     392
     393    free(strHdr);
     394}
     395
     396void notifyStream(PluginObject* object, const char *url, const char *headers)
     397{
     398    if (object->firstUrl == NULL) {
     399        if (url)
     400            object->firstUrl = strdup(url);
     401        if (headers)
     402            object->firstHeaders = strdup(headers);
     403    } else {
     404        free(object->lastUrl);
     405        free(object->lastHeaders);
     406        object->lastUrl = (url ? strdup(url) : NULL);
     407        object->lastHeaders = (headers ? strdup(headers) : NULL);
     408    }
     409}
  • trunk/WebKitTools/DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.h

    r20742 r20867  
    4444    NPStream* stream;
    4545    char* onStreamLoad;
     46    char* firstUrl;
     47    char* firstHeaders;
     48    char* lastUrl;
     49    char* lastHeaders;
    4650} PluginObject;
    4751
    4852extern NPClass *getPluginClass(void);
    4953extern void handleCallback(PluginObject* object, const char *url, NPReason reason, void *notifyData);
     54extern void notifyStream(PluginObject* object, const char *url, const char *headers);
  • trunk/WebKitTools/DumpRenderTree/TestNetscapePlugIn.subproj/main.c

    r20742 r20867  
    115115    *stype = NP_ASFILEONLY;
    116116
     117    if (obj && (browser->version >= NPVERS_HAS_RESPONSE_HEADERS))
     118        notifyStream(obj, stream->url, stream->headers);
     119
    117120    if (obj->onStreamLoad) {
    118121        NPObject *windowScriptObject;
Note: See TracChangeset for help on using the changeset viewer.