2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/renderer/frame_impl.h"
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2016-03-16 03:55:59 +01:00
|
|
|
#if defined(OS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic error "-Wdeprecated-declarations"
|
|
|
|
#else
|
2016-03-16 03:55:59 +01:00
|
|
|
#pragma warning(push)
|
2017-05-17 11:29:28 +02:00
|
|
|
#pragma warning(default : 4996)
|
2016-03-16 03:55:59 +01:00
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/cef_messages.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/common/net/http_header_utils.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/request_impl.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "libcef/renderer/blink_glue.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/browser_impl.h"
|
2012-04-27 23:19:06 +02:00
|
|
|
#include "libcef/renderer/dom_document_impl.h"
|
2017-07-06 22:39:37 +02:00
|
|
|
#include "libcef/renderer/render_frame_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/renderer/thread_util.h"
|
|
|
|
#include "libcef/renderer/v8_impl.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
|
|
|
|
#include "third_party/blink/public/platform/web_data.h"
|
|
|
|
#include "third_party/blink/public/platform/web_string.h"
|
|
|
|
#include "third_party/blink/public/platform/web_url.h"
|
|
|
|
#include "third_party/blink/public/web/blink.h"
|
|
|
|
#include "third_party/blink/public/web/web_document.h"
|
2018-07-09 22:12:39 +02:00
|
|
|
#include "third_party/blink/public/web/web_document_loader.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/web_frame_content_dumper.h"
|
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
|
|
|
#include "third_party/blink/public/web/web_script_source.h"
|
|
|
|
#include "third_party/blink/public/web/web_view.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
using blink::WebString;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-07-09 20:36:37 +02:00
|
|
|
CefFrameImpl::CefFrameImpl(CefBrowserImpl* browser,
|
|
|
|
blink::WebLocalFrame* frame,
|
|
|
|
int64_t frame_id)
|
|
|
|
: browser_(browser), frame_(frame), frame_id_(frame_id) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefFrameImpl::~CefFrameImpl() {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
bool CefFrameImpl::IsValid() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
|
|
|
return (frame_ != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Undo() {
|
2016-07-21 23:21:32 +02:00
|
|
|
ExecuteCommand("Undo");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Redo() {
|
2016-07-21 23:21:32 +02:00
|
|
|
ExecuteCommand("Redo");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Cut() {
|
2016-07-21 23:21:32 +02:00
|
|
|
ExecuteCommand("Cut");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Copy() {
|
2016-07-21 23:21:32 +02:00
|
|
|
ExecuteCommand("Copy");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Paste() {
|
2016-07-21 23:21:32 +02:00
|
|
|
ExecuteCommand("Paste");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::Delete() {
|
2016-07-21 23:21:32 +02:00
|
|
|
ExecuteCommand("Delete");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::SelectAll() {
|
2016-07-21 23:21:32 +02:00
|
|
|
ExecuteCommand("SelectAll");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::ViewSource() {
|
|
|
|
NOTREACHED() << "ViewSource cannot be called from the renderer process";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::GetSource(CefRefPtr<CefStringVisitor> visitor) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (frame_) {
|
|
|
|
const CefString& content =
|
|
|
|
std::string(blink::WebFrameContentDumper::DumpAsMarkup(frame_).Utf8());
|
2012-04-03 03:34:16 +02:00
|
|
|
visitor->Visit(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::GetText(CefRefPtr<CefStringVisitor> visitor) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
|
|
|
if (frame_) {
|
2018-04-19 17:44:42 +02:00
|
|
|
const CefString& content = blink_glue::DumpDocumentText(frame_);
|
2012-04-03 03:34:16 +02:00
|
|
|
visitor->Visit(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::LoadRequest(CefRefPtr<CefRequest> request) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
|
|
|
if (!browser_)
|
|
|
|
return;
|
|
|
|
|
2014-07-16 23:27:25 +02:00
|
|
|
CefMsg_LoadRequest_Params params;
|
2012-04-03 03:34:16 +02:00
|
|
|
params.url = GURL(std::string(request->GetURL()));
|
|
|
|
params.method = request->GetMethod();
|
|
|
|
params.frame_id = frame_id_;
|
2017-09-06 23:40:58 +02:00
|
|
|
params.site_for_cookies =
|
2014-07-16 23:27:25 +02:00
|
|
|
GURL(std::string(request->GetFirstPartyForCookies()));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefRequest::HeaderMap headerMap;
|
|
|
|
request->GetHeaderMap(headerMap);
|
|
|
|
if (!headerMap.empty())
|
|
|
|
params.headers = HttpHeaderUtils::GenerateHeaders(headerMap);
|
|
|
|
|
|
|
|
CefRefPtr<CefPostData> postData = request->GetPostData();
|
|
|
|
if (postData.get()) {
|
|
|
|
CefPostDataImpl* impl = static_cast<CefPostDataImpl*>(postData.get());
|
|
|
|
params.upload_data = new net::UploadData();
|
|
|
|
impl->Get(*params.upload_data.get());
|
|
|
|
}
|
|
|
|
|
2014-07-16 23:27:25 +02:00
|
|
|
params.load_flags = request->GetFlags();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
browser_->LoadRequest(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::LoadURL(const CefString& url) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
|
|
|
if (!browser_)
|
|
|
|
return;
|
|
|
|
|
2014-07-16 23:27:25 +02:00
|
|
|
CefMsg_LoadRequest_Params params;
|
2012-04-03 03:34:16 +02:00
|
|
|
params.url = GURL(url.ToString());
|
|
|
|
params.method = "GET";
|
|
|
|
params.frame_id = frame_id_;
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
browser_->LoadRequest(params);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefFrameImpl::LoadString(const CefString& string, const CefString& url) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
|
|
|
if (frame_) {
|
|
|
|
GURL gurl = GURL(url.ToString());
|
2017-04-20 21:28:17 +02:00
|
|
|
frame_->LoadHTMLString(string.ToString(), gurl);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefFrameImpl::ExecuteJavaScript(const CefString& jsCode,
|
|
|
|
const CefString& scriptUrl,
|
|
|
|
int startLine) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
if (jsCode.empty())
|
|
|
|
return;
|
2016-10-27 18:34:19 +02:00
|
|
|
if (startLine < 1)
|
|
|
|
startLine = 1;
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
if (frame_) {
|
|
|
|
GURL gurl = GURL(scriptUrl.ToString());
|
2017-05-17 11:29:28 +02:00
|
|
|
frame_->ExecuteScript(blink::WebScriptSource(
|
|
|
|
WebString::FromUTF16(jsCode.ToString16()), gurl, startLine));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefFrameImpl::IsMain() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
|
|
|
if (frame_)
|
2017-04-20 21:28:17 +02:00
|
|
|
return (frame_->Parent() == NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefFrameImpl::IsFocused() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (frame_ && frame_->View())
|
|
|
|
return (frame_->View()->FocusedFrame() == frame_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefFrameImpl::GetName() {
|
|
|
|
CefString name;
|
|
|
|
CEF_REQUIRE_RT_RETURN(name);
|
|
|
|
|
|
|
|
if (frame_)
|
2018-03-28 19:30:15 +02:00
|
|
|
name = render_frame_util::GetName(frame_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 CefFrameImpl::GetIdentifier() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(0);
|
|
|
|
|
|
|
|
return frame_id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> CefFrameImpl::GetParent() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(NULL);
|
|
|
|
|
|
|
|
if (frame_) {
|
2017-04-20 21:28:17 +02:00
|
|
|
blink::WebFrame* parent = frame_->Parent();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (parent && parent->IsWebLocalFrame())
|
|
|
|
return browser_->GetWebFrameImpl(parent->ToWebLocalFrame()).get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefFrameImpl::GetURL() {
|
|
|
|
CefString url;
|
|
|
|
CEF_REQUIRE_RT_RETURN(url);
|
|
|
|
|
|
|
|
if (frame_) {
|
2017-04-20 21:28:17 +02:00
|
|
|
GURL gurl = frame_->GetDocument().Url();
|
2018-07-09 20:36:37 +02:00
|
|
|
if (gurl.is_empty()) {
|
|
|
|
// For popups the main document URL will be empty during loading. Return
|
|
|
|
// the provisional document URL instead.
|
|
|
|
blink::WebDocumentLoader* loader = frame_->GetProvisionalDocumentLoader();
|
|
|
|
if (loader)
|
|
|
|
gurl = loader->GetRequest().Url();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
url = gurl.spec();
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> CefFrameImpl::GetBrowser() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(NULL);
|
|
|
|
|
|
|
|
return browser_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> CefFrameImpl::GetV8Context() {
|
|
|
|
CEF_REQUIRE_RT_RETURN(NULL);
|
|
|
|
|
|
|
|
if (frame_) {
|
2017-04-20 21:28:17 +02:00
|
|
|
v8::Isolate* isolate = blink::MainThreadIsolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2017-04-20 21:28:17 +02:00
|
|
|
return new CefV8ContextImpl(isolate, frame_->MainWorldScriptContext());
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 23:19:06 +02:00
|
|
|
void CefFrameImpl::VisitDOM(CefRefPtr<CefDOMVisitor> visitor) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
|
|
|
|
|
|
|
if (!frame_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Create a CefDOMDocumentImpl object that is valid only for the scope of this
|
|
|
|
// method.
|
|
|
|
CefRefPtr<CefDOMDocumentImpl> documentImpl;
|
2017-04-20 21:28:17 +02:00
|
|
|
const blink::WebDocument& document = frame_->GetDocument();
|
|
|
|
if (!document.IsNull())
|
2012-04-27 23:19:06 +02:00
|
|
|
documentImpl = new CefDOMDocumentImpl(browser_, frame_);
|
|
|
|
|
|
|
|
visitor->Visit(documentImpl.get());
|
|
|
|
|
|
|
|
if (documentImpl.get())
|
|
|
|
documentImpl->Detach();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefFrameImpl::Detach() {
|
|
|
|
browser_ = NULL;
|
|
|
|
frame_ = NULL;
|
|
|
|
}
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
void CefFrameImpl::ExecuteCommand(const std::string& command) {
|
|
|
|
CEF_REQUIRE_RT_RETURN_VOID();
|
2017-07-27 01:19:27 +02:00
|
|
|
if (frame_)
|
|
|
|
frame_->ExecuteCommand(WebString::FromUTF8(command));
|
2016-07-21 23:21:32 +02:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2016-03-16 03:55:59 +01:00
|
|
|
#if defined(OS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#else
|
2016-03-16 03:55:59 +01:00
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|