Index: chrome/browser/resources/md_feedback/feedback.js |
diff --git a/chrome/browser/resources/md_feedback/feedback.js b/chrome/browser/resources/md_feedback/feedback.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..73e294f75bbbced4df49b923f23666b00eaeb013 |
--- /dev/null |
+++ b/chrome/browser/resources/md_feedback/feedback.js |
@@ -0,0 +1,72 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+cr.define('feedback', function() { |
+ 'use strict'; |
+ |
+ /** |
+ * The feedback-container element. Initialized after Polymer is ready. |
+ * @type {?FeedbackContainer} |
+ */ |
+ var container = null; |
+ |
+ /** |
+ * Initialize the Feedback WebUI by requesting data to populate the current |
+ * feedback form. |
+ */ |
+ function initialize() { |
+ container = /** @type {!FeedbackContainerElement} */ |
+ ($('container')); |
+ |
+ feedback.browserApi.requestData(); |
+ } |
+ |
+ return { |
+ initialize: initialize, |
+ }; |
+}); |
+ |
+// API invoked by the browser MdFeedbackWebUIMessageHandler to communicate |
+// with this UI. |
+cr.define('feedback.ui', function() { |
+ 'use strict'; |
+ |
+ /** |
+ * Populates the feedback form with data. |
+ * |
+ * @param {{email: string|undefined, |
+ * url: string|undefined}} data |
+ * Parameters in data: |
+ * email - user's email, if available. |
+ * url - url of the tab the user was on before triggering feedback. |
+ */ |
+ function setData(data) { |
+ container.email = data['email']; |
+ container.url = data['url']; |
+ } |
+ |
+ return { |
+ setData: setData, |
+ }; |
+}); |
+ |
+// API invoked by this UI to communicate with the browser WebUI message |
+// handler. |
+cr.define('feedback.browserApi', function() { |
+ 'use strict'; |
+ |
+ /** |
+ * Requests data to initialize the WebUI with. |
+ * The data will be returned via feedback.ui.setData. |
+ */ |
+ function requestData() { |
+ chrome.send('requestData'); |
+ } |
+ |
+ return { |
+ requestData: requestData, |
+ }; |
+}); |
+ |
+window.addEventListener('load', feedback.initialize); |