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