<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[20886] trunk: Theme Customizer: Check for CORS support when the preview and admin urls are cross-domain.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/20886">20886</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-05-24 21:13:21 +0000 (Thu, 24 May 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Theme Customizer: Check for CORS support when the preview and admin urls are cross-domain. Add a fallback to the customize control frame, and check support there as well. see <a href="http://core.trac.wordpress.org/ticket/20582">#20582</a>, <a href="http://core.trac.wordpress.org/ticket/19910">#19910</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincustomizephp">trunk/wp-admin/customize.php</a></li>
<li><a href="#trunkwpincludesjscustomizebasedevjs">trunk/wp-includes/js/customize-base.dev.js</a></li>
<li><a href="#trunkwpincludesjscustomizecontrolsdevjs">trunk/wp-includes/js/customize-controls.dev.js</a></li>
<li><a href="#trunkwpincludesjscustomizeloaderdevjs">trunk/wp-includes/js/customize-loader.dev.js</a></li>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincustomizephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/customize.php (20885 => 20886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/customize.php        2012-05-24 21:07:39 UTC (rev 20885)
+++ trunk/wp-admin/customize.php        2012-05-24 21:13:21 UTC (rev 20886)
</span><span class="lines">@@ -107,22 +107,33 @@
</span><span class="cx">         $allowed_urls = array( home_url('/') );
</span><span class="cx">         $admin_origin = parse_url( admin_url() );
</span><span class="cx">         $home_origin = parse_url( home_url() );
</span><ins>+        $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
</ins><span class="cx">
</span><del>-        if ( is_ssl() && ( $admin_origin[ 'host' ] == $home_origin[ 'host' ] ) )
</del><ins>+        if ( is_ssl() && ! $cross_domain )
</ins><span class="cx">                 $allowed_urls[] = home_url( '/', 'https' );
</span><span class="cx">
</span><span class="cx">         $allowed_urls = array_unique( apply_filters( 'customize_allowed_urls', $allowed_urls ) );
</span><span class="cx">
</span><ins>+        $fallback_url = add_query_arg( array(
+                'preview' => 1,
+                'template' => $wp_customize->get_template(),
+                'stylesheet' => $wp_customize->get_stylesheet(),
+                'preview_iframe' => true,
+                'TB_iframe' => 'true'
+        ), home_url( '/' ) );
+
</ins><span class="cx">         $settings = array(
</span><span class="cx">                 'theme' => array(
</span><span class="cx">                         'stylesheet' => $wp_customize->get_stylesheet(),
</span><span class="cx">                         'active' => $wp_customize->is_theme_active(),
</span><span class="cx">                 ),
</span><span class="cx">                 'url' => array(
</span><del>-                        'preview' => esc_url( home_url( '/' ) ),
-                        'parent' => esc_url( admin_url() ),
-                        'ajax' => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ),
-                        'allowed' => array_map( 'esc_url', $allowed_urls ),
</del><ins>+                        'preview' => esc_url( home_url( '/' ) ),
+                        'parent' => esc_url( admin_url() ),
+                        'ajax' => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ),
+                        'allowed' => array_map( 'esc_url', $allowed_urls ),
+                        'isCrossDomain' => $cross_domain,
+                        'fallback' => $fallback_url,
</ins><span class="cx">                 ),
</span><span class="cx">                 'settings' => array(),
</span><span class="cx">                 'controls' => array(),
</span></span></pre></div>
<a id="trunkwpincludesjscustomizebasedevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/customize-base.dev.js (20885 => 20886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/customize-base.dev.js        2012-05-24 21:07:39 UTC (rev 20885)
+++ trunk/wp-includes/js/customize-base.dev.js        2012-05-24 21:13:21 UTC (rev 20886)
</span><span class="lines">@@ -474,6 +474,8 @@
</span><span class="cx">          * Messenger for postMessage.
</span><span class="cx">          * ===================================================================== */
</span><span class="cx">
</span><ins>+        $.support.postMessage = !! window.postMessage;
+
</ins><span class="cx">         api.Messenger = api.Class.extend({
</span><span class="cx">                 add: function( key, initial, options ) {
</span><span class="cx">                         return this[ key ] = new api.Value( initial, options );
</span></span></pre></div>
<a id="trunkwpincludesjscustomizecontrolsdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/customize-controls.dev.js (20885 => 20886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/customize-controls.dev.js        2012-05-24 21:07:39 UTC (rev 20885)
+++ trunk/wp-includes/js/customize-controls.dev.js        2012-05-24 21:13:21 UTC (rev 20886)
</span><span class="lines">@@ -442,6 +442,9 @@
</span><span class="cx">                 if ( ! api.settings )
</span><span class="cx">                         return;
</span><span class="cx">
</span><ins>+                if ( ! $.support.postMessage || ( ! $.support.cors && api.settings.isCrossDomain ) )
+                        return window.location = api.settings.url.fallback;
+
</ins><span class="cx">                 // Initialize Previewer
</span><span class="cx">                 var body = $( document.body ),
</span><span class="cx">                         query, previewer, parent;
</span></span></pre></div>
<a id="trunkwpincludesjscustomizeloaderdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/customize-loader.dev.js (20885 => 20886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/customize-loader.dev.js        2012-05-24 21:07:39 UTC (rev 20885)
+++ trunk/wp-includes/js/customize-loader.dev.js        2012-05-24 21:13:21 UTC (rev 20886)
</span><span class="lines">@@ -5,14 +5,24 @@
</span><span class="cx">         var api = wp.customize,
</span><span class="cx">                 Loader;
</span><span class="cx">
</span><ins>+        $.extend( $.support, {
+                history: !! ( window.history && history.pushState ),
+                hashchange: ('onhashchange' in window) && (document.documentMode === undefined || document.documentMode > 7)
+        });
+
</ins><span class="cx">         Loader = $.extend( {}, api.Events, {
</span><del>-                supports: {
-                        history: !! ( window.history && history.pushState ),
-                        hashchange: ('onhashchange' in window) && (document.documentMode === undefined || document.documentMode > 7)
-                },
</del><ins>+                initialize: function() {
+                        this.body = $( document.body );
</ins><span class="cx">
</span><del>-                initialize: function() {
-                        this.body = $( document.body ).addClass('customize-support');
</del><ins>+                        // Ensure the loader is supported.
+                        // Check for settings, postMessage support, and whether we require CORS support.
+                        if ( ! Loader.settings || ! $.support.postMessage || ( ! $.support.cors && Loader.settings.isCrossDomain ) ) {
+                                this.body.removeClass( 'customize-support' ).addClass( 'no-customize-support' );
+                                return;
+                        }
+
+                        this.body.removeClass( 'no-customize-support' ).addClass( 'customize-support' );
+
</ins><span class="cx">                         this.window = $( window );
</span><span class="cx">                         this.element = $( '<div id="customize-container" class="wp-full-overlay" />' ).appendTo( this.body );
</span><span class="cx">
</span><span class="lines">@@ -27,10 +37,10 @@
</span><span class="cx">                         });
</span><span class="cx">
</span><span class="cx">                         // Add navigation listeners.
</span><del>-                        if ( this.supports.history )
</del><ins>+                        if ( $.support.history )
</ins><span class="cx">                                 this.window.on( 'popstate', Loader.popstate );
</span><span class="cx">
</span><del>-                        if ( this.supports.hashchange )
</del><ins>+                        if ( $.support.hashchange )
</ins><span class="cx">                                 this.window.on( 'hashchange', Loader.hashchange );
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -48,7 +58,7 @@
</span><span class="cx">                         if ( hash && 0 === hash.indexOf( 'customize=on' ) )
</span><span class="cx">                                 Loader.open( wpCustomizeLoaderL10n.url + '?' + hash );
</span><span class="cx">
</span><del>-                        if ( ! hash && ! Loader.supports.history )
</del><ins>+                        if ( ! hash && ! $.support.history )
</ins><span class="cx">                                 Loader.close();
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -73,9 +83,9 @@
</span><span class="cx">                         });
</span><span class="cx">
</span><span class="cx">                         this.messenger.bind( 'close', function() {
</span><del>-                                if ( Loader.supports.history )
</del><ins>+                                if ( $.support.history )
</ins><span class="cx">                                         history.back();
</span><del>-                                else if ( Loader.supports.hashchange )
</del><ins>+                                else if ( $.support.hashchange )
</ins><span class="cx">                                         window.location.hash = '';
</span><span class="cx">                                 else
</span><span class="cx">                                         Loader.close();
</span><span class="lines">@@ -84,9 +94,9 @@
</span><span class="cx">                         hash = src.split('?')[1];
</span><span class="cx">
</span><span class="cx">                         // Ensure we don't call pushState if the user hit the forward button.
</span><del>-                        if ( Loader.supports.history && window.location.href !== src )
</del><ins>+                        if ( $.support.history && window.location.href !== src )
</ins><span class="cx">                                 history.pushState( { customize: src }, '', src );
</span><del>-                        else if ( ! Loader.supports.history && Loader.supports.hashchange && hash )
</del><ins>+                        else if ( ! $.support.history && $.support.hashchange && hash )
</ins><span class="cx">                                 window.location.hash = hash;
</span><span class="cx">
</span><span class="cx">                         this.trigger( 'open' );
</span><span class="lines">@@ -128,8 +138,8 @@
</span><span class="cx">         });
</span><span class="cx">
</span><span class="cx">         $( function() {
</span><del>-                if ( window.postMessage )
-                        Loader.initialize();
</del><ins>+                Loader.settings = _wpCustomizeLoaderSettings;
+                Loader.initialize();
</ins><span class="cx">         });
</span><span class="cx">
</span><span class="cx">         // Expose the API to the world.
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (20885 => 20886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2012-05-24 21:07:39 UTC (rev 20885)
+++ trunk/wp-includes/theme.php        2012-05-24 21:13:21 UTC (rev 20886)
</span><span class="lines">@@ -1584,16 +1584,31 @@
</span><span class="cx"> add_action( 'plugins_loaded', '_wp_customize_include' );
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Localizes the customize-loader script.
</del><ins>+ * Adds settings for the customize-loader script.
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.4.0
</span><span class="cx"> */
</span><del>-function _wp_customize_loader_localize() {
-        wp_localize_script( 'customize-loader', 'wpCustomizeLoaderL10n', array(
-                'url' => admin_url( 'admin.php' ),
-        ) );
</del><ins>+function _wp_customize_loader_settings() {
+        global $wp_scripts;
+
+        $admin_origin = parse_url( admin_url() );
+        $home_origin = parse_url( home_url() );
+        $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
+
+        $settings = array(
+                'url' => esc_url( admin_url( 'admin.php' ) ),
+                'isCrossDomain' => $cross_domain,
+        );
+
+        $script = 'var _wpCustomizeLoaderSettings = ' . json_encode( $settings ) . ';';
+
+        $data = $wp_scripts->get_data( 'customize-loader', 'data' );
+        if ( $data )
+                $script = "$data\n$script";
+
+        $wp_scripts->add_data( 'customize-loader', 'data', $script );
</ins><span class="cx"> }
</span><del>-add_action( 'admin_enqueue_scripts', '_wp_customize_loader_localize' );
</del><ins>+add_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings' );
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Returns a URL to load the theme customizer.
</span><span class="lines">@@ -1602,4 +1617,4 @@
</span><span class="cx"> */
</span><span class="cx"> function wp_customize_url( $stylesheet ) {
</span><span class="cx">         return esc_url( admin_url( 'customize.php' ) . '?theme=' . $stylesheet );
</span><del>-}
</del><span class="cx">\ No newline at end of file
</span><ins>+}
</ins></span></pre>
</div>
</div>
</body>
</html>