Home | History | Annotate | Download | only in loader
      1 /*
      2  * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
      3  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *
      9  * 1.  Redistributions of source code must retain the above copyright
     10  *     notice, this list of conditions and the following disclaimer.
     11  * 2.  Redistributions in binary form must reproduce the above copyright
     12  *     notice, this list of conditions and the following disclaimer in the
     13  *     documentation and/or other materials provided with the distribution.
     14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     15  *     its contributors may be used to endorse or promote products derived
     16  *     from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #ifndef PolicyChecker_h
     31 #define PolicyChecker_h
     32 
     33 #include "FrameLoaderTypes.h"
     34 #include "PlatformString.h"
     35 #include "PolicyCallback.h"
     36 #include "ResourceRequest.h"
     37 #include <wtf/PassRefPtr.h>
     38 
     39 namespace WebCore {
     40 
     41 class DocumentLoader;
     42 class FormState;
     43 class Frame;
     44 class NavigationAction;
     45 class ResourceError;
     46 class ResourceResponse;
     47 
     48 class PolicyChecker {
     49     WTF_MAKE_NONCOPYABLE(PolicyChecker);
     50 public:
     51     PolicyChecker(Frame*);
     52 
     53     void checkNavigationPolicy(const ResourceRequest&, DocumentLoader*, PassRefPtr<FormState>, NavigationPolicyDecisionFunction, void* argument);
     54     void checkNavigationPolicy(const ResourceRequest&, NavigationPolicyDecisionFunction, void* argument);
     55     void checkNewWindowPolicy(const NavigationAction&, NewWindowPolicyDecisionFunction, const ResourceRequest&, PassRefPtr<FormState>, const String& frameName, void* argument);
     56     void checkContentPolicy(const ResourceResponse&, ContentPolicyDecisionFunction, void* argument);
     57 
     58     // FIXME: These are different.  They could use better names.
     59     void cancelCheck();
     60     void stopCheck();
     61 
     62     void cannotShowMIMEType(const ResourceResponse&);
     63 
     64     FrameLoadType loadType() const { return m_loadType; }
     65     void setLoadType(FrameLoadType loadType) { m_loadType = loadType; }
     66 
     67     bool delegateIsDecidingNavigationPolicy() const { return m_delegateIsDecidingNavigationPolicy; }
     68     bool delegateIsHandlingUnimplementablePolicy() const { return m_delegateIsHandlingUnimplementablePolicy; }
     69 
     70     // FIXME: This function is a cheat.  Basically, this is just an asynchronouc callback
     71     // from the FrameLoaderClient, but this callback uses the policy types and so has to
     72     // live on this object.  In the long term, we should create a type for non-policy
     73     // callbacks from the FrameLoaderClient and remove this vestige.  I just don't have
     74     // the heart to hack on all the platforms to make that happen right now.
     75     void continueLoadAfterWillSubmitForm(PolicyAction);
     76 
     77 private:
     78     void continueAfterNavigationPolicy(PolicyAction);
     79     void continueAfterNewWindowPolicy(PolicyAction);
     80     void continueAfterContentPolicy(PolicyAction);
     81 
     82     void handleUnimplementablePolicy(const ResourceError&);
     83 
     84     Frame* m_frame;
     85 
     86     bool m_delegateIsDecidingNavigationPolicy;
     87     bool m_delegateIsHandlingUnimplementablePolicy;
     88 
     89     // This identifies the type of navigation action which prompted this load. Note
     90     // that WebKit conveys this value as the WebActionNavigationTypeKey value
     91     // on navigation action delegate callbacks.
     92     FrameLoadType m_loadType;
     93     PolicyCallback m_callback;
     94 };
     95 
     96 } // namespace WebCore
     97 
     98 #endif // PolicyChecker_h
     99