WebKitTools/DumpRenderTree/chromium/WebViewHost.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2010 Google 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 are
       
     6  * met:
       
     7  *
       
     8  *     * Redistributions of source code must retain the above copyright
       
     9  * notice, this list of conditions and the following disclaimer.
       
    10  *     * Redistributions in binary form must reproduce the above
       
    11  * copyright notice, this list of conditions and the following disclaimer
       
    12  * in the documentation and/or other materials provided with the
       
    13  * distribution.
       
    14  *     * Neither the name of Google Inc. nor the names of its
       
    15  * contributors may be used to endorse or promote products derived from
       
    16  * this software without specific prior written permission.
       
    17  *
       
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29  */
       
    30 
       
    31 #ifndef WebViewHost_h
       
    32 #define WebViewHost_h
       
    33 
       
    34 #include "MockSpellCheck.h"
       
    35 #include "TestNavigationController.h"
       
    36 #include "public/WebCursorInfo.h"
       
    37 #include "public/WebFrameClient.h"
       
    38 #include "public/WebViewClient.h"
       
    39 #include <wtf/HashMap.h>
       
    40 #include <wtf/HashSet.h>
       
    41 #include <wtf/Vector.h>
       
    42 #include <wtf/text/WTFString.h>
       
    43 
       
    44 class LayoutTestController;
       
    45 class TestShell;
       
    46 namespace WebKit {
       
    47 class WebFrame;
       
    48 class WebGeolocationServiceMock;
       
    49 class WebURL;
       
    50 struct WebRect;
       
    51 struct WebURLError;
       
    52 struct WebWindowFeatures;
       
    53 }
       
    54 namespace skia {
       
    55 class PlatformCanvas;
       
    56 }
       
    57 
       
    58 class WebViewHost : public WebKit::WebViewClient, public WebKit::WebFrameClient, public NavigationHost {
       
    59  public:
       
    60     WebViewHost(TestShell* shell);
       
    61     ~WebViewHost();
       
    62     void setWebWidget(WebKit::WebWidget* widget) { m_webWidget = widget; }
       
    63     WebKit::WebView* webView() const;
       
    64     WebKit::WebWidget* webWidget() const;
       
    65     void reset();
       
    66     void setSelectTrailingWhitespaceEnabled(bool);
       
    67     void setSmartInsertDeleteEnabled(bool);
       
    68     void waitForPolicyDelegate();
       
    69     void setCustomPolicyDelegate(bool, bool);
       
    70     WebKit::WebFrame* topLoadingFrame() { return m_topLoadingFrame; }
       
    71     void setBlockRedirects(bool block) { m_blocksRedirects = block; }
       
    72     void setRequestReturnNull(bool returnNull) { m_requestReturnNull = returnNull; }
       
    73     void setEditCommand(const std::string& name, const std::string& value);
       
    74     void clearEditCommand();
       
    75     void setPendingExtraData(TestShellExtraData*);
       
    76 
       
    77     void paintRect(const WebKit::WebRect&);
       
    78     void updatePaintRect(const WebKit::WebRect&);
       
    79     void paintInvalidatedRegion();
       
    80     skia::PlatformCanvas* canvas();
       
    81     void displayRepaintMask();
       
    82 
       
    83     void loadURLForFrame(const WebKit::WebURL&, const WebKit::WebString& frameName);
       
    84     TestNavigationController* navigationController() { return m_navigationController.get(); }
       
    85 
       
    86     void addClearHeader(const WebCore::String& header) { m_clearHeaders.add(header); }
       
    87     const HashSet<WebCore::String>& clearHeaders() const { return m_clearHeaders; }
       
    88 
       
    89     // NavigationHost
       
    90     virtual bool navigate(const TestNavigationEntry&, bool reload);
       
    91 
       
    92     // WebKit::WebViewClient
       
    93     virtual WebKit::WebView* createView(WebKit::WebFrame*, const WebKit::WebWindowFeatures&, const WebKit::WebString&);
       
    94     virtual WebKit::WebWidget* createPopupMenu(WebKit::WebPopupType);
       
    95     virtual WebKit::WebWidget* createPopupMenu(const WebKit::WebPopupMenuInfo&);
       
    96     virtual WebKit::WebStorageNamespace* createSessionStorageNamespace(unsigned quota);
       
    97     virtual void didAddMessageToConsole(const WebKit::WebConsoleMessage&, const WebKit::WebString& sourceName, unsigned sourceLine);
       
    98     virtual void didStartLoading();
       
    99     virtual void didStopLoading();
       
   100     virtual bool shouldBeginEditing(const WebKit::WebRange&);
       
   101     virtual bool shouldEndEditing(const WebKit::WebRange&);
       
   102     virtual bool shouldInsertNode(const WebKit::WebNode&, const WebKit::WebRange&, WebKit::WebEditingAction);
       
   103     virtual bool shouldInsertText(const WebKit::WebString&, const WebKit::WebRange&, WebKit::WebEditingAction);
       
   104     virtual bool shouldChangeSelectedRange(const WebKit::WebRange& from, const WebKit::WebRange& to, WebKit::WebTextAffinity, bool stillSelecting);
       
   105     virtual bool shouldDeleteRange(const WebKit::WebRange&);
       
   106     virtual bool shouldApplyStyle(const WebKit::WebString& style, const WebKit::WebRange&);
       
   107     virtual bool isSmartInsertDeleteEnabled();
       
   108     virtual bool isSelectTrailingWhitespaceEnabled();
       
   109     virtual void didBeginEditing();
       
   110     virtual void didChangeSelection(bool isSelectionEmpty);
       
   111     virtual void didChangeContents();
       
   112     virtual void didEndEditing();
       
   113     virtual bool handleCurrentKeyboardEvent();
       
   114     virtual void spellCheck(const WebKit::WebString&, int& offset, int& length);
       
   115     virtual WebKit::WebString autoCorrectWord(const WebKit::WebString&);
       
   116     virtual void runModalAlertDialog(WebKit::WebFrame*, const WebKit::WebString&);
       
   117     virtual bool runModalConfirmDialog(WebKit::WebFrame*, const WebKit::WebString&);
       
   118     virtual bool runModalPromptDialog(WebKit::WebFrame*, const WebKit::WebString& message, const WebKit::WebString& defaultValue, WebKit::WebString* actualValue);
       
   119     virtual bool runModalBeforeUnloadDialog(WebKit::WebFrame*, const WebKit::WebString&);
       
   120     virtual void showContextMenu(WebKit::WebFrame*, const WebKit::WebContextMenuData&);
       
   121     virtual void setStatusText(const WebKit::WebString&);
       
   122     virtual void startDragging(const WebKit::WebDragData&, WebKit::WebDragOperationsMask, const WebKit::WebImage&, const WebKit::WebPoint&);
       
   123     virtual void navigateBackForwardSoon(int offset);
       
   124     virtual int historyBackListCount();
       
   125     virtual int historyForwardListCount();
       
   126     virtual void focusAccessibilityObject(const WebKit::WebAccessibilityObject&);
       
   127     virtual WebKit::WebNotificationPresenter* notificationPresenter();
       
   128     virtual WebKit::WebGeolocationService* geolocationService();
       
   129 
       
   130     // WebKit::WebWidgetClient
       
   131     virtual void didInvalidateRect(const WebKit::WebRect&);
       
   132     virtual void didScrollRect(int dx, int dy, const WebKit::WebRect&);
       
   133     virtual void didFocus();
       
   134     virtual void didBlur();
       
   135     virtual void didChangeCursor(const WebKit::WebCursorInfo&);
       
   136     virtual void closeWidgetSoon();
       
   137     virtual void show(WebKit::WebNavigationPolicy);
       
   138     virtual void runModal();
       
   139     virtual WebKit::WebRect windowRect();
       
   140     virtual void setWindowRect(const WebKit::WebRect&);
       
   141     virtual WebKit::WebRect rootWindowRect();
       
   142     virtual WebKit::WebRect windowResizerRect();
       
   143     virtual WebKit::WebScreenInfo screenInfo();
       
   144 
       
   145     // WebKit::WebFrameClient
       
   146     virtual WebKit::WebPlugin* createPlugin(WebKit::WebFrame*, const WebKit::WebPluginParams&);
       
   147     virtual WebKit::WebWorker* createWorker(WebKit::WebFrame*, WebKit::WebWorkerClient*);
       
   148     virtual WebKit::WebMediaPlayer* createMediaPlayer(WebKit::WebFrame*, WebKit::WebMediaPlayerClient*);
       
   149     virtual WebKit::WebApplicationCacheHost* createApplicationCacheHost(WebKit::WebFrame*, WebKit::WebApplicationCacheHostClient*);
       
   150      virtual bool allowPlugins(WebKit::WebFrame*, bool enabledPerSettings);
       
   151     virtual bool allowImages(WebKit::WebFrame*, bool enabledPerSettings);
       
   152     virtual void loadURLExternally(WebKit::WebFrame*, const WebKit::WebURLRequest&, WebKit::WebNavigationPolicy);
       
   153     virtual WebKit::WebNavigationPolicy decidePolicyForNavigation(
       
   154         WebKit::WebFrame*, const WebKit::WebURLRequest&,
       
   155         WebKit::WebNavigationType, const WebKit::WebNode&,
       
   156         WebKit::WebNavigationPolicy, bool isRedirect);
       
   157     virtual bool canHandleRequest(WebKit::WebFrame*, const WebKit::WebURLRequest&);
       
   158     virtual WebKit::WebURLError cannotHandleRequestError(WebKit::WebFrame*, const WebKit::WebURLRequest&);
       
   159     virtual WebKit::WebURLError cancelledError(WebKit::WebFrame*, const WebKit::WebURLRequest&);
       
   160     virtual void unableToImplementPolicyWithError(WebKit::WebFrame*, const WebKit::WebURLError&);
       
   161     virtual void willPerformClientRedirect(
       
   162         WebKit::WebFrame*, const WebKit::WebURL& from, const WebKit::WebURL& to,
       
   163         double interval, double fireTime);
       
   164     virtual void didCancelClientRedirect(WebKit::WebFrame*);
       
   165     virtual void didCreateDataSource(WebKit::WebFrame*, WebKit::WebDataSource*);
       
   166     virtual void didStartProvisionalLoad(WebKit::WebFrame*);
       
   167     virtual void didReceiveServerRedirectForProvisionalLoad(WebKit::WebFrame*);
       
   168     virtual void didFailProvisionalLoad(WebKit::WebFrame*, const WebKit::WebURLError&);
       
   169     virtual void didCommitProvisionalLoad(WebKit::WebFrame*, bool isNewNavigation);
       
   170     virtual void didClearWindowObject(WebKit::WebFrame*);
       
   171     virtual void didReceiveTitle(WebKit::WebFrame*, const WebKit::WebString&);
       
   172     virtual void didFinishDocumentLoad(WebKit::WebFrame*);
       
   173     virtual void didHandleOnloadEvents(WebKit::WebFrame*);
       
   174     virtual void didFailLoad(WebKit::WebFrame*, const WebKit::WebURLError&);
       
   175     virtual void didFinishLoad(WebKit::WebFrame*);
       
   176     virtual void didNavigateWithinPage(WebKit::WebFrame*, bool isNewNavigation);
       
   177     virtual void didChangeLocationWithinPage(WebKit::WebFrame*);
       
   178     virtual void assignIdentifierToRequest(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLRequest&);
       
   179     virtual void willSendRequest(WebKit::WebFrame*, unsigned identifier, WebKit::WebURLRequest&, const WebKit::WebURLResponse&);
       
   180     virtual void didReceiveResponse(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLResponse&);
       
   181     virtual void didFinishResourceLoad(WebKit::WebFrame*, unsigned identifier);
       
   182     virtual void didFailResourceLoad(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLError&);
       
   183     virtual void didDisplayInsecureContent(WebKit::WebFrame*);
       
   184     virtual void didRunInsecureContent(WebKit::WebFrame*, const WebKit::WebSecurityOrigin&);
       
   185     virtual bool allowScript(WebKit::WebFrame*, bool enabledPerSettings);
       
   186 
       
   187 private:
       
   188     LayoutTestController* layoutTestController() const;
       
   189 
       
   190     // Called the title of the page changes.
       
   191     // Can be used to update the title of the window.
       
   192     void setPageTitle(const WebKit::WebString&);
       
   193 
       
   194     // Called when the URL of the page changes.
       
   195     // Extracts the URL and forwards on to SetAddressBarURL().
       
   196     void updateAddressBar(WebKit::WebView*);
       
   197 
       
   198     // Called when the URL of the page changes.
       
   199     // Should be used to update the text of the URL bar.
       
   200     void setAddressBarURL(const WebKit::WebURL&);
       
   201 
       
   202     // In the Mac code, this is called to trigger the end of a test after the
       
   203     // page has finished loading.  From here, we can generate the dump for the
       
   204     // test.
       
   205     void locationChangeDone(WebKit::WebFrame*);
       
   206 
       
   207     void updateForCommittedLoad(WebKit::WebFrame*, bool isNewNavigation);
       
   208     void updateURL(WebKit::WebFrame*);
       
   209     void updateSessionHistory(WebKit::WebFrame*);
       
   210 
       
   211     // Dumping a frame to the console.
       
   212     void printFrameDescription(WebKit::WebFrame*);
       
   213 
       
   214     bool hasWindow() const { return m_hasWindow; }
       
   215     void resetScrollRect();
       
   216     void discardBackingStore();
       
   217 
       
   218     // Causes navigation actions just printout the intended navigation instead
       
   219     // of taking you to the page. This is used for cases like mailto, where you
       
   220     // don't actually want to open the mail program.
       
   221     bool m_policyDelegateEnabled;
       
   222 
       
   223     // Toggles the behavior of the policy delegate.  If true, then navigations
       
   224     // will be allowed.  Otherwise, they will be ignored (dropped).
       
   225     bool m_policyDelegateIsPermissive;
       
   226 
       
   227     // If true, the policy delegate will signal layout test completion.
       
   228     bool m_policyDelegateShouldNotifyDone;
       
   229 
       
   230     // Non-owning pointer. The WebViewHost instance is owned by this TestShell instance.
       
   231     TestShell* m_shell;
       
   232 
       
   233     // This delegate works for the following widget.
       
   234     WebKit::WebWidget* m_webWidget;
       
   235 
       
   236     // This is non-0 IFF a load is in progress.
       
   237     WebKit::WebFrame* m_topLoadingFrame;
       
   238 
       
   239     // For tracking session history.  See RenderView.
       
   240     int m_pageId;
       
   241     int m_lastPageIdUpdated;
       
   242 
       
   243     OwnPtr<TestShellExtraData> m_pendingExtraData;
       
   244 
       
   245     // Maps resource identifiers to a descriptive string.
       
   246     typedef HashMap<unsigned, std::string> ResourceMap;
       
   247     ResourceMap m_resourceIdentifierMap;
       
   248     void printResourceDescription(unsigned identifier);
       
   249 
       
   250     WebKit::WebCursorInfo m_currentCursor;
       
   251 
       
   252     bool m_hasWindow;
       
   253     WebKit::WebRect m_windowRect;
       
   254 
       
   255     // true if we want to enable smart insert/delete.
       
   256     bool m_smartInsertDeleteEnabled;
       
   257 
       
   258     // true if we want to enable selection of trailing whitespaces
       
   259     bool m_selectTrailingWhitespaceEnabled;
       
   260 
       
   261     // Set of headers to clear in willSendRequest.
       
   262     HashSet<WebCore::String> m_clearHeaders;
       
   263 
       
   264     // true if we should block any redirects
       
   265     bool m_blocksRedirects;
       
   266 
       
   267     // true if we should block (set an empty request for) any requests
       
   268     bool m_requestReturnNull;
       
   269 
       
   270     // Edit command associated to the current keyboard event.
       
   271     std::string m_editCommandName;
       
   272     std::string m_editCommandValue;
       
   273 
       
   274     // The mock spellchecker used in spellCheck().
       
   275     MockSpellCheck m_spellcheck;
       
   276 
       
   277     // Painting.
       
   278     OwnPtr<skia::PlatformCanvas> m_canvas;
       
   279     WebKit::WebRect m_paintRect;
       
   280     bool m_isPainting;
       
   281 
       
   282     // Geolocation
       
   283     OwnPtr<WebKit::WebGeolocationServiceMock> m_geolocationServiceMock;
       
   284 
       
   285     OwnPtr<TestNavigationController*> m_navigationController;
       
   286 };
       
   287 
       
   288 #endif // WebViewHost_h