Index: chrome/browser/ui/webui/md_feedback/md_feedback_webui_message_handler.cc |
diff --git a/chrome/browser/ui/webui/md_feedback/md_feedback_webui_message_handler.cc b/chrome/browser/ui/webui/md_feedback/md_feedback_webui_message_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..58eca0bc9c3a1c8f3ab04a95e994af8dfbd4f45b |
--- /dev/null |
+++ b/chrome/browser/ui/webui/md_feedback/md_feedback_webui_message_handler.cc |
@@ -0,0 +1,70 @@ |
+// 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. |
+ |
+#include "chrome/browser/ui/webui/md_feedback/md_feedback_webui_message_handler.h" |
+ |
+#include "base/bind.h" |
+#include "base/values.h" |
+#include "chrome/browser/feedback/feedback_dialog_utils.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/signin/signin_manager_factory.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_finder.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
+#include "chrome/browser/ui/webui/md_feedback/md_feedback_ui.h" |
+#include "components/signin/core/browser/signin_manager.h" |
+ |
+namespace { |
+ |
+// Message names. |
+constexpr char kRequestData[] = "requestData"; |
+ |
+// JS function names. |
+constexpr char kSetData[] = "feedback.ui.setData"; |
+ |
+} // namespace |
+ |
+MdFeedbackWebUIMessageHandler::MdFeedbackWebUIMessageHandler( |
+ MdFeedbackUI* md_feedback_ui) |
+ : md_feedback_ui_(md_feedback_ui) { |
+ DCHECK(md_feedback_ui_); |
+} |
+ |
+MdFeedbackWebUIMessageHandler::~MdFeedbackWebUIMessageHandler() { |
+} |
+ |
+void MdFeedbackWebUIMessageHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback( |
+ kRequestData, |
+ base::Bind(&MdFeedbackWebUIMessageHandler::OnRequestData, |
+ base::Unretained(this))); |
+} |
+ |
+void MdFeedbackWebUIMessageHandler::OnRequestData(const base::ListValue* args) { |
+ DVLOG(1) << "OnRequestData"; |
+ base::DictionaryValue data; |
+ |
+ // TODO(apacible): Handle multiple profiles on CrOS. |
afakhry
2016/09/14 01:48:15
I wonder if we really need to worry about this TOD
apacible
2016/09/14 17:53:20
Acknowledged.
|
+ Profile* profile = md_feedback_ui_->profile(); |
+ // Do not launch feedback on an OTR profile. |
+ profile = profile->GetOriginalProfile(); |
afakhry
2016/09/14 01:48:15
If the above comment is correct, then probably we
apacible
2016/09/14 17:53:20
Correct, we still need this. I keep track of the p
|
+ DCHECK(profile); |
+ |
+ SigninManagerBase* signin_manager = |
+ SigninManagerFactory::GetForProfile(profile); |
+ DCHECK(signin_manager); |
+ data.SetString("email", signin_manager->GetAuthenticatedAccountInfo().email); |
+ |
+ GURL page_url = GURL(); |
+ Browser* browser = chrome::FindBrowserWithProfile(profile); |
+ if (browser) { |
+ page_url = chrome::GetTargetTabUrl(browser->session_id().id(), |
+ browser->tab_strip_model()->active_index()); |
afakhry
2016/09/14 01:48:15
Indentation here is wrong. Can you please run `get
apacible
2016/09/14 17:53:20
Done.
|
+ } |
+ |
+ data.SetString("url", page_url.spec()); |
+ |
+ web_ui()->CallJavascriptFunctionUnsafe(kSetData, data); |
+} |