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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "ipc/ipc_message.h" | 33 #include "ipc/ipc_message.h" |
34 #include "ipc/ipc_message_macros.h" | 34 #include "ipc/ipc_message_macros.h" |
35 #include "ui/gfx/geometry/rect.h" | 35 #include "ui/gfx/geometry/rect.h" |
36 #include "ui/gfx/image/image.h" | 36 #include "ui/gfx/image/image.h" |
37 | 37 |
38 using base::UserMetricsAction; | 38 using base::UserMetricsAction; |
39 | 39 |
40 PanelHost::PanelHost(Panel* panel, Profile* profile) | 40 PanelHost::PanelHost(Panel* panel, Profile* profile) |
41 : panel_(panel), | 41 : panel_(panel), |
42 profile_(profile), | 42 profile_(profile), |
43 extension_function_dispatcher_(profile, this), | |
44 weak_factory_(this) { | 43 weak_factory_(this) { |
45 } | 44 } |
46 | 45 |
47 PanelHost::~PanelHost() { | 46 PanelHost::~PanelHost() { |
48 } | 47 } |
49 | 48 |
50 void PanelHost::Init(const GURL& url) { | 49 void PanelHost::Init(const GURL& url) { |
51 if (url.is_empty()) | 50 if (url.is_empty()) |
52 return; | 51 return; |
53 | 52 |
(...skipping 10 matching lines...) Expand all Loading... |
64 // Needed to give the web contents a Tab ID. Extension APIs | 63 // Needed to give the web contents a Tab ID. Extension APIs |
65 // expect web contents to have a Tab ID. | 64 // expect web contents to have a Tab ID. |
66 SessionTabHelper::CreateForWebContents(web_contents_.get()); | 65 SessionTabHelper::CreateForWebContents(web_contents_.get()); |
67 SessionTabHelper::FromWebContents(web_contents_.get())->SetWindowID( | 66 SessionTabHelper::FromWebContents(web_contents_.get())->SetWindowID( |
68 panel_->session_id()); | 67 panel_->session_id()); |
69 | 68 |
70 favicon::CreateContentFaviconDriverForWebContents(web_contents_.get()); | 69 favicon::CreateContentFaviconDriverForWebContents(web_contents_.get()); |
71 PrefsTabHelper::CreateForWebContents(web_contents_.get()); | 70 PrefsTabHelper::CreateForWebContents(web_contents_.get()); |
72 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 71 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
73 web_contents_.get()); | 72 web_contents_.get()); |
| 73 extensions::ExtensionWebContentsObserver::GetForWebContents( |
| 74 web_contents_.get())->dispatcher()->set_delegate(this); |
74 | 75 |
75 web_contents_->GetController().LoadURL( | 76 web_contents_->GetController().LoadURL( |
76 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 77 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
77 } | 78 } |
78 | 79 |
79 void PanelHost::DestroyWebContents() { | 80 void PanelHost::DestroyWebContents() { |
80 // Cannot do a web_contents_.reset() because web_contents_.get() will | 81 // Cannot do a web_contents_.reset() because web_contents_.get() will |
81 // still return the pointer when we CHECK in WebContentsDestroyed (or if | 82 // still return the pointer when we CHECK in WebContentsDestroyed (or if |
82 // we get called back in the middle of web contents destruction, which | 83 // we get called back in the middle of web contents destruction, which |
83 // WebView might do when it detects the web contents is destroyed). | 84 // WebView might do when it detects the web contents is destroyed). |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // to cleanly unwind.) | 219 // to cleanly unwind.) |
219 base::MessageLoop::current()->PostTask( | 220 base::MessageLoop::current()->PostTask( |
220 FROM_HERE, | 221 FROM_HERE, |
221 base::Bind(&PanelHost::ClosePanel, weak_factory_.GetWeakPtr())); | 222 base::Bind(&PanelHost::ClosePanel, weak_factory_.GetWeakPtr())); |
222 } | 223 } |
223 | 224 |
224 void PanelHost::ClosePanel() { | 225 void PanelHost::ClosePanel() { |
225 panel_->Close(); | 226 panel_->Close(); |
226 } | 227 } |
227 | 228 |
228 bool PanelHost::OnMessageReceived(const IPC::Message& message) { | |
229 bool handled = true; | |
230 IPC_BEGIN_MESSAGE_MAP(PanelHost, message) | |
231 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
232 IPC_MESSAGE_UNHANDLED(handled = false) | |
233 IPC_END_MESSAGE_MAP() | |
234 return handled; | |
235 } | |
236 | |
237 void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { | |
238 if (!web_contents_.get()) | |
239 return; | |
240 | |
241 extension_function_dispatcher_.Dispatch(params, | |
242 web_contents_->GetRenderViewHost()); | |
243 } | |
244 | |
245 extensions::WindowController* PanelHost::GetExtensionWindowController() const { | 229 extensions::WindowController* PanelHost::GetExtensionWindowController() const { |
246 return panel_->extension_window_controller(); | 230 return panel_->extension_window_controller(); |
247 } | 231 } |
248 | 232 |
249 content::WebContents* PanelHost::GetAssociatedWebContents() const { | 233 content::WebContents* PanelHost::GetAssociatedWebContents() const { |
250 return web_contents_.get(); | 234 return web_contents_.get(); |
251 } | 235 } |
252 | 236 |
253 void PanelHost::Reload() { | 237 void PanelHost::Reload() { |
254 content::RecordAction(UserMetricsAction("Reload")); | 238 content::RecordAction(UserMetricsAction("Reload")); |
255 web_contents_->GetController().Reload(true); | 239 web_contents_->GetController().Reload(true); |
256 } | 240 } |
257 | 241 |
258 void PanelHost::ReloadIgnoringCache() { | 242 void PanelHost::ReloadIgnoringCache() { |
259 content::RecordAction(UserMetricsAction("ReloadIgnoringCache")); | 243 content::RecordAction(UserMetricsAction("ReloadIgnoringCache")); |
260 web_contents_->GetController().ReloadIgnoringCache(true); | 244 web_contents_->GetController().ReloadIgnoringCache(true); |
261 } | 245 } |
262 | 246 |
263 void PanelHost::StopLoading() { | 247 void PanelHost::StopLoading() { |
264 content::RecordAction(UserMetricsAction("Stop")); | 248 content::RecordAction(UserMetricsAction("Stop")); |
265 web_contents_->Stop(); | 249 web_contents_->Stop(); |
266 } | 250 } |
267 | 251 |
268 void PanelHost::Zoom(content::PageZoom zoom) { | 252 void PanelHost::Zoom(content::PageZoom zoom) { |
269 ui_zoom::PageZoom::Zoom(web_contents_.get(), zoom); | 253 ui_zoom::PageZoom::Zoom(web_contents_.get(), zoom); |
270 } | 254 } |
OLD | NEW |