| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/guestview/webview/webview_guest.h" | 5 #include "chrome/browser/guestview/webview/webview_guest.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 7 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 8 #include "chrome/browser/extensions/extension_renderer_state.h" | 8 #include "chrome/browser/extensions/extension_renderer_state.h" |
| 9 #include "chrome/browser/extensions/script_executor.h" | 9 #include "chrome/browser/extensions/script_executor.h" |
| 10 #include "chrome/browser/favicon/favicon_tab_helper.h" | 10 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 NOTREACHED(); | 64 NOTREACHED(); |
| 65 break; | 65 break; |
| 66 } | 66 } |
| 67 return std::string(); | 67 return std::string(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void RemoveWebViewEventListenersOnIOThread( | 70 void RemoveWebViewEventListenersOnIOThread( |
| 71 void* profile, | 71 void* profile, |
| 72 const std::string& extension_id, | 72 const std::string& extension_id, |
| 73 int embedder_process_id, | 73 int embedder_process_id, |
| 74 int view_instance_id) { | 74 int embedder_routing_id, |
| 75 int guest_instance_id) { |
| 75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 76 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 76 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | 77 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( |
| 77 profile, | 78 profile, |
| 78 extension_id, | 79 extension_id, |
| 79 embedder_process_id, | 80 embedder_process_id, |
| 80 view_instance_id); | 81 embedder_routing_id, |
| 82 guest_instance_id); |
| 81 } | 83 } |
| 82 | 84 |
| 83 void AttachWebViewHelpers(WebContents* contents) { | 85 void AttachWebViewHelpers(WebContents* contents) { |
| 84 FaviconTabHelper::CreateForWebContents(contents); | 86 FaviconTabHelper::CreateForWebContents(contents); |
| 85 } | 87 } |
| 86 | 88 |
| 87 } // namespace | 89 } // namespace |
| 88 | 90 |
| 89 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) | 91 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) |
| 90 : GuestView(guest_web_contents), | 92 : GuestView(guest_web_contents), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 args->SetString(webview::kSourceId, source_id); | 147 args->SetString(webview::kSourceId, source_id); |
| 146 DispatchEvent( | 148 DispatchEvent( |
| 147 new GuestView::Event(webview::kEventConsoleMessage, args.Pass())); | 149 new GuestView::Event(webview::kEventConsoleMessage, args.Pass())); |
| 148 } | 150 } |
| 149 | 151 |
| 150 void WebViewGuest::Close() { | 152 void WebViewGuest::Close() { |
| 151 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 153 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 152 DispatchEvent(new GuestView::Event(webview::kEventClose, args.Pass())); | 154 DispatchEvent(new GuestView::Event(webview::kEventClose, args.Pass())); |
| 153 } | 155 } |
| 154 | 156 |
| 155 void WebViewGuest::EmbedderDestroyed() { | |
| 156 // TODO(fsamuel): WebRequest event listeners for <webview> should survive | |
| 157 // reparenting of a <webview> within a single embedder. Right now, we keep | |
| 158 // around the browser state for the listener for the lifetime of the embedder. | |
| 159 // Ideally, the lifetime of the listeners should match the lifetime of the | |
| 160 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move | |
| 161 // the call to RemoveWebViewEventListenersOnIOThread back to | |
| 162 // WebViewGuest::WebContentsDestroyed. | |
| 163 content::BrowserThread::PostTask( | |
| 164 content::BrowserThread::IO, | |
| 165 FROM_HERE, | |
| 166 base::Bind( | |
| 167 &RemoveWebViewEventListenersOnIOThread, | |
| 168 browser_context(), extension_id(), | |
| 169 embedder_render_process_id(), | |
| 170 view_instance_id())); | |
| 171 } | |
| 172 | |
| 173 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { | 157 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { |
| 174 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 158 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 175 args->SetInteger(webview::kProcessId, | 159 args->SetInteger(webview::kProcessId, |
| 176 web_contents()->GetRenderProcessHost()->GetID()); | 160 web_contents()->GetRenderProcessHost()->GetID()); |
| 177 args->SetString(webview::kReason, TerminationStatusToString(status)); | 161 args->SetString(webview::kReason, TerminationStatusToString(status)); |
| 178 DispatchEvent( | 162 DispatchEvent( |
| 179 new GuestView::Event(webview::kEventExit, args.Pass())); | 163 new GuestView::Event(webview::kEventExit, args.Pass())); |
| 180 } | 164 } |
| 181 | 165 |
| 182 bool WebViewGuest::HandleKeyboardEvent( | 166 bool WebViewGuest::HandleKeyboardEvent( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 DispatchEvent(new GuestView::Event(webview::kEventLoadStart, args.Pass())); | 392 DispatchEvent(new GuestView::Event(webview::kEventLoadStart, args.Pass())); |
| 409 } | 393 } |
| 410 | 394 |
| 411 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { | 395 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { |
| 412 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 396 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 413 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); | 397 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); |
| 414 } | 398 } |
| 415 | 399 |
| 416 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { | 400 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { |
| 417 RemoveWebViewFromExtensionRendererState(web_contents); | 401 RemoveWebViewFromExtensionRendererState(web_contents); |
| 402 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
| 403 // reparenting of a <webview> within a single embedder. The lifetime of |
| 404 // WebRequest event listeners should be equal to the lifetime of the embedder |
| 405 // WebContents rather than the guest until http://crbug.com/156219 is |
| 406 // resolved. |
| 407 content::BrowserThread::PostTask( |
| 408 content::BrowserThread::IO, |
| 409 FROM_HERE, |
| 410 base::Bind( |
| 411 &RemoveWebViewEventListenersOnIOThread, |
| 412 browser_context(), extension_id(), |
| 413 embedder_render_process_id(), |
| 414 embedder_routing_id(), |
| 415 view_instance_id())); |
| 418 } | 416 } |
| 419 | 417 |
| 420 void WebViewGuest::LoadHandlerCalled() { | 418 void WebViewGuest::LoadHandlerCalled() { |
| 421 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 419 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 422 DispatchEvent(new GuestView::Event(webview::kEventContentLoad, args.Pass())); | 420 DispatchEvent(new GuestView::Event(webview::kEventContentLoad, args.Pass())); |
| 423 } | 421 } |
| 424 | 422 |
| 425 void WebViewGuest::LoadRedirect(const GURL& old_url, | 423 void WebViewGuest::LoadRedirect(const GURL& old_url, |
| 426 const GURL& new_url, | 424 const GURL& new_url, |
| 427 bool is_top_level) { | 425 bool is_top_level) { |
| 428 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 426 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 429 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 427 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| 430 args->SetString(webview::kNewURL, new_url.spec()); | 428 args->SetString(webview::kNewURL, new_url.spec()); |
| 431 args->SetString(webview::kOldURL, old_url.spec()); | 429 args->SetString(webview::kOldURL, old_url.spec()); |
| 432 DispatchEvent(new GuestView::Event(webview::kEventLoadRedirect, args.Pass())); | 430 DispatchEvent(new GuestView::Event(webview::kEventLoadRedirect, args.Pass())); |
| 433 } | 431 } |
| 434 | 432 |
| 435 void WebViewGuest::AddWebViewToExtensionRendererState() { | 433 void WebViewGuest::AddWebViewToExtensionRendererState() { |
| 436 ExtensionRendererState::WebViewInfo webview_info; | 434 ExtensionRendererState::WebViewInfo webview_info; |
| 437 webview_info.embedder_process_id = embedder_render_process_id(); | 435 webview_info.embedder_process_id = embedder_render_process_id(); |
| 436 webview_info.embedder_routing_id = embedder_web_contents()->GetRoutingID(); |
| 438 webview_info.instance_id = view_instance_id(); | 437 webview_info.instance_id = view_instance_id(); |
| 439 | 438 |
| 440 content::BrowserThread::PostTask( | 439 content::BrowserThread::PostTask( |
| 441 content::BrowserThread::IO, FROM_HERE, | 440 content::BrowserThread::IO, FROM_HERE, |
| 442 base::Bind( | 441 base::Bind( |
| 443 &ExtensionRendererState::AddWebView, | 442 &ExtensionRendererState::AddWebView, |
| 444 base::Unretained(ExtensionRendererState::GetInstance()), | 443 base::Unretained(ExtensionRendererState::GetInstance()), |
| 445 guest_web_contents()->GetRenderProcessHost()->GetID(), | 444 guest_web_contents()->GetRenderProcessHost()->GetID(), |
| 446 guest_web_contents()->GetRoutingID(), | 445 guest_web_contents()->GetRoutingID(), |
| 447 webview_info)); | 446 webview_info)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 461 | 460 |
| 462 void WebViewGuest::SizeChanged(const gfx::Size& old_size, | 461 void WebViewGuest::SizeChanged(const gfx::Size& old_size, |
| 463 const gfx::Size& new_size) { | 462 const gfx::Size& new_size) { |
| 464 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 463 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 465 args->SetInteger(webview::kOldHeight, old_size.height()); | 464 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 466 args->SetInteger(webview::kOldWidth, old_size.width()); | 465 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 467 args->SetInteger(webview::kNewHeight, new_size.height()); | 466 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 468 args->SetInteger(webview::kNewWidth, new_size.width()); | 467 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 469 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); | 468 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); |
| 470 } | 469 } |
| OLD | NEW |