Chromium Code Reviews| OLD | NEW |
|---|---|
| (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"; | |
| 20 | |
| 21 // JS function names. | |
| 22 const char kSetData[] = "feedback.ui.setData"; | |
| 23 | |
| 24 GURL GetTargetTabUrl(int session_id, int index) { | |
|
afakhry
2016/08/03 23:56:01
This is the same code as in chrome::ShowFeedbackPa
apacible
2016/08/11 18:50:33
My plan is to remove this (and from chrome::ShowF
| |
| 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 } | |
| 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()); | |
| 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 } | |
| OLD | NEW |