OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/supervised_user_interstitial.h" | 5 #include "chrome/browser/supervised_user/supervised_user_interstitial.h" |
6 | 6 |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.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 "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 std::string BuildAvatarImageUrl(const std::string& url, int size) { | 55 std::string BuildAvatarImageUrl(const std::string& url, int size) { |
56 std::string result = url; | 56 std::string result = url; |
57 size_t slash = result.rfind('/'); | 57 size_t slash = result.rfind('/'); |
58 if (slash != std::string::npos) | 58 if (slash != std::string::npos) |
59 result.insert(slash, "/s" + base::IntToString(size)); | 59 result.insert(slash, "/s" + base::IntToString(size)); |
60 return result; | 60 return result; |
61 } | 61 } |
62 | 62 |
63 class TabCloser : public content::WebContentsUserData<TabCloser> { | 63 class TabCloser : public content::WebContentsUserData<TabCloser> { |
64 // To use, call TabCloser::CreateForWebContents. | 64 public: |
| 65 static void MaybeClose(WebContents* web_contents) { |
| 66 // Close the tab if there is no history entry to go back to and there is a |
| 67 // browser for the tab (which is not the case for example in a <webview>). |
| 68 if (!web_contents->GetController().IsInitialBlankNavigation()) |
| 69 return; |
| 70 |
| 71 #if !defined(OS_ANDROID) |
| 72 if (!chrome::FindBrowserWithWebContents(web_contents)) |
| 73 return; |
| 74 #endif |
| 75 TabCloser::CreateForWebContents(web_contents); |
| 76 } |
| 77 |
65 private: | 78 private: |
66 friend class content::WebContentsUserData<TabCloser>; | 79 friend class content::WebContentsUserData<TabCloser>; |
67 | 80 |
68 explicit TabCloser(WebContents* web_contents) | 81 explicit TabCloser(WebContents* web_contents) |
69 : web_contents_(web_contents), weak_ptr_factory_(this) { | 82 : web_contents_(web_contents), weak_ptr_factory_(this) { |
70 BrowserThread::PostTask( | 83 BrowserThread::PostTask( |
71 BrowserThread::UI, | 84 BrowserThread::UI, |
72 FROM_HERE, | 85 FROM_HERE, |
73 base::Bind(&TabCloser::CloseTabImpl, weak_ptr_factory_.GetWeakPtr())); | 86 base::Bind(&TabCloser::CloseTabImpl, weak_ptr_factory_.GetWeakPtr())); |
74 } | 87 } |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", | 311 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", |
299 BACK, | 312 BACK, |
300 HISTOGRAM_BOUNDING_VALUE); | 313 HISTOGRAM_BOUNDING_VALUE); |
301 | 314 |
302 // The interstitial's reference to the WebContents will go away after the | 315 // The interstitial's reference to the WebContents will go away after the |
303 // DontProceed call. | 316 // DontProceed call. |
304 WebContents* web_contents = web_contents_; | 317 WebContents* web_contents = web_contents_; |
305 DCHECK(web_contents->GetController().GetTransientEntry()); | 318 DCHECK(web_contents->GetController().GetTransientEntry()); |
306 interstitial_page_->DontProceed(); | 319 interstitial_page_->DontProceed(); |
307 | 320 |
308 // Close the tab if there is no history entry to go back to. | 321 TabCloser::MaybeClose(web_contents); |
309 if (web_contents->GetController().IsInitialBlankNavigation()) | |
310 TabCloser::CreateForWebContents(web_contents); | |
311 | |
312 return; | 322 return; |
313 } | 323 } |
314 | 324 |
315 if (command == "\"request\"") { | 325 if (command == "\"request\"") { |
316 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", | 326 UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", |
317 ACCESS_REQUEST, | 327 ACCESS_REQUEST, |
318 HISTOGRAM_BOUNDING_VALUE); | 328 HISTOGRAM_BOUNDING_VALUE); |
319 | 329 |
320 SupervisedUserService* supervised_user_service = | 330 SupervisedUserService* supervised_user_service = |
321 SupervisedUserServiceFactory::GetForProfile(profile_); | 331 SupervisedUserServiceFactory::GetForProfile(profile_); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 supervised_user_service->RemoveObserver(this); | 401 supervised_user_service->RemoveObserver(this); |
392 | 402 |
393 if (!callback_.is_null()) | 403 if (!callback_.is_null()) |
394 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 404 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
395 base::Bind(callback_, continue_request)); | 405 base::Bind(callback_, continue_request)); |
396 | 406 |
397 // After this, the WebContents may be destroyed. Make sure we don't try to use | 407 // After this, the WebContents may be destroyed. Make sure we don't try to use |
398 // it again. | 408 // it again. |
399 web_contents_ = NULL; | 409 web_contents_ = NULL; |
400 } | 410 } |
OLD | NEW |