2010-10-03 23:04:50 +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.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/browser_webview_delegate.h"
|
2012-01-23 20:04:54 +01:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/browser_appcache_system.h"
|
|
|
|
#include "libcef/browser_file_system.h"
|
|
|
|
#include "libcef/browser_impl.h"
|
|
|
|
#include "libcef/browser_navigation_controller.h"
|
|
|
|
#include "libcef/browser_webkit_glue.h"
|
|
|
|
#include "libcef/browser_webstoragenamespace_impl.h"
|
|
|
|
#include "libcef/browser_zoom_map.h"
|
|
|
|
#include "libcef/cef_context.h"
|
|
|
|
#include "libcef/cef_process_ui_thread.h"
|
|
|
|
#include "libcef/dom_document_impl.h"
|
|
|
|
#include "libcef/request_impl.h"
|
|
|
|
#include "libcef/v8_impl.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2010-10-26 18:37:30 +02:00
|
|
|
#include "base/debug/trace_event.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/file_util.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "base/process_util.h"
|
|
|
|
#include "base/string_util.h"
|
2011-09-10 21:40:03 +02:00
|
|
|
#include "base/stringprintf.h"
|
2012-04-11 21:37:06 +02:00
|
|
|
#include "media/audio/null_audio_sink.h"
|
2010-12-16 22:54:42 +01:00
|
|
|
#include "media/base/filter_collection.h"
|
2011-09-10 21:40:03 +02:00
|
|
|
#include "media/base/media_log.h"
|
2012-04-05 00:32:24 +02:00
|
|
|
#include "media/base/message_loop_factory.h"
|
2012-04-11 21:37:06 +02:00
|
|
|
#include "media/filters/audio_renderer_impl.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "net/base/net_errors.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
|
2011-07-03 02:03:30 +02:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
|
2011-12-21 19:35:55 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
|
|
|
|
#include "ui/gfx/native_widget_types.h"
|
|
|
|
#include "ui/gfx/point.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "webkit/appcache/web_application_cache_host_impl.h"
|
|
|
|
#include "webkit/glue/glue_serialize.h"
|
|
|
|
#include "webkit/glue/webpreferences.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "webkit/glue/weburlrequest_extradata_impl.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "webkit/glue/webkit_glue.h"
|
|
|
|
#include "webkit/glue/window_open_disposition.h"
|
2011-11-18 23:10:53 +01:00
|
|
|
#include "webkit/media/webmediaplayer_impl.h"
|
2011-01-07 22:34:20 +01:00
|
|
|
#include "webkit/plugins/npapi/plugin_list.h"
|
|
|
|
#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
|
|
|
|
#include "webkit/plugins/npapi/webplugin_impl.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/browser_drag_delegate_win.h"
|
|
|
|
#include "libcef/web_drop_target_win.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#endif
|
|
|
|
|
2012-01-23 20:04:54 +01:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
#include "libcef/web_drag_source_gtk.h"
|
|
|
|
#include "libcef/web_drop_target_gtk.h"
|
|
|
|
#endif
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
using appcache::WebApplicationCacheHostImpl;
|
|
|
|
using WebKit::WebApplicationCacheHost;
|
|
|
|
using WebKit::WebApplicationCacheHostClient;
|
|
|
|
using WebKit::WebConsoleMessage;
|
|
|
|
using WebKit::WebContextMenuData;
|
|
|
|
using WebKit::WebCookieJar;
|
|
|
|
using WebKit::WebData;
|
|
|
|
using WebKit::WebDataSource;
|
|
|
|
using WebKit::WebEditingAction;
|
|
|
|
using WebKit::WebFileChooserParams;
|
|
|
|
using WebKit::WebFileSystem;
|
|
|
|
using WebKit::WebFileSystemCallbacks;
|
|
|
|
using WebKit::WebFormElement;
|
|
|
|
using WebKit::WebFrame;
|
|
|
|
using WebKit::WebHistoryItem;
|
|
|
|
using WebKit::WebMediaPlayer;
|
|
|
|
using WebKit::WebMediaPlayerClient;
|
|
|
|
using WebKit::WebNavigationType;
|
|
|
|
using WebKit::WebNavigationPolicy;
|
|
|
|
using WebKit::WebNode;
|
|
|
|
using WebKit::WebPlugin;
|
|
|
|
using WebKit::WebPluginParams;
|
|
|
|
using WebKit::WebPoint;
|
|
|
|
using WebKit::WebPopupType;
|
|
|
|
using WebKit::WebRange;
|
|
|
|
using WebKit::WebRect;
|
|
|
|
using WebKit::WebScreenInfo;
|
|
|
|
using WebKit::WebSecurityOrigin;
|
|
|
|
using WebKit::WebSize;
|
|
|
|
using WebKit::WebStorageNamespace;
|
|
|
|
using WebKit::WebString;
|
|
|
|
using WebKit::WebTextAffinity;
|
|
|
|
using WebKit::WebTextDirection;
|
|
|
|
using WebKit::WebURL;
|
|
|
|
using WebKit::WebURLError;
|
|
|
|
using WebKit::WebURLRequest;
|
|
|
|
using WebKit::WebURLResponse;
|
|
|
|
using WebKit::WebVector;
|
|
|
|
using WebKit::WebView;
|
|
|
|
using WebKit::WebWidget;
|
|
|
|
using WebKit::WebWindowFeatures;
|
|
|
|
using WebKit::WebKeyboardEvent;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
int next_page_id_ = 1;
|
|
|
|
|
2010-11-16 17:45:49 +01:00
|
|
|
void TranslatePopupFeatures(const WebWindowFeatures& webKitFeatures,
|
2012-01-10 00:46:23 +01:00
|
|
|
CefPopupFeatures& features) {
|
2010-11-16 17:45:49 +01:00
|
|
|
features.x = static_cast<int>(webKitFeatures.x);
|
|
|
|
features.xSet = webKitFeatures.xSet;
|
|
|
|
features.y = static_cast<int>(webKitFeatures.y);
|
|
|
|
features.ySet = webKitFeatures.ySet;
|
|
|
|
features.width = static_cast<int>(webKitFeatures.width);
|
|
|
|
features.widthSet = webKitFeatures.widthSet;
|
|
|
|
features.height = static_cast<int>(webKitFeatures.height);
|
|
|
|
features.heightSet = webKitFeatures.heightSet;
|
|
|
|
|
|
|
|
features.menuBarVisible = webKitFeatures.menuBarVisible;
|
|
|
|
features.statusBarVisible = webKitFeatures.statusBarVisible;
|
|
|
|
features.toolBarVisible = webKitFeatures.toolBarVisible;
|
|
|
|
features.locationBarVisible = webKitFeatures.locationBarVisible;
|
|
|
|
features.scrollbarsVisible = webKitFeatures.scrollbarsVisible;
|
|
|
|
features.resizable = webKitFeatures.resizable;
|
|
|
|
|
|
|
|
features.fullscreen = webKitFeatures.fullscreen;
|
2012-01-10 00:46:23 +01:00
|
|
|
features.dialog = webKitFeatures.dialog;
|
2010-11-16 17:45:49 +01:00
|
|
|
features.additionalFeatures = NULL;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (webKitFeatures.additionalFeatures.size() > 0)
|
2010-11-16 17:45:49 +01:00
|
|
|
features.additionalFeatures = cef_string_list_alloc();
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString str;
|
2012-01-10 00:46:23 +01:00
|
|
|
for (unsigned int i = 0; i < webKitFeatures.additionalFeatures.size(); ++i) {
|
2010-11-22 18:49:46 +01:00
|
|
|
str = string16(webKitFeatures.additionalFeatures[i]);
|
|
|
|
cef_string_list_append(features.additionalFeatures, str.GetStruct());
|
2010-11-16 17:45:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// WebViewClient -------------------------------------------------------------
|
|
|
|
|
|
|
|
WebView* BrowserWebViewDelegate::createView(WebFrame* creator,
|
2011-01-12 00:46:14 +01:00
|
|
|
const WebURLRequest& request, const WebWindowFeatures& features,
|
2012-04-05 00:32:24 +02:00
|
|
|
const WebString& name, WebKit::WebNavigationPolicy policy) {
|
2011-01-12 00:46:14 +01:00
|
|
|
CefString url;
|
|
|
|
if (!request.isNull())
|
|
|
|
url = request.url().spec().utf16();
|
2010-11-16 17:45:49 +01:00
|
|
|
CefPopupFeatures cefFeatures;
|
|
|
|
TranslatePopupFeatures(features, cefFeatures);
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> browser =
|
2011-01-12 00:46:14 +01:00
|
|
|
browser_->UIT_CreatePopupWindow(url, cefFeatures);
|
2011-01-29 02:42:59 +01:00
|
|
|
return browser.get() ? browser->UIT_GetWebView() : NULL;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WebWidget* BrowserWebViewDelegate::createPopupMenu(WebPopupType popup_type) {
|
|
|
|
// TODO(darin): Should we take into account |popup_type| (for activation
|
|
|
|
// purpose)?
|
|
|
|
return browser_->UIT_CreatePopupWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
WebStorageNamespace* BrowserWebViewDelegate::createSessionStorageNamespace(
|
|
|
|
unsigned quota) {
|
2012-04-05 00:32:24 +02:00
|
|
|
#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND
|
|
|
|
NOTREACHED();
|
|
|
|
#else
|
2011-10-06 15:34:47 +02:00
|
|
|
// Ignore the quota parameter from WebCore as in Chrome.
|
|
|
|
return new BrowserWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
|
|
|
|
kLocalStorageNamespaceId + 1);
|
2012-04-05 00:32:24 +02:00
|
|
|
#endif
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-02-18 01:19:52 +01:00
|
|
|
WebKit::WebGraphicsContext3D* BrowserWebViewDelegate::createGraphicsContext3D(
|
2012-04-05 00:32:24 +02:00
|
|
|
const WebKit::WebGraphicsContext3D::Attributes& attributes) {
|
|
|
|
WebKit::WebView* web_view = browser_->UIT_GetWebView();
|
|
|
|
if (!web_view)
|
|
|
|
return NULL;
|
|
|
|
|
2012-02-18 01:19:52 +01:00
|
|
|
const CefSettings& settings = _Context->settings();
|
|
|
|
return webkit_glue::CreateGraphicsContext3D(settings.graphics_implementation,
|
2012-04-05 00:32:24 +02:00
|
|
|
attributes, web_view, true);
|
2012-02-18 01:19:52 +01:00
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
void BrowserWebViewDelegate::didAddMessageToConsole(
|
|
|
|
const WebConsoleMessage& message, const WebString& source_name,
|
|
|
|
unsigned source_line) {
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string messageStr = message.text.utf8();
|
|
|
|
std::string sourceStr = source_name.utf8();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
bool handled = false;
|
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefDisplayHandler> handler = client->GetDisplayHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
handled = handler->OnConsoleMessage(browser_, messageStr, sourceStr,
|
|
|
|
source_line);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!handled) {
|
2010-10-03 23:04:50 +02:00
|
|
|
logging::LogMessage("CONSOLE", 0).stream() << "\""
|
2010-11-22 18:49:46 +01:00
|
|
|
<< messageStr
|
2010-10-03 23:04:50 +02:00
|
|
|
<< ",\" source: "
|
2010-11-22 18:49:46 +01:00
|
|
|
<< sourceStr
|
2010-10-03 23:04:50 +02:00
|
|
|
<< "("
|
|
|
|
<< source_line
|
|
|
|
<< ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::printPage(WebFrame* frame) {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (!frame) {
|
|
|
|
WebView* view = browser_->UIT_GetWebView();
|
|
|
|
if (view)
|
|
|
|
frame = view->mainFrame();
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
if (frame)
|
|
|
|
browser_->UIT_PrintPages(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2010-11-16 17:45:49 +01:00
|
|
|
bool BrowserWebViewDelegate::shouldChangeSelectedRange(
|
|
|
|
const WebRange& from_range, const WebRange& to_range,
|
|
|
|
WebTextAffinity affinity, bool still_selecting) {
|
2010-10-03 23:04:50 +02:00
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::handleCurrentKeyboardEvent() {
|
2011-11-04 19:19:14 +01:00
|
|
|
WebWidgetHost* host = GetWidgetHost();
|
|
|
|
if (host && OnKeyboardEvent(host->GetLastKeyEvent(), true))
|
2010-10-03 23:04:50 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (edit_command_name_.empty())
|
|
|
|
return false;
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = browser_->UIT_GetWebView();
|
|
|
|
WebFrame* frame = NULL;
|
|
|
|
if (view)
|
|
|
|
frame = view->focusedFrame();
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!frame)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return frame->executeCommand(WebString::fromUTF8(edit_command_name_),
|
|
|
|
WebString::fromUTF8(edit_command_value_));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::runFileChooser(
|
|
|
|
const WebFileChooserParams& params,
|
|
|
|
WebKit::WebFileChooserCompletion* chooser_completion) {
|
|
|
|
// Support file open dialog.
|
|
|
|
std::vector<FilePath> file_names;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
|
|
|
if (!ShowFileChooser(file_names, params.multiSelect, params.title,
|
2010-10-03 23:04:50 +02:00
|
|
|
webkit_glue::WebStringToFilePath(params.initialValue))) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::runModalAlertDialog(
|
|
|
|
WebFrame* frame, const WebString& message) {
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString messageStr = string16(message);
|
2011-05-20 16:42:25 +02:00
|
|
|
bool handled = false;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
CefRefPtr<CefJSDialogHandler> handler;
|
|
|
|
if (client.get())
|
|
|
|
handler = client->GetJSDialogHandler();
|
|
|
|
|
|
|
|
if (handler.get()) {
|
|
|
|
handled = handler->OnJSAlert(browser_, browser_->UIT_GetCefFrame(frame),
|
2010-10-03 23:04:50 +02:00
|
|
|
messageStr);
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
if (!handled)
|
2010-10-03 23:04:50 +02:00
|
|
|
ShowJavaScriptAlert(frame, messageStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::runModalConfirmDialog(
|
|
|
|
WebFrame* frame, const WebString& message) {
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString messageStr = string16(message);
|
2010-10-03 23:04:50 +02:00
|
|
|
bool retval = false;
|
2011-05-20 16:42:25 +02:00
|
|
|
bool handled = false;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
CefRefPtr<CefJSDialogHandler> handler;
|
|
|
|
if (client.get())
|
|
|
|
handler = client->GetJSDialogHandler();
|
|
|
|
|
|
|
|
if (handler.get()) {
|
|
|
|
handled = handler->OnJSConfirm(browser_, browser_->UIT_GetCefFrame(frame),
|
2010-10-03 23:04:50 +02:00
|
|
|
messageStr, retval);
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
if (!handled)
|
2010-10-03 23:04:50 +02:00
|
|
|
retval = ShowJavaScriptConfirm(frame, messageStr);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::runModalPromptDialog(
|
|
|
|
WebFrame* frame, const WebString& message, const WebString& default_value,
|
|
|
|
WebString* actual_value) {
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString messageStr = string16(message);
|
|
|
|
CefString defaultValueStr = string16(default_value);
|
|
|
|
CefString actualValueStr;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (actual_value)
|
2010-11-22 18:49:46 +01:00
|
|
|
actualValueStr = string16(*actual_value);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
bool retval = false;
|
2011-05-20 16:42:25 +02:00
|
|
|
bool handled = false;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
CefRefPtr<CefJSDialogHandler> handler;
|
|
|
|
if (client.get())
|
|
|
|
handler = client->GetJSDialogHandler();
|
|
|
|
|
|
|
|
if (handler.get()) {
|
|
|
|
handled = handler->OnJSPrompt(browser_, browser_->UIT_GetCefFrame(frame),
|
2010-11-22 18:49:46 +01:00
|
|
|
messageStr, defaultValueStr, retval, actualValueStr);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
if (!handled) {
|
2010-11-22 18:49:46 +01:00
|
|
|
retval = ShowJavaScriptPrompt(frame, messageStr, defaultValueStr,
|
|
|
|
&actualValueStr);
|
|
|
|
}
|
|
|
|
if (actual_value)
|
|
|
|
*actual_value = string16(actualValueStr);
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::runModalBeforeUnloadDialog(
|
|
|
|
WebFrame* frame, const WebString& message) {
|
|
|
|
return true; // Allow window closure.
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::setStatusText(const WebString& text) {
|
2011-01-26 16:12:49 +01:00
|
|
|
ShowStatus(text, STATUSTYPE_TEXT);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::setMouseOverURL(const WebURL& url) {
|
2011-01-26 16:12:49 +01:00
|
|
|
ShowStatus(url.spec().utf16(), STATUSTYPE_MOUSEOVER_URL);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::setKeyboardFocusURL(const WebKit::WebURL& url) {
|
2011-01-26 16:12:49 +01:00
|
|
|
ShowStatus(url.spec().utf16(), STATUSTYPE_KEYBOARD_FOCUS_URL);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::setToolTipText(
|
2012-01-10 00:46:23 +01:00
|
|
|
const WebString& text, WebTextDirection hint) {
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString tooltipStr = string16(text);
|
2011-05-20 16:42:25 +02:00
|
|
|
bool handled = false;
|
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefDisplayHandler> handler = client->GetDisplayHandler();
|
|
|
|
if (handler.get())
|
|
|
|
handled = handler->OnTooltip(browser_, tooltipStr);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
if (!handled)
|
|
|
|
GetWidgetHost()->SetTooltipText(tooltipStr);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-10-19 18:37:31 +02:00
|
|
|
bool BrowserWebViewDelegate::acceptsLoadDrops() {
|
|
|
|
return !browser_->settings().load_drops_disabled;
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
void BrowserWebViewDelegate::focusNext() {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefFocusHandler> handler = client->GetFocusHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler that it should take a focus
|
|
|
|
handler->OnTakeFocus(browser_, true);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::focusPrevious() {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefFocusHandler> handler = client->GetFocusHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler that it should take a focus
|
|
|
|
handler->OnTakeFocus(browser_, false);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 14:40:40 +02:00
|
|
|
void BrowserWebViewDelegate::focusedNodeChanged(const WebKit::WebNode& node) {
|
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefFocusHandler> handler = client->GetFocusHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
if (node.isNull()) {
|
|
|
|
handler->OnFocusedNodeChanged(browser_, browser_->GetFocusedFrame(),
|
|
|
|
NULL);
|
|
|
|
} else {
|
|
|
|
const WebKit::WebDocument& document = node.document();
|
|
|
|
if (!document.isNull()) {
|
|
|
|
WebKit::WebFrame* frame = document.frame();
|
|
|
|
CefRefPtr<CefDOMDocumentImpl> documentImpl =
|
|
|
|
new CefDOMDocumentImpl(browser_, frame);
|
|
|
|
handler->OnFocusedNodeChanged(browser_,
|
|
|
|
browser_->UIT_GetCefFrame(frame),
|
|
|
|
documentImpl->GetOrCreateNode(node));
|
|
|
|
documentImpl->Detach();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-05 20:34:20 +01:00
|
|
|
// WebPermissionClient -------------------------------------------------------
|
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::allowScriptExtension(
|
|
|
|
WebKit::WebFrame* frame,
|
|
|
|
const WebKit::WebString& extensionName,
|
|
|
|
int extensionGroup) {
|
|
|
|
bool allowExtension = true;
|
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefPermissionHandler> handler = client->GetPermissionHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefString extensionNameStr = string16(extensionName);
|
|
|
|
allowExtension = !handler->OnBeforeScriptExtensionLoad(
|
|
|
|
browser_, browser_->UIT_GetCefFrame(frame), extensionNameStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return allowExtension;
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// WebPluginPageDelegate -----------------------------------------------------
|
|
|
|
|
|
|
|
WebCookieJar* BrowserWebViewDelegate::GetCookieJar() {
|
2012-03-22 23:08:05 +01:00
|
|
|
return &cookie_jar_;
|
2010-10-03 23:04:50 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::scheduleComposite() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost())
|
|
|
|
host->ScheduleComposite();
|
|
|
|
}
|
|
|
|
|
2011-02-15 19:07:24 +01:00
|
|
|
void BrowserWebViewDelegate::scheduleAnimation() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost())
|
|
|
|
host->ScheduleAnimation();
|
|
|
|
}
|
|
|
|
|
2011-08-27 20:41:21 +02:00
|
|
|
// This method is called when:
|
|
|
|
// A. A request is loaded in a window other than the source window
|
|
|
|
// (FrameLoader::loadFrameRequest), or
|
|
|
|
// B. A request is loaded in an already existing popup window
|
|
|
|
// (FrameLoader::createWindow), or
|
|
|
|
// C. A DOM window receives a focus event (DOMWindow::focus)
|
2010-10-03 23:04:50 +02:00
|
|
|
void BrowserWebViewDelegate::didFocus() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
bool handled = false;
|
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefFocusHandler> handler = client->GetFocusHandler();
|
|
|
|
if (handler.get())
|
2011-10-07 12:30:10 +02:00
|
|
|
handled = handler->OnSetFocus(browser_, FOCUS_SOURCE_WIDGET);
|
2011-05-20 16:42:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled)
|
2010-10-03 23:04:50 +02:00
|
|
|
browser_->UIT_SetFocus(host, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 20:41:21 +02:00
|
|
|
// This method is called when a DOM window receives a blur event
|
|
|
|
// (DOMWindow::blur).
|
2010-10-03 23:04:50 +02:00
|
|
|
void BrowserWebViewDelegate::didBlur() {
|
|
|
|
if (WebWidgetHost* host = GetWidgetHost())
|
|
|
|
browser_->UIT_SetFocus(host, false);
|
|
|
|
}
|
|
|
|
|
2011-02-01 16:37:47 +01:00
|
|
|
void BrowserWebViewDelegate::closeWidgetSoon() {
|
|
|
|
if (this == browser_->UIT_GetWebViewDelegate()) {
|
|
|
|
browser_->UIT_CloseBrowser();
|
|
|
|
} else if (this == browser_->UIT_GetPopupDelegate()) {
|
|
|
|
browser_->UIT_ClosePopupWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
WebScreenInfo BrowserWebViewDelegate::screenInfo() {
|
2011-03-24 21:36:47 +01:00
|
|
|
if (WebWidgetHost* host = GetWidgetHost()) {
|
|
|
|
WebScreenInfo info = host->GetScreenInfo();
|
|
|
|
|
|
|
|
if (browser_->IsWindowRenderingDisabled()) {
|
|
|
|
// Retrieve the screen rectangle from the handler.
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRenderHandler> handler = client->GetRenderHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRect rect(info.rect.x, info.rect.y, info.rect.width,
|
|
|
|
info.rect.height);
|
|
|
|
if (handler->GetScreenRect(browser_, rect)) {
|
|
|
|
info.rect = WebRect(rect.x, rect.y, rect.width, rect.height);
|
|
|
|
info.availableRect = info.rect;
|
|
|
|
}
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-25 20:53:01 +01:00
|
|
|
|
|
|
|
return info;
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
return WebScreenInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// WebFrameClient ------------------------------------------------------------
|
|
|
|
|
|
|
|
WebPlugin* BrowserWebViewDelegate::createPlugin(
|
|
|
|
WebFrame* frame, const WebPluginParams& params) {
|
|
|
|
bool allow_wildcard = true;
|
2011-09-10 21:40:03 +02:00
|
|
|
std::vector<webkit::WebPluginInfo> plugins;
|
|
|
|
std::vector<std::string> mime_types;
|
|
|
|
webkit::npapi::PluginList::Singleton()->GetPluginInfoArray(
|
|
|
|
params.url, params.mimeType.utf8(), allow_wildcard,
|
|
|
|
NULL, &plugins, &mime_types);
|
|
|
|
if (plugins.empty())
|
2010-10-03 23:04:50 +02:00
|
|
|
return NULL;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
// Mac does not supported windowed plugins.
|
|
|
|
bool force_windowless = true;
|
|
|
|
#else
|
|
|
|
bool force_windowless = browser_->IsWindowRenderingDisabled();
|
|
|
|
#endif
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
if (force_windowless) {
|
2012-05-22 20:19:26 +02:00
|
|
|
DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
|
2011-10-12 21:09:15 +02:00
|
|
|
|
2012-05-22 20:19:26 +02:00
|
|
|
std::string mime_type = mime_types.front();
|
|
|
|
bool flash = LowerCaseEqualsASCII(mime_type,
|
2011-05-10 17:47:46 +02:00
|
|
|
"application/x-shockwave-flash");
|
2012-05-22 20:19:26 +02:00
|
|
|
bool silverlight = StartsWithASCII(mime_type,
|
2011-05-10 17:47:46 +02:00
|
|
|
"application/x-silverlight", false);
|
|
|
|
|
2012-05-22 20:19:26 +02:00
|
|
|
if (flash) {
|
|
|
|
// "wmode" values of "opaque" or "transparent" are allowed.
|
|
|
|
size_t size = params.attributeNames.size();
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
|
|
std::string name = params.attributeNames[i].utf8();
|
|
|
|
if (name == "wmode") {
|
|
|
|
std::string value = params.attributeValues[i].utf8();
|
|
|
|
if (value == "opaque" || value == "transparent")
|
|
|
|
flash = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-10 17:47:46 +02:00
|
|
|
if (flash || silverlight) {
|
2012-05-22 20:19:26 +02:00
|
|
|
WebPluginParams params_copy = params;
|
|
|
|
params_copy.mimeType = WebString::fromUTF8(mime_type);
|
|
|
|
|
2011-05-10 17:55:18 +02:00
|
|
|
// Force Flash and Silverlight plugins to use windowless mode.
|
2011-10-12 21:09:15 +02:00
|
|
|
size_t size = params_copy.attributeNames.size();
|
2011-05-10 17:47:46 +02:00
|
|
|
|
|
|
|
WebVector<WebString> new_names(size+1), new_values(size+1);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
2011-10-12 21:09:15 +02:00
|
|
|
new_names[i] = params_copy.attributeNames[i];
|
|
|
|
new_values[i] = params_copy.attributeValues[i];
|
2011-05-10 17:47:46 +02:00
|
|
|
}
|
|
|
|
|
2011-05-10 17:55:18 +02:00
|
|
|
if (flash) {
|
|
|
|
new_names[size] = "wmode";
|
|
|
|
new_values[size] = "opaque";
|
|
|
|
} else if (silverlight) {
|
|
|
|
new_names[size] = "windowless";
|
|
|
|
new_values[size] = "true";
|
|
|
|
}
|
2011-05-10 17:47:46 +02:00
|
|
|
|
2011-10-12 21:09:15 +02:00
|
|
|
params_copy.attributeNames.swap(new_names);
|
|
|
|
params_copy.attributeValues.swap(new_values);
|
2011-05-10 17:47:46 +02:00
|
|
|
|
|
|
|
return new webkit::npapi::WebPluginImpl(
|
2011-10-12 21:09:15 +02:00
|
|
|
frame, params_copy, plugins.front().path, AsWeakPtr());
|
2011-05-10 17:47:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-07 22:34:20 +01:00
|
|
|
return new webkit::npapi::WebPluginImpl(
|
2011-10-12 21:09:15 +02:00
|
|
|
frame, params, plugins.front().path, AsWeakPtr());
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WebMediaPlayer* BrowserWebViewDelegate::createMediaPlayer(
|
|
|
|
WebFrame* frame, WebMediaPlayerClient* client) {
|
2011-02-15 19:07:24 +01:00
|
|
|
scoped_ptr<media::MessageLoopFactory> message_loop_factory(
|
2012-04-05 00:32:24 +02:00
|
|
|
new media::MessageLoopFactory());
|
2011-02-15 19:07:24 +01:00
|
|
|
|
2010-12-16 22:54:42 +01:00
|
|
|
scoped_ptr<media::FilterCollection> collection(
|
|
|
|
new media::FilterCollection());
|
|
|
|
|
2010-10-26 18:37:30 +02:00
|
|
|
// Add the audio renderer.
|
2012-02-18 01:19:52 +01:00
|
|
|
// TODO(vrk): Re-enable audio. (crbug.com/112159)
|
2012-04-11 21:37:06 +02:00
|
|
|
collection->AddAudioRenderer(
|
|
|
|
new media::AudioRendererImpl(new media::NullAudioSink()));
|
2010-10-26 18:37:30 +02:00
|
|
|
|
2012-02-17 15:51:20 +01:00
|
|
|
return new webkit_media::WebMediaPlayerImpl(
|
|
|
|
frame,
|
|
|
|
client,
|
|
|
|
base::WeakPtr<webkit_media::WebMediaPlayerDelegate>(),
|
|
|
|
collection.release(),
|
|
|
|
NULL,
|
|
|
|
message_loop_factory.release(),
|
|
|
|
NULL,
|
|
|
|
new media::MediaLog());
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WebApplicationCacheHost* BrowserWebViewDelegate::createApplicationCacheHost(
|
|
|
|
WebFrame* frame, WebApplicationCacheHostClient* client) {
|
|
|
|
return BrowserAppCacheSystem::CreateApplicationCacheHost(client);
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
WebKit::WebCookieJar* BrowserWebViewDelegate::cookieJar(WebFrame* frame) {
|
|
|
|
return &cookie_jar_;
|
|
|
|
}
|
|
|
|
|
2011-02-23 04:45:13 +01:00
|
|
|
void BrowserWebViewDelegate::willClose(WebFrame* frame) {
|
|
|
|
browser_->UIT_BeforeFrameClosed(frame);
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
void BrowserWebViewDelegate::loadURLExternally(
|
|
|
|
WebFrame* frame, const WebURLRequest& request,
|
|
|
|
WebNavigationPolicy policy) {
|
|
|
|
DCHECK_NE(policy, WebKit::WebNavigationPolicyCurrentTab);
|
2011-05-10 18:41:41 +02:00
|
|
|
std::string url = request.url().spec().data();
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> newBrowser =
|
2011-05-10 18:41:41 +02:00
|
|
|
browser_->UIT_CreatePopupWindow(url, CefPopupFeatures());
|
|
|
|
if (newBrowser.get() && !url.empty())
|
|
|
|
newBrowser->GetMainFrame()->LoadURL(url);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WebNavigationPolicy BrowserWebViewDelegate::decidePolicyForNavigation(
|
|
|
|
WebFrame* frame, const WebURLRequest& request,
|
|
|
|
WebNavigationType type, const WebNode& originating_node,
|
|
|
|
WebNavigationPolicy default_policy, bool is_redirect) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Gather browse request information
|
|
|
|
CefRefPtr<CefRequest> req(CefRequest::CreateRequest());
|
|
|
|
|
|
|
|
GURL request_url = request.url();
|
|
|
|
if (!request_url.is_valid())
|
|
|
|
return WebKit::WebNavigationPolicyIgnore;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
req->SetURL(request_url.spec());
|
|
|
|
req->SetMethod(string16(request.httpMethod()));
|
|
|
|
|
|
|
|
const WebKit::WebHTTPBody& httpBody = request.httpBody();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!httpBody.isNull()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefPostData> postdata(CefPostData::CreatePostData());
|
|
|
|
static_cast<CefPostDataImpl*>(postdata.get())->Set(httpBody);
|
|
|
|
req->SetPostData(postdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRequest::HeaderMap map;
|
|
|
|
CefRequestImpl::GetHeaderMap(request, map);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (map.size() > 0)
|
2011-05-20 16:42:25 +02:00
|
|
|
static_cast<CefRequestImpl*>(req.get())->SetHeaderMap(map);
|
|
|
|
|
2011-10-18 02:23:32 +02:00
|
|
|
cef_handler_navtype_t navType;
|
|
|
|
if (browser_->is_dropping())
|
|
|
|
navType = NAVTYPE_LINKDROPPED;
|
|
|
|
else
|
|
|
|
navType = (cef_handler_navtype_t)type;
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// Notify the handler of a browse request
|
|
|
|
bool handled = handler->OnBeforeBrowse(browser_,
|
2011-10-18 02:23:32 +02:00
|
|
|
browser_->UIT_GetCefFrame(frame), req, navType,
|
2011-05-20 16:42:25 +02:00
|
|
|
is_redirect);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (handled)
|
2011-05-20 16:42:25 +02:00
|
|
|
return WebKit::WebNavigationPolicyIgnore;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
WebNavigationPolicy result;
|
|
|
|
if (policy_delegate_enabled_) {
|
|
|
|
if (policy_delegate_is_permissive_) {
|
|
|
|
result = WebKit::WebNavigationPolicyCurrentTab;
|
|
|
|
} else {
|
|
|
|
result = WebKit::WebNavigationPolicyIgnore;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = default_policy;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didCreateDataSource(
|
|
|
|
WebFrame* frame, WebDataSource* ds) {
|
|
|
|
ds->setExtraData(pending_extra_data_.release());
|
2012-03-22 23:08:05 +01:00
|
|
|
|
|
|
|
if (frame->parent() == 0) {
|
|
|
|
GURL url = ds->request().url();
|
|
|
|
if (!url.is_empty())
|
|
|
|
browser_->set_pending_url(url);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didStartProvisionalLoad(WebFrame* frame) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didReceiveServerRedirectForProvisionalLoad(
|
|
|
|
WebFrame* frame) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didFailProvisionalLoad(
|
|
|
|
WebFrame* frame, const WebURLError& error) {
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
const WebDataSource* failed_ds = frame->provisionalDataSource();
|
|
|
|
BrowserExtraData* extra_data =
|
|
|
|
static_cast<BrowserExtraData*>(failed_ds->extraData());
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +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));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string error_text;
|
2011-01-06 20:37:10 +01:00
|
|
|
CefString errorStr;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
bool handled = false;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefLoadHandler> handler = client->GetLoadHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// give the handler an opportunity to generate a custom error message
|
|
|
|
handled = handler->OnLoadError(browser_,
|
|
|
|
browser_->UIT_GetCefFrame(frame),
|
|
|
|
static_cast<cef_handler_errorcode_t>(error.reason),
|
|
|
|
std::string(failed_ds->request().url().spec().data()), errorStr);
|
|
|
|
}
|
2011-01-06 20:37:10 +01:00
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
|
|
|
if (handled && !errorStr.empty()) {
|
2011-01-06 20:37:10 +01:00
|
|
|
error_text = errorStr;
|
2010-10-03 23:04:50 +02:00
|
|
|
} else {
|
2011-09-10 21:40:03 +02:00
|
|
|
error_text = base::StringPrintf("Error %d when loading url %s",
|
2010-10-03 23:04:50 +02:00
|
|
|
error.reason, failed_ds->request().url().spec().data());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we never show errors in view source mode.
|
|
|
|
frame->enableViewSourceMode(false);
|
|
|
|
|
|
|
|
frame->loadHTMLString(
|
2011-10-21 16:42:21 +02:00
|
|
|
error_text, GURL("cef-error:"), error.unreachableURL, false);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// In case loadHTMLString failed before DidCreateDataSource was called.
|
|
|
|
set_pending_extra_data(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didCommitProvisionalLoad(
|
|
|
|
WebFrame* frame, bool is_new_navigation) {
|
2011-03-08 20:33:18 +01:00
|
|
|
bool is_main_frame = (frame->parent() == 0);
|
|
|
|
if (is_main_frame) {
|
|
|
|
// Clear the title so we can tell if it wasn't provided by the page.
|
|
|
|
browser_->UIT_SetTitle(std::wstring());
|
2011-01-12 00:46:14 +01:00
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
UpdateForCommittedLoad(frame, is_new_navigation);
|
2011-01-12 00:46:14 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefLoadHandler> handler = client->GetLoadHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler that loading has started.
|
|
|
|
handler->OnLoadStart(browser_, browser_->UIT_GetCefFrame(frame));
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2011-01-25 16:34:50 +01:00
|
|
|
|
|
|
|
// Apply zoom settings only on top-level frames.
|
2011-05-20 16:42:25 +02:00
|
|
|
if (is_main_frame) {
|
2011-01-25 16:34:50 +01:00
|
|
|
// Restore the zoom value that we have for this URL, if any.
|
2011-01-29 02:42:59 +01:00
|
|
|
double zoomLevel = 0.0;
|
2011-07-03 02:03:30 +02:00
|
|
|
ZoomMap::GetInstance()->get(frame->document().url(), zoomLevel);
|
2011-01-29 02:42:59 +01:00
|
|
|
frame->view()->setZoomLevel(false, zoomLevel);
|
|
|
|
browser_->set_zoom_level(zoomLevel);
|
2011-01-25 16:34:50 +01:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-11-21 22:21:55 +01:00
|
|
|
void BrowserWebViewDelegate::didCreateScriptContext(
|
2012-04-05 00:32:24 +02:00
|
|
|
WebFrame* frame, v8::Handle<v8::Context> context, int extensionGroup,
|
|
|
|
int worldId) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
2011-11-21 22:21:55 +01:00
|
|
|
if (!client.get())
|
|
|
|
return;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
2011-11-21 22:21:55 +01:00
|
|
|
CefRefPtr<CefV8ContextHandler> handler = client->GetV8ContextHandler();
|
|
|
|
if (!handler.get())
|
|
|
|
return;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
2011-11-21 22:21:55 +01:00
|
|
|
v8::HandleScope handle_scope;
|
|
|
|
v8::Context::Scope scope(context);
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> framePtr(browser_->UIT_GetCefFrame(frame));
|
|
|
|
CefRefPtr<CefV8Context> contextPtr(new CefV8ContextImpl(context));
|
|
|
|
|
|
|
|
handler->OnContextCreated(browser_, framePtr, contextPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::willReleaseScriptContext(
|
|
|
|
WebFrame* frame, v8::Handle<v8::Context> context, int worldId) {
|
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (!client.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CefRefPtr<CefV8ContextHandler> handler = client->GetV8ContextHandler();
|
|
|
|
if (!handler.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
v8::HandleScope handle_scope;
|
|
|
|
v8::Context::Scope scope(context);
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> framePtr(browser_->UIT_GetCefFrame(frame));
|
|
|
|
CefRefPtr<CefV8Context> contextPtr(new CefV8ContextImpl(context));
|
|
|
|
|
|
|
|
handler->OnContextReleased(browser_, framePtr, contextPtr);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didReceiveTitle(
|
2011-05-16 18:56:12 +02:00
|
|
|
WebFrame* frame, const WebString& title, WebTextDirection direction) {
|
2011-03-08 20:33:18 +01:00
|
|
|
bool is_main_frame = (frame->parent() == 0);
|
|
|
|
if (is_main_frame) {
|
2011-01-12 00:46:14 +01:00
|
|
|
CefString titleStr = string16(title);
|
|
|
|
browser_->UIT_SetTitle(titleStr);
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefDisplayHandler> handler = client->GetDisplayHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler of a page title change
|
|
|
|
handler->OnTitleChange(browser_, titleStr);
|
|
|
|
}
|
2011-01-12 00:46:14 +01:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didFailLoad(
|
|
|
|
WebFrame* frame, const WebURLError& error) {
|
|
|
|
LocationChangeDone(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::didFinishLoad(WebFrame* frame) {
|
|
|
|
LocationChangeDone(frame);
|
|
|
|
}
|
|
|
|
|
2011-03-23 00:53:10 +01:00
|
|
|
void BrowserWebViewDelegate::didNavigateWithinPage(
|
2010-10-03 23:04:50 +02:00
|
|
|
WebFrame* frame, bool is_new_navigation) {
|
|
|
|
frame->dataSource()->setExtraData(pending_extra_data_.release());
|
|
|
|
UpdateForCommittedLoad(frame, is_new_navigation);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The requestor ID is used by the resource loader bridge to locate the
|
|
|
|
// browser that originated the request.
|
|
|
|
request.setRequestorID(browser_->UIT_GetUniqueID());
|
|
|
|
}
|
|
|
|
|
2011-10-21 16:09:04 +02:00
|
|
|
void BrowserWebViewDelegate::didChangeContentsSize(
|
|
|
|
WebFrame* frame, const WebSize& size) {
|
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefDisplayHandler> handler = client->GetDisplayHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
handler->OnContentsSizeChange(browser_, browser_->UIT_GetCefFrame(frame),
|
|
|
|
size.width, size.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
void BrowserWebViewDelegate::reportFindInPageMatchCount(
|
2012-01-10 00:46:23 +01:00
|
|
|
int request_id, int count, bool final_update) {
|
2010-10-03 23:04:50 +02:00
|
|
|
browser_->UIT_NotifyFindStatus(request_id, count, gfx::Rect(),
|
2011-10-21 16:09:04 +02:00
|
|
|
-1, // Don't update active match ordinal.
|
2010-10-03 23:04:50 +02:00
|
|
|
final_update);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::reportFindInPageSelection(
|
2012-01-10 00:46:23 +01:00
|
|
|
int request_id, int active_match_ordinal, const WebKit::WebRect& sel) {
|
2010-10-03 23:04:50 +02:00
|
|
|
browser_->UIT_NotifyFindStatus(request_id, -1, sel, active_match_ordinal,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::openFileSystem(
|
2012-01-10 00:46:23 +01:00
|
|
|
WebFrame* frame, WebFileSystem::Type type,
|
|
|
|
long long size, // NOLINT(runtime/int)
|
|
|
|
bool create,
|
2010-10-03 23:04:50 +02:00
|
|
|
WebFileSystemCallbacks* callbacks) {
|
2010-12-16 22:54:42 +01:00
|
|
|
BrowserFileSystem* fileSystem = static_cast<BrowserFileSystem*>(
|
2011-09-10 21:40:03 +02:00
|
|
|
WebKit::webKitPlatformSupport()->fileSystem());
|
2010-12-16 22:54:42 +01:00
|
|
|
fileSystem->OpenFileSystem(frame, type, size, create, callbacks);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Public methods ------------------------------------------------------------
|
|
|
|
|
|
|
|
BrowserWebViewDelegate::BrowserWebViewDelegate(CefBrowserImpl* browser)
|
|
|
|
: policy_delegate_enabled_(false),
|
|
|
|
policy_delegate_is_permissive_(false),
|
|
|
|
policy_delegate_should_notify_done_(false),
|
|
|
|
browser_(browser),
|
|
|
|
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
|
2012-03-22 23:08:05 +01:00
|
|
|
block_redirects_(false),
|
|
|
|
cookie_jar_(browser) {
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowserWebViewDelegate::~BrowserWebViewDelegate() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::Reset() {
|
|
|
|
// Do a little placement new dance...
|
|
|
|
CefBrowserImpl* browser = browser_;
|
|
|
|
this->~BrowserWebViewDelegate();
|
2012-01-10 00:46:23 +01:00
|
|
|
new (this)BrowserWebViewDelegate(browser); // NOLINT(whitespace/parens)
|
2010-10-03 23:04:50 +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::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;
|
|
|
|
policy_delegate_should_notify_done_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private methods -----------------------------------------------------------
|
|
|
|
|
2011-11-04 19:19:14 +01:00
|
|
|
bool BrowserWebViewDelegate::OnKeyboardEvent(
|
2012-01-10 00:46:23 +01:00
|
|
|
const WebKit::WebKeyboardEvent& event, bool isAfterJavaScript) {
|
2011-11-04 19:19:14 +01:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
CefRefPtr<CefKeyboardHandler> handler;
|
|
|
|
if (client.get())
|
|
|
|
handler = client->GetKeyboardHandler();
|
|
|
|
if (!handler.get())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CefKeyboardHandler::KeyEventType eventType;
|
|
|
|
switch (event.type) {
|
2012-01-10 00:46:23 +01:00
|
|
|
case WebKeyboardEvent::RawKeyDown:
|
2011-11-04 19:19:14 +01:00
|
|
|
eventType = KEYEVENT_RAWKEYDOWN;
|
|
|
|
break;
|
2012-01-10 00:46:23 +01:00
|
|
|
case WebKeyboardEvent::KeyDown:
|
2011-11-04 19:19:14 +01:00
|
|
|
eventType = KEYEVENT_KEYDOWN;
|
|
|
|
break;
|
|
|
|
case WebKeyboardEvent::KeyUp:
|
|
|
|
eventType = KEYEVENT_KEYUP;
|
|
|
|
break;
|
|
|
|
case WebKeyboardEvent::Char:
|
|
|
|
eventType = KEYEVENT_CHAR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handler->OnKeyEvent(browser_, eventType, event.windowsKeyCode,
|
|
|
|
event.modifiers, event.isSystemKey?true:false, isAfterJavaScript);
|
|
|
|
}
|
|
|
|
|
2011-01-26 16:12:49 +01:00
|
|
|
void BrowserWebViewDelegate::ShowStatus(const WebString& text,
|
2012-01-10 00:46:23 +01:00
|
|
|
cef_handler_statustype_t type) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefDisplayHandler> handler = client->GetDisplayHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefString textStr = string16(text);
|
|
|
|
handler->OnStatusMessage(browser_, textStr, type);
|
|
|
|
}
|
2011-01-26 16:12:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
void BrowserWebViewDelegate::LocationChangeDone(WebFrame* frame) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (!client.get())
|
2011-03-08 20:33:18 +01:00
|
|
|
return;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-03-08 20:33:18 +01:00
|
|
|
bool is_main_frame = (frame->parent() == 0);
|
|
|
|
if (is_main_frame) {
|
|
|
|
CefString title = browser_->UIT_GetTitle();
|
|
|
|
if (title.empty()) {
|
|
|
|
// No title was provided by the page, so send a blank string to the
|
|
|
|
// client.
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefDisplayHandler> handler = client->GetDisplayHandler();
|
|
|
|
if (handler.get())
|
|
|
|
handler->OnTitleChange(browser_, title);
|
2011-03-08 20:33:18 +01:00
|
|
|
}
|
2011-01-12 00:46:14 +01:00
|
|
|
}
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefLoadHandler> handler = client->GetLoadHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler that loading has ended.
|
|
|
|
int httpStatusCode = frame->dataSource()->response().httpStatusCode();
|
|
|
|
handler->OnLoadEnd(browser_, browser_->UIT_GetCefFrame(frame),
|
|
|
|
httpStatusCode);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WebWidgetHost* BrowserWebViewDelegate::GetWidgetHost() {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (this == browser_->UIT_GetWebViewDelegate())
|
|
|
|
return browser_->UIT_GetWebViewHost();
|
|
|
|
if (this == browser_->UIT_GetPopupDelegate())
|
|
|
|
return browser_->UIT_GetPopupHost();
|
2010-10-03 23:04:50 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::UpdateForCommittedLoad(WebFrame* frame,
|
2011-01-12 00:46:14 +01:00
|
|
|
bool is_new_navigation) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Code duplicated from RenderView::DidCommitLoadForFrame.
|
|
|
|
BrowserExtraData* extra_data = static_cast<BrowserExtraData*>(
|
|
|
|
frame->dataSource()->extraData());
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
|
|
|
|
WebDataSource* ds = frame->dataSource();
|
|
|
|
DCHECK(ds);
|
|
|
|
|
|
|
|
const WebURLRequest& request = ds->request();
|
2011-08-30 18:20:27 +02:00
|
|
|
BrowserNavigationController* controller =
|
|
|
|
browser_->UIT_GetNavigationController();
|
|
|
|
|
|
|
|
if (controller->GetEntryCount() == 0) {
|
|
|
|
// This is the first navigation for the browser. Indicate that the browser
|
|
|
|
// now has a document.
|
|
|
|
browser_->set_has_document(true);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
// Update attributes of the CefFrame if it currently exists.
|
|
|
|
browser_->UIT_UpdateCefFrame(frame);
|
|
|
|
|
2011-03-08 20:33:18 +01:00
|
|
|
bool is_main_frame = (frame->parent() == 0);
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
2011-03-24 21:36:47 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
if (is_main_frame && client.get()) {
|
|
|
|
CefRefPtr<CefDisplayHandler> handler = client->GetDisplayHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler of an address change
|
|
|
|
std::string url = std::string(entry->GetURL().spec().c_str());
|
|
|
|
handler->OnAddressChange(browser_, browser_->UIT_GetCefFrame(frame), url);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const WebHistoryItem& history_item = frame->currentHistoryItem();
|
|
|
|
if (!history_item.isNull())
|
|
|
|
entry->SetContentState(webkit_glue::HistoryItemToString(history_item));
|
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
bool old_can_go_back = !controller->IsAtStart();
|
|
|
|
bool old_can_go_forward = !controller->IsAtEnd();
|
2011-01-29 02:42:59 +01:00
|
|
|
controller->DidNavigateToEntry(entry.release());
|
2011-03-24 21:36:47 +01:00
|
|
|
bool new_can_go_back = !controller->IsAtStart();
|
|
|
|
bool new_can_go_forward = !controller->IsAtEnd();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
last_page_id_updated_ = std::max(last_page_id_updated_, page_id_);
|
2011-03-24 21:36:47 +01:00
|
|
|
|
|
|
|
if (old_can_go_back != new_can_go_back ||
|
|
|
|
old_can_go_forward != new_can_go_forward) {
|
|
|
|
browser_->set_nav_state(new_can_go_back, new_can_go_forward);
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefDisplayHandler> handler = client->GetDisplayHandler();
|
2011-03-24 21:36:47 +01:00
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler of a navigation state change
|
2011-05-20 16:42:25 +02:00
|
|
|
handler->OnNavStateChange(browser_, new_can_go_back, new_can_go_forward);
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebViewDelegate::UpdateSessionHistory(WebFrame* frame) {
|
|
|
|
// 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;
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = browser_->UIT_GetWebView();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!view)
|
2010-10-03 23:04:50 +02:00
|
|
|
return;
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
const WebHistoryItem& history_item = view->mainFrame()->previousHistoryItem();
|
2010-10-03 23:04:50 +02:00
|
|
|
if (history_item.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry->SetContentState(webkit_glue::HistoryItemToString(history_item));
|
|
|
|
}
|
2011-09-12 21:49:38 +02:00
|
|
|
|
|
|
|
bool BrowserWebViewDelegate::OnBeforeMenu(
|
|
|
|
const WebKit::WebContextMenuData& data, int mouse_x, int mouse_y,
|
|
|
|
int& edit_flags, int& type_flags) {
|
|
|
|
// Populate the edit flags values.
|
|
|
|
edit_flags = data.editFlags;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (browser_->UIT_CanGoBack())
|
2011-09-12 21:49:38 +02:00
|
|
|
edit_flags |= MENU_CAN_GO_BACK;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (browser_->UIT_CanGoForward())
|
2011-09-12 21:49:38 +02:00
|
|
|
edit_flags |= MENU_CAN_GO_FORWARD;
|
|
|
|
|
|
|
|
// Populate the type flags values.
|
|
|
|
type_flags = MENUTYPE_NONE;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!data.pageURL.isEmpty())
|
2011-09-12 21:49:38 +02:00
|
|
|
type_flags |= MENUTYPE_PAGE;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!data.frameURL.isEmpty())
|
2011-09-12 21:49:38 +02:00
|
|
|
type_flags |= MENUTYPE_FRAME;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!data.linkURL.isEmpty())
|
2011-09-12 21:49:38 +02:00
|
|
|
type_flags |= MENUTYPE_LINK;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (data.mediaType == WebContextMenuData::MediaTypeImage)
|
2011-09-12 21:49:38 +02:00
|
|
|
type_flags |= MENUTYPE_IMAGE;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!data.selectedText.isEmpty())
|
2011-09-12 21:49:38 +02:00
|
|
|
type_flags |= MENUTYPE_SELECTION;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (data.isEditable)
|
2011-09-12 21:49:38 +02:00
|
|
|
type_flags |= MENUTYPE_EDITABLE;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (data.isSpellCheckingEnabled && !data.misspelledWord.isEmpty())
|
2011-09-12 21:49:38 +02:00
|
|
|
type_flags |= MENUTYPE_MISSPELLED_WORD;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (data.mediaType == WebContextMenuData::MediaTypeVideo)
|
2011-09-12 21:49:38 +02:00
|
|
|
type_flags |= MENUTYPE_VIDEO;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (data.mediaType == WebContextMenuData::MediaTypeAudio)
|
2011-09-12 21:49:38 +02:00
|
|
|
type_flags |= MENUTYPE_AUDIO;
|
|
|
|
|
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
CefRefPtr<CefMenuHandler> handler;
|
|
|
|
if (client.get())
|
|
|
|
handler = client->GetMenuHandler();
|
|
|
|
|
|
|
|
if (handler.get()) {
|
|
|
|
// Gather menu information.
|
2011-12-08 02:38:30 +01:00
|
|
|
CefMenuInfo menuInfo;
|
2011-09-12 21:49:38 +02:00
|
|
|
|
|
|
|
CefString linkStr(std::string(data.linkURL.spec()));
|
|
|
|
CefString imageStr(std::string(data.srcURL.spec()));
|
|
|
|
CefString pageStr(std::string(data.pageURL.spec()));
|
|
|
|
CefString frameStr(std::string(data.frameURL.spec()));
|
|
|
|
CefString selectedTextStr(string16(data.selectedText));
|
|
|
|
CefString misspelledWordStr(string16(data.misspelledWord));
|
|
|
|
CefString securityInfoStr(std::string(data.securityInfo));
|
|
|
|
|
|
|
|
menuInfo.typeFlags = type_flags;
|
|
|
|
menuInfo.x = mouse_x;
|
|
|
|
menuInfo.y = mouse_y;
|
|
|
|
cef_string_set(linkStr.c_str(), linkStr.length(), &menuInfo.linkUrl, false);
|
|
|
|
cef_string_set(imageStr.c_str(), imageStr.length(), &menuInfo.imageUrl,
|
|
|
|
false);
|
|
|
|
cef_string_set(pageStr.c_str(), pageStr.length(), &menuInfo.pageUrl, false);
|
|
|
|
cef_string_set(frameStr.c_str(), frameStr.length(), &menuInfo.frameUrl,
|
|
|
|
false);
|
|
|
|
cef_string_set(selectedTextStr.c_str(), selectedTextStr.length(),
|
|
|
|
&menuInfo.selectionText, false);
|
|
|
|
cef_string_set(misspelledWordStr.c_str(), misspelledWordStr.length(),
|
|
|
|
&menuInfo.misspelledWord, false);
|
|
|
|
menuInfo.editFlags = edit_flags;
|
|
|
|
cef_string_set(securityInfoStr.c_str(), securityInfoStr.length(),
|
|
|
|
&menuInfo.securityInfo, false);
|
|
|
|
|
|
|
|
// Notify the handler that a context menu is requested.
|
|
|
|
if (handler->OnBeforeMenu(browser_, menuInfo))
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-09-12 21:49:38 +02:00
|
|
|
return false;
|
|
|
|
}
|