| 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 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 content::WebContents* WebView::GetWebContents() { | 41 content::WebContents* WebView::GetWebContents() { |
| 42 CreateWebContentsWithSiteInstance(NULL); | 42 CreateWebContentsWithSiteInstance(NULL); |
| 43 return web_contents_; | 43 return web_contents_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void WebView::CreateWebContentsWithSiteInstance( | 46 void WebView::CreateWebContentsWithSiteInstance( |
| 47 content::SiteInstance* site_instance) { | 47 content::SiteInstance* site_instance) { |
| 48 if (!web_contents_) { | 48 if (!web_contents_) { |
| 49 wc_owner_.reset(content::WebContents::Create(browser_context_, | 49 wc_owner_.reset(CreateWebContents(browser_context_, site_instance)); |
| 50 site_instance, | |
| 51 MSG_ROUTING_NONE, | |
| 52 NULL, | |
| 53 NULL)); | |
| 54 web_contents_ = wc_owner_.get(); | 50 web_contents_ = wc_owner_.get(); |
| 55 web_contents_->SetDelegate(this); | 51 web_contents_->SetDelegate(this); |
| 56 AttachWebContents(); | 52 AttachWebContents(); |
| 57 } | 53 } |
| 58 } | 54 } |
| 59 | 55 |
| 60 void WebView::SetWebContents(content::WebContents* web_contents) { | 56 void WebView::SetWebContents(content::WebContents* web_contents) { |
| 61 if (web_contents == web_contents_) | 57 if (web_contents == web_contents_) |
| 62 return; | 58 return; |
| 63 DetachWebContents(); | 59 DetachWebContents(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
| 165 // WebView, content::WebContentsDelegate implementation: | 161 // WebView, content::WebContentsDelegate implementation: |
| 166 | 162 |
| 167 void WebView::WebContentsFocused(content::WebContents* web_contents) { | 163 void WebView::WebContentsFocused(content::WebContents* web_contents) { |
| 168 DCHECK(wc_owner_.get()); | 164 DCHECK(wc_owner_.get()); |
| 169 // The WebView is only the delegate of WebContentses it creates itself. | 165 // The WebView is only the delegate of WebContentses it creates itself. |
| 170 OnWebContentsFocused(web_contents_); | 166 OnWebContentsFocused(web_contents_); |
| 171 } | 167 } |
| 172 | 168 |
| 173 //////////////////////////////////////////////////////////////////////////////// | 169 //////////////////////////////////////////////////////////////////////////////// |
| 170 // WebView, protected: |
| 171 |
| 172 content::WebContents* WebView::CreateWebContents( |
| 173 content::BrowserContext* browser_context, |
| 174 content::SiteInstance* site_instance) { |
| 175 return content::WebContents::Create(browser_context, |
| 176 site_instance, |
| 177 MSG_ROUTING_NONE, |
| 178 NULL, |
| 179 NULL); |
| 180 } |
| 181 |
| 182 //////////////////////////////////////////////////////////////////////////////// |
| 174 // WebView, private: | 183 // WebView, private: |
| 175 | 184 |
| 176 void WebView::AttachWebContents() { | 185 void WebView::AttachWebContents() { |
| 177 // Prevents attachment if the WebView isn't already in a Widget, or it's | 186 // Prevents attachment if the WebView isn't already in a Widget, or it's |
| 178 // already attached. | 187 // already attached. |
| 179 if (!GetWidget() || !web_contents_ || | 188 if (!GetWidget() || !web_contents_ || |
| 180 wcv_holder_->native_view() == web_contents_->GetNativeView()) { | 189 wcv_holder_->native_view() == web_contents_->GetNativeView()) { |
| 181 return; | 190 return; |
| 182 } | 191 } |
| 183 | 192 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 if (GetFocusManager()->GetFocusedView() == this) | 231 if (GetFocusManager()->GetFocusedView() == this) |
| 223 web_contents_->Focus(); | 232 web_contents_->Focus(); |
| 224 } | 233 } |
| 225 | 234 |
| 226 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { | 235 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { |
| 227 DCHECK(web_contents == web_contents_); | 236 DCHECK(web_contents == web_contents_); |
| 228 SetWebContents(NULL); | 237 SetWebContents(NULL); |
| 229 } | 238 } |
| 230 | 239 |
| 231 } // namespace views | 240 } // namespace views |
| OLD | NEW |