1 // Copyright (c) 2010 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/public/common/page_transition_types.h" 6 7 #include "base/logging.h" 8 9 namespace content { 10 PageTransitionCoreTypeIs(PageTransition lhs,PageTransition rhs)11bool PageTransitionCoreTypeIs(PageTransition lhs, 12 PageTransition rhs) { 13 // Expect the rhs to be a compile time constant without qualifiers. 14 DCHECK(PageTransitionGetQualifier(rhs) == 0 && 15 PageTransitionIsValidType(rhs)); 16 return implicit_cast<int>(PageTransitionStripQualifier(lhs)) == 17 implicit_cast<int>(PageTransitionStripQualifier(rhs)); 18 } 19 PageTransitionStripQualifier(PageTransition type)20PageTransition PageTransitionStripQualifier(PageTransition type) { 21 return static_cast<PageTransition>(type & ~PAGE_TRANSITION_QUALIFIER_MASK); 22 } 23 PageTransitionIsValidType(int32 type)24bool PageTransitionIsValidType(int32 type) { 25 PageTransition t = PageTransitionStripQualifier( 26 static_cast<PageTransition>(type)); 27 return (t <= PAGE_TRANSITION_LAST_CORE); 28 } 29 PageTransitionFromInt(int32 type)30PageTransition PageTransitionFromInt(int32 type) { 31 if (!PageTransitionIsValidType(type)) { 32 NOTREACHED() << "Invalid transition type " << type; 33 34 // Return a safe default so we don't have corrupt data in release mode. 35 return PAGE_TRANSITION_LINK; 36 } 37 return static_cast<PageTransition>(type); 38 } 39 PageTransitionIsMainFrame(PageTransition type)40bool PageTransitionIsMainFrame(PageTransition type) { 41 int32 t = PageTransitionStripQualifier(type); 42 return (t != PAGE_TRANSITION_AUTO_SUBFRAME && 43 t != PAGE_TRANSITION_MANUAL_SUBFRAME); 44 } 45 PageTransitionIsRedirect(PageTransition type)46bool PageTransitionIsRedirect(PageTransition type) { 47 return (type & PAGE_TRANSITION_IS_REDIRECT_MASK) != 0; 48 } 49 PageTransitionIsNewNavigation(PageTransition type)50bool PageTransitionIsNewNavigation(PageTransition type) { 51 return (type & PAGE_TRANSITION_FORWARD_BACK) == 0 && 52 !PageTransitionCoreTypeIs(type, content::PAGE_TRANSITION_RELOAD); 53 } 54 PageTransitionGetQualifier(PageTransition type)55int32 PageTransitionGetQualifier(PageTransition type) { 56 return type & PAGE_TRANSITION_QUALIFIER_MASK; 57 } 58 PageTransitionIsWebTriggerable(PageTransition type)59bool PageTransitionIsWebTriggerable(PageTransition type) { 60 int32 t = PageTransitionStripQualifier(type); 61 switch (t) { 62 case PAGE_TRANSITION_LINK: 63 case PAGE_TRANSITION_AUTO_SUBFRAME: 64 case PAGE_TRANSITION_MANUAL_SUBFRAME: 65 case PAGE_TRANSITION_FORM_SUBMIT: 66 return true; 67 } 68 return false; 69 } 70 PageTransitionGetCoreTransitionString(PageTransition type)71const char* PageTransitionGetCoreTransitionString(PageTransition type) { 72 int32 t = PageTransitionStripQualifier(type); 73 switch (t) { 74 case PAGE_TRANSITION_LINK: return "link"; 75 case PAGE_TRANSITION_TYPED: return "typed"; 76 case PAGE_TRANSITION_AUTO_BOOKMARK: return "auto_bookmark"; 77 case PAGE_TRANSITION_AUTO_SUBFRAME: return "auto_subframe"; 78 case PAGE_TRANSITION_MANUAL_SUBFRAME: return "manual_subframe"; 79 case PAGE_TRANSITION_GENERATED: return "generated"; 80 case PAGE_TRANSITION_AUTO_TOPLEVEL: return "auto_toplevel"; 81 case PAGE_TRANSITION_FORM_SUBMIT: return "form_submit"; 82 case PAGE_TRANSITION_RELOAD: return "reload"; 83 case PAGE_TRANSITION_KEYWORD: return "keyword"; 84 case PAGE_TRANSITION_KEYWORD_GENERATED: return "keyword_generated"; 85 } 86 return NULL; 87 } 88 89 } // namespace content 90