2009-05-28 02:31:21 +02:00
|
|
|
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
2008-12-02 16:48:14 +01:00
|
|
|
// 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"
|
|
|
|
#include "base/ref_counted.h"
|
2009-06-03 01:27:47 +02:00
|
|
|
#include "base/scoped_ptr.h"
|
2009-01-14 20:54:37 +01:00
|
|
|
#include "webkit/glue/webcursor.h"
|
2008-12-02 16:48:14 +01:00
|
|
|
#include "webkit/glue/webview_delegate.h"
|
|
|
|
#include "webkit/glue/webwidget_delegate.h"
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "browser_drag_delegate.h"
|
|
|
|
#include "browser_drop_delegate.h"
|
|
|
|
#endif
|
2009-06-03 01:27:47 +02:00
|
|
|
#include "browser_navigation_controller.h"
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
class CefBrowserImpl;
|
|
|
|
struct WebPreferences;
|
|
|
|
class GURL;
|
|
|
|
class WebDataSource;
|
|
|
|
class WebWidgetHost;
|
|
|
|
|
|
|
|
class BrowserWebViewDelegate : public base::RefCounted<BrowserWebViewDelegate>,
|
2009-05-28 02:31:21 +02:00
|
|
|
public WebViewDelegate {
|
2008-12-02 16:48:14 +01:00
|
|
|
public:
|
2009-05-28 02:31:21 +02:00
|
|
|
BrowserWebViewDelegate(CefBrowserImpl* browser)
|
2009-04-28 02:29:14 +02:00
|
|
|
: policy_delegate_enabled_(false),
|
|
|
|
policy_delegate_is_permissive_(false),
|
2009-05-28 02:31:21 +02:00
|
|
|
browser_(browser),
|
2008-12-02 16:48:14 +01:00
|
|
|
top_loading_frame_(NULL),
|
|
|
|
page_id_(-1),
|
2009-04-28 02:29:14 +02:00
|
|
|
last_page_id_updated_(-1),
|
|
|
|
smart_insert_delete_enabled_(true)
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
, select_trailing_whitespace_enabled_(true)
|
|
|
|
#else
|
|
|
|
, select_trailing_whitespace_enabled_(false)
|
|
|
|
#endif
|
2009-01-14 20:54:37 +01:00
|
|
|
#if defined(OS_LINUX)
|
2008-12-02 16:48:14 +01:00
|
|
|
, cursor_type_(GDK_X_CURSOR)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
}
|
2009-05-28 02:31:21 +02:00
|
|
|
virtual ~BrowserWebViewDelegate() {}
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
// WebViewDelegate
|
2009-05-15 17:09:51 +02:00
|
|
|
virtual WebView* CreateWebView(WebView* webview,
|
|
|
|
bool user_gesture,
|
|
|
|
const GURL& creator_url);
|
2009-01-14 20:54:37 +01:00
|
|
|
virtual WebWidget* CreatePopupWidget(WebView* webview, bool activatable);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual WebPluginDelegate* CreatePluginDelegate(
|
|
|
|
WebView* webview,
|
|
|
|
const GURL& url,
|
|
|
|
const std::string& mime_type,
|
|
|
|
const std::string& clsid,
|
|
|
|
std::string* actual_mime_type);
|
2009-04-28 02:29:14 +02:00
|
|
|
virtual WebKit::WebWorker* CreateWebWorker(WebKit::WebWorkerClient* client);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual void OpenURL(WebView* webview,
|
|
|
|
const GURL& url,
|
|
|
|
const GURL& referrer,
|
|
|
|
WindowOpenDisposition disposition);
|
2009-03-09 20:38:59 +01:00
|
|
|
virtual void RunJavaScriptAlert(WebFrame* webframe,
|
2008-12-02 16:48:14 +01:00
|
|
|
const std::wstring& message);
|
2009-03-09 20:38:59 +01:00
|
|
|
virtual bool RunJavaScriptConfirm(WebFrame* webframe,
|
2008-12-02 16:48:14 +01:00
|
|
|
const std::wstring& message);
|
2009-03-09 20:38:59 +01:00
|
|
|
virtual bool RunJavaScriptPrompt(WebFrame* webframe,
|
2008-12-02 16:48:14 +01:00
|
|
|
const std::wstring& message,
|
|
|
|
const std::wstring& default_value,
|
|
|
|
std::wstring* result);
|
2009-02-12 17:25:52 +01:00
|
|
|
virtual void SetStatusbarText(WebView* webview,
|
|
|
|
const std::wstring& message);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual void AddMessageToConsole(WebView* webview,
|
|
|
|
const std::wstring& message,
|
|
|
|
unsigned int line_no,
|
|
|
|
const std::wstring& source_id);
|
|
|
|
virtual void StartDragging(WebView* webview,
|
2009-04-28 02:29:14 +02:00
|
|
|
const WebKit::WebDragData& drop_data);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual void ShowContextMenu(WebView* webview,
|
2009-01-29 17:36:37 +01:00
|
|
|
ContextNode in_node,
|
2008-12-02 16:48:14 +01:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
const GURL& link_url,
|
|
|
|
const GURL& image_url,
|
|
|
|
const GURL& page_url,
|
|
|
|
const GURL& frame_url,
|
|
|
|
const std::wstring& selection_text,
|
|
|
|
const std::wstring& misspelled_word,
|
|
|
|
int edit_flags,
|
2009-05-15 17:09:51 +02:00
|
|
|
const std::string& security_info,
|
|
|
|
const std::string& frame_charset);
|
2009-06-03 01:27:47 +02:00
|
|
|
virtual void DidCreateDataSource(WebFrame* frame,
|
|
|
|
WebDataSource* ds);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual void DidStartProvisionalLoadForFrame(
|
|
|
|
WebView* webview,
|
|
|
|
WebFrame* frame,
|
|
|
|
NavigationGesture gesture);
|
|
|
|
virtual void DidReceiveServerRedirectForProvisionalLoadForFrame(
|
|
|
|
WebView* webview, WebFrame* frame);
|
|
|
|
virtual void DidFailProvisionalLoadWithError(WebView* webview,
|
|
|
|
const WebError& error,
|
|
|
|
WebFrame* frame);
|
|
|
|
virtual void DidCommitLoadForFrame(WebView* webview, WebFrame* frame,
|
|
|
|
bool is_new_navigation);
|
|
|
|
virtual void DidReceiveTitle(WebView* webview,
|
|
|
|
const std::wstring& title,
|
|
|
|
WebFrame* frame);
|
|
|
|
virtual void DidFinishDocumentLoadForFrame(WebView* webview,
|
|
|
|
WebFrame* frame);
|
|
|
|
virtual void DidHandleOnloadEventsForFrame(WebView* webview,
|
|
|
|
WebFrame* frame);
|
|
|
|
virtual void DidChangeLocationWithinPageForFrame(WebView* webview,
|
|
|
|
WebFrame* frame,
|
|
|
|
bool is_new_navigation);
|
|
|
|
virtual void DidReceiveIconForFrame(WebView* webview, WebFrame* frame);
|
|
|
|
|
|
|
|
virtual void WillPerformClientRedirect(WebView* webview,
|
|
|
|
WebFrame* frame,
|
|
|
|
const std::wstring& dest_url,
|
|
|
|
unsigned int delay_seconds,
|
|
|
|
unsigned int fire_date);
|
|
|
|
virtual void DidCancelClientRedirect(WebView* webview,
|
|
|
|
WebFrame* frame);
|
|
|
|
|
|
|
|
virtual void DidFinishLoadForFrame(WebView* webview, WebFrame* frame);
|
|
|
|
virtual void DidFailLoadWithError(WebView* webview,
|
|
|
|
const WebError& error,
|
|
|
|
WebFrame* forFrame);
|
|
|
|
|
|
|
|
virtual void AssignIdentifierToRequest(WebView* webview,
|
|
|
|
uint32 identifier,
|
|
|
|
const WebRequest& request);
|
|
|
|
virtual void WillSendRequest(WebView* webview,
|
|
|
|
uint32 identifier,
|
|
|
|
WebRequest* request);
|
|
|
|
virtual void DidFinishLoading(WebView* webview, uint32 identifier);
|
|
|
|
virtual void DidFailLoadingWithError(WebView* webview,
|
|
|
|
uint32 identifier,
|
|
|
|
const WebError& error);
|
|
|
|
|
|
|
|
virtual bool ShouldBeginEditing(WebView* webview, std::wstring range);
|
|
|
|
virtual bool ShouldEndEditing(WebView* webview, std::wstring range);
|
|
|
|
virtual bool ShouldInsertNode(WebView* webview,
|
|
|
|
std::wstring node,
|
|
|
|
std::wstring range,
|
|
|
|
std::wstring action);
|
|
|
|
virtual bool ShouldInsertText(WebView* webview,
|
|
|
|
std::wstring text,
|
|
|
|
std::wstring range,
|
|
|
|
std::wstring action);
|
|
|
|
virtual bool ShouldChangeSelectedRange(WebView* webview,
|
|
|
|
std::wstring fromRange,
|
|
|
|
std::wstring toRange,
|
|
|
|
std::wstring affinity,
|
|
|
|
bool stillSelecting);
|
|
|
|
virtual bool ShouldDeleteRange(WebView* webview, std::wstring range);
|
|
|
|
virtual bool ShouldApplyStyle(WebView* webview,
|
|
|
|
std::wstring style,
|
|
|
|
std::wstring range);
|
|
|
|
virtual bool SmartInsertDeleteEnabled();
|
|
|
|
virtual void DidBeginEditing();
|
|
|
|
virtual void DidChangeSelection();
|
|
|
|
virtual void DidChangeContents();
|
|
|
|
virtual void DidEndEditing();
|
|
|
|
|
|
|
|
virtual void DidStartLoading(WebView* webview);
|
|
|
|
virtual void DidStopLoading(WebView* webview);
|
|
|
|
|
|
|
|
virtual void WindowObjectCleared(WebFrame* webframe);
|
|
|
|
virtual WindowOpenDisposition DispositionForNavigationAction(
|
|
|
|
WebView* webview,
|
|
|
|
WebFrame* frame,
|
|
|
|
const WebRequest* request,
|
|
|
|
WebNavigationType type,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
bool is_redirect);
|
2009-05-15 17:09:51 +02:00
|
|
|
virtual void NavigateBackForwardSoon(int offset);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual int GetHistoryBackListCount();
|
|
|
|
virtual int GetHistoryForwardListCount();
|
|
|
|
|
|
|
|
// WebWidgetDelegate
|
2009-01-29 17:36:37 +01:00
|
|
|
virtual gfx::NativeViewId GetContainingView(WebWidget* webwidget);
|
2009-04-28 02:29:14 +02:00
|
|
|
virtual void DidInvalidateRect(WebWidget* webwidget,
|
|
|
|
const WebKit::WebRect& rect);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual void DidScrollRect(WebWidget* webwidget, int dx, int dy,
|
2009-04-28 02:29:14 +02:00
|
|
|
const WebKit::WebRect& clip_rect);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual void Show(WebWidget* webview, WindowOpenDisposition disposition);
|
2009-04-28 02:29:14 +02:00
|
|
|
virtual void ShowAsPopupWithItems(WebWidget* webwidget,
|
|
|
|
const WebKit::WebRect& bounds,
|
|
|
|
int item_height,
|
|
|
|
int selected_index,
|
|
|
|
const std::vector<WebMenuItem>& items);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual void CloseWidgetSoon(WebWidget* webwidget);
|
|
|
|
virtual void Focus(WebWidget* webwidget);
|
|
|
|
virtual void Blur(WebWidget* webwidget);
|
|
|
|
virtual void SetCursor(WebWidget* webwidget,
|
|
|
|
const WebCursor& cursor);
|
2009-04-28 02:29:14 +02:00
|
|
|
virtual void GetWindowRect(WebWidget* webwidget, WebKit::WebRect* rect);
|
|
|
|
virtual void SetWindowRect(WebWidget* webwidget, const WebKit::WebRect& rect);
|
|
|
|
virtual void GetRootWindowRect(WebWidget *,WebKit::WebRect *);
|
|
|
|
virtual void GetRootWindowResizerRect(WebWidget* webwidget,
|
|
|
|
WebKit::WebRect* rect);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual void DidMove(WebWidget* webwidget, const WebPluginGeometry& move);
|
|
|
|
virtual void RunModal(WebWidget* webwidget);
|
2009-04-28 02:29:14 +02:00
|
|
|
virtual bool IsHidden(WebWidget* webwidget);
|
|
|
|
virtual WebKit::WebScreenInfo GetScreenInfo(WebWidget* webwidget);
|
2008-12-02 16:48:14 +01:00
|
|
|
virtual void AddRef() {
|
|
|
|
base::RefCounted<BrowserWebViewDelegate>::AddRef();
|
|
|
|
}
|
|
|
|
virtual void Release() {
|
|
|
|
base::RefCounted<BrowserWebViewDelegate>::Release();
|
|
|
|
}
|
2009-03-08 03:26:16 +01:00
|
|
|
virtual void TakeFocus(WebView* webview, bool reverse);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
2009-04-28 02:29:14 +02:00
|
|
|
void SetSmartInsertDeleteEnabled(bool enabled);
|
|
|
|
void SetSelectTrailingWhitespaceEnabled(bool enabled);
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
// Additional accessors
|
|
|
|
WebFrame* top_loading_frame() { return top_loading_frame_; }
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
IDropTarget* drop_delegate() { return drop_delegate_.get(); }
|
|
|
|
IDropSource* drag_delegate() { return drag_delegate_.get(); }
|
|
|
|
#endif
|
2009-06-03 01:27:47 +02:00
|
|
|
|
|
|
|
void set_pending_extra_data(BrowserExtraData* extra_data) {
|
|
|
|
pending_extra_data_.reset(extra_data);
|
|
|
|
}
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
// Methods for modifying WebPreferences
|
|
|
|
void SetUserStyleSheetEnabled(bool is_enabled);
|
|
|
|
void SetUserStyleSheetLocation(const GURL& location);
|
|
|
|
|
|
|
|
// Sets the webview as a drop target.
|
|
|
|
void RegisterDragDrop();
|
|
|
|
|
2009-04-28 02:29:14 +02:00
|
|
|
void SetCustomPolicyDelegate(bool is_custom, bool is_permissive);
|
|
|
|
void WaitForPolicyDelegate();
|
|
|
|
|
2008-12-02 16:48:14 +01:00
|
|
|
CefBrowserImpl* GetBrowser() { return browser_; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Called when the URL of the page changes.
|
|
|
|
void UpdateAddressBar(WebView* webView);
|
|
|
|
|
|
|
|
// Default handling of JavaScript messages.
|
2009-03-09 20:38:59 +01:00
|
|
|
void ShowJavaScriptAlert(WebFrame* webframe, const std::wstring& message);
|
|
|
|
bool ShowJavaScriptConfirm(WebFrame* webframe, const std::wstring& message);
|
|
|
|
bool ShowJavaScriptPrompt(WebFrame* webframe, const std::wstring& message,
|
2008-12-02 16:48:14 +01:00
|
|
|
const std::wstring& default_value, std::wstring* result);
|
|
|
|
|
|
|
|
// 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-04-28 02:29:14 +02:00
|
|
|
void LocationChangeDone(WebFrame*);
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
WebWidgetHost* GetHostForWidget(WebWidget* webwidget);
|
|
|
|
|
|
|
|
void UpdateForCommittedLoad(WebFrame* webframe, bool is_new_navigation);
|
|
|
|
void UpdateURL(WebFrame* frame);
|
|
|
|
void UpdateSessionHistory(WebFrame* frame);
|
|
|
|
|
|
|
|
// Get a string suitable for dumping a frame to the console.
|
|
|
|
std::wstring GetFrameDescription(WebFrame* webframe);
|
|
|
|
|
|
|
|
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.
|
2009-04-28 02:29:14 +02:00
|
|
|
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_;
|
2008-12-02 16:48:14 +01:00
|
|
|
|
|
|
|
// Non-owning pointer. The delegate is owned by the host.
|
|
|
|
CefBrowserImpl* browser_;
|
|
|
|
|
|
|
|
// This is non-NULL IFF a load is in progress.
|
|
|
|
WebFrame* top_loading_frame_;
|
|
|
|
|
|
|
|
// For tracking session history. See RenderView.
|
|
|
|
int page_id_;
|
|
|
|
int last_page_id_updated_;
|
|
|
|
|
2009-06-03 01:27:47 +02:00
|
|
|
scoped_ptr<BrowserExtraData> pending_extra_data_;
|
|
|
|
|
2009-04-28 02:29:14 +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_;
|
|
|
|
|
2009-01-14 20:54:37 +01:00
|
|
|
WebCursor current_cursor_;
|
2008-12-02 16:48:14 +01:00
|
|
|
#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-02-12 17:25:52 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(BrowserWebViewDelegate);
|
2008-12-02 16:48:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _BROWSER_WEBVIEW_DELEGATE_H
|