Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/search/instant_controller.h" | 5 #include "chrome/browser/ui/search/instant_controller.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 #include "chrome/common/content_settings_types.h" | 36 #include "chrome/common/content_settings_types.h" |
| 37 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 39 #include "components/sessions/serialized_navigation_entry.h" | 39 #include "components/sessions/serialized_navigation_entry.h" |
| 40 #include "content/public/browser/navigation_entry.h" | 40 #include "content/public/browser/navigation_entry.h" |
| 41 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
| 42 #include "content/public/browser/render_process_host.h" | 42 #include "content/public/browser/render_process_host.h" |
| 43 #include "content/public/browser/render_widget_host_view.h" | 43 #include "content/public/browser/render_widget_host_view.h" |
| 44 #include "content/public/browser/user_metrics.h" | 44 #include "content/public/browser/user_metrics.h" |
| 45 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 46 #include "content/public/browser/web_contents_user_data.h" | |
| 46 #include "content/public/browser/web_contents_view.h" | 47 #include "content/public/browser/web_contents_view.h" |
| 47 #include "net/base/escape.h" | 48 #include "net/base/escape.h" |
| 48 #include "net/base/network_change_notifier.h" | 49 #include "net/base/network_change_notifier.h" |
| 49 #include "third_party/icu/public/common/unicode/normalizer2.h" | 50 #include "third_party/icu/public/common/unicode/normalizer2.h" |
| 50 | 51 |
| 51 #if defined(TOOLKIT_VIEWS) | 52 #if defined(TOOLKIT_VIEWS) |
| 52 #include "ui/views/widget/widget.h" | 53 #include "ui/views/widget/widget.h" |
| 53 #endif | 54 #endif |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 template <typename T> | 244 template <typename T> |
| 244 void DeletePageSoon(scoped_ptr<T> page) { | 245 void DeletePageSoon(scoped_ptr<T> page) { |
| 245 if (page->contents()) { | 246 if (page->contents()) { |
| 246 base::MessageLoop::current()->DeleteSoon( | 247 base::MessageLoop::current()->DeleteSoon( |
| 247 FROM_HERE, page->ReleaseContents().release()); | 248 FROM_HERE, page->ReleaseContents().release()); |
| 248 } | 249 } |
| 249 | 250 |
| 250 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); | 251 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); |
| 251 } | 252 } |
| 252 | 253 |
| 254 class NtpLoggingUserData | |
|
beaudoin
2013/06/22 01:14:53
Please document the class.
annark1
2013/06/25 16:01:38
Done.
| |
| 255 : public content::WebContentsUserData<NtpLoggingUserData> { | |
| 256 public: | |
| 257 virtual ~NtpLoggingUserData() {} | |
|
beaudoin
2013/06/22 01:14:53
Indentation is wrong in the class:
one space befor
annark1
2013/06/25 16:01:38
Done.
| |
| 258 | |
| 259 // Called each time the mouse hovers over an iframe or title. | |
| 260 void increment_iframe_hovers(int iframe_pos) { | |
| 261 ntp_logging_data_[iframe_pos] += 1; | |
|
beaudoin
2013/06/22 01:14:53
++
annark1
2013/06/25 16:01:38
Done.
| |
| 262 } | |
| 263 | |
| 264 // Sums the values in the |ntp_logging_data_| map and logs to histogram. | |
|
beaudoin
2013/06/22 01:14:53
Clarify to indicate that you are summing over ever
annark1
2013/06/25 16:01:38
changed to just an int.
On 2013/06/22 01:14:53, be
| |
| 265 // Called when a tab is about to be deactivated. | |
| 266 void sum_values_and_log() { | |
| 267 int result = 0; | |
| 268 for (size_t i = 0; i < ntp_logging_data_.size(); ++i) { | |
| 269 result += ntp_logging_data_[i]; | |
| 270 } | |
| 271 if (result > 0) { | |
| 272 HISTOGRAM_COUNTS_10000("NewTabPage.NumberOfMouseOvers", result); | |
| 273 ntp_logging_data_.clear(); | |
| 274 } | |
|
beaudoin
2013/06/22 01:14:53
Please check with asvitkine@ that you're using thi
annark1
2013/06/25 16:01:38
Alexei suggested just using the default UMA_HISTOG
| |
| 275 } | |
| 276 | |
| 277 private: | |
| 278 explicit NtpLoggingUserData(content::WebContents* contents) {} | |
| 279 friend class content::WebContentsUserData<NtpLoggingUserData>; | |
| 280 | |
| 281 // Map in which to log user data. | |
| 282 std::map<int, int> ntp_logging_data_; | |
| 283 }; | |
| 284 | |
| 253 } // namespace | 285 } // namespace |
| 254 | 286 |
| 287 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NtpLoggingUserData); | |
| 288 | |
| 255 InstantController::InstantController(BrowserInstantController* browser, | 289 InstantController::InstantController(BrowserInstantController* browser, |
| 256 bool extended_enabled) | 290 bool extended_enabled) |
| 257 : browser_(browser), | 291 : browser_(browser), |
| 258 extended_enabled_(extended_enabled), | 292 extended_enabled_(extended_enabled), |
| 259 instant_enabled_(false), | 293 instant_enabled_(false), |
| 260 use_local_page_only_(true), | 294 use_local_page_only_(true), |
| 261 preload_ntp_(true), | 295 preload_ntp_(true), |
| 262 model_(this), | 296 model_(this), |
| 263 use_tab_for_suggestions_(false), | 297 use_tab_for_suggestions_(false), |
| 264 last_omnibox_text_has_inline_autocompletion_(false), | 298 last_omnibox_text_has_inline_autocompletion_(false), |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1044 ResetInstantTab(); | 1078 ResetInstantTab(); |
| 1045 } | 1079 } |
| 1046 | 1080 |
| 1047 void InstantController::TabDeactivated(content::WebContents* contents) { | 1081 void InstantController::TabDeactivated(content::WebContents* contents) { |
| 1048 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated"); | 1082 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated"); |
| 1049 if (extended_enabled() && !contents->IsBeingDestroyed()) | 1083 if (extended_enabled() && !contents->IsBeingDestroyed()) |
| 1050 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); | 1084 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
| 1051 | 1085 |
| 1052 if (GetOverlayContents()) | 1086 if (GetOverlayContents()) |
| 1053 HideOverlay(); | 1087 HideOverlay(); |
| 1088 | |
| 1089 NtpLoggingUserData* data = | |
| 1090 NtpLoggingUserData::FromWebContents(contents); | |
| 1091 if (data) { | |
| 1092 data->sum_values_and_log(); | |
| 1093 } | |
|
beaudoin
2013/06/22 01:14:53
Nit: No {}
annark1
2013/06/25 16:01:38
Done.
| |
| 1054 } | 1094 } |
| 1055 | 1095 |
| 1056 void InstantController::SetInstantEnabled(bool instant_enabled, | 1096 void InstantController::SetInstantEnabled(bool instant_enabled, |
| 1057 bool use_local_page_only) { | 1097 bool use_local_page_only) { |
| 1058 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 1098 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 1059 "SetInstantEnabled: instant_enabled=%d, use_local_page_only=%d", | 1099 "SetInstantEnabled: instant_enabled=%d, use_local_page_only=%d", |
| 1060 instant_enabled, use_local_page_only)); | 1100 instant_enabled, use_local_page_only)); |
| 1061 | 1101 |
| 1062 // Non extended mode does not care about |use_local_page_only|. | 1102 // Non extended mode does not care about |use_local_page_only|. |
| 1063 if (instant_enabled == instant_enabled_ && | 1103 if (instant_enabled == instant_enabled_ && |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1593 if (!chrome::ShouldShowInstantNTP()) | 1633 if (!chrome::ShouldShowInstantNTP()) |
| 1594 return; | 1634 return; |
| 1595 | 1635 |
| 1596 // Instant NTP is only used in extended mode so we should always have a | 1636 // Instant NTP is only used in extended mode so we should always have a |
| 1597 // non-empty URL to use. | 1637 // non-empty URL to use. |
| 1598 DCHECK(!instant_url.empty()); | 1638 DCHECK(!instant_url.empty()); |
| 1599 ntp_.reset(new InstantNTP(this, instant_url)); | 1639 ntp_.reset(new InstantNTP(this, instant_url)); |
| 1600 ntp_->InitContents(profile(), browser_->GetActiveWebContents(), | 1640 ntp_->InitContents(profile(), browser_->GetActiveWebContents(), |
| 1601 base::Bind(&InstantController::ReloadStaleNTP, | 1641 base::Bind(&InstantController::ReloadStaleNTP, |
| 1602 base::Unretained(this))); | 1642 base::Unretained(this))); |
| 1643 | |
| 1644 if (ntp_->contents()) { | |
| 1645 NtpLoggingUserData::CreateForWebContents(ntp_->contents()); | |
| 1646 } | |
|
beaudoin
2013/06/22 01:14:53
Nit: no {}
annark1
2013/06/25 16:01:38
Done.
| |
| 1647 | |
| 1603 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 1648 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 1604 "ResetNTP: instant_url='%s'", instant_url.c_str())); | 1649 "ResetNTP: instant_url='%s'", instant_url.c_str())); |
| 1605 } | 1650 } |
| 1606 | 1651 |
| 1607 void InstantController::ReloadStaleNTP() { | 1652 void InstantController::ReloadStaleNTP() { |
| 1608 ResetNTP(GetInstantURL()); | 1653 ResetNTP(GetInstantURL()); |
| 1609 } | 1654 } |
| 1610 | 1655 |
| 1611 bool InstantController::ShouldSwitchToLocalNTP() const { | 1656 bool InstantController::ShouldSwitchToLocalNTP() const { |
| 1612 if (!ntp()) | 1657 if (!ntp()) |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1893 result->relevance = match.relevance; | 1938 result->relevance = match.relevance; |
| 1894 result->autocomplete_match_index = autocomplete_match_index; | 1939 result->autocomplete_match_index = autocomplete_match_index; |
| 1895 | 1940 |
| 1896 DVLOG(1) << " " << result->relevance << " " | 1941 DVLOG(1) << " " << result->relevance << " " |
| 1897 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " | 1942 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " |
| 1898 << result->provider << " " << result->destination_url << " '" | 1943 << result->provider << " " << result->destination_url << " '" |
| 1899 << result->description << "' '" << result->search_query << "' " | 1944 << result->description << "' '" << result->search_query << "' " |
| 1900 << result->transition << " " << result->autocomplete_match_index; | 1945 << result->transition << " " << result->autocomplete_match_index; |
| 1901 } | 1946 } |
| 1902 | 1947 |
| 1948 void InstantController::LogIframeHover(int pos) { | |
| 1949 if (!browser_ || !browser_->GetActiveWebContents()) | |
| 1950 return; | |
| 1951 | |
| 1952 NtpLoggingUserData* data = | |
| 1953 NtpLoggingUserData::FromWebContents(browser_->GetActiveWebContents()); | |
| 1954 if (data) { | |
| 1955 data->increment_iframe_hovers(pos); | |
|
beaudoin
2013/06/22 01:14:53
Do you really have to keep the "pos" here? If you'
annark1
2013/06/25 16:01:38
Yes, I agree that only an int is needed to just lo
| |
| 1956 } | |
| 1957 } | |
| 1958 | |
| 1903 bool InstantController::IsJavascriptEnabled() const { | 1959 bool InstantController::IsJavascriptEnabled() const { |
| 1904 GURL instant_url(GetInstantURL()); | 1960 GURL instant_url(GetInstantURL()); |
| 1905 GURL origin(instant_url.GetOrigin()); | 1961 GURL origin(instant_url.GetOrigin()); |
| 1906 ContentSetting js_setting = profile()->GetHostContentSettingsMap()-> | 1962 ContentSetting js_setting = profile()->GetHostContentSettingsMap()-> |
| 1907 GetContentSetting(origin, origin, CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 1963 GetContentSetting(origin, origin, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 1908 NO_RESOURCE_IDENTIFIER); | 1964 NO_RESOURCE_IDENTIFIER); |
| 1909 // Javascript can be disabled either in content settings or via a WebKit | 1965 // Javascript can be disabled either in content settings or via a WebKit |
| 1910 // preference, so check both. Disabling it through the Settings page affects | 1966 // preference, so check both. Disabling it through the Settings page affects |
| 1911 // content settings. I'm not sure how to disable the WebKit preference, but | 1967 // content settings. I'm not sure how to disable the WebKit preference, but |
| 1912 // it's theoretically possible some users have it off. | 1968 // it's theoretically possible some users have it off. |
| 1913 bool js_content_enabled = | 1969 bool js_content_enabled = |
| 1914 js_setting == CONTENT_SETTING_DEFAULT || | 1970 js_setting == CONTENT_SETTING_DEFAULT || |
| 1915 js_setting == CONTENT_SETTING_ALLOW; | 1971 js_setting == CONTENT_SETTING_ALLOW; |
| 1916 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean( | 1972 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean( |
| 1917 prefs::kWebKitJavascriptEnabled); | 1973 prefs::kWebKitJavascriptEnabled); |
| 1918 return js_content_enabled && js_webkit_enabled; | 1974 return js_content_enabled && js_webkit_enabled; |
| 1919 } | 1975 } |
| 1920 | 1976 |
| 1921 bool InstantController::InStartup() const { | 1977 bool InstantController::InStartup() const { |
| 1922 // TODO(shishir): This is not completely reliable. Find a better way to detect | 1978 // TODO(shishir): This is not completely reliable. Find a better way to detect |
| 1923 // startup time. | 1979 // startup time. |
| 1924 return !browser_->GetActiveWebContents(); | 1980 return !browser_->GetActiveWebContents(); |
| 1925 } | 1981 } |
| OLD | NEW |