Bug 1266683 - Part 2 - Add private browsing mode info to InputContext. r=masayuki
Android now supports telling an IME that it shouldn't store user-entered content into it's dictionary/language model/etc. and we want to automatically enable this in private browsing. As the code that handles input on Android doesn't have any notion of tabs (and therefore of the difference between normal and private tabs), the best way to get that info across is to retrieve it directly within the IMEStateManager from the corresponding document and store it in the inputContext, which is then passed to Java for Fennec to handle. Implementing this within Gecko also has the benefit that this part of the code can be used by other platforms as well should they want to support similar features in the future. MozReview-Commit-ID: DsxjC4Ma7DR
This commit is contained in:
@@ -347,7 +347,7 @@ IMEStateManager::OnDestroyPresContext(nsPresContext* aPresContext)
|
||||
InputContextAction::LOST_FOCUS);
|
||||
InputContext::Origin origin =
|
||||
sActiveTabParent ? InputContext::ORIGIN_CONTENT : sOrigin;
|
||||
SetIMEState(newState, nullptr, sWidget, action, origin);
|
||||
SetIMEState(newState, nullptr, nullptr, sWidget, action, origin);
|
||||
}
|
||||
sWidget = nullptr;
|
||||
sContent = nullptr;
|
||||
@@ -404,7 +404,7 @@ IMEStateManager::OnRemoveContent(nsPresContext* aPresContext,
|
||||
InputContextAction::LOST_FOCUS);
|
||||
InputContext::Origin origin =
|
||||
sActiveTabParent ? InputContext::ORIGIN_CONTENT : sOrigin;
|
||||
SetIMEState(newState, nullptr, sWidget, action, origin);
|
||||
SetIMEState(newState, aPresContext, nullptr, sWidget, action, origin);
|
||||
}
|
||||
|
||||
sWidget = nullptr;
|
||||
@@ -634,7 +634,7 @@ IMEStateManager::OnChangeFocusInternal(nsPresContext* aPresContext,
|
||||
}
|
||||
|
||||
// Update IME state for new focus widget
|
||||
SetIMEState(newState, aContent, newWidget, aAction,
|
||||
SetIMEState(newState, aPresContext, aContent, newWidget, aAction,
|
||||
newTabParent ? InputContext::ORIGIN_CONTENT : sOrigin);
|
||||
}
|
||||
|
||||
@@ -786,7 +786,7 @@ IMEStateManager::OnClickInEditor(nsPresContext* aPresContext,
|
||||
|
||||
InputContextAction action(cause, InputContextAction::FOCUS_NOT_CHANGED);
|
||||
IMEState newState = GetNewIMEState(aPresContext, aContent);
|
||||
SetIMEState(newState, aContent, widget, action, sOrigin);
|
||||
SetIMEState(newState, aPresContext, aContent, widget, action, sOrigin);
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -1003,7 +1003,7 @@ IMEStateManager::UpdateIMEState(const IMEState& aNewIMEState,
|
||||
if (updateIMEState) {
|
||||
InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
|
||||
InputContextAction::FOCUS_NOT_CHANGED);
|
||||
SetIMEState(aNewIMEState, aContent, widget, action, sOrigin);
|
||||
SetIMEState(aNewIMEState, presContext, aContent, widget, action, sOrigin);
|
||||
if (NS_WARN_IF(widget->Destroyed())) {
|
||||
MOZ_LOG(sISMLog, LogLevel::Error,
|
||||
(" UpdateIMEState(), widget has gone during setting input context"));
|
||||
@@ -1113,8 +1113,8 @@ IMEStateManager::SetInputContextForChildProcess(
|
||||
MOZ_LOG(sISMLog, LogLevel::Info,
|
||||
("SetInputContextForChildProcess(aTabParent=0x%p, "
|
||||
"aInputContext={ mIMEState={ mEnabled=%s, mOpen=%s }, "
|
||||
"mHTMLInputType=\"%s\", mHTMLInputInputmode=\"%s\", mActionHint=\"%s\" }, "
|
||||
"aAction={ mCause=%s, mAction=%s }), "
|
||||
"mHTMLInputType=\"%s\", mHTMLInputInputmode=\"%s\", mActionHint=\"%s\", "
|
||||
"mInPrivateBrowsing=%s }, aAction={ mCause=%s, mAction=%s }), "
|
||||
"sPresContext=0x%p (available: %s), sWidget=0x%p (available: %s), "
|
||||
"sActiveTabParent=0x%p",
|
||||
aTabParent, GetIMEStateEnabledName(aInputContext.mIMEState.mEnabled),
|
||||
@@ -1122,6 +1122,7 @@ IMEStateManager::SetInputContextForChildProcess(
|
||||
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputType).get(),
|
||||
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputInputmode).get(),
|
||||
NS_ConvertUTF16toUTF8(aInputContext.mActionHint).get(),
|
||||
GetBoolName(aInputContext.mInPrivateBrowsing),
|
||||
GetActionCauseName(aAction.mCause),
|
||||
GetActionFocusChangeName(aAction.mFocusChange),
|
||||
sPresContext.get(), GetBoolName(CanHandleWith(sPresContext)),
|
||||
@@ -1161,6 +1162,7 @@ IMEStateManager::SetInputContextForChildProcess(
|
||||
// static
|
||||
void
|
||||
IMEStateManager::SetIMEState(const IMEState& aState,
|
||||
nsPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIWidget* aWidget,
|
||||
InputContextAction aAction,
|
||||
@@ -1185,6 +1187,10 @@ IMEStateManager::SetIMEState(const IMEState& aState,
|
||||
context.mMayBeIMEUnaware = context.mIMEState.IsEditable() &&
|
||||
sCheckForIMEUnawareWebApps && MayBeIMEUnawareWebApp(aContent);
|
||||
|
||||
context.mInPrivateBrowsing =
|
||||
aPresContext &&
|
||||
nsContentUtils::IsInPrivateBrowsing(aPresContext->Document());
|
||||
|
||||
if (aContent &&
|
||||
aContent->IsAnyOfHTMLElements(nsGkAtoms::input, nsGkAtoms::textarea)) {
|
||||
if (!aContent->IsHTMLElement(nsGkAtoms::textarea)) {
|
||||
@@ -1269,7 +1275,8 @@ IMEStateManager::SetInputContext(nsIWidget* aWidget,
|
||||
MOZ_LOG(sISMLog, LogLevel::Info,
|
||||
("SetInputContext(aWidget=0x%p, aInputContext={ "
|
||||
"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",
|
||||
aWidget,
|
||||
GetIMEStateEnabledName(aInputContext.mIMEState.mEnabled),
|
||||
@@ -1277,6 +1284,7 @@ IMEStateManager::SetInputContext(nsIWidget* aWidget,
|
||||
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputType).get(),
|
||||
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputInputmode).get(),
|
||||
NS_ConvertUTF16toUTF8(aInputContext.mActionHint).get(),
|
||||
GetBoolName(aInputContext.mInPrivateBrowsing),
|
||||
GetActionCauseName(aAction.mCause),
|
||||
GetActionFocusChangeName(aAction.mFocusChange),
|
||||
sActiveTabParent.get()));
|
||||
|
||||
@@ -260,6 +260,7 @@ protected:
|
||||
nsIContent* aContent,
|
||||
InputContextAction aAction);
|
||||
static void SetIMEState(const IMEState &aState,
|
||||
nsPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIWidget* aWidget,
|
||||
InputContextAction aAction,
|
||||
|
||||
@@ -354,6 +354,7 @@ parent:
|
||||
nsString type,
|
||||
nsString inputmode,
|
||||
nsString actionHint,
|
||||
bool inPrivateBrowsing,
|
||||
int32_t cause,
|
||||
int32_t focusChange);
|
||||
|
||||
|
||||
@@ -2339,6 +2339,7 @@ TabParent::RecvSetInputContext(const int32_t& aIMEEnabled,
|
||||
const nsString& aType,
|
||||
const nsString& aInputmode,
|
||||
const nsString& aActionHint,
|
||||
const bool& aInPrivateBrowsing,
|
||||
const int32_t& aCause,
|
||||
const int32_t& aFocusChange)
|
||||
{
|
||||
@@ -2349,6 +2350,7 @@ TabParent::RecvSetInputContext(const int32_t& aIMEEnabled,
|
||||
context.mHTMLInputInputmode.Assign(aInputmode);
|
||||
context.mActionHint.Assign(aActionHint);
|
||||
context.mOrigin = InputContext::ORIGIN_CONTENT;
|
||||
context.mInPrivateBrowsing = aInPrivateBrowsing;
|
||||
|
||||
InputContextAction action(
|
||||
static_cast<InputContextAction::Cause>(aCause),
|
||||
|
||||
@@ -250,6 +250,7 @@ public:
|
||||
const nsString& aType,
|
||||
const nsString& aInputmode,
|
||||
const nsString& aActionHint,
|
||||
const bool& aInPrivateBrowsing,
|
||||
const int32_t& aCause,
|
||||
const int32_t& aFocusChange) override;
|
||||
|
||||
|
||||
@@ -271,6 +271,7 @@ struct InputContext final
|
||||
InputContext()
|
||||
: mOrigin(XRE_IsParentProcess() ? ORIGIN_MAIN : ORIGIN_CONTENT)
|
||||
, mMayBeIMEUnaware(false)
|
||||
, mInPrivateBrowsing(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -308,6 +309,10 @@ struct InputContext final
|
||||
* compatibility with webapps relying on key listeners. */
|
||||
bool mMayBeIMEUnaware;
|
||||
|
||||
/* Whether the owning document of the input element has been loaded
|
||||
* in private browsing mode. */
|
||||
bool mInPrivateBrowsing;
|
||||
|
||||
bool IsOriginMainProcess() const
|
||||
{
|
||||
return mOrigin == ORIGIN_MAIN;
|
||||
|
||||
@@ -738,6 +738,7 @@ PuppetWidget::SetInputContext(const InputContext& aContext,
|
||||
aContext.mHTMLInputType,
|
||||
aContext.mHTMLInputInputmode,
|
||||
aContext.mActionHint,
|
||||
aContext.mInPrivateBrowsing,
|
||||
static_cast<int32_t>(aAction.mCause),
|
||||
static_cast<int32_t>(aAction.mFocusChange));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user