Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added a couple of helpers to assist in determining if IE is loading a page using the Chrome Frame plugin #13

Open
wants to merge 4 commits into from

9 participants

@impact11

Chrome Frame uses the same IE USER_AGENT string when loading the page, but appends a chromeframe tag to the user agent to allow you to identify this.

This new code allows you to check if the page is being loaded with chromeframe, without interfering with the IE detection when needed.

@fnando
Owner

Can you please add a test for this? Also, use chrome_frame? as the method name. Thanks, dude! ;)

Juan Felipe ... added some commits
@impact11

There you go!

@impact11

Oi Fernando,

Any thoughts on rolling this into the project? Do you need anything else?

@auchenberg

+1 for this.

Was about to fork myself, but then I saw this pull request.

@loop23

+1

@gnarmis

+1

Was about to add this in myself...

@axlekb

+1

@fnando
Owner

@impact11 do you think is a good idea detecting :chrome_frame as Chrome as well? I know that Chrome Frame doesn't implement all of Chrome's goodness, but it's good enough.

Maybe consider it as Chrome and also detect it with Browser#chrome_frame?.

@fnando
Owner

Anyway... implemented the Chrome detection here: 434db3f

@impact11

@fnando I think it's probably safer to detect them separately and let the developer decide whether or not to treat both flags as equivalent for development purposes. The differences may actually matter to someone. Anyhow, I see that you brought it in, which is awesome. Let me know if you need any other assistance.

@impact11

Hi @fnando -- I'd love to have my app start using the main branch again, but right now I'm still pointing to my fork because this pull request is still outstanding. Is there anything you need in addition before you can pull it into the main branch?

@pekeler

+1
I know chrome frame is deprecated. But now what IE11 doesn't support conditional comments anymore, I really depend on Browser to detect chrome(frame). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 11, 2012
  1. @impact11
  2. @impact11

    Update README.rdoc

    impact11 authored
  3. Initial commit

    Juan Felipe Rincón authored
  4. Support and passing tests for chrome_frame detection

    Juan Felipe Rincón authored
This page is out of date. Refresh to see the latest.
Showing with 143 additions and 32 deletions.
  1. +18 −0 .project
  2. +4 −0 README.rdoc
  3. +22 −14 lib/browser.rb
  4. +99 −18 test/browser_test.rb
