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