summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Ulanov <sergeyu@chromium.org>2014-12-23 16:45:47 -0800
committerSergey Ulanov <sergeyu@chromium.org>2014-12-24 00:46:51 +0000
commit339a931275cbe3b2e5cac355e6d75440ad111912 (patch)
treef453aa06fc95bd86030b4e8082f2bed5a4aa990e
parenta8c7c463889fd2b8968f6e0bb0c67b49312a59be (diff)
downloadchromium_src-339a931275cbe3b2e5cac355e6d75440ad111912.zip
chromium_src-339a931275cbe3b2e5cac355e6d75440ad111912.tar.gz
chromium_src-339a931275cbe3b2e5cac355e6d75440ad111912.tar.bz2
Fix content scripts to wait for response before calling window.close().
Chrome may not always deliver messages if window is closed soon after sendMessage() was called. Now content scripts wait for response from the main page before calling window.close(). This is a workaround for crbug.com/444130 BUG=444127 Review URL: https://codereview.chromium.org/803463003 Cr-Commit-Position: refs/heads/master@{#309287} (cherry picked from commit 16e83f5222d52d53e30f54fb960da49aaa15fb8c) TBR=sergeyu@chromium.org Review URL: https://codereview.chromium.org/789613006 Cr-Commit-Position: refs/branch-heads/2214@{#355} Cr-Branched-From: 03655fd3f6d72165dc3c9bd2c89807305316fe6c-refs/heads/master@{#303346}
-rw-r--r--remoting/webapp/crd/js/cs_oauth2_trampoline.js6
-rw-r--r--remoting/webapp/crd/js/cs_third_party_auth_trampoline.js7
-rw-r--r--remoting/webapp/crd/js/oauth2.js4
-rw-r--r--remoting/webapp/crd/js/third_party_token_fetcher.js10
-rw-r--r--remoting/webapp/js_proto/chrome_proto.js3
5 files changed, 21 insertions, 9 deletions
diff --git a/remoting/webapp/crd/js/cs_oauth2_trampoline.js b/remoting/webapp/crd/js/cs_oauth2_trampoline.js
index 0cf2327..b03bfb0 100644
--- a/remoting/webapp/crd/js/cs_oauth2_trampoline.js
+++ b/remoting/webapp/crd/js/cs_oauth2_trampoline.js
@@ -21,6 +21,8 @@ if (window.location.pathname == officialPath ||
queryArgs[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
- chrome.extension.sendMessage(queryArgs);
- window.close();
+ // Chrome may not deliver the message if window.close() is called after
+ // sendMessage(), see crbug.com/444130 . To ensure the message is delivered
+ // wait for a response before closing the window.
+ chrome.extension.sendMessage(queryArgs, function() { window.close(); });
}
diff --git a/remoting/webapp/crd/js/cs_third_party_auth_trampoline.js b/remoting/webapp/crd/js/cs_third_party_auth_trampoline.js
index f3c65c2..8e299ee 100644
--- a/remoting/webapp/crd/js/cs_third_party_auth_trampoline.js
+++ b/remoting/webapp/crd/js/cs_third_party_auth_trampoline.js
@@ -5,6 +5,9 @@
var thirdPartyPath = '/talkgadget/oauth/chrome-remote-desktop/thirdpartyauth';
if (window.location.pathname == thirdPartyPath) {
- chrome.extension.sendMessage(window.location.href);
- window.close();
+ // Chrome may not deliver the message if window.close() is called after
+ // sendMessage(), see crbug.com/444130 . To ensure the message is delivered
+ // wait for a response before closing the window.
+ chrome.extension.sendMessage(
+ window.location.href, function() { window.close(); });
}
diff --git a/remoting/webapp/crd/js/oauth2.js b/remoting/webapp/crd/js/oauth2.js
index 15ade7a..83440b6 100644
--- a/remoting/webapp/crd/js/oauth2.js
+++ b/remoting/webapp/crd/js/oauth2.js
@@ -261,8 +261,9 @@ remoting.OAuth2.prototype.doAuthRedirect = function(onDone) {
*
* @param {Object.<string, string>} message Dictionary containing the parsed
* OAuth redirect URL parameters.
+ * @param {function(*)} sendResponse Function to send response.
*/
- function oauth2MessageListener(message) {
+ function oauth2MessageListener(message, sender, sendResponse) {
if ('code' in message && 'state' in message) {
that.exchangeCodeForToken(
message['code'], message['state'], onDone);
@@ -277,6 +278,7 @@ remoting.OAuth2.prototype.doAuthRedirect = function(onDone) {
}
}
chrome.extension.onMessage.removeListener(oauth2MessageListener);
+ sendResponse(null);
}
chrome.extension.onMessage.addListener(oauth2MessageListener);
window.open(GET_CODE_URL, '_blank', 'location=yes,toolbar=no,menubar=no');
diff --git a/remoting/webapp/crd/js/third_party_token_fetcher.js b/remoting/webapp/crd/js/third_party_token_fetcher.js
index 69b5cf4..ba98132 100644
--- a/remoting/webapp/crd/js/third_party_token_fetcher.js
+++ b/remoting/webapp/crd/js/third_party_token_fetcher.js
@@ -153,10 +153,14 @@ remoting.ThirdPartyTokenFetcher.prototype.fetchTokenWindowOpen_ = function() {
var that = this;
var fullTokenUrl = this.getFullTokenUrl_();
// The function below can't be anonymous, since it needs to reference itself.
- /** @param {string} message Message received from the content script. */
- function tokenMessageListener(message) {
+ /**
+ * @param {string} message Message received from the content script.
+ * @param {function(*)} sendResponse Function to send response.
+ */
+ function tokenMessageListener(message, sender, sendResponse) {
that.parseRedirectUrl_(message);
chrome.extension.onMessage.removeListener(tokenMessageListener);
+ sendResponse(null);
}
chrome.extension.onMessage.addListener(tokenMessageListener);
window.open(fullTokenUrl, '_blank', 'location=yes,toolbar=no,menubar=no');
@@ -171,4 +175,4 @@ remoting.ThirdPartyTokenFetcher.prototype.fetchTokenIdentityApi_ = function() {
chrome.identity.launchWebAuthFlow(
{'url': fullTokenUrl, 'interactive': true},
this.parseRedirectUrl_.bind(this));
-}; \ No newline at end of file
+};
diff --git a/remoting/webapp/js_proto/chrome_proto.js b/remoting/webapp/js_proto/chrome_proto.js
index 7dbc965..d7b1f13 100644
--- a/remoting/webapp/js_proto/chrome_proto.js
+++ b/remoting/webapp/js_proto/chrome_proto.js
@@ -132,8 +132,9 @@ chrome.extension = {};
/**
* @param {*} message
+ * @param {function(*)=} opt_callback
*/
-chrome.extension.sendMessage = function(message) {}
+chrome.extension.sendMessage = function(message, opt_callback) {};
/** @type {chrome.Event} */
chrome.extension.onMessage;