1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "auto_fill_extension_context.h" 17 18 #include "hilog_tag_wrapper.h" 19 #include "js_auto_fill_extension_util.h" 20 21 namespace OHOS { 22 namespace AbilityRuntime { 23 const size_t AutoFillExtensionContext::CONTEXT_TYPE_ID(std::hash<const char*> {} ("AutoFillExtensionContext")); 24 SetAutoFillExtensionCallback(const std::weak_ptr<IAutoFillExtensionCallback> & autoFillExtensionCallback)25void AutoFillExtensionContext::SetAutoFillExtensionCallback( 26 const std::weak_ptr<IAutoFillExtensionCallback> &autoFillExtensionCallback) 27 { 28 autoFillExtensionCallback_ = autoFillExtensionCallback; 29 } 30 SetSessionInfo(const sptr<AAFwk::SessionInfo> & sessionInfo)31void AutoFillExtensionContext::SetSessionInfo(const sptr<AAFwk::SessionInfo> &sessionInfo) 32 { 33 sessionInfo_ = sessionInfo; 34 } 35 ReloadInModal(const CustomData & customData)36int32_t AutoFillExtensionContext::ReloadInModal(const CustomData &customData) 37 { 38 TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "called"); 39 if (sessionInfo_ == nullptr) { 40 TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "null sessionInfo_"); 41 return ERR_NULL_OBJECT; 42 } 43 auto autoFillExtensionCallback = autoFillExtensionCallback_.lock(); 44 if (autoFillExtensionCallback == nullptr) { 45 TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "null autoFillExtensionCallback"); 46 return ERR_NULL_OBJECT; 47 } 48 return autoFillExtensionCallback->OnReloadInModal(sessionInfo_, customData); 49 } 50 IsContext(size_t contextTypeId)51bool AutoFillExtensionContext::IsContext(size_t contextTypeId) 52 { 53 return contextTypeId == CONTEXT_TYPE_ID || UIExtensionContext::IsContext(contextTypeId); 54 } 55 } // namespace AbilityRuntime 56 } // namespace OHOS 57