1 /*
2  * Copyright (c) 2023 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 "agent/page_impl.h"
17 
18 #include "base/pt_events.h"
19 #include "protocol_channel.h"
20 
21 namespace panda::ecmascript::tooling {
Dispatch(const DispatchRequest &request)22 void PageImpl::DispatcherImpl::Dispatch(const DispatchRequest &request)
23 {
24     Method method = GetMethodEnum(request.GetMethod());
25     LOG_DEBUGGER(INFO) << "dispatch [" << request.GetMethod() << "] to PageImpl";
26     switch (method) {
27         case Method::GET_NAVIGATION_HISTORY:
28             GetNavigationHistory(request);
29             break;
30         default:
31             SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod()));
32             break;
33     }
34 }
35 
GetMethodEnum(const std::string& method)36 PageImpl::DispatcherImpl::Method PageImpl::DispatcherImpl::GetMethodEnum(const std::string& method)
37 {
38     if (method == "getNavigationHistory") {
39         return Method::GET_NAVIGATION_HISTORY;
40     } else {
41         return Method::UNKNOWN;
42     }
43 }
44 
GetNavigationHistory(const DispatchRequest &request)45 void PageImpl::DispatcherImpl::GetNavigationHistory(const DispatchRequest &request)
46 {
47     DispatchResponse response = DispatchResponse::Ok();
48     GetNavigationHistoryReturns result;
49     SendResponse(request, response, result);
50 }
51 }  // namespace panda::ecmascript::tooling