Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: chrome/browser/instant/instant_loader.cc

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

Powered by Google App Engine
This is Rietveld 408576698