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