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

Side by Side Diff: chrome/browser/ui/webui/md_feedback/md_feedback_webui_message_handler.cc

Issue 2190653003: [Md Feedback] Add initial data population for dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 3 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 #include "chrome/browser/ui/webui/md_feedback/md_feedback_webui_message_handler. h"
6
7 #include "base/bind.h"
8 #include "base/values.h"
9 #include "chrome/browser/feedback/feedback_dialog_utils.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/browser/ui/webui/md_feedback/md_feedback_ui.h"
17 #include "components/signin/core/browser/signin_manager.h"
18
19 namespace {
20
21 // Message names.
22 constexpr char kRequestData[] = "requestData";
23
24 // JS function names.
25 constexpr char kSetData[] = "feedback.ui.setData";
26
27 } // namespace
28
29 MdFeedbackWebUIMessageHandler::MdFeedbackWebUIMessageHandler(
30 MdFeedbackUI* md_feedback_ui)
31 : md_feedback_ui_(md_feedback_ui) {
32 DCHECK(md_feedback_ui_);
33 }
34
35 MdFeedbackWebUIMessageHandler::~MdFeedbackWebUIMessageHandler() {
36 }
37
38 void MdFeedbackWebUIMessageHandler::RegisterMessages() {
39 web_ui()->RegisterMessageCallback(
40 kRequestData,
41 base::Bind(&MdFeedbackWebUIMessageHandler::OnRequestData,
42 base::Unretained(this)));
43 }
44
45 void MdFeedbackWebUIMessageHandler::OnRequestData(const base::ListValue* args) {
46 DVLOG(1) << "OnRequestData";
47 base::DictionaryValue data;
48
49 // 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.
50 Profile* profile = md_feedback_ui_->profile();
51 // Do not launch feedback on an OTR profile.
52 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
53 DCHECK(profile);
54
55 SigninManagerBase* signin_manager =
56 SigninManagerFactory::GetForProfile(profile);
57 DCHECK(signin_manager);
58 data.SetString("email", signin_manager->GetAuthenticatedAccountInfo().email);
59
60 GURL page_url = GURL();
61 Browser* browser = chrome::FindBrowserWithProfile(profile);
62 if (browser) {
63 page_url = chrome::GetTargetTabUrl(browser->session_id().id(),
64 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.
65 }
66
67 data.SetString("url", page_url.spec());
68
69 web_ui()->CallJavascriptFunctionUnsafe(kSetData, data);
70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698