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.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_FRAME_HOST_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_FRAME_HOST_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <queue>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_frame.h"
|
2013-05-31 17:34:53 +02:00
|
|
|
#include "libcef/common/response_manager.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/synchronization/lock.h"
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "ui/base/page_transition_types.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
namespace content {
|
|
|
|
class RenderFrameHost;
|
2019-05-24 22:23:43 +02:00
|
|
|
struct Referrer;
|
|
|
|
} // namespace content
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
class Message;
|
2019-05-11 00:14:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
class GURL;
|
|
|
|
|
|
|
|
struct Cef_DraggableRegion_Params;
|
|
|
|
struct Cef_Request_Params;
|
|
|
|
struct Cef_Response_Params;
|
|
|
|
class CefBrowserInfo;
|
2012-04-03 03:34:16 +02:00
|
|
|
class CefBrowserHostImpl;
|
2019-05-24 22:23:43 +02:00
|
|
|
struct CefNavigateParams;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Implementation of CefFrame. CefFrameHostImpl objects should always be created
|
|
|
|
// or retrieved via CefBrowerInfo.
|
2012-04-03 03:34:16 +02:00
|
|
|
class CefFrameHostImpl : public CefFrame {
|
|
|
|
public:
|
2019-05-24 22:23:43 +02:00
|
|
|
// Create a temporary frame.
|
|
|
|
CefFrameHostImpl(scoped_refptr<CefBrowserInfo> browser_info,
|
2017-05-17 11:29:28 +02:00
|
|
|
bool is_main_frame,
|
2019-05-24 22:23:43 +02:00
|
|
|
int64_t parent_frame_id);
|
|
|
|
|
|
|
|
// Create a frame backed by a RFH and owned by CefBrowserInfo.
|
|
|
|
CefFrameHostImpl(scoped_refptr<CefBrowserInfo> browser_info,
|
|
|
|
content::RenderFrameHost* render_frame_host);
|
|
|
|
|
|
|
|
// Update an existing main frame object.
|
|
|
|
void SetRenderFrameHost(content::RenderFrameHost* host);
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefFrameHostImpl() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefFrame methods
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsValid() override;
|
|
|
|
void Undo() override;
|
|
|
|
void Redo() override;
|
|
|
|
void Cut() override;
|
|
|
|
void Copy() override;
|
|
|
|
void Paste() override;
|
|
|
|
void Delete() override;
|
|
|
|
void SelectAll() override;
|
|
|
|
void ViewSource() override;
|
|
|
|
void GetSource(CefRefPtr<CefStringVisitor> visitor) override;
|
|
|
|
void GetText(CefRefPtr<CefStringVisitor> visitor) override;
|
|
|
|
void LoadRequest(CefRefPtr<CefRequest> request) override;
|
|
|
|
void LoadURL(const CefString& url) override;
|
|
|
|
void ExecuteJavaScript(const CefString& jsCode,
|
|
|
|
const CefString& scriptUrl,
|
|
|
|
int startLine) override;
|
|
|
|
bool IsMain() override;
|
|
|
|
bool IsFocused() override;
|
|
|
|
CefString GetName() override;
|
|
|
|
int64 GetIdentifier() override;
|
|
|
|
CefRefPtr<CefFrame> GetParent() override;
|
|
|
|
CefString GetURL() override;
|
|
|
|
CefRefPtr<CefBrowser> GetBrowser() override;
|
|
|
|
CefRefPtr<CefV8Context> GetV8Context() override;
|
|
|
|
void VisitDOM(CefRefPtr<CefDOMVisitor> visitor) override;
|
2019-05-11 00:14:48 +02:00
|
|
|
CefRefPtr<CefURLRequest> CreateURLRequest(
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefURLRequestClient> client) override;
|
2019-05-24 22:23:43 +02:00
|
|
|
void SendProcessMessage(CefProcessId target_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
void SetFocused(bool focused);
|
2019-05-24 22:23:43 +02:00
|
|
|
void RefreshAttributes();
|
|
|
|
|
|
|
|
// Navigate as specified by the |params| argument.
|
|
|
|
void Navigate(const CefNavigateParams& params);
|
|
|
|
|
|
|
|
// Load the specified URL.
|
|
|
|
void LoadURLWithExtras(const std::string& url,
|
|
|
|
const content::Referrer& referrer,
|
|
|
|
ui::PageTransition transition,
|
|
|
|
const std::string& extra_headers);
|
|
|
|
|
|
|
|
// Send a command to the renderer for execution.
|
|
|
|
void SendCommand(const std::string& command,
|
|
|
|
CefRefPtr<CefResponseManager::Handler> responseHandler);
|
|
|
|
|
|
|
|
// Send code to the renderer for execution.
|
|
|
|
void SendCode(bool is_javascript,
|
|
|
|
const std::string& code,
|
|
|
|
const std::string& script_url,
|
|
|
|
int script_start_line,
|
|
|
|
CefRefPtr<CefResponseManager::Handler> responseHandler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Send JavaScript to the renderer for execution.
|
2012-10-18 00:45:49 +02:00
|
|
|
void SendJavaScript(const std::string& jsCode,
|
|
|
|
const std::string& scriptUrl,
|
|
|
|
int startLine);
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Called from CefBrowserHostImpl::DidStopLoading.
|
|
|
|
void MaybeSendDidStopLoading();
|
|
|
|
|
|
|
|
// Called from CefBrowserHostImpl::OnMessageReceived.
|
|
|
|
bool OnMessageReceived(const IPC::Message& message);
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
void ExecuteJavaScriptWithUserGestureForTests(const CefString& javascript);
|
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
// Returns the RFH associated with this frame. Must be called on the UI
|
|
|
|
// thread.
|
2019-05-24 22:23:43 +02:00
|
|
|
content::RenderFrameHost* GetRenderFrameHost() const;
|
2019-05-11 00:14:48 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// Owned frame objects will be detached explicitly when the associated
|
|
|
|
// RenderFrame is deleted. Temporary frame objects will be detached
|
|
|
|
// implicitly via CefBrowserInfo::browser() returning nullptr.
|
2012-04-03 03:34:16 +02:00
|
|
|
void Detach();
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
static int64_t MakeFrameId(const content::RenderFrameHost* host);
|
|
|
|
static int64_t MakeFrameId(int32_t render_process_id,
|
|
|
|
int32_t render_routing_id);
|
|
|
|
|
|
|
|
static const int64_t kMainFrameId;
|
|
|
|
static const int64_t kFocusedFrameId;
|
|
|
|
static const int64_t kUnspecifiedFrameId;
|
|
|
|
static const int64_t kInvalidFrameId;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int64 GetFrameId() const;
|
|
|
|
CefRefPtr<CefBrowserHostImpl> GetBrowserHostImpl() const;
|
|
|
|
|
|
|
|
// OnMessageReceived message handlers.
|
|
|
|
void OnAttached();
|
|
|
|
void OnDidFinishLoad(const GURL& validated_url, int http_status_code);
|
|
|
|
void OnUpdateDraggableRegions(
|
|
|
|
const std::vector<Cef_DraggableRegion_Params>& regions);
|
|
|
|
void OnRequest(const Cef_Request_Params& params);
|
|
|
|
void OnResponse(const Cef_Response_Params& params);
|
|
|
|
void OnResponseAck(int request_id);
|
|
|
|
|
|
|
|
// Send a message to the RenderFrameHost associated with this frame.
|
|
|
|
void Send(IPC::Message* message);
|
|
|
|
|
|
|
|
const bool is_main_frame_;
|
|
|
|
|
|
|
|
// The following members may be read/modified from any thread. All access must
|
|
|
|
// be protected by |state_lock_|.
|
|
|
|
mutable base::Lock state_lock_;
|
2012-04-03 03:34:16 +02:00
|
|
|
int64 frame_id_;
|
2019-05-24 22:23:43 +02:00
|
|
|
scoped_refptr<CefBrowserInfo> browser_info_;
|
2012-04-03 03:34:16 +02:00
|
|
|
bool is_focused_;
|
|
|
|
CefString url_;
|
|
|
|
CefString name_;
|
|
|
|
int64 parent_frame_id_;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
// The following members are only accessed on the UI thread.
|
|
|
|
content::RenderFrameHost* render_frame_host_ = nullptr;
|
|
|
|
|
|
|
|
bool is_attached_ = false;
|
|
|
|
|
|
|
|
// Qeueud messages to send when the renderer process attaches.
|
|
|
|
std::queue<std::unique_ptr<IPC::Message>> queued_messages_;
|
|
|
|
|
|
|
|
// Manages response registrations.
|
|
|
|
std::unique_ptr<CefResponseManager> response_manager_;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CefFrameHostImpl);
|
2015-12-09 17:10:16 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefFrameHostImpl);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_FRAME_HOST_IMPL_H_
|