feat: expose frame & move properties to console-message event object (#43617)
* feat: expose frame on console-message event refactor: use property names similar to ServiceWorker's console-message event refactor: don't use deprecated params in tests doc: console-message breaking change chore: add deprecation warning docs: restore deprecated argument descriptions * move console-message deprecations to v34 --------- Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
35aeab6ecd
commit
87bd665e41
13 changed files with 140 additions and 65 deletions
|
@ -1068,14 +1068,31 @@ void WebContents::Close(std::optional<gin_helper::Dictionary> options) {
|
|||
}
|
||||
}
|
||||
|
||||
bool WebContents::DidAddMessageToConsole(
|
||||
content::WebContents* source,
|
||||
void WebContents::OnDidAddMessageToConsole(
|
||||
content::RenderFrameHost* source_frame,
|
||||
blink::mojom::ConsoleMessageLevel level,
|
||||
const std::u16string& message,
|
||||
int32_t line_no,
|
||||
const std::u16string& source_id) {
|
||||
return Emit("console-message", static_cast<int32_t>(level), message, line_no,
|
||||
source_id);
|
||||
const std::u16string& source_id,
|
||||
const std::optional<std::u16string>& untrusted_stack_trace) {
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
gin::Handle<gin_helper::internal::Event> event =
|
||||
gin_helper::internal::Event::New(isolate);
|
||||
v8::Local<v8::Object> event_object = event.ToV8().As<v8::Object>();
|
||||
|
||||
gin_helper::Dictionary dict(isolate, event_object);
|
||||
dict.SetGetter("frame", source_frame);
|
||||
dict.Set("level", level);
|
||||
dict.Set("message", message);
|
||||
dict.Set("lineNumber", line_no);
|
||||
dict.Set("sourceId", source_id);
|
||||
|
||||
// TODO(samuelmaddock): Delete when deprecated arguments are fully removed.
|
||||
dict.Set("_level", static_cast<int32_t>(level));
|
||||
|
||||
EmitWithoutEvent("-console-message", event);
|
||||
}
|
||||
|
||||
void WebContents::OnCreateWindow(
|
||||
|
|
|
@ -530,11 +530,6 @@ class WebContents final : public ExclusiveAccessContext,
|
|||
#endif
|
||||
|
||||
// content::WebContentsDelegate:
|
||||
bool DidAddMessageToConsole(content::WebContents* source,
|
||||
blink::mojom::ConsoleMessageLevel level,
|
||||
const std::u16string& message,
|
||||
int32_t line_no,
|
||||
const std::u16string& source_id) override;
|
||||
bool IsWebContentsCreationOverridden(
|
||||
content::SiteInstance* source_site_instance,
|
||||
content::mojom::WindowContainerType window_container_type,
|
||||
|
@ -680,6 +675,13 @@ class WebContents final : public ExclusiveAccessContext,
|
|||
content::RenderWidgetHost* render_widget_host) override;
|
||||
void OnWebContentsLostFocus(
|
||||
content::RenderWidgetHost* render_widget_host) override;
|
||||
void OnDidAddMessageToConsole(
|
||||
content::RenderFrameHost* source_frame,
|
||||
blink::mojom::ConsoleMessageLevel level,
|
||||
const std::u16string& message,
|
||||
int32_t line_no,
|
||||
const std::u16string& source_id,
|
||||
const std::optional<std::u16string>& untrusted_stack_trace) override;
|
||||
|
||||
// InspectableWebContentsDelegate:
|
||||
void DevToolsReloadPage() override;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "third_party/blink/public/common/input/web_mouse_event.h"
|
||||
#include "third_party/blink/public/common/input/web_mouse_wheel_event.h"
|
||||
#include "third_party/blink/public/common/widget/device_emulation_params.h"
|
||||
#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
|
||||
#include "third_party/blink/public/mojom/loader/referrer.mojom.h"
|
||||
#include "ui/base/clipboard/clipboard.h"
|
||||
#include "ui/events/blink/blink_event_util.h"
|
||||
|
@ -699,4 +700,18 @@ bool Converter<blink::CloneableMessage>::FromV8(v8::Isolate* isolate,
|
|||
return electron::SerializeV8Value(isolate, val, out);
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<blink::mojom::ConsoleMessageLevel>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const blink::mojom::ConsoleMessageLevel& in) {
|
||||
using Val = blink::mojom::ConsoleMessageLevel;
|
||||
static constexpr auto Lookup = base::MakeFixedFlatMap<Val, std::string_view>({
|
||||
{Val::kVerbose, "debug"},
|
||||
{Val::kInfo, "info"},
|
||||
{Val::kWarning, "warning"},
|
||||
{Val::kError, "error"},
|
||||
});
|
||||
return StringToV8(isolate, Lookup.at(in));
|
||||
}
|
||||
|
||||
} // namespace gin
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "third_party/blink/public/common/input/web_input_event.h"
|
||||
#include "third_party/blink/public/common/messaging/cloneable_message.h"
|
||||
#include "third_party/blink/public/common/web_cache/web_cache_resource_type_stats.h"
|
||||
#include "third_party/blink/public/mojom/devtools/console_message.mojom-forward.h"
|
||||
#include "third_party/blink/public/mojom/loader/referrer.mojom-forward.h"
|
||||
|
||||
namespace blink {
|
||||
|
@ -126,6 +127,12 @@ struct Converter<blink::CloneableMessage> {
|
|||
blink::CloneableMessage* out);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<blink::mojom::ConsoleMessageLevel> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const blink::mojom::ConsoleMessageLevel& in);
|
||||
};
|
||||
|
||||
v8::Local<v8::Value> EditFlagsToV8(v8::Isolate* isolate, int editFlags);
|
||||
v8::Local<v8::Value> MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue