Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/resources/chromeos/arc_support/background.js

Issue 1681813003: arc: Use incognito profile for OptIn and cookie fetcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor cleanup Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 // Chrome window that hosts UI. Only one window is allowed.
xiyuan 2016/02/12 17:06:59 nit: Use JsDoc style and also doc type /** * Chr
khmel 2016/02/12 18:15:14 Done.
6 var appWindow = null;
7
8 // Contains Web content provided by Google authorization server.
xiyuan 2016/02/12 17:06:59 /** * Contains Web content provided by Google aut
khmel 2016/02/12 18:15:15 Done.
9 var webview = null;
10
11 // Used for bidirectional communication with native code.
xiyuan 2016/02/12 17:06:59 /** * Used for bidirectional communication with n
khmel 2016/02/12 18:15:14 Done.
12 var port = null;
13
14 // Indicates that window was closed internally and it is not required to send
15 // closure notification.
xiyuan 2016/02/12 17:06:59 /** * Indicates that window was closed internally
khmel 2016/02/12 18:15:14 Done.
16 var windowClosedInternally = false;
17
18 function sendNativeMessage(code) {
xiyuan 2016/02/12 17:06:59 /** * Sends a native message to ArcSupportHost.
khmel 2016/02/12 18:15:14 Done.
19 message = {'action': code};
20 port.postMessage(message);
21 }
22
23 function onNativeMessage(message) {
xiyuan 2016/02/12 17:06:59 /** * Handles native messages received from ArcSu
khmel 2016/02/12 18:15:15 Done.
24 if (!message.action) {
25 return;
26 }
27
28 if (message.action == 'closeUI') {
29 if (appWindow) {
30 windowClosedInternally = true;
31 appWindow.contentWindow.close();
xiyuan 2016/02/12 17:06:59 nit: appWindow.close();
khmel 2016/02/12 18:15:15 Done.
32 appWindow = null;
33 }
34 }
35 }
36
37 function connectPort() {
xiyuan 2016/02/12 17:06:59 /** * Connects to ArcSupportHost. */
khmel 2016/02/12 18:15:15 Done.
38 var hostName = 'com.google.arc_support';
39 port = chrome.runtime.connectNative(hostName);
40 port.onMessage.addListener(onNativeMessage);
41 }
42
43 chrome.app.runtime.onLaunched.addListener(function() {
44 var onContentLoad = function() {
xiyuan 2016/02/12 17:06:59 nit: onContentLoad -> onAppContentLoad to make it
khmel 2016/02/12 18:15:14 Done.
45 var doc = appWindow.contentWindow.document;
46 webview = doc.getElementById('arc_support');
47
48 var onLoadStop = function() {
49 if (webview.src.indexOf(
50 'https://accounts.google.com/o/oauth2/programmatic_auth') == 0) {
51 sendNativeMessage('fetchAuthCode');
52 }
53 };
54
55 webview.addEventListener('loadstop', onLoadStop);
xiyuan 2016/02/12 17:06:59 loadstop is indeed tricky and triggering unnecessa
khmel 2016/02/12 18:15:14 Thanks for hint! It works much better and predicta
56 };
57
58 var onWindowCreated = function(createdWindow) {
59 appWindow = createdWindow;
60 appWindow.contentWindow.onload = onContentLoad;
61 createdWindow.onClosed.addListener(onWindowClosed);
62 connectPort();
63 };
64
65 var onWindowClosed = function() {
66 if (windowClosedInternally) {
67 return;
68 }
69 sendNativeMessage('cancelAuthCode');
70 };
71
72 var options = {
73 'id': 'arc_support_wnd',
74 'innerBounds': {
75 'width': 500,
76 'height': 600
77 }
78 };
79 chrome.app.window.create('main.html', options, onWindowCreated);
80 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698