Skip to content

Commit

Permalink
Move message routing from CefBrowser to CefFrame (see issue chromiume…
Browse files Browse the repository at this point in the history
…mbedded#2498).

This change moves the SendProcessMessage method from CefBrowser to CefFrame and
adds CefBrowser parameters to OnProcessMessageReceived and
OnDraggableRegionsChanged.

The internal implementation has changed as follows:
- Frame IDs are now a 64-bit combination of the 32-bit render_process_id and
  render_routing_id values that uniquely identify a RenderFrameHost (RFH).
- CefFrameHostImpl objects are now managed by CefBrowserInfo with life span tied
  to RFH expectations. Specifically, a CefFrameHostImpl object representing a
  sub-frame will be created when a RenderFrame is created in the renderer
  process and detached when the associated RenderFrame is deleted or the
  renderer process in which it runs has died.
- The CefFrameHostImpl object representing the main frame will always be valid
  but the underlying RFH (and associated frame ID) may change over time as a
  result of cross-origin navigations. Despite these changes calling LoadURL on
  the main frame object in the browser process will always navigate as expected.
- Speculative RFHs, which may be created as a result of a cross-origin
  navigation and discarded if that navigation is not committed, are now handled
  correctly (e.g. ignored in most cases until they're committed).
- It is less likely, but still possible, to receive a CefFrame object with an
  invalid frame ID (ID < 0). This can happen in cases where a RFH has not yet
  been created for a sub-frame. For example, when OnBeforeBrowse is called
  before initiating navigation in a previously nonexisting sub-frame.

To test: All tests pass with NetworkService enabled and disabled.
  • Loading branch information
magreenblatt committed May 29, 2019
1 parent 35295d2 commit 241941a
Show file tree
Hide file tree
Showing 80 changed files with 2,353 additions and 2,349 deletions.
2 changes: 2 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ static_library("libcef_static") {
"libcef/common/extensions/extensions_util.cc",
"libcef/common/extensions/extensions_util.h",
"libcef/common/file_util_impl.cc",
"libcef/common/frame_util.cc",
"libcef/common/frame_util.h",
"libcef/common/json_impl.cc",
"libcef/common/main_delegate.cc",
"libcef/common/main_delegate.h",
Expand Down
12 changes: 1 addition & 11 deletions include/capi/cef_browser_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=2385e0531c91a419fe7f4036b5a59da743b1622e$
// $hash=623d324a1ef5637353ae74761fdc04eac4d99716$
//

#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_CAPI_H_
Expand All @@ -45,7 +45,6 @@
#include "include/capi/cef_frame_capi.h"
#include "include/capi/cef_image_capi.h"
#include "include/capi/cef_navigation_entry_capi.h"
#include "include/capi/cef_process_message_capi.h"
#include "include/capi/cef_request_context_capi.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -179,15 +178,6 @@ typedef struct _cef_browser_t {
///
void(CEF_CALLBACK* get_frame_names)(struct _cef_browser_t* self,
cef_string_list_t names);

///
// Send a message to the specified |target_process|. Returns true (1) if the
// message was sent successfully.
///
int(CEF_CALLBACK* send_process_message)(
struct _cef_browser_t* self,
cef_process_id_t target_process,
struct _cef_process_message_t* message);
} cef_browser_t;

///
Expand Down
3 changes: 2 additions & 1 deletion include/capi/cef_client_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=485de431252b72e5516f3f7f16a8d6f416801dfd$
// $hash=c8b6ce6786bb8369c3d9bb9e932a115fb379b145$
//

#ifndef CEF_INCLUDE_CAPI_CEF_CLIENT_CAPI_H_
Expand Down Expand Up @@ -166,6 +166,7 @@ typedef struct _cef_client_t {
int(CEF_CALLBACK* on_process_message_received)(
struct _cef_client_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
cef_process_id_t source_process,
struct _cef_process_message_t* message);
} cef_client_t;
Expand Down
4 changes: 3 additions & 1 deletion include/capi/cef_drag_handler_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=22ebb1d811a4e0a834eb115859d797c72a5c4ca3$
// $hash=5c7eb1cee72dcb8b7657007b3f9db64680ea8c4d$
//

#ifndef CEF_INCLUDE_CAPI_CEF_DRAG_HANDLER_CAPI_H_
Expand All @@ -43,6 +43,7 @@
#include "include/capi/cef_base_capi.h"
#include "include/capi/cef_browser_capi.h"
#include "include/capi/cef_drag_data_capi.h"
#include "include/capi/cef_frame_capi.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -79,6 +80,7 @@ typedef struct _cef_drag_handler_t {
void(CEF_CALLBACK* on_draggable_regions_changed)(
struct _cef_drag_handler_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
size_t regionsCount,
cef_draggable_region_t const* regions);
} cef_drag_handler_t;
Expand Down
14 changes: 13 additions & 1 deletion include/capi/cef_frame_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=4e8384d7f289708b09f08be98c5477f2be3fde97$
// $hash=6bef924a259845dbf03e9cf5084ff7feb2771034$
//

#ifndef CEF_INCLUDE_CAPI_CEF_FRAME_CAPI_H_
Expand All @@ -42,6 +42,7 @@

#include "include/capi/cef_base_capi.h"
#include "include/capi/cef_dom_capi.h"
#include "include/capi/cef_process_message_capi.h"
#include "include/capi/cef_request_capi.h"
#include "include/capi/cef_stream_capi.h"
#include "include/capi/cef_string_visitor_capi.h"
Expand Down Expand Up @@ -244,6 +245,17 @@ typedef struct _cef_frame_t {
struct _cef_frame_t* self,
struct _cef_request_t* request,
struct _cef_urlrequest_client_t* client);

///
// Send a message to the specified |target_process|. Message delivery is not
// guaranteed in all cases (for example, if the browser is closing,
// navigating, or if the target process crashes). Send an ACK message back
// from the target process if confirmation is required.
///
void(CEF_CALLBACK* send_process_message)(
struct _cef_frame_t* self,
cef_process_id_t target_process,
struct _cef_process_message_t* message);
} cef_frame_t;

