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