From 11b20155357740a5f7e0e912e066865bae624448 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 22 Dec 2015 17:16:00 -0500 Subject: [PATCH] Add did-change-theme-color event to webview --- atom/browser/api/atom_api_web_contents.cc | 10 ++++++++++ atom/browser/api/atom_api_web_contents.h | 1 + atom/browser/lib/guest-view-manager.coffee | 1 + .../lib/web-view/guest-view-internal.coffee | 1 + docs/api/web-contents.md | 8 -------- docs/api/web-view-tag.md | 14 ++++++++++++++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 037663db475..05c2683b260 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -489,6 +489,16 @@ void WebContents::MediaPaused() { Emit("media-paused"); } +void WebContents::DidChangeThemeColor(SkColor theme_color) { + char themeColor[8] = { 0 }; + snprintf(themeColor, sizeof(themeColor), + "#%02X%02X%02X", + SkColorGetR(theme_color), + SkColorGetG(theme_color), + SkColorGetB(theme_color)); + Emit("did-change-theme-color", themeColor); +} + void WebContents::DocumentLoadedInFrame( content::RenderFrameHost* render_frame_host) { if (!render_frame_host->GetParent()) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 0c7f129bd2c..52a244eb896 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -235,6 +235,7 @@ class WebContents : public mate::TrackableObject, base::ProcessId plugin_pid) override; void MediaStartedPlaying() override; void MediaPaused() override; + void DidChangeThemeColor(SkColor theme_color) override; // brightray::InspectableWebContentsViewDelegate: void DevToolsFocused() override; diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index 17308f4ce12..b0ba82eef3c 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -26,6 +26,7 @@ supportedWebViewEvents = [ 'media-started-playing' 'media-paused' 'found-in-page' + 'did-change-theme-color' ] nextInstanceId = 0 diff --git a/atom/renderer/lib/web-view/guest-view-internal.coffee b/atom/renderer/lib/web-view/guest-view-internal.coffee index 9178b3273dd..55e0c49a1aa 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.coffee +++ b/atom/renderer/lib/web-view/guest-view-internal.coffee @@ -22,6 +22,7 @@ WEB_VIEW_EVENTS = 'plugin-crashed': ['name', 'version'] 'media-started-playing': [] 'media-paused': [] + 'did-change-theme-color': ['themeColor'] 'destroyed': [] 'page-title-updated': ['title', 'explicitSet'] 'page-favicon-updated': ['favicons'] diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index f856b9229c1..7e41b02ae66 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -221,14 +221,6 @@ Emitted when `webContents` wants to do basic auth. The usage is the same with [the `login` event of `app`](app.md#event-login). -### Event: 'media-started-playing' - -Emitted when media starts playing. - -### Event: 'media-paused' - -Emitted when media is paused or done playing. - ### Event: 'found-in-page' Returns: diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index ea99358290b..0eda4882463 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -634,3 +634,17 @@ Fired when a plugin process is crashed. ### Event: 'destroyed' Fired when the WebContents is destroyed. + +### Event: 'media-started-playing' + +Emitted when media starts playing. + +### Event: 'media-paused' + +Emitted when media is paused or done playing. + +### Event: 'did-change-theme-color' + +Emitted when a page's theme color changes. This is usually due to encountering a meta tag: + +