#ifdef __cplusplus
Expand Down
3 changes: 2 additions & 1 deletion include/capi/cef_render_process_handler_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=a3cf58db4b29d7395975ab8d63461b5ea8aad064$
// $hash=6c6efd722dda7480a5449ef31f1d6d9a16fd3465$
//

#ifndef CEF_INCLUDE_CAPI_CEF_RENDER_PROCESS_HANDLER_CAPI_H_
Expand Down Expand Up @@ -166,6 +166,7 @@ typedef struct _cef_render_process_handler_t {
int(CEF_CALLBACK* on_process_message_received)(
struct _cef_render_process_handler_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
cef_process_id_t source_process,
struct _cef_process_message_t* message);
} cef_render_process_handler_t;
Expand Down
10 changes: 5 additions & 5 deletions include/cef_api_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=2fc75812c34a605fb4e67a5942f6597c6dd3be78$
// $hash=0bc0d1faa22392b4245dc6eaf56337e7847a1900$
//

#ifndef CEF_INCLUDE_API_HASH_H_
Expand All @@ -47,13 +47,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "f9715e9bc13434498505eecee052706483eb7892"
#define CEF_API_HASH_UNIVERSAL "31b55dcbcf52e9f51fe423741f64e5c77e71c65a"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "7bd952f75673366dc4834de5e5995798d3db91f0"
#define CEF_API_HASH_PLATFORM "afb8ea794d1bb0f56ba5ce1718a16e5dfd64229e"
#elif defined(OS_MACOSX)
#define CEF_API_HASH_PLATFORM "daa91396f67341e7bde65747f69487ecde4e3cf5"
#define CEF_API_HASH_PLATFORM "e3a279cf087095495c08fd9fa88daef5dbafff3a"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "be8ed9d9ba0b53e18c5c0adae09ff841b1fa7063"
#define CEF_API_HASH_PLATFORM "d25833941c670d82cff0aa0ccf47b557d6813634"
#endif

