webengine/osswebengine/WebKit/Plugins/WebNetscapePluginStream.mm
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  *
       
     8  * 1.  Redistributions of source code must retain the above copyright
       
     9  *     notice, this list of conditions and the following disclaimer. 
       
    10  * 2.  Redistributions in binary form must reproduce the above copyright
       
    11  *     notice, this list of conditions and the following disclaimer in the
       
    12  *     documentation and/or other materials provided with the distribution. 
       
    13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    14  *     its contributors may be used to endorse or promote products derived
       
    15  *     from this software without specific prior written permission. 
       
    16  *
       
    17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    27  */
       
    28 #ifndef __LP64__
       
    29 #import <WebKit/WebNetscapePluginStream.h>
       
    30 
       
    31 #import <Foundation/NSURLConnection.h>
       
    32 #import <WebCore/DocumentLoader.h>
       
    33 #import <WebCore/Frame.h>
       
    34 #import <WebCore/FrameLoader.h>
       
    35 #import <WebCore/NetscapePlugInStreamLoader.h>
       
    36 #import <WebKit/WebDataSourceInternal.h>
       
    37 #import <WebKit/WebFrameBridge.h>
       
    38 #import <WebKit/WebFrameInternal.h>
       
    39 #import <WebKit/WebKitErrorsPrivate.h>
       
    40 #import <WebKit/WebKitLogging.h>
       
    41 #import <WebKit/WebNSURLRequestExtras.h>
       
    42 #import <WebKit/WebNetscapePluginEmbeddedView.h>
       
    43 #import <WebKit/WebNetscapePluginPackage.h>
       
    44 #import <WebKit/WebViewInternal.h>
       
    45 #import <WebCore/ResourceError.h>
       
    46 #import <WebCore/WebCoreObjCExtras.h>
       
    47 #import <wtf/PassRefPtr.h>
       
    48 
       
    49 using namespace WebCore;
       
    50 
       
    51 @implementation WebNetscapePluginStream
       
    52 
       
    53 #ifndef BUILDING_ON_TIGER
       
    54 + (void)initialize
       
    55 {
       
    56     WebCoreObjCFinalizeOnMainThread(self);
       
    57 }
       
    58 #endif
       
    59 
       
    60 - (id)initWithFrameLoader:(FrameLoader *)frameLoader
       
    61 {
       
    62     _frameLoader = frameLoader;
       
    63     
       
    64     return self;
       
    65 }
       
    66 
       
    67 - (id)initWithRequest:(NSURLRequest *)theRequest
       
    68            plugin:(NPP)thePlugin
       
    69        notifyData:(void *)theNotifyData 
       
    70  sendNotification:(BOOL)flag
       
    71 {   
       
    72     WebBaseNetscapePluginView *view = (WebBaseNetscapePluginView *)thePlugin->ndata;
       
    73 
       
    74     if (!core([view webFrame])->loader()->canLoad([theRequest URL], core([view webFrame])->document()))
       
    75         return nil;
       
    76 
       
    77     if ([self initWithRequestURL:[theRequest URL]
       
    78                           plugin:thePlugin
       
    79                        notifyData:theNotifyData
       
    80                  sendNotification:flag] == nil) {
       
    81         return nil;
       
    82     }
       
    83     
       
    84     // Temporarily set isTerminated to YES to avoid assertion failure in dealloc in case we are released in this method.
       
    85     isTerminated = YES;
       
    86     
       
    87     request = [theRequest mutableCopy];
       
    88     if (core([view webFrame])->loader()->shouldHideReferrer([theRequest URL], core([view webFrame])->loader()->outgoingReferrer()))
       
    89         [(NSMutableURLRequest *)request _web_setHTTPReferrer:nil];
       
    90 
       
    91     _loader = NetscapePlugInStreamLoader::create(core([view webFrame]), self).releaseRef();
       
    92     
       
    93     isTerminated = NO;
       
    94 
       
    95     return self;
       
    96 }
       
    97 
       
    98 - (void)dealloc
       
    99 {
       
   100     if (_loader)
       
   101         _loader->deref();
       
   102     [request release];
       
   103     [super dealloc];
       
   104 }
       
   105 
       
   106 - (void)finalize
       
   107 {
       
   108     ASSERT_MAIN_THREAD();
       
   109     if (_loader)
       
   110         _loader->deref();
       
   111     [super finalize];
       
   112 }
       
   113 
       
   114 - (void)start
       
   115 {
       
   116     ASSERT(request);
       
   117     ASSERT(!_frameLoader);
       
   118     
       
   119     _loader->documentLoader()->addPlugInStreamLoader(_loader);
       
   120     _loader->load(request);
       
   121 }
       
   122 
       
   123 - (void)cancelLoadWithError:(NSError *)error
       
   124 {
       
   125     if (_frameLoader) {
       
   126         ASSERT(!_loader);
       
   127     
       
   128         DocumentLoader* documentLoader = _frameLoader->activeDocumentLoader();
       
   129         ASSERT(documentLoader);
       
   130         
       
   131         if (documentLoader->isLoadingMainResource())
       
   132             documentLoader->cancelMainResourceLoad(error);
       
   133         return;
       
   134     }
       
   135     
       
   136     if (!_loader->isDone())
       
   137         _loader->cancel(error);
       
   138 }
       
   139 
       
   140 - (void)stop
       
   141 {
       
   142     ASSERT(!_frameLoader);
       
   143     
       
   144     if (!_loader->isDone())
       
   145         [self cancelLoadAndDestroyStreamWithError:_loader->cancelledError()];
       
   146 }
       
   147 
       
   148 @end
       
   149 #endif