OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/webview/webview.h" | 5 #include "ui/views/controls/webview/webview.h" |
6 | 6 |
7 #include "content/public/browser/browser_context.h" | 7 #include "content/public/browser/browser_context.h" |
8 #include "content/public/browser/navigation_controller.h" | 8 #include "content/public/browser/navigation_controller.h" |
9 #include "content/public/browser/notification_details.h" | 9 #include "content/public/browser/notification_details.h" |
10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // Prevents attachment if the WebView isn't already in a Widget, or it's | 173 // Prevents attachment if the WebView isn't already in a Widget, or it's |
174 // already attached. | 174 // already attached. |
175 if (!GetWidget() || !web_contents_ || | 175 if (!GetWidget() || !web_contents_ || |
176 wcv_holder_->native_view() == web_contents_->GetNativeView()) { | 176 wcv_holder_->native_view() == web_contents_->GetNativeView()) { |
177 return; | 177 return; |
178 } | 178 } |
179 | 179 |
180 if (web_contents_) { | 180 if (web_contents_) { |
181 wcv_holder_->Attach(web_contents_->GetNativeView()); | 181 wcv_holder_->Attach(web_contents_->GetNativeView()); |
182 | 182 |
183 // The WebContentsView will not be focused automatically when it is | |
184 // attached, so we need to pass on focus to it if the FocusManager thinks | |
185 // the WebView is focused. | |
186 if (GetFocusManager()->GetFocusedView() == this) | |
187 web_contents_->Focus(); | |
188 | |
189 registrar_.Add( | 183 registrar_.Add( |
190 this, | 184 this, |
191 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 185 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
192 content::Source<content::NavigationController>( | 186 content::Source<content::NavigationController>( |
193 &web_contents_->GetController())); | 187 &web_contents_->GetController())); |
194 registrar_.Add( | 188 registrar_.Add( |
195 this, | 189 this, |
196 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 190 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
197 content::Source<content::WebContents>(web_contents_)); | 191 content::Source<content::WebContents>(web_contents_)); |
198 } | 192 } |
(...skipping 18 matching lines...) Expand all Loading... |
217 if (GetFocusManager()->GetFocusedView() == this) | 211 if (GetFocusManager()->GetFocusedView() == this) |
218 web_contents_->Focus(); | 212 web_contents_->Focus(); |
219 } | 213 } |
220 | 214 |
221 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { | 215 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { |
222 DCHECK(web_contents == web_contents_); | 216 DCHECK(web_contents == web_contents_); |
223 SetWebContents(NULL); | 217 SetWebContents(NULL); |
224 } | 218 } |
225 | 219 |
226 } // namespace views | 220 } // namespace views |
OLD | NEW |