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

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: Changes per afakhry@'s comments. Created 4 years, 4 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/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/webui/md_feedback/md_feedback_ui.h"
15
16 namespace {
17
18 // Message names.
19 const char kRequestData[] = "requestData";
afakhry 2016/08/11 23:31:31 constexpr
apacible 2016/08/12 01:46:42 Done.
20
21 // JS function names.
22 const char kSetData[] = "feedback.ui.setData";
afakhry 2016/08/11 23:31:31 constexpr
apacible 2016/08/12 01:46:42 Done.
23
24 GURL GetTargetTabUrl(int session_id, int index) {
25 Browser* browser = chrome::FindBrowserWithID(session_id);
26 // Sanity checks.
27 if (!browser || index >= browser->tab_strip_model()->count())
28 return GURL();
29
30 if (index >= 0) {
31 content::WebContents* target_tab =
32 browser->tab_strip_model()->GetWebContentsAt(index);
33 if (target_tab)
34 return target_tab->GetURL();
35 }
36
37 return GURL();
38 }
afakhry 2016/08/11 23:31:31 I totally understand your intent and agree with yo
apacible 2016/09/10 07:47:00 Done. Also pulled out GetFeedbackProfile(), but si
39
40 } // namespace
41
42 MdFeedbackWebUIMessageHandler::MdFeedbackWebUIMessageHandler(
43 MdFeedbackUI* md_feedback_ui)
44 : md_feedback_ui_(md_feedback_ui) {
45 DCHECK(md_feedback_ui_);
46 }
47
48 MdFeedbackWebUIMessageHandler::~MdFeedbackWebUIMessageHandler() {
49 }
50
51 void MdFeedbackWebUIMessageHandler::RegisterMessages() {
52 web_ui()->RegisterMessageCallback(
53 kRequestData,
54 base::Bind(&MdFeedbackWebUIMessageHandler::OnRequestData,
55 base::Unretained(this)));
56 }
57
58 void MdFeedbackWebUIMessageHandler::OnRequestData(const base::ListValue* args) {
59 DVLOG(1) << "OnRequestData";
60 base::DictionaryValue data;
61
62 // Do not launch feedback on an OTR profile.
63 // TODO(apacible): Handle multiple profiles on CrOS.
64 Profile* profile =
65 ProfileManager::GetLastUsedProfileAllowedByPolicy();
66 profile = profile->GetOriginalProfile();
67 DCHECK(profile);
68 data.SetString("email", profile->GetProfileUserName());
afakhry 2016/08/11 23:31:31 For the email, in the current feedback app we use
apacible 2016/09/10 07:47:00 Done.
69
70 GURL page_url = GURL();
71 Browser* browser = chrome::FindBrowserWithProfile(profile);
72 if (browser) {
73 page_url = GetTargetTabUrl(browser->session_id().id(),
74 browser->tab_strip_model()->active_index());
75 }
76
77 data.SetString("url", page_url.spec());
78
79 web_ui()->CallJavascriptFunctionUnsafe(kSetData, data);
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698