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/browser/loader/resource_scheduler_filter.h" 6 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" 8 #include "content/browser/loader/resource_scheduler.h" 9 #include "content/common/view_messages.h" 10 #include "content/public/common/page_transition_types.h" 11 12 namespace content { 13 ResourceSchedulerFilter(int child_id)14ResourceSchedulerFilter::ResourceSchedulerFilter(int child_id) 15 : child_id_(child_id) { 16 } 17 ~ResourceSchedulerFilter()18ResourceSchedulerFilter::~ResourceSchedulerFilter() { 19 } 20 OnMessageReceived(const IPC::Message & message,bool * message_was_ok)21bool ResourceSchedulerFilter::OnMessageReceived(const IPC::Message& message, 22 bool* message_was_ok) { 23 ResourceScheduler* scheduler = 24 ResourceDispatcherHostImpl::Get()->scheduler(); 25 // scheduler can be NULL during shutdown, in which case it's ok to ignore the 26 // renderer's messages. 27 if (!scheduler) 28 return false; 29 30 switch (message.type()) { 31 case ViewHostMsg_FrameNavigate::ID: { 32 PickleIterator iter(message); 33 ViewHostMsg_FrameNavigate_Params params; 34 if (!IPC::ParamTraits<ViewHostMsg_FrameNavigate_Params>::Read( 35 &message, &iter, ¶ms)) { 36 break; 37 } 38 if (PageTransitionIsMainFrame(params.transition) && 39 !params.was_within_same_page) { 40 scheduler->OnNavigate(child_id_, message.routing_id()); 41 } 42 break; 43 } 44 45 case ViewHostMsg_WillInsertBody::ID: 46 scheduler->OnWillInsertBody(child_id_, message.routing_id()); 47 break; 48 49 default: 50 break; 51 } 52 53 return false; 54 } 55 56 } // namespace content 57