2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2011 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.
|
|
|
|
|
2013-10-16 02:25:38 +02:00
|
|
|
// MSVC++ requires this to be set before any other includes to get M_PI.
|
|
|
|
// Otherwise there will be compile errors in wtf/MathExtras.h.
|
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
|
2013-10-29 18:53:18 +01:00
|
|
|
// Defines required to access Blink internals (unwrap WebNode).
|
|
|
|
#undef BLINK_IMPLEMENTATION
|
|
|
|
#define BLINK_IMPLEMENTATION 1
|
|
|
|
#undef INSIDE_BLINK
|
|
|
|
#define INSIDE_BLINK 1
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/webkit_glue.h"
|
|
|
|
|
|
|
|
#include "base/compiler_specific.h"
|
2013-10-29 18:53:18 +01:00
|
|
|
#include "v8/include/v8.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-05-07 23:48:34 +02:00
|
|
|
#include "config.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
MSVC_PUSH_WARNING_LEVEL(0);
|
2013-10-29 18:53:18 +01:00
|
|
|
#include "third_party/WebKit/public/platform/WebString.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebDocument.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebElement.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebNode.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebViewClient.h"
|
|
|
|
|
2013-10-16 02:25:38 +02:00
|
|
|
#include "bindings/v8/V8Binding.h"
|
2013-05-07 23:48:34 +02:00
|
|
|
#include "bindings/v8/ScriptController.h"
|
2013-10-29 18:53:18 +01:00
|
|
|
#include "third_party/WebKit/Source/core/dom/Node.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "third_party/WebKit/Source/web/WebFrameImpl.h"
|
|
|
|
#include "third_party/WebKit/Source/web/WebViewImpl.h"
|
2013-10-29 18:53:18 +01:00
|
|
|
#include "third_party/WebKit/Source/wtf/PassRefPtr.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
MSVC_POP_WARNING();
|
|
|
|
#undef LOG
|
|
|
|
|
|
|
|
namespace webkit_glue {
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
bool CanGoBack(blink::WebView* view) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (!view)
|
|
|
|
return false;
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebViewImpl* impl = reinterpret_cast<blink::WebViewImpl*>(view);
|
2013-10-29 18:53:18 +01:00
|
|
|
return (impl->client()->historyBackListCount() > 0);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
bool CanGoForward(blink::WebView* view) {
|
2013-07-24 22:15:18 +02:00
|
|
|
if (!view)
|
|
|
|
return false;
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebViewImpl* impl = reinterpret_cast<blink::WebViewImpl*>(view);
|
2013-10-29 18:53:18 +01:00
|
|
|
return (impl->client()->historyForwardListCount() > 0);
|
2013-07-24 22:15:18 +02:00
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
void GoBack(blink::WebView* view) {
|
2013-07-24 22:15:18 +02:00
|
|
|
if (!view)
|
|
|
|
return;
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebViewImpl* impl = reinterpret_cast<blink::WebViewImpl*>(view);
|
2013-10-29 18:53:18 +01:00
|
|
|
if (impl->client()->historyBackListCount() > 0)
|
|
|
|
impl->client()->navigateBackForwardSoon(-1);
|
2013-07-24 22:15:18 +02:00
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
void GoForward(blink::WebView* view) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (!view)
|
|
|
|
return;
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebViewImpl* impl = reinterpret_cast<blink::WebViewImpl*>(view);
|
2013-10-29 18:53:18 +01:00
|
|
|
if (impl->client()->historyForwardListCount() > 0)
|
|
|
|
impl->client()->navigateBackForwardSoon(1);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
v8::Isolate* GetV8Isolate(blink::WebFrame* frame) {
|
|
|
|
blink::WebFrameImpl* impl = static_cast<blink::WebFrameImpl*>(frame);
|
2013-10-16 02:25:38 +02:00
|
|
|
return WebCore::toIsolate(impl->frame());
|
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
v8::Handle<v8::Context> GetV8Context(blink::WebFrame* frame) {
|
|
|
|
blink::WebFrameImpl* impl = static_cast<blink::WebFrameImpl*>(frame);
|
2012-08-29 00:26:35 +02:00
|
|
|
return WebCore::ScriptController::mainWorldContext(impl->frame());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
std::string DumpDocumentText(blink::WebFrame* frame) {
|
2013-06-04 19:41:37 +02:00
|
|
|
// We use the document element's text instead of the body text here because
|
|
|
|
// not all documents have a body, such as XML documents.
|
2013-11-08 22:28:56 +01:00
|
|
|
blink::WebElement document_element = frame->document().documentElement();
|
2013-06-04 19:41:37 +02:00
|
|
|
if (document_element.isNull())
|
2013-10-29 18:53:18 +01:00
|
|
|
return std::string();
|
|
|
|
|
|
|
|
return document_element.innerText().utf8();
|
|
|
|
}
|
2013-06-04 19:41:37 +02:00
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
bool SetNodeValue(blink::WebNode& node, const blink::WebString& value) {
|
2013-10-29 18:53:18 +01:00
|
|
|
WebCore::Node* web_node = node.unwrap<WebCore::Node>();
|
|
|
|
web_node->setNodeValue(value);
|
|
|
|
return true;
|
2013-06-04 19:41:37 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
} // webkit_glue
|