Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: chrome/browser/chromeos/login/merge_session_load_page.cc

Issue 12256046: Added interstitial page for merge session. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 string16 failed_url(ASCIIToUTF16(url_.spec()));
90 if (rtl)
91 base::i18n::WrapStringWithLTRFormatting(&failed_url);
92 strings.SetString("url", failed_url);
93
94 strings.SetString("display_icon", "block");
oshima 2013/02/15 22:40:52 are these two values used?
zel 2013/02/15 23:16:58 Done.
95
96 base::StringPiece html(
97 ResourceBundle::GetSharedInstance().GetRawDataResource(
98 IDR_MERGE_SESSION_LOAD_HTML));
99 return webui::GetI18nTemplateHtml(html, &strings);
100 }
101
102 void MergeSessionLoadPage::OverrideRendererPrefs(
103 content::RendererPreferences* prefs) {
104 Profile* profile = Profile::FromBrowserContext(
105 web_contents_->GetBrowserContext());
106 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile);
107 }
108
109 void MergeSessionLoadPage::OnProceed() {
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
111 proceeded_ = true;
112 NotifyBlockingPageComplete(true);
113 }
114
115 void MergeSessionLoadPage::OnDontProceed() {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
117 // Ignore if it's already proceeded.
118 if (proceeded_)
119 return;
120 NotifyBlockingPageComplete(false);
121 }
122
123 void MergeSessionLoadPage::CommandReceived(const std::string& cmd) {
124 std::string command(cmd);
125 // The Jasonified response has quotes, remove them.
126 if (command.length() > 1 && command[0] == '"') {
127 command = command.substr(1, command.length() - 2);
128 }
oshima 2013/02/15 22:40:52 nuke {}
zel 2013/02/15 23:16:58 Done.
129 if (command == "proceed") {
130 interstitial_page_->Proceed();
131 } else {
132 DVLOG(1) << "Unknown command:" << cmd;
133 }
134 }
135
136 void MergeSessionLoadPage::NotifyBlockingPageComplete(bool proceed) {
137 if (!callback_.is_null()) {
138 BrowserThread::PostTask(
139 BrowserThread::IO, FROM_HERE, base::Bind(callback_, proceed));
140 }
141 }
142
143 void MergeSessionLoadPage::MergeSessionStateChanged(
144 UserManager::MergeSessionState state) {
145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
146 DVLOG(1) << "Merge session is "
147 << (state != UserManager:: MERGE_STATUS_IN_PROCESS ?
148 " NOT " : "")
149 << " in progress, "
150 << state;
151 if (state != UserManager:: MERGE_STATUS_IN_PROCESS) {
152 UserManager::Get()->RemoveObserver(this);
153 interstitial_page_->Proceed();
154 }
155 }
156
157 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698