OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview A collection of utility methods for UberPage and its contained | 6 * @fileoverview A collection of utility methods for UberPage and its contained |
7 * pages. | 7 * pages. |
8 */ | 8 */ |
9 | 9 |
10 cr.define('uber', function() { | 10 cr.define('uber', function() { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 * @return {boolean} Whether this frame has a parent. | 101 * @return {boolean} Whether this frame has a parent. |
102 */ | 102 */ |
103 function hasParent() { | 103 function hasParent() { |
104 return window != window.parent; | 104 return window != window.parent; |
105 } | 105 } |
106 | 106 |
107 /** | 107 /** |
108 * Invokes a method on the parent window (UberPage). This is a convenience | 108 * Invokes a method on the parent window (UberPage). This is a convenience |
109 * method for API calls into the uber page. | 109 * method for API calls into the uber page. |
110 * @param {string} method The name of the method to invoke. | 110 * @param {string} method The name of the method to invoke. |
111 * @param {Object=} opt_params Optional property bag of parameters to pass to | 111 * @param {(Object|number|boolean)=} opt_params Optional property bag of |
112 * the invoked method. | 112 * parameters to pass to the invoked method. |
113 * @private | 113 * @private |
114 */ | 114 */ |
115 function invokeMethodOnParent(method, opt_params) { | 115 function invokeMethodOnParent(method, opt_params) { |
116 if (!hasParent()) | 116 if (!hasParent()) |
117 return; | 117 return; |
118 | 118 |
119 invokeMethodOnWindow(window.parent, method, opt_params, 'chrome://chrome'); | 119 invokeMethodOnWindow(window.parent, method, opt_params, 'chrome://chrome'); |
120 } | 120 } |
121 | 121 |
122 /** | 122 /** |
123 * Invokes a method on the target window. | 123 * Invokes a method on the target window. |
124 * @param {string} method The name of the method to invoke. | 124 * @param {string} method The name of the method to invoke. |
125 * @param {Object=} opt_params Optional property bag of parameters to pass to | 125 * @param {(Object|number|boolean)=} opt_params Optional property bag of |
126 * the invoked method. | 126 * parameters to pass to the invoked method. |
127 * @param {string=} opt_url The origin of the target window. | 127 * @param {string=} opt_url The origin of the target window. |
128 * @private | 128 * @private |
129 */ | 129 */ |
130 function invokeMethodOnWindow(targetWindow, method, opt_params, opt_url) { | 130 function invokeMethodOnWindow(targetWindow, method, opt_params, opt_url) { |
131 var data = {method: method, params: opt_params}; | 131 var data = {method: method, params: opt_params}; |
132 targetWindow.postMessage(data, opt_url ? opt_url : '*'); | 132 targetWindow.postMessage(data, opt_url ? opt_url : '*'); |
133 } | 133 } |
134 | 134 |
135 /** | 135 /** |
136 * Updates the page's history state. If the page is embedded in a child, | 136 * Updates the page's history state. If the page is embedded in a child, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 192 |
193 return { | 193 return { |
194 invokeMethodOnParent: invokeMethodOnParent, | 194 invokeMethodOnParent: invokeMethodOnParent, |
195 invokeMethodOnWindow: invokeMethodOnWindow, | 195 invokeMethodOnWindow: invokeMethodOnWindow, |
196 onContentFrameLoaded: onContentFrameLoaded, | 196 onContentFrameLoaded: onContentFrameLoaded, |
197 pushState: pushState, | 197 pushState: pushState, |
198 replaceState: replaceState, | 198 replaceState: replaceState, |
199 setTitle: setTitle, | 199 setTitle: setTitle, |
200 }; | 200 }; |
201 }); | 201 }); |
OLD | NEW |