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 "chrome/browser/content_settings/tab_specific_content_settings.h" | 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
8 #include "chrome/browser/instant/instant_loader_delegate.h" | 8 #include "chrome/browser/instant/instant_controller.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" | 10 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" |
11 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 11 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
12 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 12 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
13 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" | 13 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" |
14 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 14 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
15 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | 15 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" |
16 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
(...skipping 10 matching lines...) Expand all Loading... |
29 | 29 |
30 class InstantLoaderUserData : public base::SupportsUserData::Data { | 30 class InstantLoaderUserData : public base::SupportsUserData::Data { |
31 public: | 31 public: |
32 explicit InstantLoaderUserData(InstantLoader* loader) : loader_(loader) {} | 32 explicit InstantLoaderUserData(InstantLoader* loader) : loader_(loader) {} |
33 virtual ~InstantLoaderUserData() {} | 33 virtual ~InstantLoaderUserData() {} |
34 | 34 |
35 InstantLoader* loader() const { return loader_; } | 35 InstantLoader* loader() const { return loader_; } |
36 | 36 |
37 private: | 37 private: |
38 InstantLoader* loader_; | 38 InstantLoader* loader_; |
39 DISALLOW_IMPLICIT_CONSTRUCTORS(InstantLoaderUserData); | 39 DISALLOW_COPY_AND_ASSIGN(InstantLoaderUserData); |
40 }; | 40 }; |
41 | 41 |
42 } | 42 } |
43 | 43 |
44 // WebContentsDelegateImpl ----------------------------------------------------- | 44 // WebContentsDelegateImpl ----------------------------------------------------- |
45 | 45 |
46 class InstantLoader::WebContentsDelegateImpl | 46 class InstantLoader::WebContentsDelegateImpl |
47 : public ConstrainedWindowTabHelperDelegate, | 47 : public ConstrainedWindowTabHelperDelegate, |
48 public CoreTabHelperDelegate, | 48 public CoreTabHelperDelegate, |
49 public content::WebContentsDelegate, | 49 public content::WebContentsDelegate, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 InstantSizeUnits units); | 101 InstantSizeUnits units); |
102 | 102 |
103 void CommitFromPointerReleaseIfNecessary(); | 103 void CommitFromPointerReleaseIfNecessary(); |
104 void MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant); | 104 void MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant); |
105 | 105 |
106 InstantLoader* const loader_; | 106 InstantLoader* const loader_; |
107 | 107 |
108 // True if the mouse or a touch pointer is down from an activate. | 108 // True if the mouse or a touch pointer is down from an activate. |
109 bool is_pointer_down_from_activate_; | 109 bool is_pointer_down_from_activate_; |
110 | 110 |
111 DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsDelegateImpl); | 111 DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateImpl); |
112 }; | 112 }; |
113 | 113 |
114 InstantLoader::WebContentsDelegateImpl::WebContentsDelegateImpl( | 114 InstantLoader::WebContentsDelegateImpl::WebContentsDelegateImpl( |
115 InstantLoader* loader) | 115 InstantLoader* loader) |
116 : content::WebContentsObserver(loader->preview_contents_->web_contents()), | 116 : content::WebContentsObserver(loader->preview_contents_->web_contents()), |
117 loader_(loader), | 117 loader_(loader), |
118 is_pointer_down_from_activate_(false) { | 118 is_pointer_down_from_activate_(false) { |
119 } | 119 } |
120 | 120 |
121 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusConstrainedWindow() { | 121 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusConstrainedWindow() { |
(...skipping 19 matching lines...) Expand all Loading... |
141 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusPageAfterCrash() { | 141 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusPageAfterCrash() { |
142 return false; | 142 return false; |
143 } | 143 } |
144 | 144 |
145 void InstantLoader::WebContentsDelegateImpl::LostCapture() { | 145 void InstantLoader::WebContentsDelegateImpl::LostCapture() { |
146 CommitFromPointerReleaseIfNecessary(); | 146 CommitFromPointerReleaseIfNecessary(); |
147 } | 147 } |
148 | 148 |
149 void InstantLoader::WebContentsDelegateImpl::WebContentsFocused( | 149 void InstantLoader::WebContentsDelegateImpl::WebContentsFocused( |
150 content::WebContents* contents) { | 150 content::WebContents* contents) { |
151 loader_->loader_delegate_->InstantLoaderContentsFocused(loader_); | 151 loader_->controller_->InstantLoaderContentsFocused(loader_); |
152 } | 152 } |
153 | 153 |
154 bool InstantLoader::WebContentsDelegateImpl::CanDownload( | 154 bool InstantLoader::WebContentsDelegateImpl::CanDownload( |
155 content::RenderViewHost* render_view_host, | 155 content::RenderViewHost* render_view_host, |
156 int request_id, | 156 int request_id, |
157 const std::string& request_method) { | 157 const std::string& request_method) { |
158 // Downloads are disabled. | 158 // Downloads are disabled. |
159 return false; | 159 return false; |
160 } | 160 } |
161 | 161 |
(...skipping 28 matching lines...) Expand all Loading... |
190 } | 190 } |
191 | 191 |
192 void InstantLoader::WebContentsDelegateImpl::DidFinishLoad( | 192 void InstantLoader::WebContentsDelegateImpl::DidFinishLoad( |
193 int64 frame_id, | 193 int64 frame_id, |
194 const GURL& validated_url, | 194 const GURL& validated_url, |
195 bool is_main_frame, | 195 bool is_main_frame, |
196 content::RenderViewHost* render_view_host) { | 196 content::RenderViewHost* render_view_host) { |
197 if (is_main_frame) { | 197 if (is_main_frame) { |
198 if (!loader_->supports_instant_) | 198 if (!loader_->supports_instant_) |
199 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); | 199 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
200 loader_->loader_delegate_->InstantLoaderPreviewLoaded(loader_); | 200 loader_->controller_->InstantLoaderPreviewLoaded(loader_); |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 bool InstantLoader::WebContentsDelegateImpl::OnMessageReceived( | 204 bool InstantLoader::WebContentsDelegateImpl::OnMessageReceived( |
205 const IPC::Message& message) { | 205 const IPC::Message& message) { |
206 bool handled = true; | 206 bool handled = true; |
207 IPC_BEGIN_MESSAGE_MAP(WebContentsDelegateImpl, message) | 207 IPC_BEGIN_MESSAGE_MAP(WebContentsDelegateImpl, message) |
208 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) | 208 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) |
209 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, | 209 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
210 OnInstantSupportDetermined) | 210 OnInstantSupportDetermined) |
211 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantPreview, | 211 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantPreview, |
212 OnShowInstantPreview); | 212 OnShowInstantPreview); |
213 IPC_MESSAGE_UNHANDLED(handled = false) | 213 IPC_MESSAGE_UNHANDLED(handled = false) |
214 IPC_END_MESSAGE_MAP() | 214 IPC_END_MESSAGE_MAP() |
215 return handled; | 215 return handled; |
216 } | 216 } |
217 | 217 |
218 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions( | 218 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions( |
219 int page_id, | 219 int page_id, |
220 const std::vector<InstantSuggestion>& suggestions) { | 220 const std::vector<InstantSuggestion>& suggestions) { |
221 DCHECK(loader_->preview_contents()); | 221 DCHECK(loader_->preview_contents()); |
222 DCHECK(loader_->preview_contents_->web_contents()); | 222 DCHECK(loader_->preview_contents_->web_contents()); |
223 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> | 223 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
224 GetController().GetActiveEntry(); | 224 GetController().GetActiveEntry(); |
225 if (entry && page_id == entry->GetPageID()) { | 225 if (entry && page_id == entry->GetPageID()) { |
226 MaybeSetAndNotifyInstantSupportDetermined(true); | 226 MaybeSetAndNotifyInstantSupportDetermined(true); |
227 loader_->loader_delegate_->SetSuggestions(loader_, suggestions); | 227 loader_->controller_->SetSuggestions(loader_, suggestions); |
228 } | 228 } |
229 } | 229 } |
230 | 230 |
231 void InstantLoader::WebContentsDelegateImpl::OnInstantSupportDetermined( | 231 void InstantLoader::WebContentsDelegateImpl::OnInstantSupportDetermined( |
232 int page_id, | 232 int page_id, |
233 bool result) { | 233 bool result) { |
234 DCHECK(loader_->preview_contents()); | 234 DCHECK(loader_->preview_contents()); |
235 DCHECK(loader_->preview_contents_->web_contents()); | 235 DCHECK(loader_->preview_contents_->web_contents()); |
236 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> | 236 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
237 GetController().GetActiveEntry(); | 237 GetController().GetActiveEntry(); |
238 if (entry && page_id == entry->GetPageID()) | 238 if (entry && page_id == entry->GetPageID()) |
239 MaybeSetAndNotifyInstantSupportDetermined(result); | 239 MaybeSetAndNotifyInstantSupportDetermined(result); |
240 } | 240 } |
241 | 241 |
242 void InstantLoader::WebContentsDelegateImpl::OnShowInstantPreview( | 242 void InstantLoader::WebContentsDelegateImpl::OnShowInstantPreview( |
243 int page_id, | 243 int page_id, |
244 InstantShownReason reason, | 244 InstantShownReason reason, |
245 int height, | 245 int height, |
246 InstantSizeUnits units) { | 246 InstantSizeUnits units) { |
247 DCHECK(loader_->preview_contents()); | 247 DCHECK(loader_->preview_contents()); |
248 DCHECK(loader_->preview_contents_->web_contents()); | 248 DCHECK(loader_->preview_contents_->web_contents()); |
249 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> | 249 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
250 GetController().GetActiveEntry(); | 250 GetController().GetActiveEntry(); |
251 if (entry && page_id == entry->GetPageID()) { | 251 if (entry && page_id == entry->GetPageID()) { |
252 MaybeSetAndNotifyInstantSupportDetermined(true); | 252 MaybeSetAndNotifyInstantSupportDetermined(true); |
253 loader_->loader_delegate_->ShowInstantPreview(loader_, | 253 loader_->controller_->ShowInstantPreview(loader_, reason, height, units); |
254 reason, height, units); | |
255 } | 254 } |
256 } | 255 } |
257 | 256 |
258 void InstantLoader::WebContentsDelegateImpl | 257 void InstantLoader::WebContentsDelegateImpl |
259 ::CommitFromPointerReleaseIfNecessary() { | 258 ::CommitFromPointerReleaseIfNecessary() { |
260 if (is_pointer_down_from_activate_) { | 259 if (is_pointer_down_from_activate_) { |
261 is_pointer_down_from_activate_ = false; | 260 is_pointer_down_from_activate_ = false; |
262 loader_->loader_delegate_->CommitInstantLoader(loader_); | 261 loader_->controller_->CommitInstantLoader(loader_); |
263 } | 262 } |
264 } | 263 } |
265 | 264 |
266 void InstantLoader::WebContentsDelegateImpl | 265 void InstantLoader::WebContentsDelegateImpl |
267 ::MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant) { | 266 ::MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant) { |
268 // If we already determined that the loader supports Instant, nothing to do. | 267 // If we already determined that the loader supports Instant, nothing to do. |
269 if (loader_->supports_instant_) | 268 if (loader_->supports_instant_) |
270 return; | 269 return; |
271 | 270 |
272 // If the page doesn't support the Instant API, InstantController schedules | 271 // If the page doesn't support the Instant API, InstantController schedules |
273 // the loader for destruction. Stop sending the controller any more messages, | 272 // the loader for destruction. Stop sending the controller any more messages, |
274 // by severing the connection from the WebContents to us (its delegate). | 273 // by severing the connection from the WebContents to us (its delegate). |
275 if (!supports_instant) { | 274 if (!supports_instant) { |
276 loader_->preview_contents_->web_contents()->SetDelegate(NULL); | 275 loader_->preview_contents_->web_contents()->SetDelegate(NULL); |
277 Observe(NULL); | 276 Observe(NULL); |
278 } | 277 } |
279 | 278 |
280 loader_->supports_instant_ = supports_instant; | 279 loader_->supports_instant_ = supports_instant; |
281 loader_->loader_delegate_->InstantSupportDetermined(loader_, | 280 loader_->controller_->InstantSupportDetermined(loader_, supports_instant); |
282 supports_instant); | |
283 } | 281 } |
284 | 282 |
285 // InstantLoader --------------------------------------------------------------- | 283 // InstantLoader --------------------------------------------------------------- |
286 | 284 |
287 // static | 285 // static |
288 InstantLoader* InstantLoader::FromWebContents( | 286 InstantLoader* InstantLoader::FromWebContents( |
289 content::WebContents* web_contents) { | 287 content::WebContents* web_contents) { |
290 InstantLoaderUserData* data = static_cast<InstantLoaderUserData*>( | 288 InstantLoaderUserData* data = static_cast<InstantLoaderUserData*>( |
291 web_contents->GetUserData(&kUserDataKey)); | 289 web_contents->GetUserData(&kUserDataKey)); |
292 return data ? data->loader() : NULL; | 290 return data ? data->loader() : NULL; |
293 } | 291 } |
294 | 292 |
295 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, | 293 InstantLoader::InstantLoader(InstantController* controller, |
296 const std::string& instant_url, | 294 const std::string& instant_url, |
297 const TabContents* tab_contents) | 295 const TabContents* tab_contents) |
298 : loader_delegate_(delegate), | 296 : controller_(controller), |
299 preview_contents_( | 297 preview_contents_( |
300 TabContents::Factory::CreateTabContents( | 298 TabContents::Factory::CreateTabContents( |
301 content::WebContents::CreateWithSessionStorage( | 299 content::WebContents::CreateWithSessionStorage( |
302 tab_contents->profile(), NULL, MSG_ROUTING_NONE, | 300 tab_contents->profile(), NULL, MSG_ROUTING_NONE, |
303 tab_contents->web_contents(), | 301 tab_contents->web_contents(), |
304 tab_contents->web_contents()->GetController(). | 302 tab_contents->web_contents()->GetController(). |
305 GetSessionStorageNamespaceMap()))), | 303 GetSessionStorageNamespaceMap()))), |
306 supports_instant_(false), | 304 supports_instant_(false), |
307 instant_url_(instant_url) { | 305 instant_url_(instant_url) { |
308 } | 306 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 466 |
469 void InstantLoader::ReplacePreviewContents(content::WebContents* old_contents, | 467 void InstantLoader::ReplacePreviewContents(content::WebContents* old_contents, |
470 content::WebContents* new_contents) { | 468 content::WebContents* new_contents) { |
471 DCHECK_EQ(old_contents, preview_contents_->web_contents()); | 469 DCHECK_EQ(old_contents, preview_contents_->web_contents()); |
472 CleanupPreviewContents(); | 470 CleanupPreviewContents(); |
473 // We release here without deleting so that the caller still has the | 471 // We release here without deleting so that the caller still has the |
474 // responsibility for deleting the TabContents. | 472 // responsibility for deleting the TabContents. |
475 ignore_result(preview_contents_.release()); | 473 ignore_result(preview_contents_.release()); |
476 preview_contents_.reset(TabContents::FromWebContents(new_contents)); | 474 preview_contents_.reset(TabContents::FromWebContents(new_contents)); |
477 SetupPreviewContents(); | 475 SetupPreviewContents(); |
478 loader_delegate_->SwappedTabContents(this); | 476 controller_->SwappedTabContents(this); |
479 } | 477 } |
OLD | NEW |