OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "build/build_config.h" | |
8 #include "chrome/browser/browser_process.h" | |
9 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h" | 7 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h" |
| 8 #include "chrome/browser/feedback/feedback_dialog_utils.h" |
10 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | |
13 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | |
14 #include "chrome/browser/ui/browser_finder.h" | |
15 #include "chrome/browser/ui/browser_window.h" | |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/browser/ui/webui/md_feedback/md_feedback_dialog_controller.h" | 12 #include "chrome/browser/ui/webui/md_feedback/md_feedback_dialog_controller.h" |
18 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
19 #include "components/signin/core/account_id/account_id.h" | |
20 #include "content/public/browser/web_contents.h" | |
21 #include "url/gurl.h" | |
22 | |
23 namespace { | |
24 | |
25 GURL GetTargetTabUrl(int session_id, int index) { | |
26 Browser* browser = chrome::FindBrowserWithID(session_id); | |
27 // Sanity checks. | |
28 if (!browser || index >= browser->tab_strip_model()->count()) | |
29 return GURL(); | |
30 | |
31 if (index >= 0) { | |
32 content::WebContents* target_tab = | |
33 browser->tab_strip_model()->GetWebContentsAt(index); | |
34 if (target_tab) | |
35 return target_tab->GetURL(); | |
36 } | |
37 | |
38 return GURL(); | |
39 } | |
40 | |
41 } // namespace | |
42 | 14 |
43 namespace chrome { | 15 namespace chrome { |
44 | 16 |
45 void ShowFeedbackPage(Browser* browser, | 17 void ShowFeedbackPage(Browser* browser, |
46 const std::string& description_template, | 18 const std::string& description_template, |
47 const std::string& category_tag) { | 19 const std::string& category_tag) { |
48 GURL page_url; | 20 GURL page_url; |
49 if (browser) { | 21 if (browser) { |
50 page_url = GetTargetTabUrl(browser->session_id().id(), | 22 page_url = GetTargetTabUrl(browser->session_id().id(), |
51 browser->tab_strip_model()->active_index()); | 23 browser->tab_strip_model()->active_index()); |
52 } | 24 } |
53 | 25 |
54 Profile* profile = NULL; | 26 Profile* profile = GetFeedbackProfile(browser); |
55 if (browser) { | |
56 profile = browser->profile(); | |
57 } else { | |
58 profile = ProfileManager::GetLastUsedProfileAllowedByPolicy(); | |
59 } | |
60 if (!profile) { | 27 if (!profile) { |
61 LOG(ERROR) << "Cannot invoke feedback: No profile found!"; | 28 LOG(ERROR) << "Cannot invoke feedback: No profile found!"; |
62 return; | 29 return; |
63 } | 30 } |
64 | 31 |
65 // We do not want to launch on an OTR profile. | |
66 profile = profile->GetOriginalProfile(); | |
67 DCHECK(profile); | |
68 | |
69 #if defined(OS_CHROMEOS) | |
70 // Obtains the display profile ID on which the Feedback window should show. | |
71 chrome::MultiUserWindowManager* const window_manager = | |
72 chrome::MultiUserWindowManager::GetInstance(); | |
73 const AccountId display_account_id = | |
74 window_manager && browser | |
75 ? window_manager->GetUserPresentingWindow( | |
76 browser->window()->GetNativeWindow()) | |
77 : EmptyAccountId(); | |
78 profile = display_account_id.is_valid() | |
79 ? multi_user_util::GetProfileFromAccountId(display_account_id) | |
80 : profile; | |
81 #endif | |
82 | |
83 if (::switches::MdFeedbackEnabled()) { | 32 if (::switches::MdFeedbackEnabled()) { |
84 MdFeedbackDialogController::GetInstance()->Show(profile); | 33 MdFeedbackDialogController::GetInstance()->Show(profile); |
85 return; | 34 return; |
86 } | 35 } |
87 | 36 |
88 extensions::FeedbackPrivateAPI* api = | 37 extensions::FeedbackPrivateAPI* api = |
89 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get(profile); | 38 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get(profile); |
90 | 39 |
91 api->RequestFeedback(description_template, | 40 api->RequestFeedback(description_template, |
92 category_tag, | 41 category_tag, |
93 page_url); | 42 page_url); |
94 } | 43 } |
95 | 44 |
96 } // namespace chrome | 45 } // namespace chrome |
OLD | NEW |