Home | History | Annotate | Download | only in common
      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 
     11 bool 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 
     20 PageTransition PageTransitionStripQualifier(PageTransition type) {
     21   return static_cast<PageTransition>(type & ~PAGE_TRANSITION_QUALIFIER_MASK);
     22 }
     23 
     24 bool PageTransitionIsValidType(int32 type) {
     25   PageTransition t = PageTransitionStripQualifier(
     26       static_cast<PageTransition>(type));
     27   return (t <= PAGE_TRANSITION_LAST_CORE);
     28 }
     29 
     30 PageTransition 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 
     40 bool PageTransitionIsMainFrame(PageTransition type) {
     41   int32 t = PageTransitionStripQualifier(type);
     42   return (t != PAGE_TRANSITION_AUTO_SUBFRAME &&
     43           t != PAGE_TRANSITION_MANUAL_SUBFRAME);
     44 }
     45 
     46 bool PageTransitionIsRedirect(PageTransition type) {
     47   return (type & PAGE_TRANSITION_IS_REDIRECT_MASK) != 0;
     48 }
     49 
     50 int32 PageTransitionGetQualifier(PageTransition type) {
     51   return type & PAGE_TRANSITION_QUALIFIER_MASK;
     52 }
     53 
     54 bool PageTransitionIsWebTriggerable(PageTransition type) {
     55   int32 t = PageTransitionStripQualifier(type);
     56   switch (t) {
     57     case PAGE_TRANSITION_LINK:
     58     case PAGE_TRANSITION_AUTO_SUBFRAME:
     59     case PAGE_TRANSITION_MANUAL_SUBFRAME:
     60     case PAGE_TRANSITION_FORM_SUBMIT:
     61       return true;
     62   }
     63   return false;
     64 }
     65 
     66 const char* PageTransitionGetCoreTransitionString(PageTransition type) {
     67   int32 t = PageTransitionStripQualifier(type);
     68   switch (t) {
     69     case PAGE_TRANSITION_LINK: return "link";
     70     case PAGE_TRANSITION_TYPED: return "typed";
     71     case PAGE_TRANSITION_AUTO_BOOKMARK: return "auto_bookmark";
     72     case PAGE_TRANSITION_AUTO_SUBFRAME: return "auto_subframe";
     73     case PAGE_TRANSITION_MANUAL_SUBFRAME: return "manual_subframe";
     74     case PAGE_TRANSITION_GENERATED: return "generated";
     75     case PAGE_TRANSITION_AUTO_TOPLEVEL: return "auto_toplevel";
     76     case PAGE_TRANSITION_FORM_SUBMIT: return "form_submit";
     77     case PAGE_TRANSITION_RELOAD: return "reload";
     78     case PAGE_TRANSITION_KEYWORD: return "keyword";
     79     case PAGE_TRANSITION_KEYWORD_GENERATED: return "keyword_generated";
     80   }
     81   return NULL;
     82 }
     83 
     84 }  // namespace content
     85