2012-01-19 19:52:59 +01:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
2010-10-03 23:04:50 +02:00
|
|
|
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/browser_impl.h"
|
|
|
|
#include "libcef/browser_devtools_scheme_handler.h"
|
|
|
|
#include "libcef/browser_webkit_glue.h"
|
|
|
|
#include "libcef/browser_zoom_map.h"
|
|
|
|
#include "libcef/cef_context.h"
|
|
|
|
#include "libcef/dom_document_impl.h"
|
|
|
|
#include "libcef/request_impl.h"
|
|
|
|
#include "libcef/stream_impl.h"
|
|
|
|
#include "libcef/v8_impl.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-02-17 15:51:20 +01:00
|
|
|
#include "base/bind.h"
|
2011-01-25 19:37:27 +01:00
|
|
|
#include "base/file_path.h"
|
|
|
|
#include "base/path_service.h"
|
2011-06-14 19:44:19 +02:00
|
|
|
#include "base/stringprintf.h"
|
2011-01-07 22:34:20 +01:00
|
|
|
#include "base/synchronization/waitable_event.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/utf_string_conversions.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
2011-12-21 19:35:55 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.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/WebURLRequest.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "webkit/glue/glue_serialize.h"
|
2011-01-07 22:34:20 +01:00
|
|
|
#include "webkit/plugins/npapi/webplugin_delegate.h"
|
|
|
|
#include "webkit/plugins/npapi/webplugin_impl.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "webkit/glue/webkit_glue.h"
|
|
|
|
|
|
|
|
using WebKit::WebDocument;
|
|
|
|
using WebKit::WebFrame;
|
|
|
|
using WebKit::WebHTTPBody;
|
|
|
|
using WebKit::WebPlugin;
|
|
|
|
using WebKit::WebPluginDocument;
|
|
|
|
using WebKit::WebRange;
|
|
|
|
using WebKit::WebRect;
|
|
|
|
using WebKit::WebScriptSource;
|
|
|
|
using WebKit::WebString;
|
|
|
|
using WebKit::WebURL;
|
|
|
|
using WebKit::WebURLRequest;
|
|
|
|
using WebKit::WebView;
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
namespace {
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
class CreateBrowserHelper {
|
|
|
|
public:
|
2011-05-20 16:42:25 +02:00
|
|
|
CreateBrowserHelper(CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
const CefString& url,
|
|
|
|
const CefBrowserSettings& settings)
|
|
|
|
: window_info_(windowInfo),
|
|
|
|
client_(client),
|
|
|
|
url_(url),
|
|
|
|
settings_(settings) {}
|
2011-01-29 02:42:59 +01:00
|
|
|
|
|
|
|
CefWindowInfo window_info_;
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client_;
|
2011-01-29 02:42:59 +01:00
|
|
|
CefString url_;
|
2011-05-20 16:42:25 +02:00
|
|
|
CefBrowserSettings settings_;
|
2011-01-29 02:42:59 +01:00
|
|
|
};
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void UIT_CreateBrowserWithHelper(CreateBrowserHelper* helper) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefBrowser::CreateBrowserSync(helper->window_info_, helper->client_,
|
|
|
|
helper->url_, helper->settings_);
|
2011-01-29 02:42:59 +01:00
|
|
|
delete helper;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
} // namespace
|
2011-01-29 02:42:59 +01:00
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
|
|
|
|
CefBrowserImpl::PaintDelegate::PaintDelegate(CefBrowserImpl* browser)
|
2012-01-10 00:46:23 +01:00
|
|
|
: browser_(browser) {
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
|
|
|
CefBrowserImpl::PaintDelegate::~PaintDelegate() {
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
2011-11-09 21:09:24 +01:00
|
|
|
void CefBrowserImpl::PaintDelegate::Paint(
|
2012-01-10 00:46:23 +01:00
|
|
|
bool popup, const std::vector<CefRect>& dirtyRects, const void* buffer) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (!client.get())
|
|
|
|
return;
|
|
|
|
CefRefPtr<CefRenderHandler> handler = client->GetRenderHandler();
|
2011-03-24 21:36:47 +01:00
|
|
|
if (!handler.get())
|
|
|
|
return;
|
|
|
|
|
2011-11-09 21:09:24 +01:00
|
|
|
handler->OnPaint(browser_, (popup?PET_POPUP:PET_VIEW), dirtyRects, buffer);
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
// static
|
2011-05-20 16:42:25 +02:00
|
|
|
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
const CefString& url,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefBrowserSettings& settings) {
|
2011-01-29 02:42:59 +01:00
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "context not valid";
|
2011-01-29 02:42:59 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// Verify that the settings structure is a valid size.
|
|
|
|
if (settings.size != sizeof(cef_browser_settings_t)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "invalid CefBrowserSettings structure size";
|
2011-05-20 16:42:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
// Create the browser on the UI thread.
|
|
|
|
CreateBrowserHelper* helper =
|
2011-05-20 16:42:25 +02:00
|
|
|
new CreateBrowserHelper(windowInfo, client, url, settings);
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(UIT_CreateBrowserWithHelper, helper));
|
2011-01-29 02:42:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(
|
|
|
|
CefWindowInfo& windowInfo, CefRefPtr<CefClient> client,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& url, const CefBrowserSettings& settings) {
|
2011-01-29 02:42:59 +01:00
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "context not valid";
|
2011-01-29 02:42:59 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// Verify that the settings structure is a valid size.
|
|
|
|
if (settings.size != sizeof(cef_browser_settings_t)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "invalid CefBrowserSettings structure size";
|
2011-01-29 02:42:59 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2011-05-20 16:42:25 +02:00
|
|
|
return NULL;
|
2011-01-29 02:42:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> browser(
|
2011-06-14 17:09:55 +02:00
|
|
|
new CefBrowserImpl(windowInfo, settings, NULL, client));
|
2011-10-21 23:00:59 +02:00
|
|
|
if (!static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(url))
|
|
|
|
return NULL;
|
2011-01-29 02:42:59 +01:00
|
|
|
|
|
|
|
return browser;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-18 22:05:25 +01:00
|
|
|
CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
|
2011-06-14 17:09:55 +02:00
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
gfx::NativeView opener,
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client)
|
2011-10-18 02:23:32 +02:00
|
|
|
: window_info_(windowInfo),
|
|
|
|
settings_(settings),
|
|
|
|
opener_(opener),
|
|
|
|
is_modal_(false),
|
|
|
|
client_(client),
|
|
|
|
webviewhost_(NULL),
|
|
|
|
popuphost_(NULL),
|
|
|
|
zoom_level_(0.0),
|
|
|
|
can_go_back_(false),
|
|
|
|
can_go_forward_(false),
|
|
|
|
has_document_(false),
|
|
|
|
is_dropping_(false),
|
2012-04-02 18:28:56 +02:00
|
|
|
is_in_onsetfocus_(false),
|
2011-10-18 02:23:32 +02:00
|
|
|
unique_id_(0)
|
2011-06-14 17:09:55 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
, opener_was_disabled_by_modal_loop_(false),
|
|
|
|
internal_modal_message_loop_is_active_(false)
|
|
|
|
#endif
|
2012-01-10 00:46:23 +01:00
|
|
|
{ // NOLINT(whitespace/braces)
|
2010-10-03 23:04:50 +02:00
|
|
|
delegate_.reset(new BrowserWebViewDelegate(this));
|
|
|
|
popup_delegate_.reset(new BrowserWebViewDelegate(this));
|
|
|
|
nav_controller_.reset(new BrowserNavigationController(this));
|
|
|
|
|
|
|
|
if (!file_system_root_.CreateUniqueTempDir()) {
|
|
|
|
LOG(WARNING) << "Failed to create a temp dir for the filesystem."
|
|
|
|
"FileSystem feature will be disabled.";
|
|
|
|
DCHECK(file_system_root_.path().empty());
|
|
|
|
}
|
2012-03-22 23:08:05 +01:00
|
|
|
|
|
|
|
// Create the singleton main frame reference.
|
|
|
|
main_frame_ = new CefFrameImpl(this, 0, CefString(), CefString());
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::CloseBrowser() {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_CloseBrowser, this));
|
2011-03-08 02:07:47 +01:00
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
|
|
|
void CefBrowserImpl::GoBack() {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleActionView, this,
|
|
|
|
MENU_ID_NAV_BACK));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::GoForward() {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleActionView, this,
|
|
|
|
MENU_ID_NAV_FORWARD));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::Reload() {
|
2012-03-22 23:08:05 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
2012-02-17 15:51:20 +01:00
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleActionView, this,
|
|
|
|
MENU_ID_NAV_RELOAD));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::ReloadIgnoreCache() {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleActionView, this,
|
|
|
|
MENU_ID_NAV_RELOAD_NOCACHE));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::StopLoad() {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleActionView, this,
|
|
|
|
MENU_ID_NAV_STOP));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::SetFocus(bool enable) {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (CefThread::CurrentlyOn(CefThread::UI)) {
|
2012-04-02 18:28:56 +02:00
|
|
|
// If SetFocus() is called from inside the OnSetFocus() callback do not re-
|
|
|
|
// enter the callback.
|
|
|
|
if (enable && !is_in_onsetfocus_) {
|
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host) {
|
|
|
|
CefRefPtr<CefClient> client = GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefFocusHandler> handler = client->GetFocusHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
is_in_onsetfocus_ = true;
|
|
|
|
bool handled = handler->OnSetFocus(this, FOCUS_SOURCE_SYSTEM);
|
|
|
|
is_in_onsetfocus_ = false;
|
|
|
|
|
|
|
|
if (handled)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
UIT_SetFocus(UIT_GetWebViewHost(), enable);
|
|
|
|
} else {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::SetFocus, this, enable));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetMainFrame() {
|
|
|
|
return GetMainCefFrame(0, GURL()).get();
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetFocusedFrame() {
|
2011-01-29 02:42:59 +01:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2011-01-29 02:42:59 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = UIT_GetWebView();
|
|
|
|
return view ? UIT_GetCefFrame(view->focusedFrame()) : NULL;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const CefString& name) {
|
2011-01-29 02:42:59 +01:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2011-01-29 02:42:59 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = UIT_GetWebView();
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!view)
|
|
|
|
return NULL;
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
WebFrame* frame = view->findFrameByName(string16(name));
|
2012-01-10 00:46:23 +01:00
|
|
|
if (frame)
|
2011-01-29 02:42:59 +01:00
|
|
|
return UIT_GetCefFrame(frame);
|
2010-10-03 23:04:50 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::GetFrameNames(std::vector<CefString>& names) {
|
2011-01-29 02:42:59 +01:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2011-01-29 02:42:59 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = UIT_GetWebView();
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebFrame* main_frame = view->mainFrame();
|
|
|
|
WebFrame* it = main_frame;
|
|
|
|
do {
|
2012-01-10 00:46:23 +01:00
|
|
|
if (it != main_frame) {
|
2010-11-22 18:49:46 +01:00
|
|
|
string16 str = it->name();
|
|
|
|
names.push_back(str);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
it = it->traverseNext(true);
|
|
|
|
} while (it != main_frame);
|
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
void CefBrowserImpl::Find(int identifier, const CefString& searchText,
|
2012-01-10 00:46:23 +01:00
|
|
|
bool forward, bool matchCase, bool findNext) {
|
2010-10-03 23:04:50 +02:00
|
|
|
WebKit::WebFindOptions options;
|
|
|
|
options.forward = forward;
|
|
|
|
options.matchCase = matchCase;
|
|
|
|
options.findNext = findNext;
|
|
|
|
|
|
|
|
// Execute the request on the UI thread.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_Find, this, identifier, searchText,
|
|
|
|
options));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::StopFinding(bool clearSelection) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Execute the request on the UI thread.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_StopFinding, this, clearSelection));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::SetZoomLevel(double zoomLevel) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_SetZoomLevel, this, zoomLevel));
|
2011-01-29 02:42:59 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::ClearHistory() {
|
2011-10-04 13:49:36 +02:00
|
|
|
if (CefThread::CurrentlyOn(CefThread::UI)) {
|
2012-09-20 21:48:39 +02:00
|
|
|
if (!nav_controller_.get())
|
|
|
|
return;
|
|
|
|
|
2011-10-04 13:49:36 +02:00
|
|
|
bool old_can_go_back = !nav_controller_->IsAtStart();
|
|
|
|
bool old_can_go_forward = !nav_controller_->IsAtEnd();
|
|
|
|
nav_controller_->Reset();
|
|
|
|
|
|
|
|
if (old_can_go_back || old_can_go_forward) {
|
|
|
|
set_nav_state(false, false);
|
|
|
|
if (client_.get()) {
|
|
|
|
CefRefPtr<CefDisplayHandler> handler = client_->GetDisplayHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler of a navigation state change
|
|
|
|
handler->OnNavStateChange(this, false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::ClearHistory, this));
|
2011-10-04 13:49:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::ShowDevTools() {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_ShowDevTools, this));
|
2011-01-25 19:37:27 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::CloseDevTools() {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_CloseDevTools, this));
|
2011-01-25 19:37:27 +01:00
|
|
|
}
|
|
|
|
|
2012-09-14 21:04:45 +02:00
|
|
|
WebKit::WebGeolocationClient* CefBrowserImpl::UIT_GetGeolocationClient() {
|
|
|
|
if (!geolocation_client_)
|
|
|
|
geolocation_client_ = new CefGeolocationClient(this);
|
|
|
|
return geolocation_client_;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::GetSize(PaintElementType type, int& width, int& height) {
|
2011-03-24 21:36:47 +01:00
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2011-03-24 21:36:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = height = 0;
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (type == PET_VIEW) {
|
2011-03-24 21:36:47 +01:00
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host) {
|
|
|
|
host->GetSize(width, height);
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (type == PET_POPUP) {
|
2011-03-24 21:36:47 +01:00
|
|
|
if (popuphost_) {
|
|
|
|
popuphost_->GetSize(width, height);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::SetSize(PaintElementType type, int width, int height) {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Intentially post event tasks in all cases so that painting tasks can be
|
|
|
|
// handled at sane times.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_SetSize, this, type, width, height));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::IsPopupVisible() {
|
2011-03-24 21:36:47 +01:00
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2011-03-24 21:36:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
return (popuphost_ != NULL);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::HidePopup() {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Intentially post event tasks in all cases so that painting tasks can be
|
|
|
|
// handled at sane times.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_ClosePopupWidget, this));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::Invalidate(const CefRect& dirtyRect) {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Intentially post event tasks in all cases so that painting tasks can be
|
|
|
|
// handled at sane times.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_Invalidate, this, dirtyRect));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::GetImage(PaintElementType type, int width, int height,
|
2012-01-10 00:46:23 +01:00
|
|
|
void* buffer) {
|
2011-03-24 21:36:47 +01:00
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2011-03-24 21:36:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (type == PET_VIEW) {
|
2011-03-24 21:36:47 +01:00
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host)
|
|
|
|
return host->GetImage(width, height, buffer);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (type == PET_POPUP) {
|
2011-03-24 21:36:47 +01:00
|
|
|
if (popuphost_)
|
|
|
|
return popuphost_->GetImage(width, height, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-16 18:56:38 +02:00
|
|
|
void CefBrowserImpl::SendKeyEvent(KeyType type, const CefKeyInfo& keyInfo,
|
|
|
|
int modifiers) {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Intentially post event tasks in all cases so that painting tasks can be
|
|
|
|
// handled at sane times.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
2012-05-16 18:56:38 +02:00
|
|
|
base::Bind(&CefBrowserImpl::UIT_SendKeyEvent, this, type, keyInfo,
|
|
|
|
modifiers));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::SendMouseClickEvent(int x, int y, MouseButtonType type,
|
2012-01-10 00:46:23 +01:00
|
|
|
bool mouseUp, int clickCount) {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Intentially post event tasks in all cases so that painting tasks can be
|
|
|
|
// handled at sane times.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_SendMouseClickEvent, this, x, y, type,
|
|
|
|
mouseUp, clickCount));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::SendMouseMoveEvent(int x, int y, bool mouseLeave) {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Intentially post event tasks in all cases so that painting tasks can be
|
|
|
|
// handled at sane times.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_SendMouseMoveEvent, this, x, y,
|
|
|
|
mouseLeave));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
2012-05-16 18:56:38 +02:00
|
|
|
void CefBrowserImpl::SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Intentially post event tasks in all cases so that painting tasks can be
|
|
|
|
// handled at sane times.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
2012-05-16 18:56:38 +02:00
|
|
|
base::Bind(&CefBrowserImpl::UIT_SendMouseWheelEvent, this, x, y, deltaX,
|
|
|
|
deltaY));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::SendFocusEvent(bool setFocus) {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Intentially post event tasks in all cases so that painting tasks can be
|
|
|
|
// handled at sane times.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_SendFocusEvent, this, setFocus));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::SendCaptureLostEvent() {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Intentially post event tasks in all cases so that painting tasks can be
|
|
|
|
// handled at sane times.
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_SendCaptureLostEvent, this));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::Undo(CefRefPtr<CefFrame> frame) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleAction, this, MENU_ID_UNDO, frame));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::Redo(CefRefPtr<CefFrame> frame) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleAction, this, MENU_ID_REDO, frame));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::Cut(CefRefPtr<CefFrame> frame) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleAction, this, MENU_ID_CUT, frame));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::Copy(CefRefPtr<CefFrame> frame) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleAction, this, MENU_ID_COPY, frame));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::Paste(CefRefPtr<CefFrame> frame) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleAction, this, MENU_ID_PASTE,
|
|
|
|
frame));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::Delete(CefRefPtr<CefFrame> frame) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleAction, this, MENU_ID_DELETE,
|
|
|
|
frame));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::SelectAll(CefRefPtr<CefFrame> frame) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleAction, this, MENU_ID_SELECTALL,
|
|
|
|
frame));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::Print(CefRefPtr<CefFrame> frame) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleAction, this, MENU_ID_PRINT,
|
|
|
|
frame));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::ViewSource(CefRefPtr<CefFrame> frame) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_HandleAction, this, MENU_ID_VIEWSOURCE,
|
|
|
|
frame));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefString CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame) {
|
2011-01-29 02:42:59 +01:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2010-11-22 18:49:46 +01:00
|
|
|
return CefString();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
// Retrieve the document string directly
|
|
|
|
WebKit::WebFrame* web_frame = UIT_GetWebFrame(frame);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (web_frame)
|
2011-01-29 02:42:59 +01:00
|
|
|
return string16(web_frame->contentAsMarkup());
|
|
|
|
return CefString();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefString CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame) {
|
2011-01-29 02:42:59 +01:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2010-11-22 18:49:46 +01:00
|
|
|
return CefString();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
// Retrieve the document text directly
|
|
|
|
WebKit::WebFrame* web_frame = UIT_GetWebFrame(frame);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (web_frame)
|
2011-01-29 02:42:59 +01:00
|
|
|
return webkit_glue::DumpDocumentText(web_frame);
|
|
|
|
return CefString();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::LoadRequest(CefRefPtr<CefFrame> frame,
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefRequest> request) {
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(request.get() != NULL);
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_LoadURLForRequestRef, this, frame,
|
|
|
|
request));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::LoadURL(CefRefPtr<CefFrame> frame,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& url) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_LoadURL, this, frame, url));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::LoadString(CefRefPtr<CefFrame> frame,
|
2010-11-22 18:49:46 +01:00
|
|
|
const CefString& string,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& url) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_LoadHTML, this, frame, string, url));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::LoadStream(CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefStreamReader> stream,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& url) {
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(stream.get() != NULL);
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_LoadHTMLForStreamRef, this, frame, stream,
|
|
|
|
url));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::ExecuteJavaScript(CefRefPtr<CefFrame> frame,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& jsCode,
|
2010-11-22 18:49:46 +01:00
|
|
|
const CefString& scriptUrl,
|
2012-01-10 00:46:23 +01:00
|
|
|
int startLine) {
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_ExecuteJavaScript, this, frame, jsCode,
|
|
|
|
scriptUrl, startLine));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::GetParent(CefRefPtr<CefFrame> frame) {
|
2011-12-08 12:44:30 +01:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebFrame* web_frame = UIT_GetWebFrame(frame);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (web_frame) {
|
2011-12-08 12:44:30 +01:00
|
|
|
if (web_frame->parent() == NULL) {
|
|
|
|
// This is the main frame.
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return UIT_GetCefFrame(web_frame->parent());
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
CefRefPtr<CefFrameImpl> CefBrowserImpl::GetCefFrame(int64 id) {
|
|
|
|
AutoLock lock_scope(this);
|
|
|
|
FrameMap::const_iterator it = frames_.find(id);
|
|
|
|
if (it != frames_.end())
|
|
|
|
return it->second;
|
2011-01-29 02:42:59 +01:00
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
return NULL;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
CefRefPtr<CefFrameImpl> CefBrowserImpl::GetOrCreateCefFrame(
|
|
|
|
int64 id,
|
|
|
|
const CefString& name,
|
|
|
|
const GURL& url) {
|
|
|
|
CefRefPtr<CefFrameImpl> cef_frame;
|
2011-01-25 16:34:50 +01:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (name.empty()) {
|
2011-01-29 02:42:59 +01:00
|
|
|
// Use the single main frame reference.
|
2012-03-22 23:08:05 +01:00
|
|
|
cef_frame = GetMainCefFrame(id, url);
|
2011-01-29 02:42:59 +01:00
|
|
|
} else {
|
|
|
|
// Locate or create the appropriate named reference.
|
|
|
|
AutoLock lock_scope(this);
|
2012-03-22 23:08:05 +01:00
|
|
|
FrameMap::const_iterator it = frames_.find(id);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (it != frames_.end()) {
|
2011-01-29 02:42:59 +01:00
|
|
|
cef_frame = it->second;
|
2012-03-22 23:08:05 +01:00
|
|
|
cef_frame->set_url(url.spec());
|
2012-01-10 00:46:23 +01:00
|
|
|
} else {
|
2012-03-22 23:08:05 +01:00
|
|
|
cef_frame = new CefFrameImpl(this, id, name, url.spec());
|
|
|
|
frames_.insert(std::make_pair(id, cef_frame.get()));
|
2011-01-29 02:42:59 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-25 16:34:50 +01:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
return cef_frame;
|
2011-01-25 16:34:50 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
void CefBrowserImpl::RemoveCefFrame(int64 id) {
|
2011-01-29 02:42:59 +01:00
|
|
|
AutoLock lock_scope(this);
|
2012-03-22 23:08:05 +01:00
|
|
|
// Remove the appropriate reference.
|
|
|
|
FrameMap::iterator it = frames_.find(id);
|
|
|
|
if (it != frames_.end())
|
|
|
|
frames_.erase(it);
|
2011-01-25 16:34:50 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
CefRefPtr<CefFrameImpl> CefBrowserImpl::GetMainCefFrame(int64 id,
|
|
|
|
const GURL& url) {
|
|
|
|
if (id != 0)
|
|
|
|
main_frame_->set_id(id);
|
|
|
|
|
2012-03-30 19:18:31 +02:00
|
|
|
if (!url.is_empty())
|
|
|
|
main_frame_->set_url(url.spec());
|
2012-03-22 23:08:05 +01:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
return main_frame_;
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefFrame> CefBrowserImpl::UIT_GetCefFrame(WebFrame* frame) {
|
2011-01-29 02:42:59 +01:00
|
|
|
REQUIRE_UIT();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
CefRefPtr<CefFrameImpl> cef_frame;
|
|
|
|
GURL url = frame->document().url();
|
2011-01-29 02:42:59 +01:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (frame->parent() == 0) {
|
2011-03-24 21:36:47 +01:00
|
|
|
// Use the single main frame reference.
|
2012-03-22 23:08:05 +01:00
|
|
|
cef_frame = GetMainCefFrame(frame->identifier(), url);
|
2011-03-24 21:36:47 +01:00
|
|
|
} else {
|
2012-03-22 23:08:05 +01:00
|
|
|
// Locate or create the appropriate reference.
|
2011-03-24 21:36:47 +01:00
|
|
|
CefString name = string16(frame->name());
|
|
|
|
DCHECK(!name.empty());
|
2012-03-22 23:08:05 +01:00
|
|
|
cef_frame = GetOrCreateCefFrame(frame->identifier(), name, url);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
return cef_frame.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_UpdateCefFrame(WebKit::WebFrame* frame) {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
GURL url = frame->document().url();
|
|
|
|
|
|
|
|
if (frame->parent() == 0) {
|
|
|
|
// Update the single main frame reference.
|
|
|
|
GetMainCefFrame(frame->identifier(), url);
|
|
|
|
} else {
|
|
|
|
// Update the appropriate reference if it currently exists.
|
|
|
|
CefRefPtr<CefFrameImpl> cef_frame = GetCefFrame(frame->identifier());
|
|
|
|
if (cef_frame.get())
|
|
|
|
cef_frame->set_url(url.spec());
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
WebFrame* CefBrowserImpl::UIT_GetMainWebFrame() {
|
2011-01-29 02:42:59 +01:00
|
|
|
REQUIRE_UIT();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = UIT_GetWebView();
|
|
|
|
if (view)
|
|
|
|
return view ->mainFrame();
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
WebFrame* CefBrowserImpl::UIT_GetWebFrame(CefRefPtr<CefFrame> frame) {
|
2011-01-29 02:42:59 +01:00
|
|
|
REQUIRE_UIT();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = UIT_GetWebView();
|
|
|
|
if (!view)
|
|
|
|
return NULL;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
CefString name = frame->GetName();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (name.empty())
|
2011-01-29 02:42:59 +01:00
|
|
|
return view ->mainFrame();
|
|
|
|
return view ->findFrameByName(string16(name));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_DestroyBrowser() {
|
2011-08-03 17:35:51 +02:00
|
|
|
if (client_.get()) {
|
|
|
|
CefRefPtr<CefLifeSpanHandler> handler = client_->GetLifeSpanHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler that the window is about to be closed.
|
|
|
|
handler->OnBeforeClose(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-14 17:09:55 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
if (is_modal_) {
|
|
|
|
// Exit our own internal modal message loop now.
|
|
|
|
if (internal_modal_message_loop_is_active_) {
|
|
|
|
MessageLoop* message_loop = MessageLoop::current();
|
|
|
|
message_loop->QuitNow();
|
|
|
|
}
|
2010-11-15 16:39:56 +01:00
|
|
|
}
|
2011-08-02 18:50:06 +02:00
|
|
|
|
|
|
|
UIT_GetWebViewDelegate()->RevokeDragDrop();
|
2011-06-14 17:09:55 +02:00
|
|
|
#endif
|
|
|
|
|
2011-01-29 23:52:34 +01:00
|
|
|
// If the current browser window is a dev tools client then disconnect from
|
|
|
|
// the agent and destroy the client before destroying the window.
|
|
|
|
UIT_DestroyDevToolsClient();
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-01-25 19:37:27 +01:00
|
|
|
if (dev_tools_agent_.get()) {
|
|
|
|
BrowserDevToolsClient* client = dev_tools_agent_->client();
|
2011-01-29 23:52:34 +01:00
|
|
|
if (client) {
|
2011-02-01 16:45:38 +01:00
|
|
|
CefBrowserImpl* browser = client->browser();
|
2011-01-29 23:52:34 +01:00
|
|
|
// Destroy the client before freeing the agent.
|
2011-02-01 16:45:38 +01:00
|
|
|
browser->UIT_DestroyDevToolsClient();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!_Context->shutting_down()) {
|
2011-01-29 23:52:34 +01:00
|
|
|
// Explicitly close the client browser window.
|
2011-02-01 16:45:38 +01:00
|
|
|
browser->UIT_CloseBrowser();
|
2011-01-29 23:52:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Free the agent.
|
|
|
|
dev_tools_agent_.reset();
|
2011-01-25 19:37:27 +01:00
|
|
|
}
|
|
|
|
|
2012-08-13 18:24:53 +02:00
|
|
|
if (frame_objects_.size() > 0)
|
|
|
|
frame_objects_.clear();
|
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
// Clean up anything associated with the WebViewHost widget.
|
2011-12-31 01:57:52 +01:00
|
|
|
if (webviewhost_.get()) {
|
|
|
|
if (webviewhost_->webwidget())
|
|
|
|
webviewhost_->webwidget()->close();
|
|
|
|
webviewhost_.reset();
|
|
|
|
}
|
2011-06-14 17:09:55 +02:00
|
|
|
|
2012-08-13 18:24:53 +02:00
|
|
|
delegate_.reset(NULL);
|
|
|
|
popup_delegate_.reset(NULL);
|
|
|
|
nav_controller_.reset(NULL);
|
|
|
|
|
|
|
|
if (paint_delegate_.get())
|
|
|
|
paint_delegate_.reset(NULL);
|
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
// Remove the reference to the window handle.
|
|
|
|
UIT_ClearMainWndHandle();
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
main_frame_ = NULL;
|
2012-05-25 22:44:34 +02:00
|
|
|
|
2012-08-07 19:18:08 +02:00
|
|
|
if (request_context_proxy_.get()) {
|
|
|
|
// Delete the proxy on the IO thread.
|
|
|
|
CefThread::DeleteSoon(CefThread::IO, FROM_HERE,
|
|
|
|
request_context_proxy_.release());
|
|
|
|
}
|
2012-03-22 23:08:05 +01:00
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
// Remove the browser from the list maintained by the context.
|
|
|
|
_Context->RemoveBrowser(this);
|
2012-08-13 18:24:53 +02:00
|
|
|
|
|
|
|
// Remove the reference added in UIT_CreateBrowser().
|
|
|
|
Release();
|
2010-11-15 16:39:56 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_CloseBrowser() {
|
2011-02-01 16:37:47 +01:00
|
|
|
REQUIRE_UIT();
|
2011-06-14 17:09:55 +02:00
|
|
|
if (IsWindowRenderingDisabled()) {
|
2011-03-24 21:36:47 +01:00
|
|
|
UIT_DestroyBrowser();
|
2011-06-14 17:09:55 +02:00
|
|
|
} else {
|
2011-12-30 21:55:16 +01:00
|
|
|
gfx::NativeView view = UIT_GetMainWndHandle();
|
|
|
|
if (view)
|
|
|
|
UIT_CloseView(view);
|
2011-06-14 17:09:55 +02:00
|
|
|
}
|
2011-02-01 16:37:47 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 23:52:34 +01:00
|
|
|
void CefBrowserImpl::UIT_LoadURL(CefRefPtr<CefFrame> frame,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& url) {
|
2010-11-22 18:49:46 +01:00
|
|
|
UIT_LoadURLForRequest(frame, url, CefString(), WebHTTPBody(),
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRequest::HeaderMap());
|
|
|
|
}
|
|
|
|
|
2011-01-29 23:52:34 +01:00
|
|
|
void CefBrowserImpl::UIT_LoadURLForRequestRef(CefRefPtr<CefFrame> frame,
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefRequest> request) {
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString url = request->GetURL();
|
|
|
|
CefString method = request->GetMethod();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRequestImpl* impl = static_cast<CefRequestImpl*>(request.get());
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
WebHTTPBody upload_data;
|
|
|
|
CefRefPtr<CefPostData> postdata = impl->GetPostData();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (postdata.get()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
upload_data.initialize();
|
|
|
|
static_cast<CefPostDataImpl*>(postdata.get())->Get(upload_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRequest::HeaderMap headers;
|
|
|
|
impl->GetHeaderMap(headers);
|
|
|
|
|
|
|
|
UIT_LoadURLForRequest(frame, url, method, upload_data, headers);
|
|
|
|
}
|
|
|
|
|
2012-09-20 21:48:39 +02:00
|
|
|
void CefBrowserImpl::UIT_LoadURLForRequest(
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& url,
|
|
|
|
const CefString& method,
|
|
|
|
const WebKit::WebHTTPBody& upload_data,
|
|
|
|
const CefRequest::HeaderMap& headers) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (url.empty())
|
|
|
|
return;
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string urlStr(url);
|
|
|
|
GURL gurl = GURL(urlStr);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
if (!gurl.is_valid() && !gurl.has_scheme()) {
|
|
|
|
// Try to add "http://" at the beginning
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string new_url = std::string("http://") + urlStr;
|
|
|
|
gurl = GURL(new_url);
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!gurl.is_valid())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-20 21:48:39 +02:00
|
|
|
if (nav_controller_.get()) {
|
|
|
|
nav_controller_->LoadEntry(
|
|
|
|
new BrowserNavigationEntry(-1, gurl, CefString(), frame->GetName(),
|
|
|
|
method, upload_data, headers));
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-01-29 23:52:34 +01:00
|
|
|
void CefBrowserImpl::UIT_LoadHTML(CefRefPtr<CefFrame> frame,
|
2010-11-22 18:49:46 +01:00
|
|
|
const CefString& html,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& url) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
2010-11-22 18:49:46 +01:00
|
|
|
|
|
|
|
std::string urlStr(url);
|
|
|
|
GURL gurl = GURL(urlStr);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
if (!gurl.is_valid() && !gurl.has_scheme()) {
|
|
|
|
// Try to add "http://" at the beginning
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string new_url = std::string("http://") + urlStr;
|
|
|
|
gurl = GURL(new_url);
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!gurl.is_valid())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebFrame* web_frame = UIT_GetWebFrame(frame);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (web_frame)
|
2010-11-22 18:49:46 +01:00
|
|
|
web_frame->loadHTMLString(std::string(html), gurl);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-01-29 23:52:34 +01:00
|
|
|
void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefStreamReader> stream,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& url) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string urlStr(url);
|
|
|
|
GURL gurl = GURL(urlStr);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
if (!gurl.is_valid() && !gurl.has_scheme()) {
|
|
|
|
// Try to add "http://" at the beginning
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string new_url = std::string("http://") + urlStr;
|
|
|
|
gurl = GURL(new_url);
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!gurl.is_valid())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read all of the stream data into a std::string.
|
|
|
|
std::stringstream ss;
|
|
|
|
char buff[BUFFER_SIZE];
|
|
|
|
size_t read;
|
|
|
|
do {
|
|
|
|
read = stream->Read(buff, sizeof(char), BUFFER_SIZE-1);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (read > 0) {
|
2010-10-03 23:04:50 +02:00
|
|
|
buff[read] = 0;
|
|
|
|
ss << buff;
|
|
|
|
}
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
while (read > 0);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebFrame* web_frame = UIT_GetWebFrame(frame);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (web_frame)
|
2010-10-03 23:04:50 +02:00
|
|
|
web_frame->loadHTMLString(ss.str(), gurl);
|
|
|
|
}
|
|
|
|
|
2011-01-29 23:52:34 +01:00
|
|
|
void CefBrowserImpl::UIT_ExecuteJavaScript(CefRefPtr<CefFrame> frame,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& js_code,
|
2010-11-22 18:49:46 +01:00
|
|
|
const CefString& script_url,
|
2012-01-10 00:46:23 +01:00
|
|
|
int start_line) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebFrame* web_frame = UIT_GetWebFrame(frame);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (web_frame) {
|
2010-11-22 18:49:46 +01:00
|
|
|
web_frame->executeScript(WebScriptSource(string16(js_code),
|
|
|
|
WebURL(GURL(std::string(script_url))), start_line));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_GoBackOrForward(int offset) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
2012-09-20 21:48:39 +02:00
|
|
|
if (nav_controller_.get())
|
|
|
|
nav_controller_->GoToOffset(offset);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_Reload(bool ignoreCache) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
2012-09-20 21:48:39 +02:00
|
|
|
if (nav_controller_.get())
|
|
|
|
nav_controller_->Reload(ignoreCache);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
|
|
|
|
bool reload,
|
2012-01-10 00:46:23 +01:00
|
|
|
bool ignoreCache) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = UIT_GetWebView();
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!view)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get the right target frame for the entry.
|
|
|
|
WebFrame* frame;
|
2010-11-22 18:49:46 +01:00
|
|
|
if (!entry.GetTargetFrame().empty())
|
|
|
|
frame = view->findFrameByName(string16(entry.GetTargetFrame()));
|
|
|
|
else
|
2010-10-03 23:04:50 +02:00
|
|
|
frame = view->mainFrame();
|
2010-10-10 02:16:24 +02:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// TODO(mpcomplete): should we clear the target frame, or should
|
|
|
|
// back/forward navigations maintain the target frame?
|
|
|
|
|
|
|
|
// A navigation resulting from loading a javascript URL should not be
|
|
|
|
// treated as a browser initiated event. Instead, we want it to look as if
|
|
|
|
// the page initiated any load resulting from JS execution.
|
|
|
|
if (!entry.GetURL().SchemeIs("javascript")) {
|
|
|
|
delegate_->set_pending_extra_data(
|
|
|
|
new BrowserExtraData(entry.GetPageID()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are reloading, then WebKit will use the state of the current page.
|
|
|
|
// Otherwise, we give it the state to navigate to.
|
|
|
|
if (reload) {
|
|
|
|
frame->reload(ignoreCache);
|
|
|
|
} else if (!entry.GetContentState().empty()) {
|
2012-01-10 00:46:23 +01:00
|
|
|
DCHECK_NE(entry.GetPageID(), -1);
|
2010-10-03 23:04:50 +02:00
|
|
|
frame->loadHistoryItem(
|
|
|
|
webkit_glue::HistoryItemFromString(entry.GetContentState()));
|
|
|
|
} else {
|
2012-01-10 00:46:23 +01:00
|
|
|
DCHECK_EQ(entry.GetPageID(), -1);
|
2010-10-03 23:04:50 +02:00
|
|
|
WebURLRequest request(entry.GetURL());
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (entry.GetMethod().length() > 0)
|
2010-11-22 18:49:46 +01:00
|
|
|
request.setHTTPMethod(string16(entry.GetMethod()));
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (entry.GetHeaders().size() > 0)
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRequestImpl::SetHeaderMap(entry.GetHeaders(), request);
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!entry.GetUploadData().isNull()) {
|
2010-11-22 18:49:46 +01:00
|
|
|
string16 method = request.httpMethod();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (method == ASCIIToUTF16("GET") || method == ASCIIToUTF16("HEAD"))
|
2010-11-22 18:49:46 +01:00
|
|
|
request.setHTTPMethod(ASCIIToUTF16("POST"));
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (request.httpHeaderField(ASCIIToUTF16("Content-Type")).length() == 0) {
|
2010-10-03 23:04:50 +02:00
|
|
|
request.setHTTPHeaderField(
|
2010-11-22 18:49:46 +01:00
|
|
|
ASCIIToUTF16("Content-Type"),
|
|
|
|
ASCIIToUTF16("application/x-www-form-urlencoded"));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
request.setHTTPBody(entry.GetUploadData());
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->loadRequest(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
// In case LoadRequest failed before DidCreateDataSource was called.
|
|
|
|
delegate_->set_pending_extra_data(NULL);
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
if (client_.get()) {
|
|
|
|
CefRefPtr<CefFocusHandler> handler = client_->GetFocusHandler();
|
2011-06-06 17:38:19 +02:00
|
|
|
if (!handler.get() ||
|
2011-10-07 12:30:10 +02:00
|
|
|
(handler.get() &&
|
|
|
|
!handler->OnSetFocus(this, FOCUS_SOURCE_NAVIGATION))) {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Restore focus to the main frame prior to loading new request.
|
|
|
|
// This makes sure that we don't have a focused iframe. Otherwise, that
|
|
|
|
// iframe would keep focus when the SetFocus called immediately after
|
|
|
|
// LoadRequest, thus making some tests fail (see http://b/issue?id=845337
|
|
|
|
// for more details).
|
|
|
|
// TODO(cef): The above comment may be wrong, or the below call to
|
|
|
|
// setFocusedFrame() may be unnecessary or in the wrong place. See this
|
|
|
|
// thread for additional details:
|
|
|
|
// http://groups.google.com/group/chromium-dev/browse_thread/thread/42bcd31b59e3a168
|
|
|
|
view->setFocusedFrame(frame);
|
|
|
|
|
|
|
|
// Give focus to the window if it is currently visible.
|
|
|
|
if (!IsWindowRenderingDisabled() &&
|
|
|
|
UIT_IsViewVisible(UIT_GetMainWndHandle()))
|
|
|
|
UIT_SetFocus(UIT_GetWebViewHost(), true);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_SetSize(PaintElementType type, int width, int height) {
|
|
|
|
if (type == PET_VIEW) {
|
2011-03-24 21:36:47 +01:00
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host)
|
|
|
|
host->SetSize(width, height);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (type == PET_POPUP) {
|
2011-03-24 21:36:47 +01:00
|
|
|
if (popuphost_)
|
|
|
|
popuphost_->SetSize(width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_Invalidate(const CefRect& dirtyRect) {
|
2011-03-24 21:36:47 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host) {
|
2011-11-09 21:09:24 +01:00
|
|
|
gfx::Rect rect(dirtyRect.x, dirtyRect.y, dirtyRect.width,
|
|
|
|
dirtyRect.height);
|
|
|
|
|
|
|
|
// Cause WebWidget::Paint() to be called when next appropriate.
|
|
|
|
host->InvalidateRect(rect);
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-16 18:56:38 +02:00
|
|
|
void CefBrowserImpl::UIT_SendKeyEvent(KeyType type, const CefKeyInfo& keyInfo,
|
|
|
|
int modifiers) {
|
2011-03-24 21:36:47 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
if (popuphost_) {
|
|
|
|
// Send the event to the popup.
|
2012-05-16 18:56:38 +02:00
|
|
|
popuphost_->SendKeyEvent(type, keyInfo, modifiers);
|
2011-03-24 21:36:47 +01:00
|
|
|
} else {
|
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host)
|
2012-05-16 18:56:38 +02:00
|
|
|
host->SendKeyEvent(type, keyInfo, modifiers);
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_SendMouseClickEvent(int x, int y, MouseButtonType type,
|
2012-01-10 00:46:23 +01:00
|
|
|
bool mouseUp, int clickCount) {
|
2011-03-24 21:36:47 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
if (popuphost_ && popup_rect_.Contains(x, y)) {
|
|
|
|
// Send the event to the popup.
|
|
|
|
popuphost_->SendMouseClickEvent(x - popup_rect_.x(), y - popup_rect_.y(),
|
|
|
|
type, mouseUp, clickCount);
|
|
|
|
} else {
|
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host)
|
|
|
|
host->SendMouseClickEvent(x, y, type, mouseUp, clickCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_SendMouseMoveEvent(int x, int y, bool mouseLeave) {
|
2011-03-24 21:36:47 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
if (popuphost_ && popup_rect_.Contains(x, y)) {
|
|
|
|
// Send the event to the popup.
|
|
|
|
popuphost_->SendMouseMoveEvent(x - popup_rect_.x(), y - popup_rect_.y(),
|
|
|
|
mouseLeave);
|
|
|
|
} else {
|
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host)
|
|
|
|
host->SendMouseMoveEvent(x, y, mouseLeave);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-16 18:56:38 +02:00
|
|
|
void CefBrowserImpl::UIT_SendMouseWheelEvent(int x, int y, int deltaX,
|
|
|
|
int deltaY) {
|
2011-03-24 21:36:47 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
if (popuphost_ && popup_rect_.Contains(x, y)) {
|
|
|
|
// Send the event to the popup.
|
|
|
|
popuphost_->SendMouseWheelEvent(x - popup_rect_.x(), y - popup_rect_.y(),
|
2012-05-16 18:56:38 +02:00
|
|
|
deltaX, deltaY);
|
2011-03-24 21:36:47 +01:00
|
|
|
} else {
|
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host)
|
2012-05-16 18:56:38 +02:00
|
|
|
host->SendMouseWheelEvent(x, y, deltaX, deltaY);
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_SendFocusEvent(bool setFocus) {
|
2011-03-24 21:36:47 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host)
|
|
|
|
host->SendFocusEvent(setFocus);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_SendCaptureLostEvent() {
|
2011-03-24 21:36:47 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
WebViewHost* host = UIT_GetWebViewHost();
|
|
|
|
if (host)
|
|
|
|
host->SendCaptureLostEvent();
|
|
|
|
}
|
|
|
|
|
2010-11-16 17:45:49 +01:00
|
|
|
CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& url, const CefPopupFeatures& features) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
CefWindowInfo info;
|
2010-10-09 21:21:09 +02:00
|
|
|
#if defined(OS_WIN)
|
2010-11-22 18:49:46 +01:00
|
|
|
info.SetAsPopup(NULL, CefString());
|
2010-10-09 21:21:09 +02:00
|
|
|
#endif
|
2011-02-02 03:25:32 +01:00
|
|
|
|
2011-10-24 22:20:52 +02:00
|
|
|
#if (defined(OS_WIN) || defined(OS_MACOSX))
|
2011-02-02 03:25:32 +01:00
|
|
|
// Default to the size from the popup features.
|
2012-01-10 00:46:23 +01:00
|
|
|
if (features.xSet)
|
2011-02-02 03:25:32 +01:00
|
|
|
info.m_x = features.x;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (features.ySet)
|
2011-02-02 03:25:32 +01:00
|
|
|
info.m_y = features.y;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (features.widthSet)
|
2011-02-02 03:25:32 +01:00
|
|
|
info.m_nWidth = features.width;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (features.heightSet)
|
2011-02-02 03:25:32 +01:00
|
|
|
info.m_nHeight = features.height;
|
2011-10-24 22:20:52 +02:00
|
|
|
#endif
|
2011-02-02 03:25:32 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = client_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2010-11-18 22:05:25 +01:00
|
|
|
// Start with the current browser window's settings.
|
|
|
|
CefBrowserSettings settings(settings_);
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
if (client_.get()) {
|
|
|
|
CefRefPtr<CefLifeSpanHandler> handler = client_->GetLifeSpanHandler();
|
2010-10-03 23:04:50 +02:00
|
|
|
// Give the handler an opportunity to modify window attributes, handler,
|
|
|
|
// or cancel the window creation.
|
2011-05-20 16:42:25 +02:00
|
|
|
if (handler.get() &&
|
|
|
|
handler->OnBeforePopup(this, features, info, url, client, settings)) {
|
2010-10-03 23:04:50 +02:00
|
|
|
return NULL;
|
2011-05-20 16:42:25 +02:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-06-14 17:09:55 +02:00
|
|
|
// Modal windows need to know which window is being suspended (the opener)
|
2012-01-10 00:46:23 +01:00
|
|
|
// so that it can be disabled while the modal window is open.
|
2010-11-18 22:05:25 +01:00
|
|
|
CefRefPtr<CefBrowserImpl> browser(
|
2011-06-14 17:09:55 +02:00
|
|
|
new CefBrowserImpl(info, settings, UIT_GetMainWndHandle(), client));
|
|
|
|
|
2011-05-10 15:55:06 +02:00
|
|
|
// Don't pass the URL to UIT_CreateBrowser for popup windows or the URL will
|
|
|
|
// be loaded twice.
|
2011-10-21 23:00:59 +02:00
|
|
|
if (!browser->UIT_CreateBrowser(CefString()))
|
|
|
|
return NULL;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
return browser;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget() {
|
2011-02-01 16:37:47 +01:00
|
|
|
REQUIRE_UIT();
|
2011-03-24 21:36:47 +01:00
|
|
|
|
2011-02-01 16:37:47 +01:00
|
|
|
DCHECK(!popuphost_);
|
2011-03-24 21:36:47 +01:00
|
|
|
popuphost_ = WebWidgetHost::Create(
|
|
|
|
(IsWindowRenderingDisabled()?NULL:UIT_GetMainWndHandle()),
|
|
|
|
popup_delegate_.get(), paint_delegate_.get());
|
2011-02-01 16:37:47 +01:00
|
|
|
popuphost_->set_popup(true);
|
2011-03-24 21:36:47 +01:00
|
|
|
|
2011-02-01 16:37:47 +01:00
|
|
|
return popuphost_->webwidget();
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_ClosePopupWidget() {
|
2011-02-01 16:37:47 +01:00
|
|
|
REQUIRE_UIT();
|
2011-03-24 21:36:47 +01:00
|
|
|
|
|
|
|
if (!popuphost_)
|
|
|
|
return;
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-02-02 03:25:32 +01:00
|
|
|
#if !defined(OS_MACOSX)
|
|
|
|
// Mac uses a WebPopupMenu for select lists so no closing is necessary.
|
2011-03-24 21:36:47 +01:00
|
|
|
if (!IsWindowRenderingDisabled())
|
|
|
|
UIT_CloseView(UIT_GetPopupWndHandle());
|
2011-02-02 03:25:32 +01:00
|
|
|
#endif
|
2011-02-01 16:37:47 +01:00
|
|
|
popuphost_ = NULL;
|
2011-03-24 21:36:47 +01:00
|
|
|
popup_rect_ = gfx::Rect();
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
if (IsWindowRenderingDisabled() && client_.get()) {
|
|
|
|
CefRefPtr<CefRenderHandler> handler = client_->GetRenderHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler of popup visibility change.
|
|
|
|
handler->OnPopupShow(this, false);
|
|
|
|
}
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
2011-02-01 16:37:47 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_Show(WebKit::WebNavigationPolicy policy) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
|
|
|
delegate_->show(policy);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_HandleActionView(cef_menu_id_t menuId) {
|
2010-10-03 23:04:50 +02:00
|
|
|
return UIT_HandleAction(menuId, NULL);
|
|
|
|
}
|
|
|
|
|
2011-12-08 02:38:30 +01:00
|
|
|
void CefBrowserImpl::UIT_HandleAction(cef_menu_id_t menuId,
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefFrame> frame) {
|
2010-10-03 23:04:50 +02:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
WebFrame* web_frame = NULL;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (frame)
|
2011-01-29 02:42:59 +01:00
|
|
|
web_frame = UIT_GetWebFrame(frame);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
switch (menuId) {
|
|
|
|
case MENU_ID_NAV_BACK:
|
|
|
|
UIT_GoBackOrForward(-1);
|
|
|
|
break;
|
|
|
|
case MENU_ID_NAV_FORWARD:
|
|
|
|
UIT_GoBackOrForward(1);
|
|
|
|
break;
|
|
|
|
case MENU_ID_NAV_RELOAD:
|
|
|
|
UIT_Reload(false);
|
|
|
|
break;
|
|
|
|
case MENU_ID_NAV_RELOAD_NOCACHE:
|
|
|
|
UIT_Reload(true);
|
|
|
|
break;
|
|
|
|
case MENU_ID_NAV_STOP:
|
|
|
|
if (UIT_GetWebView())
|
|
|
|
UIT_GetWebView()->mainFrame()->stopLoading();
|
|
|
|
break;
|
|
|
|
case MENU_ID_UNDO:
|
|
|
|
if (web_frame)
|
|
|
|
web_frame->executeCommand(WebString::fromUTF8("Undo"));
|
|
|
|
break;
|
|
|
|
case MENU_ID_REDO:
|
|
|
|
if (web_frame)
|
|
|
|
web_frame->executeCommand(WebString::fromUTF8("Redo"));
|
|
|
|
break;
|
|
|
|
case MENU_ID_CUT:
|
|
|
|
if (web_frame)
|
|
|
|
web_frame->executeCommand(WebString::fromUTF8("Cut"));
|
|
|
|
break;
|
|
|
|
case MENU_ID_COPY:
|
|
|
|
if (web_frame)
|
|
|
|
web_frame->executeCommand(WebString::fromUTF8("Copy"));
|
|
|
|
break;
|
|
|
|
case MENU_ID_PASTE:
|
|
|
|
if (web_frame)
|
|
|
|
web_frame->executeCommand(WebString::fromUTF8("Paste"));
|
|
|
|
break;
|
|
|
|
case MENU_ID_DELETE:
|
|
|
|
if (web_frame)
|
|
|
|
web_frame->executeCommand(WebString::fromUTF8("Delete"));
|
|
|
|
break;
|
|
|
|
case MENU_ID_SELECTALL:
|
|
|
|
if (web_frame)
|
|
|
|
web_frame->executeCommand(WebString::fromUTF8("SelectAll"));
|
|
|
|
break;
|
|
|
|
case MENU_ID_PRINT:
|
|
|
|
if (web_frame)
|
|
|
|
UIT_PrintPages(web_frame);
|
|
|
|
break;
|
|
|
|
case MENU_ID_VIEWSOURCE:
|
|
|
|
if (web_frame)
|
|
|
|
UIT_ViewDocumentString(web_frame);
|
|
|
|
break;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
void CefBrowserImpl::UIT_Find(int identifier, const CefString& search_text,
|
2012-01-10 00:46:23 +01:00
|
|
|
const WebKit::WebFindOptions& options) {
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = UIT_GetWebView();
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebFrame* main_frame = view->mainFrame();
|
2010-11-22 18:49:46 +01:00
|
|
|
string16 searchText(search_text);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
if (main_frame->document().isPluginDocument()) {
|
|
|
|
WebPlugin* plugin = main_frame->document().to<WebPluginDocument>().plugin();
|
2011-09-10 21:40:03 +02:00
|
|
|
if (plugin) {
|
|
|
|
if (options.findNext) {
|
|
|
|
// Just navigate back/forward.
|
|
|
|
plugin->selectFindResult(options.forward);
|
2010-10-03 23:04:50 +02:00
|
|
|
} else {
|
2011-09-10 21:40:03 +02:00
|
|
|
if (plugin->startFind(searchText, options.matchCase, identifier)) {
|
|
|
|
} else {
|
|
|
|
// No find results.
|
|
|
|
UIT_NotifyFindStatus(identifier, 0, gfx::Rect(), 0, true);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2011-09-10 21:40:03 +02:00
|
|
|
return;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WebFrame* frame_after_main = main_frame->traverseNext(true);
|
|
|
|
WebFrame* focused_frame = view->focusedFrame();
|
|
|
|
WebFrame* search_frame = focused_frame; // start searching focused frame.
|
|
|
|
|
|
|
|
bool multi_frame = (frame_after_main != main_frame);
|
|
|
|
|
|
|
|
// If we have multiple frames, we don't want to wrap the search within the
|
|
|
|
// frame, so we check here if we only have main_frame in the chain.
|
|
|
|
bool wrap_within_frame = !multi_frame;
|
|
|
|
|
|
|
|
WebRect selection_rect;
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
// If something is selected when we start searching it means we cannot just
|
|
|
|
// increment the current match ordinal; we need to re-generate it.
|
|
|
|
WebRange current_selection = focused_frame->selectionRange();
|
|
|
|
|
|
|
|
do {
|
2010-11-22 18:49:46 +01:00
|
|
|
result = search_frame->find(identifier, searchText, options,
|
|
|
|
wrap_within_frame, &selection_rect);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
// don't leave text selected as you move to the next frame.
|
|
|
|
search_frame->executeCommand(WebString::fromUTF8("Unselect"));
|
|
|
|
|
|
|
|
// Find the next frame, but skip the invisible ones.
|
|
|
|
do {
|
|
|
|
// What is the next frame to search? (we might be going backwards). Note
|
|
|
|
// that we specify wrap=true so that search_frame never becomes NULL.
|
|
|
|
search_frame = options.forward ?
|
|
|
|
search_frame->traverseNext(true) :
|
|
|
|
search_frame->traversePrevious(true);
|
|
|
|
} while (!search_frame->hasVisibleContent() &&
|
|
|
|
search_frame != focused_frame);
|
|
|
|
|
|
|
|
// Make sure selection doesn't affect the search operation in new frame.
|
|
|
|
search_frame->executeCommand(WebString::fromUTF8("Unselect"));
|
|
|
|
|
|
|
|
// If we have multiple frames and we have wrapped back around to the
|
|
|
|
// focused frame, we need to search it once more allowing wrap within
|
|
|
|
// the frame, otherwise it will report 'no match' if the focused frame has
|
|
|
|
// reported matches, but no frames after the focused_frame contain a
|
|
|
|
// match for the search word(s).
|
|
|
|
if (multi_frame && search_frame == focused_frame) {
|
|
|
|
result = search_frame->find(
|
2010-11-22 18:49:46 +01:00
|
|
|
identifier, searchText,
|
2010-10-10 02:16:24 +02:00
|
|
|
options, true, // Force wrapping.
|
2010-10-03 23:04:50 +02:00
|
|
|
&selection_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
view->setFocusedFrame(search_frame);
|
|
|
|
} while (!result && search_frame != focused_frame);
|
|
|
|
|
|
|
|
if (options.findNext && current_selection.isNull()) {
|
|
|
|
// Force the main_frame to report the actual count.
|
|
|
|
main_frame->increaseMatchCount(0, identifier);
|
|
|
|
} else {
|
|
|
|
// If nothing is found, set result to "0 of 0", otherwise, set it to
|
|
|
|
// "-1 of 1" to indicate that we found at least one item, but we don't know
|
|
|
|
// yet what is active.
|
|
|
|
int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
|
|
|
|
int match_count = result ? 1 : 0; // 1 here means possibly more coming.
|
|
|
|
|
|
|
|
// If we find no matches then this will be our last status update.
|
|
|
|
// Otherwise the scoping effort will send more results.
|
|
|
|
bool final_status_update = !result;
|
|
|
|
|
|
|
|
// Send the search result.
|
|
|
|
UIT_NotifyFindStatus(identifier, match_count, selection_rect, ordinal,
|
|
|
|
final_status_update);
|
|
|
|
|
|
|
|
// Scoping effort begins, starting with the mainframe.
|
|
|
|
search_frame = main_frame;
|
|
|
|
|
|
|
|
main_frame->resetMatchCount();
|
|
|
|
|
|
|
|
do {
|
|
|
|
// Cancel all old scoping requests before starting a new one.
|
|
|
|
search_frame->cancelPendingScopingEffort();
|
|
|
|
|
|
|
|
// We don't start another scoping effort unless at least one match has
|
|
|
|
// been found.
|
|
|
|
if (result) {
|
|
|
|
// Start new scoping request. If the scoping function determines that it
|
|
|
|
// needs to scope, it will defer until later.
|
2010-11-22 18:49:46 +01:00
|
|
|
search_frame->scopeStringMatches(identifier, searchText, options,
|
2010-10-03 23:04:50 +02:00
|
|
|
true); // reset the tickmarks
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate to the next frame. The frame will not necessarily scope, for
|
|
|
|
// example if it is not visible.
|
|
|
|
search_frame = search_frame->traverseNext(true);
|
|
|
|
} while (search_frame != main_frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_StopFinding(bool clear_selection) {
|
2011-01-29 02:42:59 +01:00
|
|
|
WebView* view = UIT_GetWebView();
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebDocument doc = view->mainFrame()->document();
|
|
|
|
if (doc.isPluginDocument()) {
|
2011-09-10 21:40:03 +02:00
|
|
|
WebPlugin* plugin =
|
|
|
|
view->mainFrame()->document().to<WebPluginDocument>().plugin();
|
|
|
|
if (plugin)
|
|
|
|
plugin->stopFind();
|
2010-10-03 23:04:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clear_selection)
|
|
|
|
view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
|
|
|
|
|
|
|
|
WebFrame* frame = view->mainFrame();
|
|
|
|
while (frame) {
|
|
|
|
frame->stopFinding(clear_selection);
|
|
|
|
frame = frame->traverseNext(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_NotifyFindStatus(int identifier, int count,
|
|
|
|
const WebKit::WebRect& selection_rect,
|
|
|
|
int active_match_ordinal,
|
2012-01-10 00:46:23 +01:00
|
|
|
bool final_update) {
|
|
|
|
if (client_.get()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefFindHandler> handler = client_->GetFindHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRect rect(selection_rect.x, selection_rect.y, selection_rect.width,
|
|
|
|
selection_rect.height);
|
|
|
|
handler->OnFindResult(this, identifier, count, rect, active_match_ordinal,
|
|
|
|
final_update);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_SetZoomLevel(double zoomLevel) {
|
2011-01-25 16:34:50 +01:00
|
|
|
REQUIRE_UIT();
|
2011-01-29 02:42:59 +01:00
|
|
|
WebKit::WebFrame* web_frame = UIT_GetMainWebFrame();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (web_frame) {
|
2012-10-01 22:35:35 +02:00
|
|
|
GURL url = web_frame->document().url();
|
2011-01-25 16:34:50 +01:00
|
|
|
web_frame->view()->setZoomLevel(false, zoomLevel);
|
2012-10-01 22:35:35 +02:00
|
|
|
bool didHandleZoom = false;
|
|
|
|
if (client_.get()) {
|
|
|
|
CefRefPtr<CefZoomHandler> handler = client_->GetZoomHandler();
|
|
|
|
if (handler.get())
|
|
|
|
didHandleZoom = handler->OnSetZoomLevel(this, url.spec(), zoomLevel);
|
|
|
|
}
|
|
|
|
if (!didHandleZoom)
|
|
|
|
ZoomMap::GetInstance()->set(url, zoomLevel);
|
2011-01-29 02:42:59 +01:00
|
|
|
set_zoom_level(zoomLevel);
|
2011-01-25 16:34:50 +01:00
|
|
|
}
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_ShowDevTools() {
|
2011-01-25 19:37:27 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!dev_tools_agent_.get())
|
2011-01-25 19:37:27 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
BrowserDevToolsClient* client = dev_tools_agent_->client();
|
|
|
|
if (!client) {
|
|
|
|
// Create the inspector window.
|
2011-10-31 19:47:01 +01:00
|
|
|
CefString url(base::StringPrintf(
|
|
|
|
"%sdevtools.html?docked=false&toolbarColor=rgba(223,223,223,1)&"
|
|
|
|
"textColor=rgba(18,50,114,1)",
|
|
|
|
kChromeDevToolsURL));
|
2011-06-14 19:44:19 +02:00
|
|
|
|
2011-01-25 19:37:27 +01:00
|
|
|
CefPopupFeatures features;
|
2011-06-14 19:44:19 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> browser = UIT_CreatePopupWindow(url, features);
|
2011-08-03 18:59:21 +02:00
|
|
|
if (browser.get()) {
|
|
|
|
browser->UIT_CreateDevToolsClient(dev_tools_agent_.get());
|
|
|
|
browser->UIT_LoadURL(browser->GetMainFrame(), url);
|
|
|
|
browser->UIT_Show(WebKit::WebNavigationPolicyNewWindow);
|
|
|
|
}
|
2011-01-25 19:37:27 +01:00
|
|
|
} else {
|
|
|
|
// Give focus to the existing inspector window.
|
|
|
|
client->browser()->UIT_Show(WebKit::WebNavigationPolicyNewWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_CloseDevTools() {
|
2011-01-29 23:52:34 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!dev_tools_agent_.get())
|
2011-01-29 23:52:34 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
BrowserDevToolsClient* client = dev_tools_agent_->client();
|
|
|
|
if (client)
|
|
|
|
client->browser()->UIT_CloseBrowser();
|
|
|
|
}
|
|
|
|
|
2011-02-23 04:45:13 +01:00
|
|
|
void CefBrowserImpl::UIT_VisitDOM(CefRefPtr<CefFrame> frame,
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefDOMVisitor> visitor) {
|
2011-02-23 04:45:13 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
WebKit::WebFrame* web_frame = UIT_GetWebFrame(frame);
|
|
|
|
if (!web_frame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Create a CefDOMDocumentImpl object that is valid only for the scope of this
|
|
|
|
// method.
|
|
|
|
CefRefPtr<CefDOMDocumentImpl> documentImpl;
|
|
|
|
const WebKit::WebDocument& document = web_frame->document();
|
|
|
|
if (!document.isNull())
|
|
|
|
documentImpl = new CefDOMDocumentImpl(this, web_frame);
|
|
|
|
|
|
|
|
visitor->Visit(documentImpl.get());
|
|
|
|
|
|
|
|
if (documentImpl.get())
|
|
|
|
documentImpl->Detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_AddFrameObject(WebKit::WebFrame* frame,
|
2012-01-19 19:52:59 +01:00
|
|
|
CefTrackNode* tracked_object) {
|
2011-02-23 04:45:13 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
CefRefPtr<CefTrackManager> manager;
|
|
|
|
|
|
|
|
if (!frame_objects_.empty()) {
|
|
|
|
FrameObjectMap::const_iterator it = frame_objects_.find(frame);
|
|
|
|
if (it != frame_objects_.end())
|
|
|
|
manager = it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!manager.get()) {
|
|
|
|
manager = new CefTrackManager();
|
|
|
|
frame_objects_.insert(std::make_pair(frame, manager));
|
|
|
|
}
|
|
|
|
|
|
|
|
manager->Add(tracked_object);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_BeforeFrameClosed(WebKit::WebFrame* frame) {
|
2011-02-23 04:45:13 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
if (!frame_objects_.empty()) {
|
|
|
|
// Remove any tracked objects associated with the frame.
|
|
|
|
FrameObjectMap::iterator it = frame_objects_.find(frame);
|
|
|
|
if (it != frame_objects_.end())
|
|
|
|
frame_objects_.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::set_zoom_level(double zoomLevel) {
|
2011-01-29 02:42:59 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
zoom_level_ = zoomLevel;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
double CefBrowserImpl::zoom_level() {
|
2011-01-29 02:42:59 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return zoom_level_;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::set_nav_state(bool can_go_back, bool can_go_forward) {
|
2011-01-29 02:42:59 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
can_go_back_ = can_go_back;
|
|
|
|
can_go_forward_ = can_go_forward;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::can_go_back() {
|
2011-01-29 02:42:59 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return can_go_back_;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::can_go_forward() {
|
2011-01-29 02:42:59 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return can_go_forward_;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::set_has_document(bool has_document) {
|
2011-08-30 18:20:27 +02:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
has_document_ = has_document;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefBrowserImpl::has_document() {
|
2011-08-30 18:20:27 +02:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return has_document_;
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
void CefBrowserImpl::set_pending_url(const GURL& url) {
|
|
|
|
AutoLock lock_scope(this);
|
|
|
|
pending_url_ = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
GURL CefBrowserImpl::pending_url() {
|
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return pending_url_;
|
|
|
|
}
|
|
|
|
|
2012-05-25 22:44:34 +02:00
|
|
|
net::URLRequestContext* CefBrowserImpl::request_context_proxy() {
|
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
|
|
|
if (!request_context_proxy_.get()) {
|
|
|
|
request_context_proxy_.reset(
|
|
|
|
new BrowserRequestContextProxy(_Context->request_context(), this));
|
|
|
|
}
|
|
|
|
return request_context_proxy_.get();
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_CreateDevToolsClient(BrowserDevToolsAgent *agent) {
|
2011-01-25 19:37:27 +01:00
|
|
|
dev_tools_client_.reset(new BrowserDevToolsClient(this, agent));
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefBrowserImpl::UIT_DestroyDevToolsClient() {
|
2011-01-29 23:52:34 +01:00
|
|
|
if (dev_tools_client_.get()) {
|
|
|
|
// Free the client. This will cause the client to clear pending messages
|
|
|
|
// and detach from the agent.
|
|
|
|
dev_tools_client_.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-25 19:37:27 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// CefFrameImpl
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
CefFrameImpl::CefFrameImpl(CefBrowserImpl* browser,
|
|
|
|
int64 id,
|
|
|
|
const CefString& name,
|
|
|
|
const CefString& url)
|
|
|
|
: browser_(browser),
|
|
|
|
name_(name),
|
2012-03-23 01:19:51 +01:00
|
|
|
id_(id),
|
2012-03-22 23:08:05 +01:00
|
|
|
url_(url) {
|
2011-01-29 02:42:59 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefFrameImpl::~CefFrameImpl() {
|
2012-03-22 23:08:05 +01:00
|
|
|
if (!IsMain())
|
|
|
|
browser_->RemoveCefFrame(id_);
|
2011-01-29 02:42:59 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefFrameImpl::IsFocused() {
|
2011-01-29 02:42:59 +01:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
2011-01-29 02:42:59 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (browser_->UIT_GetWebView() &&
|
|
|
|
(browser_->UIT_GetWebFrame(this) ==
|
|
|
|
browser_->UIT_GetWebView()->focusedFrame()));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2011-02-23 04:45:13 +01:00
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
int64 CefFrameImpl::GetIdentifier() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefFrameImpl::GetURL() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return url_;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefFrameImpl::VisitDOM(CefRefPtr<CefDOMVisitor> visitor) {
|
|
|
|
if (!visitor.get()) {
|
2011-10-28 22:30:19 +02:00
|
|
|
NOTREACHED() << "invalid parameter";
|
2011-02-23 04:45:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
CefRefPtr<CefFrame> framePtr(this);
|
2012-02-17 15:51:20 +01:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserImpl::UIT_VisitDOM, browser_.get(), framePtr,
|
|
|
|
visitor));
|
2011-02-23 04:45:13 +01:00
|
|
|
}
|
2011-10-28 22:30:19 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefV8Context> CefFrameImpl::GetV8Context() {
|
2011-10-28 22:30:19 +02:00
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CefThread::CurrentlyOn(CefThread::UI)) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebKit::WebFrame* frame = browser_->UIT_GetWebFrame(this);
|
|
|
|
if (frame) {
|
|
|
|
v8::HandleScope handle_scope;
|
|
|
|
return new CefV8ContextImpl(webkit_glue::GetV8Context(frame));
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 23:08:05 +01:00
|
|
|
|
|
|
|
void CefFrameImpl::set_id(int64 id) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
id_ = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::set_url(const CefString& url) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
url_ = url;
|
|
|
|
}
|