[Release] wrt_0.8.274
[platform/framework/web/wrt.git] / src / view / i_context_manager.h
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    i_context_manager.h
18  * @author  Iwanek Tomasz (t.iwanek@samsung.com)
19  * @version 0.1
20  * @brief   Abstract file for handling operation regarding Ewk_Context.
21  */
22
23 #ifndef ABSTRACT_CONTEXT_MANAGER_H
24 #define ABSTRACT_CONTEXT_MANAGER_H
25
26 #include <memory>
27 #include <functional>
28 #include <i_view_module.h>
29
30 class Ewk_Context; // forward declaration of context type
31
32 namespace ViewModule {
33
34 class IContextManager;
35 typedef std::shared_ptr<IContextManager> ContextManagerPtr;
36
37 typedef std::function<ContextManagerPtr (const std::string&, Ewk_Context*, ViewModule::IViewModulePtr)> ContextManagerFactoryMethod;
38
39 /**
40  * @brief The AbstractContextManager class Factory for ewk context
41  *
42  * This is interface class for ewk context factory.
43  * It's uses tizenId, view module to initialize it approriatly context.
44  *
45  * Constructor should create new context only if ewkContext parameter is NULL.
46  * If ewkContext parameter is not NULL, context should not be destroyed in destructor.
47  * This means used context is managed by manager only if was created internally.
48  *
49  * NOTE: This interface in not visible outside core module and it should not be.
50  *       Reason for this code is not modify RunnableWidgetObject behaviour for mocks.
51  */
52 class IContextManager {
53 public:
54     IContextManager(
55             const std::string& tizenAppId,
56             Ewk_Context* ewkContext,
57             ViewModule::IViewModulePtr viewModule) :
58             m_appId(tizenAppId), m_ewkContext(ewkContext), m_view(viewModule) {}
59     virtual ~IContextManager() {}
60     /**
61      * @brief getEwkContext returns ewk context
62      * @return ewk context
63      */
64     virtual Ewk_Context* getEwkContext() const = 0;
65     /**
66      * @brief handleLowMemory
67      *
68      * Handles low memory conditions
69      */
70     virtual void handleLowMemory() = 0;
71 protected:
72     std::string m_appId;
73     Ewk_Context* m_ewkContext;
74     IViewModulePtr m_view;
75 };
76
77 ContextManagerPtr contextManagerFactoryMethod(const std::string& id, Ewk_Context* c, IViewModulePtr view);
78
79 ContextManagerFactoryMethod makeContextManagerFactoryMethod();
80
81 } // namespace ViewModule
82
83 #endif // ABSTRACT_CONTEXT_MANAGER_H