Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2011 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/utf_string_conversions.h"
     11 #include "chrome/browser/extensions/extension_service.h"
     12 #include "chrome/browser/profiles/profile.h"
     13 #include "chrome/browser/profiles/profile_manager.h"
     14 #include "grit/generated_resources.h"
     15 #include "ui/base/l10n/l10n_util.h"
     16 
     17 namespace {
     18 
     19 const char kHelpAppFormat[] =
     20     "chrome-extension://honijodknafkokifofgiaalefdiedpko/oobe.html?id=%d";
     21 
     22 }
     23 
     24 namespace chromeos {
     25 
     26 ///////////////////////////////////////////////////////////////////////////////
     27 // HelpApp, public:
     28 
     29 HelpAppLauncher::HelpAppLauncher(gfx::NativeWindow parent_window)
     30     : parent_window_(parent_window) {
     31 }
     32 
     33 void HelpAppLauncher::ShowHelpTopic(HelpTopic help_topic_id) {
     34   Profile* profile = ProfileManager::GetDefaultProfile();
     35   ExtensionService* service = profile->GetExtensionService();
     36 
     37   DCHECK(service);
     38   if (!service)
     39     return;
     40 
     41   GURL url(base::StringPrintf(kHelpAppFormat,
     42                               static_cast<int>(help_topic_id)));
     43   // HelpApp component extension presents only in official builds so we can
     44   // show help only when the extensions is installed.
     45   if (service->GetExtensionByURL(url))
     46     ShowHelpTopicDialog(GURL(url));
     47 }
     48 
     49 ///////////////////////////////////////////////////////////////////////////////
     50 // HelpApp, private:
     51 
     52 void HelpAppLauncher::ShowHelpTopicDialog(const GURL& topic_url) {
     53   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     54   dialog_.reset(new LoginHtmlDialog(
     55       this,
     56       parent_window_,
     57       UTF16ToWide(
     58           l10n_util::GetStringUTF16(IDS_LOGIN_OOBE_HELP_DIALOG_TITLE)),
     59       topic_url,
     60       LoginHtmlDialog::STYLE_BUBBLE));
     61   dialog_->Show();
     62 }
     63 
     64 }  // namespace chromeos
     65