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

Side by Side Diff: chrome/browser/managed_mode/managed_mode_interstitial.cc

Issue 12887005: Show interstitial from ManagedModeNavigationObserver instead of ManagedModeResourceThrottle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 7 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" 5 #include "chrome/browser/managed_mode/managed_mode_interstitial.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" 10 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
11 #include "chrome/browser/managed_mode/managed_user_service.h" 11 #include "chrome/browser/managed_mode/managed_user_service.h"
12 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 12 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tab_contents/tab_util.h"
15 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
16 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/interstitial_page.h" 17 #include "content/public/browser/interstitial_page.h"
19 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
20 #include "content/public/browser/web_contents_delegate.h" 19 #include "content/public/browser/web_contents_delegate.h"
21 #include "grit/browser_resources.h" 20 #include "grit/browser_resources.h"
22 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
23 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
24 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/webui/jstemplate_builder.h" 25 #include "ui/webui/jstemplate_builder.h"
27 #include "ui/webui/web_ui_util.h" 26 #include "ui/webui/web_ui_util.h"
28 27
29 using content::BrowserThread; 28 using content::BrowserThread;
30 29
31 namespace {
32
33 void ShowInterstitialOnUIThread(int render_process_host_id,
34 int render_view_id,
35 const GURL& url,
36 const base::Callback<void(bool)>& callback) {
37 // The tab might have been closed.
38 content::WebContents* web_contents =
39 tab_util::GetWebContentsByID(render_process_host_id, render_view_id);
40 if (!web_contents) {
41 BrowserThread::PostTask(
42 BrowserThread::IO, FROM_HERE, base::Bind(callback, true));
43 return;
44 }
45
46 ManagedModeNavigationObserver* navigation_observer =
47 ManagedModeNavigationObserver::FromWebContents(web_contents);
48 if (navigation_observer)
49 navigation_observer->SetStateToRecordingAfterPreview();
50
51 new ManagedModeInterstitial(web_contents, url, callback);
52 }
53
54 } // namespace
55
56 // static
57 void ManagedModeInterstitial::ShowInterstitial(
58 int render_process_host_id,
59 int render_view_id,
60 const GURL& url,
61 const base::Callback<void(bool)>& callback) {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
63 BrowserThread::PostTask(
64 BrowserThread::UI, FROM_HERE,
65 base::Bind(&ShowInterstitialOnUIThread, render_process_host_id,
66 render_view_id, url, callback));
67 }
68
69 ManagedModeInterstitial::ManagedModeInterstitial( 30 ManagedModeInterstitial::ManagedModeInterstitial(
70 content::WebContents* web_contents, 31 content::WebContents* web_contents,
71 const GURL& url, 32 const GURL& url,
72 const base::Callback<void(bool)>& callback) 33 const base::Callback<void(bool)>& callback)
73 : web_contents_(web_contents), 34 : web_contents_(web_contents),
74 url_(url), 35 url_(url),
75 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 36 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
76 callback_(callback) { 37 callback_(callback) {
77 Profile* profile = 38 Profile* profile =
78 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 39 Profile::FromBrowserContext(web_contents->GetBrowserContext());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 NTP, 118 NTP,
158 HISTOGRAM_BOUNDING_VALUE); 119 HISTOGRAM_BOUNDING_VALUE);
159 GoToNewTabPage(); 120 GoToNewTabPage();
160 return; 121 return;
161 } 122 }
162 123
163 NOTREACHED(); 124 NOTREACHED();
164 } 125 }
165 126
166 void ManagedModeInterstitial::OnProceed() { 127 void ManagedModeInterstitial::OnProceed() {
167 DispatchContinueRequest(true); 128 callback_.Run(true);
168 } 129 }
169 130
170 void ManagedModeInterstitial::OnDontProceed() { 131 void ManagedModeInterstitial::OnDontProceed() {
171 DispatchContinueRequest(false); 132 callback_.Run(false);
172 } 133 }
173 134
174 void ManagedModeInterstitial::OnAuthorizationResult(bool success) { 135 void ManagedModeInterstitial::OnAuthorizationResult(bool success) {
175 if (success) 136 if (success)
176 interstitial_page_->Proceed(); 137 interstitial_page_->Proceed();
177 } 138 }
178
179 void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) {
180 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
181 base::Bind(callback_, continue_request));
182 }
183
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698