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/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/extensions/api/web_navigation/web_navigation_api.h" | 8 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
9 #include "chrome/browser/favicon/favicon_tab_helper.h" | 9 #include "chrome/browser/favicon/favicon_tab_helper.h" |
10 #include "chrome/browser/history/history_tab_helper.h" | 10 #include "chrome/browser/history/history_tab_helper.h" |
11 #include "chrome/browser/instant/instant_controller.h" | |
12 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" | 11 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" |
| 12 #include "chrome/browser/tab_contents/tab_util.h" |
13 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 13 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
14 #include "chrome/browser/ui/search/search_tab_helper.h" | 14 #include "chrome/browser/ui/search/search_tab_helper.h" |
15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
16 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | 16 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
19 #include "content/public/browser/render_widget_host_view.h" | 19 #include "content/public/browser/render_widget_host_view.h" |
20 #include "content/public/browser/site_instance.h" | 20 #include "content/public/browser/site_instance.h" |
21 #include "content/public/browser/web_contents_delegate.h" | |
22 #include "content/public/browser/web_contents_view.h" | 21 #include "content/public/browser/web_contents_view.h" |
23 #include "ipc/ipc_message.h" | |
24 | 22 |
25 namespace { | 23 namespace { |
26 | 24 |
27 int kUserDataKey; | 25 const int kStalePageTimeoutMS = 3 * 3600 * 1000; // 3 hours |
28 | 26 |
29 class InstantLoaderUserData : public base::SupportsUserData::Data { | 27 // This HTTP header and value are set on loads that originate from Instant. |
30 public: | 28 const char kInstantHeader[] = "X-Purpose: Instant"; |
31 explicit InstantLoaderUserData(InstantLoader* loader) : loader_(loader) {} | |
32 | 29 |
33 InstantLoader* loader() const { return loader_; } | 30 } // namespace |
34 | 31 |
35 private: | 32 InstantLoader::Delegate::~Delegate() { |
36 ~InstantLoaderUserData() {} | |
37 | |
38 InstantLoader* const loader_; | |
39 | |
40 DISALLOW_COPY_AND_ASSIGN(InstantLoaderUserData); | |
41 }; | |
42 | |
43 } | 33 } |
44 | 34 |
45 // WebContentsDelegateImpl ----------------------------------------------------- | 35 InstantLoader::InstantLoader(Delegate* delegate) |
46 | 36 : delegate_(delegate), |
47 class InstantLoader::WebContentsDelegateImpl | 37 contents_(NULL), |
48 : public CoreTabHelperDelegate, | 38 stale_page_timer_(false, false) { |
49 public content::WebContentsDelegate { | |
50 public: | |
51 explicit WebContentsDelegateImpl(InstantLoader* loader); | |
52 | |
53 private: | |
54 // Overridden from CoreTabHelperDelegate: | |
55 virtual void SwapTabContents(content::WebContents* old_contents, | |
56 content::WebContents* new_contents) OVERRIDE; | |
57 | |
58 // Overridden from content::WebContentsDelegate: | |
59 virtual bool ShouldSuppressDialogs() OVERRIDE; | |
60 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; | |
61 virtual void LostCapture() OVERRIDE; | |
62 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; | |
63 virtual bool CanDownload(content::RenderViewHost* render_view_host, | |
64 int request_id, | |
65 const std::string& request_method) OVERRIDE; | |
66 virtual void HandleMouseDown() OVERRIDE; | |
67 virtual void HandleMouseUp() OVERRIDE; | |
68 virtual void HandlePointerActivate() OVERRIDE; | |
69 virtual void HandleGestureEnd() OVERRIDE; | |
70 virtual void DragEnded() OVERRIDE; | |
71 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; | |
72 virtual content::WebContents* OpenURLFromTab( | |
73 content::WebContents* source, | |
74 const content::OpenURLParams& params) OVERRIDE; | |
75 | |
76 void MaybeCommitFromPointerRelease(); | |
77 | |
78 InstantLoader* const loader_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateImpl); | |
81 }; | |
82 | |
83 InstantLoader::WebContentsDelegateImpl::WebContentsDelegateImpl( | |
84 InstantLoader* loader) | |
85 : loader_(loader) { | |
86 } | |
87 | |
88 void InstantLoader::WebContentsDelegateImpl::SwapTabContents( | |
89 content::WebContents* old_contents, | |
90 content::WebContents* new_contents) { | |
91 // If this is being called, something is swapping in to loader's |contents_| | |
92 // before we've added it to the tab strip. | |
93 loader_->ReplacePreviewContents(old_contents, new_contents); | |
94 } | |
95 | |
96 bool InstantLoader::WebContentsDelegateImpl::ShouldSuppressDialogs() { | |
97 // Any message shown during Instant cancels Instant, so we suppress them. | |
98 return true; | |
99 } | |
100 | |
101 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusPageAfterCrash() { | |
102 return false; | |
103 } | |
104 | |
105 void InstantLoader::WebContentsDelegateImpl::LostCapture() { | |
106 MaybeCommitFromPointerRelease(); | |
107 } | |
108 | |
109 void InstantLoader::WebContentsDelegateImpl::WebContentsFocused( | |
110 content::WebContents* /* contents */) { | |
111 // The preview is getting focus. Equivalent to it being clicked. | |
112 bool tmp = loader_->is_pointer_down_from_activate_; | |
113 loader_->is_pointer_down_from_activate_ = true; | |
114 loader_->controller_->InstantLoaderContentsFocused(); | |
115 loader_->is_pointer_down_from_activate_ = tmp; | |
116 } | |
117 | |
118 bool InstantLoader::WebContentsDelegateImpl::CanDownload( | |
119 content::RenderViewHost* /* render_view_host */, | |
120 int /* request_id */, | |
121 const std::string& /* request_method */) { | |
122 // Downloads are disabled. | |
123 return false; | |
124 } | |
125 | |
126 void InstantLoader::WebContentsDelegateImpl::HandleMouseDown() { | |
127 loader_->is_pointer_down_from_activate_ = true; | |
128 } | |
129 | |
130 void InstantLoader::WebContentsDelegateImpl::HandleMouseUp() { | |
131 MaybeCommitFromPointerRelease(); | |
132 } | |
133 | |
134 void InstantLoader::WebContentsDelegateImpl::HandlePointerActivate() { | |
135 loader_->is_pointer_down_from_activate_ = true; | |
136 } | |
137 | |
138 void InstantLoader::WebContentsDelegateImpl::HandleGestureEnd() { | |
139 MaybeCommitFromPointerRelease(); | |
140 } | |
141 | |
142 void InstantLoader::WebContentsDelegateImpl::DragEnded() { | |
143 // If the user drags, we won't get a mouse up (at least on Linux). Commit the | |
144 // Instant result when the drag ends, so that during the drag the page won't | |
145 // move around. | |
146 MaybeCommitFromPointerRelease(); | |
147 } | |
148 | |
149 bool InstantLoader::WebContentsDelegateImpl::OnGoToEntryOffset(int offset) { | |
150 return false; | |
151 } | |
152 | |
153 content::WebContents* InstantLoader::WebContentsDelegateImpl::OpenURLFromTab( | |
154 content::WebContents* source, | |
155 const content::OpenURLParams& params) { | |
156 content::WebContents* preview = loader_->contents_.get(); | |
157 if (loader_->controller_->CommitIfPossible(INSTANT_COMMIT_NAVIGATED)) | |
158 return preview->GetDelegate()->OpenURLFromTab(source, params); | |
159 return NULL; | |
160 } | |
161 | |
162 void InstantLoader::WebContentsDelegateImpl::MaybeCommitFromPointerRelease() { | |
163 if (loader_->is_pointer_down_from_activate_) { | |
164 loader_->is_pointer_down_from_activate_ = false; | |
165 loader_->controller_->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); | |
166 } | |
167 } | |
168 | |
169 // InstantLoader --------------------------------------------------------------- | |
170 | |
171 // static | |
172 InstantLoader* InstantLoader::FromWebContents( | |
173 const content::WebContents* web_contents) { | |
174 InstantLoaderUserData* data = static_cast<InstantLoaderUserData*>( | |
175 web_contents->GetUserData(&kUserDataKey)); | |
176 return data ? data->loader() : NULL; | |
177 } | |
178 | |
179 InstantLoader::InstantLoader(InstantController* controller, | |
180 const std::string& instant_url) | |
181 : client_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
182 controller_(controller), | |
183 delegate_(new WebContentsDelegateImpl( | |
184 ALLOW_THIS_IN_INITIALIZER_LIST(this))), | |
185 instant_url_(instant_url), | |
186 supports_instant_(false), | |
187 is_pointer_down_from_activate_(false) { | |
188 } | 39 } |
189 | 40 |
190 InstantLoader::~InstantLoader() { | 41 InstantLoader::~InstantLoader() { |
191 } | 42 } |
192 | 43 |
193 void InstantLoader::InitContents(const content::WebContents* active_tab) { | 44 void InstantLoader::Init(const GURL& instant_url, |
194 content::WebContents::CreateParams create_params( | 45 Profile* profile, |
195 active_tab->GetBrowserContext(), | 46 const content::WebContents* active_tab, |
196 active_tab->GetSiteInstance()->GetRelatedSiteInstance( | 47 const base::Closure& on_stale_callback) { |
197 GURL(instant_url_))); | 48 content::WebContents::CreateParams create_params(profile); |
198 if (active_tab) | 49 if (active_tab) { |
199 create_params.initial_size = active_tab->GetView()->GetContainerSize(); | 50 create_params.initial_size = active_tab->GetView()->GetContainerSize(); |
200 contents_.reset(content::WebContents::CreateWithSessionStorage( | 51 create_params.site_instance = active_tab->GetSiteInstance()-> |
201 create_params, | 52 GetRelatedSiteInstance(instant_url); |
202 active_tab->GetController().GetSessionStorageNamespaceMap())); | 53 } else { |
203 SetupPreviewContents(); | 54 create_params.site_instance = content::SiteInstance::CreateForURL( |
| 55 profile, instant_url); |
| 56 } |
| 57 SetContents(scoped_ptr<content::WebContents>( |
| 58 content::WebContents::Create(create_params))); |
| 59 instant_url_ = instant_url; |
| 60 on_stale_callback_ = on_stale_callback; |
| 61 } |
204 | 62 |
205 // This HTTP header and value are set on loads that originate from Instant. | 63 void InstantLoader::Load() { |
206 const char kInstantHeader[] = "X-Purpose: Instant"; | |
207 DVLOG(1) << "LoadURL: " << instant_url_; | 64 DVLOG(1) << "LoadURL: " << instant_url_; |
208 contents_->GetController().LoadURL(GURL(instant_url_), content::Referrer(), | 65 contents_->GetController().LoadURL( |
| 66 instant_url_, content::Referrer(), |
209 content::PAGE_TRANSITION_GENERATED, kInstantHeader); | 67 content::PAGE_TRANSITION_GENERATED, kInstantHeader); |
210 contents_->WasHidden(); | 68 contents_->WasHidden(); |
| 69 stale_page_timer_.Start( |
| 70 FROM_HERE, |
| 71 base::TimeDelta::FromMilliseconds(kStalePageTimeoutMS), |
| 72 on_stale_callback_); |
211 } | 73 } |
212 | 74 |
213 content::WebContents* InstantLoader::ReleaseContents() { | 75 void InstantLoader::SetContents(scoped_ptr<content::WebContents> new_contents) { |
214 CleanupPreviewContents(); | 76 contents_.reset(new_contents.release()); |
215 return contents_.release(); | 77 contents_->SetDelegate(this); |
216 } | |
217 | |
218 void InstantLoader::DidNavigate( | |
219 const history::HistoryAddPageArgs& add_page_args) { | |
220 last_navigation_ = add_page_args; | |
221 } | |
222 | |
223 bool InstantLoader::IsUsingLocalPreview() const { | |
224 return instant_url_ == InstantController::kLocalOmniboxPopupURL; | |
225 } | |
226 | |
227 void InstantLoader::Update(const string16& text, | |
228 size_t selection_start, | |
229 size_t selection_end, | |
230 bool verbatim) { | |
231 last_navigation_ = history::HistoryAddPageArgs(); | |
232 client_.Update(text, selection_start, selection_end, verbatim); | |
233 } | |
234 | |
235 void InstantLoader::Submit(const string16& text) { | |
236 client_.Submit(text); | |
237 } | |
238 | |
239 void InstantLoader::Cancel(const string16& text) { | |
240 client_.Cancel(text); | |
241 } | |
242 | |
243 void InstantLoader::SetPopupBounds(const gfx::Rect& bounds) { | |
244 client_.SetPopupBounds(bounds); | |
245 } | |
246 | |
247 void InstantLoader::SetMarginSize(int start, int end) { | |
248 client_.SetMarginSize(start, end); | |
249 } | |
250 | |
251 void InstantLoader::InitializeFonts() { | |
252 client_.InitializeFonts(); | |
253 } | |
254 | |
255 void InstantLoader::SendAutocompleteResults( | |
256 const std::vector<InstantAutocompleteResult>& results) { | |
257 client_.SendAutocompleteResults(results); | |
258 } | |
259 | |
260 void InstantLoader::UpOrDownKeyPressed(int count) { | |
261 client_.UpOrDownKeyPressed(count); | |
262 } | |
263 | |
264 void InstantLoader::SearchModeChanged(const chrome::search::Mode& mode) { | |
265 client_.SearchModeChanged(mode); | |
266 } | |
267 | |
268 void InstantLoader::SendThemeBackgroundInfo( | |
269 const ThemeBackgroundInfo& theme_info) { | |
270 client_.SendThemeBackgroundInfo(theme_info); | |
271 } | |
272 | |
273 void InstantLoader::SendThemeAreaHeight(int height) { | |
274 client_.SendThemeAreaHeight(height); | |
275 } | |
276 | |
277 void InstantLoader::SetDisplayInstantResults(bool display_instant_results) { | |
278 client_.SetDisplayInstantResults(display_instant_results); | |
279 } | |
280 | |
281 void InstantLoader::KeyCaptureChanged(bool is_key_capture_enabled) { | |
282 client_.KeyCaptureChanged(is_key_capture_enabled); | |
283 } | |
284 | |
285 void InstantLoader::SetSuggestions( | |
286 const std::vector<InstantSuggestion>& suggestions) { | |
287 InstantSupportDetermined(true); | |
288 controller_->SetSuggestions(contents(), suggestions); | |
289 } | |
290 | |
291 void InstantLoader::InstantSupportDetermined(bool supports_instant) { | |
292 // If we had already determined that the page supports Instant, nothing to do. | |
293 if (supports_instant_) | |
294 return; | |
295 | |
296 supports_instant_ = supports_instant; | |
297 controller_->InstantSupportDetermined(contents(), supports_instant); | |
298 } | |
299 | |
300 void InstantLoader::ShowInstantPreview(InstantShownReason reason, | |
301 int height, | |
302 InstantSizeUnits units) { | |
303 InstantSupportDetermined(true); | |
304 controller_->ShowInstantPreview(reason, height, units); | |
305 } | |
306 | |
307 void InstantLoader::StartCapturingKeyStrokes() { | |
308 InstantSupportDetermined(true); | |
309 controller_->StartCapturingKeyStrokes(); | |
310 } | |
311 | |
312 void InstantLoader::StopCapturingKeyStrokes() { | |
313 InstantSupportDetermined(true); | |
314 controller_->StopCapturingKeyStrokes(); | |
315 } | |
316 | |
317 void InstantLoader::RenderViewGone() { | |
318 controller_->InstantLoaderRenderViewGone(); | |
319 } | |
320 | |
321 void InstantLoader::AboutToNavigateMainFrame(const GURL& url) { | |
322 controller_->InstantLoaderAboutToNavigateMainFrame(url); | |
323 } | |
324 | |
325 void InstantLoader::NavigateToURL(const GURL& url, | |
326 content::PageTransition transition) { | |
327 InstantSupportDetermined(true); | |
328 controller_->NavigateToURL(url, transition); | |
329 } | |
330 | |
331 void InstantLoader::RenderViewCreated() { | |
332 controller_->InstantLoaderRenderViewCreated(); | |
333 } | |
334 | |
335 void InstantLoader::Observe(int type, | |
336 const content::NotificationSource& source, | |
337 const content::NotificationDetails& details) { | |
338 #if defined(OS_MACOSX) | |
339 if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) { | |
340 if (content::RenderWidgetHostView* rwhv = | |
341 contents_->GetRenderWidgetHostView()) | |
342 rwhv->SetTakesFocusOnlyOnMouseDown(true); | |
343 return; | |
344 } | |
345 NOTREACHED(); | |
346 #endif | |
347 } | |
348 | |
349 void InstantLoader::SetupPreviewContents() { | |
350 client_.SetContents(contents()); | |
351 contents_->SetUserData(&kUserDataKey, new InstantLoaderUserData(this)); | |
352 contents_->SetDelegate(delegate_.get()); | |
353 | 78 |
354 // Set up various tab helpers. The rest will get attached when (if) the | 79 // Set up various tab helpers. The rest will get attached when (if) the |
355 // contents is added to the tab strip. | 80 // contents is added to the tab strip. |
356 | 81 |
357 // Tab helpers to control popups. | 82 // Tab helpers to control popups. |
358 BlockedContentTabHelper::CreateForWebContents(contents()); | 83 BlockedContentTabHelper::CreateForWebContents(contents()); |
359 BlockedContentTabHelper::FromWebContents(contents())-> | 84 BlockedContentTabHelper::FromWebContents(contents())-> |
360 SetAllContentsBlocked(true); | 85 SetAllContentsBlocked(true); |
361 TabSpecificContentSettings::CreateForWebContents(contents()); | 86 TabSpecificContentSettings::CreateForWebContents(contents()); |
362 TabSpecificContentSettings::FromWebContents(contents())-> | 87 TabSpecificContentSettings::FromWebContents(contents())-> |
363 SetPopupsBlocked(true); | 88 SetPopupsBlocked(true); |
364 | 89 |
365 // A tab helper to catch prerender content swapping shenanigans. | 90 // A tab helper to catch prerender content swapping shenanigans. |
366 CoreTabHelper::CreateForWebContents(contents()); | 91 CoreTabHelper::CreateForWebContents(contents()); |
367 CoreTabHelper::FromWebContents(contents())->set_delegate(delegate_.get()); | 92 CoreTabHelper::FromWebContents(contents())->set_delegate(this); |
368 | 93 |
369 // Tab helpers used when committing a preview. | 94 // Tab helpers used when committing a preview. |
370 chrome::search::SearchTabHelper::CreateForWebContents(contents()); | 95 chrome::search::SearchTabHelper::CreateForWebContents(contents()); |
371 HistoryTabHelper::CreateForWebContents(contents()); | 96 HistoryTabHelper::CreateForWebContents(contents()); |
372 | 97 |
373 // Observers. | 98 // Observers. |
374 extensions::WebNavigationTabObserver::CreateForWebContents(contents()); | 99 extensions::WebNavigationTabObserver::CreateForWebContents(contents()); |
375 | 100 |
376 // Favicons, required by the Task Manager. | 101 // Favicons, required by the Task Manager. |
377 FaviconTabHelper::CreateForWebContents(contents()); | 102 FaviconTabHelper::CreateForWebContents(contents()); |
378 | 103 |
379 // And some flat-out paranoia. | 104 // And some flat-out paranoia. |
380 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(contents()); | 105 safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(contents()); |
381 | 106 |
382 #if defined(OS_MACOSX) | 107 #if defined(OS_MACOSX) |
383 // If |contents_| doesn't yet have a RWHV, SetTakesFocusOnlyOnMouseDown() will | 108 // If |contents_| doesn't yet have a RWHV, SetTakesFocusOnlyOnMouseDown() will |
384 // be called later, when NOTIFICATION_RENDER_VIEW_HOST_CHANGED is received. | 109 // be called later, when NOTIFICATION_RENDER_VIEW_HOST_CHANGED is received. |
385 if (content::RenderWidgetHostView* rwhv = | 110 if (content::RenderWidgetHostView* rwhv = |
386 contents_->GetRenderWidgetHostView()) | 111 contents_->GetRenderWidgetHostView()) |
387 rwhv->SetTakesFocusOnlyOnMouseDown(true); | 112 rwhv->SetTakesFocusOnlyOnMouseDown(true); |
388 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 113 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
389 content::Source<content::NavigationController>( | 114 content::Source<content::NavigationController>( |
390 &contents_->GetController())); | 115 &contents_->GetController())); |
391 #endif | 116 #endif |
392 } | 117 } |
393 | 118 |
394 void InstantLoader::CleanupPreviewContents() { | 119 scoped_ptr<content::WebContents> InstantLoader::ReleaseContents() { |
395 client_.SetContents(NULL); | |
396 contents_->RemoveUserData(&kUserDataKey); | |
397 contents_->SetDelegate(NULL); | 120 contents_->SetDelegate(NULL); |
398 | 121 |
399 // Undo tab helper work done in SetupPreviewContents(). | 122 // Undo tab helper work done in SetContents(). |
400 | 123 |
401 BlockedContentTabHelper::FromWebContents(contents())-> | 124 BlockedContentTabHelper::FromWebContents(contents())-> |
402 SetAllContentsBlocked(false); | 125 SetAllContentsBlocked(false); |
403 TabSpecificContentSettings::FromWebContents(contents())-> | 126 TabSpecificContentSettings::FromWebContents(contents())-> |
404 SetPopupsBlocked(false); | 127 SetPopupsBlocked(false); |
405 | 128 |
406 CoreTabHelper::FromWebContents(contents())->set_delegate(NULL); | 129 CoreTabHelper::FromWebContents(contents())->set_delegate(NULL); |
407 | 130 |
408 #if defined(OS_MACOSX) | 131 #if defined(OS_MACOSX) |
409 if (content::RenderWidgetHostView* rwhv = | 132 if (content::RenderWidgetHostView* rwhv = |
410 contents_->GetRenderWidgetHostView()) | 133 contents_->GetRenderWidgetHostView()) |
411 rwhv->SetTakesFocusOnlyOnMouseDown(false); | 134 rwhv->SetTakesFocusOnlyOnMouseDown(false); |
412 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 135 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
413 content::Source<content::NavigationController>( | 136 content::Source<content::NavigationController>( |
414 &contents_->GetController())); | 137 &contents_->GetController())); |
415 #endif | 138 #endif |
| 139 |
| 140 return contents_.Pass(); |
416 } | 141 } |
417 | 142 |
418 void InstantLoader::ReplacePreviewContents(content::WebContents* old_contents, | 143 void InstantLoader::Observe(int type, |
419 content::WebContents* new_contents) { | 144 const content::NotificationSource& /* source */, |
| 145 const content::NotificationDetails& /* details */) { |
| 146 #if defined(OS_MACOSX) |
| 147 if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) { |
| 148 if (content::RenderWidgetHostView* rwhv = |
| 149 contents_->GetRenderWidgetHostView()) |
| 150 rwhv->SetTakesFocusOnlyOnMouseDown(true); |
| 151 return; |
| 152 } |
| 153 NOTREACHED(); |
| 154 #endif |
| 155 } |
| 156 |
| 157 void InstantLoader::SwapTabContents(content::WebContents* old_contents, |
| 158 content::WebContents* new_contents) { |
420 DCHECK_EQ(old_contents, contents()); | 159 DCHECK_EQ(old_contents, contents()); |
421 CleanupPreviewContents(); | 160 // We release here without deleting since the caller has the responsibility |
422 // We release here without deleting so that the caller still has the | 161 // for deleting the old WebContents. |
423 // responsibility for deleting the WebContents. | 162 ignore_result(ReleaseContents().release()); |
424 ignore_result(contents_.release()); | 163 SetContents(scoped_ptr<content::WebContents>(new_contents)); |
425 contents_.reset(new_contents); | 164 delegate_->OnSwappedContents(); |
426 SetupPreviewContents(); | |
427 controller_->SwappedWebContents(); | |
428 } | 165 } |
| 166 |
| 167 bool InstantLoader::ShouldSuppressDialogs() { |
| 168 // Messages shown during Instant cancel Instant, so we suppress them. |
| 169 return true; |
| 170 } |
| 171 |
| 172 bool InstantLoader::ShouldFocusPageAfterCrash() { |
| 173 return false; |
| 174 } |
| 175 |
| 176 void InstantLoader::LostCapture() { |
| 177 delegate_->OnMouseUp(); |
| 178 } |
| 179 |
| 180 void InstantLoader::WebContentsFocused(content::WebContents* /* contents */) { |
| 181 delegate_->OnFocus(); |
| 182 } |
| 183 |
| 184 bool InstantLoader::CanDownload(content::RenderViewHost* /* render_view_host */, |
| 185 int /* request_id */, |
| 186 const std::string& /* request_method */) { |
| 187 // Downloads are disabled. |
| 188 return false; |
| 189 } |
| 190 |
| 191 void InstantLoader::HandleMouseDown() { |
| 192 delegate_->OnMouseDown(); |
| 193 } |
| 194 |
| 195 void InstantLoader::HandleMouseUp() { |
| 196 delegate_->OnMouseUp(); |
| 197 } |
| 198 |
| 199 void InstantLoader::HandlePointerActivate() { |
| 200 delegate_->OnMouseDown(); |
| 201 } |
| 202 |
| 203 void InstantLoader::HandleGestureEnd() { |
| 204 delegate_->OnMouseUp(); |
| 205 } |
| 206 |
| 207 void InstantLoader::DragEnded() { |
| 208 // If the user drags, we won't get a mouse up (at least on Linux). Commit |
| 209 // the Instant result when the drag ends, so that during the drag the page |
| 210 // won't move around. |
| 211 delegate_->OnMouseUp(); |
| 212 } |
| 213 |
| 214 bool InstantLoader::OnGoToEntryOffset(int /* offset */) { |
| 215 return false; |
| 216 } |
| 217 |
| 218 content::WebContents* InstantLoader::OpenURLFromTab( |
| 219 content::WebContents* source, |
| 220 const content::OpenURLParams& params) { |
| 221 return delegate_->OpenURLFromTab(source, params); |
| 222 } |
OLD | NEW |