| 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/guestview/guestview_constants.h" | 10 #include "chrome/browser/guestview/guestview_constants.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 NOTREACHED(); | 63 NOTREACHED(); |
| 64 break; | 64 break; |
| 65 } | 65 } |
| 66 return std::string(); | 66 return std::string(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void RemoveWebViewEventListenersOnIOThread( | 69 void RemoveWebViewEventListenersOnIOThread( |
| 70 void* profile, | 70 void* profile, |
| 71 const std::string& extension_id, | 71 const std::string& extension_id, |
| 72 int embedder_process_id, | 72 int embedder_process_id, |
| 73 int embedder_routing_id, | 73 int view_instance_id) { |
| 74 int guest_instance_id) { | |
| 75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 74 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 76 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | 75 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( |
| 77 profile, | 76 profile, |
| 78 extension_id, | 77 extension_id, |
| 79 embedder_process_id, | 78 embedder_process_id, |
| 80 embedder_routing_id, | 79 view_instance_id); |
| 81 guest_instance_id); | |
| 82 } | 80 } |
| 83 | 81 |
| 84 } // namespace | 82 } // namespace |
| 85 | 83 |
| 86 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) | 84 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) |
| 87 : GuestView(guest_web_contents), | 85 : GuestView(guest_web_contents), |
| 88 WebContentsObserver(guest_web_contents), | 86 WebContentsObserver(guest_web_contents), |
| 89 script_executor_(new extensions::ScriptExecutor(guest_web_contents, | 87 script_executor_(new extensions::ScriptExecutor(guest_web_contents, |
| 90 &script_observers_)), | 88 &script_observers_)), |
| 91 next_permission_request_id_(0) { | 89 next_permission_request_id_(0) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 args->SetString(webview::kSourceId, source_id); | 138 args->SetString(webview::kSourceId, source_id); |
| 141 DispatchEvent( | 139 DispatchEvent( |
| 142 new GuestView::Event(webview::kEventConsoleMessage, args.Pass())); | 140 new GuestView::Event(webview::kEventConsoleMessage, args.Pass())); |
| 143 } | 141 } |
| 144 | 142 |
| 145 void WebViewGuest::Close() { | 143 void WebViewGuest::Close() { |
| 146 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 144 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 147 DispatchEvent(new GuestView::Event(webview::kEventClose, args.Pass())); | 145 DispatchEvent(new GuestView::Event(webview::kEventClose, args.Pass())); |
| 148 } | 146 } |
| 149 | 147 |
| 148 void WebViewGuest::EmbedderDestroyed() { |
| 149 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
| 150 // reparenting of a <webview> within a single embedder. Right now, we keep |
| 151 // around the browser state for the listener for the lifetime of the embedder. |
| 152 // Ideally, the lifetime of the listeners should match the lifetime of the |
| 153 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move |
| 154 // the call to RemoveWebViewEventListenersOnIOThread back to |
| 155 // WebViewGuest::WebContentsDestroyed. |
| 156 content::BrowserThread::PostTask( |
| 157 content::BrowserThread::IO, |
| 158 FROM_HERE, |
| 159 base::Bind( |
| 160 &RemoveWebViewEventListenersOnIOThread, |
| 161 browser_context(), extension_id(), |
| 162 embedder_render_process_id(), |
| 163 view_instance_id())); |
| 164 } |
| 165 |
| 150 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { | 166 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { |
| 151 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 167 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 152 args->SetInteger(webview::kProcessId, | 168 args->SetInteger(webview::kProcessId, |
| 153 web_contents()->GetRenderProcessHost()->GetID()); | 169 web_contents()->GetRenderProcessHost()->GetID()); |
| 154 args->SetString(webview::kReason, TerminationStatusToString(status)); | 170 args->SetString(webview::kReason, TerminationStatusToString(status)); |
| 155 DispatchEvent( | 171 DispatchEvent( |
| 156 new GuestView::Event(webview::kEventExit, args.Pass())); | 172 new GuestView::Event(webview::kEventExit, args.Pass())); |
| 157 } | 173 } |
| 158 | 174 |
| 159 bool WebViewGuest::HandleKeyboardEvent( | 175 bool WebViewGuest::HandleKeyboardEvent( |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 DispatchEvent(new GuestView::Event(webview::kEventLoadStart, args.Pass())); | 394 DispatchEvent(new GuestView::Event(webview::kEventLoadStart, args.Pass())); |
| 379 } | 395 } |
| 380 | 396 |
| 381 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { | 397 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { |
| 382 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 398 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 383 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); | 399 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); |
| 384 } | 400 } |
| 385 | 401 |
| 386 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { | 402 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { |
| 387 RemoveWebViewFromExtensionRendererState(web_contents); | 403 RemoveWebViewFromExtensionRendererState(web_contents); |
| 388 // TODO(fsamuel): WebRequest event listeners for <webview> should survive | |
| 389 // reparenting of a <webview> within a single embedder. The lifetime of | |
| 390 // WebRequest event listeners should be equal to the lifetime of the embedder | |
| 391 // WebContents rather than the guest until http://crbug.com/156219 is | |
| 392 // resolved. | |
| 393 content::BrowserThread::PostTask( | |
| 394 content::BrowserThread::IO, | |
| 395 FROM_HERE, | |
| 396 base::Bind( | |
| 397 &RemoveWebViewEventListenersOnIOThread, | |
| 398 browser_context(), extension_id(), | |
| 399 embedder_render_process_id(), | |
| 400 embedder_routing_id(), | |
| 401 view_instance_id())); | |
| 402 } | 404 } |
| 403 | 405 |
| 404 void WebViewGuest::LoadHandlerCalled() { | 406 void WebViewGuest::LoadHandlerCalled() { |
| 405 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 407 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 406 DispatchEvent(new GuestView::Event(webview::kEventContentLoad, args.Pass())); | 408 DispatchEvent(new GuestView::Event(webview::kEventContentLoad, args.Pass())); |
| 407 } | 409 } |
| 408 | 410 |
| 409 void WebViewGuest::LoadRedirect(const GURL& old_url, | 411 void WebViewGuest::LoadRedirect(const GURL& old_url, |
| 410 const GURL& new_url, | 412 const GURL& new_url, |
| 411 bool is_top_level) { | 413 bool is_top_level) { |
| 412 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 414 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 413 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 415 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| 414 args->SetString(webview::kNewURL, new_url.spec()); | 416 args->SetString(webview::kNewURL, new_url.spec()); |
| 415 args->SetString(webview::kOldURL, old_url.spec()); | 417 args->SetString(webview::kOldURL, old_url.spec()); |
| 416 DispatchEvent(new GuestView::Event(webview::kEventLoadRedirect, args.Pass())); | 418 DispatchEvent(new GuestView::Event(webview::kEventLoadRedirect, args.Pass())); |
| 417 } | 419 } |
| 418 | 420 |
| 419 void WebViewGuest::AddWebViewToExtensionRendererState() { | 421 void WebViewGuest::AddWebViewToExtensionRendererState() { |
| 420 ExtensionRendererState::WebViewInfo webview_info; | 422 ExtensionRendererState::WebViewInfo webview_info; |
| 421 webview_info.embedder_process_id = embedder_render_process_id(); | 423 webview_info.embedder_process_id = embedder_render_process_id(); |
| 422 webview_info.embedder_routing_id = embedder_web_contents()->GetRoutingID(); | |
| 423 webview_info.instance_id = view_instance_id(); | 424 webview_info.instance_id = view_instance_id(); |
| 424 | 425 |
| 425 content::BrowserThread::PostTask( | 426 content::BrowserThread::PostTask( |
| 426 content::BrowserThread::IO, FROM_HERE, | 427 content::BrowserThread::IO, FROM_HERE, |
| 427 base::Bind( | 428 base::Bind( |
| 428 &ExtensionRendererState::AddWebView, | 429 &ExtensionRendererState::AddWebView, |
| 429 base::Unretained(ExtensionRendererState::GetInstance()), | 430 base::Unretained(ExtensionRendererState::GetInstance()), |
| 430 guest_web_contents()->GetRenderProcessHost()->GetID(), | 431 guest_web_contents()->GetRenderProcessHost()->GetID(), |
| 431 guest_web_contents()->GetRoutingID(), | 432 guest_web_contents()->GetRoutingID(), |
| 432 webview_info)); | 433 webview_info)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 446 | 447 |
| 447 void WebViewGuest::SizeChanged(const gfx::Size& old_size, | 448 void WebViewGuest::SizeChanged(const gfx::Size& old_size, |
| 448 const gfx::Size& new_size) { | 449 const gfx::Size& new_size) { |
| 449 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 450 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 450 args->SetInteger(webview::kOldHeight, old_size.height()); | 451 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 451 args->SetInteger(webview::kOldWidth, old_size.width()); | 452 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 452 args->SetInteger(webview::kNewHeight, new_size.height()); | 453 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 453 args->SetInteger(webview::kNewWidth, new_size.width()); | 454 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 454 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); | 455 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); |
| 455 } | 456 } |
| OLD | NEW |