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.
|
|
|
|
|
|
|
|
// This file contains the implementation of BrowserWebViewDelegate, which serves
|
|
|
|
// as the WebViewDelegate for the BrowserWebHost. The host is expected to
|
|
|
|
// have initialized a MessageLoop before these methods are called.
|
|
|
|
|
|
|
|
#include "browser_webview_delegate.h"
|
2010-06-21 20:02:39 +02:00
|
|
|
#include "browser_appcache_system.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#include "browser_impl.h"
|
|
|
|
#include "browser_navigation_controller.h"
|
2010-07-24 03:13:55 +02:00
|
|
|
#include "cef_context.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#include "request_impl.h"
|
|
|
|
#include "v8_impl.h"
|
|
|
|
|
|
|
|
#include "base/file_util.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "base/process_util.h"
|
2010-08-09 21:13:43 +02:00
|
|
|
#include "base/string_util.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#include "base/trace_event.h"
|
2010-03-29 19:53:26 +02:00
|
|
|
#include "base/utf_string_conversions.h"
|
|
|
|
#include "gfx/gdi_util.h"
|
|
|
|
#include "gfx/native_widget_types.h"
|
2010-08-09 21:13:43 +02:00
|
|
|
#include "gfx/point.h"
|
2010-09-22 15:42:01 +02:00
|
|
|
#include "media/filters/audio_renderer_impl.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#include "net/base/net_errors.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebData.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
|
2010-09-13 03:59:43 +02:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebFileError.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
|
2010-03-29 19:53:26 +02:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebKitClient.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h"
|
2010-06-21 20:02:39 +02:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h"
|
2010-02-11 19:33:33 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
|
2010-01-20 17:43:47 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
|
2010-01-12 02:37:00 +01:00
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
|
2010-02-11 19:33:33 +01:00
|
|
|
#include "webkit/appcache/web_application_cache_host_impl.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#include "webkit/glue/glue_serialize.h"
|
|
|
|
#include "webkit/glue/media/buffered_data_source.h"
|
|
|
|
#include "webkit/glue/media/media_resource_loader_bridge_factory.h"
|
|
|
|
#include "webkit/glue/media/simple_data_source.h"
|
2010-03-29 19:53:26 +02:00
|
|
|
#include "webkit/glue/media/video_renderer_impl.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#include "webkit/glue/webdropdata.h"
|
2010-06-21 20:02:39 +02:00
|
|
|
#include "webkit/glue/plugins/webplugin_impl.h"
|
2009-07-24 21:11:01 +02:00
|
|
|
#include "webkit/glue/webpreferences.h"
|
|
|
|
#include "webkit/glue/webkit_glue.h"
|
|
|
|
#include "webkit/glue/plugins/plugin_list.h"
|
|
|
|
#include "webkit/glue/plugins/webplugin_delegate_impl.h"
|
|
|
|
#include "webkit/glue/webmediaplayer_impl.h"
|
|
|
|
#include "webkit/glue/window_open_disposition.h"
|
2009-05-28 02:31:21 +02:00
|
|
|
#include "browser_webkit_glue.h"
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// TODO(port): make these files work everywhere.
|
|
|
|
#include "browser_drag_delegate.h"
|
|
|
|
#include "browser_drop_delegate.h"
|
|
|
|
#endif
|
|
|
|
|
2010-02-11 19:33:33 +01:00
|
|
|
using appcache::WebApplicationCacheHostImpl;
|
2010-06-21 20:02:39 +02:00
|
|
|
using WebKit::WebApplicationCacheHost;
|
|
|
|
using WebKit::WebApplicationCacheHostClient;
|
2009-09-17 18:56:32 +02:00
|
|
|
using WebKit::WebConsoleMessage;
|
2009-10-13 03:39:30 +02:00
|
|
|
using WebKit::WebContextMenuData;
|
2010-03-29 19:53:26 +02:00
|
|
|
using WebKit::WebCookieJar;
|
2009-07-24 21:11:01 +02:00
|
|
|
using WebKit::WebData;
|
|
|
|
using WebKit::WebDataSource;
|
|
|
|
using WebKit::WebDragData;
|
2009-09-17 18:56:32 +02:00
|
|
|
using WebKit::WebDragOperationsMask;
|
|
|
|
using WebKit::WebEditingAction;
|
2010-04-12 15:47:30 +02:00
|
|
|
using WebKit::WebFileChooserParams;
|
2010-09-13 03:59:43 +02:00
|
|
|
using WebKit::WebFileSystem;
|
|
|
|
using WebKit::WebFileSystemCallbacks;
|
2010-01-12 02:37:00 +01:00
|
|
|
using WebKit::WebFormElement;
|
2009-09-17 18:56:32 +02:00
|
|
|
using WebKit::WebFrame;
|
2009-07-24 21:11:01 +02:00
|
|
|
using WebKit::WebHistoryItem;
|
2010-06-21 20:02:39 +02:00
|
|
|
using WebKit::WebImage;
|
2009-09-17 18:56:32 +02:00
|
|
|
using WebKit::WebMediaPlayer;
|
|
|
|
using WebKit::WebMediaPlayerClient;
|
|
|
|
using WebKit::WebNavigationType;
|
2009-07-24 21:11:01 +02:00
|
|
|
using WebKit::WebNavigationPolicy;
|
2009-09-17 18:56:32 +02:00
|
|
|
using WebKit::WebNode;
|
|
|
|
using WebKit::WebPlugin;
|
|
|
|
using WebKit::WebPluginParams;
|
|
|
|
using WebKit::WebPoint;
|
|
|
|
using WebKit::WebPopupMenu;
|
2010-06-21 20:02:39 +02:00
|
|
|
using WebKit::WebPopupType;
|
2009-09-17 18:56:32 +02:00
|
|
|
using WebKit::WebRange;
|
2009-07-24 21:11:01 +02:00
|
|
|
using WebKit::WebRect;
|
|
|
|
using WebKit::WebScreenInfo;
|
2009-09-22 18:34:27 +02:00
|
|
|
using WebKit::WebSecurityOrigin;
|
2009-07-24 21:11:01 +02:00
|
|
|
using WebKit::WebSize;
|
2010-02-11 19:33:33 +01:00
|
|
|
using WebKit::WebStorageNamespace;
|
2009-07-24 21:11:01 +02:00
|
|
|
using WebKit::WebString;
|
2009-09-17 18:56:32 +02:00
|
|
|
using WebKit::WebTextAffinity;
|
|
|
|
using WebKit::WebTextDirection;
|
2009-07-24 21:11:01 +02:00
|
|
|
using WebKit::WebURL;
|
|
|
|
using WebKit::WebURLError;
|
|
|
|
using WebKit::WebURLRequest;
|
2009-08-13 19:23:08 +02:00
|
|
|
using WebKit::WebURLResponse;
|
2010-01-20 17:43:47 +01:00
|
|
|
using WebKit::WebVector;
|
2009-10-22 01:27:29 +02:00
|
|
|
using WebKit::WebView;
|
2009-07-24 21:11:01 +02:00
|
|
|
using WebKit::WebWidget;
|
2010-06-21 20:02:39 +02:00
|
|
|
using WebKit::WebWindowFeatures;
|
2009-07-24 21:11:01 +02:00
|
|
|
using WebKit::WebWorker;
|
|
|
|
using WebKit::WebWorkerClient;
|
2010-02-03 20:25:11 +01:00
|
|
|
using WebKit::WebKeyboardEvent;
|
2009-07-24 21:11:01 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
int next_page_id_ = 1;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// WebViewDelegate -----------------------------------------------------------
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::SetUserStyleSheetEnabled(bool is_enabled) {
|
2010-07-24 03:13:55 +02:00
|
|
|
WebPreferences* prefs = _Context->web_preferences();
|
2009-09-17 18:56:32 +02:00
|
|
|
prefs->user_style_sheet_enabled = is_enabled;
|
2010-08-31 16:10:31 +02:00
|
|
|
if (browser_->GetWebView())
|
|
|
|
prefs->Apply(browser_->GetWebView());
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) {
|
2010-07-24 03:13:55 +02:00
|
|
|
WebPreferences* prefs = _Context->web_preferences();
|
2009-09-17 18:56:32 +02:00
|
|
|
prefs->user_style_sheet_enabled = true;
|
|
|
|
prefs->user_style_sheet_location = location;
|
2010-08-31 16:10:31 +02:00
|
|
|
if (browser_->GetWebView())
|
|
|
|
prefs->Apply(browser_->GetWebView());
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
// WebViewClient -------------------------------------------------------------
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2010-06-21 20:02:39 +02:00
|
|
|
WebView* BrowserWebViewDelegate::createView(WebFrame* creator,
|
|
|
|
const WebWindowFeatures& features,
|
|
|
|
const WebString& name) {
|
2009-09-17 18:56:32 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> browser =
|
|
|
|
browser_->UIT_CreatePopupWindow(std::wstring());
|
|
|
|
return browser.get() ? browser->GetWebView() : NULL;
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2010-06-21 20:02:39 +02:00
|
|
|
WebWidget* BrowserWebViewDelegate::createPopupMenu(WebPopupType popup_type) {
|
|
|
|
// TODO(darin): Should we take into account |popup_type| (for activation
|
|
|
|
// purpose)?
|
2009-09-17 18:56:32 +02:00
|
|
|
return browser_->UIT_CreatePopupWidget();
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2010-06-21 20:02:39 +02:00
|
|
|
WebStorageNamespace* BrowserWebViewDelegate::createSessionStorageNamespace(
|
|
|
|
unsigned quota) {
|
|
|
|
// Enforce quota, ignoring the parameter from WebCore as in Chrome.
|
|
|
|
return WebKit::WebStorageNamespace::createSessionStorageNamespace(
|
|
|
|
WebStorageNamespace::m_sessionStorageQuota);
|
2010-02-11 19:33:33 +01:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didAddMessageToConsole(
|
|
|
|
const WebConsoleMessage& message, const WebString& source_name,
|
|
|
|
unsigned source_line) {
|
2010-06-22 16:49:03 +02:00
|
|
|
std::wstring wmessage = UTF16ToWideHack(message.text);
|
|
|
|
std::wstring wsource = UTF16ToWideHack(source_name);
|
|
|
|
|
|
|
|
CefHandler::RetVal rv = RV_CONTINUE;
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
rv = handler->HandleConsoleMessage(browser_, wmessage, wsource,
|
|
|
|
source_line);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rv == RV_CONTINUE) {
|
2009-09-17 18:56:32 +02:00
|
|
|
logging::LogMessage("CONSOLE", 0).stream() << "\""
|
|
|
|
<< message.text.utf8().data()
|
|
|
|
<< ",\" source: "
|
|
|
|
<< source_name.utf8().data()
|
|
|
|
<< "("
|
|
|
|
<< source_line
|
|
|
|
<< ")";
|
2010-06-22 16:49:03 +02:00
|
|
|
}
|
2009-09-17 18:56:32 +02:00
|
|
|
}
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2010-07-20 15:28:44 +02:00
|
|
|
void BrowserWebViewDelegate::printPage(WebFrame* frame) {
|
2010-08-31 16:10:31 +02:00
|
|
|
if (!frame)
|
|
|
|
frame = browser_->GetWebView() ? browser_->GetWebView()->mainFrame() : NULL;
|
|
|
|
if (frame)
|
|
|
|
browser_->UIT_PrintPages(frame);
|
2010-07-20 15:28:44 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didStartLoading() {
|
2009-07-24 21:11:01 +02:00
|
|
|
// clear the title so we can tell if it wasn't provided by the page
|
|
|
|
browser_->UIT_SetTitle(std::wstring());
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
2009-07-24 21:11:01 +02:00
|
|
|
// Notify the handler that loading has started
|
|
|
|
handler->HandleLoadStart(browser_, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didStopLoading() {
|
2009-07-24 21:11:01 +02:00
|
|
|
if(browser_->UIT_GetTitle().empty()) {
|
|
|
|
// no title was provided by the page, so send a blank string to the client
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
// Notify the handler of a page title change
|
|
|
|
handler->HandleTitleChange(browser_, browser_->UIT_GetTitle());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
// Notify the handler that loading has ended
|
|
|
|
handler->HandleLoadEnd(browser_, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 18:34:27 +02:00
|
|
|
bool BrowserWebViewDelegate::shouldBeginEditing(const WebRange& range) {
|
|
|
|
return browser_->UIT_AllowEditing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::shouldEndEditing(const WebRange& range) {
|
|
|
|
return browser_->UIT_AllowEditing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::shouldInsertNode(const WebNode& node,
|
|
|
|
const WebRange& range,
|
|
|
|
WebEditingAction action) {
|
|
|
|
return browser_->UIT_AllowEditing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::shouldInsertText(const WebString& text,
|
|
|
|
const WebRange& range,
|
|
|
|
WebEditingAction action) {
|
|
|
|
return browser_->UIT_AllowEditing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::shouldChangeSelectedRange(const WebRange& from_range,
|
|
|
|
const WebRange& to_range,
|
|
|
|
WebTextAffinity affinity,
|
|
|
|
bool still_selecting) {
|
|
|
|
return browser_->UIT_AllowEditing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::shouldDeleteRange(const WebRange& range) {
|
|
|
|
return browser_->UIT_AllowEditing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::shouldApplyStyle(const WebString& style,
|
|
|
|
const WebRange& range) {
|
|
|
|
return browser_->UIT_AllowEditing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::isSmartInsertDeleteEnabled() {
|
|
|
|
return smart_insert_delete_enabled_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::isSelectTrailingWhitespaceEnabled() {
|
|
|
|
return select_trailing_whitespace_enabled_;
|
|
|
|
}
|
|
|
|
|
2010-01-12 02:37:00 +01:00
|
|
|
bool BrowserWebViewDelegate::handleCurrentKeyboardEvent() {
|
2010-02-03 20:25:11 +01:00
|
|
|
CefHandler::RetVal rv = RV_CONTINUE;
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
WebWidgetHost* host = GetWidgetHost();
|
|
|
|
if (host) {
|
|
|
|
WebKeyboardEvent event = host->GetLastKeyEvent();
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case WebKeyboardEvent::RawKeyDown:
|
|
|
|
rv = handler->HandleKeyEvent(browser_,
|
|
|
|
KEYEVENT_RAWKEYDOWN, event.windowsKeyCode,
|
|
|
|
event.modifiers, event.isSystemKey?true:false);
|
|
|
|
break;
|
|
|
|
case WebKeyboardEvent::KeyUp:
|
|
|
|
rv = handler->HandleKeyEvent(browser_,
|
|
|
|
KEYEVENT_KEYUP, event.windowsKeyCode,
|
|
|
|
event.modifiers, event.isSystemKey?true:false);
|
|
|
|
break;
|
|
|
|
case WebKeyboardEvent::Char:
|
|
|
|
rv = handler->HandleKeyEvent(browser_,
|
|
|
|
KEYEVENT_CHAR, event.windowsKeyCode,
|
|
|
|
event.modifiers, event.isSystemKey?true:false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rv == RV_HANDLED)
|
|
|
|
return true;
|
|
|
|
|
2010-01-12 02:37:00 +01:00
|
|
|
if (edit_command_name_.empty())
|
|
|
|
return false;
|
|
|
|
|
2010-08-31 16:10:31 +02:00
|
|
|
WebFrame* frame = browser_->GetWebView() ?
|
|
|
|
browser_->GetWebView()->focusedFrame() : NULL;
|
2010-01-12 02:37:00 +01:00
|
|
|
if (!frame)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return frame->executeCommand(WebString::fromUTF8(edit_command_name_),
|
|
|
|
WebString::fromUTF8(edit_command_value_));
|
|
|
|
}
|
|
|
|
|
2009-10-13 03:39:30 +02:00
|
|
|
bool BrowserWebViewDelegate::runFileChooser(
|
2010-04-12 15:47:30 +02:00
|
|
|
const WebFileChooserParams& params,
|
2009-10-13 03:39:30 +02:00
|
|
|
WebKit::WebFileChooserCompletion* chooser_completion) {
|
2010-01-20 17:43:47 +01:00
|
|
|
// Support file open dialog.
|
|
|
|
std::vector<FilePath> file_names;
|
|
|
|
|
2010-04-12 15:47:30 +02:00
|
|
|
if(!ShowFileChooser(file_names, params.multiSelect, params.title,
|
|
|
|
webkit_glue::WebStringToFilePath(params.initialValue))) {
|
2010-01-20 17:43:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebVector<WebString> ws_file_names(file_names.size());
|
|
|
|
for (size_t i = 0; i < file_names.size(); ++i) {
|
|
|
|
ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
chooser_completion->didChooseFile(ws_file_names);
|
|
|
|
|
|
|
|
return true;
|
2009-10-13 03:39:30 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::runModalAlertDialog(
|
|
|
|
WebFrame* frame, const WebString& message) {
|
|
|
|
std::wstring messageStr = UTF16ToWideHack(message);
|
|
|
|
CefHandler::RetVal rv = RV_CONTINUE;
|
2009-07-24 21:11:01 +02:00
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
2009-09-17 18:56:32 +02:00
|
|
|
rv = handler->HandleJSAlert(browser_, browser_->GetCefFrame(frame),
|
|
|
|
messageStr);
|
|
|
|
}
|
|
|
|
if(rv != RV_HANDLED)
|
|
|
|
ShowJavaScriptAlert(frame, messageStr);
|
|
|
|
}
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
bool BrowserWebViewDelegate::runModalConfirmDialog(
|
|
|
|
WebFrame* frame, const WebString& message) {
|
|
|
|
std::wstring messageStr = UTF16ToWideHack(message);
|
|
|
|
CefHandler::RetVal rv = RV_CONTINUE;
|
|
|
|
bool retval = false;
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
rv = handler->HandleJSConfirm(browser_, browser_->GetCefFrame(frame),
|
|
|
|
messageStr, retval);
|
|
|
|
}
|
|
|
|
if(rv != RV_HANDLED)
|
|
|
|
retval = ShowJavaScriptConfirm(frame, messageStr);
|
|
|
|
return retval;
|
|
|
|
}
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
bool BrowserWebViewDelegate::runModalPromptDialog(
|
|
|
|
WebFrame* frame, const WebString& message, const WebString& default_value,
|
|
|
|
WebString* actual_value) {
|
|
|
|
std::wstring wmessage = UTF16ToWideHack(message);
|
|
|
|
std::wstring wdefault = UTF16ToWideHack(default_value);
|
|
|
|
std::wstring wresult;
|
|
|
|
|
|
|
|
if(actual_value)
|
|
|
|
wresult = UTF16ToWideHack(*actual_value);
|
|
|
|
|
|
|
|
CefHandler::RetVal rv = RV_CONTINUE;
|
|
|
|
bool retval = false;
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
rv = handler->HandleJSPrompt(browser_, browser_->GetCefFrame(frame),
|
|
|
|
wmessage, wdefault, retval, wresult);
|
|
|
|
}
|
|
|
|
if(rv != RV_HANDLED)
|
|
|
|
retval = ShowJavaScriptPrompt(frame, wmessage, wdefault, &wresult);
|
|
|
|
|
|
|
|
if(actual_value && !wresult.empty())
|
|
|
|
*actual_value = WideToUTF16Hack(wresult);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::runModalBeforeUnloadDialog(
|
|
|
|
WebFrame* frame, const WebString& message) {
|
|
|
|
return true; // Allow window closure.
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::setStatusText(const WebString& text) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::setMouseOverURL(const WebURL& url) {
|
|
|
|
}
|
|
|
|
|
2009-11-03 02:39:16 +01:00
|
|
|
void BrowserWebViewDelegate::setKeyboardFocusURL(const WebKit::WebURL& url) {
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::setToolTipText(
|
2010-08-30 22:54:13 +02:00
|
|
|
const WebString& text, WebTextDirection hint)
|
|
|
|
{
|
|
|
|
std::wstring tooltipText(UTF8ToWide(webkit_glue::WebStringToStdString(text)));
|
|
|
|
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get() && handler->HandleTooltip(browser_, tooltipText) == RV_CONTINUE){
|
|
|
|
GetWidgetHost()->SetTooltipText(tooltipText);
|
|
|
|
}
|
2009-09-17 18:56:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::startDragging(
|
2010-06-21 20:02:39 +02:00
|
|
|
const WebDragData& data,
|
|
|
|
WebDragOperationsMask mask,
|
|
|
|
const WebImage& image,
|
|
|
|
const WebPoint& image_offset) {
|
2009-09-17 18:56:32 +02:00
|
|
|
// TODO(tc): Drag and drop is disabled in the test shell because we need
|
|
|
|
// to be able to convert from WebDragData to an IDataObject.
|
|
|
|
//if (!drag_delegate_)
|
|
|
|
// drag_delegate_ = new BrowserDragDelegate(shell_->webViewWnd(),
|
|
|
|
// shell_->webView());
|
|
|
|
//const DWORD ok_effect = DROPEFFECT_COPY | DROPEFFECT_LINK | DROPEFFECT_MOVE;
|
|
|
|
//DWORD effect;
|
|
|
|
//HRESULT res = DoDragDrop(drop_data.data_object, drag_delegate_.get(),
|
|
|
|
// ok_effect, &effect);
|
|
|
|
//DCHECK(DRAGDROP_S_DROP == res || DRAGDROP_S_CANCEL == res);
|
2010-08-31 16:10:31 +02:00
|
|
|
if (browser_->GetWebView())
|
|
|
|
browser_->GetWebView()->dragSourceSystemDragEnded();
|
2009-10-03 03:36:52 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::focusNext() {
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
// Notify the handler that it should take a focus
|
|
|
|
handler->HandleTakeFocus(browser_, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::focusPrevious() {
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
// Notify the handler that it should take a focus
|
|
|
|
handler->HandleTakeFocus(browser_, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::navigateBackForwardSoon(int offset) {
|
|
|
|
browser_->UIT_GetNavigationController()->GoToOffset(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
int BrowserWebViewDelegate::historyBackListCount() {
|
|
|
|
int current_index =
|
|
|
|
browser_->UIT_GetNavigationController()->GetLastCommittedEntryIndex();
|
|
|
|
return current_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BrowserWebViewDelegate::historyForwardListCount() {
|
|
|
|
int current_index =
|
|
|
|
browser_->UIT_GetNavigationController()->GetLastCommittedEntryIndex();
|
|
|
|
return browser_->UIT_GetNavigationController()->GetEntryCount()
|
|
|
|
- current_index - 1;
|
|
|
|
}
|
|
|
|
|
2010-03-29 19:53:26 +02:00
|
|
|
// WebPluginPageDelegate -----------------------------------------------------
|
|
|
|
|
|
|
|
WebCookieJar* BrowserWebViewDelegate::GetCookieJar() {
|
|
|
|
return WebKit::webKitClient()->cookieJar();
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
// WebWidgetClient -----------------------------------------------------------
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didInvalidateRect(const WebRect& rect) {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost())
|
|
|
|
host->DidInvalidateRect(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didScrollRect(int dx, int dy,
|
|
|
|
const WebRect& clip_rect) {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost())
|
|
|
|
host->DidScrollRect(dx, dy, clip_rect);
|
|
|
|
}
|
|
|
|
|
2010-10-03 22:35:06 +02:00
|
|
|
void BrowserWebViewDelegate::scheduleComposite() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost())
|
|
|
|
host->ScheduleComposite();
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didFocus() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost()) {
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if (handler.get() && handler->HandleSetFocus(browser_, true) == RV_CONTINUE)
|
|
|
|
browser_->UIT_SetFocus(host, true);
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didBlur() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost())
|
|
|
|
browser_->UIT_SetFocus(host, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebScreenInfo BrowserWebViewDelegate::screenInfo() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost())
|
|
|
|
return host->GetScreenInfo();
|
|
|
|
|
|
|
|
return WebScreenInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// WebFrameClient ------------------------------------------------------------
|
|
|
|
|
|
|
|
WebPlugin* BrowserWebViewDelegate::createPlugin(
|
|
|
|
WebFrame* frame, const WebPluginParams& params) {
|
2010-06-21 20:02:39 +02:00
|
|
|
bool allow_wildcard = true;
|
|
|
|
WebPluginInfo info;
|
|
|
|
std::string actual_mime_type;
|
|
|
|
if (!NPAPI::PluginList::Singleton()->GetPluginInfo(
|
|
|
|
params.url, params.mimeType.utf8(), allow_wildcard, &info,
|
|
|
|
&actual_mime_type)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actual_mime_type.empty())
|
|
|
|
actual_mime_type = params.mimeType.utf8();
|
|
|
|
|
|
|
|
return new webkit_glue::WebPluginImpl(
|
|
|
|
frame, params, info.path, actual_mime_type, AsWeakPtr());
|
2009-09-17 18:56:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WebMediaPlayer* BrowserWebViewDelegate::createMediaPlayer(
|
|
|
|
WebFrame* frame, WebMediaPlayerClient* client) {
|
|
|
|
scoped_refptr<media::FilterFactoryCollection> factory =
|
|
|
|
new media::FilterFactoryCollection();
|
|
|
|
|
2010-09-22 15:42:01 +02:00
|
|
|
// Add the audio renderer factory.
|
|
|
|
factory->AddFactory(media::AudioRendererImpl::CreateFilterFactory());
|
|
|
|
|
2010-03-29 19:53:26 +02:00
|
|
|
appcache::WebApplicationCacheHostImpl* appcache_host =
|
|
|
|
appcache::WebApplicationCacheHostImpl::FromFrame(frame);
|
2010-02-11 19:33:33 +01:00
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
// TODO(hclam): this is the same piece of code as in RenderView, maybe they
|
|
|
|
// should be grouped together.
|
|
|
|
webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
|
|
|
|
new webkit_glue::MediaResourceLoaderBridgeFactory(
|
2010-03-29 19:53:26 +02:00
|
|
|
GURL(), // referrer
|
|
|
|
"null", // frame origin
|
|
|
|
"null", // main_frame_origin
|
2009-09-17 18:56:32 +02:00
|
|
|
base::GetCurrentProcId(),
|
2010-02-11 19:33:33 +01:00
|
|
|
appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
|
2009-09-17 18:56:32 +02:00
|
|
|
0);
|
2009-10-25 20:29:12 +01:00
|
|
|
// A simple data source that keeps all data in memory.
|
|
|
|
media::FilterFactory* simple_data_source_factory =
|
|
|
|
webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
|
|
|
|
bridge_factory);
|
|
|
|
// A sophisticated data source that does memory caching.
|
|
|
|
media::FilterFactory* buffered_data_source_factory =
|
|
|
|
webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
|
|
|
|
bridge_factory);
|
|
|
|
factory->AddFactory(buffered_data_source_factory);
|
|
|
|
factory->AddFactory(simple_data_source_factory);
|
2010-03-29 19:53:26 +02:00
|
|
|
return new webkit_glue::WebMediaPlayerImpl(
|
2010-06-21 20:02:39 +02:00
|
|
|
client, factory, new webkit_glue::VideoRendererImpl::FactoryFactory(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
WebApplicationCacheHost* BrowserWebViewDelegate::createApplicationCacheHost(
|
|
|
|
WebFrame* frame, WebApplicationCacheHostClient* client) {
|
|
|
|
return BrowserAppCacheSystem::CreateApplicationCacheHost(client);
|
2009-09-17 18:56:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::loadURLExternally(
|
|
|
|
WebFrame* frame, const WebURLRequest& request,
|
|
|
|
WebNavigationPolicy policy) {
|
|
|
|
DCHECK_NE(policy, WebKit::WebNavigationPolicyCurrentTab);
|
|
|
|
browser_->UIT_CreatePopupWindow(UTF8ToWide(request.url().spec().data()));
|
|
|
|
}
|
|
|
|
|
|
|
|
WebNavigationPolicy BrowserWebViewDelegate::decidePolicyForNavigation(
|
|
|
|
WebFrame* frame, const WebURLRequest& request,
|
2009-10-13 03:39:30 +02:00
|
|
|
WebNavigationType type, const WebNode& originating_node,
|
|
|
|
WebNavigationPolicy default_policy, bool is_redirect) {
|
2009-07-24 21:11:01 +02:00
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
// Gather browse request information
|
|
|
|
CefRefPtr<CefRequest> req(CefRequest::CreateRequest());
|
2010-08-09 22:04:13 +02:00
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
GURL request_url = request.url();
|
2010-08-09 22:04:13 +02:00
|
|
|
if (!request_url.is_valid())
|
|
|
|
return WebKit::WebNavigationPolicyIgnore;
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
req->SetURL(UTF8ToWide(request_url.spec()));
|
|
|
|
req->SetMethod(
|
|
|
|
UTF8ToWide(webkit_glue::WebStringToStdString(request.httpMethod())));
|
|
|
|
|
|
|
|
const WebKit::WebHTTPBody& httpBody = request.httpBody();
|
|
|
|
if(!httpBody.isNull()) {
|
|
|
|
CefRefPtr<CefPostData> postdata(CefPostData::CreatePostData());
|
|
|
|
static_cast<CefPostDataImpl*>(postdata.get())->Set(httpBody);
|
|
|
|
req->SetPostData(postdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRequest::HeaderMap map;
|
|
|
|
CefRequestImpl::GetHeaderMap(request, map);
|
|
|
|
if(map.size() > 0)
|
|
|
|
static_cast<CefRequestImpl*>(req.get())->SetHeaderMap(map);
|
|
|
|
|
|
|
|
// Notify the handler of a browse request
|
|
|
|
CefHandler::RetVal rv = handler->HandleBeforeBrowse(browser_,
|
|
|
|
browser_->GetCefFrame(frame), req, (CefHandler::NavType)type,
|
|
|
|
is_redirect);
|
|
|
|
if(rv == RV_HANDLED)
|
|
|
|
return WebKit::WebNavigationPolicyIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebNavigationPolicy result;
|
|
|
|
if (policy_delegate_enabled_) {
|
|
|
|
if (policy_delegate_is_permissive_) {
|
|
|
|
result = WebKit::WebNavigationPolicyCurrentTab;
|
|
|
|
} else {
|
|
|
|
result = WebKit::WebNavigationPolicyIgnore;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = default_policy;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-10-22 01:27:29 +02:00
|
|
|
WebURLError BrowserWebViewDelegate::cannotHandleRequestError(
|
|
|
|
WebFrame* frame, const WebURLRequest& request) {
|
|
|
|
WebURLError error;
|
|
|
|
error.domain = WebString::fromUTF8(net::kErrorDomain);
|
|
|
|
error.reason = net::ERR_ABORTED;
|
|
|
|
error.unreachableURL = request.url();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebURLError BrowserWebViewDelegate::cancelledError(
|
|
|
|
WebFrame* frame, const WebURLRequest& request) {
|
|
|
|
WebURLError error;
|
|
|
|
error.domain = WebString::fromUTF8(net::kErrorDomain);
|
|
|
|
error.reason = net::ERR_ABORTED;
|
|
|
|
error.unreachableURL = request.url();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didCreateDataSource(
|
|
|
|
WebFrame* frame, WebDataSource* ds) {
|
2009-07-24 21:11:01 +02:00
|
|
|
ds->setExtraData(pending_extra_data_.release());
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didStartProvisionalLoad(WebFrame* frame) {
|
2009-07-24 21:11:01 +02:00
|
|
|
if (!top_loading_frame_) {
|
|
|
|
top_loading_frame_ = frame;
|
|
|
|
}
|
2009-09-17 18:56:32 +02:00
|
|
|
|
|
|
|
UpdateAddressBar(frame->view());
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didReceiveServerRedirectForProvisionalLoad(
|
|
|
|
WebFrame* frame) {
|
|
|
|
UpdateAddressBar(frame->view());
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didFailProvisionalLoad(
|
|
|
|
WebFrame* frame, const WebURLError& error) {
|
2009-07-24 21:11:01 +02:00
|
|
|
LocationChangeDone(frame);
|
|
|
|
|
|
|
|
// error codes are defined in net\base\net_error_list.h
|
|
|
|
|
|
|
|
// Don't display an error page if this is simply a cancelled load. Aside
|
|
|
|
// from being dumb, WebCore doesn't expect it and it will cause a crash.
|
|
|
|
if (error.reason == net::ERR_ABORTED)
|
|
|
|
return;
|
|
|
|
|
2009-08-13 19:23:08 +02:00
|
|
|
const WebDataSource* failed_ds = frame->provisionalDataSource();
|
2009-07-24 21:11:01 +02:00
|
|
|
BrowserExtraData* extra_data =
|
|
|
|
static_cast<BrowserExtraData*>(failed_ds->extraData());
|
2010-09-23 17:11:25 +02:00
|
|
|
|
|
|
|
if (extra_data && !extra_data->request_committed) {
|
|
|
|
// Set the pending extra_data for our error page as the same pending_page_id
|
|
|
|
// to keep the history from getting messed up.
|
|
|
|
set_pending_extra_data(new BrowserExtraData(extra_data->pending_page_id));
|
|
|
|
}
|
2009-07-24 21:11:01 +02:00
|
|
|
|
|
|
|
std::string error_text;
|
|
|
|
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
// give the handler an opportunity to generate a custom error message
|
|
|
|
std::wstring error_str;
|
|
|
|
CefHandler::RetVal rv = handler->HandleLoadError(browser_,
|
|
|
|
browser_->GetCefFrame(frame),
|
|
|
|
static_cast<CefHandler::ErrorCode>(error.reason),
|
|
|
|
UTF8ToWide(failed_ds->request().url().spec().data()), error_str);
|
|
|
|
if(rv == RV_HANDLED && !error_str.empty())
|
|
|
|
error_text = WideToUTF8(error_str);
|
|
|
|
} else {
|
2010-08-09 21:13:43 +02:00
|
|
|
error_text = StringPrintf("Error %d when loading url %s",
|
|
|
|
error.reason, failed_ds->request().url().spec().data());
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we never show errors in view source mode.
|
2009-08-13 19:23:08 +02:00
|
|
|
frame->enableViewSourceMode(false);
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2009-08-13 19:23:08 +02:00
|
|
|
frame->loadHTMLString(
|
2010-09-23 17:11:25 +02:00
|
|
|
error_text, GURL("testshell-error:"), error.unreachableURL, false);
|
|
|
|
|
|
|
|
// In case loadHTMLString failed before DidCreateDataSource was called.
|
|
|
|
set_pending_extra_data(NULL);
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didCommitProvisionalLoad(
|
|
|
|
WebFrame* frame, bool is_new_navigation) {
|
2009-07-24 21:11:01 +02:00
|
|
|
UpdateForCommittedLoad(frame, is_new_navigation);
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
// Notify the handler that loading has started
|
|
|
|
handler->HandleLoadStart(browser_, browser_->GetCefFrame(frame));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-31 19:52:34 +02:00
|
|
|
void BrowserWebViewDelegate::didClearWindowObject(WebFrame* frame) {
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
v8::HandleScope handle_scope;
|
|
|
|
v8::Handle<v8::Context> context = webkit_glue::GetV8Context(frame);
|
|
|
|
if(context.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
v8::Context::Scope scope(context);
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> cframe(browser_->GetCefFrame(frame));
|
|
|
|
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(context->Global());
|
|
|
|
handler->HandleJSBinding(browser_, cframe, object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didReceiveTitle(
|
|
|
|
WebFrame* frame, const WebString& title) {
|
|
|
|
std::wstring wtitle = UTF16ToWideHack(title);
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
browser_->UIT_SetTitle(wtitle);
|
2009-07-24 21:11:01 +02:00
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
2009-09-17 18:56:32 +02:00
|
|
|
// Notify the handler of a page title change
|
|
|
|
handler->HandleTitleChange(browser_, wtitle);
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didFailLoad(
|
|
|
|
WebFrame* frame, const WebURLError& error) {
|
|
|
|
LocationChangeDone(frame);
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didFinishLoad(WebFrame* frame) {
|
|
|
|
UpdateAddressBar(frame->view());
|
|
|
|
LocationChangeDone(frame);
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
// Notify the handler that loading has ended
|
|
|
|
handler->HandleLoadEnd(browser_, browser_->GetCefFrame(frame));
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::didChangeLocationWithinPage(
|
|
|
|
WebFrame* frame, bool is_new_navigation) {
|
|
|
|
frame->dataSource()->setExtraData(pending_extra_data_.release());
|
|
|
|
UpdateForCommittedLoad(frame, is_new_navigation);
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::willSendRequest(
|
|
|
|
WebFrame* frame, unsigned identifier, WebURLRequest& request,
|
|
|
|
const WebURLResponse& redirect_response) {
|
|
|
|
if (!redirect_response.isNull() && block_redirects_) {
|
|
|
|
// To block the request, we set its URL to an empty one.
|
|
|
|
request.setURL(WebURL());
|
|
|
|
return;
|
|
|
|
}
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
// The requestor ID is used by the resource loader bridge to locate the
|
|
|
|
// browser that originated the request.
|
|
|
|
request.setRequestorID(browser_->UIT_GetUniqueID());
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2010-07-20 00:19:30 +02:00
|
|
|
void BrowserWebViewDelegate::reportFindInPageMatchCount(
|
|
|
|
int request_id, int count, bool final_update)
|
|
|
|
{
|
|
|
|
browser_->UIT_NotifyFindStatus(request_id, count, gfx::Rect(),
|
|
|
|
-1, // // Don't update active match ordinal.
|
|
|
|
final_update);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::reportFindInPageSelection(
|
|
|
|
int request_id, int active_match_ordinal, const WebKit::WebRect& sel)
|
|
|
|
{
|
|
|
|
browser_->UIT_NotifyFindStatus(request_id, -1, sel, active_match_ordinal,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
2010-09-13 03:59:43 +02:00
|
|
|
void BrowserWebViewDelegate::openFileSystem(
|
|
|
|
WebFrame* frame, WebFileSystem::Type type, long long size,
|
|
|
|
WebFileSystemCallbacks* callbacks) {
|
|
|
|
if (browser_->file_system_root().empty()) {
|
|
|
|
// The FileSystem temp directory was not initialized successfully.
|
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
} else {
|
|
|
|
callbacks->didOpenFileSystem(
|
|
|
|
"CefFileSystem",
|
|
|
|
webkit_glue::FilePathToWebString(browser_->file_system_root()));
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
// Public methods ------------------------------------------------------------
|
2009-07-24 21:11:01 +02:00
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
BrowserWebViewDelegate::BrowserWebViewDelegate(CefBrowserImpl* browser)
|
|
|
|
: policy_delegate_enabled_(false),
|
|
|
|
policy_delegate_is_permissive_(false),
|
|
|
|
policy_delegate_should_notify_done_(false),
|
|
|
|
browser_(browser),
|
|
|
|
top_loading_frame_(NULL),
|
|
|
|
page_id_(-1),
|
|
|
|
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
|
|
|
|
block_redirects_(false) {
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
BrowserWebViewDelegate::~BrowserWebViewDelegate() {
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::Reset() {
|
|
|
|
// Do a little placement new dance...
|
|
|
|
CefBrowserImpl* browser = browser_;
|
|
|
|
this->~BrowserWebViewDelegate();
|
|
|
|
new (this) BrowserWebViewDelegate(browser);
|
2009-07-24 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::SetSmartInsertDeleteEnabled(bool enabled) {
|
|
|
|
smart_insert_delete_enabled_ = enabled;
|
|
|
|
// In upstream WebKit, smart insert/delete is mutually exclusive with select
|
|
|
|
// trailing whitespace, however, we allow both because Chromium on Windows
|
|
|
|
// allows both.
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::SetSelectTrailingWhitespaceEnabled(bool enabled) {
|
|
|
|
select_trailing_whitespace_enabled_ = enabled;
|
|
|
|
// In upstream WebKit, smart insert/delete is mutually exclusive with select
|
|
|
|
// trailing whitespace, however, we allow both because Chromium on Windows
|
|
|
|
// allows both.
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::RegisterDragDrop() {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
// TODO(port): add me once drag and drop works.
|
|
|
|
DCHECK(!drop_delegate_);
|
|
|
|
drop_delegate_ = new BrowserDropDelegate(browser_->GetWebViewWndHandle(),
|
|
|
|
browser_->GetWebView());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-08-13 19:23:08 +02:00
|
|
|
void BrowserWebViewDelegate::RevokeDragDrop() {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
::RevokeDragDrop(browser_->GetWebViewWndHandle());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
void BrowserWebViewDelegate::SetCustomPolicyDelegate(bool is_custom,
|
|
|
|
bool is_permissive) {
|
|
|
|
policy_delegate_enabled_ = is_custom;
|
|
|
|
policy_delegate_is_permissive_ = is_permissive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::WaitForPolicyDelegate() {
|
|
|
|
policy_delegate_enabled_ = true;
|
2009-09-17 18:56:32 +02:00
|
|
|
policy_delegate_should_notify_done_ = true;
|
2009-08-13 19:23:08 +02:00
|
|
|
}
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
// Private methods -----------------------------------------------------------
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::UpdateAddressBar(WebView* webView) {
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::LocationChangeDone(WebFrame* frame) {
|
2009-07-24 21:11:01 +02:00
|
|
|
if (frame == top_loading_frame_)
|
|
|
|
top_loading_frame_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebWidgetHost* BrowserWebViewDelegate::GetWidgetHost() {
|
|
|
|
if (this == browser_->GetWebViewDelegate())
|
|
|
|
return browser_->GetWebViewHost();
|
|
|
|
if (this == browser_->GetPopupDelegate())
|
|
|
|
return browser_->GetPopupHost();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::UpdateForCommittedLoad(WebFrame* frame,
|
2009-07-24 21:11:01 +02:00
|
|
|
bool is_new_navigation) {
|
|
|
|
// Code duplicated from RenderView::DidCommitLoadForFrame.
|
|
|
|
BrowserExtraData* extra_data = static_cast<BrowserExtraData*>(
|
2009-08-13 19:23:08 +02:00
|
|
|
frame->dataSource()->extraData());
|
2009-07-24 21:11:01 +02:00
|
|
|
|
|
|
|
if (is_new_navigation) {
|
|
|
|
// New navigation.
|
|
|
|
UpdateSessionHistory(frame);
|
|
|
|
page_id_ = next_page_id_++;
|
|
|
|
} else if (extra_data && extra_data->pending_page_id != -1 &&
|
|
|
|
!extra_data->request_committed) {
|
|
|
|
// This is a successful session history navigation!
|
|
|
|
UpdateSessionHistory(frame);
|
|
|
|
page_id_ = extra_data->pending_page_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't update session history multiple times.
|
|
|
|
if (extra_data)
|
|
|
|
extra_data->request_committed = true;
|
|
|
|
|
|
|
|
UpdateURL(frame);
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
|
2009-08-13 19:23:08 +02:00
|
|
|
WebDataSource* ds = frame->dataSource();
|
2009-07-24 21:11:01 +02:00
|
|
|
DCHECK(ds);
|
|
|
|
|
|
|
|
const WebURLRequest& request = ds->request();
|
|
|
|
|
|
|
|
// Type is unused.
|
|
|
|
scoped_ptr<BrowserNavigationEntry> entry(new BrowserNavigationEntry);
|
|
|
|
|
|
|
|
// Bug 654101: the referrer will be empty on https->http transitions. It
|
|
|
|
// would be nice if we could get the real referrer from somewhere.
|
|
|
|
entry->SetPageID(page_id_);
|
|
|
|
if (ds->hasUnreachableURL()) {
|
|
|
|
entry->SetURL(ds->unreachableURL());
|
|
|
|
} else {
|
|
|
|
entry->SetURL(request.url());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring url = UTF8ToWide(entry->GetURL().spec().c_str());
|
|
|
|
|
|
|
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
|
|
|
if(handler.get()) {
|
|
|
|
// Notify the handler of an address change
|
|
|
|
handler->HandleAddressChange(browser_, browser_->GetCefFrame(frame), url);
|
|
|
|
}
|
|
|
|
|
2009-08-13 19:23:08 +02:00
|
|
|
const WebHistoryItem& history_item = frame->currentHistoryItem();
|
2009-07-24 21:11:01 +02:00
|
|
|
if (!history_item.isNull())
|
|
|
|
entry->SetContentState(webkit_glue::HistoryItemToString(history_item));
|
|
|
|
|
|
|
|
browser_->UIT_GetNavigationController()->DidNavigateToEntry(entry.release());
|
|
|
|
|
|
|
|
last_page_id_updated_ = std::max(last_page_id_updated_, page_id_);
|
|
|
|
}
|
|
|
|
|
2009-09-17 18:56:32 +02:00
|
|
|
void BrowserWebViewDelegate::UpdateSessionHistory(WebFrame* frame) {
|
2009-07-24 21:11:01 +02:00
|
|
|
// If we have a valid page ID at this point, then it corresponds to the page
|
|
|
|
// we are navigating away from. Otherwise, this is the first navigation, so
|
|
|
|
// there is no past session history to record.
|
|
|
|
if (page_id_ == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
BrowserNavigationEntry* entry = static_cast<BrowserNavigationEntry*>(
|
|
|
|
browser_->UIT_GetNavigationController()->GetEntryWithPageID(page_id_));
|
|
|
|
if (!entry)
|
|
|
|
return;
|
|
|
|
|
2010-08-31 16:10:31 +02:00
|
|
|
if (!browser_->GetWebView())
|
|
|
|
return;
|
|
|
|
|
2009-07-24 21:11:01 +02:00
|
|
|
const WebHistoryItem& history_item =
|
2009-10-03 03:36:52 +02:00
|
|
|
browser_->GetWebView()->mainFrame()->previousHistoryItem();
|
2009-07-24 21:11:01 +02:00
|
|
|
if (history_item.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry->SetContentState(webkit_glue::HistoryItemToString(history_item));
|
|
|
|
}
|