Chromium Code Reviews| 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 "chrome/browser/ui/panels/panel_host.h" | 5 #include "chrome/browser/ui/panels/panel_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/chrome_page_zoom.h" | 10 #include "chrome/browser/chrome_page_zoom.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 panel_->session_id()); | 64 panel_->session_id()); |
| 65 | 65 |
| 66 FaviconTabHelper::CreateForWebContents(web_contents_.get()); | 66 FaviconTabHelper::CreateForWebContents(web_contents_.get()); |
| 67 PrefsTabHelper::CreateForWebContents(web_contents_.get()); | 67 PrefsTabHelper::CreateForWebContents(web_contents_.get()); |
| 68 | 68 |
| 69 web_contents_->GetController().LoadURL( | 69 web_contents_->GetController().LoadURL( |
| 70 url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); | 70 url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void PanelHost::DestroyWebContents() { | 73 void PanelHost::DestroyWebContents() { |
| 74 web_contents_.reset(); | 74 // Cannot do a web_contents_.reset() because web_contents_.get() will |
| 75 // still return the pointer when we CHECK in WebContentsDestroyed (or if | |
| 76 // we get called back in the middle of web contents destruction, which | |
| 77 // WebView might do when it detects the web contents is destroyed). | |
| 78 content::WebContents* contents = web_contents_.release(); | |
| 79 delete contents; | |
| 75 } | 80 } |
| 76 | 81 |
| 77 gfx::Image PanelHost::GetPageIcon() const { | 82 gfx::Image PanelHost::GetPageIcon() const { |
| 78 if (!web_contents_.get()) | 83 if (!web_contents_.get()) |
| 79 return gfx::Image(); | 84 return gfx::Image(); |
| 80 | 85 |
| 81 FaviconTabHelper* favicon_tab_helper = | 86 FaviconTabHelper* favicon_tab_helper = |
| 82 FaviconTabHelper::FromWebContents(web_contents_.get()); | 87 FaviconTabHelper::FromWebContents(web_contents_.get()); |
| 83 return favicon_tab_helper->GetFavicon(); | 88 DCHECK(favicon_tab_helper); |
|
sky
2012/10/15 23:34:17
Make this a CHECK so we can know for sure if its N
jennb
2012/10/16 00:17:07
Done.
| |
| 89 return favicon_tab_helper ? favicon_tab_helper->GetFavicon() : gfx::Image(); | |
| 84 } | 90 } |
| 85 | 91 |
| 86 content::WebContents* PanelHost::OpenURLFromTab( | 92 content::WebContents* PanelHost::OpenURLFromTab( |
| 87 content::WebContents* source, | 93 content::WebContents* source, |
| 88 const content::OpenURLParams& params) { | 94 const content::OpenURLParams& params) { |
| 89 // These dispositions aren't really navigations. | 95 // These dispositions aren't really navigations. |
| 90 if (params.disposition == SUPPRESS_OPEN || | 96 if (params.disposition == SUPPRESS_OPEN || |
| 91 params.disposition == SAVE_TO_DISK || | 97 params.disposition == SAVE_TO_DISK || |
| 92 params.disposition == IGNORE_ACTION) | 98 params.disposition == IGNORE_ACTION) |
| 93 return NULL; | 99 return NULL; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 extensions::WindowController* window = GetExtensionWindowController(); | 202 extensions::WindowController* window = GetExtensionWindowController(); |
| 197 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId( | 203 render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId( |
| 198 render_view_host->GetRoutingID(), window->GetWindowId())); | 204 render_view_host->GetRoutingID(), window->GetWindowId())); |
| 199 } | 205 } |
| 200 | 206 |
| 201 void PanelHost::RenderViewGone(base::TerminationStatus status) { | 207 void PanelHost::RenderViewGone(base::TerminationStatus status) { |
| 202 CloseContents(web_contents_.get()); | 208 CloseContents(web_contents_.get()); |
| 203 } | 209 } |
| 204 | 210 |
| 205 void PanelHost::WebContentsDestroyed(content::WebContents* web_contents) { | 211 void PanelHost::WebContentsDestroyed(content::WebContents* web_contents) { |
| 212 // Web contents should only be destroyed by us. | |
| 213 CHECK(!web_contents_.get()); | |
| 214 | |
| 206 // Close the panel after we return to the message loop (not immediately, | 215 // Close the panel after we return to the message loop (not immediately, |
| 207 // otherwise, it may destroy this object before the stack has a chance | 216 // otherwise, it may destroy this object before the stack has a chance |
| 208 // to cleanly unwind.) | 217 // to cleanly unwind.) |
| 209 MessageLoop::current()->PostTask( | 218 MessageLoop::current()->PostTask( |
| 210 FROM_HERE, | 219 FROM_HERE, |
| 211 base::Bind(&PanelHost::ClosePanel, weak_factory_.GetWeakPtr())); | 220 base::Bind(&PanelHost::ClosePanel, weak_factory_.GetWeakPtr())); |
| 212 } | 221 } |
| 213 | 222 |
| 214 void PanelHost::ClosePanel() { | 223 void PanelHost::ClosePanel() { |
| 215 panel_->Close(); | 224 panel_->Close(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 260 } |
| 252 | 261 |
| 253 void PanelHost::StopLoading() { | 262 void PanelHost::StopLoading() { |
| 254 content::RecordAction(UserMetricsAction("Stop")); | 263 content::RecordAction(UserMetricsAction("Stop")); |
| 255 web_contents_->Stop(); | 264 web_contents_->Stop(); |
| 256 } | 265 } |
| 257 | 266 |
| 258 void PanelHost::Zoom(content::PageZoom zoom) { | 267 void PanelHost::Zoom(content::PageZoom zoom) { |
| 259 chrome_page_zoom::Zoom(web_contents_.get(), zoom); | 268 chrome_page_zoom::Zoom(web_contents_.get(), zoom); |
| 260 } | 269 } |
| OLD | NEW |