1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "android_webview/renderer/aw_render_process_observer.h"
6
7#include "android_webview/common/render_view_messages.h"
8#include "ipc/ipc_message_macros.h"
9#include "third_party/WebKit/public/web/WebCache.h"
10#include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
11
12namespace android_webview {
13
14AwRenderProcessObserver::AwRenderProcessObserver()
15  : webkit_initialized_(false) {
16}
17
18AwRenderProcessObserver::~AwRenderProcessObserver() {
19}
20
21bool AwRenderProcessObserver::OnControlMessageReceived(
22    const IPC::Message& message) {
23  bool handled = true;
24  IPC_BEGIN_MESSAGE_MAP(AwRenderProcessObserver, message)
25    IPC_MESSAGE_HANDLER(AwViewMsg_ClearCache, OnClearCache)
26    IPC_MESSAGE_HANDLER(AwViewMsg_SetJsOnlineProperty, OnSetJsOnlineProperty)
27    IPC_MESSAGE_UNHANDLED(handled = false)
28  IPC_END_MESSAGE_MAP()
29  return handled;
30}
31
32void AwRenderProcessObserver::WebKitInitialized() {
33  webkit_initialized_ = true;
34}
35
36void AwRenderProcessObserver::OnClearCache() {
37  if (webkit_initialized_)
38    blink::WebCache::clear();
39}
40
41void AwRenderProcessObserver::OnSetJsOnlineProperty(bool network_up) {
42  if (webkit_initialized_)
43    blink::WebNetworkStateNotifier::setOnLine(network_up);
44}
45
46}  // nanemspace android_webview
47