- add sources.
[platform/framework/web/crosswalk.git] / src / content / common / swapped_out_messages.cc
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 "content/common/swapped_out_messages.h"
6
7 #include "content/common/accessibility_messages.h"
8 #include "content/common/input_messages.h"
9 #include "content/common/view_messages.h"
10 #include "content/public/common/content_client.h"
11
12 namespace content {
13
14 bool SwappedOutMessages::CanSendWhileSwappedOut(const IPC::Message* msg) {
15   // We filter out most IPC messages when swapped out.  However, some are
16   // important (e.g., ACKs) for keeping the browser and renderer state
17   // consistent in case we later return to the same renderer.
18   switch (msg->type()) {
19     // Handled by RenderWidget.
20     case InputHostMsg_HandleInputEvent_ACK::ID:
21     case ViewHostMsg_PaintAtSize_ACK::ID:
22     case ViewHostMsg_UpdateRect::ID:
23     // Allow targeted navigations while swapped out.
24     case ViewHostMsg_OpenURL::ID:
25     case ViewHostMsg_Focus::ID:
26     // Handled by RenderView.
27     case ViewHostMsg_RenderProcessGone::ID:
28     case ViewHostMsg_ShouldClose_ACK::ID:
29     case ViewHostMsg_SwapOut_ACK::ID:
30     case ViewHostMsg_ClosePage_ACK::ID:
31     case ViewHostMsg_DomOperationResponse::ID:
32     case ViewHostMsg_SwapCompositorFrame::ID:
33     case ViewHostMsg_UpdateIsDelayed::ID:
34     case ViewHostMsg_DidActivateAcceleratedCompositing::ID:
35     // Allow cross-process JavaScript calls.
36     case ViewHostMsg_RouteCloseEvent::ID:
37     case ViewHostMsg_RouteMessageEvent::ID:
38       return true;
39     default:
40       break;
41   }
42
43   // Check with the embedder as well.
44   ContentClient* client = GetContentClient();
45   return client->CanSendWhileSwappedOut(msg);
46 }
47
48 bool SwappedOutMessages::CanHandleWhileSwappedOut(
49     const IPC::Message& msg) {
50   // Any message the renderer is allowed to send while swapped out should
51   // be handled by the browser.
52   if (CanSendWhileSwappedOut(&msg))
53     return true;
54
55   // We drop most other messages that arrive from a swapped out renderer.
56   // However, some are important (e.g., ACKs) for keeping the browser and
57   // renderer state consistent in case we later return to the renderer.
58   // Note that synchronous messages that are not handled will receive an
59   // error reply instead, to avoid leaving the renderer in a stuck state.
60   switch (msg.type()) {
61     // Sends an ACK.
62     case ViewHostMsg_ShowView::ID:
63     // Sends an ACK.
64     case ViewHostMsg_ShowWidget::ID:
65     // Sends an ACK.
66     case ViewHostMsg_ShowFullscreenWidget::ID:
67     // Updates browser state.
68     case ViewHostMsg_RenderViewReady::ID:
69     // Updates the previous navigation entry.
70     case ViewHostMsg_UpdateState::ID:
71     // Sends an ACK.
72     case ViewHostMsg_UpdateTargetURL::ID:
73     // We allow closing even if we are in the process of swapping out.
74     case ViewHostMsg_Close::ID:
75     // Sends an ACK.
76     case ViewHostMsg_RequestMove::ID:
77     // Sends an ACK.
78     case AccessibilityHostMsg_Events::ID:
79 #if defined(USE_X11)
80     // Synchronous message when leaving a page with plugin.  In this case,
81     // we want to destroy the plugin rather than return an error message.
82     case ViewHostMsg_DestroyPluginContainer::ID:
83 #endif
84       return true;
85     default:
86       break;
87   }
88
89   // Check with the embedder as well.
90   ContentClient* client = GetContentClient();
91   return client->CanHandleWhileSwappedOut(msg);
92 }
93
94 }  // namespace content