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
3 // found in the LICENSE file.
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
12 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
13 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "content/public/browser/web_contents.h"
21 GURL
GetTargetTabUrl(int session_id
, int index
) {
22 Browser
* browser
= chrome::FindBrowserWithID(session_id
);
24 if (!browser
|| index
>= browser
->tab_strip_model()->count())
28 content::WebContents
* target_tab
=
29 browser
->tab_strip_model()->GetWebContentsAt(index
);
31 return target_tab
->GetURL();
41 void ShowFeedbackPage(Browser
* browser
,
42 const std::string
& description_template
,
43 const std::string
& category_tag
) {
46 page_url
= GetTargetTabUrl(browser
->session_id().id(),
47 browser
->tab_strip_model()->active_index());
50 Profile
* profile
= NULL
;
52 profile
= browser
->profile();
54 profile
= ProfileManager::GetLastUsedProfileAllowedByPolicy();
57 LOG(ERROR
) << "Cannot invoke feedback: No profile found!";
61 // We do not want to launch on an OTR profile.
62 profile
= profile
->GetOriginalProfile();
65 #if defined(OS_CHROMEOS)
66 // Obtains the display profile ID on which the Feedback window should show.
67 chrome::MultiUserWindowManager
* const window_manager
=
68 chrome::MultiUserWindowManager::GetInstance();
69 const std::string display_profile_id
=
70 window_manager
&& browser
71 ? window_manager
->GetUserPresentingWindow(
72 browser
->window()->GetNativeWindow())
74 profile
= display_profile_id
.empty()
76 : multi_user_util::GetProfileFromUserID(display_profile_id
);
79 extensions::FeedbackPrivateAPI
* api
=
80 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get(profile
);
82 api
->RequestFeedback(description_template
,