| OLD | NEW |
| 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/instant/instant_loader.h" | 5 #include "chrome/browser/instant/instant_loader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // Only track the histogram for the instant loaders, for now. | 86 // Only track the histogram for the instant loaders, for now. |
| 87 if (template_url_id) { | 87 if (template_url_id) { |
| 88 base::Histogram* histogram = base::LinearHistogram::FactoryGet( | 88 base::Histogram* histogram = base::LinearHistogram::FactoryGet( |
| 89 "Instant.Previews" + group, 1, PREVIEW_NUM_TYPES, PREVIEW_NUM_TYPES + 1, | 89 "Instant.Previews" + group, 1, PREVIEW_NUM_TYPES, PREVIEW_NUM_TYPES + 1, |
| 90 base::Histogram::kUmaTargetedHistogramFlag); | 90 base::Histogram::kUmaTargetedHistogramFlag); |
| 91 histogram->Add(usage); | 91 histogram->Add(usage); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 SessionStorageNamespace* GetSessionStorageNamespace(TabContents* tab) { | 95 SessionStorageNamespace* GetSessionStorageNamespace(TabContents* tab) { |
| 96 return tab->web_contents()->GetController().GetSessionStorageNamespace(); | 96 // TODO(ajwong): This is wrong because it assumes a default |
| 97 // SessionStorageNamespace for a TabContents. |
| 98 // |
| 99 // http://crbug.com/140612 |
| 100 return tab->web_contents()->GetController() |
| 101 .GetSessionStorageNamespaceMap().find("")->second; |
| 97 } | 102 } |
| 98 | 103 |
| 99 } // namespace | 104 } // namespace |
| 100 | 105 |
| 101 // static | 106 // static |
| 102 const char* const InstantLoader::kInstantHeader = "X-Purpose"; | 107 const char* const InstantLoader::kInstantHeader = "X-Purpose"; |
| 103 // static | 108 // static |
| 104 const char* const InstantLoader::kInstantHeaderValue = "instant"; | 109 const char* const InstantLoader::kInstantHeaderValue = "instant"; |
| 105 | 110 |
| 106 // FrameLoadObserver is responsible for determining if the page supports | 111 // FrameLoadObserver is responsible for determining if the page supports |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 #endif | 848 #endif |
| 844 } | 849 } |
| 845 preview_contents_->web_contents()->SetDelegate(NULL); | 850 preview_contents_->web_contents()->SetDelegate(NULL); |
| 846 ready_ = false; | 851 ready_ = false; |
| 847 } | 852 } |
| 848 update_bounds_timer_.Stop(); | 853 update_bounds_timer_.Stop(); |
| 849 AddPreviewUsageForHistogram(template_url_id_, | 854 AddPreviewUsageForHistogram(template_url_id_, |
| 850 type == INSTANT_COMMIT_DESTROY ? PREVIEW_DELETED : PREVIEW_COMMITTED, | 855 type == INSTANT_COMMIT_DESTROY ? PREVIEW_DELETED : PREVIEW_COMMITTED, |
| 851 group_); | 856 group_); |
| 852 if (type != INSTANT_COMMIT_DESTROY) { | 857 if (type != INSTANT_COMMIT_DESTROY) { |
| 858 // This tracks the number of times a committed preview page destroys the |
| 859 // Session Storage for the tab. |
| 853 base::Histogram* histogram = base::LinearHistogram::FactoryGet( | 860 base::Histogram* histogram = base::LinearHistogram::FactoryGet( |
| 854 "Instant.SessionStorageNamespace" + group_, 1, 2, 3, | 861 "Instant.SessionStorageNamespace" + group_, 1, 2, 3, |
| 855 base::Histogram::kUmaTargetedHistogramFlag); | 862 base::Histogram::kUmaTargetedHistogramFlag); |
| 856 histogram->Add(tab_contents == NULL || session_storage_namespace_ == | 863 histogram->Add(tab_contents == NULL || session_storage_namespace_ == |
| 857 GetSessionStorageNamespace(tab_contents)); | 864 GetSessionStorageNamespace(tab_contents)); |
| 858 // Now that the ownership is being passed to the caller, the thumbnailer | 865 // Now that the ownership is being passed to the caller, the thumbnailer |
| 859 // needs to resume taking thumbnails. | 866 // needs to resume taking thumbnails. |
| 860 if (preview_contents_->thumbnail_generator()) | 867 if (preview_contents_->thumbnail_generator()) |
| 861 preview_contents_->thumbnail_generator()->set_enabled(true); | 868 preview_contents_->thumbnail_generator()->set_enabled(true); |
| 862 } | 869 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 preview_contents_->web_contents()->GetView()->SizeContents(tab_bounds.size()); | 1143 preview_contents_->web_contents()->GetView()->SizeContents(tab_bounds.size()); |
| 1137 | 1144 |
| 1138 // Carry over the user agent override string. | 1145 // Carry over the user agent override string. |
| 1139 const std::string& override = | 1146 const std::string& override = |
| 1140 tab_contents->web_contents()->GetUserAgentOverride(); | 1147 tab_contents->web_contents()->GetUserAgentOverride(); |
| 1141 preview_contents_->web_contents()->SetUserAgentOverride(override); | 1148 preview_contents_->web_contents()->SetUserAgentOverride(override); |
| 1142 } | 1149 } |
| 1143 | 1150 |
| 1144 void InstantLoader::CreatePreviewContents(TabContents* tab_contents) { | 1151 void InstantLoader::CreatePreviewContents(TabContents* tab_contents) { |
| 1145 WebContents* new_contents = WebContents::Create( | 1152 WebContents* new_contents = WebContents::Create( |
| 1146 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1153 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL); |
| 1147 preview_contents_.reset(new TabContents(new_contents)); | 1154 preview_contents_.reset(new TabContents(new_contents)); |
| 1148 AddPreviewUsageForHistogram(template_url_id_, PREVIEW_CREATED, group_); | 1155 AddPreviewUsageForHistogram(template_url_id_, PREVIEW_CREATED, group_); |
| 1149 session_storage_namespace_ = GetSessionStorageNamespace(tab_contents); | 1156 session_storage_namespace_ = GetSessionStorageNamespace(tab_contents); |
| 1150 preview_tab_contents_delegate_.reset(new WebContentsDelegateImpl(this)); | 1157 preview_tab_contents_delegate_.reset(new WebContentsDelegateImpl(this)); |
| 1151 SetupPreviewContents(tab_contents); | 1158 SetupPreviewContents(tab_contents); |
| 1152 | 1159 |
| 1153 // TODO(beng): investigate if we can avoid this and instead rely on the | 1160 // TODO(beng): investigate if we can avoid this and instead rely on the |
| 1154 // visibility of the WebContentsView | 1161 // visibility of the WebContentsView |
| 1155 preview_contents_->web_contents()->WasShown(); | 1162 preview_contents_->web_contents()->WasShown(); |
| 1156 } | 1163 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 host->Send(new ChromeViewMsg_SearchBoxResize( | 1200 host->Send(new ChromeViewMsg_SearchBoxResize( |
| 1194 host->GetRoutingID(), GetOmniboxBoundsInTermsOfPreview())); | 1201 host->GetRoutingID(), GetOmniboxBoundsInTermsOfPreview())); |
| 1195 } else { | 1202 } else { |
| 1196 host->Send(new ChromeViewMsg_SearchBoxChange( | 1203 host->Send(new ChromeViewMsg_SearchBoxChange( |
| 1197 host->GetRoutingID(), user_text, verbatim, 0, 0)); | 1204 host->GetRoutingID(), user_text, verbatim, 0, 0)); |
| 1198 } | 1205 } |
| 1199 | 1206 |
| 1200 frame_load_observer_.reset(new FrameLoadObserver( | 1207 frame_load_observer_.reset(new FrameLoadObserver( |
| 1201 this, preview_contents()->web_contents(), user_text, verbatim)); | 1208 this, preview_contents()->web_contents(), user_text, verbatim)); |
| 1202 } | 1209 } |
| OLD | NEW |