Remove obsolete for_web_contents parameter in FontRenderParamsQuery.
[chromium-blink-merge.git] / chrome / browser / feedback / show_feedback_page.cc
blobf70a83d0b3cccfa1d04d372d08b7b95eaf9cf6b8
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.
5 #include <string>
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"
17 #include "url/gurl.h"
19 namespace {
21 GURL GetTargetTabUrl(int session_id, int index) {
22 Browser* browser = chrome::FindBrowserWithID(session_id);
23 // Sanity checks.
24 if (!browser || index >= browser->tab_strip_model()->count())
25 return GURL();
27 if (index >= 0) {
28 content::WebContents* target_tab =
29 browser->tab_strip_model()->GetWebContentsAt(index);
30 if (target_tab)
31 return target_tab->GetURL();
34 return GURL();
37 } // namespace
39 namespace chrome {
41 void ShowFeedbackPage(Browser* browser,
42 const std::string& description_template,
43 const std::string& category_tag) {
44 GURL page_url;
45 if (browser) {
46 page_url = GetTargetTabUrl(browser->session_id().id(),
47 browser->tab_strip_model()->active_index());
50 Profile* profile = NULL;
51 if (browser) {
52 profile = browser->profile();
53 } else {
54 profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
56 if (!profile) {
57 LOG(ERROR) << "Cannot invoke feedback: No profile found!";
58 return;
61 // We do not want to launch on an OTR profile.
62 profile = profile->GetOriginalProfile();
63 DCHECK(profile);
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())
73 : "";
74 profile = display_profile_id.empty()
75 ? profile
76 : multi_user_util::GetProfileFromUserID(display_profile_id);
77 #endif
79 extensions::FeedbackPrivateAPI* api =
80 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get(profile);
82 api->RequestFeedback(description_template,
83 category_tag,
84 page_url);
87 } // namespace chrome