Switch to new internal chromium branch dev/m38_2114 .
[platform/framework/web/chromium-efl.git] / tizen_src / impl / renderer / render_process_observer_efl.cc
1 #include "renderer/render_process_observer_efl.h"
2
3 #include "base/allocator/allocator_extension.h"
4 #include "content/public/renderer/render_thread.h"
5 #include "third_party/WebKit/public/web/WebCache.h"
6 #include "third_party/sqlite/sqlite3.h"
7 #include "v8/include/v8.h"
8 #include "renderer/content_renderer_client_efl.h"
9
10 // XXX:  config.h needs to be included before internal blink headers.
11 // XXX2: It'd be great if we did not include internal blibk headers.
12 #include "third_party/WebKit/Source/config.h"
13 #include "third_party/WebKit/Source/platform/fonts/FontCache.h"
14
15
16 using blink::WebCache;
17 using content::RenderThread;
18
19 bool RenderProcessObserverEfl::OnControlMessageReceived(const IPC::Message& message)
20 {
21   bool handled = true;
22   IPC_BEGIN_MESSAGE_MAP(RenderProcessObserverEfl, message)
23     IPC_MESSAGE_HANDLER(EflViewMsg_ClearCache, OnClearCache)
24     IPC_MESSAGE_HANDLER(EflViewMsg_SetCache, OnSetCache)
25     IPC_MESSAGE_HANDLER(EwkViewMsg_PurgeMemory, OnPurgeMemory)
26     IPC_MESSAGE_HANDLER(EwkViewMsg_SetWidgetInfo, OnWidgetInfo)
27     IPC_MESSAGE_HANDLER(EwkViewMsg_SendWrtMessage, OnWrtMessage)
28     IPC_MESSAGE_UNHANDLED(handled = false)
29   IPC_END_MESSAGE_MAP()
30   return handled;
31 }
32
33 void RenderProcessObserverEfl::OnWidgetInfo(int widget_id,
34                                             double scale,
35                                             const std::string &theme,
36                                             const std::string &encoded_bundle)
37 {
38   content_client_->SetWidgetInfo(widget_id, scale, encoded_bundle, theme);
39 }
40
41 void RenderProcessObserverEfl::OnWrtMessage(const tizen_webview::WrtIpcMessageData& data)
42 {
43   content_client_->WrtMessageReceived(data);
44 }
45
46 void RenderProcessObserverEfl::WebKitInitialized()
47 {
48   webkit_initialized_ = true;
49   OnSetCache(pending_cache_params_);
50 }
51 void RenderProcessObserverEfl::OnClearCache()
52 {
53   WebCache::clear();
54 }
55
56 void RenderProcessObserverEfl::OnSetCache(const CacheParamsEfl& params)
57 {
58   pending_cache_params_ = params;
59   if(!webkit_initialized_)
60     return;
61
62   WebCache::setCapacities(static_cast<size_t>(params.cache_min_dead_capacity),
63     static_cast<size_t>(params.cache_max_dead_capacity),
64     static_cast<size_t>(params.cache_total_capacity));
65 }
66
67 void RenderProcessObserverEfl::OnPurgeMemory()
68 {
69   RenderThread::Get()->EnsureWebKitInitialized();
70   // Clear the object cache (as much as possible; some live objects cannot be
71   // freed).
72   OnClearCache();
73   // Clear the font/glyph cache.
74   blink::FontCache::fontCache()->invalidate();
75   // TODO(pk): currently web process not linking sqlite. when used this should enable
76   // Release all freeable memory from the SQLite process-global page cache (a
77   // low-level object which backs the Connection-specific page caches).
78   //while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) {
79   //}
80   v8::Isolate::GetCurrent()->LowMemoryNotification();
81   // Tell our allocator to release any free pages it's still holding.
82   base::allocator::ReleaseFreeMemory();
83 }