#ifdef __cplusplus
Expand Down
9 changes: 0 additions & 9 deletions include/cef_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include "include/cef_frame.h"
#include "include/cef_image.h"
#include "include/cef_navigation_entry.h"
#include "include/cef_process_message.h"
#include "include/cef_request_context.h"

class CefBrowserHost;
Expand Down Expand Up @@ -181,14 +180,6 @@ class CefBrowser : public virtual CefBaseRefCounted {
///
/*--cef()--*/
virtual void GetFrameNames(std::vector<CefString>& names) = 0;

///
// Send a message to the specified |target_process|. Returns true if the
// message was sent successfully.
///
/*--cef()--*/
virtual bool SendProcessMessage(CefProcessId target_process,
CefRefPtr<CefProcessMessage> message) = 0;
};

///
Expand Down
1 change: 1 addition & 0 deletions include/cef_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class CefClient : public virtual CefBaseRefCounted {
///
/*--cef()--*/
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions include/cef_drag_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "include/cef_base.h"
#include "include/cef_browser.h"
#include "include/cef_drag_data.h"
#include "include/cef_frame.h"

///
// Implement this interface to handle events related to dragging. The methods of
Expand Down Expand Up @@ -74,6 +75,7 @@ class CefDragHandler : public virtual CefBaseRefCounted {
/*--cef()--*/
virtual void OnDraggableRegionsChanged(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::vector<CefDraggableRegion>& regions) {}
};

Expand Down
11 changes: 11 additions & 0 deletions include/cef_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "include/cef_base.h"
#include "include/cef_dom.h"
#include "include/cef_process_message.h"
#include "include/cef_request.h"
#include "include/cef_stream.h"
#include "include/cef_string_visitor.h"
Expand Down Expand Up @@ -248,6 +249,16 @@ class CefFrame : public virtual CefBaseRefCounted {
virtual CefRefPtr<CefURLRequest> CreateURLRequest(
CefRefPtr<CefRequest> request,
CefRefPtr<CefURLRequestClient> client) = 0;

///
// Send a message to the specified |target_process|. Message delivery is not
// guaranteed in all cases (for example, if the browser is closing,
// navigating, or if the target process crashes). Send an ACK message back
// from the target process if confirmation is required.
///
/*--cef()--*/
virtual void SendProcessMessage(CefProcessId target_process,
CefRefPtr<CefProcessMessage> message) = 0;
};

#endif // CEF_INCLUDE_CEF_FRAME_H_
1 change: 1 addition & 0 deletions include/cef_render_process_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class CefRenderProcessHandler : public virtual CefBaseRefCounted {
///
/*--cef()--*/
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions include/wrapper/cef_message_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class CefMessageRouterBrowserSide
///
virtual bool OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) = 0;

Expand Down Expand Up @@ -415,6 +416,7 @@ class CefMessageRouterRendererSide
///
virtual bool OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) = 0;

Expand Down
4 changes: 2 additions & 2 deletions libcef/browser/audio_mirror_destination.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void CefAudioMirrorDestination::QueryForMatchesOnUIThread(
std::set<content::GlobalFrameRoutingId> matches;
for (auto& candidate : candidates) {
CefRefPtr<CefBrowserHostImpl> browser =
CefBrowserHostImpl::GetBrowserForFrame(candidate.child_id,
candidate.frame_routing_id);
CefBrowserHostImpl::GetBrowserForFrameRoute(candidate.child_id,
candidate.frame_routing_id);
if (browser == browser_) {
matches.insert(candidate);
}
Expand Down
Loading

0 comments on commit 241941a

Please sign in to comment.