View
18 .project
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>browser</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.aptana.ide.core.unifiedBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.aptana.ruby.core.rubynature</nature>
+ <nature>com.aptana.projects.webnature</nature>
+ </natures>
+</projectDescription>
View
4 README.rdoc
@@ -1,3 +1,7 @@
+= Fork Note
+
+This fork adds helpers to see if a user is navigating using IE with chromeframe installed.
+
= Browser
Do some browser detection with Ruby. Includes ActionController integration.
View
36 lib/browser.rb
@@ -12,20 +12,21 @@ class Browser
alias :ua= :user_agent=
NAMES = {
- :android => "Android",
- :blackberry => "BlackBerry",
- :chrome => "Chrome",
- :firefox => "Firefox",
- :ie => "Internet Explorer",
- :ipad => "iPad",
- :iphone => "iPhone",
- :ipod => "iPod Touch",
- :opera => "Opera",
- :other => "Other",
- :safari => "Safari",
- :psp => "PlayStation Portable",
- :quicktime => "QuickTime",
- :core_media => "Apple CoreMedia"
+ :android => "Android",
+ :blackberry => "BlackBerry",
+ :chrome => "Chrome",
+ :chrome_frame => "IE+Chromeframe",
+ :firefox => "Firefox",
+ :ie => "Internet Explorer",
+ :ipad => "iPad",
+ :iphone => "iPhone",
+ :ipod => "iPod Touch",
+ :opera => "Opera",
+ :other => "Other",
+ :safari => "Safari",
+ :psp => "PlayStation Portable",
+ :quicktime => "QuickTime",
+ :core_media => "Apple CoreMedia"
}
VERSION_REGEX = /(?:Version|MSIE|Opera|Firefox|Chrome|QuickTime|BlackBerry[^\/]+|CoreMedia v)[\/ ]?([a-z0-9.]+)/i
@@ -173,6 +174,7 @@ def name
def id
case
when chrome? then :chrome
+ when chrome_frame? then :chrome_frame
when iphone? then :iphone
when ipad? then :ipad
when ipod? then :ipod
@@ -286,6 +288,11 @@ def chrome?
!!(ua =~ /Chrome/)
end
+ # Detect if browser is IE running Chrome Frame
+ def chrome_frame?
+ !!(ua =~ /chromeframe/)
+ end
+
# Detect if browser is Internet Explorer.
def ie?
!!(ua =~ /MSIE/ && ua !~ /Opera/)
@@ -358,6 +365,7 @@ def meta
m << platform
m << "capable" if capable?
m << "mobile" if mobile?
+ m << "chromeframe" if chrome_frame?
end
end
View
117 test/browser_test.rb
@@ -1,24 +1,31 @@
require "test_helper"
class BrowserTest < Test::Unit::TestCase
- IPHONE = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3"
- IPOD = "Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3"
- IPAD = "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10"
- SAFARI = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8"
- IE6 = "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
- IE7 = "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)"
- IE8 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
- IE8_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; Media Center PC 5.0; .NET CLR 3.5.21022)"
- IE9 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
- IE9_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)"
- OPERA = "Opera/9.99 (Windows NT 5.1; U; pl) Presto/9.9.9"
- FIREFOX = "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"
- CHROME = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4"
- ANDROID = "Android SDK 1.5r3: Mozilla/5.0 (Linux; U; Android 1.5; de-; sdk Build/CUPCAKE) AppleWebkit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1"
- BLACKBERRY = "BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103"
- PSP = "Mozilla/4.0 (PSP (PlayStation Portable); 2.00)"
- QUICKTIME = "QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)"
- COREMEDIA = "Apple Mac OS X v10.6.4 CoreMedia v1.0.0.10F569"
+
+ IPHONE = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3"
+ IPOD = "Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3"
+ IPAD = "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10"
+ SAFARI = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8"
+ IE6 = "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
+ IE7 = "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)"
+ IE8 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
+ IE8_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; Media Center PC 5.0; .NET CLR 3.5.21022)"
+ IE9 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
+ IE9_COMPAT = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)"
+ OPERA = "Opera/9.99 (Windows NT 5.1; U; pl) Presto/9.9.9"
+ FIREFOX = "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"
+ CHROME = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4"
+ ANDROID = "Android SDK 1.5r3: Mozilla/5.0 (Linux; U; Android 1.5; de-; sdk Build/CUPCAKE) AppleWebkit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1"
+ BLACKBERRY = "BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103"
+ PSP = "Mozilla/4.0 (PSP (PlayStation Portable); 2.00)"
+ QUICKTIME = "QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)"
+ COREMEDIA = "Apple Mac OS X v10.6.4 CoreMedia v1.0.0.10F569"
+ IE6_CHROME = "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; chromeframe/11.0.660.0)"
+ IE7_CHROME = "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US; chromeframe/11.0.660.0)"
+ IE8_CHROME = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; chromeframe/11.0.660.0)"
+ IE8_COMPAT_CHROME = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; Media Center PC 5.0; .NET CLR 3.5.21022; chromeframe/11.0.660.0)"
+ IE9_CHROME = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; chromeframe/11.0.660.0)"
+ IE9_COMPAT_CHROME = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0; chromeframe/11.0.660.0)"
def setup
@browser = Browser.new
@@ -208,6 +215,80 @@ def test_detect_chrome
assert_equal "5", @browser.version
end
+ def test_detect_ie6_chrome_frame
+ @browser.ua = IE6_CHROME
+
+ assert_equal "IE+Chromeframe", @browser.name
+ assert @browser.ie?
+ assert @browser.ie6?
+ assert @browser.capable? == false
+ assert @browser.chrome_frame?
+ assert_equal "6.0", @browser.full_version
+ assert_equal "6", @browser.version
+ end
+
+ def test_detect_ie7_chrome_frame
+ @browser.ua = IE7_CHROME
+
+ assert_equal "IE+Chromeframe", @browser.name
+ assert @browser.ie?
+ assert @browser.ie7?
+ assert @browser.capable?
+ assert @browser.chrome_frame?
+ assert_equal "7.0", @browser.full_version
+ assert_equal "7", @browser.version
+ end
+
+ def test_detect_ie8_chrome_frame
+ @browser.ua = IE8_CHROME
+
+ assert_equal "IE+Chromeframe", @browser.name
+ assert @browser.ie?
+ assert @browser.ie8?
+ assert @browser.capable?
+ assert @browser.chrome_frame?
+ assert_equal "8.0", @browser.full_version
+ assert_equal "8", @browser.version
+ end
+
+ def test_detect_ie8_in_compatibility_view_chrome_frame
+ @browser.ua = IE8_COMPAT_CHROME
+
+ assert_equal "IE+Chromeframe", @browser.name
+ assert @browser.ie?
+ assert @browser.ie8?
+ assert @browser.capable?
+ assert @browser.compatibility_view?
+ assert @browser.chrome_frame?
+ assert_equal "8.0", @browser.full_version
+ assert_equal "8", @browser.version
+ end
+
+ def test_detect_ie9_chrome_frame
+ @browser.ua = IE9_CHROME
+
+ assert_equal "IE+Chromeframe", @browser.name
+ assert @browser.ie?
+ assert @browser.ie9?
+ assert @browser.capable?
+ assert @browser.chrome_frame?
+ assert_equal "9.0", @browser.full_version
+ assert_equal "9", @browser.version
+ end
+
+ def test_detect_ie9_in_compatibility_view_chrome_frame
+ @browser.ua = IE9_COMPAT_CHROME
+
+ assert_equal "IE+Chromeframe", @browser.name
+ assert @browser.ie?
+ assert @browser.ie9?
+ assert @browser.capable?
+ assert @browser.compatibility_view?
+ assert @browser.chrome_frame?
+ assert_equal "9.0", @browser.full_version
+ assert_equal "9", @browser.version
+ end
+
def test_detect_android
@browser.ua = ANDROID
Something went wrong with that request. Please try again.