cef/libcef/renderer/browser_impl.h

161 lines
5.9 KiB
C
Raw Normal View History

// 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.
#ifndef CEF_LIBCEF_RENDERER_BROWSER_IMPL_H_
#define CEF_LIBCEF_RENDERER_BROWSER_IMPL_H_
#pragma once
#include <stdint.h>
#include <map>
#include <string>
#include <vector>
#include "include/cef_browser.h"
#include "include/cef_client.h"
#include "libcef/common/tracker.h"
#include "libcef/renderer/frame_impl.h"
#include "content/public/renderer/render_view_observer.h"
class GURL;
struct CefMsg_LoadRequest_Params;
struct Cef_Request_Params;
struct Cef_Response_Params;
class CefContentRendererClient;
class CefResponseManager;
namespace base {
class ListValue;
}
// Renderer plumbing for CEF features. There is a one-to-one relationship
// between RenderView on the renderer side and RenderViewHost on the browser
// side.
//
// RenderViewObserver: Interface for observing RenderView notifications and IPC
// messages. IPC messages received by the RenderView will be forwarded to this
// RenderViewObserver implementation. IPC messages sent using
// RenderViewObserver::Send() will be forwarded to the RenderView. Use
// RenderViewObserver::routing_id() when sending IPC messages.
class CefBrowserImpl : public CefBrowser,
public content::RenderViewObserver {
public:
// Returns the browser associated with the specified RenderView.
static CefRefPtr<CefBrowserImpl> GetBrowserForView(content::RenderView* view);
// Returns the browser associated with the specified main WebFrame.
static CefRefPtr<CefBrowserImpl> GetBrowserForMainFrame(
blink::WebFrame* frame);
// CefBrowser methods.
CefRefPtr<CefBrowserHost> GetHost() override;
bool CanGoBack() override;
void GoBack() override;
bool CanGoForward() override;
void GoForward() override;
bool IsLoading() override;
void Reload() override;
void ReloadIgnoreCache() override;
void StopLoad() override;
int GetIdentifier() override;
bool IsSame(CefRefPtr<CefBrowser> that) override;
bool IsPopup() override;
bool HasDocument() override;
CefRefPtr<CefFrame> GetMainFrame() override;
CefRefPtr<CefFrame> GetFocusedFrame() override;
CefRefPtr<CefFrame> GetFrame(int64 identifier) override;
CefRefPtr<CefFrame> GetFrame(const CefString& name) override;
size_t GetFrameCount() override;
void GetFrameIdentifiers(std::vector<int64>& identifiers) override;
void GetFrameNames(std::vector<CefString>& names) override;
bool SendProcessMessage(
CefProcessId target_process,
CefRefPtr<CefProcessMessage> message) override;
CefBrowserImpl(content::RenderView* render_view,
int browser_id,
Implement off-screen rendering support using delegated rendering (issue #1257). This implementation supports both GPU compositing and software compositing (used when GPU is not supported or when passing `--disable-gpu --disable-gpu-compositing` command-line flags). GPU-accelerated features (WebGL and 3D CSS) that did not work with the previous off-screen rendering implementation do work with this implementation when GPU support is available. Rendering now operates on a per-frame basis. The frame rate is configurable via CefBrowserSettings.windowless_frame_rate up to a maximum of 60fps (potentially limited by how fast the system can generate new frames). CEF generates a bitmap from the compositor backing and passes it to CefRenderHandler::OnPaint. The previous CefRenderHandler/CefBrowserHost API for off-screen rendering has been restored mostly as-is with some minor changes: - CefBrowserHost::Invalidate no longer accepts a CefRect region argument. Instead of invalidating a specific region it now triggers generation of a new frame. - The |dirtyRects| argument to CefRenderHandler::OnPaint will now always be a single CefRect representing the whole view (frame) size. Previously, invalidated regions were listed separately. - Linux: CefBrowserHost::SendKeyEvent now expects X11 event information instead of GTK event information. See cefclient for an example of converting GTK events to the necessary format. - Sizes passed to the CefRenderHandler OnPaint and OnPopupSize methods are now already DPI scaled. Previously, the client had to perform DPI scaling. - Includes drag&drop implementation from issue #1032. - Includes unit test fixes from issue #1245. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1751 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
2014-07-01 00:30:29 +02:00
bool is_popup,
bool is_windowless);
~CefBrowserImpl() override;
void LoadRequest(const CefMsg_LoadRequest_Params& params);
// Avoids unnecessary string type conversions.
bool SendProcessMessage(CefProcessId target_process,
const std::string& name,
base::ListValue* arguments,
bool user_initiated);
// Returns the matching CefFrameImpl reference or creates a new one.
CefRefPtr<CefFrameImpl> GetWebFrameImpl(blink::WebFrame* frame);
CefRefPtr<CefFrameImpl> GetWebFrameImpl(int64_t frame_id);
// Frame objects will be deleted immediately before the frame is closed.
void AddFrameObject(int64_t frame_id, CefTrackNode* tracked_object);
int browser_id() const { return browser_id_; }
bool is_popup() const { return is_popup_; }
Implement off-screen rendering support using delegated rendering (issue #1257). This implementation supports both GPU compositing and software compositing (used when GPU is not supported or when passing `--disable-gpu --disable-gpu-compositing` command-line flags). GPU-accelerated features (WebGL and 3D CSS) that did not work with the previous off-screen rendering implementation do work with this implementation when GPU support is available. Rendering now operates on a per-frame basis. The frame rate is configurable via CefBrowserSettings.windowless_frame_rate up to a maximum of 60fps (potentially limited by how fast the system can generate new frames). CEF generates a bitmap from the compositor backing and passes it to CefRenderHandler::OnPaint. The previous CefRenderHandler/CefBrowserHost API for off-screen rendering has been restored mostly as-is with some minor changes: - CefBrowserHost::Invalidate no longer accepts a CefRect region argument. Instead of invalidating a specific region it now triggers generation of a new frame. - The |dirtyRects| argument to CefRenderHandler::OnPaint will now always be a single CefRect representing the whole view (frame) size. Previously, invalidated regions were listed separately. - Linux: CefBrowserHost::SendKeyEvent now expects X11 event information instead of GTK event information. See cefclient for an example of converting GTK events to the necessary format. - Sizes passed to the CefRenderHandler OnPaint and OnPopupSize methods are now already DPI scaled. Previously, the client had to perform DPI scaling. - Includes drag&drop implementation from issue #1032. - Includes unit test fixes from issue #1245. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1751 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
2014-07-01 00:30:29 +02:00
bool is_windowless() const { return is_windowless_; }
content::RenderView* render_view() const {
return content::RenderViewObserver::render_view();
}
bool is_swapped_out() const;
private:
// RenderViewObserver methods.
void OnDestruct() override;
void DidStartLoading() override;
void DidStopLoading() override;
void DidFailLoad(blink::WebLocalFrame* frame,
const blink::WebURLError& error) override;
void DidFinishLoad(blink::WebLocalFrame* frame) override;
void DidStartProvisionalLoad(blink::WebLocalFrame* frame) override;
void DidFailProvisionalLoad(
blink::WebLocalFrame* frame,
const blink::WebURLError& error) override;
void DidCommitProvisionalLoad(blink::WebLocalFrame* frame,
bool is_new_navigation) override;
void FrameDetached(blink::WebFrame* frame) override;
void FocusedNodeChanged(const blink::WebNode& node) override;
void DraggableRegionsChanged(blink::WebFrame* frame) override;
bool OnMessageReceived(const IPC::Message& message) override;
// RenderViewObserver::OnMessageReceived message handlers.
void OnRequest(const Cef_Request_Params& params);
void OnResponse(const Cef_Response_Params& params);
void OnResponseAck(int request_id);
void OnLoadingStateChange(bool isLoading);
void OnLoadStart(blink::WebLocalFrame* frame);
void OnLoadEnd(blink::WebLocalFrame* frame);
void OnLoadError(blink::WebLocalFrame* frame,
const blink::WebURLError& error);
// ID of the browser that this RenderView is associated with. During loading
// of cross-origin requests multiple RenderViews may be associated with the
// same browser ID.
int browser_id_;
bool is_popup_;
Implement off-screen rendering support using delegated rendering (issue #1257). This implementation supports both GPU compositing and software compositing (used when GPU is not supported or when passing `--disable-gpu --disable-gpu-compositing` command-line flags). GPU-accelerated features (WebGL and 3D CSS) that did not work with the previous off-screen rendering implementation do work with this implementation when GPU support is available. Rendering now operates on a per-frame basis. The frame rate is configurable via CefBrowserSettings.windowless_frame_rate up to a maximum of 60fps (potentially limited by how fast the system can generate new frames). CEF generates a bitmap from the compositor backing and passes it to CefRenderHandler::OnPaint. The previous CefRenderHandler/CefBrowserHost API for off-screen rendering has been restored mostly as-is with some minor changes: - CefBrowserHost::Invalidate no longer accepts a CefRect region argument. Instead of invalidating a specific region it now triggers generation of a new frame. - The |dirtyRects| argument to CefRenderHandler::OnPaint will now always be a single CefRect representing the whole view (frame) size. Previously, invalidated regions were listed separately. - Linux: CefBrowserHost::SendKeyEvent now expects X11 event information instead of GTK event information. See cefclient for an example of converting GTK events to the necessary format. - Sizes passed to the CefRenderHandler OnPaint and OnPopupSize methods are now already DPI scaled. Previously, the client had to perform DPI scaling. - Includes drag&drop implementation from issue #1032. - Includes unit test fixes from issue #1245. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1751 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
2014-07-01 00:30:29 +02:00
bool is_windowless_;
// Map of unique frame ids to CefFrameImpl references.
typedef std::map<int64, CefRefPtr<CefFrameImpl> > FrameMap;
FrameMap frames_;
// Map of unique frame ids to CefTrackManager objects that need to be cleaned
// up when the frame is deleted.
typedef std::map<int64, CefRefPtr<CefTrackManager> > FrameObjectMap;
FrameObjectMap frame_objects_;
// Manages response registrations.
std::unique_ptr<CefResponseManager> response_manager_;
IMPLEMENT_REFCOUNTING(CefBrowserImpl);
DISALLOW_COPY_AND_ASSIGN(CefBrowserImpl);
};
#endif // CEF_LIBCEF_RENDERER_BROWSER_IMPL_H_