summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-16 16:47:52 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-16 16:47:52 +0000
commit48c9cf2d85fa8a6a2de61946d377d561b9bb5c6e (patch)
treeedf21dfb828b0b18ed2db136424f0a12e5cb9655 /webkit
parent2dd011df2acf628a0d23346a8a518000d18dd683 (diff)
downloadchromium_src-48c9cf2d85fa8a6a2de61946d377d561b9bb5c6e.zip
chromium_src-48c9cf2d85fa8a6a2de61946d377d561b9bb5c6e.tar.gz
chromium_src-48c9cf2d85fa8a6a2de61946d377d561b9bb5c6e.tar.bz2
Hook up WebViewClient, part 1.
This change makes WebViewDelegate extend from WebViewClient as a temporary means to start having consumers implement and use WebViewClient. R=dglazkov BUG=10033 TEST=none Review URL: http://codereview.chromium.org/196128 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/api/public/WebViewClient.h105
-rw-r--r--webkit/glue/back_forward_list_client_impl.cc12
-rw-r--r--webkit/glue/chrome_client_impl.cc148
-rw-r--r--webkit/glue/dragclient_impl.cc6
-rw-r--r--webkit/glue/webframeloaderclient_impl.cc35
-rw-r--r--webkit/glue/webview_delegate.h152
-rw-r--r--webkit/glue/webview_impl.cc15
-rw-r--r--webkit/glue/webview_impl.h8
-rw-r--r--webkit/tools/test_shell/layout_test_controller.cc24
-rw-r--r--webkit/tools/test_shell/layout_test_controller.h2
-rw-r--r--webkit/tools/test_shell/mac/test_webview_delegate.mm31
-rw-r--r--webkit/tools/test_shell/test_shell.cc2
-rw-r--r--webkit/tools/test_shell/test_shell.h4
-rw-r--r--webkit/tools/test_shell/test_shell_gtk.cc2
-rw-r--r--webkit/tools/test_shell/test_shell_mac.mm2
-rw-r--r--webkit/tools/test_shell/test_shell_win.cc2
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.cc199
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.h72
-rw-r--r--webkit/tools/test_shell/test_webview_delegate_gtk.cc24
-rw-r--r--webkit/tools/test_shell/test_webview_delegate_win.cc14
-rw-r--r--webkit/webkit.gyp1
21 files changed, 382 insertions, 478 deletions
diff --git a/webkit/api/public/WebViewClient.h b/webkit/api/public/WebViewClient.h
index 54dae44..07717c8 100644
--- a/webkit/api/public/WebViewClient.h
+++ b/webkit/api/public/WebViewClient.h
@@ -31,31 +31,36 @@
#ifndef WebViewClient_h
#define WebViewClient_h
-#error "This header file is still a work in progress; do not include!"
-
+#include "WebDragOperation.h"
#include "WebWidgetClient.h"
+class WebView; // FIXME: Move into the WebKit namespace.
+
namespace WebKit {
+ class WebDragData;
class WebFileChooserCompletion;
class WebFrame;
- class WebPopupMenu;
class WebString;
- class WebView;
+ class WebWidget;
struct WebConsoleMessage;
struct WebContextMenuInfo;
+ struct WebPoint;
struct WebPopupMenuInfo;
- class WebViewClient : public WebWidgetClient {
+ // Since a WebView is a WebWidget, a WebViewClient is a WebWidgetClient.
+ // Virtual inheritance allows an implementation of WebWidgetClient to be
+ // easily reused as part of an implementation of WebViewClient.
+ class WebViewClient : virtual public WebWidgetClient {
public:
// Factory methods -----------------------------------------------------
// Create a new related WebView.
- virtual WebView* createView(bool hasUserGesture) = 0;
+ virtual WebView* createView(WebFrame* creator) = 0;
// Create a new WebPopupMenu. In the second form, the client is
// responsible for rendering the contents of the popup menu.
- virtual WebPopupMenu* createPopupMenu(bool activatable) = 0;
- virtual WebPopupMenu* createPopupMenu(bool activatable, const WebPopupMenuInfo&) = 0;
+ virtual WebWidget* createPopupMenu(bool activatable) = 0;
+ virtual WebWidget* createPopupMenu(const WebPopupMenuInfo&) = 0;
// Misc ----------------------------------------------------------------
@@ -64,15 +69,11 @@ namespace WebKit {
virtual void didAddMessageToConsole(
const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine) = 0;
- // If enabled, sudden termination implies that there are no registered
- // unload event handlers that would need to run in order to close the
- // WebView. This information allows the embedder to determine if the
- // process can be closed without closing the respective WebViews.
- virtual void enableSuddenTermination() = 0;
- virtual void disableSuddenTermination() = 0;
-
- // Called when script in the page calls window.print().
- virtual void printPage() = 0;
+ // Called when script in the page calls window.print(). If frame is
+ // non-null, then it selects a particular frame, including its
+ // children, to print. Otherwise, the main frame and its children
+ // should be printed.
+ virtual void printPage(WebFrame*) = 0;
// Navigational --------------------------------------------------------
@@ -81,39 +82,52 @@ namespace WebKit {
virtual void didStartLoading() = 0;
virtual void didStopLoading() = 0;
- // A frame (or subframe) was created. The client may return a
- // WebFrameClient to be associated with the newly created frame.
- virtual WebFrameClient* didCreateFrame(WebFrame* frame) = 0;
-
-
- // Editing -------------------------------------------------------------
- // May return null. The WebEditingClient is passed additional events
- // related to text editing in the page.
- virtual WebEditingClient* editingClient() = 0;
+ // Spellchecker --------------------------------------------------------
// The client should perform spell-checking on the given word
// synchronously. Return a length of 0 if the word is not misspelled.
- virtual void spellCheck(
- const WebString& word, int& misspelledOffset, int& misspelledLength) = 0;
+ // FIXME hook this up
+ //virtual void spellCheck(
+ // const WebString& word, int& misspelledOffset, int& misspelledLength) = 0;
// Dialogs -------------------------------------------------------------
- // These methods should not return until the dialog has been closed.
- virtual void runModalAlertDialog(const WebString& message) = 0;
- virtual bool runModalConfirmDialog(const WebString& message) = 0;
+ // Displays a modal alert dialog containing the given message. Returns
+ // once the user dismisses the dialog.
+ virtual void runModalAlertDialog(
+ WebFrame*, const WebString& message) = 0;
+
+ // Displays a modal confirmation dialog with the given message as
+ // description and OK/Cancel choices. Returns true if the user selects
+ // 'OK' or false otherwise.
+ virtual bool runModalConfirmDialog(
+ WebFrame*, const WebString& message) = 0;
+
+ // Displays a modal input dialog with the given message as description
+ // and OK/Cancel choices. The input field is pre-filled with
+ // defaultValue. Returns true if the user selects 'OK' or false
+ // otherwise. Upon returning true, actualValue contains the value of
+ // the input field.
virtual bool runModalPromptDialog(
- const WebString& message, const WebString& defaultValue,
+ WebFrame*, const WebString& message, const WebString& defaultValue,
WebString* actualValue) = 0;
- virtual bool runModalBeforeUnloadDialog(const WebString& message) = 0;
+
+ // Displays a modal confirmation dialog containing the given message as
+ // description and OK/Cancel choices, where 'OK' means that it is okay
+ // to proceed with closing the view. Returns true if the user selects
+ // 'OK' or false otherwise.
+ virtual bool runModalBeforeUnloadDialog(
+ WebFrame*, const WebString& message) = 0;
// This method returns immediately after showing the dialog. When the
// dialog is closed, it should call the WebFileChooserCompletion to
// pass the results of the dialog.
- virtual void runFileChooser(
- bool multiSelect, const WebString& title,
- const WebString& initialValue, WebFileChooserCompletion*) = 0;
+ // FIXME hook this up
+ //virtual void runFileChooser(
+ // bool multiSelect, const WebString& title,
+ // const WebString& initialValue, WebFileChooserCompletion*) = 0;
// UI ------------------------------------------------------------------
@@ -125,13 +139,15 @@ namespace WebKit {
virtual void setMouseOverURL(const WebURL&) = 0;
// Called when a tooltip should be shown at the current cursor position.
- virtual void setToolTipText(const WebString&) = 0;
+ virtual void setToolTipText(const WebString&, WebTextDirection hint) = 0;
// Called when a context menu should be shown at the current cursor position.
- virtual void showContextMenu(const WebContextMenuInfo&) = 0;
+ // FIXME hook this up
+ //virtual void showContextMenu(const WebContextMenuInfo&) = 0;
// Called when a drag-n-drop operation should begin.
- virtual void startDragging(WebFrame*, const WebDragData&) = 0;
+ virtual void startDragging(
+ const WebPoint& from, const WebDragData&, WebDragOperationsMask) = 0;
// Take focus away from the WebView by focusing an adjacent UI element
// in the containing window.
@@ -141,8 +157,10 @@ namespace WebKit {
// Session History -----------------------------------------------------
- // Returns the history item at the given index.
- virtual WebHistoryItem historyItemAtIndex(int index) = 0;
+ // Tells the embedder to navigate back or forward in session history by
+ // the given offset (relative to the current position in session
+ // history).
+ virtual void navigateBackForwardSoon(int offset) = 0;
// Returns the number of history items before/after the current
// history item.
@@ -153,11 +171,6 @@ namespace WebKit {
virtual void didAddHistoryItem() = 0;
- // Developer Tools -----------------------------------------------------
-
- virtual void didOpenInspector(int numResources) = 0;
-
-
// FIXME need to something for:
// OnPasswordFormsSeen
// OnAutofillFormSubmitted
diff --git a/webkit/glue/back_forward_list_client_impl.cc b/webkit/glue/back_forward_list_client_impl.cc
index ec24804..65f2472 100644
--- a/webkit/glue/back_forward_list_client_impl.cc
+++ b/webkit/glue/back_forward_list_client_impl.cc
@@ -40,8 +40,8 @@ void BackForwardListClientImpl::addItem(PassRefPtr<WebCore::HistoryItem> item) {
// not a reload or back/forward).
webview_->ObserveNewNavigation();
- if (webview_->delegate())
- webview_->delegate()->DidAddHistoryItem();
+ if (webview_->client())
+ webview_->client()->didAddHistoryItem();
}
void BackForwardListClientImpl::goToItem(WebCore::HistoryItem* item) {
@@ -78,17 +78,17 @@ WebCore::HistoryItem* BackForwardListClientImpl::itemAtIndex(int index) {
}
int BackForwardListClientImpl::backListCount() {
- if (!webview_->delegate())
+ if (!webview_->client())
return 0;
- return webview_->delegate()->GetHistoryBackListCount();
+ return webview_->client()->historyBackListCount();
}
int BackForwardListClientImpl::forwardListCount() {
- if (!webview_->delegate())
+ if (!webview_->client())
return 0;
- return webview_->delegate()->GetHistoryForwardListCount();
+ return webview_->client()->historyForwardListCount();
}
void BackForwardListClientImpl::close() {
diff --git a/webkit/glue/chrome_client_impl.cc b/webkit/glue/chrome_client_impl.cc
index 818f0e11..6aa4478 100644
--- a/webkit/glue/chrome_client_impl.cc
+++ b/webkit/glue/chrome_client_impl.cc
@@ -29,6 +29,7 @@
#undef LOG
#include "googleurl/src/gurl.h"
+#include "webkit/api/public/WebConsoleMessage.h"
#include "webkit/api/public/WebCursorInfo.h"
#include "webkit/api/public/WebFrameClient.h"
#include "webkit/api/public/WebInputEvent.h"
@@ -50,13 +51,16 @@
using WebCore::PopupContainer;
using WebCore::PopupItem;
+using WebKit::WebConsoleMessage;
using WebKit::WebCursorInfo;
using WebKit::WebInputEvent;
using WebKit::WebMouseEvent;
using WebKit::WebNavigationPolicy;
using WebKit::WebPopupMenuInfo;
using WebKit::WebRect;
+using WebKit::WebString;
using WebKit::WebTextDirection;
+using WebKit::WebURL;
using WebKit::WebURLRequest;
using WebKit::WebVector;
using WebKit::WebWidget;
@@ -192,29 +196,23 @@ bool ChromeClientImpl::canTakeFocus(WebCore::FocusDirection) {
}
void ChromeClientImpl::takeFocus(WebCore::FocusDirection direction) {
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
- delegate->TakeFocus(webview_,
- direction == WebCore::FocusDirectionBackward);
+ if (!webview_->client())
+ return;
+ if (direction == WebCore::FocusDirectionBackward) {
+ webview_->client()->focusPrevious();
+ } else {
+ webview_->client()->focusNext();
}
}
WebCore::Page* ChromeClientImpl::createWindow(
WebCore::Frame* frame, const WebCore::FrameLoadRequest& r,
const WebCore::WindowFeatures& features) {
- WebViewDelegate* delegate = webview_->delegate();
- if (!delegate)
+ if (!webview_->client())
return NULL;
- bool user_gesture = frame->script()->processingUserGesture();
-
- const std::string security_origin(webkit_glue::StringToStdString(
- frame->document()->securityOrigin()->toString()));
- GURL creator_url(security_origin);
WebViewImpl* new_view = static_cast<WebViewImpl*>(
- delegate->CreateWebView(webview_, user_gesture,
- (creator_url.is_valid() && creator_url.IsStandard()) ?
- creator_url : GURL()));
+ webview_->client()->createView(WebFrameImpl::FromFrame(frame)));
if (!new_view)
return NULL;
@@ -225,8 +223,7 @@ WebCore::Page* ChromeClientImpl::createWindow(
new_view->main_frame()->loadRequest(request);
}
- WebViewImpl* new_view_impl = static_cast<WebViewImpl*>(new_view);
- return new_view_impl->page();
+ return new_view->page();
}
static inline bool CurrentEventShouldCauseBackgroundTab(
@@ -323,12 +320,12 @@ void ChromeClientImpl::addMessageToConsole(WebCore::MessageSource source,
const WebCore::String& message,
unsigned int line_no,
const WebCore::String& source_id) {
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
- std::wstring wstr_message = webkit_glue::StringToStdWString(message);
- std::wstring wstr_source_id = webkit_glue::StringToStdWString(source_id);
- delegate->AddMessageToConsole(webview_, wstr_message,
- line_no, wstr_source_id);
+ if (webview_->client()) {
+ webview_->client()->didAddMessageToConsole(
+ WebConsoleMessage(static_cast<WebConsoleMessage::Level>(level),
+ webkit_glue::StringToWebString(message)),
+ webkit_glue::StringToWebString(source_id),
+ line_no);
}
}
@@ -339,11 +336,10 @@ bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel() {
bool ChromeClientImpl::runBeforeUnloadConfirmPanel(
const WebCore::String& message,
WebCore::Frame* frame) {
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
- std::wstring wstr = webkit_glue::StringToStdWString(message);
- return delegate->RunBeforeUnloadConfirm(WebFrameImpl::FromFrame(frame),
- wstr);
+ if (webview_->client()) {
+ return webview_->client()->runModalBeforeUnloadDialog(
+ WebFrameImpl::FromFrame(frame),
+ webkit_glue::StringToWebString(message));
}
return false;
}
@@ -355,36 +351,33 @@ void ChromeClientImpl::closeWindowSoon() {
// Make sure that all loading is stopped. Ensures that JS stops executing!
webview_->StopLoading();
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate)
- delegate->closeWidgetSoon();
+ if (webview_->client())
+ webview_->client()->closeWidgetSoon();
}
// Although a WebCore::Frame is passed in, we don't actually use it, since we
// already know our own webview_.
void ChromeClientImpl::runJavaScriptAlert(WebCore::Frame* frame,
const WebCore::String& message) {
- // Pass the request on to the WebView delegate, for more control.
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
+ if (webview_->client()) {
#if USE(V8)
// Before showing the JavaScript dialog, we give the proxy implementation
// a chance to process any pending console messages.
WebCore::V8Proxy::processConsoleMessages();
#endif
-
- std::wstring wstr = webkit_glue::StringToStdWString(message);
- delegate->RunJavaScriptAlert(WebFrameImpl::FromFrame(frame), wstr);
+ webview_->client()->runModalAlertDialog(
+ WebFrameImpl::FromFrame(frame),
+ webkit_glue::StringToWebString(message));
}
}
// See comments for runJavaScriptAlert().
bool ChromeClientImpl::runJavaScriptConfirm(WebCore::Frame* frame,
const WebCore::String& message) {
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
- std::wstring wstr = webkit_glue::StringToStdWString(message);
- return delegate->RunJavaScriptConfirm(WebFrameImpl::FromFrame(frame), wstr);
+ if (webview_->client()) {
+ return webview_->client()->runModalConfirmDialog(
+ WebFrameImpl::FromFrame(frame),
+ webkit_glue::StringToWebString(message));
}
return false;
}
@@ -392,29 +385,26 @@ bool ChromeClientImpl::runJavaScriptConfirm(WebCore::Frame* frame,
// See comments for runJavaScriptAlert().
bool ChromeClientImpl::runJavaScriptPrompt(WebCore::Frame* frame,
const WebCore::String& message,
- const WebCore::String& defaultValue,
+ const WebCore::String& default_value,
WebCore::String& result) {
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
- std::wstring wstr_message = webkit_glue::StringToStdWString(message);
- std::wstring wstr_default = webkit_glue::StringToStdWString(defaultValue);
- std::wstring wstr_result;
- bool ok = delegate->RunJavaScriptPrompt(WebFrameImpl::FromFrame(frame),
- wstr_message,
- wstr_default,
- &wstr_result);
+ if (webview_->client()) {
+ WebString actual_value;
+ bool ok = webview_->client()->runModalPromptDialog(
+ WebFrameImpl::FromFrame(frame),
+ webkit_glue::StringToWebString(message),
+ webkit_glue::StringToWebString(default_value),
+ &actual_value);
if (ok)
- result = webkit_glue::StdWStringToString(wstr_result);
+ result = webkit_glue::WebStringToString(actual_value);
return ok;
}
return false;
}
void ChromeClientImpl::setStatusbarText(const WebCore::String& message) {
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
- std::wstring wstr = webkit_glue::StringToStdWString(message);
- delegate->SetStatusbarText(webview_, wstr);
+ if (webview_->client()) {
+ webview_->client()->setStatusText(
+ webkit_glue::StringToWebString(message));
}
}
@@ -499,37 +489,32 @@ void ChromeClientImpl::scrollbarsModeDidChange() const {
}
void ChromeClientImpl::mouseDidMoveOverElement(
- const WebCore::HitTestResult& result, unsigned modifierFlags) {
- // Find out if the mouse is over a link, and if so, let our UI know... somehow
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
- if (result.isLiveLink() && !result.absoluteLinkURL().string().isEmpty()) {
- delegate->UpdateTargetURL(
- webview_, webkit_glue::KURLToGURL(result.absoluteLinkURL()));
- } else {
- delegate->UpdateTargetURL(webview_, GURL());
- }
+ const WebCore::HitTestResult& result, unsigned modifier_flags) {
+ if (!webview_->client())
+ return;
+ // Find out if the mouse is over a link, and if so, let our UI know...
+ if (result.isLiveLink() && !result.absoluteLinkURL().string().isEmpty()) {
+ webview_->client()->setMouseOverURL(
+ webkit_glue::KURLToWebURL(result.absoluteLinkURL()));
+ } else {
+ webview_->client()->setMouseOverURL(WebURL());
}
}
void ChromeClientImpl::setToolTip(const WebCore::String& tooltip_text,
WebCore::TextDirection dir) {
- if (webview_->delegate()) {
- std::wstring tooltip_text_as_wstring =
- webkit_glue::StringToStdWString(tooltip_text);
- WebTextDirection text_direction = (dir == WebCore::RTL) ?
- WebKit::WebTextDirectionRightToLeft :
- WebKit::WebTextDirectionLeftToRight;
- webview_->delegate()->SetTooltipText(webview_, tooltip_text_as_wstring,
- text_direction);
- }
+ if (!webview_->client())
+ return;
+ WebTextDirection text_direction = (dir == WebCore::RTL) ?
+ WebKit::WebTextDirectionRightToLeft :
+ WebKit::WebTextDirectionLeftToRight;
+ webview_->client()->setToolTipText(
+ webkit_glue::StringToWebString(tooltip_text), text_direction);
}
void ChromeClientImpl::print(WebCore::Frame* frame) {
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
- delegate->ScriptedPrint(WebFrameImpl::FromFrame(frame));
- }
+ if (webview_->client())
+ webview_->client()->printPage(WebFrameImpl::FromFrame(frame));
}
void ChromeClientImpl::exceededDatabaseQuota(WebCore::Frame* frame,
@@ -562,17 +547,16 @@ void ChromeClientImpl::popupOpened(PopupContainer* popup_container,
const WebCore::IntRect& bounds,
bool activatable,
bool handle_externally) {
- WebViewDelegate* delegate = webview_->delegate();
- if (!delegate)
+ if (!webview_->client())
return;
WebWidget* webwidget;
if (handle_externally) {
WebPopupMenuInfo popup_info;
GetPopupMenuInfo(popup_container, &popup_info);
- webwidget = delegate->CreatePopupWidgetWithInfo(webview_, popup_info);
+ webwidget = webview_->client()->createPopupMenu(popup_info);
} else {
- webwidget = delegate->CreatePopupWidget(webview_, activatable);
+ webwidget = webview_->client()->createPopupMenu(activatable);
}
static_cast<WebPopupMenuImpl*>(webwidget)->Init(
diff --git a/webkit/glue/dragclient_impl.cc b/webkit/glue/dragclient_impl.cc
index 75a8ba9..dff2ccd 100644
--- a/webkit/glue/dragclient_impl.cc
+++ b/webkit/glue/dragclient_impl.cc
@@ -61,11 +61,11 @@ void DragClientImpl::startDrag(WebCore::DragImageRef drag_image,
static_cast<WebCore::ClipboardChromium*>(clipboard)->dataObject());
WebCore::DragOperation drag_operation_mask;
- if (!clipboard->sourceOperation(drag_operation_mask)) {
+ if (!clipboard->sourceOperation(drag_operation_mask))
drag_operation_mask = WebCore::DragOperationEvery;
- }
- webview_->StartDragging(webkit_glue::IntPointToWebPoint(event_pos),
+ webview_->StartDragging(
+ webkit_glue::IntPointToWebPoint(event_pos),
drag_data,
static_cast<WebKit::WebDragOperationsMask>(drag_operation_mask));
}
diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc
index d08377c..4f806cc 100644
--- a/webkit/glue/webframeloaderclient_impl.cc
+++ b/webkit/glue/webframeloaderclient_impl.cc
@@ -504,9 +504,8 @@ void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage() {
// Anchor fragment navigations are not normal loads, so we need to synthesize
// some events for our delegate.
WebViewImpl* webview = webframe_->GetWebViewImpl();
- WebViewDelegate* d = webview->delegate();
- if (d)
- d->DidStartLoading(webview);
+ if (webview->client())
+ webview->client()->didStartLoading();
WebDataSourceImpl* ds = webframe_->GetDataSourceImpl();
DCHECK(ds) << "DataSource NULL when navigating to reference fragment";
@@ -550,8 +549,8 @@ void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage() {
webframe_, is_new_navigation);
}
- if (d)
- d->DidStopLoading(webview);
+ if (webview->client())
+ webview->client()->didStopLoading();
}
void WebFrameLoaderClient::dispatchWillClose() {
@@ -885,12 +884,9 @@ void WebFrameLoaderClient::setMainDocumentError(DocumentLoader*,
}
void WebFrameLoaderClient::postProgressStartedNotification() {
- if (hasWebView()) {
- WebViewImpl* web_view = webframe_->GetWebViewImpl();
- WebViewDelegate* d = web_view->delegate();
- if (d)
- d->DidStartLoading(web_view);
- }
+ WebViewImpl* webview = webframe_->GetWebViewImpl();
+ if (webview && webview->client())
+ webview->client()->didStartLoading();
}
void WebFrameLoaderClient::postProgressEstimateChangedNotification() {
@@ -898,14 +894,11 @@ void WebFrameLoaderClient::postProgressEstimateChangedNotification() {
}
void WebFrameLoaderClient::postProgressFinishedNotification() {
- // TODO(ericroman): why might webframe_->webview_impl be null?
+ // TODO(ericroman): why might the webview be null?
// http://b/1234461
- if (hasWebView()) {
- WebViewImpl* web_view = webframe_->GetWebViewImpl();
- WebViewDelegate* d = web_view->delegate();
- if (d)
- d->DidStopLoading(web_view);
- }
+ WebViewImpl* webview = webframe_->GetWebViewImpl();
+ if (webview && webview->client())
+ webview->client()->didStopLoading();
}
void WebFrameLoaderClient::setMainFrameDocumentReady(bool ready) {
@@ -1335,9 +1328,9 @@ void WebFrameLoaderClient::HandleBackForwardNavigation(const GURL& url) {
if (!StringToInt(offset_str, &offset))
return;
- WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate();
- if (d)
- d->NavigateBackForwardSoon(offset);
+ WebViewImpl* webview = webframe_->GetWebViewImpl();
+ if (webview->client())
+ webview->client()->navigateBackForwardSoon(offset);
}
PassOwnPtr<WebPluginLoadObserver> WebFrameLoaderClient::GetPluginLoadObserver() {
diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h
index 4987326..f9f8837 100644
--- a/webkit/glue/webview_delegate.h
+++ b/webkit/glue/webview_delegate.h
@@ -31,7 +31,7 @@
#include "webkit/api/public/WebDragOperation.h"
#include "webkit/api/public/WebFrame.h"
#include "webkit/api/public/WebTextDirection.h"
-#include "webkit/api/public/WebWidgetClient.h"
+#include "webkit/api/public/WebViewClient.h"
#include "webkit/glue/context_menu.h"
namespace WebCore {
@@ -65,42 +65,11 @@ class WebFileChooserCallback {
DISALLOW_COPY_AND_ASSIGN(WebFileChooserCallback);
};
-
-// Inheritance here is somewhat weird, but since a WebView is a WebWidget,
-// it makes sense that a WebViewDelegate is a WebWidgetClient.
-class WebViewDelegate : virtual public WebKit::WebWidgetClient {
+// TODO(darin): Eliminate WebViewDelegate in favor of WebViewClient.
+class WebViewDelegate : public WebKit::WebViewClient {
public:
// WebView additions -------------------------------------------------------
- // This method is called to create a new WebView. The WebView should not be
- // made visible until the new WebView's Delegate has its Show method called.
- // The returned WebView pointer is assumed to be owned by the host window,
- // and the caller of CreateWebView should not release the given WebView.
- // |user_gesture| is true if a user action initiated this call.
- // |creator_url|, if nonempty, holds the security origin of the page creating
- // this WebView.
- virtual WebView* CreateWebView(WebView* webview,
- bool user_gesture,
- const GURL& creator_url) {
- return NULL;
- }
-
- // This method is called to create a new WebWidget to act as a popup
- // (like a drop-down menu).
- virtual WebKit::WebWidget* CreatePopupWidget(
- WebView* webview,
- bool activatable) {
- return NULL;
- }
-
- // Like CreatePopupWidget, except the actual widget is rendered by the
- // embedder using the supplied info.
- virtual WebKit::WebWidget* CreatePopupWidgetWithInfo(
- WebView* webview,
- const WebKit::WebPopupMenuInfo& info) {
- return NULL;
- }
-
// Notifies how many matches have been found so far, for a given request_id.
// |final_update| specifies whether this is the last update (all frames have
// completed scoping).
@@ -139,14 +108,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient {
return true;
}
- // Notifies the delegate that a load has begun.
- virtual void DidStartLoading(WebView* webview) {
- }
-
- // Notifies the delegate that all loads are finished.
- virtual void DidStopLoading(WebView* webview) {
- }
-
// Notifies that a new script context has been created for this frame.
// This is similar to WindowObjectCleared but only called once per frame
// context.
@@ -163,16 +124,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient {
// ChromeClient ------------------------------------------------------------
- // Appends a line to the application's error console. The message contains
- // an error description or other information, the line_no provides a line
- // number (e.g. for a JavaScript error report), and the source_id contains
- // a URL or other description of the source of the message.
- virtual void AddMessageToConsole(WebView* webview,
- const std::wstring& message,
- unsigned int line_no,
- const std::wstring& source_id) {
- }
-
// Queries the browser for suggestions to be shown for the form text field
// named |field_name|. |text| is the text entered by the user so far and
// |node_id| is the id of the node of the input field.
@@ -194,57 +145,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient {
// UIDelegate --------------------------------------------------------------
- // Displays a JavaScript alert panel associated with the given view. Clients
- // should visually indicate that this panel comes from JavaScript and some
- // information about the originating frame (at least the domain). The panel
- // should have a single OK button.
- virtual void RunJavaScriptAlert(WebKit::WebFrame* webframe,
- const std::wstring& message) {
- }
-
- // Displays a JavaScript confirm panel associated with the given view.
- // Clients should visually indicate that this panel comes
- // from JavaScript. The panel should have two buttons, e.g. "OK" and
- // "Cancel". Returns true if the user hit OK, or false if the user hit Cancel.
- virtual bool RunJavaScriptConfirm(WebKit::WebFrame* webframe,
- const std::wstring& message) {
- return false;
- }
-
- // Displays a JavaScript text input panel associated with the given view.
- // Clients should visually indicate that this panel comes from JavaScript.
- // The panel should have two buttons, e.g. "OK" and "Cancel", and an area to
- // type text. The default_value should appear as the initial text in the
- // panel when it is shown. If the user hit OK, returns true and fills result
- // with the text in the box. The value of result is undefined if the user
- // hit Cancel.
- virtual bool RunJavaScriptPrompt(WebKit::WebFrame* webframe,
- const std::wstring& message,
- const std::wstring& default_value,
- std::wstring* result) {
- return false;
- }
-
- // Sets the status bar text.
- virtual void SetStatusbarText(WebView* webview,
- const std::wstring& message) { }
-
- // Displays a "before unload" confirm panel associated with the given view.
- // The panel should have two buttons, e.g. "OK" and "Cancel", where OK means
- // that the navigation should continue, and Cancel means that the navigation
- // should be cancelled, leaving the user on the current page. Returns true
- // if the user hit OK, or false if the user hit Cancel.
- virtual bool RunBeforeUnloadConfirm(WebKit::WebFrame* webframe,
- const std::wstring& message) {
- return true; // OK, continue to navigate away
- }
-
- // Tells the client that we're hovering over a link with a given URL,
- // if the node is not a link, the URL will be an empty GURL.
- virtual void UpdateTargetURL(WebView* webview,
- const GURL& url) {
- }
-
// Called to display a file chooser prompt. The prompt should be pre-
// populated with the given initial_filename string. The WebViewDelegate
// will own the WebFileChooserCallback object and is responsible for
@@ -295,24 +195,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient {
const std::string& frame_charset) {
}
- // Starts a drag session with the supplied contextual information.
- // webview: The WebView sending the delegate method.
- // mouseCoords: Current mouse coordinates
- // drop_data: a WebDropData struct which should contain all the necessary
- // information for dragging data out of the webview.
- // drag_source_operation_mask: indicates what drag operations are allowed
- virtual void StartDragging(WebView* webview,
- const WebKit::WebPoint &mouseCoords,
- const WebKit::WebDragData& drag_data,
- WebKit::WebDragOperationsMask operations_mask) {
- }
-
- // Returns the focus to the client.
- // reverse: Whether the focus should go to the previous (if true) or the next
- // focusable element.
- virtual void TakeFocus(WebView* webview, bool reverse) {
- }
-
// Notification that a user metric has occurred.
virtual void UserMetricsRecordAction(const std::wstring& action) { }
@@ -331,27 +213,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient {
// History Related ---------------------------------------------------------
- // Tells the embedder to navigate back or forward in session history by the
- // given offset (relative to the current position in session history).
- virtual void NavigateBackForwardSoon(int offset) {
- }
-
- // Returns how many entries are in the back and forward lists, respectively.
- virtual int GetHistoryBackListCount() {
- return 0;
- }
- virtual int GetHistoryForwardListCount() {
- return 0;
- }
-
- // -------------------------------------------------------------------------
-
- // Tell the delegate the tooltip text and its directionality hint for the
- // current mouse position.
- virtual void SetTooltipText(WebView* webview,
- const std::wstring& tooltip_text,
- WebKit::WebTextDirection text_direction_hint) { }
-
// InspectorClient ---------------------------------------------------------
virtual void UpdateInspectorSettings(const std::wstring& raw_settings) { }
@@ -390,13 +251,6 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient {
// Update the spelling panel with the |word|.
virtual void UpdateSpellingUIWithMisspelledWord(const std::wstring& word) { }
- // Asks the user to print the page or a specific frame. Called in response to
- // a window.print() call.
- virtual void ScriptedPrint(WebKit::WebFrame* frame) { }
-
- // Called when an item was added to the history
- virtual void DidAddHistoryItem() { }
-
// The "CurrentKeyboardEvent" refers to the keyboard event passed to
// WebView's handleInputEvent method.
//
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc
index e708327..38d4f94 100644
--- a/webkit/glue/webview_impl.cc
+++ b/webkit/glue/webview_impl.cc
@@ -116,6 +116,7 @@ using WebKit::WebTextDirection;
using WebKit::WebTextDirectionDefault;
using WebKit::WebTextDirectionLeftToRight;
using WebKit::WebTextDirectionRightToLeft;
+using WebKit::WebURL;
using webkit_glue::ImageResourceFetcher;
@@ -457,7 +458,7 @@ void WebViewImpl::MouseLeave(const WebMouseEvent& event) {
if (!main_frame() || !main_frame()->frameview())
return;
- delegate_->UpdateTargetURL(this, GURL());
+ client()->setMouseOverURL(WebURL());
main_frame()->frame()->eventHandler()->handleMouseMoveEvent(
PlatformMouseEventBuilder(main_frame()->frameview(), event));
@@ -1814,14 +1815,14 @@ void WebViewImpl::DidCommitLoad(bool* is_new_navigation) {
observed_new_navigation_ = false;
}
-void WebViewImpl::StartDragging(WebPoint event_pos,
+void WebViewImpl::StartDragging(const WebPoint& event_pos,
const WebDragData& drag_data,
WebDragOperationsMask mask) {
- if (delegate_) {
- DCHECK(!doing_drag_and_drop_);
- doing_drag_and_drop_ = true;
- delegate_->StartDragging(this, event_pos, drag_data, mask);
- }
+ if (!client())
+ return;
+ DCHECK(!doing_drag_and_drop_);
+ doing_drag_and_drop_ = true;
+ client()->startDragging(event_pos, drag_data, mask);
}
void WebViewImpl::OnImageFetchComplete(ImageResourceFetcher* fetcher,
diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h
index f81e9dd..9b860bc 100644
--- a/webkit/glue/webview_impl.h
+++ b/webkit/glue/webview_impl.h
@@ -167,6 +167,11 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> {
static WebViewImpl* FromPage(WebCore::Page* page);
+ WebKit::WebViewClient* client() {
+ return delegate_;
+ }
+
+ // TODO(darin): Remove this method in favor of client().
WebViewDelegate* delegate() {
return delegate_;
}
@@ -228,7 +233,8 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> {
}
// Start a system drag and drop operation.
- void StartDragging(WebKit::WebPoint event_pos,
+ void StartDragging(
+ const WebKit::WebPoint& event_pos,
const WebKit::WebDragData& drag_data,
WebKit::WebDragOperationsMask drag_source_operation_mask);
diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc
index 8fa349c..2263377 100644
--- a/webkit/tools/test_shell/layout_test_controller.cc
+++ b/webkit/tools/test_shell/layout_test_controller.cc
@@ -14,6 +14,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "webkit/api/public/WebConsoleMessage.h"
#include "webkit/api/public/WebFrame.h"
#include "webkit/api/public/WebKit.h"
#include "webkit/api/public/WebScriptSource.h"
@@ -28,6 +29,7 @@
using std::string;
using std::wstring;
+using WebKit::WebConsoleMessage;
using WebKit::WebScriptSource;
using WebKit::WebString;
@@ -839,8 +841,7 @@ bool LayoutTestController::CppVariantToBool(const CppVariant& value) {
if (valueString == "false")
return false;
}
- shell_->delegate()->AddMessageToConsole(shell_->webView(),
- L"Invalid value. Expected boolean value.", 0, L"");
+ LogErrorToConsole("Invalid value. Expected boolean value.");
return false;
}
@@ -852,8 +853,7 @@ int32 LayoutTestController::CppVariantToInt32(const CppVariant& value) {
if (StringToInt(value.ToString(), &number))
return number;
}
- shell_->delegate()->AddMessageToConsole(shell_->webView(),
- L"Invalid value for preference. Expected integer value.", 0, L"");
+ LogErrorToConsole("Invalid value for preference. Expected integer value.");
return 0;
}
@@ -861,8 +861,7 @@ std::wstring LayoutTestController::CppVariantToWstring(
const CppVariant& value) {
if (value.isString())
return UTF8ToWide(value.ToString());
- shell_->delegate()->AddMessageToConsole(shell_->webView(),
- L"Invalid value for preference. Expected string value.", 0, L"");
+ LogErrorToConsole("Invalid value for preference. Expected string value.");
return std::wstring();
}
@@ -924,10 +923,9 @@ void LayoutTestController::overridePreference(
else if (key == "WebKitOfflineWebApplicationCacheEnabled")
preferences->application_cache_enabled = CppVariantToBool(value);
else {
- std::wstring message(L"Invalid name for preference: ");
- message.append(ASCIIToWide(key));
- shell_->delegate()->AddMessageToConsole(shell_->webView(),
- message, 0, L"");
+ std::string message("Invalid name for preference: ");
+ message.append(key);
+ LogErrorToConsole(message);
}
preferences->Apply(shell_->webView());
}
@@ -963,3 +961,9 @@ void LayoutTestController::whiteListAccessFromOrigin(
WebString::fromUTF8(args[2].ToString()),
args[3].ToBoolean());
}
+
+void LayoutTestController::LogErrorToConsole(const std::string& text) {
+ shell_->webView()->GetMainFrame()->addMessageToConsole(
+ WebConsoleMessage(WebConsoleMessage::LevelError,
+ WebString::fromUTF8(text)));
+}
diff --git a/webkit/tools/test_shell/layout_test_controller.h b/webkit/tools/test_shell/layout_test_controller.h
index af0313c..51c5e8c 100644
--- a/webkit/tools/test_shell/layout_test_controller.h
+++ b/webkit/tools/test_shell/layout_test_controller.h
@@ -281,6 +281,8 @@ class LayoutTestController : public CppBoundClass {
int32 CppVariantToInt32(const CppVariant&);
std::wstring CppVariantToWstring(const CppVariant&);
+ void LogErrorToConsole(const std::string& text);
+
// Non-owning pointer. The LayoutTestController is owned by the host.
static TestShell* shell_;
diff --git a/webkit/tools/test_shell/mac/test_webview_delegate.mm b/webkit/tools/test_shell/mac/test_webview_delegate.mm
index 97c1280..369eaa4 100644
--- a/webkit/tools/test_shell/mac/test_webview_delegate.mm
+++ b/webkit/tools/test_shell/mac/test_webview_delegate.mm
@@ -8,6 +8,7 @@
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "webkit/api/public/WebCursorInfo.h"
+#include "webkit/api/public/WebPopupMenu.h"
#include "webkit/glue/webcursor.h"
#include "webkit/glue/webview.h"
#include "webkit/glue/plugins/plugin_list.h"
@@ -17,31 +18,20 @@
using WebKit::WebCursorInfo;
using WebKit::WebNavigationPolicy;
+using WebKit::WebPopupMenu;
using WebKit::WebPopupMenuInfo;
using WebKit::WebRect;
using WebKit::WebWidget;
-// WebViewDelegate ------------------------------------------------------------
+// WebViewClient --------------------------------------------------------------
-WebWidget* TestWebViewDelegate::CreatePopupWidgetWithInfo(
- WebView* webview,
+WebWidget* TestWebViewDelegate::createPopupMenu(
const WebPopupMenuInfo& info) {
- WebWidget* webwidget = shell_->CreatePopupWidget(webview);
+ WebWidget* webwidget = shell_->CreatePopupWidget();
popup_menu_info_.reset(new WebPopupMenuInfo(info));
return webwidget;
}
-void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) {
- NSString *text =
- [NSString stringWithUTF8String:WideToUTF8(message).c_str()];
- NSAlert *alert = [NSAlert alertWithMessageText:@"JavaScript Alert"
- defaultButton:@"OK"
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:text];
- [alert runModal];
-}
-
// WebWidgetClient ------------------------------------------------------------
void TestWebViewDelegate::show(WebNavigationPolicy policy) {
@@ -215,6 +205,17 @@ void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) {
// Private methods ------------------------------------------------------------
+void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) {
+ NSString *text =
+ [NSString stringWithUTF8String:WideToUTF8(message).c_str()];
+ NSAlert *alert = [NSAlert alertWithMessageText:@"JavaScript Alert"
+ defaultButton:@"OK"
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:text];
+ [alert runModal];
+}
+
void TestWebViewDelegate::SetPageTitle(const std::wstring& title) {
[[shell_->webViewHost()->view_handle() window]
setTitle:[NSString stringWithUTF8String:WideToUTF8(title).c_str()]];
diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc
index 44d3a68..a58c9bc 100644
--- a/webkit/tools/test_shell/test_shell.cc
+++ b/webkit/tools/test_shell/test_shell.cc
@@ -485,7 +485,7 @@ void TestShell::CallJSGC() {
webView()->GetMainFrame()->collectGarbage();
}
-WebView* TestShell::CreateWebView(WebView* webview) {
+WebView* TestShell::CreateWebView() {
// If we're running layout tests, only open a new window if the test has
// called layoutTestController.setCanOpenWindows()
if (layout_test_mode_ && !layout_test_controller_->CanOpenWindows())
diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h
index 7518cec..1b7502b 100644
--- a/webkit/tools/test_shell/test_shell.h
+++ b/webkit/tools/test_shell/test_shell.h
@@ -181,8 +181,8 @@ public:
// Implements CreateWebView for TestWebViewDelegate, which in turn
// is called as a WebViewDelegate.
- WebView* CreateWebView(WebView* webview);
- WebKit::WebWidget* CreatePopupWidget(WebView* webview);
+ WebView* CreateWebView();
+ WebKit::WebWidget* CreatePopupWidget();
void ClosePopup();
#if defined(OS_WIN)
diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc
index 848751d..e4c0b19 100644
--- a/webkit/tools/test_shell/test_shell_gtk.cc
+++ b/webkit/tools/test_shell/test_shell_gtk.cc
@@ -466,7 +466,7 @@ void TestShell::DestroyWindow(gfx::NativeWindow windowHandle) {
gtk_widget_destroy(GTK_WIDGET(windowHandle));
}
-WebWidget* TestShell::CreatePopupWidget(WebView* webview) {
+WebWidget* TestShell::CreatePopupWidget() {
GtkWidget* popupwindow = gtk_window_new(GTK_WINDOW_POPUP);
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
WebWidgetHost* host = WebWidgetHost::Create(vbox, popup_delegate_.get());
diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm
index 299876a..54f2a65 100644
--- a/webkit/tools/test_shell/test_shell_mac.mm
+++ b/webkit/tools/test_shell/test_shell_mac.mm
@@ -453,7 +453,7 @@ void TestShell::DestroyWindow(gfx::NativeWindow windowHandle) {
[windowHandle autorelease];
}
-WebWidget* TestShell::CreatePopupWidget(WebView* webview) {
+WebWidget* TestShell::CreatePopupWidget() {
DCHECK(!m_popupHost);
m_popupHost = WebWidgetHost::Create(webViewWnd(), popup_delegate_.get());
diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc
index 2bde111..f231ba0 100644
--- a/webkit/tools/test_shell/test_shell_win.cc
+++ b/webkit/tools/test_shell/test_shell_win.cc
@@ -454,7 +454,7 @@ void TestShell::InteractiveSetFocus(WebWidgetHost* host, bool enable) {
::SetFocus(NULL);
}
-WebWidget* TestShell::CreatePopupWidget(WebView* webview) {
+WebWidget* TestShell::CreatePopupWidget() {
DCHECK(!m_popupHost);
m_popupHost = WebWidgetHost::Create(NULL, popup_delegate_.get());
ShowWindow(popupWnd(), SW_SHOW);
diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc
index b69d855..903e3d2 100644
--- a/webkit/tools/test_shell/test_webview_delegate.cc
+++ b/webkit/tools/test_shell/test_webview_delegate.cc
@@ -20,6 +20,7 @@
#include "base/string_util.h"
#include "base/trace_event.h"
#include "net/base/net_errors.h"
+#include "webkit/api/public/WebConsoleMessage.h"
#include "webkit/api/public/WebCString.h"
#include "webkit/api/public/WebData.h"
#include "webkit/api/public/WebDataSource.h"
@@ -29,6 +30,7 @@
#include "webkit/api/public/WebKit.h"
#include "webkit/api/public/WebNode.h"
#include "webkit/api/public/WebPoint.h"
+#include "webkit/api/public/WebPopupMenu.h"
#include "webkit/api/public/WebRange.h"
#include "webkit/api/public/WebScreenInfo.h"
#include "webkit/api/public/WebString.h"
@@ -60,6 +62,7 @@
#include "webkit/tools/test_shell/drop_delegate.h"
#endif
+using WebKit::WebConsoleMessage;
using WebKit::WebData;
using WebKit::WebDataSource;
using WebKit::WebDragData;
@@ -76,12 +79,14 @@ using WebKit::WebNode;
using WebKit::WebPlugin;
using WebKit::WebPluginParams;
using WebKit::WebPoint;
+using WebKit::WebPopupMenu;
using WebKit::WebRange;
using WebKit::WebRect;
using WebKit::WebScreenInfo;
using WebKit::WebSize;
using WebKit::WebString;
using WebKit::WebTextAffinity;
+using WebKit::WebTextDirection;
using WebKit::WebURL;
using WebKit::WebURLError;
using WebKit::WebURLRequest;
@@ -105,13 +110,14 @@ int next_page_id_ = 1;
// Used to write a platform neutral file:/// URL by only taking the filename
// (e.g., converts "file:///tmp/foo.txt" to just "foo.txt").
-std::wstring UrlSuitableForTestResult(const std::wstring& url) {
- if (url.empty() || std::wstring::npos == url.find(L"file://"))
+std::string UrlSuitableForTestResult(const std::string& url) {
+ if (url.empty() || std::string::npos == url.find("file://"))
return url;
- std::wstring filename = file_util::GetFilenameFromPath(url);
+ std::string filename =
+ WideToUTF8(file_util::GetFilenameFromPath(UTF8ToWide(url)));
if (filename.empty())
- return L"file:"; // A WebKit test has this in its expected output.
+ return "file:"; // A WebKit test has this in its expected output.
return filename;
}
@@ -244,102 +250,148 @@ std::string GetTextAffinityDescription(WebTextAffinity affinity) {
// WebViewDelegate -----------------------------------------------------------
-WebView* TestWebViewDelegate::CreateWebView(WebView* webview,
- bool user_gesture,
- const GURL& creator_url) {
- return shell_->CreateWebView(webview);
+std::string TestWebViewDelegate::GetResourceDescription(uint32 identifier) {
+ ResourceMap::iterator it = resource_identifier_map_.find(identifier);
+ return it != resource_identifier_map_.end() ? it->second : "<unknown>";
}
-WebWidget* TestWebViewDelegate::CreatePopupWidget(WebView* webview,
- bool activatable) {
- return shell_->CreatePopupWidget(webview);
+void TestWebViewDelegate::ShowContextMenu(
+ WebView* webview,
+ ContextNodeType node_type,
+ int x,
+ int y,
+ const GURL& link_url,
+ const GURL& image_url,
+ const GURL& page_url,
+ const GURL& frame_url,
+ const ContextMenuMediaParams& media_params,
+ const std::wstring& selection_text,
+ const std::wstring& misspelled_word,
+ int edit_flags,
+ const std::string& security_info,
+ const std::string& frame_charset) {
+ CapturedContextMenuEvent context(node_type, x, y);
+ captured_context_menu_events_.push_back(context);
}
-std::string TestWebViewDelegate::GetResourceDescription(uint32 identifier) {
- ResourceMap::iterator it = resource_identifier_map_.find(identifier);
- return it != resource_identifier_map_.end() ? it->second : "<unknown>";
+void TestWebViewDelegate::SetUserStyleSheetEnabled(bool is_enabled) {
+ WebPreferences* prefs = shell_->GetWebPreferences();
+ prefs->user_style_sheet_enabled = is_enabled;
+ prefs->Apply(shell_->webView());
+}
+
+void TestWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) {
+ WebPreferences* prefs = shell_->GetWebPreferences();
+ prefs->user_style_sheet_enabled = true;
+ prefs->user_style_sheet_location = location;
+ prefs->Apply(shell_->webView());
+}
+
+// WebViewClient -------------------------------------------------------------
+
+WebView* TestWebViewDelegate::createView(WebFrame* creator) {
+ return shell_->CreateWebView();
+}
+
+WebWidget* TestWebViewDelegate::createPopupMenu(
+ bool activatable) {
+ // TODO(darin): Should we honor activatable?
+ return shell_->CreatePopupWidget();
}
-void TestWebViewDelegate::AddMessageToConsole(WebView* webview,
- const std::wstring& message,
- unsigned int line_no,
- const std::wstring& source_id) {
+void TestWebViewDelegate::didAddMessageToConsole(
+ const WebConsoleMessage& message, const WebString& source_name,
+ unsigned source_line) {
if (!shell_->layout_test_mode()) {
logging::LogMessage("CONSOLE", 0).stream() << "\""
- << message.c_str()
+ << message.text.utf8().data()
<< ",\" source: "
- << source_id.c_str()
+ << source_name.utf8().data()
<< "("
- << line_no
+ << source_line
<< ")";
} else {
// This matches win DumpRenderTree's UIDelegate.cpp.
- std::wstring new_message = message;
- if (!message.empty()) {
- new_message = message;
- size_t file_protocol = new_message.find(L"file://");
- if (file_protocol != std::wstring::npos) {
+ std::string new_message;
+ if (!message.text.isEmpty()) {
+ new_message = message.text.utf8();
+ size_t file_protocol = new_message.find("file://");
+ if (file_protocol != std::string::npos) {
new_message = new_message.substr(0, file_protocol) +
UrlSuitableForTestResult(new_message.substr(file_protocol));
}
}
- std::string utf8 = WideToUTF8(new_message);
- printf("CONSOLE MESSAGE: line %d: %s\n", line_no, utf8.c_str());
+ printf("CONSOLE MESSAGE: line %d: %s\n", source_line, new_message.data());
}
}
-void TestWebViewDelegate::RunJavaScriptAlert(WebFrame* webframe,
- const std::wstring& message) {
+void TestWebViewDelegate::printPage(WebFrame* frame) {
+}
+
+void TestWebViewDelegate::didStartLoading() {
+}
+
+void TestWebViewDelegate::didStopLoading() {
+}
+
+void TestWebViewDelegate::runModalAlertDialog(
+ WebFrame* frame, const WebString& message) {
if (!shell_->layout_test_mode()) {
- ShowJavaScriptAlert(message);
+ ShowJavaScriptAlert(UTF16ToWideHack(message));
} else {
- std::string utf8 = WideToUTF8(message);
- printf("ALERT: %s\n", utf8.c_str());
+ printf("ALERT: %s\n", message.utf8().data());
}
}
-bool TestWebViewDelegate::RunJavaScriptConfirm(WebFrame* webframe,
- const std::wstring& message) {
+bool TestWebViewDelegate::runModalConfirmDialog(
+ WebFrame* frame, const WebString& message) {
if (shell_->layout_test_mode()) {
// When running tests, write to stdout.
- std::string utf8 = WideToUTF8(message);
- printf("CONFIRM: %s\n", utf8.c_str());
+ printf("CONFIRM: %s\n", message.utf8().data());
return true;
}
return false;
}
-bool TestWebViewDelegate::RunJavaScriptPrompt(WebFrame* webframe,
- const std::wstring& message,
- const std::wstring& default_value,
- std::wstring* result) {
+bool TestWebViewDelegate::runModalPromptDialog(
+ WebFrame* frame, const WebString& message, const WebString& default_value,
+ WebString* actual_value) {
if (shell_->layout_test_mode()) {
// When running tests, write to stdout.
- std::string utf8_message = WideToUTF8(message);
- std::string utf8_default_value = WideToUTF8(default_value);
- printf("PROMPT: %s, default text: %s\n", utf8_message.c_str(),
- utf8_default_value.c_str());
+ printf("PROMPT: %s, default text: %s\n",
+ message.utf8().data(),
+ default_value.utf8().data());
return true;
}
return false;
}
-void TestWebViewDelegate::SetStatusbarText(WebView* webview,
- const std::wstring& message) {
+bool TestWebViewDelegate::runModalBeforeUnloadDialog(
+ WebFrame* frame, const WebString& message) {
+ return true; // Allow window closure.
+}
+
+void TestWebViewDelegate::setStatusText(const WebString& text) {
if (WebKit::layoutTestMode() &&
shell_->layout_test_controller()->ShouldDumpStatusCallbacks()) {
// When running tests, write to stdout.
- printf("UI DELEGATE STATUS CALLBACK: setStatusText:%S\n", message.c_str());
+ printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", text.utf8().data());
}
}
-void TestWebViewDelegate::StartDragging(WebView* webview,
- const WebPoint &mouse_coords,
- const WebDragData& drag_data,
- WebDragOperationsMask mask) {
+void TestWebViewDelegate::setMouseOverURL(const WebURL& url) {
+}
+
+void TestWebViewDelegate::setToolTipText(
+ const WebString& text, WebTextDirection hint) {
+}
+
+void TestWebViewDelegate::startDragging(
+ const WebPoint& mouse_coords, const WebDragData& data,
+ WebDragOperationsMask mask) {
if (WebKit::layoutTestMode()) {
- WebDragData mutable_drag_data = drag_data;
+ WebDragData mutable_drag_data = data;
if (shell_->layout_test_controller()->ShouldAddFileToPasteboard()) {
// Add a file called DRTFakeFile to the drag&drop clipboard.
AddDRTFakeFileToDataObject(&mutable_drag_data);
@@ -360,55 +412,32 @@ void TestWebViewDelegate::StartDragging(WebView* webview,
// ok_effect, &effect);
//DCHECK(DRAGDROP_S_DROP == res || DRAGDROP_S_CANCEL == res);
}
- webview->DragSourceSystemDragEnded();
+ shell_->webView()->DragSourceSystemDragEnded();
}
-void TestWebViewDelegate::ShowContextMenu(
- WebView* webview,
- ContextNodeType node_type,
- int x,
- int y,
- const GURL& link_url,
- const GURL& image_url,
- const GURL& page_url,
- const GURL& frame_url,
- const ContextMenuMediaParams& media_params,
- const std::wstring& selection_text,
- const std::wstring& misspelled_word,
- int edit_flags,
- const std::string& security_info,
- const std::string& frame_charset) {
- CapturedContextMenuEvent context(node_type, x, y);
- captured_context_menu_events_.push_back(context);
+void TestWebViewDelegate::focusNext() {
}
-void TestWebViewDelegate::NavigateBackForwardSoon(int offset) {
+void TestWebViewDelegate::focusPrevious() {
+}
+
+void TestWebViewDelegate::navigateBackForwardSoon(int offset) {
shell_->navigation_controller()->GoToOffset(offset);
}
-int TestWebViewDelegate::GetHistoryBackListCount() {
+int TestWebViewDelegate::historyBackListCount() {
int current_index =
shell_->navigation_controller()->GetLastCommittedEntryIndex();
return current_index;
}
-int TestWebViewDelegate::GetHistoryForwardListCount() {
+int TestWebViewDelegate::historyForwardListCount() {
int current_index =
shell_->navigation_controller()->GetLastCommittedEntryIndex();
return shell_->navigation_controller()->GetEntryCount() - current_index - 1;
}
-void TestWebViewDelegate::SetUserStyleSheetEnabled(bool is_enabled) {
- WebPreferences* prefs = shell_->GetWebPreferences();
- prefs->user_style_sheet_enabled = is_enabled;
- prefs->Apply(shell_->webView());
-}
-
-void TestWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) {
- WebPreferences* prefs = shell_->GetWebPreferences();
- prefs->user_style_sheet_enabled = true;
- prefs->user_style_sheet_location = location;
- prefs->Apply(shell_->webView());
+void TestWebViewDelegate::didAddHistoryItem() {
}
// WebWidgetClient -----------------------------------------------------------
diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h
index 8e3e99a..90627ef 100644
--- a/webkit/tools/test_shell/test_webview_delegate.h
+++ b/webkit/tools/test_shell/test_webview_delegate.h
@@ -68,37 +68,6 @@ class TestWebViewDelegate : public WebViewDelegate,
typedef std::vector<CapturedContextMenuEvent> CapturedContextMenuEvents;
// WebViewDelegate
- virtual WebView* CreateWebView(WebView* webview,
- bool user_gesture,
- const GURL& creator_url);
- virtual WebKit::WebWidget* CreatePopupWidget(
- WebView* webview,
- bool activatable);
-#if defined(OS_MACOSX)
- virtual WebKit::WebWidget* CreatePopupWidgetWithInfo(
- WebView* webview,
- const WebKit::WebPopupMenuInfo& info);
-#endif
- virtual void RunJavaScriptAlert(WebKit::WebFrame* webframe,
- const std::wstring& message);
- virtual bool RunJavaScriptConfirm(WebKit::WebFrame* webframe,
- const std::wstring& message);
- virtual bool RunJavaScriptPrompt(WebKit::WebFrame* webframe,
- const std::wstring& message,
- const std::wstring& default_value,
- std::wstring* result);
-
- virtual void SetStatusbarText(WebView* webview,
- const std::wstring& message);
-
- virtual void AddMessageToConsole(WebView* webview,
- const std::wstring& message,
- unsigned int line_no,
- const std::wstring& source_id);
- virtual void StartDragging(WebView* webview,
- const WebKit::WebPoint &mouseCoords,
- const WebKit::WebDragData& drag_data,
- WebKit::WebDragOperationsMask operations_mask);
virtual void ShowContextMenu(WebView* webview,
ContextNodeType node_type,
int x,
@@ -113,9 +82,40 @@ class TestWebViewDelegate : public WebViewDelegate,
int edit_flags,
const std::string& security_info,
const std::string& frame_charset);
- virtual void NavigateBackForwardSoon(int offset);
- virtual int GetHistoryBackListCount();
- virtual int GetHistoryForwardListCount();
+
+ // WebKit::WebViewClient
+ virtual WebView* createView(WebKit::WebFrame* creator);
+ 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 printPage(WebKit::WebFrame* frame);
+ virtual void didStartLoading();
+ virtual void didStopLoading();
+ 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);
+ virtual void setStatusText(const WebKit::WebString& text);
+ virtual void setMouseOverURL(const WebKit::WebURL& url);
+ virtual void setToolTipText(
+ const WebKit::WebString& text, WebKit::WebTextDirection hint);
+ virtual void startDragging(
+ const WebKit::WebPoint& from, const WebKit::WebDragData& data,
+ WebKit::WebDragOperationsMask mask);
+ virtual void focusNext();
+ virtual void focusPrevious();
+ virtual void navigateBackForwardSoon(int offset);
+ virtual int historyBackListCount();
+ virtual int historyForwardListCount();
+ virtual void didAddHistoryItem();
// WebKit::WebWidgetClient
virtual void didInvalidateRect(const WebKit::WebRect& rect);
@@ -286,7 +286,8 @@ class TestWebViewDelegate : public WebViewDelegate,
return block_redirects_;
}
- protected:
+ private:
+
// Called the title of the page changes.
// Can be used to update the title of the window.
void SetPageTitle(const std::wstring& title);
@@ -319,7 +320,6 @@ class TestWebViewDelegate : public WebViewDelegate,
// Get a string suitable for dumping a frame to the console.
std::wstring GetFrameDescription(WebKit::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.
diff --git a/webkit/tools/test_shell/test_webview_delegate_gtk.cc b/webkit/tools/test_shell/test_webview_delegate_gtk.cc
index 8340227..f99b280 100644
--- a/webkit/tools/test_shell/test_webview_delegate_gtk.cc
+++ b/webkit/tools/test_shell/test_webview_delegate_gtk.cc
@@ -36,7 +36,9 @@
using WebKit::WebCursorInfo;
using WebKit::WebFrame;
using WebKit::WebNavigationPolicy;
+using WebKit::WebPopupMenuInfo;
using WebKit::WebRect;
+using WebKit::WebWidget;
namespace {
@@ -82,15 +84,12 @@ void SelectionClipboardGetContents(GtkClipboard* clipboard,
} // namespace
-// WebViewDelegate ------------------------------------------------------------
+// WebViewClient --------------------------------------------------------------
-void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) {
- GtkWidget* dialog = gtk_message_dialog_new(
- shell_->mainWnd(), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO,
- GTK_BUTTONS_OK, "%s", WideToUTF8(message).c_str());
- gtk_window_set_title(GTK_WINDOW(dialog), "JavaScript Alert");
- gtk_dialog_run(GTK_DIALOG(dialog)); // Runs a nested message loop.
- gtk_widget_destroy(dialog);
+WebWidget* TestWebViewDelegate::createPopupMenu(
+ const WebPopupMenuInfo& info) {
+ NOTREACHED();
+ return NULL;
}
// WebWidgetClient ------------------------------------------------------------
@@ -261,6 +260,15 @@ void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) {
// Private methods ------------------------------------------------------------
+void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) {
+ GtkWidget* dialog = gtk_message_dialog_new(
+ shell_->mainWnd(), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK, "%s", WideToUTF8(message).c_str());
+ gtk_window_set_title(GTK_WINDOW(dialog), "JavaScript Alert");
+ gtk_dialog_run(GTK_DIALOG(dialog)); // Runs a nested message loop.
+ gtk_widget_destroy(dialog);
+}
+
void TestWebViewDelegate::SetPageTitle(const std::wstring& title) {
gtk_window_set_title(GTK_WINDOW(shell_->mainWnd()),
("Test Shell - " + WideToUTF8(title)).c_str());
diff --git a/webkit/tools/test_shell/test_webview_delegate_win.cc b/webkit/tools/test_shell/test_webview_delegate_win.cc
index 9d0ada7..04eeb1e 100644
--- a/webkit/tools/test_shell/test_webview_delegate_win.cc
+++ b/webkit/tools/test_shell/test_webview_delegate_win.cc
@@ -37,12 +37,16 @@
using WebKit::WebCursorInfo;
using WebKit::WebNavigationPolicy;
+using WebKit::WebPopupMenuInfo;
using WebKit::WebRect;
+using WebKit::WebWidget;
-// WebViewDelegate ------------------------------------------------------------
+// WebViewClient --------------------------------------------------------------
-void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) {
- MessageBox(NULL, message.c_str(), L"JavaScript Alert", MB_OK);
+WebWidget* TestWebViewDelegate::createPopupMenu(
+ const WebPopupMenuInfo& info) {
+ NOTREACHED();
+ return NULL;
}
// WebWidgetClient ------------------------------------------------------------
@@ -197,6 +201,10 @@ void TestWebViewDelegate::UpdateSelectionClipboard(bool is_empty_selection) {
// Private methods ------------------------------------------------------------
+void TestWebViewDelegate::ShowJavaScriptAlert(const std::wstring& message) {
+ MessageBox(NULL, message.c_str(), L"JavaScript Alert", MB_OK);
+}
+
void TestWebViewDelegate::SetPageTitle(const std::wstring& title) {
// The Windows test shell, pre-refactoring, ignored this. *shrug*
}
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index 1f95d93..d2cf2b8 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -1011,6 +1011,7 @@
'api/public/WebURLRequest.h',
'api/public/WebURLResponse.h',
'api/public/WebVector.h',
+ 'api/public/WebViewClient.h',
'api/public/WebWidget.h',
'api/public/WebWidgetClient.h',
'api/public/WebWorker.h',