Issue #1348 - Part 2: Teach IMEState about Private Browsing mode.

This commit is contained in:
wolfbeast 2020-01-09 13:19:56 +01:00 • committed by Roy Tam
commit 9d2e51ac97
3 changed files with 21 additions and 8 deletions

View file

@ -297,7 +297,7 @@ IMEStateManager::OnDestroyPresContext(nsPresContext* aPresContext)
IMEState newState = GetNewIMEState(sPresContext, nullptr); IMEState newState = GetNewIMEState(sPresContext, nullptr);
InputContextAction action(InputContextAction::CAUSE_UNKNOWN, InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
InputContextAction::LOST_FOCUS); InputContextAction::LOST_FOCUS);
SetIMEState(newState, nullptr, sWidget, action); SetIMEState(newState, nullptr, nullptr, sWidget, action);
} }
sWidget = nullptr; sWidget = nullptr;
sContent = nullptr; sContent = nullptr;
@ -352,7 +352,7 @@ IMEStateManager::OnRemoveContent(nsPresContext* aPresContext,
IMEState newState = GetNewIMEState(sPresContext, nullptr); IMEState newState = GetNewIMEState(sPresContext, nullptr);
InputContextAction action(InputContextAction::CAUSE_UNKNOWN, InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
InputContextAction::LOST_FOCUS); InputContextAction::LOST_FOCUS);
SetIMEState(newState, nullptr, sWidget, action); SetIMEState(newState, aPresContext, nullptr, sWidget, action);
} }
sWidget = nullptr; sWidget = nullptr;
@ -542,7 +542,7 @@ IMEStateManager::OnChangeFocusInternal(nsPresContext* aPresContext,
} }
// Update IME state for new focus widget // Update IME state for new focus widget
SetIMEState(newState, aContent, newWidget, aAction); SetIMEState(newState, aPresContext, aContent, newWidget, aAction);
} }
sActiveTabParent = newTabParent; sActiveTabParent = newTabParent;
@ -704,7 +704,7 @@ IMEStateManager::OnClickInEditor(nsPresContext* aPresContext,
InputContextAction action(cause, InputContextAction::FOCUS_NOT_CHANGED); InputContextAction action(cause, InputContextAction::FOCUS_NOT_CHANGED);
IMEState newState = GetNewIMEState(aPresContext, aContent); IMEState newState = GetNewIMEState(aPresContext, aContent);
SetIMEState(newState, aContent, widget, action); SetIMEState(newState, aPresContext, aContent, widget, action);
} }
// static // static
@ -912,7 +912,7 @@ IMEStateManager::UpdateIMEState(const IMEState& aNewIMEState,
if (updateIMEState) { if (updateIMEState) {
InputContextAction action(InputContextAction::CAUSE_UNKNOWN, InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
InputContextAction::FOCUS_NOT_CHANGED); InputContextAction::FOCUS_NOT_CHANGED);
SetIMEState(aNewIMEState, aContent, widget, action); SetIMEState(aNewIMEState, sPresContext, aContent, widget, action);
if (NS_WARN_IF(widget->Destroyed())) { if (NS_WARN_IF(widget->Destroyed())) {
MOZ_LOG(sISMLog, LogLevel::Error, MOZ_LOG(sISMLog, LogLevel::Error,
(" UpdateIMEState(), widget has gone during setting input context")); (" UpdateIMEState(), widget has gone during setting input context"));
@ -1022,8 +1022,8 @@ IMEStateManager::SetInputContextForChildProcess(
MOZ_LOG(sISMLog, LogLevel::Info, MOZ_LOG(sISMLog, LogLevel::Info,
("SetInputContextForChildProcess(aTabParent=0x%p, " ("SetInputContextForChildProcess(aTabParent=0x%p, "
"aInputContext={ mIMEState={ mEnabled=%s, mOpen=%s }, " "aInputContext={ mIMEState={ mEnabled=%s, mOpen=%s }, "
"mHTMLInputType=\"%s\", mHTMLInputInputmode=\"%s\", mActionHint=\"%s\" }, " "mHTMLInputType=\"%s\", mHTMLInputInputmode=\"%s\", mActionHint=\"%s\", "
"aAction={ mCause=%s, mAction=%s }), " "mInPrivateBrowsing=%s }, aAction={ mCause=%s, mAction=%s }), "
"sPresContext=0x%p (available: %s), sWidget=0x%p (available: %s), " "sPresContext=0x%p (available: %s), sWidget=0x%p (available: %s), "
"sActiveTabParent=0x%p", "sActiveTabParent=0x%p",
aTabParent, GetIMEStateEnabledName(aInputContext.mIMEState.mEnabled), aTabParent, GetIMEStateEnabledName(aInputContext.mIMEState.mEnabled),
@ -1031,6 +1031,7 @@ IMEStateManager::SetInputContextForChildProcess(
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputType).get(), NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputType).get(),
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputInputmode).get(), NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputInputmode).get(),
NS_ConvertUTF16toUTF8(aInputContext.mActionHint).get(), NS_ConvertUTF16toUTF8(aInputContext.mActionHint).get(),
GetBoolName(aInputContext.mInPrivateBrowsing),
GetActionCauseName(aAction.mCause), GetActionCauseName(aAction.mCause),
GetActionFocusChangeName(aAction.mFocusChange), GetActionFocusChangeName(aAction.mFocusChange),
sPresContext.get(), GetBoolName(CanHandleWith(sPresContext)), sPresContext.get(), GetBoolName(CanHandleWith(sPresContext)),
@ -1070,6 +1071,7 @@ IMEStateManager::SetInputContextForChildProcess(
// static // static
void void
IMEStateManager::SetIMEState(const IMEState& aState, IMEStateManager::SetIMEState(const IMEState& aState,
nsPresContext* aPresContext,
nsIContent* aContent, nsIContent* aContent,
nsIWidget* aWidget, nsIWidget* aWidget,
InputContextAction aAction) InputContextAction aAction)
@ -1091,6 +1093,10 @@ IMEStateManager::SetIMEState(const IMEState& aState,
context.mMayBeIMEUnaware = context.mIMEState.IsEditable() && context.mMayBeIMEUnaware = context.mIMEState.IsEditable() &&
sCheckForIMEUnawareWebApps && MayBeIMEUnawareWebApp(aContent); sCheckForIMEUnawareWebApps && MayBeIMEUnawareWebApp(aContent);
context.mInPrivateBrowsing =
aPresContext &&
nsContentUtils::IsInPrivateBrowsing(aPresContext->Document());
if (aContent && if (aContent &&
aContent->IsAnyOfHTMLElements(nsGkAtoms::input, nsGkAtoms::textarea)) { aContent->IsAnyOfHTMLElements(nsGkAtoms::input, nsGkAtoms::textarea)) {
if (!aContent->IsHTMLElement(nsGkAtoms::textarea)) { if (!aContent->IsHTMLElement(nsGkAtoms::textarea)) {
@ -1175,7 +1181,8 @@ IMEStateManager::SetInputContext(nsIWidget* aWidget,
MOZ_LOG(sISMLog, LogLevel::Info, MOZ_LOG(sISMLog, LogLevel::Info,
("SetInputContext(aWidget=0x%p, aInputContext={ " ("SetInputContext(aWidget=0x%p, aInputContext={ "
"mIMEState={ mEnabled=%s, mOpen=%s }, mHTMLInputType=\"%s\", " "mIMEState={ mEnabled=%s, mOpen=%s }, mHTMLInputType=\"%s\", "
"mHTMLInputInputmode=\"%s\", mActionHint=\"%s\" }, " "mHTMLInputInputmode=\"%s\", mActionHint=\"%s\", "
"mInPrivateBrowsing=%s }, "
"aAction={ mCause=%s, mAction=%s }), sActiveTabParent=0x%p", "aAction={ mCause=%s, mAction=%s }), sActiveTabParent=0x%p",
aWidget, aWidget,
GetIMEStateEnabledName(aInputContext.mIMEState.mEnabled), GetIMEStateEnabledName(aInputContext.mIMEState.mEnabled),
@ -1183,6 +1190,7 @@ IMEStateManager::SetInputContext(nsIWidget* aWidget,
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputType).get(), NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputType).get(),
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputInputmode).get(), NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputInputmode).get(),
NS_ConvertUTF16toUTF8(aInputContext.mActionHint).get(), NS_ConvertUTF16toUTF8(aInputContext.mActionHint).get(),
GetBoolName(aInputContext.mInPrivateBrowsing),
GetActionCauseName(aAction.mCause), GetActionCauseName(aAction.mCause),
GetActionFocusChangeName(aAction.mFocusChange), GetActionFocusChangeName(aAction.mFocusChange),
sActiveTabParent.get())); sActiveTabParent.get()));

View file

@ -247,6 +247,7 @@ protected:
nsIContent* aContent, nsIContent* aContent,
InputContextAction aAction); InputContextAction aAction);
static void SetIMEState(const IMEState &aState, static void SetIMEState(const IMEState &aState,
nsPresContext* aPresContext,
nsIContent* aContent, nsIContent* aContent,
nsIWidget* aWidget, nsIWidget* aWidget,
InputContextAction aAction); InputContextAction aAction);

View file

@ -300,6 +300,10 @@ struct InputContext final
* compatibility with webapps relying on key listeners. */ * compatibility with webapps relying on key listeners. */
bool mMayBeIMEUnaware; bool mMayBeIMEUnaware;
/* Whether the owning document of the input element has been loaded
* in private browsing mode. */
bool mInPrivateBrowsing;
bool IsOriginMainProcess() const bool IsOriginMainProcess() const
{ {
return mOrigin == ORIGIN_MAIN; return mOrigin == ORIGIN_MAIN;