Home | History | Annotate | Download | only in InjectedBundle
      1 /*
      2  * Copyright (C) 2010 Apple 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  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef InjectedBundle_h
     27 #define InjectedBundle_h
     28 
     29 #include "EventSendingController.h"
     30 #include "GCController.h"
     31 #include "LayoutTestController.h"
     32 #include <WebKit2/WKBase.h>
     33 #include <WebKit2/WKRetainPtr.h>
     34 #include <wtf/OwnPtr.h>
     35 #include <wtf/RefPtr.h>
     36 #include <wtf/Vector.h>
     37 
     38 #include <sstream>
     39 
     40 namespace WTR {
     41 
     42 class InjectedBundlePage;
     43 
     44 class InjectedBundle {
     45 public:
     46     static InjectedBundle& shared();
     47 
     48     // Initialize the InjectedBundle.
     49     void initialize(WKBundleRef, WKTypeRef initializationUserData);
     50 
     51     WKBundleRef bundle() const { return m_bundle; }
     52     WKBundlePageGroupRef pageGroup() const { return m_pageGroup; }
     53 
     54     LayoutTestController* layoutTestController() { return m_layoutTestController.get(); }
     55     GCController* gcController() { return m_gcController.get(); }
     56     EventSendingController* eventSendingController() { return m_eventSendingController.get(); }
     57 
     58     InjectedBundlePage* page() const;
     59     size_t pageCount() const { return m_pages.size(); }
     60     void closeOtherPages();
     61 
     62     void dumpBackForwardListsForAllPages();
     63 
     64     void done();
     65     std::ostringstream& os() { return m_outputStream; }
     66     void setPixelResult(WKImageRef image) { m_pixelResult = image; }
     67 
     68     bool isTestRunning() { return m_state == Testing; }
     69 
     70     WKBundleFrameRef topLoadingFrame() { return m_topLoadingFrame; }
     71     void setTopLoadingFrame(WKBundleFrameRef frame) { m_topLoadingFrame = frame; }
     72 
     73     bool shouldDumpPixels() const { return m_dumpPixels; }
     74 
     75 private:
     76     InjectedBundle();
     77     ~InjectedBundle();
     78 
     79     static void didCreatePage(WKBundleRef, WKBundlePageRef, const void* clientInfo);
     80     static void willDestroyPage(WKBundleRef, WKBundlePageRef, const void* clientInfo);
     81     static void didInitializePageGroup(WKBundleRef, WKBundlePageGroupRef, const void* clientInfo);
     82     static void didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo);
     83 
     84     void didCreatePage(WKBundlePageRef);
     85     void willDestroyPage(WKBundlePageRef);
     86     void didInitializePageGroup(WKBundlePageGroupRef);
     87     void didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody);
     88 
     89     void platformInitialize(WKTypeRef initializationUserData);
     90     void resetLocalSettings();
     91 
     92     void beginTesting();
     93 
     94     WKBundleRef m_bundle;
     95     WKBundlePageGroupRef m_pageGroup;
     96     Vector<OwnPtr<InjectedBundlePage> > m_pages;
     97 
     98     RefPtr<LayoutTestController> m_layoutTestController;
     99     RefPtr<GCController> m_gcController;
    100     RefPtr<EventSendingController> m_eventSendingController;
    101 
    102     WKBundleFrameRef m_topLoadingFrame;
    103 
    104     std::ostringstream m_outputStream;
    105 
    106     enum State {
    107         Idle,
    108         Testing,
    109         Stopping
    110     };
    111     State m_state;
    112 
    113     bool m_dumpPixels;
    114 
    115     WKRetainPtr<WKImageRef> m_pixelResult;
    116 };
    117 
    118 } // namespace WTR
    119 
    120 #endif // InjectedBundle_h
    121