| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 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/merge_session_load_page.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/shell_delegate.h" | |
| 9 #include "ash/system/tray/system_tray_delegate.h" | |
| 10 #include "base/i18n/rtl.h" | |
| 11 #include "base/metrics/histogram.h" | |
| 12 #include "base/string_piece.h" | |
| 13 #include "base/stringprintf.h" | |
| 14 #include "base/utf_string_conversions.h" | |
| 15 #include "base/values.h" | |
| 16 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 17 #include "chrome/browser/chromeos/cros/network_library.h" | |
| 18 #include "chrome/browser/extensions/extension_service.h" | |
| 19 #include "chrome/browser/extensions/extension_system.h" | |
| 20 #include "chrome/browser/profiles/profile.h" | |
| 21 #include "chrome/browser/renderer_preferences_util.h" | |
| 22 #include "chrome/browser/tab_contents/tab_util.h" | |
| 23 #include "chrome/common/chrome_notification_types.h" | |
| 24 #include "chrome/common/extensions/extension.h" | |
| 25 #include "chrome/common/extensions/extension_constants.h" | |
| 26 #include "chrome/common/extensions/extension_icon_set.h" | |
| 27 #include "chrome/common/url_constants.h" | |
| 28 #include "content/public/browser/browser_thread.h" | |
| 29 #include "content/public/browser/interstitial_page.h" | |
| 30 #include "content/public/browser/notification_types.h" | |
| 31 #include "content/public/browser/web_contents.h" | |
| 32 #include "grit/browser_resources.h" | |
| 33 #include "grit/generated_resources.h" | |
| 34 #include "net/base/escape.h" | |
| 35 #include "ui/base/l10n/l10n_util.h" | |
| 36 #include "ui/base/resource/resource_bundle.h" | |
| 37 #include "ui/webui/jstemplate_builder.h" | |
| 38 | |
| 39 using content::BrowserThread; | |
| 40 using content::InterstitialPage; | |
| 41 using content::WebContents; | |
| 42 | |
| 43 namespace { | |
| 44 | |
| 45 // Delay time for showing interstitial page. | |
| 46 const int kShowDelayTimeMS = 1000; | |
| 47 | |
| 48 // Maximum time for showing interstitial page. | |
| 49 const int kTotalWaitTimeMS = 10000; | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 53 namespace chromeos { | |
| 54 | |
| 55 MergeSessionLoadPage::MergeSessionLoadPage(WebContents* web_contents, | |
| 56 const GURL& url, | |
| 57 const CompletionCallback& callback) | |
| 58 : callback_(callback), | |
| 59 proceeded_(false), | |
| 60 web_contents_(web_contents), | |
| 61 url_(url) { | |
| 62 UserManager::Get()->AddObserver(this); | |
| 63 interstitial_page_ = InterstitialPage::Create(web_contents, true, url, this); | |
| 64 } | |
| 65 | |
| 66 MergeSessionLoadPage::~MergeSessionLoadPage() { | |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 68 UserManager::Get()->RemoveObserver(this); | |
| 69 } | |
| 70 | |
| 71 void MergeSessionLoadPage::Show() { | |
| 72 interstitial_page_->Show(); | |
| 73 } | |
| 74 | |
| 75 std::string MergeSessionLoadPage::GetHTMLContents() { | |
| 76 DictionaryValue strings; | |
| 77 strings.SetString("title", web_contents_->GetTitle()); | |
| 78 // Set the timeout to show the page. | |
| 79 strings.SetInteger("show_delay_time", kShowDelayTimeMS); | |
| 80 strings.SetInteger("total_wait_time", kTotalWaitTimeMS); | |
| 81 // TODO(zelidrag): Flip the message to IDS_MERGE_SESSION_LOAD_HEADLINE | |
| 82 // after merge. | |
| 83 strings.SetString("heading", | |
| 84 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE)); | |
| 85 | |
| 86 bool rtl = base::i18n::IsRTL(); | |
| 87 strings.SetString("textdirection", rtl ? "rtl" : "ltr"); | |
| 88 | |
| 89 base::StringPiece html( | |
| 90 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 91 IDR_MERGE_SESSION_LOAD_HTML)); | |
| 92 return webui::GetI18nTemplateHtml(html, &strings); | |
| 93 } | |
| 94 | |
| 95 void MergeSessionLoadPage::OverrideRendererPrefs( | |
| 96 content::RendererPreferences* prefs) { | |
| 97 Profile* profile = Profile::FromBrowserContext( | |
| 98 web_contents_->GetBrowserContext()); | |
| 99 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); | |
| 100 } | |
| 101 | |
| 102 void MergeSessionLoadPage::OnProceed() { | |
| 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 104 proceeded_ = true; | |
| 105 NotifyBlockingPageComplete(); | |
| 106 } | |
| 107 | |
| 108 void MergeSessionLoadPage::OnDontProceed() { | |
| 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 110 // Ignore if it's already proceeded. | |
| 111 if (proceeded_) | |
| 112 return; | |
| 113 NotifyBlockingPageComplete(); | |
| 114 } | |
| 115 | |
| 116 void MergeSessionLoadPage::CommandReceived(const std::string& cmd) { | |
| 117 std::string command(cmd); | |
| 118 // The Jasonified response has quotes, remove them. | |
| 119 if (command.length() > 1 && command[0] == '"') | |
| 120 command = command.substr(1, command.length() - 2); | |
| 121 | |
| 122 if (command == "proceed") { | |
| 123 interstitial_page_->Proceed(); | |
| 124 } else { | |
| 125 DVLOG(1) << "Unknown command:" << cmd; | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 void MergeSessionLoadPage::NotifyBlockingPageComplete() { | |
| 130 if (!callback_.is_null()) { | |
| 131 BrowserThread::PostTask( | |
| 132 BrowserThread::IO, FROM_HERE, callback_); | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 void MergeSessionLoadPage::MergeSessionStateChanged( | |
| 137 UserManager::MergeSessionState state) { | |
| 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 139 DVLOG(1) << "Merge session is " | |
| 140 << (state != UserManager:: MERGE_STATUS_IN_PROCESS ? | |
| 141 " NOT " : "") | |
| 142 << " in progress, " | |
| 143 << state; | |
| 144 if (state != UserManager:: MERGE_STATUS_IN_PROCESS) { | |
| 145 UserManager::Get()->RemoveObserver(this); | |
| 146 interstitial_page_->Proceed(); | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 } // namespace chromeos | |
| OLD | NEW |