Reland "Ensure Virtual Keyboard extension has the functionality to load UI color dynamically."
There are two changes between the original and reland CL: 1. Keep `third_party/closure_compiler/externs/virtual_keyboard_private.js` updated since we introduce a new event onColorProviderChanged. 2. Fix the content security policy change by adding style-src 'unsafe-inline' chrome://theme. Futher explanation of the content security policy change: 1. To allow virtual keyboard loading external css files from `chrome/theme/colors.css`, we need to add `chrome://theme` here. 2. `style-src 'unsafe-inline'` is equivalent to `style-src-elem 'unsafe-inline'` and `style-src-attr 'unsafe-inline'`. We need both of them because: a) For `style-src-elem`, in long form handwriting library, we have some usecase which dynamically injects <style> tag from JS runtime. b) For `style-src-attr`, we have many other usecases which dynamically change the style attribute of DOM elements. The original CL does not consider usecase 2.a. That's the root cause of breaking handwriting mode in original CL. This reverts commitc6342d400c
. Reason for revert: Fix the content security policy, modify extern virtual_keyboard_private.js to keep it updated with private api definition and reland the CL Original change's description: > Revert "Ensure Virtual Keyboard extension has the functionality to load UI color dynamically." > > This reverts commitd81b7218c9
. > > Reason for revert: Breaks handwriting tast tests > > Original change's description: > > Ensure Virtual Keyboard extension has the functionality to load UI color dynamically. > > > > 1. Switch from DefaultColorProviderSource to AshColorProviderSource for Chrome Keyboard Web Contents. > > 2. Allow Virtual Keyboard load stylesheets from chrome://theme > > 3. Introduce a new event `onColorProviderChanged` in Virtual Keyboard Private API. > > > > Change-Id: I67443bea00b9f821ff779f1faff38fbc555d1256 > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3958460 > > Reviewed-by: Sean Kau <skau@chromium.org> > > Reviewed-by: John Palmer <jopalmer@chromium.org> > > Reviewed-by: Darren Shen <shend@chromium.org> > > Commit-Queue: Grey Wang <greywang@google.com> > > Reviewed-by: Istiaque Ahmed <lazyboy@chromium.org> > > Cr-Commit-Position: refs/heads/main@{#1068884} > > BUG=b/258738124 > > Change-Id: I575fb82e760df802f8b8cfd371d986f3eeb9cb9c > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4022327 > Quick-Run: Grey Wang <greywang@google.com> > Commit-Queue: Timothy Loh <timloh@chromium.org> > Owners-Override: Timothy Loh <timloh@chromium.org> > Reviewed-by: John Palmer <jopalmer@chromium.org> > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#1070182} Bug: b/258738124 Change-Id: Id6877ef613ec479a8f8a5bea92c7aa82fb66eaf3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4023316 Reviewed-by: Sean Kau <skau@chromium.org> Commit-Queue: Grey Wang <greywang@google.com> Reviewed-by: Istiaque Ahmed <lazyboy@chromium.org> Reviewed-by: John Palmer <jopalmer@chromium.org> Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org> Reviewed-by: Darren Shen <shend@chromium.org> Cr-Commit-Position: refs/heads/main@{#1071438}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
6e99b3c5bc
commit
bc0dae6f70
chrome/browser
resources
chromeos
input_method
ui
extensions
third_party/closure_compiler/externs
tools/metrics/histograms
@ -1699,5 +1699,5 @@
|
||||
}
|
||||
],
|
||||
"manifest_version": 2,
|
||||
"content_security_policy": "script-src 'self' 'wasm-eval'; object-src 'self'"
|
||||
"content_security_policy": "script-src 'self' 'wasm-eval'; object-src 'self'; style-src 'unsafe-inline' chrome://theme"
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "ash/keyboard/ui/resources/keyboard_resource_util.h"
|
||||
#include "ash/style/color_util.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/callback_helpers.h"
|
||||
#include "base/feature_list.h"
|
||||
@ -24,8 +25,10 @@
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/browser/web_contents_delegate.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "extensions/browser/event_router.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/view_type_utils.h"
|
||||
#include "extensions/common/api/virtual_keyboard_private.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "extensions/common/mojom/view_type.mojom.h"
|
||||
#include "third_party/blink/public/common/input/web_gesture_event.h"
|
||||
@ -151,6 +154,7 @@ ChromeKeyboardWebContents::ChromeKeyboardWebContents(
|
||||
web_contents_params.initially_hidden = true;
|
||||
web_contents_ = content::WebContents::Create(web_contents_params);
|
||||
web_contents_->SetDelegate(new ChromeKeyboardContentsDelegate());
|
||||
web_contents_->SetColorProviderSource(&color_provider_source_);
|
||||
|
||||
extensions::SetViewType(web_contents_.get(),
|
||||
extensions::mojom::ViewType::kComponent);
|
||||
@ -231,6 +235,32 @@ void ChromeKeyboardWebContents::DidStopLoading() {
|
||||
std::move(load_callback_).Run();
|
||||
}
|
||||
|
||||
void ChromeKeyboardWebContents::OnColorProviderChanged() {
|
||||
if (!web_contents_)
|
||||
return;
|
||||
|
||||
auto* browser_context = web_contents_->GetBrowserContext();
|
||||
|
||||
if (!browser_context)
|
||||
return;
|
||||
|
||||
auto* router = extensions::EventRouter::Get(browser_context);
|
||||
|
||||
if (!router ||
|
||||
!router->HasEventListener(extensions::api::virtual_keyboard_private::
|
||||
OnColorProviderChanged::kEventName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto event = std::make_unique<extensions::Event>(
|
||||
extensions::events::VIRTUAL_KEYBOARD_PRIVATE_ON_COLOR_PROVIDER_CHANGED,
|
||||
extensions::api::virtual_keyboard_private::OnColorProviderChanged::
|
||||
kEventName,
|
||||
base::Value::List(), browser_context);
|
||||
|
||||
router->BroadcastEvent(std::move(event));
|
||||
}
|
||||
|
||||
void ChromeKeyboardWebContents::LoadContents(const GURL& url) {
|
||||
TRACE_EVENT0("vk", "LoadContents");
|
||||
content::OpenURLParams params(url, content::Referrer(),
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ash/style/ash_color_provider_source.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
@ -64,6 +65,7 @@ class ChromeKeyboardWebContents : public content::WebContentsObserver,
|
||||
// content::WebContentsObserver overrides
|
||||
void RenderFrameCreated(content::RenderFrameHost* frame_host) override;
|
||||
void DidStopLoading() override;
|
||||
void OnColorProviderChanged() override;
|
||||
|
||||
// Loads the web contents for the given |url|.
|
||||
void LoadContents(const GURL& url);
|
||||
@ -74,6 +76,8 @@ class ChromeKeyboardWebContents : public content::WebContentsObserver,
|
||||
const gfx::Rect& new_bounds,
|
||||
ui::PropertyChangeReason reason) override;
|
||||
|
||||
ash::AshColorProviderSource color_provider_source_;
|
||||
|
||||
std::unique_ptr<content::WebContents> web_contents_;
|
||||
std::unique_ptr<ChromeKeyboardBoundsObserver> window_bounds_observer_;
|
||||
|
||||
|
@ -518,6 +518,7 @@ enum HistogramValue {
|
||||
INPUT_METHOD_PRIVATE_ON_CARET_BOUNDS_CHANGED = 496,
|
||||
PASSWORDS_PRIVATE_ON_PASSWORD_MANAGER_AUTH_TIMEOUT = 497,
|
||||
PASSWORDS_PRIVATE_ON_INSECURE_CREDENTIALS_CHANGED = 498,
|
||||
VIRTUAL_KEYBOARD_PRIVATE_ON_COLOR_PROVIDER_CHANGED = 499,
|
||||
// Last entry: Add new entries above, then run:
|
||||
// tools/metrics/histograms/update_extension_histograms.py
|
||||
ENUM_BOUNDARY
|
||||
|
@ -456,6 +456,11 @@
|
||||
"$ref": "ClipboardItem"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "onColorProviderChanged",
|
||||
"type": "function",
|
||||
"description": "Fired when the color provider of virtual keyboard window has changed."
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -271,3 +271,9 @@ chrome.virtualKeyboardPrivate.onClipboardHistoryChanged;
|
||||
* @type {!ChromeEvent}
|
||||
*/
|
||||
chrome.virtualKeyboardPrivate.onClipboardItemUpdated;
|
||||
|
||||
/**
|
||||
* Fired when the color provider of virtual keyboard window has changed.
|
||||
* @type {!ChromeEvent}
|
||||
*/
|
||||
chrome.virtualKeyboardPrivate.onColorProviderChanged;
|
||||
|
@ -34778,6 +34778,7 @@ Called by update_extension_histograms.py.-->
|
||||
<int value="496" label="INPUT_METHOD_PRIVATE_ON_CARET_BOUNDS_CHANGED"/>
|
||||
<int value="497" label="PASSWORDS_PRIVATE_ON_PASSWORD_MANAGER_AUTH_TIMEOUT"/>
|
||||
<int value="498" label="PASSWORDS_PRIVATE_ON_INSECURE_CREDENTIALS_CHANGED"/>
|
||||
<int value="499" label="VIRTUAL_KEYBOARD_PRIVATE_ON_COLOR_PROVIDER_CHANGED"/>
|
||||
</enum>
|
||||
|
||||
<enum name="ExtensionFileWriteResult">
|
||||
|
Reference in New Issue
Block a user