help_app_launcher.cc revision 868fa2fe829687343ffae624259930155e16dbd8
1// Copyright (c) 2012 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/chromeos/login/help_app_launcher.h"
6
7#include <string>
8
9#include "base/stringprintf.h"
10#include "base/strings/utf_string_conversions.h"
11#include "chrome/browser/chromeos/profiles/profile_helper.h"
12#include "chrome/browser/extensions/extension_service.h"
13#include "chrome/browser/extensions/extension_system.h"
14#include "content/public/browser/browser_thread.h"
15#include "grit/generated_resources.h"
16#include "ui/base/l10n/l10n_util.h"
17
18using content::BrowserThread;
19
20namespace {
21
22const char kHelpAppFormat[] =
23    "chrome-extension://honijodknafkokifofgiaalefdiedpko/oobe.html?id=%d";
24
25}  // namespace
26
27namespace chromeos {
28
29///////////////////////////////////////////////////////////////////////////////
30// HelpApp, public:
31
32HelpAppLauncher::HelpAppLauncher(gfx::NativeWindow parent_window)
33    : parent_window_(parent_window) {
34}
35
36void HelpAppLauncher::ShowHelpTopic(HelpTopic help_topic_id) {
37  Profile* profile = ProfileHelper::GetSigninProfile();
38  ExtensionService* service =
39      extensions::ExtensionSystem::Get(profile)->extension_service();
40
41  DCHECK(service);
42  if (!service)
43    return;
44
45  GURL url(base::StringPrintf(kHelpAppFormat,
46                              static_cast<int>(help_topic_id)));
47  // HelpApp component extension presents only in official builds so we can
48  // show help only when the extensions is installed.
49  if (service->extensions()->GetByID(url.host()))
50    ShowHelpTopicDialog(GURL(url));
51}
52
53///////////////////////////////////////////////////////////////////////////////
54// HelpApp, protected:
55
56HelpAppLauncher::~HelpAppLauncher() {}
57
58///////////////////////////////////////////////////////////////////////////////
59// HelpApp, private:
60
61void HelpAppLauncher::ShowHelpTopicDialog(const GURL& topic_url) {
62  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
63  LoginWebDialog* dialog = new LoginWebDialog(
64      NULL,
65      parent_window_,
66      l10n_util::GetStringUTF16(IDS_LOGIN_OOBE_HELP_DIALOG_TITLE),
67      topic_url,
68      LoginWebDialog::STYLE_BUBBLE);
69  dialog->Show();
70  // The dialog object will be deleted on dialog close.
71}
72
73}  // namespace chromeos
74