2009-07-24 21:11:01 +02:00
|
|
|
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// BrowserWebViewDelegate class:
|
|
|
|
// This class implements the WebViewDelegate methods for the test shell. One
|
|
|
|
// instance is owned by each CefBrowser.
|
|
|
|
|
|
|
|
#ifndef _BROWSER_WEBVIEW_DELEGATE_H
|
|
|
|
#define _BROWSER_WEBVIEW_DELEGATE_H
|
|
|
|
|
|
|
|
#include "build/build_config.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
#include <gdk/gdkcursor.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
2009-09-17 18:56:32 +02:00
|
|
|
#include "base/scoped_ptr.h"
|
|
|
|
#include "base/weak_ptr.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebFrameClient.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebViewClient.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#include "webkit/glue/webcursor.h"
|
2009-09-17 18:56:32 +02:00
|
|
|
#include "webkit/glue/webplugin_page_delegate.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "browser_drag_delegate.h"
|
|
|
|
#include "browser_drop_delegate.h"
|
|
|
|
#endif
|
|
|
|
#include "browser_navigation_controller.h"
|
|
|
|
|
|
|
|
class CefBrowserImpl;
|
|
|
|
struct WebPreferences;
|
|
|
|
class GURL;
|
|
|
|
class WebWidgetHost;
|
2010-01-20 17:43:47 +01:00
|
|
|
class FilePath;
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2009-10-22 01:27:29 +02:00
|
|
|
class BrowserWebViewDelegate : public WebKit::WebViewClient,
|
2009-09-17 18:56:32 +02:00
|
|
|
public WebKit::WebFrameClient,
|
|
|
|
public webkit_glue::WebPluginPageDelegate,
|
|
|
|
public base::SupportsWeakPtr<BrowserWebViewDelegate> {
|
2009-07-24 21:11:01 +02:00
|
|
|
public:
|
2009-09-17 18:56:32 +02:00
|
|
|
// WebKit::WebViewClient
|
2009-10-22 01:27:29 +02:00
|
|
|
virtual WebKit::WebView* createView(WebKit::WebFrame* creator);
|
2009-09-17 18:56:32 +02:00
|
|
|
virtual WebKit::WebWidget* createPopupMenu(bool activatable);
|
|
|
|
virtual WebKit::WebWidget* createPopupMenu(
|
|
|
|
const WebKit::WebPopupMenuInfo& info);
|
|
|
|
virtual void didAddMessageToConsole(
|
|
|
|
const WebKit::WebConsoleMessage& message,
|
|
|
|
const WebKit::WebString& source_name, unsigned source_line);
|
|
|
|
virtual void didStartLoading();
|
|
|
|
virtual void didStopLoading();
|
2009-09-22 18:34:27 +02:00
|
|
|
virtual bool shouldBeginEditing(const WebKit::WebRange& range);
|
|
|
|
virtual bool shouldEndEditing(const WebKit::WebRange& range);
|
|
|
|
virtual bool shouldInsertNode(
|
|
|
|
const WebKit::WebNode& node, const WebKit::WebRange& range,
|
|
|
|
WebKit::WebEditingAction action);
|
|
|
|
virtual bool shouldInsertText(
|
|
|
|
const WebKit::WebString& text, const WebKit::WebRange& range,
|
|
|
|
WebKit::WebEditingAction action);
|
|
|
|
virtual bool shouldChangeSelectedRange(
|
|
|
|
const WebKit::WebRange& from, const WebKit::WebRange& to,
|
|
|
|
WebKit::WebTextAffinity affinity, bool still_selecting);
|
|
|
|
virtual bool shouldDeleteRange(const WebKit::WebRange& range);
|
|
|
|
virtual bool shouldApplyStyle(
|
|
|
|
const WebKit::WebString& style, const WebKit::WebRange& range);
|
|
|
|
virtual bool isSmartInsertDeleteEnabled();
|
|
|
|
virtual bool isSelectTrailingWhitespaceEnabled();
|
2010-01-12 02:37:00 +01:00
|
|
|
virtual bool handleCurrentKeyboardEvent();
|
2009-10-13 03:39:30 +02:00
|
|
|
virtual bool runFileChooser(
|
|
|
|
bool multi_select, const WebKit::WebString& title,
|
|
|
|
const WebKit::WebString& initial_value,
|
|
|
|
WebKit::WebFileChooserCompletion* chooser_completion);
|
2009-09-17 18:56:32 +02:00
|
|
|
virtual void runModalAlertDialog(
|
|
|
|
WebKit::WebFrame* frame, const WebKit::WebString& message);
|
|
|
|
virtual bool runModalConfirmDialog(
|
|
|
|
WebKit::WebFrame* frame, const WebKit::WebString& message);
|
|
|
|
virtual bool runModalPromptDialog(
|
|
|
|
WebKit::WebFrame* frame, const WebKit::WebString& message,
|
|
|
|
const WebKit::WebString& default_value, WebKit::WebString* actual_value);
|
|
|
|
virtual bool runModalBeforeUnloadDialog(
|
|
|
|
WebKit::WebFrame* frame, const WebKit::WebString& message);
|
2009-10-13 03:39:30 +02:00
|
|
|
virtual void showContextMenu(
|
|
|
|
WebKit::WebFrame* frame, const WebKit::WebContextMenuData& data);
|
2009-09-17 18:56:32 +02:00
|
|
|
virtual void setStatusText(const WebKit::WebString& text);
|
|
|
|
virtual void setMouseOverURL(const WebKit::WebURL& url);
|
2009-11-03 02:39:16 +01:00
|
|
|
virtual void setKeyboardFocusURL(const WebKit::WebURL& url);
|
2009-09-17 18:56:32 +02:00
|
|
|
virtual void setToolTipText(
|
|
|
|
const WebKit::WebString& text, WebKit::WebTextDirection hint);
|
|
|
|
virtual void startDragging(
|
|
|
|
const WebKit::WebPoint& from, const WebKit::WebDragData& data,
|
|
|
|
WebKit::WebDragOperationsMask mask);
|
2009-11-05 04:48:34 +01:00
|
|
|
virtual bool acceptsLoadDrops() { return true; }
|
2009-09-17 18:56:32 +02:00
|
|
|
virtual void focusNext();
|
|
|
|
virtual void focusPrevious();
|
|
|
|
virtual void navigateBackForwardSoon(int offset);
|
|
|
|
virtual int historyBackListCount();
|
|
|
|
virtual int historyForwardListCount();
|
2009-10-18 22:39:22 +02:00
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
// WebKit::WebWidgetClient
|
2009-07-24 21:11:01 +02:00
|
|
|
virtual void didInvalidateRect(const WebKit::WebRect& rect);
|
|
|
|
virtual void didScrollRect(int dx, int dy,
|
|
|
|
const WebKit::WebRect& clip_rect);
|
|
|
|
virtual void didFocus();
|
|
|
|
virtual void didBlur();
|
|
|
|
virtual void didChangeCursor(const WebKit::WebCursorInfo& cursor);
|
|
|
|
virtual void closeWidgetSoon();
|
|
|
|
virtual void show(WebKit::WebNavigationPolicy policy);
|
|
|
|
virtual void runModal();
|
|
|
|
virtual WebKit::WebRect windowRect();
|
|
|
|
virtual void setWindowRect(const WebKit::WebRect& rect);
|
|
|
|
virtual WebKit::WebRect rootWindowRect();
|
|
|
|
virtual WebKit::WebRect windowResizerRect();
|
|
|
|
virtual WebKit::WebScreenInfo screenInfo();
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
// WebKit::WebFrameClient
|
|
|
|
virtual WebKit::WebPlugin* createPlugin(
|
|
|
|
WebKit::WebFrame*, const WebKit::WebPluginParams&);
|
|
|
|
virtual WebKit::WebMediaPlayer* createMediaPlayer(
|
|
|
|
WebKit::WebFrame*, WebKit::WebMediaPlayerClient*);
|
|
|
|
virtual void loadURLExternally(
|
|
|
|
WebKit::WebFrame*, const WebKit::WebURLRequest&,
|
|
|
|
WebKit::WebNavigationPolicy);
|
|
|
|
virtual WebKit::WebNavigationPolicy decidePolicyForNavigation(
|
|
|
|
WebKit::WebFrame*, const WebKit::WebURLRequest&,
|
2009-10-13 03:39:30 +02:00
|
|
|
WebKit::WebNavigationType, const WebKit::WebNode&,
|
|
|
|
WebKit::WebNavigationPolicy default_policy, bool isRedirect);
|
2009-10-22 01:27:29 +02:00
|
|
|
virtual bool canHandleRequest(
|
2009-11-05 04:48:34 +01:00
|
|
|
WebKit::WebFrame*, const WebKit::WebURLRequest&) { return true; }
|
2009-10-22 01:27:29 +02:00
|
|
|
virtual WebKit::WebURLError cannotHandleRequestError(
|
|
|
|
WebKit::WebFrame*, const WebKit::WebURLRequest& request);
|
|
|
|
virtual WebKit::WebURLError cancelledError(
|
|
|
|
WebKit::WebFrame*, const WebKit::WebURLRequest& request);
|
2009-09-17 18:56:32 +02:00
|
|
|
virtual void didCreateDataSource(
|
|
|
|
WebKit::WebFrame*, WebKit::WebDataSource*);
|
|
|
|
virtual void didStartProvisionalLoad(WebKit::WebFrame*);
|
|
|
|
virtual void didReceiveServerRedirectForProvisionalLoad(WebKit::WebFrame*);
|
|
|
|
virtual void didFailProvisionalLoad(
|
|
|
|
WebKit::WebFrame*, const WebKit::WebURLError&);
|
|
|
|
virtual void didCommitProvisionalLoad(
|
|
|
|
WebKit::WebFrame*, bool is_new_navigation);
|
|
|
|
virtual void didClearWindowObject(WebKit::WebFrame*);
|
|
|
|
virtual void didReceiveTitle(
|
|
|
|
WebKit::WebFrame*, const WebKit::WebString& title);
|
|
|
|
virtual void didFailLoad(
|
|
|
|
WebKit::WebFrame*, const WebKit::WebURLError&);
|
|
|
|
virtual void didFinishLoad(WebKit::WebFrame*);
|
|
|
|
virtual void didChangeLocationWithinPage(
|
|
|
|
WebKit::WebFrame*, bool isNewNavigation);
|
|
|
|
virtual void willSendRequest(
|
|
|
|
WebKit::WebFrame*, unsigned identifier, WebKit::WebURLRequest&,
|
|
|
|
const WebKit::WebURLResponse& redirectResponse);
|
|
|
|
|
|
|
|
// webkit_glue::WebPluginPageDelegate
|
|
|
|
virtual webkit_glue::WebPluginDelegate* CreatePluginDelegate(
|
|
|
|
const GURL& url,
|
|
|
|
const std::string& mime_type,
|
|
|
|
std::string* actual_mime_type);
|
|
|
|
virtual void CreatedPluginWindow(
|
|
|
|
gfx::PluginWindowHandle handle);
|
|
|
|
virtual void WillDestroyPluginWindow(
|
|
|
|
gfx::PluginWindowHandle handle);
|
|
|
|
virtual void DidMovePlugin(
|
|
|
|
const webkit_glue::WebPluginGeometry& move);
|
|
|
|
virtual void DidStartLoadingForPlugin() {}
|
|
|
|
virtual void DidStopLoadingForPlugin() {}
|
|
|
|
virtual void ShowModalHTMLDialogForPlugin(
|
|
|
|
const GURL& url,
|
|
|
|
const gfx::Size& size,
|
|
|
|
const std::string& json_arguments,
|
|
|
|
std::string* json_retval) {}
|
|
|
|
|
|
|
|
BrowserWebViewDelegate(CefBrowserImpl* browser);
|
|
|
|
~BrowserWebViewDelegate();
|
|
|
|
void Reset();
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
void SetSmartInsertDeleteEnabled(bool enabled);
|
|
|
|
void SetSelectTrailingWhitespaceEnabled(bool enabled);
|
|
|
|
|
|
|
|
// Additional accessors
|
2009-08-13 19:23:08 +02:00
|
|
|
WebKit::WebFrame* top_loading_frame() { return top_loading_frame_; }
|
2009-07-24 21:11:01 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
IDropTarget* drop_delegate() { return drop_delegate_.get(); }
|
|
|
|
IDropSource* drag_delegate() { return drag_delegate_.get(); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void set_pending_extra_data(BrowserExtraData* extra_data) {
|
|
|
|
pending_extra_data_.reset(extra_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for modifying WebPreferences
|
|
|
|
void SetUserStyleSheetEnabled(bool is_enabled);
|
|
|
|
void SetUserStyleSheetLocation(const GURL& location);
|
|
|
|
|
|
|
|
// Sets the webview as a drop target.
|
|
|
|
void RegisterDragDrop();
|
2009-08-13 19:23:08 +02:00
|
|
|
void RevokeDragDrop();
|
|
|
|
|
|
|
|
void ResetDragDrop();
|
2009-07-24 21:11:01 +02:00
|
|
|
|
|
|
|
void SetCustomPolicyDelegate(bool is_custom, bool is_permissive);
|
|
|
|
void WaitForPolicyDelegate();
|
|
|
|
|
2009-08-13 19:23:08 +02:00
|
|
|
void set_block_redirects(bool block_redirects) {
|
|
|
|
block_redirects_ = block_redirects;
|
|
|
|
}
|
|
|
|
bool block_redirects() const {
|
|
|
|
return block_redirects_;
|
|
|
|
}
|
|
|
|
|
2010-01-12 02:37:00 +01:00
|
|
|
void SetEditCommand(const std::string& name, const std::string& value) {
|
|
|
|
edit_command_name_ = name;
|
|
|
|
edit_command_value_ = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearEditCommand() {
|
|
|
|
edit_command_name_.clear();
|
|
|
|
edit_command_value_.clear();
|
|
|
|
}
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
CefBrowserImpl* GetBrowser() { return browser_; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Called when the URL of the page changes.
|
2009-10-22 01:27:29 +02:00
|
|
|
void UpdateAddressBar(WebKit::WebView* webView);
|
2009-07-24 21:11:01 +02:00
|
|
|
|
|
|
|
// Default handling of JavaScript messages.
|
2009-08-13 19:23:08 +02:00
|
|
|
void ShowJavaScriptAlert(WebKit::WebFrame* webframe,
|
|
|
|
const std::wstring& message);
|
|
|
|
bool ShowJavaScriptConfirm(WebKit::WebFrame* webframe,
|
|
|
|
const std::wstring& message);
|
|
|
|
bool ShowJavaScriptPrompt(WebKit::WebFrame* webframe,
|
|
|
|
const std::wstring& message,
|
|
|
|
const std::wstring& default_value,
|
|
|
|
std::wstring* result);
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2010-01-20 17:43:47 +01:00
|
|
|
// Called to show the file chooser dialog.
|
|
|
|
bool ShowFileChooser(std::vector<FilePath>& file_names,
|
|
|
|
const bool multi_select,
|
|
|
|
const WebKit::WebString& title,
|
|
|
|
const FilePath& default_file);
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
// In the Mac code, this is called to trigger the end of a test after the
|
|
|
|
// page has finished loading. From here, we can generate the dump for the
|
|
|
|
// test.
|
2009-08-13 19:23:08 +02:00
|
|
|
void LocationChangeDone(WebKit::WebFrame*);
|
2009-07-24 21:11:01 +02:00
|
|
|
|
|
|
|
WebWidgetHost* GetWidgetHost();
|
|
|
|
|
2009-08-13 19:23:08 +02:00
|
|
|
void UpdateForCommittedLoad(WebKit::WebFrame* webframe,
|
|
|
|
bool is_new_navigation);
|
|
|
|
void UpdateURL(WebKit::WebFrame* frame);
|
|
|
|
void UpdateSessionHistory(WebKit::WebFrame* frame);
|
2009-07-24 21:11:01 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Causes navigation actions just printout the intended navigation instead
|
|
|
|
// of taking you to the page. This is used for cases like mailto, where you
|
|
|
|
// don't actually want to open the mail program.
|
|
|
|
bool policy_delegate_enabled_;
|
|
|
|
|
|
|
|
// Toggles the behavior of the policy delegate. If true, then navigations
|
|
|
|
// will be allowed. Otherwise, they will be ignored (dropped).
|
|
|
|
bool policy_delegate_is_permissive_;
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
// If true, the policy delegate will signal layout test completion.
|
|
|
|
bool policy_delegate_should_notify_done_;
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
// Non-owning pointer. The delegate is owned by the host.
|
|
|
|
CefBrowserImpl* browser_;
|
|
|
|
|
|
|
|
// This is non-NULL IFF a load is in progress.
|
2009-08-13 19:23:08 +02:00
|
|
|
WebKit::WebFrame* top_loading_frame_;
|
2009-07-24 21:11:01 +02:00
|
|
|
|
|
|
|
// For tracking session history. See RenderView.
|
|
|
|
int page_id_;
|
|
|
|
int last_page_id_updated_;
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
scoped_ptr<BrowserExtraData> pending_extra_data_;
|
2009-07-24 21:11:01 +02:00
|
|
|
|
|
|
|
WebCursor current_cursor_;
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Classes needed by drag and drop.
|
|
|
|
scoped_refptr<BrowserDragDelegate> drag_delegate_;
|
|
|
|
scoped_refptr<BrowserDropDelegate> drop_delegate_;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
// The type of cursor the window is currently using.
|
|
|
|
// Used for judging whether a new SetCursor call is actually changing the
|
|
|
|
// cursor.
|
|
|
|
GdkCursorType cursor_type_;
|
|
|
|
#endif
|
|
|
|
|
2009-08-13 19:23:08 +02:00
|
|
|
// true if we want to enable smart insert/delete.
|
|
|
|
bool smart_insert_delete_enabled_;
|
|
|
|
|
|
|
|
// true if we want to enable selection of trailing whitespaces
|
|
|
|
bool select_trailing_whitespace_enabled_;
|
|
|
|
|
|
|
|
// true if we should block any redirects
|
|
|
|
bool block_redirects_;
|
2009-09-17 18:56:32 +02:00
|
|
|
|
2010-01-12 02:37:00 +01:00
|
|
|
// Edit command associated to the current keyboard event.
|
|
|
|
std::string edit_command_name_;
|
|
|
|
std::string edit_command_value_;
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(BrowserWebViewDelegate);
|
2009-07-24 21:11:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _BROWSER_WEBVIEW_DELEGATE_H
|